diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ProxyIdRepoServiceImpl.java b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ProxyIdRepoServiceImpl.java index c8da526db7..46c99afb29 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ProxyIdRepoServiceImpl.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ProxyIdRepoServiceImpl.java @@ -272,11 +272,9 @@ private String getDescription(ResidentTransactionEntity residentTransactionEntit private ResidentTransactionEntity getEventIdFromRid(String rid, String individualId, List attributes) throws ResidentServiceCheckedException, ApisResourceAccessException { ResidentTransactionEntity residentTransactionEntityAlreadyPresent = residentTransactionRepository.findTopByAidOrderByCrDtimesDesc(rid); - String eventId = residentTransactionEntityAlreadyPresent.getEventId(); - if(eventId == null){ + if(residentTransactionEntityAlreadyPresent == null){ ResidentTransactionEntity residentTransactionEntity = utility.createEntity(RequestType.UPDATE_MY_UIN); - eventId = utility.createEventId(); - residentTransactionEntity.setEventId(eventId); + residentTransactionEntity.setEventId(utility.createEventId()); residentTransactionEntity.setRefId(utility.convertToMaskData(individualId)); residentTransactionEntity.setIndividualId(individualId); residentTransactionEntity.setTokenId(identityServiceImpl.getResidentIdaToken()); diff --git a/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ProxyIdRepoServiceTest.java b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ProxyIdRepoServiceTest.java index 01f20ecd0b..ff5c28ea60 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ProxyIdRepoServiceTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/service/impl/ProxyIdRepoServiceTest.java @@ -240,4 +240,39 @@ public void testGetPendingDraftsSuccessWithPendingDraft() throws ResidentService assertEquals("123", service.getPendingDrafts("eng").getResponse().getDrafts().get(0).getEid()); } + @Test + public void testGetPendingDraftsSuccessWithPendingDraftEmptyValue() throws ResidentServiceCheckedException, ApisResourceAccessException { + ResponseWrapper responseWrapper = new ResponseWrapper<>(); + DraftResponseDto draftResponseDto = new DraftResponseDto(); + DraftUinResponseDto draftUinResponseDto = new DraftUinResponseDto(); + draftUinResponseDto.setAttributes(List.of("PHONE")); + draftUinResponseDto.setRid("123"); + draftUinResponseDto.setCreatedDTimes(LocalDateTime.now().toString()); + draftResponseDto.setDrafts(List.of(draftUinResponseDto)); + responseWrapper.setResponse(draftResponseDto); + ResidentTransactionEntity residentTransactionEntity = new ResidentTransactionEntity(); + residentTransactionEntity.setStatusCode(EventStatusInProgress.NEW.name()); + residentTransactionEntity.setRequestTypeCode(RequestType.UPDATE_MY_UIN.name()); + residentTransactionEntity.setEventId("123"); + + ResidentTransactionEntity residentTransactionEntity1 = new ResidentTransactionEntity(); + residentTransactionEntity1.setStatusCode(EventStatusInProgress.NEW.name()); + residentTransactionEntity1.setRequestTypeCode(RequestType.UPDATE_MY_UIN.name()); + residentTransactionEntity1.setEventId("1234"); + + when(identityServiceImpl.getResidentIndvidualIdFromSession()).thenReturn("123"); + when(identityServiceImpl.getUinForIndividualId(Mockito.anyString())).thenReturn("123"); + when(environment.getProperty(Mockito.anyString())).thenReturn("id"); + when(residentServiceRestClient.getApi(any(), (Map) any(), any())).thenReturn(responseWrapper); + when(objectMapper.convertValue((Object) any(), (Class) any())).thenReturn(draftResponseDto); + when(residentTransactionRepository.findTopByAidOrderByCrDtimesDesc(Mockito.anyString())).thenReturn(null); + when(residentTransactionRepository.findByTokenIdAndRequestTypeCodeAndStatusCode(Mockito.anyString() + , Mockito.anyString(), Mockito.anyString())).thenReturn(List.of(residentTransactionEntity, residentTransactionEntity1)); + when(utility.createEntity(any())).thenReturn(residentTransactionEntity); + when(identityServiceImpl.getResidentIdaToken()).thenReturn("123"); + when(residentService.getEventStatusCode(Mockito.anyString(), Mockito.anyString())).thenReturn(Tuples.of(EventStatusInProgress.NEW.name(), + "eng")); + assertEquals(1, service.getPendingDrafts("eng").getResponse().getDrafts().size()); + } + }