Search in sources :

Example 96 with ResolvableType

use of cn.taketoday.core.ResolvableType in project today-framework by TAKETODAY.

the class Jackson2JsonDecoderTests method decodeAscii.

@Test
@SuppressWarnings("unchecked")
public void decodeAscii() {
    Flux<DataBuffer> input = Flux.concat(stringBuffer("{\"foo\":\"bar\"}", StandardCharsets.US_ASCII));
    ResolvableType type = ResolvableType.fromType(new TypeReference<Map<String, String>>() {
    });
    testDecode(input, type, step -> step.assertNext(value -> assertThat((Map<String, String>) value).containsEntry("foo", "bar")).verifyComplete(), MediaType.parseMediaType("application/json; charset=us-ascii"), null);
}
Also used : ResolvableType(cn.taketoday.core.ResolvableType) Map(java.util.Map) DataBuffer(cn.taketoday.core.io.buffer.DataBuffer) Test(org.junit.jupiter.api.Test)

Example 97 with ResolvableType

use of cn.taketoday.core.ResolvableType in project today-framework by TAKETODAY.

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.fromClassWithGenerics(List.class, Pojo.class);
    testDecodeToMonoAll(input, elementType, step -> step.expectNext(Arrays.asList(new Pojo("f1", "b1"), new Pojo("f2", "b2"))).expectComplete().verify(), null, null);
}
Also used : Pojo(cn.taketoday.http.codec.Pojo) ResolvableType(cn.taketoday.core.ResolvableType) DataBuffer(cn.taketoday.core.io.buffer.DataBuffer) Test(org.junit.jupiter.api.Test)

Example 98 with ResolvableType

use of cn.taketoday.core.ResolvableType in project today-framework by TAKETODAY.

the class Jackson2JsonDecoderTests method decodeNonUtf8Encoding.

@Test
@SuppressWarnings("unchecked")
public void decodeNonUtf8Encoding() {
    Mono<DataBuffer> input = stringBuffer("{\"foo\":\"bar\"}", StandardCharsets.UTF_16);
    ResolvableType type = ResolvableType.fromType(new TypeReference<Map<String, String>>() {
    });
    testDecode(input, type, step -> step.assertNext(value -> assertThat((Map<String, String>) value).containsEntry("foo", "bar")).verifyComplete(), MediaType.parseMediaType("application/json; charset=utf-16"), null);
}
Also used : ResolvableType(cn.taketoday.core.ResolvableType) Map(java.util.Map) DataBuffer(cn.taketoday.core.io.buffer.DataBuffer) Test(org.junit.jupiter.api.Test)

Example 99 with ResolvableType

use of cn.taketoday.core.ResolvableType in project today-framework by TAKETODAY.

the class Jackson2CborEncoderTests method canNotEncode.

@Test
public void canNotEncode() {
    assertThat(this.encoder.canEncode(ResolvableType.fromClass(String.class), null)).isFalse();
    assertThat(this.encoder.canEncode(ResolvableType.fromClass(Pojo.class), APPLICATION_XML)).isFalse();
    ResolvableType sseType = ResolvableType.fromClass(ServerSentEvent.class);
    assertThat(this.encoder.canEncode(sseType, CBOR_MIME_TYPE)).isFalse();
}
Also used : Pojo(cn.taketoday.http.codec.Pojo) ResolvableType(cn.taketoday.core.ResolvableType) Test(org.junit.jupiter.api.Test)

Example 100 with ResolvableType

use of cn.taketoday.core.ResolvableType in project today-framework by TAKETODAY.

the class MultipartHttpMessageWriterTests method parse.

static MultiValueMap<String, Part> parse(MockServerHttpResponse response, Map<String, Object> hints) {
    MediaType contentType = response.getHeaders().getContentType();
    assertThat(contentType.getParameter("boundary")).as("No boundary found").isNotNull();
    // see if we can read what we wrote
    DefaultPartHttpMessageReader partReader = new DefaultPartHttpMessageReader();
    MultipartHttpMessageReader reader = new MultipartHttpMessageReader(partReader);
    MockServerHttpRequest request = MockServerHttpRequest.post("/").contentType(MediaType.parseMediaType(contentType.toString())).body(response.getBody());
    ResolvableType elementType = ResolvableType.fromClassWithGenerics(MultiValueMap.class, String.class, Part.class);
    MultiValueMap<String, Part> result = reader.readMono(elementType, request, hints).block(Duration.ofSeconds(5));
    assertThat(result).isNotNull();
    return result;
}
Also used : MockServerHttpRequest(cn.taketoday.http.server.reactive.MockServerHttpRequest) MediaType(cn.taketoday.http.MediaType) ResolvableType(cn.taketoday.core.ResolvableType)

Aggregations

ResolvableType (cn.taketoday.core.ResolvableType)159 Test (org.junit.jupiter.api.Test)106 DataBuffer (cn.taketoday.core.io.buffer.DataBuffer)30 Map (java.util.Map)24 Pojo (cn.taketoday.http.codec.Pojo)20 List (java.util.List)16 MediaType (cn.taketoday.http.MediaType)15 MockConfigurationPropertySource (cn.taketoday.context.properties.source.MockConfigurationPropertySource)14 Flux (reactor.core.publisher.Flux)12 Mono (reactor.core.publisher.Mono)10 Resource (cn.taketoday.core.io.Resource)8 Nullable (cn.taketoday.lang.Nullable)8 ArrayList (java.util.ArrayList)8 IOException (java.io.IOException)7 MultiValueMap (cn.taketoday.core.MultiValueMap)6 ReactiveHttpOutputMessage (cn.taketoday.http.ReactiveHttpOutputMessage)6 ServerSentEvent (cn.taketoday.http.codec.ServerSentEvent)6 MimeType (cn.taketoday.util.MimeType)6 Arrays (java.util.Arrays)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5