Search in sources :

Example 16 with Pojo

use of org.springframework.web.testfixture.xml.Pojo in project spring-framework by spring-projects.

the class Jackson2JsonEncoderTests method encodeAsStreamWithCustomStreamingType.

// SPR-15727
@Test
public void encodeAsStreamWithCustomStreamingType() {
    MediaType fooMediaType = new MediaType("application", "foo");
    MediaType barMediaType = new MediaType("application", "bar");
    this.encoder.setStreamingMediaTypes(Arrays.asList(fooMediaType, barMediaType));
    Flux<Pojo> input = Flux.just(new Pojo("foo", "bar"), new Pojo("foofoo", "barbar"), new Pojo("foofoofoo", "barbarbar"));
    testEncode(input, ResolvableType.forClass(Pojo.class), step -> step.consumeNextWith(expectString("{\"foo\":\"foo\",\"bar\":\"bar\"}\n").andThen(DataBufferUtils::release)).consumeNextWith(expectString("{\"foo\":\"foofoo\",\"bar\":\"barbar\"}\n").andThen(DataBufferUtils::release)).consumeNextWith(expectString("{\"foo\":\"foofoofoo\",\"bar\":\"barbarbar\"}\n").andThen(DataBufferUtils::release)).verifyComplete(), barMediaType, null);
}
Also used : Pojo(org.springframework.web.testfixture.xml.Pojo) DataBufferUtils(org.springframework.core.io.buffer.DataBufferUtils) MediaType(org.springframework.http.MediaType) Test(org.junit.jupiter.api.Test)

Example 17 with Pojo

use of org.springframework.web.testfixture.xml.Pojo in project spring-framework by spring-projects.

the class Jackson2JsonEncoderTests method encode.

@Override
@Test
@SuppressWarnings("deprecation")
public void encode() throws Exception {
    Flux<Object> input = Flux.just(new Pojo("foo", "bar"), new Pojo("foofoo", "barbar"), new Pojo("foofoofoo", "barbarbar"));
    testEncodeAll(input, ResolvableType.forClass(Pojo.class), step -> step.consumeNextWith(expectString("{\"foo\":\"foo\",\"bar\":\"bar\"}\n")).consumeNextWith(expectString("{\"foo\":\"foofoo\",\"bar\":\"barbar\"}\n")).consumeNextWith(expectString("{\"foo\":\"foofoofoo\",\"bar\":\"barbarbar\"}\n")).verifyComplete(), APPLICATION_STREAM_JSON, null);
}
Also used : Pojo(org.springframework.web.testfixture.xml.Pojo) Test(org.junit.jupiter.api.Test)

Example 18 with Pojo

use of org.springframework.web.testfixture.xml.Pojo in project spring-framework by spring-projects.

the class Jackson2JsonEncoderTests method encodeAscii.

@Test
public void encodeAscii() {
    Mono<Object> input = Mono.just(new Pojo("foo", "bar"));
    testEncode(input, ResolvableType.forClass(Pojo.class), step -> step.consumeNextWith(expectString("{\"foo\":\"foo\",\"bar\":\"bar\"}")).verifyComplete(), new MimeType("application", "json", StandardCharsets.US_ASCII), null);
}
Also used : Pojo(org.springframework.web.testfixture.xml.Pojo) MimeType(org.springframework.util.MimeType) Test(org.junit.jupiter.api.Test)

Example 19 with Pojo

use of org.springframework.web.testfixture.xml.Pojo in project spring-framework by spring-projects.

the class Jackson2JsonEncoderTests method encodeWithFlushAfterWriteOff.

// gh-22771
@Test
public void encodeWithFlushAfterWriteOff() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(SerializationFeature.FLUSH_AFTER_WRITE_VALUE, false);
    Jackson2JsonEncoder encoder = new Jackson2JsonEncoder(mapper);
    Flux<DataBuffer> result = encoder.encode(Flux.just(new Pojo("foo", "bar")), this.bufferFactory, ResolvableType.forClass(Pojo.class), MimeTypeUtils.APPLICATION_JSON, Collections.emptyMap());
    StepVerifier.create(result).consumeNextWith(expectString("[{\"foo\":\"foo\",\"bar\":\"bar\"}]")).expectComplete().verify(Duration.ofSeconds(5));
}
Also used : Pojo(org.springframework.web.testfixture.xml.Pojo) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DataBuffer(org.springframework.core.io.buffer.DataBuffer) Test(org.junit.jupiter.api.Test)

Example 20 with Pojo

use of org.springframework.web.testfixture.xml.Pojo in project spring-framework by spring-projects.

the class Jaxb2XmlEncoderTests method encode.

@Override
@Test
public void encode() {
    Mono<Pojo> input = Mono.just(new Pojo("foofoo", "barbar"));
    testEncode(input, Pojo.class, step -> step.consumeNextWith(expectXml("<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" + "<pojo><bar>barbar</bar><foo>foofoo</foo></pojo>")).verifyComplete());
}
Also used : Pojo(org.springframework.web.testfixture.xml.Pojo) Test(org.junit.jupiter.api.Test)

Aggregations

Pojo (org.springframework.web.testfixture.xml.Pojo)20 Test (org.junit.jupiter.api.Test)17 DataBuffer (org.springframework.core.io.buffer.DataBuffer)10 ResolvableType (org.springframework.core.ResolvableType)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 DataBufferUtils (org.springframework.core.io.buffer.DataBufferUtils)3 MediaType (org.springframework.http.MediaType)3 MimeType (org.springframework.util.MimeType)3 MockServerHttpResponse (org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse)3 Flux (reactor.core.publisher.Flux)3 Mono (reactor.core.publisher.Mono)3 StepVerifier (reactor.test.StepVerifier)3 MappingIterator (com.fasterxml.jackson.databind.MappingIterator)2 IOException (java.io.IOException)2 UncheckedIOException (java.io.UncheckedIOException)2 Arrays (java.util.Arrays)2 List (java.util.List)2 DataBufferUtils.release (org.springframework.core.io.buffer.DataBufferUtils.release)2 AbstractEncoderTests (org.springframework.core.testfixture.codec.AbstractEncoderTests)2