Skip to content

Commit

Permalink
Sonar coverage (#1016)
Browse files Browse the repository at this point in the history
* removed validate-request audits

* removed initial audits from controllers

* fixed audit and logger

* fixed debug logs

* fixed logger

* fixed audit and logger

* removed audits from test classes

* fixed one exception

* fixed sonar bug

* sonar coverage

* added test cases

---------

Co-authored-by: Ritik Jain <[email protected]>
  • Loading branch information
RitikJain4108 and Ritik Jain authored Jul 19, 2023
1 parent eb3aba1 commit cb52c2a
Show file tree
Hide file tree
Showing 8 changed files with 400 additions and 223 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,9 @@ public ResponseEntity<Object> reqAauthTypeStatusUpdateV2(
@Valid @RequestBody RequestWrapper<AuthLockOrUnLockRequestDtoV2> requestDTO)
throws ResidentServiceCheckedException, ApisResourceAccessException {
logger.debug("ResidentController::reqAauthTypeStatusUpdateV2()::entry");
String individualId = null;
ResponseWrapper<ResponseDTO> response = new ResponseWrapper<>();
Tuple2<ResponseDTO, String> tupleResponse = null;
try {
individualId = identityServiceImpl.getResidentIndvidualIdFromSession();
validator.validateAuthLockOrUnlockRequestV2(requestDTO);
logger.debug("ResidentController::Requesting auth lock/unlock api");
tupleResponse = residentService.reqAauthTypeStatusUpdateV2(requestDTO.getRequest());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import io.mosip.kernel.core.crypto.spi.CryptoCoreSpec;
import io.mosip.kernel.core.http.ResponseWrapper;
import io.mosip.resident.exception.ResidentServiceException;
import io.mosip.resident.helper.ObjectStoreHelper;
import io.mosip.resident.service.ProxyIdRepoService;
import io.mosip.resident.service.ResidentVidService;
Expand Down Expand Up @@ -108,6 +109,12 @@ public void testGetResidentUISchema() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get("/auth-proxy/config/ui-schema/update-demographics")).andExpect(status().isOk());
}

@Test(expected = Exception.class)
public void testGetResidentUISchemaWithResidentServiceException() throws Exception {
Mockito.when(residentConfigService.getUISchema("update-demographics")).thenThrow(ResidentServiceException.class);
mockMvc.perform(MockMvcRequestBuilders.get("/auth-proxy/config/ui-schema/update-demographics")).andExpect(status().isOk());
}

@Test
public void testGetIdentityMapping() throws Exception {
Mockito.when(residentConfigService.getIdentityMapping()).thenReturn("identity-mapping-json");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import io.mosip.kernel.core.crypto.spi.CryptoCoreSpec;
import io.mosip.kernel.core.http.ResponseWrapper;
import io.mosip.resident.exception.ResidentServiceCheckedException;
import io.mosip.resident.helper.ObjectStoreHelper;
import io.mosip.resident.service.DocumentService;
import io.mosip.resident.service.ProxyIdRepoService;
Expand Down Expand Up @@ -107,6 +108,14 @@ public void testGetValidDocumentByLangCode() throws Exception {
.andExpect(status().isOk());
}

@Test(expected = Exception.class)
public void testGetValidDocumentByLangCodeWithResidentServiceCheckedException() throws Exception {
Mockito.when(proxyMasterdataService.getValidDocumentByLangCode(Mockito.anyString()))
.thenThrow(ResidentServiceCheckedException.class);
mockMvc.perform(MockMvcRequestBuilders.get("/proxy/masterdata/validdocuments/langCode"))
.andExpect(status().isOk());
}

@Test
public void testGetLocationHierarchyLevelByLangCode() throws Exception {
Mockito.when(proxyMasterdataService.getLocationHierarchyLevelByLangCode(Mockito.anyString()))
Expand All @@ -115,6 +124,14 @@ public void testGetLocationHierarchyLevelByLangCode() throws Exception {
.andExpect(status().isOk());
}

@Test(expected = Exception.class)
public void testGetLocationHierarchyLevelByLangCodeWithResidentServiceCheckedException() throws Exception {
Mockito.when(proxyMasterdataService.getLocationHierarchyLevelByLangCode(Mockito.anyString()))
.thenThrow(ResidentServiceCheckedException.class);
mockMvc.perform(MockMvcRequestBuilders.get("/proxy/masterdata/locationHierarchyLevels/langcode"))
.andExpect(status().isOk());
}

@Test
public void testGetImmediateChildrenByLocCodeAndLangCode() throws Exception {
Mockito.when(proxyMasterdataService.getImmediateChildrenByLocCodeAndLangCode(Mockito.anyString(),
Expand All @@ -124,6 +141,15 @@ public void testGetImmediateChildrenByLocCodeAndLangCode() throws Exception {
.andExpect(status().isOk());
}

@Test(expected = Exception.class)
public void testGetImmediateChildrenByLocCodeAndLangCodeWithResidentServiceCheckedException() throws Exception {
Mockito.when(proxyMasterdataService.getImmediateChildrenByLocCodeAndLangCode(Mockito.anyString(),
Mockito.anyString())).thenThrow(ResidentServiceCheckedException.class);
mockMvc.perform(
MockMvcRequestBuilders.get("/proxy/masterdata/locations/immediatechildren/locationcode/langcode"))
.andExpect(status().isOk());
}

@Test
public void testGetLocationDetailsByLocCodeAndLangCode() throws Exception {
Mockito.when(
Expand All @@ -133,6 +159,15 @@ public void testGetLocationDetailsByLocCodeAndLangCode() throws Exception {
.andExpect(status().isOk());
}

@Test(expected = Exception.class)
public void testGetLocationDetailsByLocCodeAndLangCodeWithResidentServiceCheckedException() throws Exception {
Mockito.when(
proxyMasterdataService.getLocationDetailsByLocCodeAndLangCode(Mockito.anyString(), Mockito.anyString()))
.thenThrow(ResidentServiceCheckedException.class);
mockMvc.perform(MockMvcRequestBuilders.get("/proxy/masterdata/locations/info/locationcode/langcode"))
.andExpect(status().isOk());
}

@Test
public void testGetCoordinateSpecificRegistrationCenters() throws Exception {
Mockito.when(proxyMasterdataService.getCoordinateSpecificRegistrationCenters(Mockito.anyString(),
Expand All @@ -142,6 +177,15 @@ public void testGetCoordinateSpecificRegistrationCenters() throws Exception {
.andExpect(status().isOk());
}

@Test(expected = Exception.class)
public void testGetCoordinateSpecificRegistrationCentersWithResidentServiceCheckedException() throws Exception {
Mockito.when(proxyMasterdataService.getCoordinateSpecificRegistrationCenters(Mockito.anyString(),
Mockito.anyDouble(), Mockito.anyDouble(), Mockito.anyInt())).thenThrow(ResidentServiceCheckedException.class);
mockMvc.perform(MockMvcRequestBuilders
.get("/proxy/masterdata/getcoordinatespecificregistrationcenters/langcode/33.4/43.5/200"))
.andExpect(status().isOk());
}

@Test
public void testGetApplicantValidDocument() throws Exception {
Mockito.when(proxyMasterdataService.getApplicantValidDocument(Mockito.anyString(), Mockito.anyList()))
Expand All @@ -151,6 +195,15 @@ public void testGetApplicantValidDocument() throws Exception {
.andExpect(status().isOk());
}

@Test(expected = Exception.class)
public void testGetApplicantValidDocumentWithResidentServiceCheckedException() throws Exception {
Mockito.when(proxyMasterdataService.getApplicantValidDocument(Mockito.anyString(), Mockito.anyList()))
.thenThrow(ResidentServiceCheckedException.class);
mockMvc.perform(
MockMvcRequestBuilders.get("/proxy/masterdata/applicanttype/applicantId/languages?languages=eng"))
.andExpect(status().isOk());
}

@Test
public void testGetRegistrationCentersByHierarchyLevel() throws Exception {
Mockito.when(proxyMasterdataService.getRegistrationCentersByHierarchyLevel(Mockito.anyString(),
Expand All @@ -159,6 +212,14 @@ public void testGetRegistrationCentersByHierarchyLevel() throws Exception {
.andExpect(status().isOk());
}

@Test(expected = Exception.class)
public void testGetRegistrationCentersByHierarchyLevelWithResidentServiceCheckedException() throws Exception {
Mockito.when(proxyMasterdataService.getRegistrationCentersByHierarchyLevel(Mockito.anyString(),
Mockito.anyShort(), Mockito.anyList())).thenThrow(ResidentServiceCheckedException.class);
mockMvc.perform(MockMvcRequestBuilders.get("/proxy/masterdata/registrationcenters/langcode/5/names?name=14110"))
.andExpect(status().isOk());
}

@Test
public void testGetRegistrationCenterByHierarchyLevelAndTextPaginated() throws Exception {
Mockito.when(proxyMasterdataService.getRegistrationCenterByHierarchyLevelAndTextPaginated(Mockito.anyString(),
Expand All @@ -169,6 +230,16 @@ public void testGetRegistrationCenterByHierarchyLevelAndTextPaginated() throws E
.andExpect(status().isOk());
}

@Test(expected = Exception.class)
public void testGetRegistrationCenterByHierarchyLevelAndTextPaginatedWithResidentServiceCheckedException() throws Exception {
Mockito.when(proxyMasterdataService.getRegistrationCenterByHierarchyLevelAndTextPaginated(Mockito.anyString(),
Mockito.anyShort(), Mockito.anyString(), Mockito.anyInt(), Mockito.anyInt(), Mockito.any(),
Mockito.anyString())).thenThrow(ResidentServiceCheckedException.class);
mockMvc.perform(MockMvcRequestBuilders.get(
"/proxy/masterdata/registrationcenters/page/langcode/5/name?pageNumber=0&pageSize=10&orderBy=desc&sortBy=createdDateTime"))
.andExpect(status().isOk());
}

@Test
public void testGetRegistrationCenterWorkingDays() throws Exception {
Mockito.when(proxyMasterdataService.getRegistrationCenterWorkingDays(Mockito.anyString(), Mockito.anyString()))
Expand All @@ -177,6 +248,14 @@ public void testGetRegistrationCenterWorkingDays() throws Exception {
.andExpect(status().isOk());
}

@Test(expected = Exception.class)
public void testGetRegistrationCenterWorkingDaysWithResidentServiceCheckedException() throws Exception {
Mockito.when(proxyMasterdataService.getRegistrationCenterWorkingDays(Mockito.anyString(), Mockito.anyString()))
.thenThrow(ResidentServiceCheckedException.class);
mockMvc.perform(MockMvcRequestBuilders.get("/proxy/masterdata/workingdays/registrationCenterID/langCode"))
.andExpect(status().isOk());
}

@Test
public void testGetLatestIdSchema() throws Exception {
Mockito.when(
Expand All @@ -185,34 +264,71 @@ public void testGetLatestIdSchema() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get("/proxy/masterdata/idschema/latest?schemaVersion=&domain=&type="))
.andExpect(status().isOk());
}


@Test(expected = Exception.class)
public void testGetLatestIdSchemaWithResidentServiceCheckedException() throws Exception {
Mockito.when(
proxyMasterdataService.getLatestIdSchema(Mockito.anyDouble(), Mockito.anyString(), Mockito.anyString()))
.thenThrow(ResidentServiceCheckedException.class);
mockMvc.perform(MockMvcRequestBuilders.get("/proxy/masterdata/idschema/latest?schemaVersion=&domain=&type="))
.andExpect(status().isOk());
}

@Test
public void testGetAllTemplateBylangCodeAndTemplateTypeCode() throws Exception {
Mockito.when(proxyMasterdataService.getAllTemplateBylangCodeAndTemplateTypeCode(Mockito.anyString(),
Mockito.anyString())).thenReturn(responseWrapper);
mockMvc.perform(MockMvcRequestBuilders.get("/auth-proxy/masterdata/templates/eng/OTP-sms-template"))
.andExpect(status().isOk());
}


@Test(expected = Exception.class)
public void testGetAllTemplateBylangCodeAndTemplateTypeCodeWithResidentServiceCheckedException() throws Exception {
Mockito.when(proxyMasterdataService.getAllTemplateBylangCodeAndTemplateTypeCode(Mockito.anyString(),
Mockito.anyString())).thenThrow(ResidentServiceCheckedException.class);
mockMvc.perform(MockMvcRequestBuilders.get("/auth-proxy/masterdata/templates/eng/OTP-sms-template"))
.andExpect(status().isOk());
}

@Test
public void testGetGenderTypesByLangCode() throws Exception {
Mockito.when(proxyMasterdataService.getDynamicFieldBasedOnLangCodeAndFieldName(Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean())).thenReturn(responseWrapper);
mockMvc.perform(MockMvcRequestBuilders.get("/auth-proxy/masterdata/dynamicfields/gender/eng?withValue=true"))
.andExpect(status().isOk());
}


@Test(expected = Exception.class)
public void testGetGenderTypesByLangCodeWithResidentServiceCheckedException() throws Exception {
Mockito.when(proxyMasterdataService.getDynamicFieldBasedOnLangCodeAndFieldName(Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean())).thenThrow(ResidentServiceCheckedException.class);
mockMvc.perform(MockMvcRequestBuilders.get("/auth-proxy/masterdata/dynamicfields/gender/eng?withValue=true"))
.andExpect(status().isOk());
}

@Test
public void testGetDocumentTypesByDocumentCategoryCodeAndLangCode() throws Exception {
Mockito.when(proxyMasterdataService.getDocumentTypesByDocumentCategoryAndLangCode(Mockito.anyString(),Mockito.anyString())).thenReturn(responseWrapper);
mockMvc.perform(MockMvcRequestBuilders.get("/proxy/masterdata/documenttypes/documentcategorycode/langcode"))
.andExpect(status().isOk());
}


@Test(expected = Exception.class)
public void testGetDocumentTypesByDocumentCategoryCodeAndLangCodeWithResidentServiceCheckedException() throws Exception {
Mockito.when(proxyMasterdataService.getDocumentTypesByDocumentCategoryAndLangCode(Mockito.anyString(),Mockito.anyString())).thenThrow(ResidentServiceCheckedException.class);
mockMvc.perform(MockMvcRequestBuilders.get("/proxy/masterdata/documenttypes/documentcategorycode/langcode"))
.andExpect(status().isOk());
}

@Test
public void testGetGenderCodeByGenderTypeAndLangCode() throws Exception {
Mockito.when(proxyMasterdataService.getGenderCodeByGenderTypeAndLangCode(Mockito.anyString(),Mockito.anyString())).thenReturn(responseWrapper);
mockMvc.perform(MockMvcRequestBuilders.get("/proxy/masterdata/gendercode/gendertype/langcode"))
.andExpect(status().isOk());
}

@Test(expected = Exception.class)
public void testGetGenderCodeByGenderTypeAndLangCodeWithResidentServiceCheckedException() throws Exception {
Mockito.when(proxyMasterdataService.getGenderCodeByGenderTypeAndLangCode(Mockito.anyString(),Mockito.anyString())).thenThrow(ResidentServiceCheckedException.class);
mockMvc.perform(MockMvcRequestBuilders.get("/proxy/masterdata/gendercode/gendertype/langcode"))
.andExpect(status().isOk());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import io.mosip.resident.dto.OtpRequestDTOV3;
import io.mosip.resident.exception.ApisResourceAccessException;
import io.mosip.resident.exception.InvalidInputException;
import io.mosip.resident.exception.ResidentServiceCheckedException;
import io.mosip.resident.exception.ResidentServiceException;
import io.mosip.resident.helper.ObjectStoreHelper;
import io.mosip.resident.service.ProxyOtpService;
Expand Down Expand Up @@ -167,6 +168,13 @@ public void testSendOtpExceptionApiResourceException() throws Exception {
proxyOtpController.sendOTP(userOtpRequest);
}

@Test(expected = Exception.class)
public void testSendOtpWithResidentServiceCheckedException() throws Exception {
Mockito.when(proxyOtpService.sendOtp(Mockito.any())).thenThrow(ResidentServiceCheckedException.class);
mockMvc.perform(MockMvcRequestBuilders.post("/contact-details/send-otp").contentType(MediaType.APPLICATION_JSON_VALUE)
.content(reqJson.getBytes())).andExpect(status().isOk());
}

@Test
public void testValidateOtp() throws Exception {
Mockito.when(proxyOtpService.validateWithUserIdOtp(Mockito.any())).thenReturn(Tuples.of(response, "12345"));
Expand Down
Loading

0 comments on commit cb52c2a

Please sign in to comment.