use of org.springframework.core.io.buffer.DataBuffer in project spring-framework by spring-projects.
the class MetadataEncoderTests method metadataWithTextPlainMimeType.
@Test
public void metadataWithTextPlainMimeType() {
DataBuffer buffer = new MetadataEncoder(MimeTypeUtils.TEXT_PLAIN, this.strategies).metadata(Unpooled.wrappedBuffer("Raw data".getBytes(UTF_8)), null).encode().block();
assertThat(buffer.toString(UTF_8)).isEqualTo("Raw data");
}
use of org.springframework.core.io.buffer.DataBuffer in project spring-framework by spring-projects.
the class MetadataEncoderTests method routeWithTextPlainMimeType.
@Test
public void routeWithTextPlainMimeType() {
DataBuffer buffer = new MetadataEncoder(MimeTypeUtils.TEXT_PLAIN, this.strategies).route("toA").encode().block();
assertThat(buffer.toString(UTF_8)).isEqualTo("toA");
}
use of org.springframework.core.io.buffer.DataBuffer in project spring-framework by spring-projects.
the class MetadataEncoderTests method defaultDataBufferFactory.
@Test
public void defaultDataBufferFactory() {
DefaultDataBufferFactory bufferFactory = DefaultDataBufferFactory.sharedInstance;
RSocketStrategies strategies = RSocketStrategies.builder().dataBufferFactory(bufferFactory).build();
DataBuffer buffer = new MetadataEncoder(COMPOSITE_METADATA, strategies).route("toA").encode().block();
ByteBuf byteBuf = new NettyDataBufferFactory(ByteBufAllocator.DEFAULT).wrap(buffer.asByteBuffer()).getNativeBuffer();
CompositeMetadata entries = new CompositeMetadata(byteBuf, false);
Iterator<CompositeMetadata.Entry> iterator = entries.iterator();
assertThat(iterator.hasNext()).isTrue();
CompositeMetadata.Entry entry = iterator.next();
assertThat(entry.getMimeType()).isEqualTo(WellKnownMimeType.MESSAGE_RSOCKET_ROUTING.getString());
assertRoute("toA", entry.getContent());
assertThat(iterator.hasNext()).isFalse();
}
use of org.springframework.core.io.buffer.DataBuffer in project spring-framework by spring-projects.
the class MessageMappingMessageHandlerTests method message.
private Message<?> message(String destination, String... content) {
Flux<DataBuffer> payload = Flux.fromIterable(Arrays.asList(content)).map(this::toDataBuffer);
MessageHeaderAccessor headers = new MessageHeaderAccessor();
headers.setLeaveMutable(true);
headers.setHeader(DestinationPatternsMessageCondition.LOOKUP_DESTINATION_HEADER, new SimpleRouteMatcher(new AntPathMatcher()).parseRoute(destination));
return MessageBuilder.createMessage(payload, headers.getMessageHeaders());
}
use of org.springframework.core.io.buffer.DataBuffer in project spring-framework by spring-projects.
the class DefaultMetadataExtractorTests method routeWithCustomFormatting.
@Test
public void routeWithCustomFormatting() {
this.extractor.metadataToExtract(TEXT_PLAIN, String.class, (text, result) -> {
String[] items = text.split(":");
Assert.isTrue(items.length == 2, "Expected two items");
result.put(ROUTE_KEY, items[0]);
result.put("entry1", items[1]);
});
MetadataEncoder encoder = new MetadataEncoder(TEXT_PLAIN, this.strategies).metadata("toA:text data", null);
DataBuffer metadata = encoder.encode().block();
Payload payload = createPayload(metadata);
Map<String, Object> result = this.extractor.extract(payload, TEXT_PLAIN);
payload.release();
assertThat(result).hasSize(2).containsEntry(ROUTE_KEY, "toA").containsEntry("entry1", "text data");
}
Aggregations