From bf9f095c864bf62d9ed167c5d90564d0eebefd02 Mon Sep 17 00:00:00 2001 From: Venkata Saidurga Polamraju Date: Tue, 8 Oct 2024 16:32:24 +0530 Subject: [PATCH] [ES-1613] Signed-off-by: Venkata Saidurga Polamraju --- .../MockAuthenticationServiceTest.java | 81 ++++++++++++++++++- 1 file changed, 79 insertions(+), 2 deletions(-) diff --git a/mock-plugin/src/test/java/io/mosip/esignet/plugin/mock/service/MockAuthenticationServiceTest.java b/mock-plugin/src/test/java/io/mosip/esignet/plugin/mock/service/MockAuthenticationServiceTest.java index 86e4943..c900b31 100644 --- a/mock-plugin/src/test/java/io/mosip/esignet/plugin/mock/service/MockAuthenticationServiceTest.java +++ b/mock-plugin/src/test/java/io/mosip/esignet/plugin/mock/service/MockAuthenticationServiceTest.java @@ -4,10 +4,12 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import io.mosip.esignet.api.dto.*; +import io.mosip.esignet.api.exception.KycAuthException; import io.mosip.esignet.api.exception.SendOtpException; import io.mosip.esignet.plugin.mock.dto.KycExchangeResponseDto; import io.mosip.esignet.api.exception.KycExchangeException; import io.mosip.esignet.api.util.ErrorConstants; +import io.mosip.esignet.plugin.mock.dto.VerifiedKycExchangeRequestDto; import io.mosip.kernel.core.http.ResponseWrapper; import io.mosip.kernel.keymanagerservice.dto.AllCertificatesDataResponseDto; import io.mosip.kernel.keymanagerservice.dto.CertificateDataResponseDto; @@ -28,6 +30,7 @@ import java.time.LocalDateTime; import java.util.*; +import static org.mockito.ArgumentMatchers.any; @RunWith(MockitoJUnitRunner.class) public class MockAuthenticationServiceTest { @@ -44,6 +47,9 @@ public class MockAuthenticationServiceTest { @Mock KeymanagerService keymanagerService; + @Mock + ObjectMapper objectMapper; + /*@Test public void doVerifiedKycExchange_withValidDetails_thenPass() throws KycExchangeException { ReflectionTestUtils.setField(mockAuthenticationService, "kycExchangeUrl", "http://localhost:8080/kyc/exchange"); @@ -222,8 +228,6 @@ public void doKycExchange_withValidDetails_thenPass() throws KycExchangeExceptio KycExchangeResult kycExchangeResult = mockAuthenticationService.doKycExchange("RP", "CL", kycExchangeDto); Assert.assertEquals(kycExchangeResponseDto.getKyc(), kycExchangeResult.getEncryptedKyc()); - - } @Test @@ -336,6 +340,79 @@ public void getAllKycSigningCertificates_withValidDetails_thenPass() { Assert.assertNotNull(allKycSigningCertificates); Assert.assertEquals(allKycSigningCertificates.size(), 2); } + + @Test + public void doKycAuth_withValidDetails_thenPass() throws KycAuthException { + String relyingPartyId = "testRelyingPartyId"; + String clientId = "testClientId"; + KycAuthDto kycAuthDto = new KycAuthDto(); + KycAuthResult expectedResult = new KycAuthResult(); + Mockito.when(mockHelperService.doKycAuthMock(relyingPartyId, clientId, kycAuthDto, false)) + .thenReturn(expectedResult); + KycAuthResult result = mockAuthenticationService.doKycAuth(relyingPartyId, clientId, false, kycAuthDto); + Assert.assertEquals(expectedResult, result); + } + + @Test + public void doVerifiedKycExchange_withValidDetails_thenPass () throws Exception { + ReflectionTestUtils.setField(mockAuthenticationService, "kycExchangeV2Url", "http://localhost:8080/kyc/exchange"); + String relyingPartyId = "testRelyingPartyId"; + String clientId = "testClientId"; + + VerifiedKycExchangeDto kycExchangeDto = new VerifiedKycExchangeDto(); + kycExchangeDto.setTransactionId("transactionId"); + kycExchangeDto.setKycToken("kycToken"); + kycExchangeDto.setIndividualId("individualId"); + kycExchangeDto.setClaimsLocales(new String[]{"en"}); + kycExchangeDto.setAcceptedClaimDetails(new HashMap<>()); + + VerifiedKycExchangeRequestDto verifiedRequestDto = new VerifiedKycExchangeRequestDto(); + verifiedRequestDto.setTransactionId(kycExchangeDto.getTransactionId()); + verifiedRequestDto.setKycToken(kycExchangeDto.getKycToken()); + verifiedRequestDto.setIndividualId(kycExchangeDto.getIndividualId()); + verifiedRequestDto.setClaimLocales(Arrays.asList(kycExchangeDto.getClaimsLocales())); + verifiedRequestDto.setAcceptedClaimDetail(kycExchangeDto.getAcceptedClaimDetails()); + + KycExchangeResponseDto responseDto = new KycExchangeResponseDto(); + responseDto.setKyc("mockKyc"); + + ResponseWrapper responseWrapper = new ResponseWrapper<>(); + responseWrapper.setResponse(responseDto); + + ResponseEntity> responseEntity = + new ResponseEntity<>(responseWrapper, HttpStatus.OK); + + Mockito.when(restTemplate.exchange( + any(RequestEntity.class), + any(ParameterizedTypeReference.class)) + ).thenReturn(responseEntity); + KycExchangeResult result = mockAuthenticationService.doVerifiedKycExchange(relyingPartyId, clientId, kycExchangeDto); + Assert.assertEquals("mockKyc", result.getEncryptedKyc()); + } + + @Test + public void doVerifiedKycExchange_withInvalidRequest_thenFail() { + String relyingPartyId = "testRelyingPartyId"; + String clientId = "testClientId"; + VerifiedKycExchangeDto kycExchangeDto = new VerifiedKycExchangeDto(); + ResponseEntity> responseEntity = + new ResponseEntity<>(HttpStatus.BAD_REQUEST); + KycExchangeException exception = Assert.assertThrows(KycExchangeException.class, () -> + mockAuthenticationService.doVerifiedKycExchange(relyingPartyId, clientId, kycExchangeDto) + ); + Assert.assertEquals("mock-ida-005", exception.getErrorCode()); + } + + @Test + public void doVerifiedKycExchange_throwsKycExchangeException_thenFail() { + String relyingPartyId = "testRelyingPartyId"; + String clientId = "testClientId"; + VerifiedKycExchangeDto kycExchangeDto = new VerifiedKycExchangeDto(); + KycExchangeException exception = Assert.assertThrows(KycExchangeException.class, () -> + mockAuthenticationService.doVerifiedKycExchange(relyingPartyId, clientId, kycExchangeDto) + ); + Assert.assertEquals("mock-ida-005", exception.getErrorCode()); + } }