use of org.springframework.web.testfixture.xml.Pojo in project spring-framework by spring-projects.
the class ServerSentEventHttpMessageWriterTests method writePojo.
@ParameterizedDataBufferAllocatingTest
void writePojo(String displayName, DataBufferFactory bufferFactory) {
super.bufferFactory = bufferFactory;
MockServerHttpResponse outputMessage = new MockServerHttpResponse(super.bufferFactory);
Flux<Pojo> source = Flux.just(new Pojo("foofoo", "barbar"), new Pojo("foofoofoo", "barbarbar"));
testWrite(source, outputMessage, Pojo.class);
StepVerifier.create(outputMessage.getBody()).consumeNextWith(stringConsumer("data:")).consumeNextWith(stringConsumer("{\"foo\":\"foofoo\",\"bar\":\"barbar\"}")).consumeNextWith(stringConsumer("\n\n")).consumeNextWith(stringConsumer("data:")).consumeNextWith(stringConsumer("{\"foo\":\"foofoofoo\",\"bar\":\"barbarbar\"}")).consumeNextWith(stringConsumer("\n\n")).expectComplete().verify();
}
use of org.springframework.web.testfixture.xml.Pojo in project spring-framework by spring-projects.
the class ServerSentEventHttpMessageReaderTests method maxInMemoryLimitAllowsReadingPojoLargerThanDefaultSize.
// gh-24312
@Test
public void maxInMemoryLimitAllowsReadingPojoLargerThanDefaultSize() {
int limit = this.jsonDecoder.getMaxInMemorySize();
String fooValue = getStringOfSize(limit) + "and then some more";
String content = "data:{\"foo\": \"" + fooValue + "\"}\n\n";
MockServerHttpRequest request = MockServerHttpRequest.post("/").body(Mono.just(stringBuffer(content)));
Jackson2JsonDecoder jacksonDecoder = new Jackson2JsonDecoder();
ServerSentEventHttpMessageReader messageReader = new ServerSentEventHttpMessageReader(jacksonDecoder);
jacksonDecoder.setMaxInMemorySize(limit + 1024);
messageReader.setMaxInMemorySize(limit + 1024);
Flux<Pojo> data = messageReader.read(ResolvableType.forClass(Pojo.class), request, Collections.emptyMap()).cast(Pojo.class);
StepVerifier.create(data).consumeNextWith(pojo -> assertThat(pojo.getFoo()).isEqualTo(fooValue)).expectComplete().verify();
}
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 cancelWithJaxb2.
// gh-22107
@Test
public void cancelWithJaxb2() {
Jaxb2XmlEncoder encoder = new Jaxb2XmlEncoder();
Flux<DataBuffer> flux = encoder.encode(Mono.just(new Pojo("foo", "bar")), this.bufferFactory, ResolvableType.forClass(Pojo.class), MediaType.APPLICATION_XML, 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 ServerSentEventHttpMessageWriterTests method writePojoWithCustomEncoding.
// SPR-16516, SPR-16539
@ParameterizedDataBufferAllocatingTest
void writePojoWithCustomEncoding(String displayName, DataBufferFactory bufferFactory) {
super.bufferFactory = bufferFactory;
MockServerHttpResponse outputMessage = new MockServerHttpResponse(super.bufferFactory);
Flux<Pojo> source = Flux.just(new Pojo("foo\uD834\uDD1E", "bar\uD834\uDD1E"));
Charset charset = StandardCharsets.UTF_16LE;
MediaType mediaType = new MediaType("text", "event-stream", charset);
testWrite(source, mediaType, outputMessage, Pojo.class);
assertThat(outputMessage.getHeaders().getContentType()).isEqualTo(mediaType);
StepVerifier.create(outputMessage.getBody()).consumeNextWith(stringConsumer("data:", charset)).consumeNextWith(stringConsumer("{\"foo\":\"foo\uD834\uDD1E\",\"bar\":\"bar\uD834\uDD1E\"}", charset)).consumeNextWith(stringConsumer("\n\n", charset)).expectComplete().verify();
}
Aggregations