Skip to content

Commit

Permalink
MOSIP-39000 Fixed code as per review comment
Browse files Browse the repository at this point in the history
Signed-off-by: kameshsr <kameshsr1338@gmail.com>
  • Loading branch information
kameshsr committed Jan 23, 2025
1 parent e425401 commit a4c6517
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public enum ApiName {
PACKETSIGNPUBLICKEY,
MACHINESEARCH,
MACHINECREATE,
MACHINEUPDATE,
MACHINESTATUSUPDATE,

PARTNER_API_URL, DECRYPT_API_URL, OTP_GEN_URL, POLICY_REQ_URL,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ private String getMachineId() throws ApisResourceAccessException {

private void activateMachineId(String machineId) throws ApisResourceAccessException {
try {
String baseUrl = env.getProperty(ApiName.MACHINEUPDATE.name());
String baseUrl = env.getProperty(ApiName.MACHINESTATUSUPDATE.name());

String apiUrl = UriComponentsBuilder.fromHttpUrl(baseUrl)
.queryParam("id", machineId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void reqPrintUinTest() throws ResidentServiceCheckedException, ApisResour

Mockito.when(env.getProperty(ApiName.PACKETSIGNPUBLICKEY.name())).thenReturn("PACKETSIGNPUBLICKEY");
Mockito.when(env.getProperty(ApiName.MACHINESEARCH.name())).thenReturn("MACHINESEARCH");
Mockito.when(env.getProperty(ApiName.MACHINEUPDATE.name())).thenReturn("http://localhost");
Mockito.when(env.getProperty(ApiName.MACHINESTATUSUPDATE.name())).thenReturn("http://localhost");

Mockito.when(residentServiceRestClient.postApi(eq("PACKETSIGNPUBLICKEY"), any(MediaType.class),
any(HttpEntity.class), eq(PacketSignPublicKeyResponseDTO.class))).thenReturn(responseDto);
Expand All @@ -155,6 +155,63 @@ public void reqPrintUinTest() throws ResidentServiceCheckedException, ApisResour

}

@Test(expected = ResidentServiceException.class)
public void reqPrintUinTestFailure() throws ResidentServiceCheckedException, ApisResourceAccessException {

RegProcCommonResponseDto reprintResp = new RegProcCommonResponseDto();
reprintResp.setMessage("sent to packet receiver");
reprintResp.setRegistrationId("10008200070004620191203115734");
reprintResp.setStatus("success");
NotificationResponseDTO notificationResponse = new NotificationResponseDTO();
notificationResponse.setMessage("Notification sent to registered contact details");
notificationResponse.setStatus("success");

String publicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuGXPqbFOIZhB_N_fbTXOMIsRgq_LMdL9DJ5kWYAneCj_LPw3OEm2ncLVIRyJsF2DcSQwvzt_Njdvg1Cr54nD1uHBu3Vt9G1sy3p6uwbeK1l5mJSMNe5oGe11fmehtsR2QcB_45_us_IiiiUzzHJrySexmDfdOiPdy-dID4DYRDAf-HXlMIEf4Di_8NV3wVrA3jq1tuNkXX3qKtM4NhZOihp0HmB9E7RHttSV9VJNh00BrC57qdMfa5xqsHok3qftU5SAan4BGuPklN2fzOVcsa-V-B8JbwxRfPdwMkq-jW7Eu1LcNhNVQYJGEWDLAQDGKY_fOB_YwBzn8xvYRjqSfQIDAQAB";
List<MachineDto> machineDtos = new ArrayList<>();
MachineDto machineDto = new MachineDto();
machineDto.setMachineSpecId("1001");
machineDto.setIsActive(false);
machineDto.setId("10147");
machineDto.setName("resident_machine_1640777004542");
machineDto.setValidityDateTime("2024-12-29T11:23:24.541Z");
machineDto.setPublicKey(publicKey);
machineDto.setSignPublicKey(publicKey);
machineDtos.add(machineDto);
MachineSearchResponseDTO.MachineSearchDto response = MachineSearchResponseDTO.MachineSearchDto.builder()
.fromRecord(0).toRecord(0).toRecord(0).data(machineDtos).build();
MachineSearchResponseDTO machineSearchResponseDTO = new MachineSearchResponseDTO();
machineSearchResponseDTO.setId("null");
machineSearchResponseDTO.setVersion("1.0");
machineSearchResponseDTO.setResponsetime("2022-01-28T06:25:23.958Z");
machineSearchResponseDTO.setResponse(response);

PacketSignPublicKeyResponseDTO responseDto = new PacketSignPublicKeyResponseDTO();
PacketSignPublicKeyResponseDTO.PacketSignPublicKeyResponse publicKeyResponse = new PacketSignPublicKeyResponseDTO.PacketSignPublicKeyResponse();
publicKeyResponse.setPublicKey(publicKey);
responseDto.setId(null);
responseDto.setVersion(null);
responseDto.setResponsetime("2022-01-28T06:51:30.286Z");
responseDto.setResponse(publicKeyResponse);
responseDto.setErrors(new ArrayList<>());

Mockito.when(env.getProperty(ApiName.PACKETSIGNPUBLICKEY.name())).thenReturn("PACKETSIGNPUBLICKEY");
Mockito.when(env.getProperty(ApiName.MACHINESEARCH.name())).thenReturn("MACHINESEARCH");
Mockito.when(env.getProperty(ApiName.MACHINESTATUSUPDATE.name())).thenReturn("http://localhost");

Mockito.when(residentServiceRestClient.postApi(eq("PACKETSIGNPUBLICKEY"), any(MediaType.class),
any(HttpEntity.class), eq(PacketSignPublicKeyResponseDTO.class))).thenReturn(responseDto);
Mockito.when(residentServiceRestClient.postApi(eq("MACHINESEARCH"), any(MediaType.class), any(HttpEntity.class),
eq(MachineSearchResponseDTO.class))).thenReturn(machineSearchResponseDTO);
when(residentServiceRestClient.patchApi(any(), any(), any(), any())).thenThrow(new ApisResourceAccessException());

when(utilities.getLanguageCode()).thenReturn("eng");

Mockito.when(notificationService.sendNotification(any(), Mockito.nullable(Map.class))).thenReturn(notificationResponse);
ResidentReprintResponseDto residentResponse = residentServiceImpl.reqPrintUin(residentReqDto);
assertEquals("10008200070004620191203115734", residentResponse.getRegistrationId());

}

@Test(expected = ResidentServiceException.class)
public void validateOtpException()
throws OtpValidationFailedException, IOException, ResidentServiceCheckedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public void setUp() throws BaseCheckedException, IOException {
notificationResponse.setStatus("success");
Mockito.when(notificationService.sendNotification(any(), Mockito.nullable(Map.class))).thenReturn(notificationResponse);

Mockito.when(env.getProperty(ApiName.MACHINEUPDATE.name())).thenReturn("http://localhost");
Mockito.when(env.getProperty(ApiName.MACHINESTATUSUPDATE.name())).thenReturn("http://localhost");
when(residentServiceRestClient.patchApi(any(), any(), any(), any())).thenReturn(new io.mosip.kernel.core.http.ResponseWrapper<>());

String publicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuGXPqbFOIZhB_N_fbTXOMIsRgq_LMdL9DJ5kWYAneCj_LPw3OEm2ncLVIRyJsF2DcSQwvzt_Njdvg1Cr54nD1uHBu3Vt9G1sy3p6uwbeK1l5mJSMNe5oGe11fmehtsR2QcB_45_us_IiiiUzzHJrySexmDfdOiPdy-dID4DYRDAf-HXlMIEf4Di_8NV3wVrA3jq1tuNkXX3qKtM4NhZOihp0HmB9E7RHttSV9VJNh00BrC57qdMfa5xqsHok3qftU5SAan4BGuPklN2fzOVcsa-V-B8JbwxRfPdwMkq-jW7Eu1LcNhNVQYJGEWDLAQDGKY_fOB_YwBzn8xvYRjqSfQIDAQAB";
Expand Down

0 comments on commit a4c6517

Please sign in to comment.