Search in sources :

Example 11 with Pojo

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

the class Jackson2CborDecoderTests method decodeToMono.

@Override
@Test
public void decodeToMono() {
    List<Pojo> expected = Arrays.asList(pojo1, pojo2);
    Flux<DataBuffer> input = Flux.just(expected).map(this::writeObject).flatMap(this::dataBuffer);
    ResolvableType elementType = ResolvableType.forClassWithGenerics(List.class, Pojo.class);
    testDecodeToMono(input, elementType, step -> step.expectNext(expected).expectComplete().verify(), null, null);
}
Also used : Pojo(org.springframework.web.testfixture.xml.Pojo) ResolvableType(org.springframework.core.ResolvableType) DataBuffer(org.springframework.core.io.buffer.DataBuffer) Test(org.junit.jupiter.api.Test)

Example 12 with Pojo

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

the class Jackson2SmileDecoderTests method decodeToMono.

@Override
@Test
public void decodeToMono() {
    List<Pojo> expected = Arrays.asList(pojo1, pojo2);
    Flux<DataBuffer> input = Flux.just(expected).map(this::writeObject).flatMap(this::dataBuffer);
    ResolvableType elementType = ResolvableType.forClassWithGenerics(List.class, Pojo.class);
    testDecodeToMono(input, elementType, step -> step.expectNext(expected).expectComplete().verify(), null, null);
}
Also used : Pojo(org.springframework.web.testfixture.xml.Pojo) ResolvableType(org.springframework.core.ResolvableType) DataBuffer(org.springframework.core.io.buffer.DataBuffer) Test(org.junit.jupiter.api.Test)

Example 13 with Pojo

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

the class ServerSentEventHttpMessageWriterTests method writePojoWithPrettyPrint.

// SPR-14899
@ParameterizedDataBufferAllocatingTest
void writePojoWithPrettyPrint(String displayName, DataBufferFactory bufferFactory) {
    super.bufferFactory = bufferFactory;
    ObjectMapper mapper = Jackson2ObjectMapperBuilder.json().indentOutput(true).build();
    this.messageWriter = new ServerSentEventHttpMessageWriter(new Jackson2JsonEncoder(mapper));
    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("{\n" + "data:  \"foo\" : \"foofoo\",\n" + "data:  \"bar\" : \"barbar\"\n" + "data:}")).consumeNextWith(stringConsumer("\n\n")).consumeNextWith(stringConsumer("data:")).consumeNextWith(stringConsumer("{\n" + "data:  \"foo\" : \"foofoofoo\",\n" + "data:  \"bar\" : \"barbarbar\"\n" + "data:}")).consumeNextWith(stringConsumer("\n\n")).expectComplete().verify();
}
Also used : Pojo(org.springframework.web.testfixture.xml.Pojo) MockServerHttpResponse(org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Jackson2JsonEncoder(org.springframework.http.codec.json.Jackson2JsonEncoder)

Example 14 with Pojo

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

the class Jackson2CborEncoderTests method encode.

@Test
public void encode() {
    Pojo value = new Pojo("foo", "bar");
    DataBuffer result = encoder.encodeValue(value, this.bufferFactory, ResolvableType.forClass(Pojo.class), CBOR_MIME_TYPE, null);
    pojoConsumer(value).accept(result);
}
Also used : Pojo(org.springframework.web.testfixture.xml.Pojo) DataBuffer(org.springframework.core.io.buffer.DataBuffer) Test(org.junit.jupiter.api.Test)

Example 15 with Pojo

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

the class Jackson2CborEncoderTests method encodeStream.

@Test
public void encodeStream() {
    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);
    assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> encoder.encode(input, this.bufferFactory, type, CBOR_MIME_TYPE, null));
}
Also used : Pojo(org.springframework.web.testfixture.xml.Pojo) ResolvableType(org.springframework.core.ResolvableType) 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