Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.mosip.registration.processor.biodedupe.stage.exception.CbeffNotFoundException;
import io.mosip.registration.processor.core.code.*;
import io.mosip.registration.processor.core.constant.ProviderStageName;
import io.mosip.registration.processor.core.constant.RegistrationType;
import io.mosip.registration.processor.core.exception.*;
import io.mosip.registration.processor.core.packet.dto.abis.ProcessedMatchedResult;
import io.mosip.registration.processor.packet.storage.utils.PriorityBasedPacketManagerService;
Expand Down Expand Up @@ -947,4 +948,57 @@ public void testProcess_ThrowsBiometricClassificationException() throws PacketMa
assertEquals(MessageBusAddress.VERIFICATION_BUS_IN, result.getMessageBusAddress());
}

@Test
public void testProcess_WhenCbeffNotFoundException_ShouldSetInternalErrorTrue() throws Exception {

MessageDTO messageDTO = new MessageDTO();
messageDTO.setRid("RID123");
messageDTO.setReg_type("LOST");
messageDTO.setIteration(0);
messageDTO.setWorkflowInstanceId("WF1");

InternalRegistrationStatusDto registrationStatus = new InternalRegistrationStatusDto();
registrationStatus.setRegistrationId("RID123");
registrationStatus.setRegistrationType(SyncTypeDto.LOST.toString());

when(registrationStatusService.getRegistrationStatus(anyString(), anyString(), anyInt(), anyString()))
.thenReturn(registrationStatus);
when(abisHandlerUtil.getPacketStatus(any())).thenThrow(new CbeffNotFoundException("CBEFF missing"));
Comment thread
ashok-ksharma marked this conversation as resolved.
Outdated

MessageDTO result = bioDedupeProcessor.process(messageDTO, stageName);
assertTrue(result.getInternalError());
assertFalse(result.getIsValid());
}

@Test
public void testLostAndUpdateUin_WhenExceptionOccurs_ShouldSetValidStatusFalseAndInternalErrorTrue() {

MessageDTO messageDTO = new MessageDTO();
messageDTO.setRid("10031100110005020190313110030");
when(abisHandlerUtil.getPacketStatus(any()))
.thenThrow(new RuntimeException("test exception"));
MessageDTO result = bioDedupeProcessor.process(messageDTO, stageName);

assertFalse(result.getIsValid());
assertTrue(result.getInternalError());
}

