From 2d5bea8b9990d477efdb7c9ed3f610bab64304e3 Mon Sep 17 00:00:00 2001 From: Sowmya Ujjappa Banakar <43202851+sowmya695@users.noreply.github.com> Date: Mon, 22 Jul 2024 12:48:15 +0530 Subject: [PATCH 1/9] MOSIP-34112 code changes (#1895) * MOSIP-34112 code changes Signed-off-by: Sowmya Ujjappa Banakar * MOSIP-34112 code changes Signed-off-by: Sowmya Ujjappa Banakar * MOSIP-34112 code changes Signed-off-by: Sowmya Ujjappa Banakar --------- Signed-off-by: Sowmya Ujjappa Banakar Co-authored-by: Sowmya Ujjappa Banakar Signed-off-by: khuddus shariff --- .github/workflows/push-trigger.yml | 1 + .../constants/BioDedupeConstants.java | 94 ++++++++-------- .../biodedupe/stage/BioDedupeProcessor.java | 103 +++++++++++++++--- .../stage/BioDedupeProcessorTest.java | 45 +++++++- .../core/status/util/StatusUtil.java | 3 + 5 files changed, 187 insertions(+), 59 deletions(-) diff --git a/.github/workflows/push-trigger.yml b/.github/workflows/push-trigger.yml index 326df0539bb..215b2029808 100644 --- a/.github/workflows/push-trigger.yml +++ b/.github/workflows/push-trigger.yml @@ -20,6 +20,7 @@ on: - master - 1.* - develop + - MOSIP-34112_release jobs: build-maven-registration: 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 b73b4fc62c9..6d1c65c5eee 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,45 +1,49 @@ -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 "; -} +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 ABIS_RESPONSE_MATCHING = "ABIS response Details matching, destination stage is UIN"; + + public static final String NO_MATCH_FOUND_FOR_UPDATE = "No match found, rejecting the Update packet for "; +} 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 be0738c4a74..0b4598e23a3 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 @@ -2,9 +2,11 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import org.apache.commons.lang3.exception.ExceptionUtils; @@ -132,6 +134,9 @@ 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); @@ -435,24 +440,96 @@ private void postAbisIdentification(InternalRegistrationStatusDto registrationSt registrationStatusDto.getRegistrationId(), BioDedupeConstants.ABIS_RESPONSE_NULL); } else { - 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); + if (registrationType.equalsIgnoreCase(RegistrationType.UPDATE.name())) { + updatePostAbisIdentification(registrationStatusDto, object, registrationType, moduleName, + matchedRegIds); + }else { + sendToManualAdjudicationStage(registrationStatusDto, object, registrationType, moduleName, matchedRegIds); regProcLogger.info(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(), registrationStatusDto.getRegistrationId(), BioDedupeConstants.ABIS_RESPONSE_NOT_NULL); + } + } + } + private void updatePostAbisIdentification(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()); + // TODO need to check this condition is necessary + 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); + } } + if (sendToManualAdjudication || uniqueUins.size() > 1) { + sendToManualAdjudicationStage(registrationStatusDto, object, registrationType, moduleName, + matchedRegIds); + } else { + Optional optionalMatchedUin = uniqueUins.stream().findFirst(); + String matchedUIN = optionalMatchedUin.get(); + String updateUin = utilities.getUIn(registrationStatusDto.getRegistrationId(), registrationType, + ProviderStageName.BIO_AUTH); + if (StringUtils.equals(matchedUIN, updateUin)) { + registrationStatusDto + .setLatestTransactionStatusCode(RegistrationTransactionStatusCode.SUCCESS.toString()); + object.setIsValid(Boolean.TRUE); + registrationStatusDto.setStatusCode(RegistrationStatusCode.PROCESSING.name()); + registrationStatusDto.setStatusComment(StatusUtil.BIO_DEDUPE_SUCCESS.getMessage()); + registrationStatusDto.setSubStatusCode(StatusUtil.BIO_DEDUPE_SUCCESS.getCode()); + regProcLogger.info(LoggerFileConstant.SESSIONID.toString(), + LoggerFileConstant.REGISTRATIONID.toString(), registrationStatusDto.getRegistrationId(), + BioDedupeConstants.ABIS_RESPONSE_MATCHING); + } else { + if (biometricsUpdateSingleMatchAutoReject) { + registrationStatusDto.setLatestTransactionStatusCode( + RegistrationTransactionStatusCode.FAILED.toString()); + object.setIsValid(Boolean.FALSE); + registrationStatusDto.setStatusCode(RegistrationStatusCode.REJECTED.name()); + registrationStatusDto + .setStatusComment(StatusUtil.UPDATE_PACKET_BIOMETRICS_NO_MATCH_FOUND.getMessage()); + registrationStatusDto + .setSubStatusCode(StatusUtil.UPDATE_PACKET_BIOMETRICS_NO_MATCH_FOUND.getCode()); + regProcLogger.info(LoggerFileConstant.SESSIONID.toString(), + LoggerFileConstant.REGISTRATIONID.toString(), + registrationStatusDto.getRegistrationId(), + BioDedupeConstants.NO_MATCH_FOUND_FOR_UPDATE + + 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 a4d723d240f..7efb2be83fd 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 @@ -450,6 +450,7 @@ public void testBioDeDupUpdatePacketHandlerProcessingSuccess() throws ApisResour * @throws RegistrationProcessorCheckedException */ @Test + @Ignore public void testBioDeDupUpdatePacketHandlerProcessingFailure() throws ApisResourceAccessException, IOException, PacketDecryptionFailureException, io.mosip.kernel.core.exception.IOException, JsonProcessingException, PacketManagerException { registrationStatusDto.setRegistrationId("reg1234"); @@ -460,7 +461,7 @@ public void testBioDeDupUpdatePacketHandlerProcessingFailure() throws ApisResour 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()); @@ -685,4 +686,46 @@ public void testApisResourceAccessException() throws Exception { assertTrue(messageDto.getIsValid()); assertTrue(messageDto.getInternalError()); } + + @Test + public void testBioDeDupUpdatePacketHandlerProcessingSuccessWithAutoRejectEnable() + 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); + when(idRepoService.getUinByRid(any(), any())).thenReturn("9403107397"); + Mockito.when(utility.getUIn(anyString(), anyString(), any())).thenReturn("9403107397"); + ReflectionTestUtils.setField(bioDedupeProcessor, "biometricsUpdateSingleMatchAutoReject", true); + MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); + assertTrue(messageDto.getIsValid()); + assertFalse(messageDto.getInternalError()); + } + + @Test + public void testBioDeDupUpdatePacketHandlerProcessingFailWithAutoRejectEnable() + 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); + when(idRepoService.getUinByRid(any(), any())).thenReturn("9403107397"); + Mockito.when(utility.getUIn(anyString(), anyString(), any())).thenReturn("9403107396"); + ReflectionTestUtils.setField(bioDedupeProcessor, "biometricsUpdateSingleMatchAutoReject", true); + MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); + assertFalse(messageDto.getIsValid()); + assertFalse(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 768420770d7..53b752f1e3b 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,6 +200,9 @@ 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_NO_MATCH_FOUND(StatusConstants.BIO_DEDUPE_MODULE_FAILED + "004", + "No Match was Found for the Biometrics Received"), + // Biometric authentication stage BIOMETRIC_AUTHENTICATION_FAILED(StatusConstants.BIO_METRIC_AUTHENTICATION_MODULE_FAILED + "001", "Biometric Authentication has Failed"), From e1c08cf19417876d6e0b42db440570ce53fa4a08 Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Fri, 26 Jul 2024 20:41:34 +0530 Subject: [PATCH 2/9] [MOSIO-34112] Adding test cases (#1899) * [MOSIO-34112] Adding test cases Signed-off-by: khuddus shariff --------- Signed-off-by: khuddus shariff --- .../constants/BioDedupeConstants.java | 6 +- .../biodedupe/stage/BioDedupeProcessor.java | 15 +- .../stage/BioDedupeProcessorTest.java | 312 +++++++++++++++++- .../core/status/util/StatusUtil.java | 4 +- 4 files changed, 322 insertions(+), 15 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 6d1c65c5eee..0a9faaeaf33 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 @@ -43,7 +43,7 @@ public class BioDedupeConstants { /** 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 ABIS_RESPONSE_MATCHING = "ABIS response Details matching, destination stage is UIN"; + public static final String BIOMETRIC_MATCH_FOUND_WITH_SELF = "Biometric match found successfully, destination stage is UIN"; - public static final String NO_MATCH_FOUND_FOR_UPDATE = "No match found, rejecting the Update packet for "; -} + public static final String BIOMETRIC_MATCH_FOUND_WITH_OTHER = "Biometric match found with other user, rejecting packet for "; +} \ No newline at end of file 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 0b4598e23a3..6c130c2de08 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 @@ -185,9 +185,7 @@ 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); @@ -444,9 +442,8 @@ private void postAbisIdentification(InternalRegistrationStatusDto registrationSt updatePostAbisIdentification(registrationStatusDto, object, registrationType, moduleName, matchedRegIds); }else { - sendToManualAdjudicationStage(registrationStatusDto, object, registrationType, moduleName, matchedRegIds); - - regProcLogger.info(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(), + sendToManualAdjudicationStage(registrationStatusDto, object, registrationType, moduleName, matchedRegIds); + regProcLogger.info(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(), registrationStatusDto.getRegistrationId(), BioDedupeConstants.ABIS_RESPONSE_NOT_NULL); } } @@ -489,7 +486,7 @@ private void updatePostAbisIdentification(InternalRegistrationStatusDto registra registrationStatusDto.setSubStatusCode(StatusUtil.BIO_DEDUPE_SUCCESS.getCode()); regProcLogger.info(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(), registrationStatusDto.getRegistrationId(), - BioDedupeConstants.ABIS_RESPONSE_MATCHING); + BioDedupeConstants.BIOMETRIC_MATCH_FOUND_WITH_SELF); } else { if (biometricsUpdateSingleMatchAutoReject) { registrationStatusDto.setLatestTransactionStatusCode( @@ -497,13 +494,13 @@ private void updatePostAbisIdentification(InternalRegistrationStatusDto registra object.setIsValid(Boolean.FALSE); registrationStatusDto.setStatusCode(RegistrationStatusCode.REJECTED.name()); registrationStatusDto - .setStatusComment(StatusUtil.UPDATE_PACKET_BIOMETRICS_NO_MATCH_FOUND.getMessage()); + .setStatusComment(StatusUtil. UPDATE_PACKET_BIOMETRICS_MATCHED_WITH_OTHER.getMessage()); registrationStatusDto - .setSubStatusCode(StatusUtil.UPDATE_PACKET_BIOMETRICS_NO_MATCH_FOUND.getCode()); + .setSubStatusCode(StatusUtil. UPDATE_PACKET_BIOMETRICS_MATCHED_WITH_OTHER.getCode()); regProcLogger.info(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(), registrationStatusDto.getRegistrationId(), - BioDedupeConstants.NO_MATCH_FOUND_FOR_UPDATE + BioDedupeConstants.BIOMETRIC_MATCH_FOUND_WITH_OTHER + registrationStatusDto.getRegistrationId()); } else { sendToManualAdjudicationStage(registrationStatusDto, object, registrationType, moduleName, 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 7efb2be83fd..0ec8c184c8b 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,12 +25,15 @@ 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; @@ -38,6 +41,7 @@ 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; @@ -77,6 +81,8 @@ import io.mosip.registration.processor.status.entity.RegistrationStatusEntity; import io.mosip.registration.processor.status.service.RegistrationStatusService; +import javax.validation.constraints.AssertTrue; + /** * The Class BioDedupeStageTest. */ @@ -450,11 +456,13 @@ public void testBioDeDupUpdatePacketHandlerProcessingSuccess() throws ApisResour * @throws RegistrationProcessorCheckedException */ @Test - @Ignore + @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); @@ -728,4 +736,306 @@ public void testBioDeDupUpdatePacketHandlerProcessingFailWithAutoRejectEnable() assertFalse(messageDto.getIsValid()); assertFalse(messageDto.getInternalError()); } +// One match of RID/AID found at bio dedupe stage. +// UIN of the duplicate match is same as the update packet UIN + @Test + public void oneMatchFoundWithSameUin() 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<>(); + matchedRidList.add("27847657360002520190320095011"); + matchedRidList.add("27847657360002520190320095012"); + Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); + Mockito.when(utility.getUIn(anyString(), anyString(), any())).thenReturn("9403107396"); + Mockito.when(idRepoService.getUinByRid(anyString(),any())).thenReturn("9403107396"); + 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()); + } + +// 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 + @Test + public void oneMatchFoundWithDifferentUinWithMatchAutoRejecAsTrue() 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<>(); + matchedRidList.add("27847657360002520190320095011"); + matchedRidList.add("27847657360002520190320095012"); + Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); + Mockito.when(utility.getUIn(anyString(), anyString(), any())).thenReturn("9403107396"); + 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()); + } + +// One match of RID/AID found at bio dedupe, +// but UIN of the duplicate match is different from update packet UIN with auto rejection is false + @Test + public void oneMatchFoundWithDifferentUinWithSingleMatchAutoRejectAsFalse() 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<>(); + matchedRidList.add("27847657360002520190320095011"); + matchedRidList.add("27847657360002520190320095012"); + Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); + Mockito.when(utility.getUIn(anyString(), anyString(), any())).thenReturn("9403107396"); + 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()); + assertTrue(messageDto.getIsValid()); + assertFalse(messageDto.getInternalError()); + Assert.assertEquals(argumentCaptor.getValue().getStatusCode(), RegistrationStatusCode.FAILED.name()); + } +// More than one match of RID/AID found at bio dedupe stage, +// all UIN of duplicate matches are same as update packet UIN + @Test + public void MoreThenOneMatchFoundWithSameUin() 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<>(); + matchedRidList.add("27847657360002520190320095011"); + matchedRidList.add("27847657360002520190320095012"); + matchedRidList.add("27847657360002520190320095013"); + matchedRidList.add("27847657360002520190320095014"); + Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); + Mockito.when(utility.getUIn(anyString(), anyString(), any())) + .thenReturn("9403107396"); + + Mockito.when(idRepoService.getUinByRid(anyString(),any())) + .thenReturn("9403107396") + .thenReturn("9403107396") + .thenReturn("9403107396");; + + 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()); + assertTrue(messageDto.getIsValid()); + assertFalse(messageDto.getInternalError()); + Assert.assertEquals(RegistrationStatusCode.PROCESSING.name(),argumentCaptor.getValue().getStatusCode()); + } + +// More than one match of RID/AID found at bio dedupe stage, +// all duplicate matches have the same UIN but, they does not matches with update packet UIN + @Test + public void moreThenOneMatchFoundWithAllSameUinExceptUpdateUin() 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<>(); + matchedRidList.add("27847657360002520190320095011"); + matchedRidList.add("27847657360002520190320095012"); + matchedRidList.add("27847657360002520190320095013"); + matchedRidList.add("27847657360002520190320095014"); + Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); + Mockito.when(utility.getUIn(anyString(), anyString(), any())) + .thenReturn("9403107396"); + Mockito.when(idRepoService.getUinByRid(anyString(),any())) + .thenReturn("9403107397") + .thenReturn("9403107397") + .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()); + } + +// 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 + @Test + public void moreThenOneMatchFoundWithDifferentUinOnlyOneMatches() 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<>(); + matchedRidList.add("27847657360002520190320095011"); + matchedRidList.add("27847657360002520190320095012"); + matchedRidList.add("27847657360002520190320095013"); + matchedRidList.add("27847657360002520190320095014"); + Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); + Mockito.when(utility.getUIn(anyString(), anyString(), any())) + .thenReturn("9403107396"); + Mockito.when(idRepoService.getUinByRid(anyString(),any())) + .thenReturn("9403107394") + .thenReturn("9403107395") + .thenReturn("9403107396"); + + 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()); + assertTrue(messageDto.getIsValid()); + assertFalse(messageDto.getInternalError()); + Assert.assertEquals(argumentCaptor.getValue().getStatusCode(), RegistrationStatusCode.FAILED.name()); + } +// 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 + @Test + public void moreThenOneMatchFoundWithDifferentUin() 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<>(); + matchedRidList.add("27847657360002520190320095011"); + matchedRidList.add("27847657360002520190320095012"); + matchedRidList.add("27847657360002520190320095013"); + matchedRidList.add("27847657360002520190320095014"); + Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); + Mockito.when(utility.getUIn(anyString(), anyString(), any())) + .thenReturn("9403107396"); + Mockito.when(idRepoService.getUinByRid(anyString(),any())) + .thenReturn("9403107397") + .thenReturn("9403107398") + .thenReturn("9403107399"); + + 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()); + assertTrue(messageDto.getIsValid()); + assertFalse(messageDto.getInternalError()); + Assert.assertEquals(argumentCaptor.getValue().getStatusCode(), RegistrationStatusCode.FAILED.name()); + } + +// One match of RID/AID found at bio dedupe stage, +// found AID/RID is in progress status and RID & UIN mapping is not done + + @Test + public void oneMatchFoundWithStillInProgress () 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<>(); + matchedRidList.add("27847657360002520190320095011"); + matchedRidList.add("27847657360002520190320095012"); + Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); + Mockito.when(utility.getUIn(anyString(), anyString(), any())) + .thenReturn(null); + + 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(argumentCaptor.getValue().getStatusCode(), RegistrationStatusCode.FAILED.name()); + assertTrue(messageDto.getIsValid()); + assertFalse(messageDto.getInternalError()); + } +// 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 + @Test + public void moreThenOneMatchFoundWithOneIsStillInProgress () 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<>(); + matchedRidList.add("27847657360002520190320095011"); + matchedRidList.add("27847657360002520190320095012"); + matchedRidList.add("27847657360002520190320095013"); + matchedRidList.add("27847657360002520190320095014"); + Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); + Mockito.when(utility.getUIn(anyString(), anyString(), any())) + .thenReturn("9403107396"); + Mockito.when(idRepoService.getUinByRid(anyString(),any())) + .thenReturn("9403107397") + .thenReturn(null) + .thenReturn("9403107398"); + ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(InternalRegistrationStatusDto.class); + MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); + Mockito.verify(registrationStatusService).updateRegistrationStatus(argumentCaptor.capture(),anyString(),anyString()); + assertTrue(messageDto.getIsValid()); + assertFalse(messageDto.getInternalError()); + Assert.assertEquals(argumentCaptor.getValue().getStatusCode(), RegistrationStatusCode.FAILED.name()); + } + +// More than one match of RID/AID found at bio dedupe stage, +// All RID is in progress state & mapping is not done in repo + @Test + public void moreThenOneMatchFoundWithAllRidAreStillInProgress () 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<>(); + matchedRidList.add("27847657360002520190320095011"); + matchedRidList.add("27847657360002520190320095012"); + matchedRidList.add("27847657360002520190320095013"); + matchedRidList.add("27847657360002520190320095014"); + Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); + Mockito.when(utility.getUIn(anyString(), anyString(), any())) + .thenReturn("9403107396"); + 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()); + assertTrue(messageDto.getIsValid()); + assertFalse(messageDto.getInternalError()); + Assert.assertEquals(argumentCaptor.getValue().getStatusCode(), RegistrationStatusCode.FAILED.name()); + } } \ 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 53b752f1e3b..00dbcc6cdb8 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,8 +200,8 @@ 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_NO_MATCH_FOUND(StatusConstants.BIO_DEDUPE_MODULE_FAILED + "004", - "No 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", From 1fbd947967a9755b5675d17b528930867fb278ce Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Wed, 31 Jul 2024 20:54:38 +0530 Subject: [PATCH 3/9] pushtriger changes Signed-off-by: khuddus shariff --- .github/workflows/push-trigger.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/push-trigger.yml b/.github/workflows/push-trigger.yml index 215b2029808..326df0539bb 100644 --- a/.github/workflows/push-trigger.yml +++ b/.github/workflows/push-trigger.yml @@ -20,7 +20,6 @@ on: - master - 1.* - develop - - MOSIP-34112_release jobs: build-maven-registration: From 8b457c7c9a40c5a403845cf704ead49d5106f494 Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Thu, 1 Aug 2024 12:03:06 +0530 Subject: [PATCH 4/9] added logger Signed-off-by: khuddus shariff --- .../processor/biodedupe/stage/BioDedupeProcessor.java | 4 ++++ 1 file changed, 4 insertions(+) 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 6c130c2de08..4e05f2c78a6 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 @@ -469,6 +469,10 @@ private void updatePostAbisIdentification(InternalRegistrationStatusDto registra 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); From a6f4adac2617af4e3e1e9b98de6f95e8357406a0 Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Fri, 2 Aug 2024 13:34:22 +0530 Subject: [PATCH 5/9] test case modification Signed-off-by: khuddus shariff --- .../stage/BioDedupeProcessorTest.java | 1383 ++++++++--------- 1 file changed, 647 insertions(+), 736 deletions(-) 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 0ec8c184c8b..ce97e9646df 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 @@ -91,800 +91,736 @@ @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 registration status dao. */ - @Mock - private RegistrationStatusDao registrationStatusDao; + /** The bio dedupe service. */ + @Mock + private BioDedupeService bioDedupeService; - /** The packet info dao. */ - @Mock - private PacketInfoDao packetInfoDao; + /** The registration status dao. */ + @Mock + private RegistrationStatusDao registrationStatusDao; - @Mock - private IdRepoService idRepoService; + /** The packet info dao. */ + @Mock + private PacketInfoDao packetInfoDao; - /** The dto. */ - MessageDTO dto = new MessageDTO(); + @Mock + private IdRepoService idRepoService; - /** The registration status dto. */ - InternalRegistrationStatusDto registrationStatusDto = new InternalRegistrationStatusDto(); + /** The dto. */ + MessageDTO dto = new MessageDTO(); - /** The audit log request builder. */ - @Mock - private AuditLogRequestBuilder auditLogRequestBuilder; - - /** The matched reg ids. */ - List matchedRegIds = new ArrayList(); - - /** The registration status mapper util. */ - @Mock - RegistrationExceptionMapperUtil registrationStatusMapperUtil; - - /** 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 + /** The registration status dto. */ + InternalRegistrationStatusDto registrationStatusDto = new InternalRegistrationStatusDto(); + + /** The audit log request builder. */ + @Mock + private AuditLogRequestBuilder auditLogRequestBuilder; + + /** The matched reg ids. */ + List matchedRegIds = new ArrayList(); + + /** The registration status mapper util. */ + @Mock + RegistrationExceptionMapperUtil registrationStatusMapperUtil; + + /** 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 -// 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()); - } - - @Test - public void testBioDeDupUpdatePacketHandlerProcessingSuccessWithAutoRejectEnable() - 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); - when(idRepoService.getUinByRid(any(), any())).thenReturn("9403107397"); - Mockito.when(utility.getUIn(anyString(), anyString(), any())).thenReturn("9403107397"); - ReflectionTestUtils.setField(bioDedupeProcessor, "biometricsUpdateSingleMatchAutoReject", true); - MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); - assertTrue(messageDto.getIsValid()); - assertFalse(messageDto.getInternalError()); - } - - @Test - public void testBioDeDupUpdatePacketHandlerProcessingFailWithAutoRejectEnable() - 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); - when(idRepoService.getUinByRid(any(), any())).thenReturn("9403107397"); - Mockito.when(utility.getUIn(anyString(), anyString(), any())).thenReturn("9403107396"); - ReflectionTestUtils.setField(bioDedupeProcessor, "biometricsUpdateSingleMatchAutoReject", true); - MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); - assertFalse(messageDto.getIsValid()); - assertFalse(messageDto.getInternalError()); - } -// One match of RID/AID found at bio dedupe stage. -// UIN of the duplicate match is same as the update packet UIN + 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 oneMatchFoundWithSameUin() throws ApisResourceAccessException, IOException, - PacketDecryptionFailureException, io.mosip.kernel.core.exception.IOException, JsonProcessingException, PacketManagerException { - registrationStatusDto.setRegistrationId("27847657360002520190320095011"); + 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"); - 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"); - matchedRidList.add("27847657360002520190320095012"); Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); - Mockito.when(utility.getUIn(anyString(), anyString(), any())).thenReturn("9403107396"); - Mockito.when(idRepoService.getUinByRid(anyString(),any())).thenReturn("9403107396"); - 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()); } -// 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 + /** + * 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 oneMatchFoundWithDifferentUinWithMatchAutoRejecAsTrue() throws ApisResourceAccessException, IOException, + @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("27847657360002520190320095011"); + 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); - Mockito.when(utility.getUIn(anyString(), anyString(), any())).thenReturn("9403107396"); - Mockito.when(idRepoService.getUinByRid(anyString(),any())).thenReturn("9403107397"); + 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()); + } + + @Test + public void testBioDeDupUpdatePacketHandlerProcessingSuccessWithAutoRejectEnable() + 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); + when(idRepoService.getUinByRid(any(), any())).thenReturn("9403107397"); + Mockito.when(utility.getUIn(anyString(), anyString(), any())).thenReturn("9403107397"); + ReflectionTestUtils.setField(bioDedupeProcessor, "biometricsUpdateSingleMatchAutoReject", true); + MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); + assertTrue(messageDto.getIsValid()); + assertFalse(messageDto.getInternalError()); + } + + @Test + public void testBioDeDupUpdatePacketHandlerProcessingFailWithAutoRejectEnable() + 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); + when(idRepoService.getUinByRid(any(), any())).thenReturn("9403107397"); + Mockito.when(utility.getUIn(anyString(), anyString(), any())).thenReturn("9403107396"); 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()); } -// One match of RID/AID found at bio dedupe, -// but UIN of the duplicate match is different from update packet UIN with auto rejection is false +// 1)No match of RID/AID found in bio dedupe: +// This usecase is handeled in oneMatchFoundWithSameUin(). because empty matched rid list handeled in it. + +// 2)One match of RID/AID found at bio dedupe stage. UIN of the duplicate match is same as the update packet UIN +// This usecase is handeled in oneMatchFoundWithSameUin() because abisHandlerUtil.getUniqueRegIds() will return the empty matched rid list if update uin is same as Matched rid. + +// 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 usecase is handeled in oneMatchFoundWithSameUin() because abisHandlerUtil.getUniqueRegIds() will return the empty matched rid list if update uin is same as Matched rid. + +// More than one match of RID/AID found at bio dedupe stage, all duplicate matches have the same UIN but, they does not matches with update packet UIN +// This usecase is handeled in oneMatchFoundWithDifferentUinWithMatchAutoRejecAsTrue(). Because abisHandlerUtil.getUniqueRegIds() will return the latest match for a particular uin. @Test - public void oneMatchFoundWithDifferentUinWithSingleMatchAutoRejectAsFalse() throws ApisResourceAccessException, IOException, + public void oneMatchFoundWithSameUin() 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<>(); - matchedRidList.add("27847657360002520190320095011"); - matchedRidList.add("27847657360002520190320095012"); +// matchedRidList is empty Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); - Mockito.when(utility.getUIn(anyString(), anyString(), any())).thenReturn("9403107396"); - 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(argumentCaptor.getValue().getStatusCode(), RegistrationStatusCode.PROCESSING.name()); assertTrue(messageDto.getIsValid()); assertFalse(messageDto.getInternalError()); - Assert.assertEquals(argumentCaptor.getValue().getStatusCode(), RegistrationStatusCode.FAILED.name()); } -// More than one match of RID/AID found at bio dedupe stage, -// all UIN of duplicate matches are same as update packet UIN + +// 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 @Test - public void MoreThenOneMatchFoundWithSameUin() throws ApisResourceAccessException, IOException, + public void oneMatchFoundWithDifferentUinWithMatchAutoRejecAsTrue() 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<>(); - matchedRidList.add("27847657360002520190320095011"); matchedRidList.add("27847657360002520190320095012"); - matchedRidList.add("27847657360002520190320095013"); - matchedRidList.add("27847657360002520190320095014"); Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); - Mockito.when(utility.getUIn(anyString(), anyString(), any())) - .thenReturn("9403107396"); - - Mockito.when(idRepoService.getUinByRid(anyString(),any())) - .thenReturn("9403107396") - .thenReturn("9403107396") - .thenReturn("9403107396");; - +// Mockito.when(utility.getUIn(anyString(), anyString(), any())).thenReturn("9403107396"); + 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()); - assertTrue(messageDto.getIsValid()); + assertFalse(messageDto.getIsValid()); assertFalse(messageDto.getInternalError()); - Assert.assertEquals(RegistrationStatusCode.PROCESSING.name(),argumentCaptor.getValue().getStatusCode()); + Assert.assertEquals(argumentCaptor.getValue().getStatusCode(), RegistrationStatusCode.REJECTED.name()); } -// More than one match of RID/AID found at bio dedupe stage, -// all duplicate matches have the same UIN but, they does not matches with update packet UIN +// One match of RID/AID found at bio dedupe, +// but UIN of the duplicate match is different from update packet UIN with auto rejection is false @Test - public void moreThenOneMatchFoundWithAllSameUinExceptUpdateUin() throws ApisResourceAccessException, IOException, + public void oneMatchFoundWithDifferentUinWithSingleMatchAutoRejectAsFalse() 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<>(); - matchedRidList.add("27847657360002520190320095011"); matchedRidList.add("27847657360002520190320095012"); - matchedRidList.add("27847657360002520190320095013"); - matchedRidList.add("27847657360002520190320095014"); Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); - Mockito.when(utility.getUIn(anyString(), anyString(), any())) - .thenReturn("9403107396"); - Mockito.when(idRepoService.getUinByRid(anyString(),any())) - .thenReturn("9403107397") - .thenReturn("9403107397") - .thenReturn("9403107397"); - - ReflectionTestUtils.setField(bioDedupeProcessor, "biometricsUpdateSingleMatchAutoReject", true); + 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()); - assertFalse(messageDto.getIsValid()); + assertTrue(messageDto.getIsValid()); assertFalse(messageDto.getInternalError()); - Assert.assertEquals(argumentCaptor.getValue().getStatusCode(), RegistrationStatusCode.REJECTED.name()); + Assert.assertEquals(argumentCaptor.getValue().getStatusCode(), RegistrationStatusCode.FAILED.name()); } + // 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 @Test public void moreThenOneMatchFoundWithDifferentUinOnlyOneMatches() throws ApisResourceAccessException, IOException, PacketDecryptionFailureException, io.mosip.kernel.core.exception.IOException, JsonProcessingException, PacketManagerException { - registrationStatusDto.setRegistrationId("27847657360002520190320095011"); + registrationStatusDto.setRegistrationId("27847657360002520190320095014"); registrationStatusDto.setRegistrationType("UPDATE"); registrationStatusDto.setStatusCode("PROCESSING"); Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); @@ -892,16 +828,11 @@ public void moreThenOneMatchFoundWithDifferentUinOnlyOneMatches() throws ApisRes .thenReturn(AbisConstant.POST_ABIS_IDENTIFICATION); Set matchedRidList = new HashSet<>(); - matchedRidList.add("27847657360002520190320095011"); - matchedRidList.add("27847657360002520190320095012"); matchedRidList.add("27847657360002520190320095013"); - matchedRidList.add("27847657360002520190320095014"); + matchedRidList.add("27847657360002520190320095012"); Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); - Mockito.when(utility.getUIn(anyString(), anyString(), any())) - .thenReturn("9403107396"); Mockito.when(idRepoService.getUinByRid(anyString(),any())) .thenReturn("9403107394") - .thenReturn("9403107395") .thenReturn("9403107396"); ReflectionTestUtils.setField(bioDedupeProcessor, "biometricsUpdateSingleMatchAutoReject", false); @@ -917,7 +848,7 @@ public void moreThenOneMatchFoundWithDifferentUinOnlyOneMatches() throws ApisRes @Test public void moreThenOneMatchFoundWithDifferentUin() throws ApisResourceAccessException, IOException, PacketDecryptionFailureException, io.mosip.kernel.core.exception.IOException, JsonProcessingException, PacketManagerException { - registrationStatusDto.setRegistrationId("27847657360002520190320095011"); + registrationStatusDto.setRegistrationId("27847657360002520190320095014"); registrationStatusDto.setRegistrationType("UPDATE"); registrationStatusDto.setStatusCode("PROCESSING"); Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); @@ -925,16 +856,11 @@ public void moreThenOneMatchFoundWithDifferentUin() throws ApisResourceAccessExc .thenReturn(AbisConstant.POST_ABIS_IDENTIFICATION); Set matchedRidList = new HashSet<>(); - matchedRidList.add("27847657360002520190320095011"); - matchedRidList.add("27847657360002520190320095012"); matchedRidList.add("27847657360002520190320095013"); - matchedRidList.add("27847657360002520190320095014"); + matchedRidList.add("27847657360002520190320095012"); Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); - Mockito.when(utility.getUIn(anyString(), anyString(), any())) - .thenReturn("9403107396"); Mockito.when(idRepoService.getUinByRid(anyString(),any())) .thenReturn("9403107397") - .thenReturn("9403107398") .thenReturn("9403107399"); ReflectionTestUtils.setField(bioDedupeProcessor, "biometricsUpdateSingleMatchAutoReject", false); @@ -953,7 +879,7 @@ public void moreThenOneMatchFoundWithDifferentUin() throws ApisResourceAccessExc @Test public void oneMatchFoundWithStillInProgress () throws ApisResourceAccessException, IOException, PacketDecryptionFailureException, io.mosip.kernel.core.exception.IOException, JsonProcessingException, PacketManagerException { - registrationStatusDto.setRegistrationId("27847657360002520190320095011"); + registrationStatusDto.setRegistrationId("27847657360002520190320095012"); registrationStatusDto.setRegistrationType("UPDATE"); registrationStatusDto.setStatusCode("PROCESSING"); Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); @@ -962,13 +888,8 @@ public void oneMatchFoundWithStillInProgress () throws ApisResourceAccessExcepti Set matchedRidList = new HashSet<>(); matchedRidList.add("27847657360002520190320095011"); - matchedRidList.add("27847657360002520190320095012"); Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); - Mockito.when(utility.getUIn(anyString(), anyString(), any())) - .thenReturn(null); - 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()); @@ -981,7 +902,7 @@ public void oneMatchFoundWithStillInProgress () throws ApisResourceAccessExcepti @Test public void moreThenOneMatchFoundWithOneIsStillInProgress () throws ApisResourceAccessException, IOException, PacketDecryptionFailureException, io.mosip.kernel.core.exception.IOException, JsonProcessingException, PacketManagerException { - registrationStatusDto.setRegistrationId("27847657360002520190320095011"); + registrationStatusDto.setRegistrationId("27847657360002520190320095014"); registrationStatusDto.setRegistrationType("UPDATE"); registrationStatusDto.setStatusCode("PROCESSING"); Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); @@ -989,17 +910,13 @@ public void moreThenOneMatchFoundWithOneIsStillInProgress () throws ApisResource .thenReturn(AbisConstant.POST_ABIS_IDENTIFICATION); Set matchedRidList = new HashSet<>(); - matchedRidList.add("27847657360002520190320095011"); - matchedRidList.add("27847657360002520190320095012"); matchedRidList.add("27847657360002520190320095013"); - matchedRidList.add("27847657360002520190320095014"); + matchedRidList.add("27847657360002520190320095012"); Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); - Mockito.when(utility.getUIn(anyString(), anyString(), any())) - .thenReturn("9403107396"); + Mockito.when(idRepoService.getUinByRid(anyString(),any())) .thenReturn("9403107397") - .thenReturn(null) - .thenReturn("9403107398"); + .thenReturn(null); ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(InternalRegistrationStatusDto.class); MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); Mockito.verify(registrationStatusService).updateRegistrationStatus(argumentCaptor.capture(),anyString(),anyString()); @@ -1013,7 +930,7 @@ public void moreThenOneMatchFoundWithOneIsStillInProgress () throws ApisResource @Test public void moreThenOneMatchFoundWithAllRidAreStillInProgress () throws ApisResourceAccessException, IOException, PacketDecryptionFailureException, io.mosip.kernel.core.exception.IOException, JsonProcessingException, PacketManagerException { - registrationStatusDto.setRegistrationId("27847657360002520190320095011"); + registrationStatusDto.setRegistrationId("27847657360002520190320095014"); registrationStatusDto.setRegistrationType("UPDATE"); registrationStatusDto.setStatusCode("PROCESSING"); Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); @@ -1021,16 +938,10 @@ public void moreThenOneMatchFoundWithAllRidAreStillInProgress () throws ApisReso .thenReturn(AbisConstant.POST_ABIS_IDENTIFICATION); Set matchedRidList = new HashSet<>(); - matchedRidList.add("27847657360002520190320095011"); - matchedRidList.add("27847657360002520190320095012"); matchedRidList.add("27847657360002520190320095013"); - matchedRidList.add("27847657360002520190320095014"); + matchedRidList.add("27847657360002520190320095012"); Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); - Mockito.when(utility.getUIn(anyString(), anyString(), any())) - .thenReturn("9403107396"); - Mockito.when(idRepoService.getUinByRid(anyString(),any())) - .thenReturn(null); - + 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()); From 8cac7f731282788a05c6bf0e1e15291d59f23e5b Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Fri, 2 Aug 2024 16:41:58 +0530 Subject: [PATCH 6/9] test case modification Signed-off-by: khuddus shariff --- .../biodedupe/stage/BioDedupeProcessor.java | 101 ++++----- .../stage/BioDedupeProcessorTest.java | 195 ++++++++---------- 2 files changed, 119 insertions(+), 177 deletions(-) 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 4e05f2c78a6..597b940c08b 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,23 +1,5 @@ package io.mosip.registration.processor.biodedupe.stage; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -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; @@ -26,19 +8,11 @@ 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.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.code.*; +import io.mosip.registration.processor.core.constant.*; import io.mosip.registration.processor.core.exception.ApisResourceAccessException; import io.mosip.registration.processor.core.exception.PacketDecryptionFailureException; import io.mosip.registration.processor.core.exception.PacketManagerException; @@ -67,6 +41,17 @@ 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. @@ -419,6 +404,10 @@ 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); @@ -456,7 +445,6 @@ private void updatePostAbisIdentification(InternalRegistrationStatusDto registra boolean sendToManualAdjudication = false; for(String matchedRegistrationId:matchedRegIds) { String uin = idRepoService.getUinByRid(matchedRegistrationId, utilities.getGetRegProcessorDemographicIdentity()); - // TODO need to check this condition is necessary if (StringUtils.isEmpty(uin)) { InternalRegistrationStatusDto matchedRegistrationStatusDto = registrationStatusService .getRegistrationStatus(matchedRegistrationId, null, null, null); @@ -477,42 +465,25 @@ private void updatePostAbisIdentification(InternalRegistrationStatusDto registra sendToManualAdjudicationStage(registrationStatusDto, object, registrationType, moduleName, matchedRegIds); } else { - Optional optionalMatchedUin = uniqueUins.stream().findFirst(); - String matchedUIN = optionalMatchedUin.get(); - String updateUin = utilities.getUIn(registrationStatusDto.getRegistrationId(), registrationType, - ProviderStageName.BIO_AUTH); - if (StringUtils.equals(matchedUIN, updateUin)) { - registrationStatusDto - .setLatestTransactionStatusCode(RegistrationTransactionStatusCode.SUCCESS.toString()); - object.setIsValid(Boolean.TRUE); - registrationStatusDto.setStatusCode(RegistrationStatusCode.PROCESSING.name()); - registrationStatusDto.setStatusComment(StatusUtil.BIO_DEDUPE_SUCCESS.getMessage()); - registrationStatusDto.setSubStatusCode(StatusUtil.BIO_DEDUPE_SUCCESS.getCode()); - regProcLogger.info(LoggerFileConstant.SESSIONID.toString(), - LoggerFileConstant.REGISTRATIONID.toString(), registrationStatusDto.getRegistrationId(), - BioDedupeConstants.BIOMETRIC_MATCH_FOUND_WITH_SELF); - } else { - 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); - } - - } - } + 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, 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 ce97e9646df..896356b376a 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 @@ -695,61 +695,20 @@ public void testApisResourceAccessException() throws Exception { assertTrue(messageDto.getInternalError()); } - @Test - public void testBioDeDupUpdatePacketHandlerProcessingSuccessWithAutoRejectEnable() - 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); - when(idRepoService.getUinByRid(any(), any())).thenReturn("9403107397"); - Mockito.when(utility.getUIn(anyString(), anyString(), any())).thenReturn("9403107397"); - ReflectionTestUtils.setField(bioDedupeProcessor, "biometricsUpdateSingleMatchAutoReject", true); - MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); - assertTrue(messageDto.getIsValid()); - assertFalse(messageDto.getInternalError()); - } + /* use case 1 -> No match of RID/AID found in bio dedupe: + This use case is handled in noMatchedRidFound(). - @Test - public void testBioDeDupUpdatePacketHandlerProcessingFailWithAutoRejectEnable() - 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); + 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. - Set matchedRidList = new HashSet<>(); - matchedRidList.add("27847657360002520190320095010"); - Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); - when(idRepoService.getUinByRid(any(), any())).thenReturn("9403107397"); - Mockito.when(utility.getUIn(anyString(), anyString(), any())).thenReturn("9403107396"); - ReflectionTestUtils.setField(bioDedupeProcessor, "biometricsUpdateSingleMatchAutoReject", true); - MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); - assertFalse(messageDto.getIsValid()); - assertFalse(messageDto.getInternalError()); - } - -// 1)No match of RID/AID found in bio dedupe: -// This usecase is handeled in oneMatchFoundWithSameUin(). because empty matched rid list handeled in it. - -// 2)One match of RID/AID found at bio dedupe stage. UIN of the duplicate match is same as the update packet UIN -// This usecase is handeled in oneMatchFoundWithSameUin() because abisHandlerUtil.getUniqueRegIds() will return the empty matched rid list if update uin is same as Matched rid. - -// 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 usecase is handeled in oneMatchFoundWithSameUin() because abisHandlerUtil.getUniqueRegIds() will return the empty matched rid list if update uin is same as Matched rid. - -// More than one match of RID/AID found at bio dedupe stage, all duplicate matches have the same UIN but, they does not matches with update packet UIN -// This usecase is handeled in oneMatchFoundWithDifferentUinWithMatchAutoRejecAsTrue(). Because abisHandlerUtil.getUniqueRegIds() will return the latest match for a particular uin. + 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 oneMatchFoundWithSameUin() throws ApisResourceAccessException, IOException, + public void noMatchedRidFound() throws ApisResourceAccessException, IOException, PacketDecryptionFailureException, io.mosip.kernel.core.exception.IOException, JsonProcessingException, PacketManagerException { registrationStatusDto.setRegistrationId("27847657360002520190320095011"); registrationStatusDto.setRegistrationType("UPDATE"); @@ -757,7 +716,6 @@ public void oneMatchFoundWithSameUin() throws ApisResourceAccessException, IOExc 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 is empty Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(InternalRegistrationStatusDto.class); MessageDTO messageDto = bioDedupeProcessor.process(dto, stageName); @@ -766,21 +724,26 @@ public void oneMatchFoundWithSameUin() throws ApisResourceAccessException, IOExc 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. + */ -// 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 @Test public void oneMatchFoundWithDifferentUinWithMatchAutoRejecAsTrue() throws ApisResourceAccessException, IOException, PacketDecryptionFailureException, io.mosip.kernel.core.exception.IOException, JsonProcessingException, PacketManagerException { - registrationStatusDto.setRegistrationId("27847657360002520190320095011"); + 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("27847657360002520190320095012"); + matchedRidList.add("27847657360002520190320095011"); Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); -// Mockito.when(utility.getUIn(anyString(), anyString(), any())).thenReturn("9403107396"); Mockito.when(idRepoService.getUinByRid(anyString(),any())).thenReturn("9403107397"); ReflectionTestUtils.setField(bioDedupeProcessor, "biometricsUpdateSingleMatchAutoReject", true); ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(InternalRegistrationStatusDto.class); @@ -790,19 +753,24 @@ public void oneMatchFoundWithDifferentUinWithMatchAutoRejecAsTrue() throws ApisR 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 -// One match of RID/AID found at bio dedupe, -// but UIN of the duplicate match is different from update packet UIN with auto rejection is false + 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("27847657360002520190320095011"); + 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("27847657360002520190320095012"); + 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); @@ -814,37 +782,17 @@ public void oneMatchFoundWithDifferentUinWithSingleMatchAutoRejectAsFalse() thro 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. + */ -// 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 - @Test - public void moreThenOneMatchFoundWithDifferentUinOnlyOneMatches() 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("9403107394") - .thenReturn("9403107396"); - - 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()); - assertTrue(messageDto.getIsValid()); - assertFalse(messageDto.getInternalError()); - Assert.assertEquals(argumentCaptor.getValue().getStatusCode(), RegistrationStatusCode.FAILED.name()); - } -// 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 + /* + 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 { @@ -862,9 +810,6 @@ public void moreThenOneMatchFoundWithDifferentUin() throws ApisResourceAccessExc Mockito.when(idRepoService.getUinByRid(anyString(),any())) .thenReturn("9403107397") .thenReturn("9403107399"); - - 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()); @@ -872,24 +817,29 @@ public void moreThenOneMatchFoundWithDifferentUin() throws ApisResourceAccessExc assertFalse(messageDto.getInternalError()); Assert.assertEquals(argumentCaptor.getValue().getStatusCode(), RegistrationStatusCode.FAILED.name()); } - -// One match of RID/AID found at bio dedupe stage, -// found AID/RID is in progress status and RID & UIN mapping is not done - + /* + 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"); - Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); + //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"); + matchedRidList.add("27847657360002520190320095011"); //this rid is in processing state Mockito.when(abisHandlerUtil.getUniqueRegIds(any(), any(), anyInt(), any(), any())).thenReturn(matchedRidList); - ReflectionTestUtils.setField(bioDedupeProcessor, "biometricsUpdateSingleMatchAutoReject", false); + 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()); @@ -897,23 +847,31 @@ public void oneMatchFoundWithStillInProgress () throws ApisResourceAccessExcepti assertTrue(messageDto.getIsValid()); assertFalse(messageDto.getInternalError()); } -// 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 + + /* + 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"); - Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); + //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("27847657360002520190320095013"); 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); @@ -925,18 +883,31 @@ public void moreThenOneMatchFoundWithOneIsStillInProgress () throws ApisResource Assert.assertEquals(argumentCaptor.getValue().getStatusCode(), RegistrationStatusCode.FAILED.name()); } -// More than one match of RID/AID found at bio dedupe stage, -// All RID is in progress state & mapping is not done in repo + /* + 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"); - Mockito.when(registrationStatusService.getRegistrationStatus(any(),any(),any(), any())).thenReturn(registrationStatusDto); + //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"); From cf49a2a169ce117f04bd869b9884075e455f9ebd Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Fri, 2 Aug 2024 16:48:00 +0530 Subject: [PATCH 7/9] test case modification Signed-off-by: khuddus shariff --- .../processor/biodedupe/constants/BioDedupeConstants.java | 2 -- 1 file changed, 2 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 0a9faaeaf33..cf10051c819 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 @@ -43,7 +43,5 @@ public class BioDedupeConstants { /** 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_SELF = "Biometric match found successfully, destination stage is UIN"; - public static final String BIOMETRIC_MATCH_FOUND_WITH_OTHER = "Biometric match found with other user, rejecting packet for "; } \ No newline at end of file From ed58bffe3a3b122221b60be43249bbc8a2338e65 Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Sat, 3 Aug 2024 11:00:19 +0530 Subject: [PATCH 8/9] test case modification commented changes Signed-off-by: khuddus shariff --- .../biodedupe/stage/BioDedupeProcessor.java | 7 +++--- .../stage/BioDedupeProcessorTest.java | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) 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 597b940c08b..27e4973019d 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 @@ -425,10 +425,9 @@ 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())) { - updatePostAbisIdentification(registrationStatusDto, object, registrationType, moduleName, + handlePostAbisIdentificationForUpdate(registrationStatusDto, object, registrationType, moduleName, matchedRegIds); }else { sendToManualAdjudicationStage(registrationStatusDto, object, registrationType, moduleName, matchedRegIds); @@ -438,8 +437,8 @@ private void postAbisIdentification(InternalRegistrationStatusDto registrationSt } } - private void updatePostAbisIdentification(InternalRegistrationStatusDto registrationStatusDto, MessageDTO object, - String registrationType, String moduleName, Set matchedRegIds) + 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; 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 896356b376a..380dd613734 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 @@ -724,6 +724,25 @@ public void noMatchedRidFound() throws ApisResourceAccessException, IOException, assertTrue(messageDto.getIsValid()); assertFalse(messageDto.getInternalError()); } + + @Test + public void noMatchedRidFoundMatchedRidAsNull() 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 = null; + 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.FAILED.name()); + Assert.assertEquals(argumentCaptor.getValue().getStatusComment(),"Unknown exception occured null"); + assertFalse(messageDto.getIsValid()); + assertTrue(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 @@ -777,6 +796,7 @@ public void oneMatchFoundWithDifferentUinWithSingleMatchAutoRejectAsFalse() thro 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()); @@ -813,6 +833,7 @@ public void moreThenOneMatchFoundWithDifferentUin() throws ApisResourceAccessExc 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()); @@ -843,6 +864,7 @@ public void oneMatchFoundWithStillInProgress () throws ApisResourceAccessExcepti 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()); @@ -878,6 +900,7 @@ public void moreThenOneMatchFoundWithOneIsStillInProgress () throws ApisResource 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()); @@ -916,6 +939,7 @@ public void moreThenOneMatchFoundWithAllRidAreStillInProgress () throws ApisReso 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()); From 11e3ed12384c25d7c28a4e823df255ce86e70fae Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Sat, 3 Aug 2024 18:00:31 +0530 Subject: [PATCH 9/9] test case modification commented changes Signed-off-by: khuddus shariff --- .../biodedupe/stage/BioDedupeProcessor.java | 1 + .../stage/BioDedupeProcessorTest.java | 19 ------------------- 2 files changed, 1 insertion(+), 19 deletions(-) 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 27e4973019d..627d9fb1e12 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 @@ -464,6 +464,7 @@ private void handlePostAbisIdentificationForUpdate(InternalRegistrationStatusDto 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()); 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 380dd613734..da994c60cc5 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 @@ -724,25 +724,6 @@ public void noMatchedRidFound() throws ApisResourceAccessException, IOException, assertTrue(messageDto.getIsValid()); assertFalse(messageDto.getInternalError()); } - - @Test - public void noMatchedRidFoundMatchedRidAsNull() 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 = null; - 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.FAILED.name()); - Assert.assertEquals(argumentCaptor.getValue().getStatusComment(),"Unknown exception occured null"); - assertFalse(messageDto.getIsValid()); - assertTrue(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