Search in sources :

Example 16 with Payload

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

Example 17 with Payload

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();
    }
}
Also used : DefaultDataBuffer(org.springframework.core.io.buffer.DefaultDataBuffer) NettyDataBuffer(org.springframework.core.io.buffer.NettyDataBuffer) Payload(io.rsocket.Payload) DefaultPayload(io.rsocket.util.DefaultPayload) ByteBufPayload(io.rsocket.util.ByteBufPayload) Test(org.junit.jupiter.api.Test)

Example 18 with Payload

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

Example 19 with Payload

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

Example 20 with Payload

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

Aggregations

Payload (io.rsocket.Payload)26 Test (org.junit.jupiter.api.Test)23 DefaultPayload (io.rsocket.util.DefaultPayload)16 ByteBufPayload (io.rsocket.util.ByteBufPayload)14 DataBuffer (org.springframework.core.io.buffer.DataBuffer)12 NettyDataBuffer (org.springframework.core.io.buffer.NettyDataBuffer)9 RSocket (io.rsocket.RSocket)7 RSocketProxy (io.rsocket.util.RSocketProxy)6 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)6 DefaultDataBuffer (org.springframework.core.io.buffer.DefaultDataBuffer)5 MimeType (org.springframework.util.MimeType)5 WellKnownMimeType (io.rsocket.metadata.WellKnownMimeType)4 Publisher (org.reactivestreams.Publisher)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 RSocketConnector (io.rsocket.core.RSocketConnector)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 Flux (reactor.core.publisher.Flux)2 Mono (reactor.core.publisher.Mono)2