use of org.springframework.http.codec.Pojo in project spring-framework by spring-projects.
the class Jaxb2XmlDecoderTests method decodeSingleXmlRootElement.
@Test
public void decodeSingleXmlRootElement() throws Exception {
Flux<DataBuffer> source = Flux.just(stringBuffer(POJO_ROOT));
Flux<Object> output = this.decoder.decode(source, ResolvableType.forClass(Pojo.class), null, Collections.emptyMap());
StepVerifier.create(output).expectNext(new Pojo("foofoo", "barbar")).expectComplete().verify();
}
use of org.springframework.http.codec.Pojo in project spring-framework by spring-projects.
the class Jaxb2XmlDecoderTests method splitMultipleBranches.
@Test
public void splitMultipleBranches() throws Exception {
Flux<XMLEvent> xmlEvents = this.xmlEventDecoder.decode(Flux.just(stringBuffer(POJO_CHILD)), null, null, Collections.emptyMap());
Flux<List<XMLEvent>> result = this.decoder.split(xmlEvents, new QName("pojo"));
StepVerifier.create(result).consumeNextWith(events -> {
assertEquals(8, events.size());
assertStartElement(events.get(0), "pojo");
assertStartElement(events.get(1), "foo");
assertCharacters(events.get(2), "foo");
assertEndElement(events.get(3), "foo");
assertStartElement(events.get(4), "bar");
assertCharacters(events.get(5), "bar");
assertEndElement(events.get(6), "bar");
assertEndElement(events.get(7), "pojo");
}).consumeNextWith(events -> {
assertEquals(8, events.size());
assertStartElement(events.get(0), "pojo");
assertStartElement(events.get(1), "foo");
assertCharacters(events.get(2), "foofoo");
assertEndElement(events.get(3), "foo");
assertStartElement(events.get(4), "bar");
assertCharacters(events.get(5), "barbar");
assertEndElement(events.get(6), "bar");
assertEndElement(events.get(7), "pojo");
}).expectComplete().verify();
}
use of org.springframework.http.codec.Pojo in project spring-framework by spring-projects.
the class Jaxb2XmlDecoderTests method toExpectedQName.
@Test
public void toExpectedQName() {
assertEquals(new QName("pojo"), this.decoder.toQName(Pojo.class));
assertEquals(new QName("pojo"), this.decoder.toQName(TypePojo.class));
assertEquals(new QName("namespace", "name"), this.decoder.toQName(XmlRootElementWithNameAndNamespace.class));
assertEquals(new QName("namespace", "name"), this.decoder.toQName(XmlRootElementWithName.class));
assertEquals(new QName("namespace", "xmlRootElement"), this.decoder.toQName(XmlRootElement.class));
assertEquals(new QName("namespace", "name"), this.decoder.toQName(XmlTypeWithNameAndNamespace.class));
assertEquals(new QName("namespace", "name"), this.decoder.toQName(XmlTypeWithName.class));
assertEquals(new QName("namespace", "xmlType"), this.decoder.toQName(XmlType.class));
}
use of org.springframework.http.codec.Pojo in project spring-framework by spring-projects.
the class Jaxb2XmlDecoderTests method decodeMultipleXmlRootElement.
@Test
public void decodeMultipleXmlRootElement() throws Exception {
Flux<DataBuffer> source = Flux.just(stringBuffer(POJO_CHILD));
Flux<Object> output = this.decoder.decode(source, ResolvableType.forClass(Pojo.class), null, Collections.emptyMap());
StepVerifier.create(output).expectNext(new Pojo("foo", "bar")).expectNext(new Pojo("foofoo", "barbar")).expectComplete().verify();
}
use of org.springframework.http.codec.Pojo in project spring-framework by spring-projects.
the class WebClientIntegrationTests method jsonPojoFlux.
@Test
public void jsonPojoFlux() throws Exception {
this.server.enqueue(new MockResponse().setHeader("Content-Type", "application/json").setBody("[{\"bar\":\"bar1\",\"foo\":\"foo1\"},{\"bar\":\"bar2\",\"foo\":\"foo2\"}]"));
Flux<Pojo> result = this.webClient.get().uri("/pojos").accept(MediaType.APPLICATION_JSON).exchange().flatMap(response -> response.bodyToFlux(Pojo.class));
StepVerifier.create(result).consumeNextWith(p -> assertThat(p.getBar(), Matchers.is("bar1"))).consumeNextWith(p -> assertThat(p.getBar(), Matchers.is("bar2"))).expectComplete().verify(Duration.ofSeconds(3));
RecordedRequest recordedRequest = server.takeRequest();
Assert.assertEquals(1, server.getRequestCount());
Assert.assertEquals("/pojos", recordedRequest.getPath());
Assert.assertEquals("application/json", recordedRequest.getHeader(HttpHeaders.ACCEPT));
}
Aggregations