use of io.rsocket.Payload in project spring-framework by spring-projects.
the class PayloadUtilsTests method createWithDefaultBuffers.
@Test
public void createWithDefaultBuffers() {
DataBuffer data = createDefaultDataBuffer("sample data");
DataBuffer metadata = createDefaultDataBuffer("sample metadata");
Payload payload = PayloadUtils.createPayload(data, metadata);
assertThat(payload).isInstanceOf(DefaultPayload.class);
assertThat(payload.getDataUtf8()).isEqualTo(data.toString(UTF_8));
assertThat(payload.getMetadataUtf8()).isEqualTo(metadata.toString(UTF_8));
}
use of io.rsocket.Payload in project spring-framework by spring-projects.
the class PayloadUtilsTests method createWithDefaultAndNettyBuffers.
@Test
public void createWithDefaultAndNettyBuffers() {
DefaultDataBuffer data = createDefaultDataBuffer("sample data");
NettyDataBuffer metadata = createNettyDataBuffer("sample metadata");
Payload payload = PayloadUtils.createPayload(data, metadata);
try {
assertThat(payload).isInstanceOf(ByteBufPayload.class);
assertThat(payload.getDataUtf8()).isEqualTo(data.toString(UTF_8));
assertThat(payload.metadata()).isSameAs(metadata.getNativeBuffer());
} finally {
payload.release();
}
}
use of io.rsocket.Payload in project spring-framework by spring-projects.
the class DefaultMetadataExtractorTests method route.
@Test
public void route() {
MimeType metaMimeType = MimeTypeUtils.parseMimeType(WellKnownMimeType.MESSAGE_RSOCKET_ROUTING.getString());
MetadataEncoder metadataEncoder = new MetadataEncoder(metaMimeType, this.strategies).route("toA");
DataBuffer metadata = metadataEncoder.encode().block();
Payload payload = createPayload(metadata);
Map<String, Object> result = this.extractor.extract(payload, metaMimeType);
payload.release();
assertThat(result).hasSize(1).containsEntry(ROUTE_KEY, "toA");
}
use of io.rsocket.Payload in project spring-framework by spring-projects.
the class DefaultMetadataExtractorTests method compositeMetadataWithDefaultSettings.
@Test
public void compositeMetadataWithDefaultSettings() {
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(1).containsEntry(ROUTE_KEY, "toA");
}
use of io.rsocket.Payload in project spring-framework by spring-projects.
the class DefaultMetadataExtractorTests method nonCompositeMetadataCanBeReadTwice.
@Test
public void nonCompositeMetadataCanBeReadTwice() {
DefaultMetadataExtractor extractor = new DefaultMetadataExtractor(new TestDecoder());
extractor.metadataToExtract(TEXT_PLAIN, String.class, "name");
MetadataEncoder encoder = new MetadataEncoder(TEXT_PLAIN, this.strategies).metadata("value", null);
DataBuffer metadata = encoder.encode().block();
Payload payload = createPayload(metadata);
Map<String, Object> result = extractor.extract(payload, TEXT_PLAIN);
assertThat(result).hasSize(1).containsEntry("name", "value");
result = extractor.extract(payload, TEXT_PLAIN);
assertThat(result).hasSize(1).containsEntry("name", "value");
payload.release();
}
Aggregations