#spring-webclient
Вопрос:
Я пытаюсь издеваться над этой конечной точкой с помощью mockito, но получаю внутреннюю ошибку сервера. Ранее мы использовали метод exchange, который вызывал проблему с утечкой памяти, а затем изменил его для извлечения, но тестовые примеры не работают .Я перепробовал все и не смог решить.Я не уверен, где я напортачил. Мне бы не помешала ваша помощь, ребята.
public static Mono<? extends ExternalApiResponse> invokeWebClientEndpoint(
WebClient webClient,
ExternalApiRequest externalApiRequest, AuditMessageProducer auditMessageProducer) {
auditMessageProducer.publishOfferDescriptionAuditMessage(AuditSource.EMJU_XAPI_OFFERS, externalApiRequest,
AuditStatus.SUCCESS, null, null);
Class<? extends ExternalApiResponse> responseClass;
if(!(externalApiRequest.getAppName().isEmpty())) {
if (externalApiRequest.getName().equals("OfferDefinitionApiRequest")) {
responseClass = OfferDefinitionResponse.class;
} else {
responseClass = GalleryResponse.class;
}
}else {
log.warn("invokeWebClientEndpoint :: Not a valid externalApiRequest Name: ", externalApiRequest.getAppName());
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR,String.format("Invalid externalApiRequest name",externalApiRequest.getAppName()));
}
return webClient.get().uri(externalApiRequest.getUrlString()).accept(MediaType.APPLICATION_JSON)
.headers(httpHeader -> httpHeader.addAll(externalApiRequest.getHeaders()))
.retrieve()
.onStatus(HttpStatus::is4xxClientError, clientResponse -> {
ResponseStatusException responseStatusException = new ResponseStatusException(
HttpStatus.INTERNAL_SERVER_ERROR,
String.format("Attempting to pull content from the Application " externalApiRequest.getAppName()
" but resulted in error. Status: ", clientResponse.statusCode()));
return Mono.error(responseStatusException);
})
.onStatus(HttpStatus::is5xxServerError, clientResponse -> {
ResponseStatusException responseStatusException = new ResponseStatusException(
HttpStatus.INTERNAL_SERVER_ERROR,
String.format("Attempting to pull content from the Application " externalApiRequest.getAppName()
" but resulted in error. Status: ", clientResponse.statusCode()));
return Mono.error(responseStatusException);
})
.bodyToMono(responseClass)
.timeout(Duration.ofMillis(externalApiRequest.getTimeOut()));
}
}
Это метод тестирования
public void testXapiOfferDescWebSignInUserTest() {
XApiContextBuilder xApiContextBuilder = XApiContext.builder();
Map<String, String> headers = new HashMap<String, String>();
headers.put("x-swyconsumerdirectorypro", "eyJraWQiOiJHT1RLUXY2NG40N3ZRVjVuaGNGSVVveVNtaWhtQTM5V0N4TFNxVXY4WFVrIiwiYWxnIjoiUlMyNTYifQ");
xApiContextBuilder.headers(headers);
XApiContext xApiContext = xApiContextBuilder.build();
OfferDefinitionResponse offerDefinitionResponse = new OfferDefinitionResponse();
offerDefinitionResponse.setOfferId(179982937L);
GalleryResponse galleryResponse = new GalleryResponse();
List<Offer> offerList = new ArrayList<Offer>();
offerList.add(getOffer());
galleryResponse.setPD(offerList);
ResponseSpec clientResponse = Mockito.mock(ResponseSpec.class);
ResponseSpec mockResponse = mock(ResponseSpec.class);
RequestHeadersUriSpec requestHeaderUriSpec = Mockito.mock(RequestHeadersUriSpec.class);
RequestHeadersSpec requestHeaderSpec = Mockito.mock(RequestHeadersSpec.class);
Mockito.when(offerWebClient.get()).thenReturn(requestHeaderUriSpec);
Mockito.when(requestHeaderUriSpec.uri(Mockito.anyString())).thenReturn(requestHeaderSpec);
Mockito.when(requestHeaderSpec.accept(Mockito.any())).thenReturn(requestHeaderSpec);
Mockito.when(requestHeaderSpec.headers(Mockito.any())).thenReturn(requestHeaderSpec);
Mockito.when(requestHeaderSpec.retrieve()).thenReturn(mockResponse);
StepVerifier.create(offerDescriptionOrchestratorImpl.orchestrateOfferDescription(xApiContext, "3132", "PD",
"179982937", "true","Y")).verifyError();
}
I am getting an Internal Server Error at onStatus Handlers