use of org.springframework.core.io.buffer.DataBuffer in project spring-framework by spring-projects.
the class DefaultMetadataExtractorTests method routeAsText.
@Test
public void routeAsText() {
this.extractor.metadataToExtract(TEXT_PLAIN, String.class, ROUTE_KEY);
MetadataEncoder metadataEncoder = new MetadataEncoder(TEXT_PLAIN, this.strategies).route("toA");
DataBuffer metadata = metadataEncoder.encode().block();
Payload payload = createPayload(metadata);
Map<String, Object> result = this.extractor.extract(payload, TEXT_PLAIN);
payload.release();
assertThat(result).hasSize(1).containsEntry(ROUTE_KEY, "toA");
}
use of org.springframework.core.io.buffer.DataBuffer in project spring-framework by spring-projects.
the class DefaultMetadataExtractorTests method compositeMetadataWithMimeTypeRegistrations.
@Test
public void compositeMetadataWithMimeTypeRegistrations() {
this.extractor.metadataToExtract(TEXT_PLAIN, String.class, "text-entry");
this.extractor.metadataToExtract(TEXT_HTML, String.class, "html-entry");
this.extractor.metadataToExtract(TEXT_XML, String.class, "xml-entry");
MetadataEncoder metadataEncoder = new MetadataEncoder(COMPOSITE_METADATA, this.strategies).route("toA").metadata("text data", TEXT_PLAIN).metadata("html data", TEXT_HTML).metadata("xml data", TEXT_XML);
DataBuffer metadata = metadataEncoder.encode().block();
Payload payload = createPayload(metadata);
Map<String, Object> result = this.extractor.extract(payload, COMPOSITE_METADATA);
payload.release();
assertThat(result).hasSize(4).containsEntry(ROUTE_KEY, "toA").containsEntry("text-entry", "text data").containsEntry("html-entry", "html data").containsEntry("xml-entry", "xml data");
}
use of org.springframework.core.io.buffer.DataBuffer in project spring-framework by spring-projects.
the class PayloadUtilsTests method createWithDefaultBuffer.
@Test
public void createWithDefaultBuffer() {
DataBuffer data = createDefaultDataBuffer("sample data");
Payload payload = PayloadUtils.createPayload(data);
assertThat(payload).isInstanceOf(DefaultPayload.class);
assertThat(payload.getDataUtf8()).isEqualTo(data.toString(UTF_8));
}
use of org.springframework.core.io.buffer.DataBuffer in project spring-framework by spring-projects.
the class HttpHandlerConnectorTests method adaptRequest.
@Test
public void adaptRequest() {
TestHttpHandler handler = new TestHttpHandler(response -> {
response.setStatusCode(HttpStatus.OK);
return response.setComplete();
});
new HttpHandlerConnector(handler).connect(HttpMethod.POST, URI.create("/custom-path"), request -> {
request.getHeaders().put("custom-header", Arrays.asList("h0", "h1"));
request.getCookies().add("custom-cookie", new HttpCookie("custom-cookie", "c0"));
return request.writeWith(Mono.just(toDataBuffer("Custom body")));
}).block(Duration.ofSeconds(5));
MockServerHttpRequest request = (MockServerHttpRequest) handler.getSavedRequest();
assertThat(request.getMethod()).isEqualTo(HttpMethod.POST);
assertThat(request.getURI().toString()).isEqualTo("/custom-path");
HttpHeaders headers = request.getHeaders();
assertThat(headers.get("custom-header")).isEqualTo(Arrays.asList("h0", "h1"));
assertThat(request.getCookies().getFirst("custom-cookie")).isEqualTo(new HttpCookie("custom-cookie", "c0"));
assertThat(headers.get(HttpHeaders.COOKIE)).isEqualTo(Collections.singletonList("custom-cookie=c0"));
DataBuffer buffer = request.getBody().blockFirst(Duration.ZERO);
assertThat(buffer.toString(UTF_8)).isEqualTo("Custom body");
}
use of org.springframework.core.io.buffer.DataBuffer in project spring-framework by spring-projects.
the class DataBufferTestUtilsTests method dumpBytes.
@ParameterizedDataBufferAllocatingTest
void dumpBytes(String displayName, DataBufferFactory bufferFactory) {
this.bufferFactory = bufferFactory;
DataBuffer buffer = this.bufferFactory.allocateBuffer(4);
byte[] source = { 'a', 'b', 'c', 'd' };
buffer.write(source);
byte[] result = DataBufferTestUtils.dumpBytes(buffer);
assertThat(result).isEqualTo(source);
release(buffer);
}
Aggregations