From e9e040089ac198f86133291f574403798de4f1f2 Mon Sep 17 00:00:00 2001 From: Vishwa Date: Mon, 12 Aug 2024 14:25:25 +0530 Subject: [PATCH] =?UTF-8?q?Revert=20"[MOSIP-34112]=20Release=201.2.0.x=20c?= =?UTF-8?q?ode=20marge=20for=20Bio-dedupes=20updated=20flow=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit b9c907c19c8a9a734d36bcdb1341a48e06426d66. --- .../constants/BioDedupeConstants.java | 92 +- .../biodedupe/stage/BioDedupeProcessor.java | 137 +- .../stage/BioDedupeProcessorTest.java | 1406 +++++++---------- .../core/status/util/StatusUtil.java | 3 - 4 files changed, 672 insertions(+), 966 deletions(-) diff --git a/registration-processor/core-processor/registration-processor-bio-dedupe-stage/src/main/java/io/mosip/registration/processor/biodedupe/constants/BioDedupeConstants.java b/registration-processor/core-processor/registration-processor-bio-dedupe-stage/src/main/java/io/mosip/registration/processor/biodedupe/constants/BioDedupeConstants.java index cf10051c819..b73b4fc62c9 100644 --- a/registration-processor/core-processor/registration-processor-bio-dedupe-stage/src/main/java/io/mosip/registration/processor/biodedupe/constants/BioDedupeConstants.java +++ b/registration-processor/core-processor/registration-processor-bio-dedupe-stage/src/main/java/io/mosip/registration/processor/biodedupe/constants/BioDedupeConstants.java @@ -1,47 +1,45 @@ -package io.mosip.registration.processor.biodedupe.constants; - -public class BioDedupeConstants { - - /** The Constant FILE_SEPARATOR. */ - public static final String FILE_SEPARATOR = "\\"; - - /** The Constant INDIVIDUAL_BIOMETRICS. */ - public static final String INDIVIDUAL_BIOMETRICS = "individualBiometrics"; - - public static final String VALUE = "value"; - - public static final String CBEFF_PRESENT_IN_PACKET = "Cbeff is present in the packet, destination stage is abis_handler"; - - public static final String CBEFF_NOT_PRESENT_IN_PACKET = "Cbeff is not present in the packet. This will be sent to manual verification."; - - public static final String CBEFF_ABSENT_IN_PACKET = "Cbeff is absent in the packet for child, destination stage is UIN"; - - public static final String UPDATE_PACKET_BIOMETRIC_NOT_NULL = "Update packet individual biometric not null, destination stage is abis_handler"; - - public static final String UPDATE_PACKET_BIOMETRIC_NULL = "Update packet individual biometric null, destination stage is UIN"; - - public static final String ABIS_RESPONSE_NOT_NULL = "ABIS response Details not null, destination stage is Manual_verification"; - - public static final String ABIS_RESPONSE_NULL = "ABIS response Details null, destination stage is UIN"; - - public static final String CBEFF_NOT_FOUND = "Cbeff not found for the lost packet"; - - public static final String APPLICANT_TYPE_CHILD = "Applicant type is child and Cbeff not present returning false"; - - public static final String APPLICANT_TYPE_ADULT = "Applicant type is adult and Cbeff not present throwing exception"; - - public static final String LOST_PRE_ABIS_IDENTITIFICATION = "Lost Packet Pre abis identification"; - - public static final String NO_MATCH_FOUND_FOR_LOST = "No match found, rejecting the lost packet for "; - - public static final String FOUND_UIN_IN_BIO_CHECK = "Found a matching UIN in bio check for the lost packet "; - - public static final String FOUND_UIN_IN_DEMO_CHECK = "Found a matching UIN in demo check for the lost packet "; - - public static final String MULTIPLE_RID_FOUND = "Multiple matched regId found, saving data in manual verification"; - - /** The Constant INTERNAL_ERROR. */ - private static final String INTERNAL_ERROR = "Internal error occurred in bio-dedupe stage while processing for registrationId "; - - public static final String BIOMETRIC_MATCH_FOUND_WITH_OTHER = "Biometric match found with other user, rejecting packet for "; -} \ No newline at end of file +package io.mosip.registration.processor.biodedupe.constants; + +public class BioDedupeConstants { + + /** The Constant FILE_SEPARATOR. */ + public static final String FILE_SEPARATOR = "\\"; + + /** The Constant INDIVIDUAL_BIOMETRICS. */ + public static final String INDIVIDUAL_BIOMETRICS = "individualBiometrics"; + + public static final String VALUE = "value"; + + public static final String CBEFF_PRESENT_IN_PACKET = "Cbeff is present in the packet, destination stage is abis_handler"; + + public static final String CBEFF_NOT_PRESENT_IN_PACKET = "Cbeff is not present in the packet. This will be sent to manual verification."; + + public static final String CBEFF_ABSENT_IN_PACKET = "Cbeff is absent in the packet for child, destination stage is UIN"; + + public static final String UPDATE_PACKET_BIOMETRIC_NOT_NULL = "Update packet individual biometric not null, destination stage is abis_handler"; + + public static final String UPDATE_PACKET_BIOMETRIC_NULL = "Update packet individual biometric null, destination stage is UIN"; + + public static final String ABIS_RESPONSE_NOT_NULL = "ABIS response Details not null, destination stage is Manual_verification"; + + public static final String ABIS_RESPONSE_NULL = "ABIS response Details null, destination stage is UIN"; + + public static final String CBEFF_NOT_FOUND = "Cbeff not found for the lost packet"; + + public static final String APPLICANT_TYPE_CHILD = "Applicant type is child and Cbeff not present returning false"; + + public static final String APPLICANT_TYPE_ADULT = "Applicant type is adult and Cbeff not present throwing exception"; + + public static final String LOST_PRE_ABIS_IDENTITIFICATION = "Lost Packet Pre abis identification"; + + public static final String NO_MATCH_FOUND_FOR_LOST = "No match found, rejecting the lost packet for "; + + public static final String FOUND_UIN_IN_BIO_CHECK = "Found a matching UIN in bio check for the lost packet "; + + public static final String FOUND_UIN_IN_DEMO_CHECK = "Found a matching UIN in demo check for the lost packet "; + + public static final String MULTIPLE_RID_FOUND = "Multiple matched regId found, saving data in manual verification"; + + /** The Constant INTERNAL_ERROR. */ + private static final String INTERNAL_ERROR = "Internal error occurred in bio-dedupe stage while processing for registrationId "; +} diff --git a/registration-processor/core-processor/registration-processor-bio-dedupe-stage/src/main/java/io/mosip/registration/processor/biodedupe/stage/BioDedupeProcessor.java b/registration-processor/core-processor/registration-processor-bio-dedupe-stage/src/main/java/io/mosip/registration/processor/biodedupe/stage/BioDedupeProcessor.java index 627d9fb1e12..be0738c4a74 100644 --- a/registration-processor/core-processor/registration-processor-bio-dedupe-stage/src/main/java/io/mosip/registration/processor/biodedupe/stage/BioDedupeProcessor.java +++ b/registration-processor/core-processor/registration-processor-bio-dedupe-stage/src/main/java/io/mosip/registration/processor/biodedupe/stage/BioDedupeProcessor.java @@ -1,5 +1,21 @@ package io.mosip.registration.processor.biodedupe.stage; +import java.io.IOException; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + import io.mosip.kernel.core.logger.spi.Logger; import io.mosip.kernel.core.util.StringUtils; import io.mosip.kernel.core.util.exception.JsonProcessingException; @@ -8,11 +24,19 @@ import io.mosip.registration.processor.biodedupe.stage.exception.CbeffNotFoundException; import io.mosip.registration.processor.core.abstractverticle.MessageBusAddress; import io.mosip.registration.processor.core.abstractverticle.MessageDTO; +import io.mosip.registration.processor.core.code.DedupeSourceName; import io.mosip.registration.processor.core.code.EventId; import io.mosip.registration.processor.core.code.EventName; import io.mosip.registration.processor.core.code.EventType; -import io.mosip.registration.processor.core.code.*; -import io.mosip.registration.processor.core.constant.*; +import io.mosip.registration.processor.core.code.ModuleName; +import io.mosip.registration.processor.core.code.RegistrationExceptionTypeCode; +import io.mosip.registration.processor.core.code.RegistrationTransactionStatusCode; +import io.mosip.registration.processor.core.code.RegistrationTransactionTypeCode; +import io.mosip.registration.processor.core.constant.AbisConstant; +import io.mosip.registration.processor.core.constant.LoggerFileConstant; +import io.mosip.registration.processor.core.constant.MappingJsonConstants; +import io.mosip.registration.processor.core.constant.ProviderStageName; +import io.mosip.registration.processor.core.constant.RegistrationType; import io.mosip.registration.processor.core.exception.ApisResourceAccessException; import io.mosip.registration.processor.core.exception.PacketDecryptionFailureException; import io.mosip.registration.processor.core.exception.PacketManagerException; @@ -41,17 +65,6 @@ import io.mosip.registration.processor.status.dto.RegistrationStatusDto; import io.mosip.registration.processor.status.dto.SyncTypeDto; import io.mosip.registration.processor.status.service.RegistrationStatusService; -import org.apache.commons.lang3.exception.ExceptionUtils; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.dao.DataAccessException; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.io.IOException; -import java.util.*; /** * The Class BioDedupeProcessor. @@ -119,9 +132,6 @@ public class BioDedupeProcessor { @Value("${registration.processor.missing.biometric.verification.enabled:true}") private boolean missingBiometricVerificationEnabled; - @Value("${registration.processor.biometrics-update.single-match.auto-reject.enabled:false}") - private boolean biometricsUpdateSingleMatchAutoReject; - /** The reg proc logger. */ private static Logger regProcLogger = RegProcessorLogger.getLogger(BioDedupeProcessor.class); @@ -170,7 +180,9 @@ public MessageDTO process(MessageDTO object, String stageName) { newPacketPreAbisIdentification(registrationStatusDto, object); } else if (packetStatus.equalsIgnoreCase(AbisConstant.POST_ABIS_IDENTIFICATION)) { postAbisIdentification(registrationStatusDto, object, registrationType); + } + } else if (registrationType.equalsIgnoreCase(SyncTypeDto.UPDATE.toString()) || registrationType.equalsIgnoreCase(SyncTypeDto.RES_UPDATE.toString())) { String packetStatus = abisHandlerUtil.getPacketStatus(registrationStatusDto); @@ -404,10 +416,6 @@ private void postAbisIdentification(InternalRegistrationStatusDto registrationSt io.mosip.kernel.core.exception.IOException, JsonProcessingException, PacketManagerException { String moduleId = ""; String moduleName = ModuleName.BIO_DEDUPE.toString(); - /* This method returns combination of below RIDs : - - RIDs which are in PROCESSING state (Except current packet RID) - - RIDs (For which UIN is generated and it reached to RID repo) associated with UINs other than current packet UIN i.e it removes the RIDs which are associated with current packet UIN. - */ Set matchedRegIds = abisHandlerUtil.getUniqueRegIds(registrationStatusDto.getRegistrationId(), registrationType, registrationStatusDto.getIteration(), registrationStatusDto.getWorkflowInstanceId(), ProviderStageName.BIO_DEDUPE); ArrayList matchedRegIdsList = new ArrayList(matchedRegIds); @@ -425,83 +433,26 @@ private void postAbisIdentification(InternalRegistrationStatusDto registrationSt registrationStatusDto.setSubStatusCode(StatusUtil.BIO_DEDUPE_SUCCESS.getCode()); regProcLogger.info(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(), registrationStatusDto.getRegistrationId(), BioDedupeConstants.ABIS_RESPONSE_NULL); + } else { - if (registrationType.equalsIgnoreCase(RegistrationType.UPDATE.name())) { - handlePostAbisIdentificationForUpdate(registrationStatusDto, object, registrationType, moduleName, - matchedRegIds); - }else { - sendToManualAdjudicationStage(registrationStatusDto, object, registrationType, moduleName, matchedRegIds); - regProcLogger.info(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(), + registrationStatusDto.setStatusCode(RegistrationStatusCode.FAILED.name()); + registrationStatusDto.setStatusComment(StatusUtil.BIO_DEDUPE_POTENTIAL_MATCH.getMessage()); + registrationStatusDto.setSubStatusCode(StatusUtil.BIO_DEDUPE_POTENTIAL_MATCH.getCode()); + registrationStatusDto.setLatestTransactionStatusCode(RegistrationTransactionStatusCode.FAILED.toString()); + moduleId = PlatformSuccessMessages.RPR_BIO_METRIC_POTENTIAL_MATCH.getCode(); + packetInfoManager.saveManualAdjudicationData(matchedRegIds, object, + DedupeSourceName.BIO, moduleId, moduleName,null,null); + //send message to manual adjudication + object.setInternalError(Boolean.FALSE); + object.setRid(registrationStatusDto.getRegistrationId()); + object.setIsValid(Boolean.TRUE); + object.setReg_type(registrationType); + object.setMessageBusAddress(MessageBusAddress.MANUAL_ADJUDICATION_BUS_IN); + + regProcLogger.info(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(), registrationStatusDto.getRegistrationId(), BioDedupeConstants.ABIS_RESPONSE_NOT_NULL); - } - } - } - private void handlePostAbisIdentificationForUpdate(InternalRegistrationStatusDto registrationStatusDto, MessageDTO object, - String registrationType, String moduleName, Set matchedRegIds) - throws IOException, ApisResourceAccessException, PacketManagerException, JsonProcessingException { - Set uniqueUins = new HashSet(); - boolean sendToManualAdjudication = false; - for(String matchedRegistrationId:matchedRegIds) { - String uin = idRepoService.getUinByRid(matchedRegistrationId, utilities.getGetRegProcessorDemographicIdentity()); - if (StringUtils.isEmpty(uin)) { - InternalRegistrationStatusDto matchedRegistrationStatusDto = registrationStatusService - .getRegistrationStatus(matchedRegistrationId, null, null, null); - if (matchedRegistrationStatusDto.getStatusCode() - .equals(RegistrationStatusCode.PROCESSING.name())) { - sendToManualAdjudication = true; - break; - } - } else { - uniqueUins.add(uin); - } } - regProcLogger.info(LoggerFileConstant.SESSIONID.toString(), - LoggerFileConstant.REGISTRATIONID.toString(), registrationStatusDto.getRegistrationId(), - "sendToManualAdjudication : " + sendToManualAdjudication + " ::uniqueUins count : " + uniqueUins.size() + - " ::biometricsUpdateSingleMatchAutoReject : " + biometricsUpdateSingleMatchAutoReject); - if (sendToManualAdjudication || uniqueUins.size() > 1) { - sendToManualAdjudicationStage(registrationStatusDto, object, registrationType, moduleName, - matchedRegIds); - } else { - //Single match of uin found which is different from update packet uin. - if (biometricsUpdateSingleMatchAutoReject) { - registrationStatusDto.setLatestTransactionStatusCode( - RegistrationTransactionStatusCode.FAILED.toString()); - object.setIsValid(Boolean.FALSE); - registrationStatusDto.setStatusCode(RegistrationStatusCode.REJECTED.name()); - registrationStatusDto - .setStatusComment(StatusUtil. UPDATE_PACKET_BIOMETRICS_MATCHED_WITH_OTHER.getMessage()); - registrationStatusDto - .setSubStatusCode(StatusUtil. UPDATE_PACKET_BIOMETRICS_MATCHED_WITH_OTHER.getCode()); - regProcLogger.info(LoggerFileConstant.SESSIONID.toString(), - LoggerFileConstant.REGISTRATIONID.toString(), - registrationStatusDto.getRegistrationId(), - BioDedupeConstants.BIOMETRIC_MATCH_FOUND_WITH_OTHER - + registrationStatusDto.getRegistrationId()); - } else { - sendToManualAdjudicationStage(registrationStatusDto, object, registrationType, moduleName, - matchedRegIds); - } - } - } - - private void sendToManualAdjudicationStage(InternalRegistrationStatusDto registrationStatusDto, MessageDTO object, - String registrationType, String moduleName, Set matchedRegIds) { - String moduleId; - registrationStatusDto.setStatusCode(RegistrationStatusCode.FAILED.name()); - registrationStatusDto.setStatusComment(StatusUtil.BIO_DEDUPE_POTENTIAL_MATCH.getMessage()); - registrationStatusDto.setSubStatusCode(StatusUtil.BIO_DEDUPE_POTENTIAL_MATCH.getCode()); - registrationStatusDto.setLatestTransactionStatusCode(RegistrationTransactionStatusCode.FAILED.toString()); - moduleId = PlatformSuccessMessages.RPR_BIO_METRIC_POTENTIAL_MATCH.getCode(); - packetInfoManager.saveManualAdjudicationData(matchedRegIds, object, - DedupeSourceName.BIO, moduleId, moduleName,null,null); - //send message to manual adjudication - object.setInternalError(Boolean.FALSE); - object.setRid(registrationStatusDto.getRegistrationId()); - object.setIsValid(Boolean.TRUE); - object.setReg_type(registrationType); - object.setMessageBusAddress(MessageBusAddress.MANUAL_ADJUDICATION_BUS_IN); } /** diff --git a/registration-processor/core-processor/registration-processor-bio-dedupe-stage/src/test/java/io/mosip/registration/processor/biodedupe/stage/BioDedupeProcessorTest.java b/registration-processor/core-processor/registration-processor-bio-dedupe-stage/src/test/java/io/mosip/registration/processor/biodedupe/stage/BioDedupeProcessorTest.java index da994c60cc5..a4d723d240f 100644 --- a/registration-processor/core-processor/registration-processor-bio-dedupe-stage/src/test/java/io/mosip/registration/processor/biodedupe/stage/BioDedupeProcessorTest.java +++ b/registration-processor/core-processor/registration-processor-bio-dedupe-stage/src/test/java/io/mosip/registration/processor/biodedupe/stage/BioDedupeProcessorTest.java @@ -25,15 +25,12 @@ import io.mosip.registration.processor.core.constant.ProviderStageName; import io.mosip.registration.processor.core.exception.PacketManagerException; import io.mosip.registration.processor.packet.storage.utils.PriorityBasedPacketManagerService; -import io.mosip.registration.processor.status.code.RegistrationStatusCode; import org.apache.commons.io.IOUtils; import org.json.simple.JSONObject; -import org.junit.Assert; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; @@ -41,7 +38,6 @@ 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.Autowired; import org.springframework.core.env.Environment; import org.springframework.dao.DataAccessException; import org.springframework.test.util.ReflectionTestUtils; @@ -81,8 +77,6 @@ import io.mosip.registration.processor.status.entity.RegistrationStatusEntity; import io.mosip.registration.processor.status.service.RegistrationStatusService; -import javax.validation.constraints.AssertTrue; - /** * The Class BioDedupeStageTest. */ @@ -91,838 +85,604 @@ @PrepareForTest({ Utilities.class }) public class BioDedupeProcessorTest { - /** The Constant ERROR. */ - private static final String ERROR = "ERROR"; + /** The Constant ERROR. */ + private static final String ERROR = "ERROR"; - /** The Constant IDENTITY. */ - private static final String IDENTITY = "identity"; + /** The Constant IDENTITY. */ + private static final String IDENTITY = "identity"; - /** The Constant ABIS_HANDLER_BUS_IN. */ - private static final String ABIS_HANDLER_BUS_IN = "abis-handler-bus-in"; + /** The Constant ABIS_HANDLER_BUS_IN. */ + private static final String ABIS_HANDLER_BUS_IN = "abis-handler-bus-in"; - /** The registration status service. */ - @Mock - private RegistrationStatusService registrationStatusService; + /** The registration status service. */ + @Mock + private RegistrationStatusService registrationStatusService; - @Mock - private CbeffValidateAndVerificatonService cbeffValidateAndVerificatonService; + @Mock + private CbeffValidateAndVerificatonService cbeffValidateAndVerificatonService; - /** The packet info manager. */ - @Mock - private PacketInfoManager packetInfoManager; + /** The packet info manager. */ + @Mock + private PacketInfoManager packetInfoManager; - /** The bio dedupe service. */ - @Mock - private BioDedupeService bioDedupeService; + /** The bio dedupe service. */ + @Mock + private BioDedupeService bioDedupeService; - /** The registration status dao. */ - @Mock - private RegistrationStatusDao registrationStatusDao; + /** The registration status dao. */ + @Mock + private RegistrationStatusDao registrationStatusDao; - /** The packet info dao. */ - @Mock - private PacketInfoDao packetInfoDao; + /** The packet info dao. */ + @Mock + private PacketInfoDao packetInfoDao; - @Mock - private IdRepoService idRepoService; + @Mock + private IdRepoService idRepoService; - /** The dto. */ - MessageDTO dto = new MessageDTO(); + /** The dto. */ + MessageDTO dto = new MessageDTO(); - /** The registration status dto. */ - InternalRegistrationStatusDto registrationStatusDto = new InternalRegistrationStatusDto(); + /** The registration status dto. */ + InternalRegistrationStatusDto registrationStatusDto = new InternalRegistrationStatusDto(); - /** The audit log request builder. */ - @Mock - private AuditLogRequestBuilder auditLogRequestBuilder; + /** The audit log request builder. */ + @Mock + private AuditLogRequestBuilder auditLogRequestBuilder; - /** The matched reg ids. */ - List matchedRegIds = new ArrayList(); + /** The matched reg ids. */ + List matchedRegIds = new ArrayList(); - /** The registration status mapper util. */ - @Mock - RegistrationExceptionMapperUtil registrationStatusMapperUtil; + /** The registration status mapper util. */ + @Mock + RegistrationExceptionMapperUtil registrationStatusMapperUtil; - /** The bio dedupe processor. */ - @InjectMocks - private BioDedupeProcessor bioDedupeProcessor; + /** The bio dedupe processor. */ + @InjectMocks + private BioDedupeProcessor bioDedupeProcessor; - /** The stage name. */ - private String stageName = "BioDedupeStage"; - - /** The utilities. */ - @Mock - Utilities utility; - - /** The rest client service. */ - @Mock - private RegistrationProcessorRestClientService restClientService; - - /** The entity. */ - @Mock - RegistrationStatusEntity entity = new RegistrationStatusEntity(); - - /** The abis handler util. */ - @Mock - private ABISHandlerUtil abisHandlerUtil; - - /** The map identity json string to object. */ - @Mock - ObjectMapper mapIdentityJsonStringToObject; - - @Mock - LogDescription description; - - @Mock - private Environment env; - - @Mock - private PriorityBasedPacketManagerService priorityBasedPacketManagerService; - - /** - * Sets the up. - * - * @throws Exception - * the exception - */ - @Before - public void setUp() throws Exception { - Mockito.doNothing().when(cbeffValidateAndVerificatonService).validateBiometrics(any(), any()); - Mockito.when(priorityBasedPacketManagerService.getFieldByMappingJsonKey(any(),any(),any(),any())).thenReturn("field"); - Mockito.when(priorityBasedPacketManagerService.getField(any(),any(),any(),any())).thenReturn("field"); - when(utility.getDefaultSource(any(), any())).thenReturn("reg-client"); - ReflectionTestUtils.setField(bioDedupeProcessor, "infantDedupe", "Y"); - ReflectionTestUtils.setField(bioDedupeProcessor, "ageLimit", "4"); - - AuditResponseDto auditResponseDto = new AuditResponseDto(); - ResponseWrapper responseWrapper = new ResponseWrapper<>(); - responseWrapper.setResponse(auditResponseDto); - Mockito.doReturn(responseWrapper).when(auditLogRequestBuilder).createAuditRequestBuilder( - "test case description", EventId.RPR_405.toString(), EventName.UPDATE.toString(), - EventType.BUSINESS.toString(), "1234testcase", ApiName.AUDIT); - - dto.setRid("reg1234"); - registrationStatusDto.setRegistrationId("reg1234"); - registrationStatusDto.setRegistrationType("new"); - - Mockito.doNothing().when(registrationStatusService).updateRegistrationStatus(any(), any(), any()); - Mockito.doNothing().when(description).setMessage(any()); - - Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); - Mockito.when(abisHandlerUtil.getPacketStatus(any())).thenReturn(AbisConstant.PRE_ABIS_IDENTIFICATION); - Mockito.when(restClientService.getApi(any(), any(), anyString(), any(), any())) - .thenReturn("1233445566".getBytes("UTF-16")); - Mockito.when(registrationStatusMapperUtil.getStatusCode(any())).thenReturn(ERROR); - Mockito.doNothing().when(packetInfoManager).saveManualAdjudicationData(any(), any(), any(), any(), any(),any(),any()); - Mockito.doNothing().when(packetInfoManager).saveRegLostUinDet(any(), any(), any(), any(), any()); - - - ClassLoader classLoader = getClass().getClassLoader(); - - File mappingJsonFile = new File(classLoader.getResource("RegistrationProcessorIdentity.json").getFile()); - InputStream is = new FileInputStream(mappingJsonFile); - String value = IOUtils.toString(is); - Mockito.when(utility.getRegistrationProcessorMappingJson(anyString())).thenReturn(JsonUtil - .getJSONObject(JsonUtil.objectMapperReadValue(value, JSONObject.class), MappingJsonConstants.IDENTITY)); - Mockito.when(bioDedupeService.getFileByRegId(any(),any())).thenReturn("test".getBytes()); - - } - - /** - * Test bio dedupe success. - * - * @throws Exception - * the exception - */ - @Test - public void testNewInsertionPostProcessing() throws Exception { - - MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); - assertTrue(messageDto.getMessageBusAddress().toString() - .equalsIgnoreCase(MessageBusAddress.ABIS_HANDLER_BUS_IN.toString())); - - } - - /** - * Test new insertion to uin success. - * - * @throws Exception - * the exception - */ - @Test - public void testNewInsertionToUinSuccess() throws Exception { - Mockito.when(bioDedupeService.getFileByRegId(anyString(),anyString())).thenReturn(null); - ReflectionTestUtils.setField(bioDedupeProcessor, "infantDedupe", "N"); - Mockito.when(restClientService.getApi(any(), any(), anyString(), any(), any())).thenReturn(null); - Mockito.when(utility.getApplicantAge(any(),any(),any())).thenReturn(2); - MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); - - assertTrue(messageDto.getIsValid()); - assertFalse(messageDto.getInternalError()); - - } - - /** - * Test new insertion adult CBEFF not found exception. - * - * @throws Exception - * the exception - */ - @Test - public void testNewInsertionAdultCBEFFNotFoundException() throws Exception { - Mockito.doThrow(new CbeffNotFoundException("Exception")).when(cbeffValidateAndVerificatonService).validateBiometrics(any(), any()); - Mockito.when(bioDedupeService.getFileByRegId(anyString(),anyString())).thenReturn(null); - Mockito.when(restClientService.getApi(any(), any(), anyString(), any(), any())).thenReturn(null); - Mockito.when(utility.getApplicantAge(any(),any(),any())).thenReturn(12); - Mockito.when(registrationStatusMapperUtil - .getStatusCode(RegistrationExceptionTypeCode.CBEFF_NOT_PRESENT_EXCEPTION)).thenReturn("FAILED"); - MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); - assertTrue(messageDto.getIsValid()); - } - - /** - * Test new exception. - * - * @throws Exception - * the exception - */ - @Test - @Ignore - public void testNewException() throws Exception { - Mockito.when(bioDedupeService.getFileByRegId(anyString(),anyString())).thenReturn(null); - - ReflectionTestUtils.setField(bioDedupeProcessor, "ageLimit", "age"); - Mockito.when(restClientService.getApi(any(), any(), anyString(), any(), any())).thenReturn(null); - Mockito.when(utility.getApplicantAge(any(),any(),any())).thenReturn(12); - MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); - assertTrue(messageDto.getInternalError()); - assertFalse(messageDto.getIsValid()); - } - - /** - * Test new insertion IO exception. - * - * @throws Exception - * the exception - */ - @Test - public void testNewInsertionIOException() throws Exception { - Mockito.doThrow(new IOException("Exception")).when(cbeffValidateAndVerificatonService).validateBiometrics(any(), any()); - Mockito.when(bioDedupeService.getFileByRegId(anyString(),anyString())).thenReturn(null); - Mockito.when(restClientService.getApi(any(), any(), anyString(), any(), any())).thenReturn(null); - Mockito.when(utility.getApplicantAge(any(),any(),any())).thenThrow(new IOException("IOException")); - Mockito.when(registrationStatusMapperUtil - .getStatusCode(RegistrationExceptionTypeCode.IOEXCEPTION)).thenReturn("ERROR"); - MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); - assertTrue(messageDto.getInternalError()); - assertFalse(messageDto.getIsValid()); - } - - /** - * Test data access exception. - */ - @Test - public void testDataAccessException() { - Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())) - .thenThrow(new DataAccessException("DataAccessException") { - private static final long serialVersionUID = 1L; - }); - Mockito.when(registrationStatusMapperUtil - .getStatusCode(RegistrationExceptionTypeCode.DATA_ACCESS_EXCEPTION)).thenReturn("REPROCESS"); - MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); - assertTrue(messageDto.getInternalError()); - assertTrue(messageDto.getIsValid()); - } - - /** - * Test new identify to UIN stage. - * - * @throws Exception - * the exception - */ - @Test - public void testNewIdentifyToUINStage() throws Exception { - Mockito.when(abisHandlerUtil.getPacketStatus(any())).thenReturn(AbisConstant.POST_ABIS_IDENTIFICATION); - MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); - - assertTrue(messageDto.getIsValid()); - assertFalse(messageDto.getInternalError()); - } - - /** - * Test new identify to manual stage. - * - * @throws Exception - * the exception - */ - @Test - public void testNewIdentifyToManualStage() throws Exception { - - Set set = new HashSet<>(); - set.add("1"); - Mockito.when(abisHandlerUtil.getPacketStatus(any())).thenReturn(AbisConstant.POST_ABIS_IDENTIFICATION); - - Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(set); - MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); - - assertTrue(messageDto.getIsValid()); - assertFalse(messageDto.getInternalError()); - - } - - /** - * Test update insertion to handler. - * - * @throws Exception - * the exception - */ - @Test - public void testUpdateInsertionToHandler() throws Exception { - - PowerMockito.mockStatic(Utilities.class); - Mockito.when(utility.getGetRegProcessorDemographicIdentity()).thenReturn(IDENTITY); - - - registrationStatusDto.setRegistrationId("reg1234"); - registrationStatusDto.setRegistrationType("Update"); - Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); - - MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); - - assertEquals(messageDto.getMessageBusAddress().getAddress(), ABIS_HANDLER_BUS_IN); - } - - /** - * Test update insertion to UIN. - * - * @throws Exception - * the exception - */ - @Test - public void testUpdateInsertionToUIN() throws Exception { - - PowerMockito.mockStatic(Utilities.class); - Mockito.when(utility.getGetRegProcessorDemographicIdentity()).thenReturn(IDENTITY); - Mockito.when(priorityBasedPacketManagerService.getField(any(),any(),any(),any())).thenReturn(null); - Mockito.when(priorityBasedPacketManagerService.getFieldByMappingJsonKey(any(),any(),any(),any())).thenReturn(null); - - registrationStatusDto.setRegistrationId("reg1234"); - registrationStatusDto.setRegistrationType("Update"); - Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); - - MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); - - assertTrue(messageDto.getIsValid()); - assertFalse(messageDto.getInternalError()); - } - - /** - * Test bio de dup update packet handler processing success. - * - * @throws ApisResourceAccessException the apis resource access - * exception - * @throws IOException Signals that an I/O exception - * has occurred. - * @throws io.mosip.kernel.core.exception.IOException - * @throws PacketDecryptionFailureException - * @throws RegistrationProcessorCheckedException - */ - @Test - public void testBioDeDupUpdatePacketHandlerProcessingSuccess() throws ApisResourceAccessException, IOException, - io.mosip.kernel.core.exception.IOException, JsonProcessingException, PacketManagerException { - - registrationStatusDto.setRegistrationId("reg1234"); - registrationStatusDto.setRegistrationType("UPDATE"); - Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); - Mockito.when(abisHandlerUtil.getPacketStatus(any())).thenReturn(AbisConstant.POST_ABIS_IDENTIFICATION); - - Set matchedRidList = new HashSet<>(); - Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); - MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); - assertTrue(messageDto.getIsValid()); - assertFalse(messageDto.getInternalError()); - } - - /** - * Test bio de dup update packet handler processing failure. - * - * @throws ApisResourceAccessException the apis resource access - * exception - * @throws IOException Signals that an I/O exception - * has occurred. - * @throws io.mosip.kernel.core.exception.IOException - * @throws PacketDecryptionFailureException - * @throws RegistrationProcessorCheckedException - */ - @Test - @Ignore -// this test cases is being handeled in oneMatchFoundWithDifferentUinWithSingleMatchAutoRejectAsFalse() test Method. - public void testBioDeDupUpdatePacketHandlerProcessingFailure() throws ApisResourceAccessException, IOException, - PacketDecryptionFailureException, io.mosip.kernel.core.exception.IOException, JsonProcessingException, PacketManagerException { - registrationStatusDto.setRegistrationId("reg1234"); - registrationStatusDto.setRegistrationType("UPDATE"); - registrationStatusDto.setStatusCode("PROCESSING"); - Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); - Mockito.when(abisHandlerUtil.getPacketStatus(any())).thenReturn(AbisConstant.POST_ABIS_IDENTIFICATION); - - Set matchedRidList = new HashSet<>(); - matchedRidList.add("27847657360002520190320095010"); - Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); - ReflectionTestUtils.setField(bioDedupeProcessor, "biometricsUpdateSingleMatchAutoReject", false); - MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); - assertTrue(messageDto.getIsValid()); - assertFalse(messageDto.getInternalError()); - } - - /** - * Test lost packet validation matched id empty. - * - * @throws ApisResourceAccessException the apis resource access - * exception - * @throws IOException Signals that an I/O exception - * has occurred. - * @throws io.mosip.kernel.core.exception.IOException - * @throws PacketDecryptionFailureException - * @throws RegistrationProcessorCheckedException - */ - @Test - public void testLostPacketValidationMatchedIdEmpty() throws ApisResourceAccessException, IOException, - PacketDecryptionFailureException, io.mosip.kernel.core.exception.IOException, JsonProcessingException, PacketManagerException { - registrationStatusDto.setRegistrationId("reg1234"); - registrationStatusDto.setRegistrationType("LOST"); - Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); - Mockito.when(abisHandlerUtil.getPacketStatus(any())).thenReturn(AbisConstant.POST_ABIS_IDENTIFICATION); - Set matchedRidList = new HashSet<>(); - Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); - - MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); - assertFalse(messageDto.getIsValid()); - assertFalse(messageDto.getInternalError()); - } - - /** - * Test lost packet validation single matched reg id. - * - * @throws ApisResourceAccessException the apis resource access - * exception - * @throws IOException Signals that an I/O exception - * has occurred. - * @throws io.mosip.kernel.core.exception.IOException - * @throws PacketDecryptionFailureException - * @throws RegistrationProcessorCheckedException - */ - @Test - public void testLostPacketValidationSingleMatchedRegId() throws ApisResourceAccessException, IOException, - PacketDecryptionFailureException, io.mosip.kernel.core.exception.IOException, JsonProcessingException, PacketManagerException { - registrationStatusDto.setRegistrationId("reg1234"); - registrationStatusDto.setRegistrationType("LOST"); - Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); - Mockito.when(abisHandlerUtil.getPacketStatus(any())).thenReturn(AbisConstant.POST_ABIS_IDENTIFICATION); - Set matchedRidList = new HashSet<>(); - matchedRidList.add("27847657360002520190320095010"); - Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); - - MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); - assertTrue(messageDto.getIsValid()); - assertFalse(messageDto.getInternalError()); - } - - /** - * Test lost packet validation multiple matched reg id. - * - * @throws Exception - * the exception - */ - @Test - public void testLostPacketValidationMultipleMatchedRegId() throws Exception { - - registrationStatusDto.setRegistrationId("reg1234"); - registrationStatusDto.setRegistrationType("LOST"); - Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); - Mockito.when(abisHandlerUtil.getPacketStatus(any())).thenReturn(AbisConstant.POST_ABIS_IDENTIFICATION); - Set matchedRidList = new HashSet<>(); - matchedRidList.add("27847657360002520190320095010"); - matchedRidList.add("27847657360002520190320095011"); - Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); - - Mockito.when(priorityBasedPacketManagerService.getField("reg1234","gender","LOST", ProviderStageName.BIO_DEDUPE)).thenReturn("MALE"); - Mockito.when(priorityBasedPacketManagerService.getField("reg1234","dob", "LOST", ProviderStageName.BIO_DEDUPE)).thenReturn("2016/01/01"); - - Map map = new LinkedHashMap<>(); - map.put("gender", "MALE"); - map.put("dateOfBirth", "2016/01/01"); - JSONObject j1 = new JSONObject(map); - - Mockito.when(idRepoService.getIdJsonFromIDRepo(any(), any())).thenReturn(j1); - Mockito.when(utility.getApplicantAge(any(),any(),any())).thenReturn(12); - MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); - - assertFalse(messageDto.getIsValid()); - assertFalse(messageDto.getInternalError()); - } - - /** - * Test lost packet validation multiple matched reg id demo match. - * - * @throws Exception - * the exception - */ - @SuppressWarnings("unchecked") - @Test - public void testLostPacketValidationSingleDemoMatch() throws Exception { - - registrationStatusDto.setRegistrationId("reg1234"); - registrationStatusDto.setRegistrationType("LOST"); - Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); - Mockito.when(abisHandlerUtil.getPacketStatus(any())).thenReturn(AbisConstant.POST_ABIS_IDENTIFICATION); - Set matchedRidList = new HashSet<>(); - matchedRidList.add("27847657360002520190320095010"); - matchedRidList.add("27847657360002520190320095011"); - Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); - - JSONObject obj1 = new JSONObject(); - obj1.put("dateOfBirth", "2016/01/01"); - - JSONObject obj2 = new JSONObject(); - obj2.put("dateOfBirth", "2016/01/02"); - Mockito.when(idRepoService.getIdJsonFromIDRepo("27847657360002520190320095010", IDENTITY)).thenReturn(obj1); - Mockito.when(idRepoService.getIdJsonFromIDRepo("27847657360002520190320095011", IDENTITY)).thenReturn(obj2); - MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); - - assertFalse(messageDto.getInternalError()); - assertFalse(messageDto.getIsValid()); - } - - @SuppressWarnings("unchecked") - @Test - public void testPacketValidationSingleDemoMatch() throws Exception { - registrationStatusDto.setRegistrationId("reg1234"); - registrationStatusDto.setRegistrationType("LOST"); - Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); - Mockito.when(abisHandlerUtil.getPacketStatus(any())).thenReturn(AbisConstant.POST_ABIS_IDENTIFICATION); - Set matchedRidList = new HashSet<>(); - matchedRidList.add("27847657360002520190320095010"); - matchedRidList.add("27847657360002520190320095011"); - Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); - - JSONObject obj1 = new JSONObject(); - obj1.put("dateOfBirth", "2016/01/01"); - - JSONObject obj2 = new JSONObject(); - obj2.put("dateOfBirth", "2016/01/02"); - LinkedHashMap map = new LinkedHashMap(); - map.put("language", "eng"); - map.put("value", "Male"); - obj2.put("gender", map); - - Mockito.when(utility.getGetRegProcessorDemographicIdentity()).thenReturn(IDENTITY); - Mockito.when(idRepoService.getIdJsonFromIDRepo("27847657360002520190320095010", IDENTITY)).thenReturn(obj1); - Mockito.when(idRepoService.getIdJsonFromIDRepo("27847657360002520190320095011", IDENTITY)).thenReturn(obj2); - Mockito.when(priorityBasedPacketManagerService.getField("reg1234","dob","LOST", ProviderStageName.BIO_DEDUPE)).thenReturn("2016/01/01"); - MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); - - assertFalse(messageDto.getInternalError()); - assertTrue(messageDto.getIsValid()); - } - - @SuppressWarnings("unchecked") - @Test - public void testLostPacketValidationMultipleDemoMatch() throws Exception { - - registrationStatusDto.setRegistrationId("reg1234"); - registrationStatusDto.setRegistrationType("LOST"); - Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); - Mockito.when(abisHandlerUtil.getPacketStatus(any())).thenReturn(AbisConstant.POST_ABIS_IDENTIFICATION); - Set matchedRidList = new HashSet<>(); - matchedRidList.add("27847657360002520190320095010"); - matchedRidList.add("27847657360002520190320095011"); - matchedRidList.add("27847657360002520190320095012"); - Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); - - JSONObject obj1 = new JSONObject(); - obj1.put("dateOfBirth", "2016/01/01"); - - JSONObject obj2 = new JSONObject(); - obj2.put("dateOfBirth", "2016/01/02"); - Mockito.when(idRepoService.getIdJsonFromIDRepo("27847657360002520190320095010", IDENTITY)).thenReturn(obj1); - Mockito.when(idRepoService.getIdJsonFromIDRepo("27847657360002520190320095011", IDENTITY)).thenReturn(obj2); - Mockito.when(idRepoService.getIdJsonFromIDRepo("27847657360002520190320095012", IDENTITY)).thenReturn(obj1); - MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); - - assertFalse(messageDto.getInternalError()); - assertFalse(messageDto.getIsValid()); - } - - @Test - public void testLostPacketValidationCbeffNotFound() throws Exception { - Mockito.doThrow(new CbeffNotFoundException("Exception")).when(cbeffValidateAndVerificatonService).validateBiometrics(any(), any()); - registrationStatusDto.setRegistrationId("reg1234"); - registrationStatusDto.setRegistrationType("LOST"); - Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); - Mockito.when(abisHandlerUtil.getPacketStatus(any())).thenReturn(AbisConstant.POST_ABIS_IDENTIFICATION); - Mockito.when(bioDedupeService.getFileByRegId(anyString(),anyString())).thenReturn(null); - Mockito.when(restClientService.getApi(any(), any(), anyString(), any(), any())).thenReturn(null); - MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); - assertFalse(messageDto.getIsValid()); - } - - @Test - public void testLostPacketPreAbis() throws Exception { - - registrationStatusDto.setRegistrationId("reg1234"); - registrationStatusDto.setRegistrationType("LOST"); - Mockito.when(abisHandlerUtil.getPacketStatus(any())).thenReturn(AbisConstant.PRE_ABIS_IDENTIFICATION); - Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); - MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); - assertTrue(messageDto.getMessageBusAddress().toString() - .equalsIgnoreCase(MessageBusAddress.ABIS_HANDLER_BUS_IN.toString())); - } - - @Test - public void testApisResourceAccessException() throws Exception { - Mockito.doThrow(new ApisResourceAccessException("Exception")).when(cbeffValidateAndVerificatonService).validateBiometrics(any(), any()); - Mockito.when(bioDedupeService.getFileByRegId(anyString(),anyString())).thenReturn(null); - ApisResourceAccessException e=new ApisResourceAccessException(); - - - Mockito.doThrow(e).when(utility).getApplicantAge(any(),any(),any()); - Mockito.when(registrationStatusMapperUtil - .getStatusCode(RegistrationExceptionTypeCode.APIS_RESOURCE_ACCESS_EXCEPTION)).thenReturn("REPROCESS"); - MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); - - assertTrue(messageDto.getIsValid()); - assertTrue(messageDto.getInternalError()); - } - - - /* use case 1 -> No match of RID/AID found in bio dedupe: - This use case is handled in noMatchedRidFound(). - - use case 2 -> One match of RID/AID found at bio dedupe stage. UIN of the duplicate match is same as the update packet UIN - This use case is handled in noMatchedRidFound() because abisHandlerUtil.getUniqueRegIds() will - return the empty matched rid list because it rid's associated with current packet. - - use case 4 -> More than one match of RID/AID found at bio dedupe stage, all UIN of duplicate matches are same as update packet UIN: - This use case is handled in noMatchedRidFound() because abisHandlerUtil.getUniqueRegIds() will - return the empty matched rid list because it rid's associated with current packet. - */ - @Test - public void noMatchedRidFound() throws ApisResourceAccessException, IOException, - PacketDecryptionFailureException, io.mosip.kernel.core.exception.IOException, JsonProcessingException, PacketManagerException { - registrationStatusDto.setRegistrationId("27847657360002520190320095011"); - registrationStatusDto.setRegistrationType("UPDATE"); - registrationStatusDto.setStatusCode("PROCESSING"); - Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); - Mockito.when(abisHandlerUtil.getPacketStatus(any())).thenReturn(AbisConstant.POST_ABIS_IDENTIFICATION); - Set matchedRidList = new HashSet<>(); - Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); - ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(InternalRegistrationStatusDto.class); - MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); - Mockito.verify(registrationStatusService).updateRegistrationStatus(argumentCaptor.capture(),anyString(),anyString()); - Assert.assertEquals(argumentCaptor.getValue().getStatusCode(), RegistrationStatusCode.PROCESSING.name()); - assertTrue(messageDto.getIsValid()); - assertFalse(messageDto.getInternalError()); - } - /* - (when registration.processor.biometrics-update.single-match.auto-reject.enabled = true) - use case 3 -> One match of RID/AID found at bio dedupe, but UIN of the duplicate match is different from update packet UIN when AutoReject is True - - use case 5 -> More than one match of RID/AID found at bio dedupe stage, all duplicate matches have the same UIN but, they does not match with update packet UIN - This use case is handled in oneMatchFoundWithDifferentUinWithMatchAutoRejecAsTrue() - because abisHandlerUtil.getUniqueRegIds() will return the latest match for a particular uin. - */ - - @Test - public void oneMatchFoundWithDifferentUinWithMatchAutoRejecAsTrue() throws ApisResourceAccessException, IOException, - PacketDecryptionFailureException, io.mosip.kernel.core.exception.IOException, JsonProcessingException, PacketManagerException { - registrationStatusDto.setRegistrationId("27847657360002520190320095012"); - registrationStatusDto.setRegistrationType("UPDATE"); - registrationStatusDto.setStatusCode("PROCESSING"); - Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); - Mockito.when(abisHandlerUtil.getPacketStatus(any())).thenReturn(AbisConstant.POST_ABIS_IDENTIFICATION); - Set matchedRidList = new HashSet<>(); - matchedRidList.add("27847657360002520190320095011"); - Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); - Mockito.when(idRepoService.getUinByRid(anyString(),any())).thenReturn("9403107397"); - ReflectionTestUtils.setField(bioDedupeProcessor, "biometricsUpdateSingleMatchAutoReject", true); - ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(InternalRegistrationStatusDto.class); - MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); - Mockito.verify(registrationStatusService).updateRegistrationStatus(argumentCaptor.capture(),anyString(),anyString()); - assertFalse(messageDto.getIsValid()); - assertFalse(messageDto.getInternalError()); - Assert.assertEquals(argumentCaptor.getValue().getStatusCode(), RegistrationStatusCode.REJECTED.name()); - } - /* - (when registration.processor.biometrics-update.single-match.auto-reject.enabled = false) - use case 3 -> One match of RID/AID found at bio dedupe, but UIN of the duplicate match is different from update packet UIN when AutoReject is True - - use case 5 -> More than one match of RID/AID found at bio dedupe stage, all duplicate matches have the same UIN but, they does not match with update packet UIN. - This use case is handled in oneMatchFoundWithDifferentUinWithMatchAutoRejecAsTrue(). - Because abisHandlerUtil.getUniqueRegIds() will return the latest match for a particular uin. - */ - @Test - public void oneMatchFoundWithDifferentUinWithSingleMatchAutoRejectAsFalse() throws ApisResourceAccessException, IOException, - PacketDecryptionFailureException, io.mosip.kernel.core.exception.IOException, JsonProcessingException, PacketManagerException { - registrationStatusDto.setRegistrationId("27847657360002520190320095012"); - registrationStatusDto.setRegistrationType("UPDATE"); - registrationStatusDto.setStatusCode("PROCESSING"); - Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); - Mockito.when(abisHandlerUtil.getPacketStatus(any())).thenReturn(AbisConstant.POST_ABIS_IDENTIFICATION); - Set matchedRidList = new HashSet<>(); - matchedRidList.add("27847657360002520190320095011"); - Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); - Mockito.when(idRepoService.getUinByRid(anyString(),any())).thenReturn("9403107397"); - ReflectionTestUtils.setField(bioDedupeProcessor, "biometricsUpdateSingleMatchAutoReject", false); - ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(InternalRegistrationStatusDto.class); - MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); - Mockito.verify(registrationStatusService).updateRegistrationStatus(argumentCaptor.capture(),anyString(),anyString()); - Assert.assertEquals(messageDto.getMessageBusAddress(),MessageBusAddress.MANUAL_ADJUDICATION_BUS_IN); - assertTrue(messageDto.getIsValid()); - assertFalse(messageDto.getInternalError()); - Assert.assertEquals(argumentCaptor.getValue().getStatusCode(), RegistrationStatusCode.FAILED.name()); - } - - /* - use case 6 -> More than one match of RID/AID found at bio dedupe stage, all duplicate matches possess different UINs. - Among that one UIN matches with update packet UIN - This is not a valid use case. because abisHandlerUtil.getUniqueRegIds() will not return rid's associated with current packet. - */ - - /* - use case 7 -> More than one match of RID/AID found at bio dedupe stage, all duplicate matches possess different UINs. - Among that no UIN matches with update packet UIN. - abisHandlerUtil.getUniqueRegIds() returns the latest rids associated with uin's other than current packet uin. - */ - @Test - public void moreThenOneMatchFoundWithDifferentUin() throws ApisResourceAccessException, IOException, - PacketDecryptionFailureException, io.mosip.kernel.core.exception.IOException, JsonProcessingException, PacketManagerException { - registrationStatusDto.setRegistrationId("27847657360002520190320095014"); - registrationStatusDto.setRegistrationType("UPDATE"); - registrationStatusDto.setStatusCode("PROCESSING"); - Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); - Mockito.when(abisHandlerUtil.getPacketStatus(any())) - .thenReturn(AbisConstant.POST_ABIS_IDENTIFICATION); - - Set matchedRidList = new HashSet<>(); - matchedRidList.add("27847657360002520190320095013"); - matchedRidList.add("27847657360002520190320095012"); - Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); - Mockito.when(idRepoService.getUinByRid(anyString(),any())) - .thenReturn("9403107397") - .thenReturn("9403107399"); - ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(InternalRegistrationStatusDto.class); - MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); - Mockito.verify(registrationStatusService).updateRegistrationStatus(argumentCaptor.capture(),anyString(),anyString()); - Assert.assertEquals(messageDto.getMessageBusAddress(),MessageBusAddress.MANUAL_ADJUDICATION_BUS_IN); - assertTrue(messageDto.getIsValid()); - assertFalse(messageDto.getInternalError()); - Assert.assertEquals(argumentCaptor.getValue().getStatusCode(), RegistrationStatusCode.FAILED.name()); - } - /* - use case 8 -> One match of RID/AID found at bio dedupe stage, found AID/RID is in progress status and RID & UIN mapping is not done - abisHandlerUtil.getUniqueRegIds() returns RID which are in PROCESSING state (Except Update packet RID) - */ - @Test - public void oneMatchFoundWithStillInProgress () throws ApisResourceAccessException, IOException, - PacketDecryptionFailureException, io.mosip.kernel.core.exception.IOException, JsonProcessingException, PacketManagerException { - registrationStatusDto.setRegistrationId("27847657360002520190320095012"); - registrationStatusDto.setRegistrationType("UPDATE"); - registrationStatusDto.setStatusCode("PROCESSING"); - //This is existing rid which is in PROCESSING status. - InternalRegistrationStatusDto existingRegistrationStatusDto=new InternalRegistrationStatusDto(); - existingRegistrationStatusDto.setRegistrationId("27847657360002520190320095011"); - existingRegistrationStatusDto.setStatusCode("PROCESSING"); - Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())) - .thenReturn(registrationStatusDto). - thenReturn(existingRegistrationStatusDto); - Mockito.when(abisHandlerUtil.getPacketStatus(any())) - .thenReturn(AbisConstant.POST_ABIS_IDENTIFICATION); - Set matchedRidList = new HashSet<>(); - matchedRidList.add("27847657360002520190320095011"); //this rid is in processing state - Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); - Mockito.when(idRepoService.getUinByRid(anyString(),any())).thenReturn(null); - ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(InternalRegistrationStatusDto.class); - MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); - Mockito.verify(registrationStatusService).updateRegistrationStatus(argumentCaptor.capture(),anyString(),anyString()); - Assert.assertEquals(messageDto.getMessageBusAddress(),MessageBusAddress.MANUAL_ADJUDICATION_BUS_IN); - Assert.assertEquals(argumentCaptor.getValue().getStatusCode(), RegistrationStatusCode.FAILED.name()); - assertTrue(messageDto.getIsValid()); - assertFalse(messageDto.getInternalError()); - } - - /* - use case 9 -> More than one match of RID/AID found at bio dedupe stage, Among them one of the RID is in progress state & mapping is not done in repo. - abisHandlerUtil.getUniqueRegIds() returns RIDs (For which UIN is generated and it reached to RID repo) other than update packet UIN - and rid's in PROCESSING state (Except Update packet RID) - */ - @Test - public void moreThenOneMatchFoundWithOneIsStillInProgress () throws ApisResourceAccessException, IOException, - PacketDecryptionFailureException, io.mosip.kernel.core.exception.IOException, JsonProcessingException, PacketManagerException { - registrationStatusDto.setRegistrationId("27847657360002520190320095014"); - registrationStatusDto.setRegistrationType("UPDATE"); - registrationStatusDto.setStatusCode("PROCESSING"); - //This is existing rid which is in PROCESSING status. - InternalRegistrationStatusDto existingRegistrationStatusDto=new InternalRegistrationStatusDto(); - existingRegistrationStatusDto.setRegistrationId("27847657360002520190320095013"); - existingRegistrationStatusDto.setStatusCode("PROCESSING"); - Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())) - .thenReturn(registrationStatusDto). - thenReturn(existingRegistrationStatusDto); - Mockito.when(abisHandlerUtil.getPacketStatus(any())) - .thenReturn(AbisConstant.POST_ABIS_IDENTIFICATION); - Set matchedRidList = new HashSet<>(); - matchedRidList.add("27847657360002520190320095012"); - matchedRidList.add("27847657360002520190320095013"); - Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); - Mockito.when(idRepoService.getUinByRid(anyString(),any())) - .thenReturn("9403107397") - .thenReturn(null); - ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(InternalRegistrationStatusDto.class); - MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); - Mockito.verify(registrationStatusService).updateRegistrationStatus(argumentCaptor.capture(),anyString(),anyString()); - Assert.assertEquals(messageDto.getMessageBusAddress(),MessageBusAddress.MANUAL_ADJUDICATION_BUS_IN); - assertTrue(messageDto.getIsValid()); - assertFalse(messageDto.getInternalError()); - Assert.assertEquals(argumentCaptor.getValue().getStatusCode(), RegistrationStatusCode.FAILED.name()); - } - - /* - use case 10 -> More than one match of RID/AID found at bio dedupe stage, All RID is in progress state & mapping is not done in repo. - abisHandlerUtil.getUniqueRegIds() returns RIDs (For which UIN is generated and it reached to RID repo) other than update packet UIN - and rid's in PROCESSING state (Except Update packet RID) - */ - @Test - public void moreThenOneMatchFoundWithAllRidAreStillInProgress () throws ApisResourceAccessException, IOException, - PacketDecryptionFailureException, io.mosip.kernel.core.exception.IOException, JsonProcessingException, PacketManagerException { - registrationStatusDto.setRegistrationId("27847657360002520190320095014"); - registrationStatusDto.setRegistrationType("UPDATE"); - registrationStatusDto.setStatusCode("PROCESSING"); - //This is existing rid which is in PROCESSING status. - InternalRegistrationStatusDto existingRegistrationStatusDto1=new InternalRegistrationStatusDto(); - existingRegistrationStatusDto1.setRegistrationId("27847657360002520190320095013"); - existingRegistrationStatusDto1.setStatusCode("PROCESSING"); - //This is existing rid which is in PROCESSING status. - InternalRegistrationStatusDto existingRegistrationStatusDto2=new InternalRegistrationStatusDto(); - existingRegistrationStatusDto1.setRegistrationId("27847657360002520190320095012"); - existingRegistrationStatusDto1.setStatusCode("PROCESSING"); - Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())) - .thenReturn(registrationStatusDto) - .thenReturn(existingRegistrationStatusDto1) - .thenReturn(existingRegistrationStatusDto2); - Mockito.when(abisHandlerUtil.getPacketStatus(any())) - .thenReturn(AbisConstant.POST_ABIS_IDENTIFICATION); - Set matchedRidList = new HashSet<>(); - matchedRidList.add("27847657360002520190320095013"); - matchedRidList.add("27847657360002520190320095012"); - Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); - Mockito.when(idRepoService.getUinByRid(anyString(),any())).thenReturn(null); - ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(InternalRegistrationStatusDto.class); - MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); - Mockito.verify(registrationStatusService).updateRegistrationStatus(argumentCaptor.capture(),anyString(),anyString()); - Assert.assertEquals(messageDto.getMessageBusAddress(),MessageBusAddress.MANUAL_ADJUDICATION_BUS_IN); - assertTrue(messageDto.getIsValid()); - assertFalse(messageDto.getInternalError()); - Assert.assertEquals(argumentCaptor.getValue().getStatusCode(), RegistrationStatusCode.FAILED.name()); - } + /** The stage name. */ + private String stageName = "BioDedupeStage"; + + /** The utilities. */ + @Mock + Utilities utility; + + /** The rest client service. */ + @Mock + private RegistrationProcessorRestClientService restClientService; + + /** The entity. */ + @Mock + RegistrationStatusEntity entity = new RegistrationStatusEntity(); + + /** The abis handler util. */ + @Mock + private ABISHandlerUtil abisHandlerUtil; + + /** The map identity json string to object. */ + @Mock + ObjectMapper mapIdentityJsonStringToObject; + + @Mock + LogDescription description; + + @Mock + private Environment env; + + @Mock + private PriorityBasedPacketManagerService priorityBasedPacketManagerService; + + /** + * Sets the up. + * + * @throws Exception + * the exception + */ + @Before + public void setUp() throws Exception { + Mockito.doNothing().when(cbeffValidateAndVerificatonService).validateBiometrics(any(), any()); + Mockito.when(priorityBasedPacketManagerService.getFieldByMappingJsonKey(any(),any(),any(),any())).thenReturn("field"); + Mockito.when(priorityBasedPacketManagerService.getField(any(),any(),any(),any())).thenReturn("field"); + when(utility.getDefaultSource(any(), any())).thenReturn("reg-client"); + ReflectionTestUtils.setField(bioDedupeProcessor, "infantDedupe", "Y"); + ReflectionTestUtils.setField(bioDedupeProcessor, "ageLimit", "4"); + + AuditResponseDto auditResponseDto = new AuditResponseDto(); + ResponseWrapper responseWrapper = new ResponseWrapper<>(); + responseWrapper.setResponse(auditResponseDto); + Mockito.doReturn(responseWrapper).when(auditLogRequestBuilder).createAuditRequestBuilder( + "test case description", EventId.RPR_405.toString(), EventName.UPDATE.toString(), + EventType.BUSINESS.toString(), "1234testcase", ApiName.AUDIT); + + dto.setRid("reg1234"); + registrationStatusDto.setRegistrationId("reg1234"); + registrationStatusDto.setRegistrationType("new"); + + Mockito.doNothing().when(registrationStatusService).updateRegistrationStatus(any(), any(), any()); + Mockito.doNothing().when(description).setMessage(any()); + + Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); + Mockito.when(abisHandlerUtil.getPacketStatus(any())).thenReturn(AbisConstant.PRE_ABIS_IDENTIFICATION); + Mockito.when(restClientService.getApi(any(), any(), anyString(), any(), any())) + .thenReturn("1233445566".getBytes("UTF-16")); + Mockito.when(registrationStatusMapperUtil.getStatusCode(any())).thenReturn(ERROR); + Mockito.doNothing().when(packetInfoManager).saveManualAdjudicationData(any(), any(), any(), any(), any(),any(),any()); + Mockito.doNothing().when(packetInfoManager).saveRegLostUinDet(any(), any(), any(), any(), any()); + + + ClassLoader classLoader = getClass().getClassLoader(); + + File mappingJsonFile = new File(classLoader.getResource("RegistrationProcessorIdentity.json").getFile()); + InputStream is = new FileInputStream(mappingJsonFile); + String value = IOUtils.toString(is); + Mockito.when(utility.getRegistrationProcessorMappingJson(anyString())).thenReturn(JsonUtil + .getJSONObject(JsonUtil.objectMapperReadValue(value, JSONObject.class), MappingJsonConstants.IDENTITY)); + Mockito.when(bioDedupeService.getFileByRegId(any(),any())).thenReturn("test".getBytes()); + + } + + /** + * Test bio dedupe success. + * + * @throws Exception + * the exception + */ + @Test + public void testNewInsertionPostProcessing() throws Exception { + + MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); + assertTrue(messageDto.getMessageBusAddress().toString() + .equalsIgnoreCase(MessageBusAddress.ABIS_HANDLER_BUS_IN.toString())); + + } + + /** + * Test new insertion to uin success. + * + * @throws Exception + * the exception + */ + @Test + public void testNewInsertionToUinSuccess() throws Exception { + Mockito.when(bioDedupeService.getFileByRegId(anyString(),anyString())).thenReturn(null); + ReflectionTestUtils.setField(bioDedupeProcessor, "infantDedupe", "N"); + Mockito.when(restClientService.getApi(any(), any(), anyString(), any(), any())).thenReturn(null); + Mockito.when(utility.getApplicantAge(any(),any(),any())).thenReturn(2); + MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); + + assertTrue(messageDto.getIsValid()); + assertFalse(messageDto.getInternalError()); + + } + + /** + * Test new insertion adult CBEFF not found exception. + * + * @throws Exception + * the exception + */ + @Test + public void testNewInsertionAdultCBEFFNotFoundException() throws Exception { + Mockito.doThrow(new CbeffNotFoundException("Exception")).when(cbeffValidateAndVerificatonService).validateBiometrics(any(), any()); + Mockito.when(bioDedupeService.getFileByRegId(anyString(),anyString())).thenReturn(null); + Mockito.when(restClientService.getApi(any(), any(), anyString(), any(), any())).thenReturn(null); + Mockito.when(utility.getApplicantAge(any(),any(),any())).thenReturn(12); + Mockito.when(registrationStatusMapperUtil + .getStatusCode(RegistrationExceptionTypeCode.CBEFF_NOT_PRESENT_EXCEPTION)).thenReturn("FAILED"); + MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); + assertTrue(messageDto.getIsValid()); + } + + /** + * Test new exception. + * + * @throws Exception + * the exception + */ + @Test + @Ignore + public void testNewException() throws Exception { + Mockito.when(bioDedupeService.getFileByRegId(anyString(),anyString())).thenReturn(null); + + ReflectionTestUtils.setField(bioDedupeProcessor, "ageLimit", "age"); + Mockito.when(restClientService.getApi(any(), any(), anyString(), any(), any())).thenReturn(null); + Mockito.when(utility.getApplicantAge(any(),any(),any())).thenReturn(12); + MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); + assertTrue(messageDto.getInternalError()); + assertFalse(messageDto.getIsValid()); + } + + /** + * Test new insertion IO exception. + * + * @throws Exception + * the exception + */ + @Test + public void testNewInsertionIOException() throws Exception { + Mockito.doThrow(new IOException("Exception")).when(cbeffValidateAndVerificatonService).validateBiometrics(any(), any()); + Mockito.when(bioDedupeService.getFileByRegId(anyString(),anyString())).thenReturn(null); + Mockito.when(restClientService.getApi(any(), any(), anyString(), any(), any())).thenReturn(null); + Mockito.when(utility.getApplicantAge(any(),any(),any())).thenThrow(new IOException("IOException")); + Mockito.when(registrationStatusMapperUtil + .getStatusCode(RegistrationExceptionTypeCode.IOEXCEPTION)).thenReturn("ERROR"); + MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); + assertTrue(messageDto.getInternalError()); + assertFalse(messageDto.getIsValid()); + } + + /** + * Test data access exception. + */ + @Test + public void testDataAccessException() { + Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())) + .thenThrow(new DataAccessException("DataAccessException") { + private static final long serialVersionUID = 1L; + }); + Mockito.when(registrationStatusMapperUtil + .getStatusCode(RegistrationExceptionTypeCode.DATA_ACCESS_EXCEPTION)).thenReturn("REPROCESS"); + MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); + assertTrue(messageDto.getInternalError()); + assertTrue(messageDto.getIsValid()); + } + + /** + * Test new identify to UIN stage. + * + * @throws Exception + * the exception + */ + @Test + public void testNewIdentifyToUINStage() throws Exception { + Mockito.when(abisHandlerUtil.getPacketStatus(any())).thenReturn(AbisConstant.POST_ABIS_IDENTIFICATION); + MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); + + assertTrue(messageDto.getIsValid()); + assertFalse(messageDto.getInternalError()); + } + + /** + * Test new identify to manual stage. + * + * @throws Exception + * the exception + */ + @Test + public void testNewIdentifyToManualStage() throws Exception { + + Set set = new HashSet<>(); + set.add("1"); + Mockito.when(abisHandlerUtil.getPacketStatus(any())).thenReturn(AbisConstant.POST_ABIS_IDENTIFICATION); + + Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(set); + MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); + + assertTrue(messageDto.getIsValid()); + assertFalse(messageDto.getInternalError()); + + } + + /** + * Test update insertion to handler. + * + * @throws Exception + * the exception + */ + @Test + public void testUpdateInsertionToHandler() throws Exception { + + PowerMockito.mockStatic(Utilities.class); + Mockito.when(utility.getGetRegProcessorDemographicIdentity()).thenReturn(IDENTITY); + + + registrationStatusDto.setRegistrationId("reg1234"); + registrationStatusDto.setRegistrationType("Update"); + Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); + + MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); + + assertEquals(messageDto.getMessageBusAddress().getAddress(), ABIS_HANDLER_BUS_IN); + } + + /** + * Test update insertion to UIN. + * + * @throws Exception + * the exception + */ + @Test + public void testUpdateInsertionToUIN() throws Exception { + + PowerMockito.mockStatic(Utilities.class); + Mockito.when(utility.getGetRegProcessorDemographicIdentity()).thenReturn(IDENTITY); + Mockito.when(priorityBasedPacketManagerService.getField(any(),any(),any(),any())).thenReturn(null); + Mockito.when(priorityBasedPacketManagerService.getFieldByMappingJsonKey(any(),any(),any(),any())).thenReturn(null); + + registrationStatusDto.setRegistrationId("reg1234"); + registrationStatusDto.setRegistrationType("Update"); + Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); + + MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); + + assertTrue(messageDto.getIsValid()); + assertFalse(messageDto.getInternalError()); + } + + /** + * Test bio de dup update packet handler processing success. + * + * @throws ApisResourceAccessException the apis resource access + * exception + * @throws IOException Signals that an I/O exception + * has occurred. + * @throws io.mosip.kernel.core.exception.IOException + * @throws PacketDecryptionFailureException + * @throws RegistrationProcessorCheckedException + */ + @Test + public void testBioDeDupUpdatePacketHandlerProcessingSuccess() throws ApisResourceAccessException, IOException, + io.mosip.kernel.core.exception.IOException, JsonProcessingException, PacketManagerException { + + registrationStatusDto.setRegistrationId("reg1234"); + registrationStatusDto.setRegistrationType("UPDATE"); + Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); + Mockito.when(abisHandlerUtil.getPacketStatus(any())).thenReturn(AbisConstant.POST_ABIS_IDENTIFICATION); + + Set matchedRidList = new HashSet<>(); + Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); + MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); + assertTrue(messageDto.getIsValid()); + assertFalse(messageDto.getInternalError()); + } + + /** + * Test bio de dup update packet handler processing failure. + * + * @throws ApisResourceAccessException the apis resource access + * exception + * @throws IOException Signals that an I/O exception + * has occurred. + * @throws io.mosip.kernel.core.exception.IOException + * @throws PacketDecryptionFailureException + * @throws RegistrationProcessorCheckedException + */ + @Test + public void testBioDeDupUpdatePacketHandlerProcessingFailure() throws ApisResourceAccessException, IOException, + PacketDecryptionFailureException, io.mosip.kernel.core.exception.IOException, JsonProcessingException, PacketManagerException { + registrationStatusDto.setRegistrationId("reg1234"); + registrationStatusDto.setRegistrationType("UPDATE"); + Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); + Mockito.when(abisHandlerUtil.getPacketStatus(any())).thenReturn(AbisConstant.POST_ABIS_IDENTIFICATION); + + Set matchedRidList = new HashSet<>(); + matchedRidList.add("27847657360002520190320095010"); + Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); + + MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); + assertTrue(messageDto.getIsValid()); + assertFalse(messageDto.getInternalError()); + } + + /** + * Test lost packet validation matched id empty. + * + * @throws ApisResourceAccessException the apis resource access + * exception + * @throws IOException Signals that an I/O exception + * has occurred. + * @throws io.mosip.kernel.core.exception.IOException + * @throws PacketDecryptionFailureException + * @throws RegistrationProcessorCheckedException + */ + @Test + public void testLostPacketValidationMatchedIdEmpty() throws ApisResourceAccessException, IOException, + PacketDecryptionFailureException, io.mosip.kernel.core.exception.IOException, JsonProcessingException, PacketManagerException { + registrationStatusDto.setRegistrationId("reg1234"); + registrationStatusDto.setRegistrationType("LOST"); + Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); + Mockito.when(abisHandlerUtil.getPacketStatus(any())).thenReturn(AbisConstant.POST_ABIS_IDENTIFICATION); + Set matchedRidList = new HashSet<>(); + Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); + + MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); + assertFalse(messageDto.getIsValid()); + assertFalse(messageDto.getInternalError()); + } + + /** + * Test lost packet validation single matched reg id. + * + * @throws ApisResourceAccessException the apis resource access + * exception + * @throws IOException Signals that an I/O exception + * has occurred. + * @throws io.mosip.kernel.core.exception.IOException + * @throws PacketDecryptionFailureException + * @throws RegistrationProcessorCheckedException + */ + @Test + public void testLostPacketValidationSingleMatchedRegId() throws ApisResourceAccessException, IOException, + PacketDecryptionFailureException, io.mosip.kernel.core.exception.IOException, JsonProcessingException, PacketManagerException { + registrationStatusDto.setRegistrationId("reg1234"); + registrationStatusDto.setRegistrationType("LOST"); + Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); + Mockito.when(abisHandlerUtil.getPacketStatus(any())).thenReturn(AbisConstant.POST_ABIS_IDENTIFICATION); + Set matchedRidList = new HashSet<>(); + matchedRidList.add("27847657360002520190320095010"); + Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); + + MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); + assertTrue(messageDto.getIsValid()); + assertFalse(messageDto.getInternalError()); + } + + /** + * Test lost packet validation multiple matched reg id. + * + * @throws Exception + * the exception + */ + @Test + public void testLostPacketValidationMultipleMatchedRegId() throws Exception { + + registrationStatusDto.setRegistrationId("reg1234"); + registrationStatusDto.setRegistrationType("LOST"); + Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); + Mockito.when(abisHandlerUtil.getPacketStatus(any())).thenReturn(AbisConstant.POST_ABIS_IDENTIFICATION); + Set matchedRidList = new HashSet<>(); + matchedRidList.add("27847657360002520190320095010"); + matchedRidList.add("27847657360002520190320095011"); + Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); + + Mockito.when(priorityBasedPacketManagerService.getField("reg1234","gender","LOST", ProviderStageName.BIO_DEDUPE)).thenReturn("MALE"); + Mockito.when(priorityBasedPacketManagerService.getField("reg1234","dob", "LOST", ProviderStageName.BIO_DEDUPE)).thenReturn("2016/01/01"); + + Map map = new LinkedHashMap<>(); + map.put("gender", "MALE"); + map.put("dateOfBirth", "2016/01/01"); + JSONObject j1 = new JSONObject(map); + + Mockito.when(idRepoService.getIdJsonFromIDRepo(any(), any())).thenReturn(j1); + Mockito.when(utility.getApplicantAge(any(),any(),any())).thenReturn(12); + MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); + + assertFalse(messageDto.getIsValid()); + assertFalse(messageDto.getInternalError()); + } + + /** + * Test lost packet validation multiple matched reg id demo match. + * + * @throws Exception + * the exception + */ + @SuppressWarnings("unchecked") + @Test + public void testLostPacketValidationSingleDemoMatch() throws Exception { + + registrationStatusDto.setRegistrationId("reg1234"); + registrationStatusDto.setRegistrationType("LOST"); + Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); + Mockito.when(abisHandlerUtil.getPacketStatus(any())).thenReturn(AbisConstant.POST_ABIS_IDENTIFICATION); + Set matchedRidList = new HashSet<>(); + matchedRidList.add("27847657360002520190320095010"); + matchedRidList.add("27847657360002520190320095011"); + Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); + + JSONObject obj1 = new JSONObject(); + obj1.put("dateOfBirth", "2016/01/01"); + + JSONObject obj2 = new JSONObject(); + obj2.put("dateOfBirth", "2016/01/02"); + Mockito.when(idRepoService.getIdJsonFromIDRepo("27847657360002520190320095010", IDENTITY)).thenReturn(obj1); + Mockito.when(idRepoService.getIdJsonFromIDRepo("27847657360002520190320095011", IDENTITY)).thenReturn(obj2); + MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); + + assertFalse(messageDto.getInternalError()); + assertFalse(messageDto.getIsValid()); + } + + @SuppressWarnings("unchecked") + @Test + public void testPacketValidationSingleDemoMatch() throws Exception { + registrationStatusDto.setRegistrationId("reg1234"); + registrationStatusDto.setRegistrationType("LOST"); + Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); + Mockito.when(abisHandlerUtil.getPacketStatus(any())).thenReturn(AbisConstant.POST_ABIS_IDENTIFICATION); + Set matchedRidList = new HashSet<>(); + matchedRidList.add("27847657360002520190320095010"); + matchedRidList.add("27847657360002520190320095011"); + Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); + + JSONObject obj1 = new JSONObject(); + obj1.put("dateOfBirth", "2016/01/01"); + + JSONObject obj2 = new JSONObject(); + obj2.put("dateOfBirth", "2016/01/02"); + LinkedHashMap map = new LinkedHashMap(); + map.put("language", "eng"); + map.put("value", "Male"); + obj2.put("gender", map); + + Mockito.when(utility.getGetRegProcessorDemographicIdentity()).thenReturn(IDENTITY); + Mockito.when(idRepoService.getIdJsonFromIDRepo("27847657360002520190320095010", IDENTITY)).thenReturn(obj1); + Mockito.when(idRepoService.getIdJsonFromIDRepo("27847657360002520190320095011", IDENTITY)).thenReturn(obj2); + Mockito.when(priorityBasedPacketManagerService.getField("reg1234","dob","LOST", ProviderStageName.BIO_DEDUPE)).thenReturn("2016/01/01"); + MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); + + assertFalse(messageDto.getInternalError()); + assertTrue(messageDto.getIsValid()); + } + + @SuppressWarnings("unchecked") + @Test + public void testLostPacketValidationMultipleDemoMatch() throws Exception { + + registrationStatusDto.setRegistrationId("reg1234"); + registrationStatusDto.setRegistrationType("LOST"); + Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); + Mockito.when(abisHandlerUtil.getPacketStatus(any())).thenReturn(AbisConstant.POST_ABIS_IDENTIFICATION); + Set matchedRidList = new HashSet<>(); + matchedRidList.add("27847657360002520190320095010"); + matchedRidList.add("27847657360002520190320095011"); + matchedRidList.add("27847657360002520190320095012"); + Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); + + JSONObject obj1 = new JSONObject(); + obj1.put("dateOfBirth", "2016/01/01"); + + JSONObject obj2 = new JSONObject(); + obj2.put("dateOfBirth", "2016/01/02"); + Mockito.when(idRepoService.getIdJsonFromIDRepo("27847657360002520190320095010", IDENTITY)).thenReturn(obj1); + Mockito.when(idRepoService.getIdJsonFromIDRepo("27847657360002520190320095011", IDENTITY)).thenReturn(obj2); + Mockito.when(idRepoService.getIdJsonFromIDRepo("27847657360002520190320095012", IDENTITY)).thenReturn(obj1); + MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); + + assertFalse(messageDto.getInternalError()); + assertFalse(messageDto.getIsValid()); + } + + @Test + public void testLostPacketValidationCbeffNotFound() throws Exception { + Mockito.doThrow(new CbeffNotFoundException("Exception")).when(cbeffValidateAndVerificatonService).validateBiometrics(any(), any()); + registrationStatusDto.setRegistrationId("reg1234"); + registrationStatusDto.setRegistrationType("LOST"); + Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); + Mockito.when(abisHandlerUtil.getPacketStatus(any())).thenReturn(AbisConstant.POST_ABIS_IDENTIFICATION); + Mockito.when(bioDedupeService.getFileByRegId(anyString(),anyString())).thenReturn(null); + Mockito.when(restClientService.getApi(any(), any(), anyString(), any(), any())).thenReturn(null); + MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); + assertFalse(messageDto.getIsValid()); + } + + @Test + public void testLostPacketPreAbis() throws Exception { + + registrationStatusDto.setRegistrationId("reg1234"); + registrationStatusDto.setRegistrationType("LOST"); + Mockito.when(abisHandlerUtil.getPacketStatus(any())).thenReturn(AbisConstant.PRE_ABIS_IDENTIFICATION); + Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); + MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); + assertTrue(messageDto.getMessageBusAddress().toString() + .equalsIgnoreCase(MessageBusAddress.ABIS_HANDLER_BUS_IN.toString())); + } + + @Test + public void testApisResourceAccessException() throws Exception { + Mockito.doThrow(new ApisResourceAccessException("Exception")).when(cbeffValidateAndVerificatonService).validateBiometrics(any(), any()); + Mockito.when(bioDedupeService.getFileByRegId(anyString(),anyString())).thenReturn(null); + ApisResourceAccessException e=new ApisResourceAccessException(); + + + Mockito.doThrow(e).when(utility).getApplicantAge(any(),any(),any()); + Mockito.when(registrationStatusMapperUtil + .getStatusCode(RegistrationExceptionTypeCode.APIS_RESOURCE_ACCESS_EXCEPTION)).thenReturn("REPROCESS"); + MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); + + assertTrue(messageDto.getIsValid()); + assertTrue(messageDto.getInternalError()); + } } \ No newline at end of file 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 00dbcc6cdb8..768420770d7 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 @@ -200,9 +200,6 @@ public enum StatusUtil { LOST_PACKET_MULTIPLE_MATCH_FOUND(StatusConstants.BIO_DEDUPE_MODULE_FAILED + "003", "Multiple Match was Found for the Biometrics Received"), - UPDATE_PACKET_BIOMETRICS_MATCHED_WITH_OTHER(StatusConstants.BIO_DEDUPE_MODULE_FAILED + "004", - "Biometric match found with another user"), - // Biometric authentication stage BIOMETRIC_AUTHENTICATION_FAILED(StatusConstants.BIO_METRIC_AUTHENTICATION_MODULE_FAILED + "001", "Biometric Authentication has Failed"),