Skip to content

Commit

Permalink
[ES-1347] added test cases (mosip#817)
Browse files Browse the repository at this point in the history
* [ES-1347] added test cases

Signed-off-by: Venkata Saidurga Polamraju <saidurgacsea@gmail.com>

* [ES-1347] updated review comments

Signed-off-by: Venkata Saidurga Polamraju <saidurgacsea@gmail.com>

---------

Signed-off-by: Venkata Saidurga Polamraju <saidurgacsea@gmail.com>
  • Loading branch information
pvsaidurga authored Jul 22, 2024
1 parent ad549e7 commit 16650d0
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ public class ClientNameLangValidator implements ConstraintValidator<ClientNameLa

private static final Locale[] availableLocales = Locale.getAvailableLocales();

@Override
public void initialize(ClientNameLang constraintAnnotation) {
}

@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
boolean isValid = Arrays.stream(availableLocales)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package io.mosip.esignet.core;

import io.mosip.esignet.api.dto.AuditDTO;
import io.mosip.esignet.api.util.Action;
import io.mosip.esignet.api.util.ActionStatus;
import io.mosip.esignet.core.util.LoggerAuditService;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class LoggerAuditServiceTest {

@Mock
private AuditDTO mockAuditDTO;

@InjectMocks
private LoggerAuditService loggerAuditService;

@Test
public void logAudit_withThrowable_thenPass() {
Action action = Action.SEND_OTP;
ActionStatus status = ActionStatus.ERROR;
Throwable throwable = new RuntimeException("Test Exception");
try {
loggerAuditService.logAudit(action, status, mockAuditDTO, throwable);
Assert.assertTrue(true);
}catch(Exception e){
Assert.fail();
}
}

@Test(expected = NullPointerException.class)
public void logAudit_withNullAction_throwsError() {
ActionStatus status = ActionStatus.ERROR;
Throwable throwable = new RuntimeException("Test Exception");
loggerAuditService.logAudit(null, status, mockAuditDTO, throwable);
}

@Test
public void logAudit_withDefaultStatus_thenPass() {
Action action = Action.SEND_OTP;
ActionStatus status = ActionStatus.SUCCESS;
String username = "testUser";
try {
loggerAuditService.logAudit(username, action, status, mockAuditDTO, null);
Assert.assertTrue(true);
}catch(Exception e){
Assert.fail();
}
}

@Test
public void logAudit_withErrorStatus_thenPass() {
Action action = Action.SEND_OTP;
ActionStatus status = ActionStatus.ERROR;
String username = "testUser";
try {
loggerAuditService.logAudit(username, action, status, mockAuditDTO, null);
Assert.assertTrue(true);
}catch(Exception e){
Assert.fail();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -633,4 +633,18 @@ public void test_ValidCodeChallengeValidator_withInvalidDetails_thenFail(){
Assert.assertFalse(validator.isValid(request,null));
}

// ============================ ClientNameLang Validator =========================

@Test
public void test_ClientNameLangValidator_WithValidDetails_thenPass(){
ClientNameLangValidator validator=new ClientNameLangValidator();
Assert.assertTrue(validator.isValid("eng", null));
}

@Test
public void test_ClientNameLangValidator_WithInValidDetail_thenFail(){
ClientNameLangValidator validator=new ClientNameLangValidator();
Assert.assertFalse(validator.isValid("abc", null));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import javax.servlet.http.HttpServletResponse;

import static io.mosip.esignet.core.spi.TokenService.ACR;
import static org.junit.Assert.assertThrows;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -1073,7 +1074,59 @@ public void authenticateV2_multipleRegisteredAcrsWithInvalidMultiFactor_thenFail
Assert.assertTrue(ex.getErrorCode().equals(ErrorConstants.AUTH_FACTOR_MISMATCH));
}
}


@Test
public void authenticateV3_withInvalidTransactionId_thenFail() {
String transactionId = "test-transaction";
when(cacheUtilService.getPreAuthTransaction(transactionId)).thenReturn(null);

AuthRequestV2 authRequest = new AuthRequestV2();
authRequest.setTransactionId(transactionId);
try {
authorizationServiceImpl.authenticateUserV3(authRequest,httpServletRequest);
Assert.fail();
} catch (EsignetException ex) {
Assert.assertTrue(ex.getErrorCode().equals(ErrorConstants.INVALID_TRANSACTION));
}
}

@Test
public void resumeHaltedTransaction_withValidTransactionId_thenPass() {
String transactionId = "validTransactionId";
ResumeRequest resumeRequest = new ResumeRequest();
resumeRequest.setTransactionId(transactionId);
resumeRequest.setWithError(false);
OIDCTransaction oidcTransaction = new OIDCTransaction();
when(cacheUtilService.getHaltedTransaction(transactionId)).thenReturn(oidcTransaction);
ResumeResponse result = authorizationServiceImpl.resumeHaltedTransaction(resumeRequest);
Assert.assertEquals(Constants.RESUMED, result.getStatus());
}

@Test
public void resumeHaltedTransaction_withInvalidTransactionId_thenFail() {
String transactionId = "invalidTransactionId";
ResumeRequest resumeRequest = new ResumeRequest();
resumeRequest.setTransactionId(transactionId);
resumeRequest.setWithError(false);
when(cacheUtilService.getHaltedTransaction(transactionId)).thenReturn(null);
assertThrows(InvalidTransactionException.class, () -> {
authorizationServiceImpl.resumeHaltedTransaction(resumeRequest);
});
}

@Test
public void resumeHaltedTransaction_withResumeNotApplicable_thenPass() {
String transactionId = "transactionId";
ResumeRequest resumeRequest = new ResumeRequest();
resumeRequest.setTransactionId(transactionId);
resumeRequest.setWithError(true);
OIDCTransaction oidcTransaction = new OIDCTransaction();
when(cacheUtilService.getHaltedTransaction(transactionId)).thenReturn(oidcTransaction);

ResumeResponse result = authorizationServiceImpl.resumeHaltedTransaction(resumeRequest);
Assert.assertEquals(Constants.RESUME_NOT_APPLICABLE, result.getStatus());
}

@Test
public void getAuthCode_withValidInput_thenPass() {
AuthCodeRequest authCodeRequest = new AuthCodeRequest();
Expand Down

0 comments on commit 16650d0

Please sign in to comment.