@Test
public void testNewPacketPreAbisIdentification_WhenCbeffAbsent_ShouldSetDedupeSuccessStatus() throws ApisResourceAccessException, PacketManagerException, IOException, JsonProcessingException {

ReflectionTestUtils.setField(bioDedupeProcessor, "infantDedupe", "N");
MessageDTO messageDTO = new MessageDTO();
messageDTO.setReg_type(RegistrationType.NEW.name());
Mockito.when(bioDedupeService.getFileByRegId(anyString(),anyString())).thenReturn(null);
Mockito.when(restClientService.getApi(any(), any(), anyString(), any(), any())).thenReturn(null);
Comment thread
ashok-ksharma marked this conversation as resolved.
Outdated
Mockito.when(utility.getApplicantAge(any(),any(),any())).thenReturn(3);
Mockito.when(registrationStatusMapperUtil
.getStatusCode(RegistrationExceptionTypeCode.CBEFF_NOT_PRESENT_EXCEPTION)).thenReturn("FAILED");
Comment thread
ashok-ksharma marked this conversation as resolved.
Outdated
MessageDTO messageDto = bioDedupeProcessor.process(messageDTO, stageName);
assertTrue(messageDto.getIsValid());
assertEquals(MessageBusAddress.BIO_DEDUPE_BUS_IN, messageDTO.getMessageBusAddress());
assertEquals(RegistrationStatusCode.PROCESSING.name(), registrationStatusDto.getStatusCode());
assertEquals(RegistrationTransactionStatusCode.SUCCESS.name(), registrationStatusDto.getLatestTransactionStatusCode());
}
Comment thread
ashok-ksharma marked this conversation as resolved.

}
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ public Integer getPort() {

/** The Constant CONFIG_SERVER_URL. */
private static final String CONFIG_SERVER_URL = "url";
private static final String IDREPO_STATUS = "DRAFTED";

private String identityMappingjsonString;

Expand Down Expand Up @@ -2775,4 +2776,210 @@ public void testProcess_WithLostPacket_ShouldReturnNull() throws Exception {
assertNull(demographicIdentity.get("packetCreatedOn"));
}

@Test
public void testProcess_UinGenerationReprocess_ShouldSetReprocessStatus() throws IOException, PacketManagerException, ApisResourceAccessException, JsonProcessingException,
IdrepoDraftReprocessableException, IdrepoDraftException {
List<ErrorDTO> errors = new ArrayList<>();
ErrorDTO errorDTO = new ErrorDTO();
errorDTO.setErrorCode("IDR-IDC-004");
errorDTO.setMessage("Unknown error occurred");
errors.add(errorDTO);

MessageDTO messageDTO = new MessageDTO();
messageDTO.setRid("10031100110005020190313110030");
messageDTO.setReg_type(RegistrationType.UPDATE.name());
IdResponseDTO idResponseDTO = new IdResponseDTO();
idResponseDTO.setErrors(errors);

when(utilities.getRegistrationProcessorMappingJson(MappingJsonConstants.IDENTITY)).thenReturn(identityObj);
when(utilities.getRegistrationProcessorMappingJson(MappingJsonConstants.DOCUMENT)).thenReturn(documentObj);
Mockito.when(registrationStatusMapperUtil
.getStatusCode(RegistrationExceptionTypeCode.PACKET_UIN_GENERATION_REPROCESS)).thenReturn(RegistrationTransactionStatusCode.REPROCESS.toString());

when(packetManagerService.getFields(any(), any(), any(), any())).thenReturn(new HashMap<>());
when(packetManagerService.getFieldByMappingJsonKey(anyString(), anyString(), any(), any())).thenReturn("0.1");

when(idrepoDraftService.idrepoUpdateDraft(anyString(), any(), any())).thenReturn(idResponseDTO);

MessageDTO result = uinGeneratorStage.process(messageDTO);

assertEquals(RegistrationTransactionStatusCode.REPROCESS.toString(), registrationStatusDto.getLatestTransactionStatusCode());
assertTrue(result.getInternalError());
assertTrue(result.getIsValid());
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

@Test
public void testProcess_UinGenerationFailed_ShouldSetReprocessStatus() throws IOException, PacketManagerException, ApisResourceAccessException, JsonProcessingException,
IdrepoDraftReprocessableException, IdrepoDraftException {

List<ErrorDTO> errors = new ArrayList<>();
ErrorDTO errorDTO = new ErrorDTO();
errorDTO.setErrorCode("IDR-IDC-005");
errors.add(errorDTO);

MessageDTO messageDTO = new MessageDTO();
messageDTO.setRid("10031100110005020190313110030");
messageDTO.setReg_type(RegistrationType.UPDATE.name());
IdResponseDTO idResponseDTO = new IdResponseDTO();
idResponseDTO.setErrors(errors);

when(utilities.getRegistrationProcessorMappingJson(MappingJsonConstants.IDENTITY)).thenReturn(identityObj);
when(utilities.getRegistrationProcessorMappingJson(MappingJsonConstants.DOCUMENT)).thenReturn(documentObj);
Mockito.when(registrationStatusMapperUtil
.getStatusCode(RegistrationExceptionTypeCode.PACKET_UIN_GENERATION_FAILED)).thenReturn(RegistrationTransactionStatusCode.REPROCESS.toString());

when(packetManagerService.getFields(any(), any(), any(), any())).thenReturn(new HashMap<>());
when(packetManagerService.getFieldByMappingJsonKey(anyString(), anyString(), any(), any())).thenReturn("0.1");

when(idrepoDraftService.idrepoUpdateDraft(anyString(), any(), any())).thenReturn(idResponseDTO);

MessageDTO result = uinGeneratorStage.process(messageDTO);

assertEquals(RegistrationTransactionStatusCode.REPROCESS.toString(), registrationStatusDto.getLatestTransactionStatusCode());
assertTrue(result.getInternalError());
assertTrue(result.getIsValid());
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

@Test
public void testLostAndUpdateUin_WhenIdRepoDraftReturnsNull_ShouldSetValidStatusFalse() throws Exception {
Map<String, String> fieldMap = new HashMap<>();
fieldMap.put("UIN", "123456");
fieldMap.put("name", "mono");
fieldMap.put("email", "mono@mono.com");

List<String> defaultFields = new ArrayList<>();
defaultFields.add("name");
defaultFields.add("dob");
defaultFields.add("gender");
defaultFields.add("UIN");
when(idRepoService.getUinByRid(anyString(), anyString())).thenReturn("9403107397");

when(utility.getUIn(any(),any(),any(ProviderStageName.class))).thenReturn("123456");
when(packetManagerService.getFieldByMappingJsonKey(anyString(),anyString(),any(),any())).thenReturn("0.1");
when(packetManagerService.getFields(anyString(),anyList(),anyString(),any())).thenReturn(fieldMap);
when(idSchemaUtil.getDefaultFields(anyDouble())).thenReturn(defaultFields);

when(idSchemaUtil.getDefaultFields(anyDouble())).thenReturn(defaultFields);
MessageDTO messageDTO = new MessageDTO();
messageDTO.setRid("27847657360002520181210094052");
messageDTO.setReg_type(RegistrationType.LOST.name());
String str = "{\"id\":\"mosip.id.read\",\"version\":\"1.0\",\"responsetime\":\"2019-04-05\",\"metadata\":null,\"response\":{\"uin\":\"2812936908\"},\"errors\":[{\"errorCode\":null,\"errorMessage\":null}]}";
String response = "{\"timestamp\":1553771083721,\"status\":404,\"errors\":[{\"errorCode\":\"KER-UIG-004\",\"errorMessage\":\"Given UIN is not in ISSUED status\"}]}";

when(utilities.getRegistrationProcessorMappingJson(MappingJsonConstants.IDENTITY)).thenReturn(identityObj);
when(registrationProcessorRestClientService.putApi(any(), any(), any(), any(), any(), any(), any()))
.thenReturn(response);

when(packetManagerService.getField(any(), any(), any(),any())).thenReturn("989879234");

when(packetManagerService.getFieldByMappingJsonKey(any(), any(), any(), any())).thenReturn("1.0");
when(regLostUinDetEntity.getLostUinMatchedRegIdByWorkflowId(any())).thenReturn("27847657360002520181210094052");
MessageDTO result = uinGeneratorStage.process(messageDTO);
assertFalse(result.getInternalError());
assertFalse(result.getIsValid());
}

@Test
public void testReactivateUin_WhenStatusActivated() throws Exception {

Map<String, String> fieldMap = new HashMap<>();
fieldMap.put("UIN", "123456");
fieldMap.put("name", "mono");
fieldMap.put("email", "mono@mono.com");

List<String> defaultFields = new ArrayList<>();
defaultFields.add("name");
defaultFields.add("dob");
defaultFields.add("gender");
defaultFields.add("UIN");

when(utility.getUIn(any(),any(),any(ProviderStageName.class))).thenReturn("123456");
when(packetManagerService.getFieldByMappingJsonKey(anyString(),anyString(),any(),any())).thenReturn("0.1");
when(packetManagerService.getFields(any(), any(), any(), any())).thenReturn(fieldMap);
when(idSchemaUtil.getDefaultFields(anyDouble())).thenReturn(defaultFields);

when(idSchemaUtil.getDefaultFields(anyDouble())).thenReturn(defaultFields);

MessageDTO messageDTO = new MessageDTO();
messageDTO.setRid("27847657360002520181210094052");
messageDTO.setReg_type(RegistrationType.valueOf("ACTIVATED").name());

IdResponseDTO idResponseDTO = new IdResponseDTO();
ResponseDTO responseDTO = new ResponseDTO();
idResponseDTO.setErrors(null);
idResponseDTO.setId("mosip.id.update");
responseDTO.setStatus(io.mosip.registration.processor.status.code.RegistrationType.ACTIVATED.toString());
idResponseDTO.setResponse(responseDTO);
idResponseDTO.setResponsetime("2019-01-17T06:29:01.940Z");
idResponseDTO.setVersion("1.0");

IdResponseDTO idResponseDTO1 = new IdResponseDTO();
ResponseDTO responseDTO1 = new ResponseDTO();
idResponseDTO1.setErrors(null);
idResponseDTO1.setId("mosip.id.update");
responseDTO1.setStatus("ANY");
idResponseDTO1.setResponse(responseDTO1);
idResponseDTO1.setResponsetime("2019-01-17T06:29:01.940Z");
idResponseDTO1.setVersion("1.0");

when(registrationProcessorRestClientService.getApi(any(), any(), anyString(), any(), any()))
.thenReturn(idResponseDTO1);

when(idrepoDraftService.idrepoUpdateDraft(anyString(), any(), any())).thenReturn(idResponseDTO);
when(registrationProcessorRestClientService.patchApi(any(), any(), any(), any(), any(), any()))
.thenReturn(idResponseDTO1);
MessageDTO result = uinGeneratorStage.process(messageDTO);
assertTrue(result.getIsValid());
assertFalse(result.getInternalError());
}
Comment thread
ashok-ksharma marked this conversation as resolved.

@Test
public void testUinUpdate_WhenIdRepoStatusDrafted_ShouldReturnTrue() throws ApisResourceAccessException, IOException, JsonProcessingException,
PacketManagerException, JSONException, IdrepoDraftException, IdrepoDraftReprocessableException {
Map<String, String> fieldMap = new HashMap<>();
fieldMap.put("UIN", "123456");
fieldMap.put("name", "mono");
fieldMap.put("email", "mono@mono.com");

List<String> defaultFields = new ArrayList<>();
defaultFields.add("name");
defaultFields.add("dob");
defaultFields.add("gender");
defaultFields.add("UIN");

when(utility.getUIn(any(),any(),any(ProviderStageName.class))).thenReturn("123456");
when(packetManagerService.getFields(any(), any(), any(), any())).thenReturn(fieldMap);

when(packetManagerService.getFieldByMappingJsonKey(anyString(),anyString(),any(),any())).thenReturn("0.1");
when(packetManagerService.getFields(anyString(),anyList(),anyString(),any())).thenReturn(fieldMap);
when(idSchemaUtil.getDefaultFields(anyDouble())).thenReturn(defaultFields);

when(idSchemaUtil.getDefaultFields(anyDouble())).thenReturn(defaultFields);
MessageDTO messageDTO = new MessageDTO();
messageDTO.setRid("10031100110005020190313110030");
messageDTO.setReg_type(RegistrationType.valueOf("UPDATE").name());
IdResponseDTO responsedto = new IdResponseDTO();

IdResponseDTO idResponseDTO = new IdResponseDTO();
ResponseDTO responseDTO = new ResponseDTO();
idResponseDTO.setErrors(null);
idResponseDTO.setId("mosip.id.update");
responseDTO.setStatus(IDREPO_STATUS);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
idResponseDTO.setResponse(responseDTO);
idResponseDTO.setResponsetime("2019-03-12T06:49:30.779Z");
idResponseDTO.setVersion("1.0");

when(idrepoDraftService.idrepoUpdateDraft(anyString(), any(), any())).thenReturn(idResponseDTO);
when(registrationProcessorRestClientService.getApi(any(), any(), anyString(), any(), any()))
.thenReturn(responsedto);
when(registrationProcessorRestClientService.patchApi(any(), any(), any(), any(), any(), any()))
.thenReturn(idResponseDTO);
when(utilities.getRegistrationProcessorMappingJson(MappingJsonConstants.IDENTITY)).thenReturn(identityObj);
when(utilities.getRegistrationProcessorMappingJson(MappingJsonConstants.DOCUMENT)).thenReturn(documentObj);

MessageDTO result = uinGeneratorStage.process(messageDTO);
assertTrue(result.getIsValid());
assertFalse(result.getInternalError());
}

}
Comment thread
ashok-ksharma marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -535,4 +535,32 @@ public void PacketManagerNonRecoverableExceptionTest() throws ApisResourceAccess
assertTrue(response.getInternalError());
}

@Test
public void testSuccessFlow_WhenManualVerificationRejected_ShouldSetRejectedStatus() throws com.fasterxml.jackson.core.JsonProcessingException {

Mockito.when(basePacketRepository.getAssignedVerificationRecord(anyString(), anyString())).thenReturn(entities);
String response = objectMapper.writeValueAsString(resp);
ActiveMQBytesMessage amq = new ActiveMQBytesMessage();
ByteSequence byteSeq = new ByteSequence();
byteSeq.setData(response.getBytes());
amq.setContent(byteSeq);
resp.setReturnValue(4);
boolean result = verificationService.updatePacketStatus(resp, stageName, queue);
assertTrue(result);
}

@Test
public void testSuccessFlow_WhenManualVerificationApproved_ShouldSetSuccessStatus() throws com.fasterxml.jackson.core.JsonProcessingException {

Mockito.when(basePacketRepository.getAssignedVerificationRecord(anyString(), anyString())).thenReturn(entities);
String response = objectMapper.writeValueAsString(resp);
ActiveMQBytesMessage amq = new ActiveMQBytesMessage();
ByteSequence byteSeq = new ByteSequence();
byteSeq.setData(response.getBytes());
amq.setContent(byteSeq);
resp.setReturnValue(1);
boolean result = verificationService.updatePacketStatus(resp, stageName, queue);
assertTrue(result);
}

}
Loading