Skip to content

Commit

Permalink
MOSIP-29105 Fixed automation issue. (#1069) (#1070)
Browse files Browse the repository at this point in the history
* Fixed service history issue.

* MOSIP-27716 Moved identity-data-formatter.mvel to credentialdata.mvel.

* Fixed Null pointer exception in notification method.

* MOSIP-28516 Removed redundant code for download personalized card.

* MOSIP-28516 Removed redundant code for contact details send otp.

* MOSIP-28516 Removed extra variable in sendNotificationV2.

* Fix Profile api issue in resident.

* MOSIP-29099 Fix Update UIN issue.

* MOSIP-29099 Fix Update UIN issue.

* MOSIP-29105 Fixed automation issue.

* MOSIP-29105 Fixed automation issue.

* MOSIP-29105 Fixed automation issue.
  • Loading branch information
kameshsr authored Aug 29, 2023
1 parent b4d2b99 commit 2b017ed
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public enum ResidentErrorCode {
IDVID_NOT_MATCH_TO_SESSION("RES-SER-452", "Provided individualId does not belong to the logged in session."),
UNAUTHORIZED("RES-ATH-401", "Authentication Failed"),
VID_NOT_BELONG_TO_INDIVITUAL("RES-SER-453", "Provided VID does not belong to the individualId."),
VID_NOT_BELONG_TO_SESSION("RES-SER-454", "Provided VID does not belong to the logged in session."),
VID_NOT_BELONG_TO_USER("RES-SER-454", "Provided VID does not belong to the logged in user."),
RID_NOT_FOUND("RES-SER-456", "RID not found"), AID_NOT_FOUND("RES-SER-457", "AID not found"),
CREDENTIAL_REQUEST_ID_NOT_FOUND("RES-SER-458", "Credential request id not found"),
CREDENTIAL_REQUEST_NOT_FOUND("RES-SER-459", "Credential request not found"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,13 +367,13 @@ public Tuple2<ResponseWrapper<VidDownloadCardResponseDto>, String> getVidCardEve
String eventId = ResidentConstants.NOT_AVAILABLE;
ResidentTransactionEntity residentTransactionEntity = null;
String uinForVid = "";
IdentityDTO identityDTOForDownloadableCardVid = null;
IdentityDTO identityDTO = null;
try {
identityDTOForDownloadableCardVid = identityService.getIdentity(vid);
if(identityDTOForDownloadableCardVid!=null) {
uinForVid = identityDTOForDownloadableCardVid.getUIN();
identityDTO = identityService.getIdentity(identityService.getResidentIndvidualIdFromSession());
if(identityDTO!=null) {
uinForVid = utilities.getUinByVid(vid);
}
residentTransactionEntity = insertDataForVidCard(vid, uinForVid);
residentTransactionEntity = insertDataForVidCard(vid, identityDTO.getUIN());
if (residentTransactionEntity != null) {
eventId = residentTransactionEntity.getEventId();
String uinForIndividualId = identityService.
Expand All @@ -383,8 +383,8 @@ public Tuple2<ResponseWrapper<VidDownloadCardResponseDto>, String> getVidCardEve
residentTransactionEntity.setStatusCode(EventStatusFailure.FAILED.name());
logger.error(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.APPLICATIONID.toString(),
LoggerFileConstant.APPLICATIONID.toString(),
ResidentErrorCode.VID_NOT_BELONG_TO_SESSION.getErrorMessage());
throw new ResidentServiceCheckedException(ResidentErrorCode.VID_NOT_BELONG_TO_SESSION,
ResidentErrorCode.VID_NOT_BELONG_TO_USER.getErrorMessage());
throw new ResidentServiceCheckedException(ResidentErrorCode.VID_NOT_BELONG_TO_USER,
Map.of(ResidentConstants.EVENT_ID, eventId));
}
}
Expand All @@ -397,7 +397,7 @@ public Tuple2<ResponseWrapper<VidDownloadCardResponseDto>, String> getVidCardEve
credentialReqestDto.setEncrypt(
Boolean.parseBoolean(environment.getProperty(ResidentConstants.CREDENTIAL_ENCRYPTION_FLAG)));
credentialReqestDto.setEncryptionKey(environment.getProperty(ResidentConstants.CREDENTIAL_ENCRYPTION_KEY));
Map<String, Object> additionalAttributes = getVidDetails(vid, identityDTOForDownloadableCardVid, timeZoneOffset, locale);
Map<String, Object> additionalAttributes = getVidDetails(vid, identityDTO, timeZoneOffset, locale);
additionalAttributes.put(TEMPLATE_TYPE_CODE,
this.environment.getProperty(ResidentConstants.VID_CARD_TEMPLATE_PROPERTY));
additionalAttributes.put(APPLICANT_PHOTO,
Expand Down Expand Up @@ -450,8 +450,8 @@ public Tuple2<ResponseWrapper<VidDownloadCardResponseDto>, String> getVidCardEve
.equals(EventStatusInProgress.NEW.name())) ? TemplateType.REQUEST_RECEIVED
: TemplateType.FAILURE;

sendNotificationV2(uinForVid, RequestType.VID_CARD_DOWNLOAD, templateType,
eventId, null, identityDTOForDownloadableCardVid);
sendNotificationV2(identityDTO.getUIN(), RequestType.VID_CARD_DOWNLOAD, templateType,
eventId, null, identityDTO);
}
}
responseWrapper.setId(environment.getProperty(ResidentConstants.VID_DOWNLOAD_CARD_ID));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ public Tuple2<ResponseWrapper<VidRevokeResponseDTO>, String> revokeVidV2(BaseVid
try {
identityDTO = identityServiceImpl.getIdentity(indivudalId);
} catch (Exception e){
throw new ResidentServiceCheckedException(ResidentErrorCode.VID_NOT_BELONG_TO_SESSION,
throw new ResidentServiceCheckedException(ResidentErrorCode.VID_NOT_BELONG_TO_USER,
Map.of(ResidentConstants.EVENT_ID, eventId));
}
uin = identityDTO.getUIN();
Expand All @@ -496,7 +496,7 @@ public Tuple2<ResponseWrapper<VidRevokeResponseDTO>, String> revokeVidV2(BaseVid
residentTransactionEntity.setStatusCode(EventStatusFailure.FAILED.name());
residentTransactionEntity.setRequestSummary(String.format("%s - %s", RequestType.REVOKE_VID.getName(), ResidentConstants.FAILED));
residentTransactionRepository.save(residentTransactionEntity);
throw new ResidentServiceCheckedException(ResidentErrorCode.VID_NOT_BELONG_TO_SESSION,
throw new ResidentServiceCheckedException(ResidentErrorCode.VID_NOT_BELONG_TO_USER,
Map.of(ResidentConstants.EVENT_ID, eventId));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,7 @@ public void validateEuinRequest(RequestWrapper<EuinRequestDTO> requestDTO) {

public void validateAuthHistoryRequest(@Valid RequestWrapper<AuthHistoryRequestDTO> requestDTO) {
validateRequest(requestDTO, RequestIdType.AUTH_HISTORY_ID);

if (StringUtils.isEmpty(requestDTO.getRequest().getIndividualId()))
throw new InvalidInputException("individualId");
validateIndividualIdV2(requestDTO.getRequest().getIndividualId(), "Request auth history API");

if (StringUtils.isEmpty(requestDTO.getRequest().getOtp())) {
audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.INPUT_INVALID, "otp", "Request for auth history"));
Expand Down Expand Up @@ -1312,13 +1310,15 @@ public void validateDownloadCardRequest(MainRequestDTO<DownloadCardRequestDTO> d
validateDate(downloadCardRequestDTOMainRequestDTO.getRequesttime());
validateTransactionId(downloadCardRequestDTOMainRequestDTO.getRequest().getTransactionId());
validateOTP(downloadCardRequestDTOMainRequestDTO.getRequest().getOtp());
validateIndividualIdV2(downloadCardRequestDTOMainRequestDTO.getRequest().getIndividualId());
String individualId = downloadCardRequestDTOMainRequestDTO.getRequest().getIndividualId();
validateMissingInputParameter(individualId, TemplateVariablesConstants.INDIVIDUAL_ID, "Validation IndividualId");
validateIndividualIdV2(individualId, "Request Download Card Request");
}

private void validateIndividualIdV2(String individualId) {
private void validateIndividualIdV2(String individualId, String eventName) {
if (individualId == null || StringUtils.isEmpty(individualId) || !validateIndividualIdvIdWithoutIdType(individualId)) {
audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.INPUT_INVALID, "individualId",
"Request service history API"));
eventName));
throw new InvalidInputException("individualId");
}
}
Expand Down Expand Up @@ -1391,7 +1391,7 @@ private void validateAPIRequestToCheckNull(RequestWrapper<?> requestWrapper) {

public void validateReqCredentialRequest(RequestWrapper<ResidentCredentialRequestDto> requestWrapper) {
validateAPIRequestToCheckNull(requestWrapper);
validateDataToCheckNullOrEmpty(requestWrapper.getRequest().getIndividualId(), ResidentConstants.INDIVIDUAL_ID);
validateIndividualIdV2(requestWrapper.getRequest().getIndividualId(), "Credential Request API");
validateDataToCheckNullOrEmpty(requestWrapper.getRequest().getCredentialType(),
ResidentConstants.CREDENTIAL_TYPE);
validateDataToCheckNullOrEmpty(requestWrapper.getRequest().getIssuer(), ResidentConstants.ISSUER);
Expand Down Expand Up @@ -1478,7 +1478,7 @@ private void validateEventIdBelongToSameSession(String eventId) throws ResidentS
}

public void validateReqOtp(IndividualIdOtpRequestDTO individualIdRequestDto) {
validateIndividualIdV2(individualIdRequestDto.getIndividualId());
validateIndividualIdV2(individualIdRequestDto.getIndividualId(), "Request OTp");
validateTransactionId(individualIdRequestDto.getTransactionId());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,6 @@ public void setup() throws Exception {
Mockito.when(identityService.getIdentity("1234567890")).thenReturn(identityDTO);
Mockito.when(identityService.getIdentity("7841261580")).thenReturn(identityDTO);
identityDTO.setUIN("123");
IdentityDTO identityDTO1 = new IdentityDTO();
identityDTO1.setUIN("234");
Mockito.when(identityService.getIdentity("123")).thenReturn(identityDTO1);
Map<String, Object> identityAttributes = new HashMap<>();
Mockito.when(identityService.getIdentityAttributes("1234567890",null)).thenReturn(identityAttributes);
}
Expand Down Expand Up @@ -289,15 +286,17 @@ public void testDownloadPersonalizedCardIOException() throws ResidentServiceChec
}

@Test
public void testGetVidCardEventIdWithVidDetails() throws BaseCheckedException {
public void testGetVidCardEventIdWithVidDetails() throws BaseCheckedException, IOException {
Mockito.when(identityService.getResidentIndvidualIdFromSession()).thenReturn("3257091426984315");
Map<String, Object> name = new HashMap<>();
name.put("language", "eng");
name.put("value", "kamesh");
identityMap.put("firstName", List.of(name));
IdentityDTO identityDTO = new IdentityDTO();
identityDTO.setDateOfBirth("1892-08-09");
identityDTO.setUIN("8251649601");
Mockito.when(identityService.getIdentity(Mockito.anyString())).thenReturn(identityDTO);
Mockito.when(utilities.getUinByVid(Mockito.anyString())).thenReturn("8251649601");
ResponseWrapper<ResidentCredentialResponseDto> responseWrapper = new ResponseWrapper<>();
ResidentCredentialResponseDto residentCredentialResponseDto = new ResidentCredentialResponseDto();
residentCredentialResponseDto.setId("123");
Expand All @@ -311,11 +310,13 @@ public void testGetVidCardEventIdWithVidDetails() throws BaseCheckedException {
}

@Test
public void testGetVidCardEventIdWithNameNull() throws BaseCheckedException {
public void testGetVidCardEventIdWithNameNull() throws BaseCheckedException, IOException {
Mockito.when(identityService.getResidentIndvidualIdFromSession()).thenReturn("3257091426984315");
IdentityDTO identityDTO = new IdentityDTO();
identityDTO.setDateOfBirth("1892-08-09");
identityDTO.setUIN("8251649601");
Mockito.when(identityService.getIdentity(Mockito.anyString())).thenReturn(identityDTO);
Mockito.when(utilities.getUinByVid(Mockito.anyString())).thenReturn("8251649601");
ResponseWrapper<ResidentCredentialResponseDto> responseWrapper = new ResponseWrapper<>();
ResidentCredentialResponseDto residentCredentialResponseDto = new ResidentCredentialResponseDto();
residentCredentialResponseDto.setId("123");
Expand All @@ -342,14 +343,11 @@ public void testGetVidCardEventIdWithRequestCredentialFailed() throws BaseChecke
}

@Test(expected = ApisResourceAccessException.class)
public void testGetVidCardEventIdWithApisResourceAccessException() throws BaseCheckedException {
public void testGetVidCardEventIdWithApisResourceAccessException() throws BaseCheckedException, IOException {
IdentityDTO identityDTO = new IdentityDTO();
identityDTO.setUIN("123456789");
Mockito.when(identityService.getIdentity("1234567890")).thenReturn(identityDTO);
identityDTO.setUIN("123");
IdentityDTO identityDTO1 = new IdentityDTO();
identityDTO1.setUIN("123");
Mockito.when(identityService.getIdentity("123")).thenReturn(identityDTO1);
identityDTO.setUIN("8251649601");
Mockito.when(identityService.getIdentity(Mockito.anyString())).thenReturn(identityDTO);
Mockito.when(utilities.getUinByVid(Mockito.anyString())).thenReturn("8251649601");
Mockito.when(vidService.retrieveVids(Mockito.anyInt(), Mockito.anyString(), Mockito.anyString()))
.thenThrow(new ApisResourceAccessException());
downloadCardService.getVidCardEventId("123", 0, LOCALE_EN_US);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1809,7 +1809,7 @@ public void testValidateDownloadCardNonNumericOtp() throws Exception{
requestValidator.validateDownloadCardRequest(downloadCardRequestDTOMainRequestDTO);
}

@Test(expected = InvalidInputException.class)
@Test(expected = ResidentServiceException.class)
public void testValidateDownloadCardInvalidIndividualId() throws Exception{
io.mosip.resident.dto.MainRequestDTO<DownloadCardRequestDTO> downloadCardRequestDTOMainRequestDTO =
new io.mosip.resident.dto.MainRequestDTO<>();
Expand All @@ -1822,7 +1822,7 @@ public void testValidateDownloadCardInvalidIndividualId() throws Exception{
requestValidator.validateDownloadCardRequest(downloadCardRequestDTOMainRequestDTO);
}

@Test(expected = InvalidInputException.class)
@Test(expected = ResidentServiceException.class)
public void testValidateDownloadCardEmptyIndividualId() throws Exception{
io.mosip.resident.dto.MainRequestDTO<DownloadCardRequestDTO> downloadCardRequestDTOMainRequestDTO =
new io.mosip.resident.dto.MainRequestDTO<>();
Expand Down Expand Up @@ -2659,7 +2659,7 @@ public void testValidateReqCredentialRequestSuccess(){
requestValidator.validateReqCredentialRequest(requestWrapper);
}

@Test(expected = ResidentServiceException.class)
@Test(expected = InvalidInputException.class)
public void testValidateReqCredentialRequestFailure(){
RequestWrapper<ResidentCredentialRequestDto> requestWrapper = new RequestWrapper<>();
ResidentCredentialRequestDto residentCredentialRequestDto = new ResidentCredentialRequestDto();
Expand Down

0 comments on commit 2b017ed

Please sign in to comment.