### Question:
SamlMessageReceiverApi { @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path(Urls.SamlProxyUrls.EIDAS_RESPONSE_POST_PATH) @Timed @ResponseMetered public Response handleEidasResponsePost(SamlRequestDto samlRequestDto) { if (eidasValidatorFactory.isPresent()) { final SessionId sessionId = new SessionId(samlRequestDto.getRelayState()); MDC.put("SessionId", sessionId); relayStateValidator.validate(samlRequestDto.getRelayState()); org.opensaml.saml.saml2.core.Response samlResponse = stringSamlResponseTransformer.apply(samlRequestDto.getSamlRequest()); eidasValidatorFactory.get().getValidatedResponse(samlResponse); authnResponsesFromCountries.labels(samlResponse.getIssuer().getValue()).inc(); protectiveMonitoringLogger.logAuthnResponse( samlResponse, Direction.INBOUND, SignatureStatus.VALID_SIGNATURE); final SamlAuthnResponseContainerDto authnResponseDto = new SamlAuthnResponseContainerDto( samlRequestDto.getSamlRequest(), sessionId, samlRequestDto.getPrincipalIpAsSeenByFrontend(), samlRequestDto.getAnalyticsSessionId(), samlRequestDto.getJourneyType() ); return Response.ok(sessionProxy.receiveAuthnResponseFromCountry(authnResponseDto, sessionId)).build(); } return Response.status(Response.Status.NOT_FOUND).build(); } @Inject  SamlMessageReceiverApi(RelayStateValidator relayStateValidator,
                                  StringToOpenSamlObjectTransformer<AuthnRequest> stringSamlAuthnRequestTransformer,
                                  StringToOpenSamlObjectTransformer<org.opensaml.saml.saml2.core.Response> stringSamlResponseTransformer,
                                  @Named("authnRequestSignatureValidator") SamlMessageSignatureValidator authnRequestSignatureValidator,
                                  @Named("authnResponseSignatureValidator") SamlMessageSignatureValidator authnResponseSignatureValidator,
                                  Optional<EidasValidatorFactory> eidasValidatorFactory,
                                  ProtectiveMonitoringLogger protectiveMonitoringLogger,
                                  SessionProxy sessionProxy); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Timed @ResponseMetered Response handleRequestPost(SamlRequestDto samlRequestDto); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path(Urls.SamlProxyUrls.RESPONSE_POST_PATH) @Timed @ResponseMetered Response handleResponsePost(SamlRequestDto samlRequestDto); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path(Urls.SamlProxyUrls.EIDAS_RESPONSE_POST_PATH) @Timed @ResponseMetered Response handleEidasResponsePost(SamlRequestDto samlRequestDto);  }### Answer:
@Test public void handleEidasResponsePost_shouldValidateSignatureOfIncomingSamlMessage() { when(stringSamlResponseTransformer.apply(SAML_REQUEST)).thenReturn(validSamlResponse); ValidatedResponse validatedResponse = new ValidatedResponse(validSamlResponse); when(eidasValidatorFactory.getValidatedResponse(validSamlResponse)).thenReturn(validatedResponse); Response response = samlMessageReceiverApi.handleEidasResponsePost(SAML_REQUEST_DTO); assertThat(response.getStatus()).isEqualTo(Status.OK.getStatusCode()); }
@Test public void handleEidasResponsePost_shouldReturnNotFoundIfValidatorAbsent() { samlMessageReceiverApi = new SamlMessageReceiverApi( relayStateValidator, stringSamlAuthnRequestTransformer, stringSamlResponseTransformer, samlMessageSignatureValidator, samlMessageSignatureValidator, Optional.empty(), protectiveMonitoringLogger, sessionProxy); Response response = samlMessageReceiverApi.handleEidasResponsePost(SAML_REQUEST_DTO); assertThat(response.getStatus()).isEqualTo(Status.NOT_FOUND.getStatusCode()); }