From 36f23d1f7578642186bf6356f97bcaf0ce308d06 Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Thu, 30 Nov 2023 16:21:35 +0530 Subject: [PATCH 01/12] [mosip 30470] uin genration Invalid input parameter Exception handeled Signed-off-by: khuddus shariff --- .../uigenerator/UinGeneratorStageTest.java | 72 +++++++++++++++++-- .../core/status/util/StatusUtil.java | 2 +- .../PriorityBasedPacketManagerService.java | 1 - 3 files changed, 69 insertions(+), 6 deletions(-) diff --git a/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java b/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java index 6e1d922d00e..97ffdc25eb2 100644 --- a/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java +++ b/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java @@ -6,6 +6,7 @@ import static org.mockito.ArgumentMatchers.anyDouble; import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.io.ByteArrayInputStream; @@ -25,6 +26,7 @@ import java.util.List; import java.util.Map; +import io.mosip.registration.processor.core.status.util.StatusUtil; import org.apache.commons.io.IOUtils; import org.assertj.core.util.Lists; import org.json.JSONException; @@ -33,14 +35,12 @@ import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; +import org.mockito.*; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.beans.factory.annotation.Value; import org.springframework.core.env.Environment; import org.springframework.http.HttpStatus; import org.springframework.test.util.ReflectionTestUtils; @@ -229,6 +229,9 @@ public void consumeAndSend(MosipEventBus mosipEventBus, MessageBusAddress fromAd @Mock private IdSchemaUtil idSchemaUtil; + @Value("${mosip.regproc.max.retrycount}") + Integer maxRetrycount=3; + @Before public void setup() throws Exception { ReflectionTestUtils.setField(uinGeneratorStage, "workerPoolSize", 10); @@ -429,6 +432,67 @@ public void testUinGenerationResponseNull() throws Exception { MessageDTO result = uinGeneratorStage.process(messageDTO); //assertFalse(result.getInternalError()); } + + @Test + public void testUinGenerationResponseWithInvalidInputParameterException() throws Exception { + ReflectionTestUtils.setField(uinGeneratorStage, "maxRetrycount", maxRetrycount); + MessageDTO messageDTO = new MessageDTO(); + messageDTO.setRid("27847657360002520181210094052"); + messageDTO.setReg_type(RegistrationType.NEW); + String str = "{\n" + + " \"id\": \"mosip.id.read\",\n" + + " \"version\": \"1.0\",\n" + + " \"responsetime\": \"2019-04-05\",\n" + + " \"metadata\": null,\n" + + " \"response\": {},\n" + + " \"errors\": [\n" + + " {\n" + + " \"errorCode\": \"IDR-IDC-002\",\n" + + " \"errorMessage\": \"Invalid Input Parameter\"\n" + + " }\n" + + " ]\n" + + "}"; + String response = "{\n" + + " \"id\": \"mosip.id.read\",\n" + + " \"version\": \"1.0\",\n" + + " \"responsetime\": \"2019-04-05\",\n" + + " \"metadata\": null,\n" + + " \"response\": {},\n" + + " \"errors\": [\n" + + " {\n" + + " \"errorCode\": \"IDR-IDC-002\",\n" + + " \"errorMessage\": \"Invalid Input Parameter\"\n" + + " }\n" + + " ]\n" + + "}"; + when(registrationProcessorRestClientService.getApi(any(), any(), anyString(), any(), any())).thenReturn(str); + when(registrationProcessorRestClientService.putApi(any(), any(), any(), any(), any(), any(), any())) + .thenReturn(response); + + IdResponseDTO idResponseDTO = new IdResponseDTO(); + ResponseDTO responseDTO = new ResponseDTO(); + + ResponseWrapper responseVid = new ResponseWrapper(); + List errors = new ArrayList<>(); + ErrorDTO errorDTO=new ErrorDTO("IDR-IDC-002", StatusUtil.INVALID_INPUT_PARAMETER.getMessage()); + errors.add(errorDTO); + idResponseDTO.setErrors(errors); + idResponseDTO.setVersion("v12"); + idResponseDTO.setMetadata(null); + DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); + LocalDateTime localdatetime = LocalDateTime + .parse(DateUtils.getUTCCurrentDateTimeString("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"), format); + responseVid.setResponsetime(localdatetime); + + when(registrationProcessorRestClientService.postApi(any(), any(), any(), any(), any(Class.class))) + .thenReturn(idResponseDTO); +// when(registrationProcessorRestClientService.postApi(ApiName.IDREPOSITORY, any(), any(), any(), any(Class.class))) + + // Mockito.when(registrationProcessorRestClientService.postApi(any(), any(), + // any(), any(), any(Class.class))); + MessageDTO result = uinGeneratorStage.process(messageDTO); + //assertFalse(result.getInternalError()); + } @Test public void testUinGenerationF() throws Exception { MessageDTO messageDTO = new MessageDTO(); diff --git a/registration-processor/registration-processor-core/src/main/java/io/mosip/registration/processor/core/status/util/StatusUtil.java b/registration-processor/registration-processor-core/src/main/java/io/mosip/registration/processor/core/status/util/StatusUtil.java index ed6264d560c..60989c91107 100644 --- a/registration-processor/registration-processor-core/src/main/java/io/mosip/registration/processor/core/status/util/StatusUtil.java +++ b/registration-processor/registration-processor-core/src/main/java/io/mosip/registration/processor/core/status/util/StatusUtil.java @@ -152,7 +152,7 @@ public enum StatusUtil { LINK_RID_FOR_LOST_PACKET_FAILED(StatusConstants.UIN_GENERATOR_MODULE_FAILED + "008","UIn not found the the matched RID"), UIN_ALREADY_EXIST_IN_IDREPO(StatusConstants.UIN_GENERATOR_MODULE_FAILED + "009", "Received ID record already exists error from idrepo even after trying with force merge"), OLD_APPLICATION_ID(StatusConstants.UIN_GENERATOR_MODULE_FAILED + "010","Received error as old application ID reprocessing not allowed from idrepo"), - + INVALID_INPUT_PARAMETER(StatusConstants.UIN_GENERATOR_MODULE_FAILED+"011","Recived error as Invalid_Input_Parameter"), //Request handler service //1)Resident UIN update RESIDENT_UPDATE_SUCCES(StatusConstants.REQUEST_HANDLER_MODULE_SUCCESS + "001" , "Resident Uin data updated sucessfully"), diff --git a/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/utils/PriorityBasedPacketManagerService.java b/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/utils/PriorityBasedPacketManagerService.java index b26996afb67..90ccf50aac6 100644 --- a/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/utils/PriorityBasedPacketManagerService.java +++ b/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/utils/PriorityBasedPacketManagerService.java @@ -65,7 +65,6 @@ public String getFieldByMappingJsonKey(String id, String key, String process, Pr String field = JsonUtil.getJSONValue( JsonUtil.getJSONObject(regProcessorIdentityJson, key), MappingJsonConstants.VALUE); - return getField(id, field, process, stageName); } From afd041cb061b025867cba01cf495db3516f8601a Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Thu, 30 Nov 2023 16:26:48 +0530 Subject: [PATCH 02/12] [mosip 30470] uin genration Invalid input parameter Exception handeled Signed-off-by: khuddus shariff --- .../uingenerator/stage/UinGeneratorStage.java | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/registration-processor/core-processor/registration-processor-uin-generator-stage/src/main/java/io/mosip/registration/processor/stages/uingenerator/stage/UinGeneratorStage.java b/registration-processor/core-processor/registration-processor-uin-generator-stage/src/main/java/io/mosip/registration/processor/stages/uingenerator/stage/UinGeneratorStage.java index 34ed8edbb17..483dcd892c5 100644 --- a/registration-processor/core-processor/registration-processor-uin-generator-stage/src/main/java/io/mosip/registration/processor/stages/uingenerator/stage/UinGeneratorStage.java +++ b/registration-processor/core-processor/registration-processor-uin-generator-stage/src/main/java/io/mosip/registration/processor/stages/uingenerator/stage/UinGeneratorStage.java @@ -113,6 +113,8 @@ public class UinGeneratorStage extends MosipVerticleAPIManager { private static final String OLD_APPLICATION_ID = "IDR-IDC-011"; private static final String RECORD_ALREADY_EXISTS_ERROR = "IDR-IDC-012"; + private static final String INVALID_INPUT_PARAMETER="IDR-IDC-002"; + @Autowired private Environment env; @@ -159,6 +161,9 @@ public class UinGeneratorStage extends MosipVerticleAPIManager { @Value("${mosip.regproc.uin.generator.dob.log.enable:false}") private boolean dobLogEnable; + @Value("${mosip.regproc.max.retrycount}") + Integer maxRetrycount; + /** The core audit request builder. */ @Autowired private AuditLogRequestBuilder auditLogRequestBuilder; @@ -238,9 +243,7 @@ public MessageDTO process(MessageDTO object) { if (matchedRegId != null) { linkRegIdWrtUin(lostPacketRegId, matchedRegId, registrationStatusDto.getRegistrationType(), object, description); } - } else { - IdResponseDTO idResponseDTO = new IdResponseDTO(); String schemaVersion = packetManagerService.getFieldByMappingJsonKey(registrationId, MappingJsonConstants.IDSCHEMA_VERSION, registrationStatusDto.getRegistrationType(), ProviderStageName.UIN_GENERATOR); @@ -292,7 +295,6 @@ public MessageDTO process(MessageDTO object) { }else { handleIdRepoSuccessResponse(registrationStatusDto, registrationId, isUinAlreadyPresent, isTransactionSuccessful, uinResponseDto, object, description); } - }else { handleIdRepoErrorResponse(idResponseDTO, registrationStatusDto, registrationId, isTransactionSuccessful, uinResponseDto, object, description); } @@ -312,13 +314,12 @@ public MessageDTO process(MessageDTO object) { description); } } - } regProcLogger.info(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(), registrationId, description.getMessage()); registrationStatusDto.setUpdatedBy(UINConstants.USER); - - } catch (io.mosip.kernel.core.util.exception.JsonProcessingException e) { + } + catch (io.mosip.kernel.core.util.exception.JsonProcessingException e) { regProcLogger.error(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(), registrationId, RegistrationStatusCode.FAILED.toString() + e.getMessage() + ExceptionUtils.getStackTrace(e)); @@ -567,9 +568,9 @@ private void handleIdRepoErrorResponse(IdResponseDTO idResponseDTO, InternalRegi String registrationId,boolean isTransactionSuccessful, UinGenResponseDto uinResponseDto,MessageDTO object, LogDescription description) throws ApisResourceAccessException, IOException{ List errors = idResponseDTO != null ? idResponseDTO.getErrors() : null; - + int retrycount = (registrationStatusDto.getRetryCount() == null) ? 0 : registrationStatusDto.getRetryCount(); String statusComment = errors != null ? errors.get(0).getMessage() : UINConstants.NULL_IDREPO_RESPONSE; - + if(errors!=null && errors.get(0).getErrorCode().equalsIgnoreCase(RECORD_ALREADY_EXISTS_ERROR)) { registrationStatusDto.setStatusCode(RegistrationTransactionStatusCode.ERROR.toString()); registrationStatusDto.setLatestTransactionStatusCode( @@ -585,8 +586,16 @@ private void handleIdRepoErrorResponse(IdResponseDTO idResponseDTO, InternalRegi .setLatestTransactionStatusCode(RegistrationTransactionStatusCode.FAILED.toString()); registrationStatusDto.setSubStatusCode(StatusUtil.OLD_APPLICATION_ID.getCode()); description.setTransactionStatusCode(RegistrationTransactionStatusCode.FAILED.toString()); - - }else { + + } else if (errors!=null && errors.get(0).getErrorCode().equalsIgnoreCase(INVALID_INPUT_PARAMETER ) && retrycount Date: Thu, 30 Nov 2023 16:30:41 +0530 Subject: [PATCH 03/12] [mosip 30470] uin genration Invalid input parameter Exception handeled Signed-off-by: khuddus shariff --- .../packet/storage/utils/PriorityBasedPacketManagerService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/utils/PriorityBasedPacketManagerService.java b/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/utils/PriorityBasedPacketManagerService.java index 90ccf50aac6..b26996afb67 100644 --- a/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/utils/PriorityBasedPacketManagerService.java +++ b/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/utils/PriorityBasedPacketManagerService.java @@ -65,6 +65,7 @@ public String getFieldByMappingJsonKey(String id, String key, String process, Pr String field = JsonUtil.getJSONValue( JsonUtil.getJSONObject(regProcessorIdentityJson, key), MappingJsonConstants.VALUE); + return getField(id, field, process, stageName); } From 0e8a02efdfd4f6775600d1d24bdcb76610aa464a Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Thu, 30 Nov 2023 16:44:14 +0530 Subject: [PATCH 04/12] [mosip 30470] uin genration Invalid input parameter Exception handeled Signed-off-by: khuddus shariff --- .../processor/stages/uingenerator/stage/UinGeneratorStage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/registration-processor/core-processor/registration-processor-uin-generator-stage/src/main/java/io/mosip/registration/processor/stages/uingenerator/stage/UinGeneratorStage.java b/registration-processor/core-processor/registration-processor-uin-generator-stage/src/main/java/io/mosip/registration/processor/stages/uingenerator/stage/UinGeneratorStage.java index 483dcd892c5..71db70403e3 100644 --- a/registration-processor/core-processor/registration-processor-uin-generator-stage/src/main/java/io/mosip/registration/processor/stages/uingenerator/stage/UinGeneratorStage.java +++ b/registration-processor/core-processor/registration-processor-uin-generator-stage/src/main/java/io/mosip/registration/processor/stages/uingenerator/stage/UinGeneratorStage.java @@ -161,7 +161,7 @@ public class UinGeneratorStage extends MosipVerticleAPIManager { @Value("${mosip.regproc.uin.generator.dob.log.enable:false}") private boolean dobLogEnable; - @Value("${mosip.regproc.max.retrycount}") + @Value("${registration.processor.max.retrycount}") Integer maxRetrycount; /** The core audit request builder. */ From 9b9b1bbd2586ea960809d4d866c96597c37b45f6 Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Thu, 30 Nov 2023 18:24:10 +0530 Subject: [PATCH 05/12] [mosip 30470] uin genration Invalid input parameter Exception handeled Signed-off-by: khuddus shariff --- .../uingenerator/stage/UinGeneratorStage.java | 2 +- .../uigenerator/UinGeneratorStageTest.java | 65 +++++++++++++++++-- .../core/status/util/StatusUtil.java | 2 +- 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/registration-processor/core-processor/registration-processor-uin-generator-stage/src/main/java/io/mosip/registration/processor/stages/uingenerator/stage/UinGeneratorStage.java b/registration-processor/core-processor/registration-processor-uin-generator-stage/src/main/java/io/mosip/registration/processor/stages/uingenerator/stage/UinGeneratorStage.java index 71db70403e3..ba85aeb18d7 100644 --- a/registration-processor/core-processor/registration-processor-uin-generator-stage/src/main/java/io/mosip/registration/processor/stages/uingenerator/stage/UinGeneratorStage.java +++ b/registration-processor/core-processor/registration-processor-uin-generator-stage/src/main/java/io/mosip/registration/processor/stages/uingenerator/stage/UinGeneratorStage.java @@ -161,7 +161,7 @@ public class UinGeneratorStage extends MosipVerticleAPIManager { @Value("${mosip.regproc.uin.generator.dob.log.enable:false}") private boolean dobLogEnable; - @Value("${registration.processor.max.retrycount}") + @Value("${mosip.regproc.uin.generator.max.retrycount}") Integer maxRetrycount; /** The core audit request builder. */ diff --git a/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java b/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java index 97ffdc25eb2..a8077354682 100644 --- a/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java +++ b/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java @@ -229,14 +229,13 @@ public void consumeAndSend(MosipEventBus mosipEventBus, MessageBusAddress fromAd @Mock private IdSchemaUtil idSchemaUtil; - @Value("${mosip.regproc.max.retrycount}") - Integer maxRetrycount=3; @Before public void setup() throws Exception { ReflectionTestUtils.setField(uinGeneratorStage, "workerPoolSize", 10); ReflectionTestUtils.setField(uinGeneratorStage, "messageExpiryTimeLimit", Long.valueOf(0)); ReflectionTestUtils.setField(uinGeneratorStage, "clusterManagerUrl", "/dummyPath"); + ReflectionTestUtils.setField(uinGeneratorStage, "maxRetrycount", 3); ClassLoader classLoader1 = getClass().getClassLoader(); File idJsonFile1 = new File(classLoader1.getResource("RegistrationProcessorIdentity.json").getFile()); @@ -435,7 +434,6 @@ public void testUinGenerationResponseNull() throws Exception { @Test public void testUinGenerationResponseWithInvalidInputParameterException() throws Exception { - ReflectionTestUtils.setField(uinGeneratorStage, "maxRetrycount", maxRetrycount); MessageDTO messageDTO = new MessageDTO(); messageDTO.setRid("27847657360002520181210094052"); messageDTO.setReg_type(RegistrationType.NEW); @@ -491,7 +489,7 @@ public void testUinGenerationResponseWithInvalidInputParameterException() throws // Mockito.when(registrationProcessorRestClientService.postApi(any(), any(), // any(), any(), any(Class.class))); MessageDTO result = uinGeneratorStage.process(messageDTO); - //assertFalse(result.getInternalError()); + assertTrue(result.getInternalError()); } @Test public void testUinGenerationF() throws Exception { @@ -538,6 +536,65 @@ public void testUinGenerationF() throws Exception { } + @Test + public void testUinGenerationResponseWithExcededRetryCount() throws Exception { + MessageDTO messageDTO = new MessageDTO(); + messageDTO.setRid("27847657360002520181210094052"); + messageDTO.setReg_type(RegistrationType.NEW); + String str = "{\n" + + " \"id\": \"mosip.id.read\",\n" + + " \"version\": \"1.0\",\n" + + " \"responsetime\": \"2019-04-05\",\n" + + " \"metadata\": null,\n" + + " \"response\": {},\n" + + " \"errors\": [\n" + + " {\n" + + " \"errorCode\": \"IDR-IDC-002\",\n" + + " \"errorMessage\": \"Invalid Input Parameter\"\n" + + " }\n" + + " ]\n" + + "}"; + String response = "{\n" + + " \"id\": \"mosip.id.read\",\n" + + " \"version\": \"1.0\",\n" + + " \"responsetime\": \"2019-04-05\",\n" + + " \"metadata\": null,\n" + + " \"response\": {},\n" + + " \"errors\": [\n" + + " {\n" + + " \"errorCode\": \"IDR-IDC-002\",\n" + + " \"errorMessage\": \"Invalid Input Parameter\"\n" + + " }\n" + + " ]\n" + + "}"; + when(registrationProcessorRestClientService.getApi(any(), any(), anyString(), any(), any())).thenReturn(str); + when(registrationProcessorRestClientService.putApi(any(), any(), any(), any(), any(), any(), any())) + .thenReturn(response); + + IdResponseDTO idResponseDTO = new IdResponseDTO(); + ResponseDTO responseDTO = new ResponseDTO(); + + ResponseWrapper responseVid = new ResponseWrapper(); + List errors = new ArrayList<>(); + ErrorDTO errorDTO=new ErrorDTO("IDR-IDC-002", StatusUtil.INVALID_INPUT_PARAMETER.getMessage()); + errors.add(errorDTO); + idResponseDTO.setErrors(errors); + idResponseDTO.setVersion("v12"); + idResponseDTO.setMetadata(null); + DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); + LocalDateTime localdatetime = LocalDateTime + .parse(DateUtils.getUTCCurrentDateTimeString("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"), format); + responseVid.setResponsetime(localdatetime); + + when(registrationProcessorRestClientService.postApi(any(), any(), any(), any(), any(Class.class))) + .thenReturn(idResponseDTO); + registrationStatusDto.setRetryCount(4); + + when(registrationStatusService.getRegistrationStatus(any())).thenReturn(registrationStatusDto); + MessageDTO result = uinGeneratorStage.process(messageDTO); + assertTrue(result.getInternalError()); + } + @Test public void testUinGenerationSuccessWithoutUINAndUinUnused() throws Exception { MessageDTO messageDTO = new MessageDTO(); diff --git a/registration-processor/registration-processor-core/src/main/java/io/mosip/registration/processor/core/status/util/StatusUtil.java b/registration-processor/registration-processor-core/src/main/java/io/mosip/registration/processor/core/status/util/StatusUtil.java index 60989c91107..13cbe9b7c45 100644 --- a/registration-processor/registration-processor-core/src/main/java/io/mosip/registration/processor/core/status/util/StatusUtil.java +++ b/registration-processor/registration-processor-core/src/main/java/io/mosip/registration/processor/core/status/util/StatusUtil.java @@ -152,7 +152,7 @@ public enum StatusUtil { LINK_RID_FOR_LOST_PACKET_FAILED(StatusConstants.UIN_GENERATOR_MODULE_FAILED + "008","UIn not found the the matched RID"), UIN_ALREADY_EXIST_IN_IDREPO(StatusConstants.UIN_GENERATOR_MODULE_FAILED + "009", "Received ID record already exists error from idrepo even after trying with force merge"), OLD_APPLICATION_ID(StatusConstants.UIN_GENERATOR_MODULE_FAILED + "010","Received error as old application ID reprocessing not allowed from idrepo"), - INVALID_INPUT_PARAMETER(StatusConstants.UIN_GENERATOR_MODULE_FAILED+"011","Recived error as Invalid_Input_Parameter"), + INVALID_INPUT_PARAMETER(StatusConstants.UIN_GENERATOR_MODULE_FAILED+"011","Received error as Invalid Input Parameter"), //Request handler service //1)Resident UIN update RESIDENT_UPDATE_SUCCES(StatusConstants.REQUEST_HANDLER_MODULE_SUCCESS + "001" , "Resident Uin data updated sucessfully"), From 31046e9d2ea8a0d61c2747a899aa513f38c55f11 Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Mon, 4 Dec 2023 13:58:35 +0530 Subject: [PATCH 06/12] [mosip 30470] uin genration Invalid input parameter Exception handeled Signed-off-by: khuddus shariff --- .../uingenerator/stage/UinGeneratorStage.java | 26 +++--- .../uigenerator/UinGeneratorStageTest.java | 83 ++++++++++++++++++- 2 files changed, 94 insertions(+), 15 deletions(-) diff --git a/registration-processor/core-processor/registration-processor-uin-generator-stage/src/main/java/io/mosip/registration/processor/stages/uingenerator/stage/UinGeneratorStage.java b/registration-processor/core-processor/registration-processor-uin-generator-stage/src/main/java/io/mosip/registration/processor/stages/uingenerator/stage/UinGeneratorStage.java index ba85aeb18d7..d980b698fa2 100644 --- a/registration-processor/core-processor/registration-processor-uin-generator-stage/src/main/java/io/mosip/registration/processor/stages/uingenerator/stage/UinGeneratorStage.java +++ b/registration-processor/core-processor/registration-processor-uin-generator-stage/src/main/java/io/mosip/registration/processor/stages/uingenerator/stage/UinGeneratorStage.java @@ -113,7 +113,7 @@ public class UinGeneratorStage extends MosipVerticleAPIManager { private static final String OLD_APPLICATION_ID = "IDR-IDC-011"; private static final String RECORD_ALREADY_EXISTS_ERROR = "IDR-IDC-012"; - private static final String INVALID_INPUT_PARAMETER="IDR-IDC-002"; + private static final String INVALID_INPUT_PARAMETER_ERROR_CODE="IDR-IDC-002"; @Autowired @@ -161,7 +161,7 @@ public class UinGeneratorStage extends MosipVerticleAPIManager { @Value("${mosip.regproc.uin.generator.dob.log.enable:false}") private boolean dobLogEnable; - @Value("${mosip.regproc.uin.generator.max.retrycount}") + @Value("${mosip.regproc.uin.generator.idrepo-max-retry-count}") Integer maxRetrycount; /** The core audit request builder. */ @@ -250,7 +250,7 @@ public MessageDTO process(MessageDTO object) { Map fieldMap = packetManagerService.getFields(registrationId, idSchemaUtil.getDefaultFields(Double.valueOf(schemaVersion)), registrationStatusDto.getRegistrationType(), ProviderStageName.UIN_GENERATOR); String uinField = fieldMap.get(utility.getMappingJsonValue(MappingJsonConstants.UIN, MappingJsonConstants.IDENTITY)); - + registrationStatusDto.setRetryCount((registrationStatusDto.getRetryCount() == null) ? 0 : registrationStatusDto.getRetryCount()); String dateOfBirth = fieldMap .get(utility.getMappingJsonValue(MappingJsonConstants.DOB, MappingJsonConstants.IDENTITY)); if ((dateOfBirth != null && !dateOfBirth.isEmpty()) && dobLogEnable) { @@ -271,19 +271,25 @@ public MessageDTO process(MessageDTO object) { String test = (String) registrationProcessorRestClientService.getApi(ApiName.UINGENERATOR, null, "", "", String.class); - regProcLogger.info(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(), registrationId, "Received response from UINGENERATOR API"); - Gson gsonObj = new Gson(); uinResponseDto = gsonObj.fromJson(test, UinGenResponseDto.class); - uinField = uinResponseDto.getResponse().getUin(); demographicIdentity.put("UIN", uinField); - idResponseDTO = sendIdRepoWithUin(registrationId, registrationStatusDto.getRegistrationType(), demographicIdentity, uinField, description); + if(idResponseDTO.getErrors()!=null && idResponseDTO.getErrors().get(0).getErrorCode().equalsIgnoreCase(INVALID_INPUT_PARAMETER_ERROR_CODE)) { + for (int i = registrationStatusDto.getRetryCount(); i < maxRetrycount; i++) { + + idResponseDTO = sendIdRepoWithUin(registrationId, registrationStatusDto.getRegistrationType(), demographicIdentity, + uinField, description); + if (idResponseDTO.getErrors()==null || idResponseDTO.getErrors().get(0).getErrorCode()!=INVALID_INPUT_PARAMETER_ERROR_CODE) + break; + registrationStatusDto.setRetryCount(registrationStatusDto.getRetryCount() + 1); + } + } boolean isUinAlreadyPresent = isUinAlreadyPresent(idResponseDTO, registrationId); if (isIdResponseNotNull(idResponseDTO) || isUinAlreadyPresent) { @@ -568,9 +574,7 @@ private void handleIdRepoErrorResponse(IdResponseDTO idResponseDTO, InternalRegi String registrationId,boolean isTransactionSuccessful, UinGenResponseDto uinResponseDto,MessageDTO object, LogDescription description) throws ApisResourceAccessException, IOException{ List errors = idResponseDTO != null ? idResponseDTO.getErrors() : null; - int retrycount = (registrationStatusDto.getRetryCount() == null) ? 0 : registrationStatusDto.getRetryCount(); String statusComment = errors != null ? errors.get(0).getMessage() : UINConstants.NULL_IDREPO_RESPONSE; - if(errors!=null && errors.get(0).getErrorCode().equalsIgnoreCase(RECORD_ALREADY_EXISTS_ERROR)) { registrationStatusDto.setStatusCode(RegistrationTransactionStatusCode.ERROR.toString()); registrationStatusDto.setLatestTransactionStatusCode( @@ -578,7 +582,6 @@ private void handleIdRepoErrorResponse(IdResponseDTO idResponseDTO, InternalRegi registrationStatusDto.setStatusComment(StatusUtil.UIN_ALREADY_EXIST_IN_IDREPO.getMessage()); registrationStatusDto.setSubStatusCode(StatusUtil.UIN_ALREADY_EXIST_IN_IDREPO.getCode()); description.setTransactionStatusCode(RegistrationTransactionStatusCode.IN_PROGRESS.toString()); - }else if(errors!=null && errors.get(0).getErrorCode().equalsIgnoreCase(OLD_APPLICATION_ID)) { registrationStatusDto.setStatusComment(StatusUtil.OLD_APPLICATION_ID.getMessage()); registrationStatusDto.setStatusCode(RegistrationTransactionStatusCode.FAILED.toString()); @@ -587,8 +590,7 @@ private void handleIdRepoErrorResponse(IdResponseDTO idResponseDTO, InternalRegi registrationStatusDto.setSubStatusCode(StatusUtil.OLD_APPLICATION_ID.getCode()); description.setTransactionStatusCode(RegistrationTransactionStatusCode.FAILED.toString()); - } else if (errors!=null && errors.get(0).getErrorCode().equalsIgnoreCase(INVALID_INPUT_PARAMETER ) && retrycount responseVid = new ResponseWrapper(); + List errors = new ArrayList<>(); + ErrorDTO errorDTO=new ErrorDTO("IDR-IDC-002", StatusUtil.INVALID_INPUT_PARAMETER.getMessage()); + errors.add(errorDTO); + idResponseDTO.setErrors(errors); + idResponseDTO.setVersion("v12"); + idResponseDTO.setMetadata(null); + DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); + LocalDateTime localdatetime = LocalDateTime + .parse(DateUtils.getUTCCurrentDateTimeString("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"), format); + responseVid.setResponsetime(localdatetime); + + when(registrationProcessorRestClientService.postApi(any(), any(), any(), any(), any(Class.class))) + .thenReturn(idResponseDTO) + .thenReturn(idResponseDTO) + .thenReturn(idResponseDTO) .thenReturn(idResponseDTO); -// when(registrationProcessorRestClientService.postApi(ApiName.IDREPOSITORY, any(), any(), any(), any(Class.class))) - // Mockito.when(registrationProcessorRestClientService.postApi(any(), any(), - // any(), any(), any(Class.class))); + when(registrationStatusService.getRegistrationStatus(any())).thenReturn(registrationStatusDto); MessageDTO result = uinGeneratorStage.process(messageDTO); assertTrue(result.getInternalError()); } From 0af305ad3f3d266d02a5edfe59f30fa0182514d0 Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Tue, 5 Dec 2023 13:42:26 +0530 Subject: [PATCH 07/12] [mosip 30470] uin genration Invalid input parameter Exception handeled Signed-off-by: khuddus shariff --- .../stages/uingenerator/stage/UinGeneratorStage.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/registration-processor/core-processor/registration-processor-uin-generator-stage/src/main/java/io/mosip/registration/processor/stages/uingenerator/stage/UinGeneratorStage.java b/registration-processor/core-processor/registration-processor-uin-generator-stage/src/main/java/io/mosip/registration/processor/stages/uingenerator/stage/UinGeneratorStage.java index d980b698fa2..0432cfea673 100644 --- a/registration-processor/core-processor/registration-processor-uin-generator-stage/src/main/java/io/mosip/registration/processor/stages/uingenerator/stage/UinGeneratorStage.java +++ b/registration-processor/core-processor/registration-processor-uin-generator-stage/src/main/java/io/mosip/registration/processor/stages/uingenerator/stage/UinGeneratorStage.java @@ -250,7 +250,7 @@ public MessageDTO process(MessageDTO object) { Map fieldMap = packetManagerService.getFields(registrationId, idSchemaUtil.getDefaultFields(Double.valueOf(schemaVersion)), registrationStatusDto.getRegistrationType(), ProviderStageName.UIN_GENERATOR); String uinField = fieldMap.get(utility.getMappingJsonValue(MappingJsonConstants.UIN, MappingJsonConstants.IDENTITY)); - registrationStatusDto.setRetryCount((registrationStatusDto.getRetryCount() == null) ? 0 : registrationStatusDto.getRetryCount()); + int retrycount=(registrationStatusDto.getRetryCount() == null) ? 0 : registrationStatusDto.getRetryCount(); String dateOfBirth = fieldMap .get(utility.getMappingJsonValue(MappingJsonConstants.DOB, MappingJsonConstants.IDENTITY)); if ((dateOfBirth != null && !dateOfBirth.isEmpty()) && dobLogEnable) { @@ -280,14 +280,13 @@ public MessageDTO process(MessageDTO object) { idResponseDTO = sendIdRepoWithUin(registrationId, registrationStatusDto.getRegistrationType(), demographicIdentity, uinField, description); if(idResponseDTO.getErrors()!=null && idResponseDTO.getErrors().get(0).getErrorCode().equalsIgnoreCase(INVALID_INPUT_PARAMETER_ERROR_CODE)) { - - for (int i = registrationStatusDto.getRetryCount(); i < maxRetrycount; i++) { + for (int i = retrycount; i < maxRetrycount; i++) { idResponseDTO = sendIdRepoWithUin(registrationId, registrationStatusDto.getRegistrationType(), demographicIdentity, uinField, description); if (idResponseDTO.getErrors()==null || idResponseDTO.getErrors().get(0).getErrorCode()!=INVALID_INPUT_PARAMETER_ERROR_CODE) break; - registrationStatusDto.setRetryCount(registrationStatusDto.getRetryCount() + 1); + retrycount++; } } boolean isUinAlreadyPresent = isUinAlreadyPresent(idResponseDTO, registrationId); From ca8d780c059692fc67271e8267e983d1515afaaf Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Tue, 5 Dec 2023 15:41:25 +0530 Subject: [PATCH 08/12] [mosip 30470] uin genration Invalid input parameter Exception handeled Signed-off-by: khuddus shariff --- .../stages/uingenerator/stage/UinGeneratorStage.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/registration-processor/core-processor/registration-processor-uin-generator-stage/src/main/java/io/mosip/registration/processor/stages/uingenerator/stage/UinGeneratorStage.java b/registration-processor/core-processor/registration-processor-uin-generator-stage/src/main/java/io/mosip/registration/processor/stages/uingenerator/stage/UinGeneratorStage.java index 0432cfea673..dbd6b9ab607 100644 --- a/registration-processor/core-processor/registration-processor-uin-generator-stage/src/main/java/io/mosip/registration/processor/stages/uingenerator/stage/UinGeneratorStage.java +++ b/registration-processor/core-processor/registration-processor-uin-generator-stage/src/main/java/io/mosip/registration/processor/stages/uingenerator/stage/UinGeneratorStage.java @@ -250,7 +250,6 @@ public MessageDTO process(MessageDTO object) { Map fieldMap = packetManagerService.getFields(registrationId, idSchemaUtil.getDefaultFields(Double.valueOf(schemaVersion)), registrationStatusDto.getRegistrationType(), ProviderStageName.UIN_GENERATOR); String uinField = fieldMap.get(utility.getMappingJsonValue(MappingJsonConstants.UIN, MappingJsonConstants.IDENTITY)); - int retrycount=(registrationStatusDto.getRetryCount() == null) ? 0 : registrationStatusDto.getRetryCount(); String dateOfBirth = fieldMap .get(utility.getMappingJsonValue(MappingJsonConstants.DOB, MappingJsonConstants.IDENTITY)); if ((dateOfBirth != null && !dateOfBirth.isEmpty()) && dobLogEnable) { @@ -280,13 +279,12 @@ public MessageDTO process(MessageDTO object) { idResponseDTO = sendIdRepoWithUin(registrationId, registrationStatusDto.getRegistrationType(), demographicIdentity, uinField, description); if(idResponseDTO.getErrors()!=null && idResponseDTO.getErrors().get(0).getErrorCode().equalsIgnoreCase(INVALID_INPUT_PARAMETER_ERROR_CODE)) { - for (int i = retrycount; i < maxRetrycount; i++) { - + for (int i = 0; i < maxRetrycount; i++) { idResponseDTO = sendIdRepoWithUin(registrationId, registrationStatusDto.getRegistrationType(), demographicIdentity, uinField, description); if (idResponseDTO.getErrors()==null || idResponseDTO.getErrors().get(0).getErrorCode()!=INVALID_INPUT_PARAMETER_ERROR_CODE) break; - retrycount++; + } } boolean isUinAlreadyPresent = isUinAlreadyPresent(idResponseDTO, registrationId); From 38095059d2dda00279a779ca5dff71f440e64b84 Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Wed, 6 Dec 2023 13:08:01 +0530 Subject: [PATCH 09/12] [mosip 30470] uin genration Invalid input parameter Exception handeled Signed-off-by: khuddus shariff --- .../uigenerator/UinGeneratorStageTest.java | 397 +++++++++--------- 1 file changed, 200 insertions(+), 197 deletions(-) diff --git a/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java b/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java index 880010e7c20..b14dfbddf8f 100644 --- a/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java +++ b/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java @@ -6,8 +6,7 @@ import static org.mockito.ArgumentMatchers.anyDouble; import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import java.io.ByteArrayInputStream; import java.io.File; @@ -230,6 +229,7 @@ public void consumeAndSend(MosipEventBus mosipEventBus, MessageBusAddress fromAd private IdSchemaUtil idSchemaUtil; + @Before public void setup() throws Exception { ReflectionTestUtils.setField(uinGeneratorStage, "workerPoolSize", 10); @@ -392,7 +392,6 @@ public void testUinGenerationSuccessWithoutUIN() throws Exception { MessageDTO result = uinGeneratorStage.process(messageDTO); assertFalse(result.getInternalError()); - } @Test @@ -432,142 +431,6 @@ public void testUinGenerationResponseNull() throws Exception { //assertFalse(result.getInternalError()); } - /** - * In this method Invalid input parameter is thrown 2 time. then 3rd time will get the positive response. - * - */ - @Test - public void testUinGenerationResponseWithInvalidInputParameterException() throws Exception { - MessageDTO messageDTO = new MessageDTO(); - messageDTO.setRid("27847657360002520181210094052"); - messageDTO.setReg_type(RegistrationType.NEW); - String str = "{\n" + - " \"id\": \"mosip.id.read\",\n" + - " \"version\": \"1.0\",\n" + - " \"responsetime\": \"2019-04-05\",\n" + - " \"metadata\": null,\n" + - " \"response\": {},\n" + - " \"errors\": [\n" + - " {\n" + - " \"errorCode\": \"IDR-IDC-002\",\n" + - " \"errorMessage\": \"Invalid Input Parameter\"\n" + - " }\n" + - " ]\n" + - "}"; - String response = "{\n" + - " \"id\": \"mosip.id.read\",\n" + - " \"version\": \"1.0\",\n" + - " \"responsetime\": \"2019-04-05\",\n" + - " \"metadata\": null,\n" + - " \"response\": {},\n" + - " \"errors\": [\n" + - " {\n" + - " \"errorCode\": \"IDR-IDC-002\",\n" + - " \"errorMessage\": \"Invalid Input Parameter\"\n" + - " }\n" + - " ]\n" + - "}"; - when(registrationProcessorRestClientService.getApi(any(), any(), anyString(), any(), any())).thenReturn(str); - when(registrationProcessorRestClientService.putApi(any(), any(), any(), any(), any(), any(), any())) - .thenReturn(response); - - IdResponseDTO idResponseDTO = new IdResponseDTO(); - ResponseDTO responseDTO = new ResponseDTO(); - - ResponseWrapper responseVid = new ResponseWrapper(); - List errors = new ArrayList<>(); - ErrorDTO errorDTO=new ErrorDTO("IDR-IDC-002", StatusUtil.INVALID_INPUT_PARAMETER.getMessage()); - errors.add(errorDTO); - idResponseDTO.setErrors(errors); - idResponseDTO.setVersion("v12"); - idResponseDTO.setMetadata(null); - DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); - LocalDateTime localdatetime = LocalDateTime - .parse(DateUtils.getUTCCurrentDateTimeString("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"), format); - responseVid.setResponsetime(localdatetime); - - IdResponseDTO positiveidResponseDTO = new IdResponseDTO(); - ResponseDTO responseDTO1 = new ResponseDTO(); - responseDTO1.setEntity("https://dev.mosip.io/idrepo/v1.0/identity/203560486746"); - responseDTO1.setStatus("ACTIVATED"); - positiveidResponseDTO.setErrors(null); - positiveidResponseDTO.setId("mosip.id.create"); - positiveidResponseDTO.setResponse(responseDTO1); - positiveidResponseDTO.setResponsetime("2019-01-17T06:29:01.940Z"); - positiveidResponseDTO.setVersion("1.0"); - when(registrationProcessorRestClientService.postApi(any(), any(), any(), any(), any(Class.class))) - .thenReturn(idResponseDTO) - .thenReturn(idResponseDTO) - .thenReturn(idResponseDTO) - .thenReturn(positiveidResponseDTO); - MessageDTO result = uinGeneratorStage.process(messageDTO); - assertTrue(result.getInternalError()); - } - -/* -In this test case each time when Uin_generator api is called Invalid input parameter is the responde. - */ - - @Test - public void testUinGenerationResponseWillExcedesRetryCount() throws Exception { - MessageDTO messageDTO = new MessageDTO(); - messageDTO.setRid("27847657360002520181210094052"); - messageDTO.setReg_type(RegistrationType.NEW); - String str = "{\n" + - " \"id\": \"mosip.id.read\",\n" + - " \"version\": \"1.0\",\n" + - " \"responsetime\": \"2019-04-05\",\n" + - " \"metadata\": null,\n" + - " \"response\": {},\n" + - " \"errors\": [\n" + - " {\n" + - " \"errorCode\": \"IDR-IDC-002\",\n" + - " \"errorMessage\": \"Invalid Input Parameter\"\n" + - " }\n" + - " ]\n" + - "}"; - String response = "{\n" + - " \"id\": \"mosip.id.read\",\n" + - " \"version\": \"1.0\",\n" + - " \"responsetime\": \"2019-04-05\",\n" + - " \"metadata\": null,\n" + - " \"response\": {},\n" + - " \"errors\": [\n" + - " {\n" + - " \"errorCode\": \"IDR-IDC-002\",\n" + - " \"errorMessage\": \"Invalid Input Parameter\"\n" + - " }\n" + - " ]\n" + - "}"; - when(registrationProcessorRestClientService.getApi(any(), any(), anyString(), any(), any())).thenReturn(str); - when(registrationProcessorRestClientService.putApi(any(), any(), any(), any(), any(), any(), any())) - .thenReturn(response); - - IdResponseDTO idResponseDTO = new IdResponseDTO(); - ResponseDTO responseDTO = new ResponseDTO(); - - ResponseWrapper responseVid = new ResponseWrapper(); - List errors = new ArrayList<>(); - ErrorDTO errorDTO=new ErrorDTO("IDR-IDC-002", StatusUtil.INVALID_INPUT_PARAMETER.getMessage()); - errors.add(errorDTO); - idResponseDTO.setErrors(errors); - idResponseDTO.setVersion("v12"); - idResponseDTO.setMetadata(null); - DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); - LocalDateTime localdatetime = LocalDateTime - .parse(DateUtils.getUTCCurrentDateTimeString("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"), format); - responseVid.setResponsetime(localdatetime); - - when(registrationProcessorRestClientService.postApi(any(), any(), any(), any(), any(Class.class))) - .thenReturn(idResponseDTO) - .thenReturn(idResponseDTO) - .thenReturn(idResponseDTO) - .thenReturn(idResponseDTO); - - when(registrationStatusService.getRegistrationStatus(any())).thenReturn(registrationStatusDto); - MessageDTO result = uinGeneratorStage.process(messageDTO); - assertTrue(result.getInternalError()); - } @Test public void testUinGenerationF() throws Exception { MessageDTO messageDTO = new MessageDTO(); @@ -613,64 +476,6 @@ public void testUinGenerationF() throws Exception { } - @Test - public void testUinGenerationResponseWithExcededRetryCount() throws Exception { - MessageDTO messageDTO = new MessageDTO(); - messageDTO.setRid("27847657360002520181210094052"); - messageDTO.setReg_type(RegistrationType.NEW); - String str = "{\n" + - " \"id\": \"mosip.id.read\",\n" + - " \"version\": \"1.0\",\n" + - " \"responsetime\": \"2019-04-05\",\n" + - " \"metadata\": null,\n" + - " \"response\": {},\n" + - " \"errors\": [\n" + - " {\n" + - " \"errorCode\": \"IDR-IDC-002\",\n" + - " \"errorMessage\": \"Invalid Input Parameter\"\n" + - " }\n" + - " ]\n" + - "}"; - String response = "{\n" + - " \"id\": \"mosip.id.read\",\n" + - " \"version\": \"1.0\",\n" + - " \"responsetime\": \"2019-04-05\",\n" + - " \"metadata\": null,\n" + - " \"response\": {},\n" + - " \"errors\": [\n" + - " {\n" + - " \"errorCode\": \"IDR-IDC-002\",\n" + - " \"errorMessage\": \"Invalid Input Parameter\"\n" + - " }\n" + - " ]\n" + - "}"; - when(registrationProcessorRestClientService.getApi(any(), any(), anyString(), any(), any())).thenReturn(str); - when(registrationProcessorRestClientService.putApi(any(), any(), any(), any(), any(), any(), any())) - .thenReturn(response); - - IdResponseDTO idResponseDTO = new IdResponseDTO(); - ResponseDTO responseDTO = new ResponseDTO(); - - ResponseWrapper responseVid = new ResponseWrapper(); - List errors = new ArrayList<>(); - ErrorDTO errorDTO=new ErrorDTO("IDR-IDC-002", StatusUtil.INVALID_INPUT_PARAMETER.getMessage()); - errors.add(errorDTO); - idResponseDTO.setErrors(errors); - idResponseDTO.setVersion("v12"); - idResponseDTO.setMetadata(null); - DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); - LocalDateTime localdatetime = LocalDateTime - .parse(DateUtils.getUTCCurrentDateTimeString("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"), format); - responseVid.setResponsetime(localdatetime); - - when(registrationProcessorRestClientService.postApi(any(), any(), any(), any(), any(Class.class))) - .thenReturn(idResponseDTO); - registrationStatusDto.setRetryCount(4); - - when(registrationStatusService.getRegistrationStatus(any())).thenReturn(registrationStatusDto); - MessageDTO result = uinGeneratorStage.process(messageDTO); - assertTrue(result.getInternalError()); - } @Test public void testUinGenerationSuccessWithoutUINAndUinUnused() throws Exception { @@ -2677,4 +2482,202 @@ public void testSuccessfullIdResponseWithUinAndRid() throws Exception { } + /** + * In this method Invalid input parameter is thrown 2 time. then 3rd time will get the positive response. + * + */ + @Test + public void testUinGenerationResponseWithInvalidInputParameterException() throws Exception { + MessageDTO messageDTO = new MessageDTO(); + messageDTO.setRid("27847657360002520181210094052"); + messageDTO.setReg_type(RegistrationType.NEW); + String str = "{\n" + + " \"id\": \"mosip.id.read\",\n" + + " \"version\": \"1.0\",\n" + + " \"responsetime\": \"2019-04-05\",\n" + + " \"metadata\": null,\n" + + " \"response\": {},\n" + + " \"errors\": [\n" + + " {\n" + + " \"errorCode\": \"IDR-IDC-002\",\n" + + " \"errorMessage\": \"Invalid Input Parameter\"\n" + + " }\n" + + " ]\n" + + "}"; + String response = "{\n" + + " \"id\": \"mosip.id.read\",\n" + + " \"version\": \"1.0\",\n" + + " \"responsetime\": \"2019-04-05\",\n" + + " \"metadata\": null,\n" + + " \"response\": {},\n" + + " \"errors\": [\n" + + " {\n" + + " \"errorCode\": \"IDR-IDC-002\",\n" + + " \"errorMessage\": \"Invalid Input Parameter\"\n" + + " }\n" + + " ]\n" + + "}"; + when(registrationProcessorRestClientService.getApi(any(), any(), anyString(), any(), any())).thenReturn(str); + when(registrationProcessorRestClientService.putApi(any(), any(), any(), any(), any(), any(), any())) + .thenReturn(response); + + IdResponseDTO idResponseDTO = new IdResponseDTO(); + ResponseDTO responseDTO = new ResponseDTO(); + + ResponseWrapper responseVid = new ResponseWrapper(); + List errors = new ArrayList<>(); + ErrorDTO errorDTO=new ErrorDTO("IDR-IDC-002", StatusUtil.INVALID_INPUT_PARAMETER.getMessage()); + errors.add(errorDTO); + idResponseDTO.setErrors(errors); + idResponseDTO.setVersion("v12"); + idResponseDTO.setMetadata(null); + DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); + LocalDateTime localdatetime = LocalDateTime + .parse(DateUtils.getUTCCurrentDateTimeString("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"), format); + responseVid.setResponsetime(localdatetime); + + IdResponseDTO positiveidResponseDTO = new IdResponseDTO(); + ResponseDTO responseDTO1 = new ResponseDTO(); + responseDTO1.setEntity("https://dev.mosip.io/idrepo/v1.0/identity/203560486746"); + responseDTO1.setStatus("ACTIVATED"); + positiveidResponseDTO.setErrors(null); + positiveidResponseDTO.setId("mosip.id.create"); + positiveidResponseDTO.setResponse(responseDTO1); + positiveidResponseDTO.setResponsetime("2019-01-17T06:29:01.940Z"); + positiveidResponseDTO.setVersion("1.0"); + + when(registrationProcessorRestClientService.postApi(any(), any(), any(), any(), any(Class.class))) + .thenReturn(idResponseDTO) + .thenReturn(idResponseDTO) + .thenReturn(idResponseDTO) + .thenReturn(positiveidResponseDTO) + .thenReturn(responseVid); + MessageDTO result = uinGeneratorStage.process(messageDTO); + assertFalse(result.getInternalError()); + } + + +/* +In this test case each time when Uin_generator api is called Invalid input parameter is the responde. + */ + @Test + public void testUinGenerationResponseWillExcedesRetryCount() throws Exception { + MessageDTO messageDTO = new MessageDTO(); + messageDTO.setRid("27847657360002520181210094052"); + messageDTO.setReg_type(RegistrationType.NEW); + String str = "{\n" + + " \"id\": \"mosip.id.read\",\n" + + " \"version\": \"1.0\",\n" + + " \"responsetime\": \"2019-04-05\",\n" + + " \"metadata\": null,\n" + + " \"response\": {},\n" + + " \"errors\": [\n" + + " {\n" + + " \"errorCode\": \"IDR-IDC-002\",\n" + + " \"errorMessage\": \"Invalid Input Parameter\"\n" + + " }\n" + + " ]\n" + + "}"; + String response = "{\n" + + " \"id\": \"mosip.id.read\",\n" + + " \"version\": \"1.0\",\n" + + " \"responsetime\": \"2019-04-05\",\n" + + " \"metadata\": null,\n" + + " \"response\": {},\n" + + " \"errors\": [\n" + + " {\n" + + " \"errorCode\": \"IDR-IDC-002\",\n" + + " \"errorMessage\": \"Invalid Input Parameter\"\n" + + " }\n" + + " ]\n" + + "}"; + when(registrationProcessorRestClientService.getApi(any(), any(), anyString(), any(), any())).thenReturn(str); + when(registrationProcessorRestClientService.putApi(any(), any(), any(), any(), any(), any(), any())) + .thenReturn(response); + + IdResponseDTO idResponseDTO = new IdResponseDTO(); + ResponseDTO responseDTO = new ResponseDTO(); + + ResponseWrapper responseVid = new ResponseWrapper(); + List errors = new ArrayList<>(); + ErrorDTO errorDTO=new ErrorDTO("IDR-IDC-002", StatusUtil.INVALID_INPUT_PARAMETER.getMessage()); + errors.add(errorDTO); + idResponseDTO.setErrors(errors); + idResponseDTO.setVersion("v12"); + idResponseDTO.setMetadata(null); + DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); + LocalDateTime localdatetime = LocalDateTime + .parse(DateUtils.getUTCCurrentDateTimeString("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"), format); + responseVid.setResponsetime(localdatetime); + + when(registrationProcessorRestClientService.postApi(any(), any(), any(), any(), any(Class.class))) + .thenReturn(idResponseDTO) + .thenReturn(idResponseDTO) + .thenReturn(idResponseDTO) + .thenReturn(idResponseDTO); + + when(registrationStatusService.getRegistrationStatus(any())).thenReturn(registrationStatusDto); + MessageDTO result = uinGeneratorStage.process(messageDTO); + assertTrue(result.getInternalError()); + } + + @Test + public void testUinGenerationResponseWithExcededRetryCount() throws Exception { + MessageDTO messageDTO = new MessageDTO(); + messageDTO.setRid("27847657360002520181210094052"); + messageDTO.setReg_type(RegistrationType.NEW); + String str = "{\n" + + " \"id\": \"mosip.id.read\",\n" + + " \"version\": \"1.0\",\n" + + " \"responsetime\": \"2019-04-05\",\n" + + " \"metadata\": null,\n" + + " \"response\": {},\n" + + " \"errors\": [\n" + + " {\n" + + " \"errorCode\": \"IDR-IDC-002\",\n" + + " \"errorMessage\": \"Invalid Input Parameter\"\n" + + " }\n" + + " ]\n" + + "}"; + String response = "{\n" + + " \"id\": \"mosip.id.read\",\n" + + " \"version\": \"1.0\",\n" + + " \"responsetime\": \"2019-04-05\",\n" + + " \"metadata\": null,\n" + + " \"response\": {},\n" + + " \"errors\": [\n" + + " {\n" + + " \"errorCode\": \"IDR-IDC-002\",\n" + + " \"errorMessage\": \"Invalid Input Parameter\"\n" + + " }\n" + + " ]\n" + + "}"; + when(registrationProcessorRestClientService.getApi(any(), any(), anyString(), any(), any())).thenReturn(str); + when(registrationProcessorRestClientService.putApi(any(), any(), any(), any(), any(), any(), any())) + .thenReturn(response); + + IdResponseDTO idResponseDTO = new IdResponseDTO(); + ResponseDTO responseDTO = new ResponseDTO(); + + ResponseWrapper responseVid = new ResponseWrapper(); + List errors = new ArrayList<>(); + ErrorDTO errorDTO=new ErrorDTO("IDR-IDC-002", StatusUtil.INVALID_INPUT_PARAMETER.getMessage()); + errors.add(errorDTO); + idResponseDTO.setErrors(errors); + idResponseDTO.setVersion("v12"); + idResponseDTO.setMetadata(null); + DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); + LocalDateTime localdatetime = LocalDateTime + .parse(DateUtils.getUTCCurrentDateTimeString("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"), format); + responseVid.setResponsetime(localdatetime); + + when(registrationProcessorRestClientService.postApi(any(), any(), any(), any(), any(Class.class))) + .thenReturn(idResponseDTO); + registrationStatusDto.setRetryCount(4); + + when(registrationStatusService.getRegistrationStatus(any())).thenReturn(registrationStatusDto); + MessageDTO result = uinGeneratorStage.process(messageDTO); + assertTrue(result.getInternalError()); + } + } \ No newline at end of file From 5a20753dabc6a94d183a7848710945f179b67f38 Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Wed, 6 Dec 2023 13:31:01 +0530 Subject: [PATCH 10/12] [mosip 30470] uin genration Invalid input parameter Exception handeled Signed-off-by: khuddus shariff --- .../uigenerator/UinGeneratorStageTest.java | 61 +------------------ 1 file changed, 1 insertion(+), 60 deletions(-) diff --git a/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java b/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java index b14dfbddf8f..12d7ac478e6 100644 --- a/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java +++ b/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java @@ -2554,6 +2554,7 @@ public void testUinGenerationResponseWithInvalidInputParameterException() throws .thenReturn(responseVid); MessageDTO result = uinGeneratorStage.process(messageDTO); assertFalse(result.getInternalError()); + assertTrue(result.getIsValid()); } @@ -2620,64 +2621,4 @@ public void testUinGenerationResponseWillExcedesRetryCount() throws Exception { MessageDTO result = uinGeneratorStage.process(messageDTO); assertTrue(result.getInternalError()); } - - @Test - public void testUinGenerationResponseWithExcededRetryCount() throws Exception { - MessageDTO messageDTO = new MessageDTO(); - messageDTO.setRid("27847657360002520181210094052"); - messageDTO.setReg_type(RegistrationType.NEW); - String str = "{\n" + - " \"id\": \"mosip.id.read\",\n" + - " \"version\": \"1.0\",\n" + - " \"responsetime\": \"2019-04-05\",\n" + - " \"metadata\": null,\n" + - " \"response\": {},\n" + - " \"errors\": [\n" + - " {\n" + - " \"errorCode\": \"IDR-IDC-002\",\n" + - " \"errorMessage\": \"Invalid Input Parameter\"\n" + - " }\n" + - " ]\n" + - "}"; - String response = "{\n" + - " \"id\": \"mosip.id.read\",\n" + - " \"version\": \"1.0\",\n" + - " \"responsetime\": \"2019-04-05\",\n" + - " \"metadata\": null,\n" + - " \"response\": {},\n" + - " \"errors\": [\n" + - " {\n" + - " \"errorCode\": \"IDR-IDC-002\",\n" + - " \"errorMessage\": \"Invalid Input Parameter\"\n" + - " }\n" + - " ]\n" + - "}"; - when(registrationProcessorRestClientService.getApi(any(), any(), anyString(), any(), any())).thenReturn(str); - when(registrationProcessorRestClientService.putApi(any(), any(), any(), any(), any(), any(), any())) - .thenReturn(response); - - IdResponseDTO idResponseDTO = new IdResponseDTO(); - ResponseDTO responseDTO = new ResponseDTO(); - - ResponseWrapper responseVid = new ResponseWrapper(); - List errors = new ArrayList<>(); - ErrorDTO errorDTO=new ErrorDTO("IDR-IDC-002", StatusUtil.INVALID_INPUT_PARAMETER.getMessage()); - errors.add(errorDTO); - idResponseDTO.setErrors(errors); - idResponseDTO.setVersion("v12"); - idResponseDTO.setMetadata(null); - DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); - LocalDateTime localdatetime = LocalDateTime - .parse(DateUtils.getUTCCurrentDateTimeString("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"), format); - responseVid.setResponsetime(localdatetime); - - when(registrationProcessorRestClientService.postApi(any(), any(), any(), any(), any(Class.class))) - .thenReturn(idResponseDTO); - registrationStatusDto.setRetryCount(4); - - when(registrationStatusService.getRegistrationStatus(any())).thenReturn(registrationStatusDto); - MessageDTO result = uinGeneratorStage.process(messageDTO); - assertTrue(result.getInternalError()); - } - } \ No newline at end of file From 171b959439ce955d2016b001166024a5bc16ebb4 Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Wed, 6 Dec 2023 13:51:13 +0530 Subject: [PATCH 11/12] [mosip 30470] uin genration Invalid input parameter Exception handeled Signed-off-by: khuddus shariff --- .../processor/stages/uigenerator/UinGeneratorStageTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java b/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java index 12d7ac478e6..10a549992f0 100644 --- a/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java +++ b/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java @@ -2487,7 +2487,7 @@ public void testSuccessfullIdResponseWithUinAndRid() throws Exception { * */ @Test - public void testUinGenerationResponseWithInvalidInputParameterException() throws Exception { + public void testUinGenerationResponseWithInvalidInputParameterExceptionForFirstThreeTimes() throws Exception { MessageDTO messageDTO = new MessageDTO(); messageDTO.setRid("27847657360002520181210094052"); messageDTO.setReg_type(RegistrationType.NEW); From 270adec786ebf8f02f57f0982cd5679e6b6a4ab8 Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Wed, 6 Dec 2023 17:08:56 +0530 Subject: [PATCH 12/12] [mosip 30470] uin genration Invalid input parameter Exception handeled Signed-off-by: khuddus shariff --- .../processor/stages/uigenerator/UinGeneratorStageTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java b/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java index 10a549992f0..a9b594f5bb2 100644 --- a/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java +++ b/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java @@ -2599,7 +2599,6 @@ public void testUinGenerationResponseWillExcedesRetryCount() throws Exception { IdResponseDTO idResponseDTO = new IdResponseDTO(); ResponseDTO responseDTO = new ResponseDTO(); - ResponseWrapper responseVid = new ResponseWrapper(); List errors = new ArrayList<>(); ErrorDTO errorDTO=new ErrorDTO("IDR-IDC-002", StatusUtil.INVALID_INPUT_PARAMETER.getMessage()); errors.add(errorDTO); @@ -2609,7 +2608,7 @@ public void testUinGenerationResponseWillExcedesRetryCount() throws Exception { DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); LocalDateTime localdatetime = LocalDateTime .parse(DateUtils.getUTCCurrentDateTimeString("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"), format); - responseVid.setResponsetime(localdatetime); + when(registrationProcessorRestClientService.postApi(any(), any(), any(), any(), any(Class.class))) .thenReturn(idResponseDTO)