Search in sources :

Example 1 with ConnectionSetupPayload

use of io.rsocket.ConnectionSetupPayload in project spring-framework by spring-projects.

the class DefaultRSocketRequesterBuilderTests method mimeTypesCannotBeChangedAtRSocketConnectorLevel.

@Test
public void mimeTypesCannotBeChangedAtRSocketConnectorLevel() {
    MimeType dataMimeType = MimeTypeUtils.APPLICATION_JSON;
    MimeType metaMimeType = MimeTypeUtils.parseMimeType(WellKnownMimeType.MESSAGE_RSOCKET_ROUTING.getString());
    RSocketRequester requester = RSocketRequester.builder().metadataMimeType(metaMimeType).dataMimeType(dataMimeType).rsocketConnector(connector -> {
        connector.metadataMimeType("text/plain");
        connector.dataMimeType("application/xml");
    }).transport(this.transport);
    ConnectionSetupPayload setupPayload = getConnectionSetupPayload(requester);
    assertThat(setupPayload.dataMimeType()).isEqualTo(dataMimeType.toString());
    assertThat(setupPayload.metadataMimeType()).isEqualTo(metaMimeType.toString());
    assertThat(requester.dataMimeType()).isEqualTo(dataMimeType);
    assertThat(requester.metadataMimeType()).isEqualTo(metaMimeType);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ClientTransport(io.rsocket.transport.ClientTransport) BeforeEach(org.junit.jupiter.api.BeforeEach) NettyDataBufferFactory(org.springframework.core.io.buffer.NettyDataBufferFactory) SocketAddress(java.net.SocketAddress) Decoder(org.springframework.core.codec.Decoder) DefaultDataBufferFactory(org.springframework.core.io.buffer.DefaultDataBufferFactory) ByteBufAllocator(io.netty.buffer.ByteBufAllocator) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DefaultConnectionSetupPayload(io.rsocket.core.DefaultConnectionSetupPayload) DecodingException(org.springframework.core.codec.DecodingException) RSocketErrorException(io.rsocket.RSocketErrorException) PayloadDecoder(io.rsocket.frame.decoder.PayloadDecoder) MimeType(org.springframework.util.MimeType) WellKnownMimeType(io.rsocket.metadata.WellKnownMimeType) ByteBuf(io.netty.buffer.ByteBuf) BDDMockito.given(org.mockito.BDDMockito.given) Duration(java.time.Duration) Map(java.util.Map) ResolvableType(org.springframework.core.ResolvableType) RSocketConnector(io.rsocket.core.RSocketConnector) StringDecoder(org.springframework.core.codec.StringDecoder) Publisher(org.reactivestreams.Publisher) Mono(reactor.core.publisher.Mono) MimeTypeUtils(org.springframework.util.MimeTypeUtils) Field(java.lang.reflect.Field) DataBuffer(org.springframework.core.io.buffer.DataBuffer) InetSocketAddress(java.net.InetSocketAddress) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) List(java.util.List) DataBufferFactory(org.springframework.core.io.buffer.DataBufferFactory) ReflectionUtils(org.springframework.util.ReflectionUtils) DuplexConnection(io.rsocket.DuplexConnection) ConnectionSetupPayload(io.rsocket.ConnectionSetupPayload) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) DefaultConnectionSetupPayload(io.rsocket.core.DefaultConnectionSetupPayload) ConnectionSetupPayload(io.rsocket.ConnectionSetupPayload) MimeType(org.springframework.util.MimeType) WellKnownMimeType(io.rsocket.metadata.WellKnownMimeType) Test(org.junit.jupiter.api.Test)

Example 2 with ConnectionSetupPayload

use of io.rsocket.ConnectionSetupPayload in project spring-framework by spring-projects.

the class DefaultRSocketRequesterBuilderTests method dataMimeTypeExplicitlySet.

@Test
public void dataMimeTypeExplicitlySet() {
    RSocketRequester requester = RSocketRequester.builder().dataMimeType(MimeTypeUtils.APPLICATION_JSON).transport(this.transport);
    ConnectionSetupPayload setupPayload = getConnectionSetupPayload(requester);
    assertThat(setupPayload.dataMimeType()).isEqualTo("application/json");
    assertThat(requester.dataMimeType()).isEqualTo(MimeTypeUtils.APPLICATION_JSON);
}
Also used : DefaultConnectionSetupPayload(io.rsocket.core.DefaultConnectionSetupPayload) ConnectionSetupPayload(io.rsocket.ConnectionSetupPayload) Test(org.junit.jupiter.api.Test)

