Search in sources :

Example 91 with DataBuffer

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");
}
Also used : DataBuffer(org.springframework.core.io.buffer.DataBuffer) NettyDataBuffer(org.springframework.core.io.buffer.NettyDataBuffer) Test(org.junit.jupiter.api.Test)

Example 92 with DataBuffer

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");
}
Also used : DataBuffer(org.springframework.core.io.buffer.DataBuffer) NettyDataBuffer(org.springframework.core.io.buffer.NettyDataBuffer) Test(org.junit.jupiter.api.Test)

Example 93 with DataBuffer

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();
}
Also used : CompositeMetadata(io.rsocket.metadata.CompositeMetadata) DefaultDataBufferFactory(org.springframework.core.io.buffer.DefaultDataBufferFactory) ByteBuf(io.netty.buffer.ByteBuf) NettyDataBufferFactory(org.springframework.core.io.buffer.NettyDataBufferFactory) DataBuffer(org.springframework.core.io.buffer.DataBuffer) NettyDataBuffer(org.springframework.core.io.buffer.NettyDataBuffer) Test(org.junit.jupiter.api.Test)

Example 94 with DataBuffer

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());
}
Also used : MessageHeaderAccessor(org.springframework.messaging.support.MessageHeaderAccessor) SimpleRouteMatcher(org.springframework.util.SimpleRouteMatcher) AntPathMatcher(org.springframework.util.AntPathMatcher) DataBuffer(org.springframework.core.io.buffer.DataBuffer)

Example 95 with DataBuffer

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");
}
Also used : Payload(io.rsocket.Payload) DataBuffer(org.springframework.core.io.buffer.DataBuffer) Test(org.junit.jupiter.api.Test)

Aggregations

DataBuffer (org.springframework.core.io.buffer.DataBuffer)230 Test (org.junit.jupiter.api.Test)111 Mono (reactor.core.publisher.Mono)55 Flux (reactor.core.publisher.Flux)52 DefaultDataBuffer (org.springframework.core.io.buffer.DefaultDataBuffer)49 ResolvableType (org.springframework.core.ResolvableType)41 DefaultDataBufferFactory (org.springframework.core.io.buffer.DefaultDataBufferFactory)36 StepVerifier (reactor.test.StepVerifier)36 List (java.util.List)34 Test (org.junit.Test)31 DataBufferUtils (org.springframework.core.io.buffer.DataBufferUtils)29 IOException (java.io.IOException)28 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)27 MockServerHttpRequest (org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest)27 Map (java.util.Map)25 NettyDataBuffer (org.springframework.core.io.buffer.NettyDataBuffer)25 DataBufferFactory (org.springframework.core.io.buffer.DataBufferFactory)24 HttpHeaders (org.springframework.http.HttpHeaders)24 MediaType (org.springframework.http.MediaType)24 ByteBuffer (java.nio.ByteBuffer)23