diff --git a/resident/resident-service/src/main/java/io/mosip/resident/controller/TransliterationController.java b/resident/resident-service/src/main/java/io/mosip/resident/controller/TransliterationController.java index 88113bf8602..5bd03eaf4fc 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/controller/TransliterationController.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/controller/TransliterationController.java @@ -55,9 +55,6 @@ public class TransliterationController { @Autowired private AuditUtil audit; - /** The Constant for GET UPDATED DATE TIME application. */ - private static final String TRANS = "resident.transliteration.transliterate"; - /** * Post API to transliterate from transliteration application. * diff --git a/resident/resident-service/src/test/java/io/mosip/resident/controller/IdAuthControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/controller/IdAuthControllerTest.java index e00d3c0a430..36bd8f2da97 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/controller/IdAuthControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/controller/IdAuthControllerTest.java @@ -2,6 +2,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import java.util.Map; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -16,6 +18,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.util.ReflectionTestUtils; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders; @@ -24,6 +27,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import io.mosip.resident.constant.ResidentConstants; import io.mosip.resident.dto.IdAuthRequestDto; import io.mosip.resident.dto.RequestWrapper; import io.mosip.resident.exception.OtpValidationFailedException; @@ -81,12 +85,13 @@ public class IdAuthControllerTest { Gson gson = new GsonBuilder().serializeNulls().create(); String reqJson; + private RequestWrapper requestWrapper; @Before public void setUp() { MockitoAnnotations.initMocks(this); this.mockMvc = MockMvcBuilders.standaloneSetup(idAuthController).build(); - RequestWrapper requestWrapper = new RequestWrapper(); + requestWrapper = new RequestWrapper(); IdAuthRequestDto idAuthRequestDto = new IdAuthRequestDto(); idAuthRequestDto.setTransactionId("1234567890"); idAuthRequestDto.setIndividualId("8251649601"); @@ -94,6 +99,7 @@ public void setUp() { requestWrapper.setRequest(idAuthRequestDto); reqJson = gson.toJson(requestWrapper); Mockito.doNothing().when(auditUtil).setAuditRequestDto(Mockito.any()); + ReflectionTestUtils.setField(idAuthController, "validateOtpId", "validate-otp-id"); } @Test @@ -104,12 +110,11 @@ public void testValidateOtp() throws Exception { .content(reqJson.getBytes())).andExpect(status().isOk()); } - @Test(expected = Exception.class) + @Test(expected = OtpValidationFailedException.class) public void testValidateOtpFailed() throws Exception { - Mockito.when(idAuthService.validateOtpV1(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) - .thenThrow(new OtpValidationFailedException()); - mockMvc.perform(MockMvcRequestBuilders.post("/validate-otp").contentType(MediaType.APPLICATION_JSON_VALUE) - .content(reqJson.getBytes())).andExpect(status().isOk()); + Mockito.doThrow(new OtpValidationFailedException("otp validation failed", Map.of(ResidentConstants.EVENT_ID, "123456"))).when(idAuthService) + .validateOtpV1(Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); + idAuthController.validateOtp(requestWrapper); } } diff --git a/resident/resident-service/src/test/java/io/mosip/resident/controller/ProxyMasterDataControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/controller/ProxyMasterDataControllerTest.java index a6a0904c0f7..e58aa937f27 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/controller/ProxyMasterDataControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/controller/ProxyMasterDataControllerTest.java @@ -2,6 +2,7 @@ import io.mosip.kernel.core.crypto.spi.CryptoCoreSpec; import io.mosip.kernel.core.http.ResponseWrapper; +import io.mosip.resident.dto.LocationImmediateChildrenResponseDto; import io.mosip.resident.exception.ResidentServiceCheckedException; import io.mosip.resident.helper.ObjectStoreHelper; import io.mosip.resident.service.DocumentService; @@ -367,5 +368,14 @@ public void testGetAllDynamicFieldFailure() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/proxy/masterdata/dynamicfields/all/gender")) .andExpect(status().isOk()); } + + @Test + public void testGetImmediateChildrenByLocCode() throws Exception { + ResponseWrapper responseWrapper = new ResponseWrapper<>(); + responseWrapper.setResponse(new LocationImmediateChildrenResponseDto()); + Mockito.when(proxyMasterdataService.getImmediateChildrenByLocCode(Mockito.anyString(), Mockito.anyList())).thenReturn(responseWrapper.getResponse()); + mockMvc.perform(MockMvcRequestBuilders.get("/auth-proxy/masterdata/locations/immediatechildren/KNT?languageCodes=eng")) + .andExpect(status().isOk()); + } } diff --git a/resident/resident-service/src/test/java/io/mosip/resident/controller/ResidentControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/controller/ResidentControllerTest.java index ca96f96e158..4dd15fdd762 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/controller/ResidentControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/controller/ResidentControllerTest.java @@ -191,7 +191,6 @@ public class ResidentControllerTest { /** The mock mvc. */ @Autowired private MockMvc mockMvc; - private JSONObject idRepoJson; private String schemaJson; @Before @@ -235,7 +234,6 @@ public void setUp() throws ApisResourceAccessException, IOException { when(environment.getProperty(anyString())).thenReturn("property"); when(utilities.retrieveIdRepoJsonIdResponseDto(Mockito.any())).thenReturn(new IdResponseDTO1()); - idRepoJson = null; schemaJson = "schema"; } @@ -251,6 +249,15 @@ public void testGetRidStatusSuccess() throws Exception { .andExpect(status().isOk()).andExpect(jsonPath("$.response.ridStatus", is("PROCESSED"))); } + @Test(expected = InvalidInputException.class) + public void testGetRidStatusException() throws Exception { + RequestWrapper requestDTO = new RequestWrapper<>(); + requestDTO.setRequest(new RequestDTO()); + ReflectionTestUtils.setField(residentController, "checkStatusId", "id"); + Mockito.doThrow(InvalidInputException.class).when(validator).validateRidCheckStatusRequestDTO(Mockito.any()); + residentController.getRidStatus(requestDTO); + } + @Test @WithUserDetails("resident") public void testRequestAuthLockSuccess() throws Exception { @@ -278,17 +285,11 @@ public void testReqAuthTypeLock() throws Exception { .andExpect(status().isOk()).andExpect(status().isOk()); } - @Test - @WithUserDetails("resident") + @Test(expected = InvalidInputException.class) public void testReqAuthTypeLockBadRequest() throws Exception { - ResponseDTO responseDto = new ResponseDTO(); - doNothing().when(validator).validateAuthLockOrUnlockRequest(Mockito.any(), Mockito.any()); - Mockito.doReturn(Tuples.of(responseDto, "12345")).when(residentService).reqAauthTypeStatusUpdateV2(Mockito.any()); - - MvcResult result = this.mockMvc - .perform(post("/auth-lock-unlock").contentType(MediaType.APPLICATION_JSON).content("")) - .andExpect(status().isOk()).andReturn(); - assertTrue(result.getResponse().getContentAsString().contains("RES-SER-418")); + ReflectionTestUtils.setField(residentController, "authLockStatusUpdateV2Id", "id"); + doThrow(InvalidInputException.class).when(validator).validateAuthLockOrUnlockRequestV2(Mockito.any()); + residentController.reqAauthTypeStatusUpdateV2(authTypeStatusRequest); } @Test @@ -394,6 +395,17 @@ public void testGetServiceHistorySuccess() throws Exception { .andExpect(status().isOk()); } + @Test(expected = InvalidInputException.class) + public void testGetServiceHistoryException() throws Exception { + ReflectionTestUtils.setField(residentController, "serviceHistoryId", "id"); + Mockito.doThrow(InvalidInputException.class).when(validator).validateServiceHistoryRequest(Mockito.any(), + Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), + Mockito.anyString()); + residentController.getServiceHistory("eng", 1, 12, LocalDate.parse("2022-06-10"), + LocalDate.parse("2022-06-10"), SortType.ASC.toString(), + ServiceType.AUTHENTICATION_REQUEST.name(), "success", "123456", 0, LOCALE_EN_US); + } + @Test @WithUserDetails("reg-admin") public void testRequestAuthHistorySuccess() throws Exception { @@ -418,14 +430,16 @@ public void testRequestAuthHistorySuccess() throws Exception { .andExpect(status().isOk()).andExpect(jsonPath("$.response.message", is("success"))); } - @Test - @WithUserDetails("reg-admin") + @Test(expected = InvalidInputException.class) public void testRequestAuthHistoryBadRequest() throws Exception { - - MvcResult result = this.mockMvc - .perform(post("/req/auth-history").contentType(MediaType.APPLICATION_JSON).content("")) - .andExpect(status().isOk()).andReturn(); - assertTrue(result.getResponse().getContentAsString().contains("RES-SER-418")); + authHistoryRequest = new RequestWrapper(); + AuthHistoryRequestDTO hisdto = new AuthHistoryRequestDTO(); + hisdto.setIndividualId("1234"); + hisdto.setOtp("1234"); + hisdto.setTransactionID("1234"); + authHistoryRequest.setRequest(hisdto); + doThrow(InvalidInputException.class).when(validator).validateAuthHistoryRequest(Mockito.any()); + residentController.reqAuthHistory(authHistoryRequest); } @Test @@ -484,6 +498,48 @@ public void testUpdateUinDemographics() throws Exception { assertEquals(new ResidentUpdateResponseDTO(), ((ResponseWrapper)responseEntity.getBody()).getResponse()); } + @Test(expected = InvalidInputException.class) + public void testUpdateUinDemographicsIdTypeUINException() throws Exception { + Mockito.when(validator.validateUin(Mockito.anyString())).thenReturn(true); + Mockito.doThrow(InvalidInputException.class).when(validator).validateUpdateRequest(Mockito.any(), Mockito.anyBoolean(), Mockito.anyString()); + ResidentDemographicUpdateRequestDTO request = new ResidentDemographicUpdateRequestDTO(); + request.setTransactionID("12345"); + request.setIdentity(JsonUtil.readValue("{\"name\":\"My Name\"}", JSONObject.class)); + + RequestWrapper requestDTO = new RequestWrapper<>(); + requestDTO.setRequest(request); + requestDTO.setId("mosip.resident.demographic"); + requestDTO.setVersion("v1"); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("IDSchemaVersion", "0.1"); + Tuple3 idRepoJsonSchemaJsonAndIdResponseDtoTuple = Tuples.of(jsonObject, schemaJson, new IdResponseDTO1()); + when(utilities. + getIdentityDataFromIndividualID(Mockito.anyString())).thenReturn(idRepoJsonSchemaJsonAndIdResponseDtoTuple); + when(identityServiceImpl.getResidentIndvidualIdFromSession()).thenReturn("9876543210"); + residentController.updateUinDemographics(requestDTO); + } + + @Test(expected = InvalidInputException.class) + public void testUpdateUinDemographicsIdTypeVIDException() throws Exception { + Mockito.when(validator.validateVid(Mockito.anyString())).thenReturn(true); + Mockito.doThrow(InvalidInputException.class).when(validator).validateUpdateRequest(Mockito.any(), Mockito.anyBoolean(), Mockito.anyString()); + ResidentDemographicUpdateRequestDTO request = new ResidentDemographicUpdateRequestDTO(); + request.setTransactionID("12345"); + request.setIdentity(JsonUtil.readValue("{\"name\":\"My Name\"}", JSONObject.class)); + + RequestWrapper requestDTO = new RequestWrapper<>(); + requestDTO.setRequest(request); + requestDTO.setId("mosip.resident.demographic"); + requestDTO.setVersion("v1"); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("IDSchemaVersion", "0.1"); + Tuple3 idRepoJsonSchemaJsonAndIdResponseDtoTuple = Tuples.of(jsonObject, schemaJson, new IdResponseDTO1()); + when(utilities. + getIdentityDataFromIndividualID(Mockito.anyString())).thenReturn(idRepoJsonSchemaJsonAndIdResponseDtoTuple); + when(identityServiceImpl.getResidentIndvidualIdFromSession()).thenReturn("9876543210"); + residentController.updateUinDemographics(requestDTO); + } + @Test @WithUserDetails("reg-admin") public void testAuthLockStatus() throws Exception { @@ -618,6 +674,14 @@ public void testNotificationCount() throws Exception { residentController.notificationCount(); } + @Test(expected = ResidentServiceCheckedException.class) + public void testNotificationCountException() throws Exception { + ReflectionTestUtils.setField(residentController, "serviceEventId", "id"); + Mockito.when(identityServiceImpl.getResidentIdaToken()).thenReturn("1234567890"); + Mockito.when(residentService.getnotificationCount(Mockito.anyString())).thenThrow(ResidentServiceCheckedException.class); + residentController.notificationCount(); + } + @Test @WithUserDetails("reg-admin") public void testBellupdateClickdttimes() throws Exception { diff --git a/resident/resident-service/src/test/java/io/mosip/resident/controller/TransliterationControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/controller/TransliterationControllerTest.java index 7c9391a9b71..1d61925d6b6 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/controller/TransliterationControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/controller/TransliterationControllerTest.java @@ -1,6 +1,7 @@ package io.mosip.resident.controller; import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doThrow; import org.junit.Test; import org.junit.runner.RunWith; @@ -20,6 +21,7 @@ import io.mosip.preregistration.application.service.TransliterationService; import io.mosip.preregistration.core.common.dto.MainRequestDTO; import io.mosip.preregistration.core.common.dto.MainResponseDTO; +import io.mosip.resident.exception.InvalidInputException; import io.mosip.resident.helper.ObjectStoreHelper; import io.mosip.resident.service.IdAuthService; import io.mosip.resident.service.impl.IdentityServiceImpl; @@ -28,8 +30,8 @@ import io.mosip.resident.validator.RequestValidator; /** - * Acknowledgment Controller Test - * Note: This class is used to test the Acknowledgment Controller + * Transliteration Controller Test + * Note: This class is used to test the Transliteration Controller * @author Kamesh Shekhar Prasad */ @@ -83,4 +85,15 @@ public void testCreateRequestGenerationSuccess() throws Exception { assertEquals(responseEntity.getStatusCode(), HttpStatus.OK); } + @Test(expected = InvalidInputException.class) + public void testWithInvalidInputException() throws Exception { + MainRequestDTO requestDTO = new MainRequestDTO<>(); + TransliterationRequestDTO transliterationRequestDTO = new TransliterationRequestDTO(); + transliterationRequestDTO.setFromFieldLang("eng"); + transliterationRequestDTO.setFromFieldValue("cat"); + transliterationRequestDTO.setToFieldLang("hin"); + requestDTO.setRequest(transliterationRequestDTO); + doThrow(InvalidInputException.class).when(requestValidator).validateId(Mockito.any()); + transliterationController.translitrator(requestDTO); + } }