@Override protected Map<String, Object> createModel(Operation operation) { try { Object object = this.objectMapper.readValue( operation.getResponse().getContentAsString(), Object.class); Object field = this.fieldProcessor.extract(JsonFieldPath.compile(this.path), object); if (field instanceof List && this.index != null) { field = ((List<?>) field).get(this.index); } return Collections.singletonMap("value", this.objectMapper.writeValueAsString(field)); } catch (Exception ex) { throw new IllegalStateException(ex); } }
private String responseBody(OperationResponse response) { String content = response.getContentAsString(); return content.isEmpty() ? content : String.format("%n%s", content); }
@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); }