Example 3 with ConnectionSetupPayload

use of io.rsocket.ConnectionSetupPayload in project spring-framework by spring-projects.

the class DefaultRSocketRequesterBuilderTests method setupWithAsyncValues.

@Test
public void setupWithAsyncValues() {
    Mono<String> asyncMeta1 = Mono.delay(Duration.ofMillis(1)).map(aLong -> "Async Metadata 1");
    Mono<String> asyncMeta2 = Mono.delay(Duration.ofMillis(1)).map(aLong -> "Async Metadata 2");
    Mono<String> data = Mono.delay(Duration.ofMillis(1)).map(aLong -> "Async data");
    RSocketRequester requester = RSocketRequester.builder().dataMimeType(MimeTypeUtils.TEXT_PLAIN).setupRoute("toA").setupMetadata(asyncMeta1, new MimeType("text", "x.test.metadata1")).setupMetadata(asyncMeta2, new MimeType("text", "x.test.metadata2")).setupData(data).transport(this.transport);
    ConnectionSetupPayload setupPayload = getConnectionSetupPayload(requester);
    MimeType compositeMimeType = MimeTypeUtils.parseMimeType(WellKnownMimeType.MESSAGE_RSOCKET_COMPOSITE_METADATA.getString());
    DefaultMetadataExtractor extractor = new DefaultMetadataExtractor(StringDecoder.allMimeTypes());
    extractor.metadataToExtract(new MimeType("text", "x.test.metadata1"), String.class, "asyncMeta1");
    extractor.metadataToExtract(new MimeType("text", "x.test.metadata2"), String.class, "asyncMeta2");
    Map<String, Object> metadataValues = extractor.extract(setupPayload, compositeMimeType);
    assertThat(metadataValues.get("asyncMeta1")).isEqualTo("Async Metadata 1");
    assertThat(metadataValues.get("asyncMeta2")).isEqualTo("Async Metadata 2");
    assertThat(setupPayload.getDataUtf8()).isEqualTo("Async data");
}
Also used : DefaultConnectionSetupPayload(io.rsocket.core.DefaultConnectionSetupPayload) ConnectionSetupPayload(io.rsocket.ConnectionSetupPayload) MimeType(org.springframework.util.MimeType) WellKnownMimeType(io.rsocket.metadata.WellKnownMimeType) Test(org.junit.jupiter.api.Test)

Example 4 with ConnectionSetupPayload

use of io.rsocket.ConnectionSetupPayload in project spring-framework by spring-projects.

the class DefaultRSocketRequesterBuilderTests method setupRoute.

@Test
public void setupRoute() {
    RSocketRequester requester = RSocketRequester.builder().dataMimeType(MimeTypeUtils.TEXT_PLAIN).metadataMimeType(MimeTypeUtils.TEXT_PLAIN).setupRoute("toA").setupData("My data").transport(this.transport);
    ConnectionSetupPayload setupPayload = getConnectionSetupPayload(requester);
    assertThat(setupPayload.getMetadataUtf8()).isEqualTo("toA");
    assertThat(setupPayload.getDataUtf8()).isEqualTo("My data");
}
Also used : DefaultConnectionSetupPayload(io.rsocket.core.DefaultConnectionSetupPayload) ConnectionSetupPayload(io.rsocket.ConnectionSetupPayload) Test(org.junit.jupiter.api.Test)

Aggregations

ConnectionSetupPayload (io.rsocket.ConnectionSetupPayload)4 DefaultConnectionSetupPayload (io.rsocket.core.DefaultConnectionSetupPayload)4 Test (org.junit.jupiter.api.Test)4 WellKnownMimeType (io.rsocket.metadata.WellKnownMimeType)2 MimeType (org.springframework.util.MimeType)2 ByteBuf (io.netty.buffer.ByteBuf)1 ByteBufAllocator (io.netty.buffer.ByteBufAllocator)1 DuplexConnection (io.rsocket.DuplexConnection)1 RSocketErrorException (io.rsocket.RSocketErrorException)1 RSocketConnector (io.rsocket.core.RSocketConnector)1 PayloadDecoder (io.rsocket.frame.decoder.PayloadDecoder)1 ClientTransport (io.rsocket.transport.ClientTransport)1 Field (java.lang.reflect.Field)1 InetSocketAddress (java.net.InetSocketAddress)1 SocketAddress (java.net.SocketAddress)1 Duration (java.time.Duration)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Consumer (java.util.function.Consumer)1