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);
}
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);
}
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);
}
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();
}
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;
}
Aggregations