Search in sources :

Example 6 with SimpleRouteMatcher

use of org.springframework.util.SimpleRouteMatcher in project spring-framework by spring-projects.

the class MethodMessageHandlerTests method handleException.

@Test
@SuppressWarnings("unchecked")
public void handleException() {
    TestMethodMessageHandler handler = initMethodMessageHandler(TestController.class);
    Message<?> message = new GenericMessage<>("body", Collections.singletonMap(DestinationPatternsMessageCondition.LOOKUP_DESTINATION_HEADER, new SimpleRouteMatcher(new AntPathMatcher()).parseRoute("/handleMessageWithError")));
    handler.handleMessage(message).block(Duration.ofSeconds(5));
    StepVerifier.create((Publisher<Object>) handler.getLastReturnValue()).expectNext("handleIllegalStateException,ex=rejected").verifyComplete();
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) SimpleRouteMatcher(org.springframework.util.SimpleRouteMatcher) AntPathMatcher(org.springframework.util.AntPathMatcher) Test(org.junit.jupiter.api.Test)

Example 7 with SimpleRouteMatcher

use of org.springframework.util.SimpleRouteMatcher in project spring-framework by spring-projects.

the class RSocketMessageHandlerTests method getRSocketStrategiesReflectsCurrentState.

@Test
public void getRSocketStrategiesReflectsCurrentState() {
    RSocketMessageHandler handler = new RSocketMessageHandler();
    // 1. Set properties
    handler.setDecoders(Collections.singletonList(new ByteArrayDecoder()));
    handler.setEncoders(Collections.singletonList(new ByteArrayEncoder()));
    handler.setRouteMatcher(new SimpleRouteMatcher(new AntPathMatcher()));
    handler.setMetadataExtractor(new DefaultMetadataExtractor());
    handler.setReactiveAdapterRegistry(new ReactiveAdapterRegistry());
    RSocketStrategies strategies = handler.getRSocketStrategies();
    assertThat(strategies.encoders()).isEqualTo(handler.getEncoders());
    assertThat(strategies.decoders()).isEqualTo(handler.getDecoders());
    assertThat(strategies.routeMatcher()).isSameAs(handler.getRouteMatcher());
    assertThat(strategies.metadataExtractor()).isSameAs(handler.getMetadataExtractor());
    assertThat(strategies.reactiveAdapterRegistry()).isSameAs(handler.getReactiveAdapterRegistry());
    // 2. Set properties again
    handler.setDecoders(Collections.singletonList(StringDecoder.allMimeTypes()));
    handler.setEncoders(Collections.singletonList(CharSequenceEncoder.allMimeTypes()));
    handler.setRouteMatcher(new SimpleRouteMatcher(new AntPathMatcher()));
    handler.setMetadataExtractor(new DefaultMetadataExtractor());
    handler.setReactiveAdapterRegistry(new ReactiveAdapterRegistry());
    handler.afterPropertiesSet();
    strategies = handler.getRSocketStrategies();
    assertThat(strategies.encoders()).isEqualTo(handler.getEncoders());
    assertThat(strategies.decoders()).isEqualTo(handler.getDecoders());
    assertThat(strategies.routeMatcher()).isSameAs(handler.getRouteMatcher());
    assertThat(strategies.metadataExtractor()).isSameAs(handler.getMetadataExtractor());
    assertThat(strategies.reactiveAdapterRegistry()).isSameAs(handler.getReactiveAdapterRegistry());
}
Also used : ByteArrayEncoder(org.springframework.core.codec.ByteArrayEncoder) ReactiveAdapterRegistry(org.springframework.core.ReactiveAdapterRegistry) RSocketStrategies(org.springframework.messaging.rsocket.RSocketStrategies) DefaultMetadataExtractor(org.springframework.messaging.rsocket.DefaultMetadataExtractor) SimpleRouteMatcher(org.springframework.util.SimpleRouteMatcher) AntPathMatcher(org.springframework.util.AntPathMatcher) ByteArrayDecoder(org.springframework.core.codec.ByteArrayDecoder) Test(org.junit.jupiter.api.Test)

Example 8 with SimpleRouteMatcher

use of org.springframework.util.SimpleRouteMatcher in project spring-framework by spring-projects.

the class RSocketMessageHandlerTests method getRSocketStrategies.

@Test
public void getRSocketStrategies() {
    RSocketMessageHandler handler = new RSocketMessageHandler();
    handler.setDecoders(Collections.singletonList(new ByteArrayDecoder()));
    handler.setEncoders(Collections.singletonList(new ByteArrayEncoder()));
    handler.setRouteMatcher(new SimpleRouteMatcher(new AntPathMatcher()));
    handler.setMetadataExtractor(new DefaultMetadataExtractor());
    handler.setReactiveAdapterRegistry(new ReactiveAdapterRegistry());
    RSocketStrategies strategies = handler.getRSocketStrategies();
    assertThat(strategies).isNotNull();
    assertThat(strategies.encoders()).isEqualTo(handler.getEncoders());
    assertThat(strategies.decoders()).isEqualTo(handler.getDecoders());
    assertThat(strategies.routeMatcher()).isSameAs(handler.getRouteMatcher());
    assertThat(strategies.metadataExtractor()).isSameAs(handler.getMetadataExtractor());
    assertThat(strategies.reactiveAdapterRegistry()).isSameAs(handler.getReactiveAdapterRegistry());
}
Also used : ByteArrayEncoder(org.springframework.core.codec.ByteArrayEncoder) ReactiveAdapterRegistry(org.springframework.core.ReactiveAdapterRegistry) RSocketStrategies(org.springframework.messaging.rsocket.RSocketStrategies) DefaultMetadataExtractor(org.springframework.messaging.rsocket.DefaultMetadataExtractor) SimpleRouteMatcher(org.springframework.util.SimpleRouteMatcher) AntPathMatcher(org.springframework.util.AntPathMatcher) ByteArrayDecoder(org.springframework.core.codec.ByteArrayDecoder) Test(org.junit.jupiter.api.Test)

