### Question:
PaymentAuthorisationAspectService extends BaseAspectService<PaymentController> { public ResponseObject<AuthorisationResponse> createPisAuthorizationAspect(ResponseObject<AuthorisationResponse> result, Xs2aCreatePisAuthorisationRequest request) { if (!result.hasError()) { if (result.getBody() instanceof Xs2aCreatePisAuthorisationResponse) { Xs2aCreatePisAuthorisationResponse response = (Xs2aCreatePisAuthorisationResponse) result.getBody(); response.setLinks(new CreatePisAuthorisationLinks(getHttpUrl(), scaApproachResolver, redirectLinkBuilder, redirectIdService, request, response.getAuthorisationId(), getScaRedirectFlow(), response.getInternalRequestId(), isAuthorisationConfirmationRequestMandated(), requestProviderService.getInstanceId())); } else if (result.getBody() instanceof Xs2aUpdatePisCommonPaymentPsuDataResponse) { Xs2aUpdatePisCommonPaymentPsuDataResponse response = (Xs2aUpdatePisCommonPaymentPsuDataResponse) result.getBody(); response.setLinks(new UpdatePisAuthorisationLinks(getHttpUrl(), scaApproachResolver, response, request)); } } return result; } @Autowired  PaymentAuthorisationAspectService(ScaApproachResolver scaApproachResolver,
                                             AspspProfileServiceWrapper aspspProfileServiceWrapper, RedirectLinkBuilder redirectLinkBuilder,
                                             RedirectIdService redirectIdService, RequestProviderService requestProviderService); ResponseObject<AuthorisationResponse> createPisAuthorizationAspect(ResponseObject<AuthorisationResponse> result,
                                                                              Xs2aCreatePisAuthorisationRequest request); ResponseObject<Xs2aUpdatePisCommonPaymentPsuDataResponse> updatePisAuthorizationAspect(ResponseObject<Xs2aUpdatePisCommonPaymentPsuDataResponse> result,
                                                                                                  Xs2aUpdatePisCommonPaymentPsuDataRequest request);  }### Answer:
@Test void createPisAuthorizationAspect_successOnCreatePisAuthorization() { aspspSettings = new JsonReader().getObjectFromFile("json/aspect/aspsp-settings.json", AspspSettings.class); when(aspspProfileServiceWrapper.isForceXs2aBaseLinksUrl()).thenReturn(aspspSettings.getCommon().isForceXs2aBaseLinksUrl()); when(aspspProfileServiceWrapper.getXs2aBaseLinksUrl()).thenReturn(aspspSettings.getCommon().getXs2aBaseLinksUrl()); responseObject = ResponseObject.<Xs2aCreatePisAuthorisationResponse>builder() .body(createPisAuthorisationResponse) .build(); ResponseObject actualResponse = service.createPisAuthorizationAspect(responseObject, request); verify(createPisAuthorisationResponse, times(1)).setLinks(any(CreatePisAuthorisationLinks.class)); assertFalse(actualResponse.hasError()); }
@Test void updatePisAuthorizationAspect_successOnUpdateAuthorization() { aspspSettings = new JsonReader().getObjectFromFile("json/aspect/aspsp-settings.json", AspspSettings.class); when(aspspProfileServiceWrapper.isForceXs2aBaseLinksUrl()).thenReturn(aspspSettings.getCommon().isForceXs2aBaseLinksUrl()); when(aspspProfileServiceWrapper.getXs2aBaseLinksUrl()).thenReturn(aspspSettings.getCommon().getXs2aBaseLinksUrl()); responseObject = ResponseObject.<Xs2aUpdatePisCommonPaymentPsuDataResponse>builder() .body(updatePisCommonPaymentPsuDataResponse) .build(); ResponseObject actualResponse = service.createPisAuthorizationAspect(responseObject, request); verify(updatePisCommonPaymentPsuDataResponse, times(1)).setLinks(any(UpdatePisAuthorisationLinks.class)); assertFalse(actualResponse.hasError()); }
@Test void createPisAuthorizationAspect_withError_shouldAddTextErrorMessage() { responseObject = ResponseObject.builder() .fail(AIS_400, of(CONSENT_UNKNOWN_400)) .build(); ResponseObject actualResponse = service.createPisAuthorizationAspect(responseObject, request); assertTrue(actualResponse.hasError()); }