@Override protected Map<String, Object> createModel(Operation operation) { OperationResponse response = operation.getResponse(); HttpStatus status = response.getStatus(); Map<String, Object> model = new HashMap<>(); model.put("responseBody", responseBody(response)); model.put("statusCode", status.value()); model.put("statusReason", status.getReasonPhrase()); model.put("headers", headers(response)); return model; }
/** * Creates a new {@code OperationResponse} based on the given {@code original} but * with the given {@code newHeaders}. * @param original the original response * @param newHeaders the new headers * @return the new response with the new headers */ public OperationResponse createFrom(OperationResponse original, HttpHeaders newHeaders) { return new StandardOperationResponse(original.getStatus(), newHeaders, original.getContent()); }
/** * Creates a new {@code OperationResponse} based on the given {@code original} but * with the given {@code newContent}. If the original response had a * {@code Content-Length} header it will be modified to match the length of the new * content. * @param original the original response * @param newContent the new content * @return the new response with the new content */ public OperationResponse createFrom(OperationResponse original, byte[] newContent) { return new StandardOperationResponse(original.getStatus(), getUpdatedHeaders(original.getHeaders(), newContent), newContent); }
@Override public OperationResponse preprocess(OperationResponse response) { return this.contentModifyingDelegate .preprocess(new OperationResponseFactory().create(response.getStatus(), modify(response.getHeaders()), response.getContent())); }
@Test public void basicResponse() { MockHttpServletResponse response = new MockHttpServletResponse(); response.setStatus(HttpServletResponse.SC_OK); OperationResponse operationResponse = this.factory.convert(response); assertThat(operationResponse.getStatus()).isEqualTo(HttpStatus.OK); }
@Test public void basicResponse() { ExchangeResult result = WebTestClient .bindToRouterFunction(RouterFunctions.route(GET("/foo"), (req) -> ServerResponse.ok().syncBody("Hello, World!"))) .configureClient().baseUrl("http://localhost").build().get().uri("/foo") .exchange().expectBody().returnResult(); OperationResponse response = this.converter.convert(result); assertThat(response.getStatus()).isEqualTo(HttpStatus.OK); assertThat(response.getContentAsString()).isEqualTo("Hello, World!"); assertThat(response.getHeaders().getContentType()) .isEqualTo(MediaType.parseMediaType("text/plain;charset=UTF-8")); assertThat(response.getHeaders().getContentLength()).isEqualTo(13); }