Example 9 with SimpleRouteMatcher

use of org.springframework.util.SimpleRouteMatcher in project spring-framework by spring-projects.

the class RSocketMessageHandlerTests method setRSocketStrategies.

@Test
public void setRSocketStrategies() {
    RSocketStrategies strategies = RSocketStrategies.builder().encoder(new ByteArrayEncoder()).decoder(new ByteArrayDecoder()).routeMatcher(new SimpleRouteMatcher(new AntPathMatcher())).metadataExtractor(new DefaultMetadataExtractor()).reactiveAdapterStrategy(new ReactiveAdapterRegistry()).build();
    RSocketMessageHandler handler = new RSocketMessageHandler();
    handler.setRSocketStrategies(strategies);
    assertThat(handler.getEncoders()).isEqualTo(strategies.encoders());
    assertThat(handler.getDecoders()).isEqualTo(strategies.decoders());
    assertThat(handler.getRouteMatcher()).isSameAs(strategies.routeMatcher());
    assertThat(handler.getMetadataExtractor()).isSameAs(strategies.metadataExtractor());
    assertThat(handler.getReactiveAdapterRegistry()).isSameAs(strategies.reactiveAdapterRegistry());
}
Also used : ByteArrayEncoder(org.springframework.core.codec.ByteArrayEncoder) ReactiveAdapterRegistry(org.springframework.core.ReactiveAdapterRegistry) RSocketStrategies(org.springframework.messaging.rsocket.RSocketStrategies) DefaultMetadataExtractor(org.springframework.messaging.rsocket.DefaultMetadataExtractor) SimpleRouteMatcher(org.springframework.util.SimpleRouteMatcher) AntPathMatcher(org.springframework.util.AntPathMatcher) ByteArrayDecoder(org.springframework.core.codec.ByteArrayDecoder) Test(org.junit.jupiter.api.Test)

Example 10 with SimpleRouteMatcher

use of org.springframework.util.SimpleRouteMatcher in project spring-framework by spring-projects.

the class RSocketMessageHandlerTests method testHandleNoMatch.

private static void testHandleNoMatch(FrameType frameType) {
    RSocketMessageHandler handler = new RSocketMessageHandler();
    handler.setDecoders(Collections.singletonList(StringDecoder.allMimeTypes()));
    handler.setEncoders(Collections.singletonList(CharSequenceEncoder.allMimeTypes()));
    handler.afterPropertiesSet();
    RouteMatcher matcher = new SimpleRouteMatcher(new AntPathMatcher("."));
    RouteMatcher.Route route = matcher.parseRoute("path");
    MessageHeaderAccessor headers = new MessageHeaderAccessor();
    headers.setHeader(RSocketFrameTypeMessageCondition.FRAME_TYPE_HEADER, frameType);
    Message<Object> message = MessageBuilder.createMessage("", headers.getMessageHeaders());
    handler.handleNoMatch(route, message);
}
Also used : RouteMatcher(org.springframework.util.RouteMatcher) SimpleRouteMatcher(org.springframework.util.SimpleRouteMatcher) MessageHeaderAccessor(org.springframework.messaging.support.MessageHeaderAccessor) SimpleRouteMatcher(org.springframework.util.SimpleRouteMatcher) AntPathMatcher(org.springframework.util.AntPathMatcher)

Aggregations

AntPathMatcher (org.springframework.util.AntPathMatcher)11 SimpleRouteMatcher (org.springframework.util.SimpleRouteMatcher)11 Test (org.junit.jupiter.api.Test)8 ReactiveAdapterRegistry (org.springframework.core.ReactiveAdapterRegistry)5 ByteArrayDecoder (org.springframework.core.codec.ByteArrayDecoder)4 ByteArrayEncoder (org.springframework.core.codec.ByteArrayEncoder)4 GenericMessage (org.springframework.messaging.support.GenericMessage)4 DefaultMetadataExtractor (org.springframework.messaging.rsocket.DefaultMetadataExtractor)3 RSocketStrategies (org.springframework.messaging.rsocket.RSocketStrategies)3 MessageHeaderAccessor (org.springframework.messaging.support.MessageHeaderAccessor)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 CharSequenceEncoder (org.springframework.core.codec.CharSequenceEncoder)2 StringDecoder (org.springframework.core.codec.StringDecoder)2 DataBuffer (org.springframework.core.io.buffer.DataBuffer)2 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)1 Duration (java.time.Duration)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Consumer (java.util.function.Consumer)1