diff --git a/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentController.java b/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentController.java index c3d4012dbb4..c3b92924d92 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentController.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentController.java @@ -51,6 +51,8 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; +import reactor.util.function.Tuple2; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.env.Environment; @@ -228,7 +230,7 @@ public ResponseWrapper reqAuthUnlock( @ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))), @ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true))), @ApiResponse(responseCode = "404", description = "Not Found", content = @Content(schema = @Schema(hidden = true))) }) - public ResponseWrapper reqAauthTypeStatusUpdateV2( + public ResponseEntity reqAauthTypeStatusUpdateV2( @Valid @RequestBody RequestWrapper requestDTO) throws ResidentServiceCheckedException, ApisResourceAccessException { audit.setAuditRequestDto( @@ -237,11 +239,14 @@ public ResponseWrapper reqAauthTypeStatusUpdateV2( validator.validateAuthLockOrUnlockRequestV2(requestDTO); audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.REQ_AUTH_LOCK, individualId)); ResponseWrapper response = new ResponseWrapper<>(); - response.setResponse(residentService.reqAauthTypeStatusUpdateV2(requestDTO.getRequest())); + Tuple2 tupleResponse = residentService.reqAauthTypeStatusUpdateV2(requestDTO.getRequest()); + response.setResponse(tupleResponse.getT1()); response.setId(authLockStatusUpdateV2Id); response.setVersion(authLockStatusUpdateV2Version); audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.REQ_AUTH_LOCK_SUCCESS, individualId)); - return response; + return ResponseEntity.ok() + .header(ResidentConstants.EVENT_ID, tupleResponse.getT2()) + .body(response); } @ResponseFilter diff --git a/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentCredentialController.java b/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentCredentialController.java index bddb9c2ad8b..fd2e46c819b 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentCredentialController.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/controller/ResidentCredentialController.java @@ -29,6 +29,7 @@ import io.mosip.kernel.core.http.ResponseWrapper; import io.mosip.resident.constant.RequestIdType; import io.mosip.resident.constant.RequestType; +import io.mosip.resident.constant.ResidentConstants; import io.mosip.resident.dto.CredentialCancelRequestResponseDto; import io.mosip.resident.dto.CredentialRequestStatusResponseDto; import io.mosip.resident.dto.CredentialTypeResponse; @@ -52,6 +53,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; +import reactor.util.function.Tuple2; @RestController @Tag(name = "resident-credential-controller", description = "Resident Credential Controller") @@ -116,15 +118,19 @@ public ResponseEntity requestShareCredWithPartner( request.setRequest(credentialRequestDto); buildAdditionalMetadata(requestDTO, request); ResponseWrapper response = new ResponseWrapper<>(); + Tuple2 tupleResponse; if(purpose != null) { - response.setResponse(residentCredentialService.shareCredential(request.getRequest(), RequestType.SHARE_CRED_WITH_PARTNER.name(),purpose)); + tupleResponse = residentCredentialService.shareCredential(request.getRequest(), RequestType.SHARE_CRED_WITH_PARTNER.name(),purpose); }else { - response.setResponse(residentCredentialService.shareCredential(request.getRequest(), RequestType.SHARE_CRED_WITH_PARTNER.name())); + tupleResponse = residentCredentialService.shareCredential(request.getRequest(), RequestType.SHARE_CRED_WITH_PARTNER.name()); } response.setId(shareCredentialId); response.setVersion(shareCredentialVersion); + response.setResponse(tupleResponse.getT1()); audit.setAuditRequestDto(EventEnum.CREDENTIAL_REQ_SUCCESS); - return ResponseEntity.status(HttpStatus.OK).body(response); + return ResponseEntity.status(HttpStatus.OK) + .header(ResidentConstants.EVENT_ID, tupleResponse.getT2()) + .body(response); } @GetMapping(value = "req/credential/status/{requestId}") diff --git a/resident/resident-service/src/main/java/io/mosip/resident/dto/AuthLockUnlockResponseDto.java b/resident/resident-service/src/main/java/io/mosip/resident/dto/AuthLockUnlockResponseDto.java deleted file mode 100644 index 26f0ea6aff6..00000000000 --- a/resident/resident-service/src/main/java/io/mosip/resident/dto/AuthLockUnlockResponseDto.java +++ /dev/null @@ -1,17 +0,0 @@ -package io.mosip.resident.dto; - -import lombok.Data; -import lombok.EqualsAndHashCode; - -/** - * The Auth Lock Unlock response dto. - * - * @author Ritik Jain - */ -@Data -@EqualsAndHashCode(callSuper = true) -public class AuthLockUnlockResponseDto extends ResponseDTO { - - private String eventId; - -} diff --git a/resident/resident-service/src/main/java/io/mosip/resident/dto/ResidentCredentialResponseDtoV2.java b/resident/resident-service/src/main/java/io/mosip/resident/dto/ResidentCredentialResponseDtoV2.java index bc07aeea7d0..e736ee6761e 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/dto/ResidentCredentialResponseDtoV2.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/dto/ResidentCredentialResponseDtoV2.java @@ -10,7 +10,6 @@ @Data public class ResidentCredentialResponseDtoV2 { - private String eventId; private String status; } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/exception/ResidentCredentialServiceException.java b/resident/resident-service/src/main/java/io/mosip/resident/exception/ResidentCredentialServiceException.java index 984666a0a43..3eb00bdf0dc 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/exception/ResidentCredentialServiceException.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/exception/ResidentCredentialServiceException.java @@ -1,13 +1,19 @@ package io.mosip.resident.exception; +import java.util.Map; + import io.mosip.kernel.core.exception.BaseUncheckedException; +import io.mosip.resident.constant.ResidentErrorCode; +import io.mosip.resident.util.ObjectWithMetadata; -public class ResidentCredentialServiceException extends BaseUncheckedException { +public class ResidentCredentialServiceException extends BaseUncheckedException implements ObjectWithMetadata { /** * Generated serial version id */ private static final long serialVersionUID = 8621530697947108810L; + + private Map metadata; /** * Constructor the initialize Handler exception @@ -29,4 +35,17 @@ public ResidentCredentialServiceException(String errorCode, String errorMessage) public ResidentCredentialServiceException(String errorCode, String errorMessage, Throwable rootCause) { super(errorCode, errorMessage, rootCause); } + + public Map getMetadata() { + return metadata; + } + + public void setMetadata(Map metadata) { + this.metadata = metadata; + } + + public ResidentCredentialServiceException(ResidentErrorCode err, Throwable rootCause, Map metadata) { + this(err.getErrorCode(), err.getErrorMessage(), rootCause); + this.metadata = metadata; + } } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/exception/ResidentServiceException.java b/resident/resident-service/src/main/java/io/mosip/resident/exception/ResidentServiceException.java index 085e7ce1822..1e7cd04f676 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/exception/ResidentServiceException.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/exception/ResidentServiceException.java @@ -70,7 +70,12 @@ public void setMetadata(Map metadata) { public ResidentServiceException(ResidentErrorCode err, Throwable rootCause, Map metadata) { this(err, rootCause); - this.metadata=metadata; + this.metadata = metadata; + } + + public ResidentServiceException(ResidentErrorCode err, Map metadata) { + this(err); + this.metadata = metadata; } } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/ResidentCredentialService.java b/resident/resident-service/src/main/java/io/mosip/resident/service/ResidentCredentialService.java index b2f0399c7a5..f339f806418 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/ResidentCredentialService.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/ResidentCredentialService.java @@ -10,6 +10,7 @@ import io.mosip.resident.dto.ResponseWrapper; import io.mosip.resident.exception.ApisResourceAccessException; import io.mosip.resident.exception.ResidentServiceCheckedException; +import reactor.util.function.Tuple2; public interface ResidentCredentialService { @@ -17,9 +18,9 @@ public interface ResidentCredentialService { public ResidentCredentialResponseDto reqCredential(ResidentCredentialRequestDto request, String id) throws ResidentServiceCheckedException; - public ResidentCredentialResponseDtoV2 shareCredential(ResidentCredentialRequestDto request, String requestType) throws ResidentServiceCheckedException, ApisResourceAccessException; + public Tuple2 shareCredential(ResidentCredentialRequestDto request, String requestType) throws ResidentServiceCheckedException, ApisResourceAccessException; - public ResidentCredentialResponseDtoV2 shareCredential(ResidentCredentialRequestDto request, String requestType, String purpose) throws ResidentServiceCheckedException, ApisResourceAccessException; + public Tuple2 shareCredential(ResidentCredentialRequestDto request, String requestType, String purpose) throws ResidentServiceCheckedException, ApisResourceAccessException; public CredentialRequestStatusResponseDto getStatus(String requestId) throws ResidentServiceCheckedException; diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/ResidentService.java b/resident/resident-service/src/main/java/io/mosip/resident/service/ResidentService.java index 80e2f369cc3..caf1dbc5603 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/ResidentService.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/ResidentService.java @@ -32,6 +32,7 @@ import io.mosip.resident.exception.ApisResourceAccessException; import io.mosip.resident.exception.OtpValidationFailedException; import io.mosip.resident.exception.ResidentServiceCheckedException; +import reactor.util.function.Tuple2; public interface ResidentService { @@ -50,7 +51,7 @@ public ResponseDTO reqAauthTypeStatusUpdate(AuthLockOrUnLockRequestDto dto, Auth public Object reqUinUpdate(ResidentUpdateRequestDto dto, JSONObject demographicJsonObject) throws ResidentServiceCheckedException; - ResponseDTO reqAauthTypeStatusUpdateV2(AuthLockOrUnLockRequestDtoV2 request) + public Tuple2 reqAauthTypeStatusUpdateV2(AuthLockOrUnLockRequestDtoV2 request) throws ResidentServiceCheckedException, ApisResourceAccessException; public ResponseWrapper getAuthLockStatus(String individualId) throws ResidentServiceCheckedException;; diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownloadCardServiceImpl.java b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownloadCardServiceImpl.java index eb86b09b24e..95e8bc5ce10 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownloadCardServiceImpl.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/DownloadCardServiceImpl.java @@ -184,18 +184,23 @@ public Tuple2 downloadPersonalizedCard(MainRequestDTO shareCredential(ResidentCredentialRequestDto dto, String requestType) throws ResidentServiceCheckedException, ApisResourceAccessException { return shareCredential(dto, requestType, null); } @Override - public ResidentCredentialResponseDtoV2 shareCredential(ResidentCredentialRequestDto dto, String requestType, + public Tuple2 shareCredential(ResidentCredentialRequestDto dto, String requestType, String purpose) throws ResidentServiceCheckedException, ApisResourceAccessException { ResidentCredentialResponseDto residentCredentialResponseDto = new ResidentCredentialResponseDto(); ResidentCredentialResponseDtoV2 residentCredentialResponseDtoV2=new ResidentCredentialResponseDtoV2(); @@ -239,10 +241,14 @@ public ResidentCredentialResponseDtoV2 shareCredential(ResidentCredentialRequest String partnerUrl = env.getProperty(ApiName.PARTNER_API_URL.name()) + "/" + dto.getIssuer(); URI partnerUri = URI.create(partnerUrl); String individualId = identityServiceImpl.getResidentIndvidualId(); + String eventId = null; ResidentTransactionEntity residentTransactionEntity = null; try { residentTransactionEntity = createResidentTransactionEntity(dto, requestType, individualId); + if (residentTransactionEntity != null) { + eventId = residentTransactionEntity.getEventId(); + } if (dto.getConsent() == null || dto.getConsent().equalsIgnoreCase(ConsentStatusType.DENIED.name()) || dto.getConsent().trim().isEmpty() || dto.getConsent().equals("null") || !dto.getConsent().equalsIgnoreCase(ConsentStatusType.ACCEPTED.name())) { residentTransactionEntity.setStatusCode(EventStatusFailure.FAILED.name()); @@ -273,27 +279,26 @@ public ResidentCredentialResponseDtoV2 shareCredential(ResidentCredentialRequest } additionalAttributes.put("RID", residentCredentialResponseDto.getRequestId()); sendNotificationV2(individualId, RequestType.valueOf(requestType), TemplateType.REQUEST_RECEIVED, - residentTransactionEntity.getEventId(), additionalAttributes); + eventId, additionalAttributes); updateResidentTransaction(dto, residentCredentialResponseDto, residentTransactionEntity); - residentCredentialResponseDtoV2.setEventId(residentTransactionEntity.getEventId()); residentCredentialResponseDtoV2.setStatus(ResidentConstants.SUCCESS); } catch (ResidentServiceCheckedException | ApisResourceAccessException e) { if (residentTransactionEntity != null) { residentTransactionEntity.setStatusCode(EventStatusFailure.FAILED.name()); sendNotificationV2(individualId, RequestType.valueOf(requestType), TemplateType.FAILURE, - residentTransactionEntity.getEventId(), additionalAttributes); + eventId, additionalAttributes); } audit.setAuditRequestDto(EventEnum.CREDENTIAL_REQ_EXCEPTION); - throw new ResidentCredentialServiceException(ResidentErrorCode.API_RESOURCE_ACCESS_EXCEPTION.getErrorCode(), - ResidentErrorCode.API_RESOURCE_ACCESS_EXCEPTION.getErrorMessage(), e); + throw new ResidentCredentialServiceException(ResidentErrorCode.API_RESOURCE_ACCESS_EXCEPTION, e, + Map.of(ResidentConstants.EVENT_ID, eventId)); } catch (IOException e) { residentTransactionEntity.setStatusCode(EventStatusFailure.FAILED.name()); sendNotificationV2(individualId, RequestType.valueOf(requestType), TemplateType.FAILURE, - residentTransactionEntity.getEventId(), additionalAttributes); + eventId, additionalAttributes); audit.setAuditRequestDto(EventEnum.CREDENTIAL_REQ_EXCEPTION); - throw new ResidentCredentialServiceException(ResidentErrorCode.IO_EXCEPTION.getErrorCode(), - ResidentErrorCode.IO_EXCEPTION.getErrorMessage(), e); + throw new ResidentCredentialServiceException(ResidentErrorCode.IO_EXCEPTION, e, + Map.of(ResidentConstants.EVENT_ID, eventId)); } finally { if (Utilitiy.isSecureSession() && residentTransactionEntity != null) { //if the status code will come as null, it will set it as failed. @@ -304,7 +309,7 @@ public ResidentCredentialResponseDtoV2 shareCredential(ResidentCredentialRequest residentTransactionRepository.save(residentTransactionEntity); } } - return residentCredentialResponseDtoV2; + return Tuples.of(residentCredentialResponseDtoV2, eventId); } private ResidentTransactionEntity createResidentTransactionEntity(ResidentCredentialRequestDto dto, diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentServiceImpl.java b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentServiceImpl.java index 840a9aa11e9..56c56cc5817 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentServiceImpl.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentServiceImpl.java @@ -78,7 +78,6 @@ import io.mosip.resident.dto.AuthLockOrUnLockRequestDto; import io.mosip.resident.dto.AuthLockOrUnLockRequestDtoV2; import io.mosip.resident.dto.AuthLockStatusResponseDtoV2; -import io.mosip.resident.dto.AuthLockUnlockResponseDto; import io.mosip.resident.dto.AuthTxnDetailsDTO; import io.mosip.resident.dto.AuthTypeStatusDtoV2; import io.mosip.resident.dto.AuthUnLockRequestDTO; @@ -152,6 +151,8 @@ import io.mosip.resident.util.UINCardDownloadService; import io.mosip.resident.util.Utilities; import io.mosip.resident.util.Utilitiy; +import reactor.util.function.Tuple2; +import reactor.util.function.Tuples; @Service public class ResidentServiceImpl implements ResidentService { @@ -1122,14 +1123,15 @@ private List getResidentDocuments(ResidentUpdateRequestDto dt } @Override - public ResponseDTO reqAauthTypeStatusUpdateV2(AuthLockOrUnLockRequestDtoV2 authLockOrUnLockRequestDtoV2) + public Tuple2 reqAauthTypeStatusUpdateV2(AuthLockOrUnLockRequestDtoV2 authLockOrUnLockRequestDtoV2) throws ResidentServiceCheckedException, ApisResourceAccessException { logger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.APPLICATIONID.toString(), LoggerFileConstant.APPLICATIONID.toString(), "ResidentServiceImpl::reqAauthTypeStatusUpdate():: entry"); - AuthLockUnlockResponseDto response = new AuthLockUnlockResponseDto(); + ResponseDTO response = new ResponseDTO(); String individualId = identityServiceImpl.getResidentIndvidualId(); boolean isTransactionSuccessful = false; List residentTransactionEntities = List.of(); + String eventId = null; try { audit.setAuditRequestDto( EventEnum.getEventEnumWithValue(EventEnum.REQ_AUTH_TYPE_LOCK, "Request for Auth Type Lock")); @@ -1144,6 +1146,9 @@ public ResponseDTO reqAauthTypeStatusUpdateV2(AuthLockOrUnLockRequestDtoV2 authL throw new RuntimeException(e); } }).collect(Collectors.toList()); + if (!residentTransactionEntities.isEmpty()) { + eventId = residentTransactionEntities.get(0).getEventId(); + } List authTypesStatusList = authLockOrUnLockRequestDtoV2.getAuthTypes(); String authType = authTypesStatusList.stream().map(ResidentServiceImpl::getAuthTypeBasedOnConfigV2) @@ -1176,8 +1181,8 @@ public ResponseDTO reqAauthTypeStatusUpdateV2(AuthLockOrUnLockRequestDtoV2 authL } else { audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.REQUEST_FAILED, "Request for auth " + authLockOrUnLockRequestDtoV2.getAuthTypes() + " lock failed")); - throw new ResidentServiceException(ResidentErrorCode.REQUEST_FAILED.getErrorCode(), - ResidentErrorCode.REQUEST_FAILED.getErrorMessage()); + throw new ResidentServiceException(ResidentErrorCode.REQUEST_FAILED, + Map.of(ResidentConstants.EVENT_ID, eventId)); } } catch (ApisResourceAccessException e) { @@ -1193,8 +1198,8 @@ public ResponseDTO reqAauthTypeStatusUpdateV2(AuthLockOrUnLockRequestDtoV2 authL + ExceptionUtils.getStackTrace(e)); audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.API_NOT_AVAILABLE, "Request for auth" + authLockOrUnLockRequestDtoV2.getAuthTypes() + " lock failed")); - throw new ResidentServiceException(ResidentErrorCode.API_RESOURCE_UNAVAILABLE.getErrorCode(), - ResidentErrorCode.API_RESOURCE_UNAVAILABLE.getErrorMessage(), e); + throw new ResidentServiceException(ResidentErrorCode.API_RESOURCE_UNAVAILABLE, e, + Map.of(ResidentConstants.EVENT_ID, eventId)); } finally { residentTransactionRepository.saveAll(residentTransactionEntities); @@ -1202,7 +1207,7 @@ public ResponseDTO reqAauthTypeStatusUpdateV2(AuthLockOrUnLockRequestDtoV2 authL TemplateType templateType = isTransactionSuccessful ? TemplateType.REQUEST_RECEIVED : TemplateType.FAILURE; NotificationResponseDTO notificationResponseDTO = sendNotificationV2(individualId, requestType, - templateType, residentTransactionEntities.get(0).getEventId(), null); + templateType, eventId, null); if (isTransactionSuccessful) audit.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.SEND_NOTIFICATION_SUCCESS, @@ -1213,12 +1218,11 @@ public ResponseDTO reqAauthTypeStatusUpdateV2(AuthLockOrUnLockRequestDtoV2 authL if (notificationResponseDTO != null) { response.setMessage(notificationResponseDTO.getMessage()); response.setStatus(ResidentConstants.SUCCESS); - response.setEventId(residentTransactionEntities.get(0).getEventId()); } } logger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.APPLICATIONID.toString(), LoggerFileConstant.APPLICATIONID.toString(), "ResidentServiceImpl::reqAauthTypeStatusUpdate():: exit"); - return response; + return Tuples.of(response, eventId); } private ResidentTransactionEntity createResidentTransactionEntity(String individualId, String partnerId) diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentControllerTest.java index a310b134651..33e019b9c3d 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentControllerTest.java @@ -93,6 +93,7 @@ import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.JsonUtil; import io.mosip.resident.validator.RequestValidator; +import reactor.util.function.Tuples; /** * @author Sowmya Ujjappa Banakar @@ -235,7 +236,7 @@ public void testReqAuthTypeLock() throws Exception { ResponseDTO responseDto = new ResponseDTO(); responseDto.setStatus("success"); doNothing().when(validator).validateAuthLockOrUnlockRequestV2(Mockito.any()); - Mockito.doReturn(responseDto).when(residentService).reqAauthTypeStatusUpdateV2(Mockito.any()); + Mockito.doReturn(Tuples.of(responseDto, "12345")).when(residentService).reqAauthTypeStatusUpdateV2(Mockito.any()); residentController.reqAauthTypeStatusUpdateV2(authTypeStatusRequest); validator.validateAuthLockOrUnlockRequestV2(authTypeStatusRequest); this.mockMvc.perform( @@ -248,7 +249,7 @@ public void testReqAuthTypeLock() throws Exception { public void testReqAuthTypeLockBadRequest() throws Exception { ResponseDTO responseDto = new ResponseDTO(); doNothing().when(validator).validateAuthLockOrUnlockRequest(Mockito.any(), Mockito.any()); - Mockito.doReturn(responseDto).when(residentService).reqAauthTypeStatusUpdateV2(Mockito.any()); + Mockito.doReturn(Tuples.of(responseDto, "12345")).when(residentService).reqAauthTypeStatusUpdateV2(Mockito.any()); MvcResult result = this.mockMvc .perform(post("/auth-lock-unlock").contentType(MediaType.APPLICATION_JSON).content("")) diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentCredentialControllerTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentCredentialControllerTest.java index 881a2407dd2..52ed3ede3c6 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentCredentialControllerTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/controller/ResidentCredentialControllerTest.java @@ -53,6 +53,7 @@ import io.mosip.resident.test.ResidentTestBootApplication; import io.mosip.resident.util.AuditUtil; import io.mosip.resident.validator.RequestValidator; +import reactor.util.function.Tuples; @RunWith(SpringRunner.class) @SpringBootTest(classes = ResidentTestBootApplication.class) @@ -114,6 +115,8 @@ public class ResidentCredentialControllerTest { CredentialRequestStatusResponseDto credentialReqStatusResponse; PartnerCredentialTypePolicyDto partnerCredentialTypeReqResponse; + + ResidentCredentialResponseDtoV2 dtoV2; String reqCredentialEventJson; @@ -125,6 +128,7 @@ public void setup() throws Exception { credentialCancelReqResponse = new CredentialCancelRequestResponseDto(); credentialReqResponse = new ResidentCredentialResponseDto(); partnerCredentialTypeReqResponse = new PartnerCredentialTypePolicyDto(); + dtoV2 = new ResidentCredentialResponseDtoV2(); MockitoAnnotations.initMocks(this); this.mockMvc = MockMvcBuilders.standaloneSetup(residentCredentialController).build(); ResidentCredentialRequestDto credentialRequestDto = new ResidentCredentialRequestDto(); @@ -193,7 +197,8 @@ public void testPartnerIdCredentialType() throws Exception { @Test public void testRequestShareCredWithPartner() throws Exception { - Mockito.when(residentCredentialService.shareCredential(Mockito.any(),Mockito.anyString())).thenReturn(new ResidentCredentialResponseDtoV2()); + Mockito.when(residentCredentialService.shareCredential(Mockito.any(), Mockito.anyString(), Mockito.anyString())) + .thenReturn(Tuples.of(dtoV2, "12345")); ShareCredentialRequestDto request = new ShareCredentialRequestDto(); SharableAttributesDTO attr = new SharableAttributesDTO(); attr.setAttributeName("name"); @@ -205,4 +210,16 @@ public void testRequestShareCredWithPartner() throws Exception { mockMvc.perform(MockMvcRequestBuilders.post("/share-credential").contentType(MediaType.APPLICATION_JSON_VALUE) .content(gson.toJson(requestWrapper).getBytes())).andExpect(status().isOk()); } + + @Test + public void testRequestShareCredWithPartnerWithoutPurpose() throws Exception { + Mockito.when(residentCredentialService.shareCredential(Mockito.any(), Mockito.anyString())) + .thenReturn(Tuples.of(dtoV2, "12345")); + ShareCredentialRequestDto request = new ShareCredentialRequestDto(); + request.setSharableAttributes(null); + RequestWrapper requestWrapper = new RequestWrapper<>(); + requestWrapper.setRequest(request); + mockMvc.perform(MockMvcRequestBuilders.post("/share-credential").contentType(MediaType.APPLICATION_JSON_VALUE) + .content(gson.toJson(requestWrapper).getBytes())).andExpect(status().isOk()); + } } diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentCredentialServiceTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentCredentialServiceTest.java index 3d016dd68b0..5c918df93cb 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentCredentialServiceTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentCredentialServiceTest.java @@ -1,6 +1,31 @@ package io.mosip.resident.test.service; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.net.URI; +import java.security.SecureRandom; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + +import org.json.JSONObject; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.cloud.context.config.annotation.RefreshScope; +import org.springframework.core.env.Environment; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.util.ReflectionTestUtils; + import com.fasterxml.jackson.databind.ObjectMapper; + import io.mosip.kernel.core.exception.ServiceError; import io.mosip.kernel.core.util.CryptoUtil; import io.mosip.kernel.core.util.DateUtils; @@ -38,30 +63,7 @@ import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.ResidentServiceRestClient; import io.mosip.resident.util.Utilitiy; -import org.json.JSONObject; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; -import org.springframework.cloud.context.config.annotation.RefreshScope; -import org.springframework.core.env.Environment; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.util.ReflectionTestUtils; - -import java.io.IOException; -import java.net.URI; -import java.security.SecureRandom; -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; +import reactor.util.function.Tuple2; @RunWith(MockitoJUnitRunner.class) @RefreshScope @@ -260,8 +262,8 @@ public void testShareCredential() throws IOException, ApisResourceAccessExceptio when(residentServiceRestClient.getApi(partnerUri, ResponseWrapper.class)).thenReturn(partnerResponseDtoResponseWrapper); when(residentServiceRestClient.postApi(any(), any(), any(), any())).thenReturn(response); - ResidentCredentialResponseDtoV2 credentialResponseDto = residentCredentialService.shareCredential(residentCredentialRequestDto,"SHARE_CRED_WITH_PARTNER"); - assertNotNull(credentialResponseDto.getEventId()); + Tuple2 credentialResponseDto = residentCredentialService.shareCredential(residentCredentialRequestDto,"SHARE_CRED_WITH_PARTNER"); + assertNotNull(credentialResponseDto.getT1().getStatus()); } @Test @@ -289,8 +291,8 @@ public void testShareCredentialPurpose() throws IOException, ApisResourceAccessE when(residentServiceRestClient.getApi(partnerUri, ResponseWrapper.class)).thenReturn(partnerResponseDtoResponseWrapper); when(residentServiceRestClient.postApi(any(), any(), any(), any())).thenReturn(response); - ResidentCredentialResponseDtoV2 credentialResponseDto = residentCredentialService.shareCredential(residentCredentialRequestDto,"SHARE_CRED_WITH_PARTNER","Banking"); - assertNotNull(credentialResponseDto.getEventId()); + Tuple2 credentialResponseDto = residentCredentialService.shareCredential(residentCredentialRequestDto,"SHARE_CRED_WITH_PARTNER","Banking"); + assertNotNull(credentialResponseDto.getT1().getStatus()); } @Test @@ -319,8 +321,8 @@ public void testShareCredentialWithEncryptionKeyNull() throws IOException, ApisR when(residentServiceRestClient.getApi(partnerUri, ResponseWrapper.class)).thenReturn(partnerResponseDtoResponseWrapper); when(residentServiceRestClient.postApi(any(), any(), any(), any())).thenReturn(response); - ResidentCredentialResponseDtoV2 credentialResponseDto = residentCredentialService.shareCredential(residentCredentialRequestDto,"SHARE_CRED_WITH_PARTNER"); - assertNotNull(credentialResponseDto.getEventId()); + Tuple2 credentialResponseDto = residentCredentialService.shareCredential(residentCredentialRequestDto,"SHARE_CRED_WITH_PARTNER"); + assertNotNull(credentialResponseDto.getT1().getStatus()); } @Test(expected = ResidentCredentialServiceException.class) diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceRequestTypeAuthLockTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceRequestTypeAuthLockTest.java index 209828069e6..14dbe0fe52e 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceRequestTypeAuthLockTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceRequestTypeAuthLockTest.java @@ -28,6 +28,8 @@ import io.mosip.resident.util.AuditUtil; import io.mosip.resident.util.UINCardDownloadService; import io.mosip.resident.util.Utilitiy; +import reactor.util.function.Tuple2; + import org.json.simple.JSONObject; import org.junit.Before; import org.junit.Test; @@ -35,14 +37,13 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.util.ReflectionTestUtils; import java.util.ArrayList; import java.util.List; -import java.util.UUID; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -110,15 +111,17 @@ public class ResidentServiceRequestTypeAuthLockTest { public void setup() throws ApisResourceAccessException, ResidentServiceCheckedException { notificationResponseDTO = new NotificationResponseDTO(); - notificationResponseDTO.setStatus("Notification success"); + notificationResponseDTO.setStatus("success"); + notificationResponseDTO.setMessage("Notification success"); Mockito.doNothing().when(audit).setAuditRequestDto(Mockito.any()); individualId = identityServiceImpl.getResidentIndvidualId(); List residentTransactionEntities=new ArrayList<>(); ResidentTransactionEntity residentTransactionEntity = new ResidentTransactionEntity(); - residentTransactionEntity.setEventId(UUID.randomUUID().toString()); + residentTransactionEntity.setEventId("12345"); when(utility.createEntity()).thenReturn(residentTransactionEntity); residentTransactionEntities.add(residentTransactionEntity); + Mockito.when(utility.createEventId()).thenReturn("12345"); ArrayList partnerIds = new ArrayList<>(); partnerIds.add("m-partner-default-auth"); when(partnerService.getPartnerDetails(Mockito.anyString())).thenReturn(partnerIds); @@ -139,13 +142,10 @@ public void testReqAuthTypeStatusUpdateSuccess() authLockOrUnLockRequestDtoV2.setAuthTypes(authTypeStatusDtoList); for (AuthTypeStatusDto authTypeStatusDto1 : authLockOrUnLockRequestDtoV2.getAuthTypes()) { Mockito.when(idAuthService.authTypeStatusUpdateForRequestId(any(), any(), any())).thenReturn("123"); - ResponseDTO response = new ResponseDTO(); - response.setMessage("Notification success"); Mockito.when(notificationService.sendNotification(Mockito.any())).thenReturn(notificationResponseDTO); - ResponseDTO authLockResponse = residentService.reqAauthTypeStatusUpdateV2(authLockOrUnLockRequestDtoV2); - assertEquals(authLockResponse.getMessage(), authLockResponse.getMessage()); + Tuple2 authLockResponse = residentService.reqAauthTypeStatusUpdateV2(authLockOrUnLockRequestDtoV2); + assertEquals(notificationResponseDTO.getMessage(), authLockResponse.getT1().getMessage()); } - } @Test(expected = ResidentServiceException.class)