use of org.springframework.web.testfixture.xml.Pojo in project spring-framework by spring-projects.
the class Jackson2JsonEncoderTests method encodeNonStream.
@Test
public void encodeNonStream() {
Flux<Pojo> input = Flux.just(new Pojo("foo", "bar"), new Pojo("foofoo", "barbar"), new Pojo("foofoofoo", "barbarbar"));
testEncode(input, Pojo.class, step -> step.consumeNextWith(expectString("[" + "{\"foo\":\"foo\",\"bar\":\"bar\"}," + "{\"foo\":\"foofoo\",\"bar\":\"barbar\"}," + "{\"foo\":\"foofoofoo\",\"bar\":\"barbarbar\"}]").andThen(DataBufferUtils::release)).verifyComplete());
}
use of org.springframework.web.testfixture.xml.Pojo in project spring-framework by spring-projects.
the class Jackson2JsonDecoderTests method decodeToMono.
@Override
@Test
public void decodeToMono() {
Flux<DataBuffer> input = Flux.concat(stringBuffer("[{\"bar\":\"b1\",\"foo\":\"f1\"},"), stringBuffer("{\"bar\":\"b2\",\"foo\":\"f2\"}]"));
ResolvableType elementType = ResolvableType.forClassWithGenerics(List.class, Pojo.class);
testDecodeToMonoAll(input, elementType, step -> step.expectNext(Arrays.asList(new Pojo("f1", "b1"), new Pojo("f2", "b2"))).expectComplete().verify(), null, null);
}
use of org.springframework.web.testfixture.xml.Pojo in project spring-framework by spring-projects.
the class CancelWithoutDemandCodecTests method cancelWithJackson.
// gh-22107
@Test
public void cancelWithJackson() {
Jackson2JsonEncoder encoder = new Jackson2JsonEncoder();
Flux<DataBuffer> flux = encoder.encode(Flux.just(new Pojo("foofoo", "barbar"), new Pojo("bar", "baz")), this.bufferFactory, ResolvableType.forClass(Pojo.class), MediaType.APPLICATION_JSON, Collections.emptyMap());
BaseSubscriber<DataBuffer> subscriber = new ZeroDemandSubscriber();
// Assume sync execution (e.g. encoding with Flux.just)..
flux.subscribe(subscriber);
subscriber.cancel();
}
use of org.springframework.web.testfixture.xml.Pojo in project spring-framework by spring-projects.
the class Jackson2SmileEncoderTests method encodeAsStream.
@Test
public void encodeAsStream() throws Exception {
Pojo pojo1 = new Pojo("foo", "bar");
Pojo pojo2 = new Pojo("foofoo", "barbar");
Pojo pojo3 = new Pojo("foofoofoo", "barbarbar");
Flux<Pojo> input = Flux.just(pojo1, pojo2, pojo3);
ResolvableType type = ResolvableType.forClass(Pojo.class);
Flux<DataBuffer> result = this.encoder.encode(input, bufferFactory, type, STREAM_SMILE_MIME_TYPE, null);
Mono<MappingIterator<Pojo>> joined = DataBufferUtils.join(result).map(buffer -> {
try {
return this.mapper.reader().forType(Pojo.class).readValues(buffer.asInputStream(true));
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
});
StepVerifier.create(joined).assertNext(iter -> assertThat(iter).toIterable().contains(pojo1, pojo2, pojo3)).verifyComplete();
}
use of org.springframework.web.testfixture.xml.Pojo in project spring-framework by spring-projects.
the class ServerSentEventHttpMessageReaderTests method readPojo.
@Test
public void readPojo() {
MockServerHttpRequest request = MockServerHttpRequest.post("/").body(Mono.just(stringBuffer("data:{\"foo\": \"foofoo\", \"bar\": \"barbar\"}\n\n" + "data:{\"foo\": \"foofoofoo\", \"bar\": \"barbarbar\"}\n\n")));
Flux<Pojo> data = reader.read(ResolvableType.forClass(Pojo.class), request, Collections.emptyMap()).cast(Pojo.class);
StepVerifier.create(data).consumeNextWith(pojo -> {
assertThat(pojo.getFoo()).isEqualTo("foofoo");
assertThat(pojo.getBar()).isEqualTo("barbar");
}).consumeNextWith(pojo -> {
assertThat(pojo.getFoo()).isEqualTo("foofoofoo");
assertThat(pojo.getBar()).isEqualTo("barbarbar");
}).expectComplete().verify();
}
Aggregations