Search in sources :

Example 11 with Pojo

use of org.springframework.http.codec.Pojo in project spring-framework by spring-projects.

the class WebClientIntegrationTests method jsonPojoMono.

@Test
public void jsonPojoMono() throws Exception {
    this.server.enqueue(new MockResponse().setHeader("Content-Type", "application/json").setBody("{\"bar\":\"barbar\",\"foo\":\"foofoo\"}"));
    Mono<Pojo> result = this.webClient.get().uri("/pojo").accept(MediaType.APPLICATION_JSON).exchange().then(response -> response.bodyToMono(Pojo.class));
    StepVerifier.create(result).consumeNextWith(p -> assertEquals("barbar", p.getBar())).expectComplete().verify(Duration.ofSeconds(3));
    RecordedRequest recordedRequest = server.takeRequest();
    Assert.assertEquals(1, server.getRequestCount());
    Assert.assertEquals("/pojo", recordedRequest.getPath());
    Assert.assertEquals("application/json", recordedRequest.getHeader(HttpHeaders.ACCEPT));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Pojo(org.springframework.http.codec.Pojo) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)11 Pojo (org.springframework.http.codec.Pojo)11 DataBuffer (org.springframework.core.io.buffer.DataBuffer)7 ResolvableType (org.springframework.core.ResolvableType)5 MockResponse (okhttp3.mockwebserver.MockResponse)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 QName (javax.xml.namespace.QName)2 MediaType (org.springframework.http.MediaType)2 XmlRootElement (org.springframework.http.codec.xml.jaxb.XmlRootElement)2 XmlRootElementWithName (org.springframework.http.codec.xml.jaxb.XmlRootElementWithName)2 XmlRootElementWithNameAndNamespace (org.springframework.http.codec.xml.jaxb.XmlRootElementWithNameAndNamespace)2 XmlType (org.springframework.http.codec.xml.jaxb.XmlType)2 XmlTypeWithName (org.springframework.http.codec.xml.jaxb.XmlTypeWithName)2 XmlTypeWithNameAndNamespace (org.springframework.http.codec.xml.jaxb.XmlTypeWithNameAndNamespace)2 Flux (reactor.core.publisher.Flux)2 StepVerifier (reactor.test.StepVerifier)2 Duration (java.time.Duration)1 Collections (java.util.Collections)1 List (java.util.List)1 XMLEvent (javax.xml.stream.events.XMLEvent)1