Search in sources :

Example 16 with AntPathMatcher

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

the class DestinationPatternsMessageConditionTests method prependSlashWithCustomPathSeparator.

@Test
public void prependSlashWithCustomPathSeparator() {
    DestinationPatternsMessageCondition c = new DestinationPatternsMessageCondition(new String[] { "foo" }, new AntPathMatcher("."));
    assertThat(c.getPatterns().iterator().next()).as("Pre-pending should be disabled when not using '/' as path separator").isEqualTo("foo");
}
Also used : AntPathMatcher(org.springframework.util.AntPathMatcher) Test(org.junit.jupiter.api.Test)

Example 17 with AntPathMatcher

use of org.springframework.util.AntPathMatcher 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 18 with AntPathMatcher

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

the class MessageMappingMessageHandlerTests method unhandledExceptionShouldFlowThrough.

@Test
public void unhandledExceptionShouldFlowThrough() {
    GenericMessage<?> message = new GenericMessage<>(new Object(), Collections.singletonMap(DestinationPatternsMessageCondition.LOOKUP_DESTINATION_HEADER, new SimpleRouteMatcher(new AntPathMatcher()).parseRoute("string")));
    StepVerifier.create(initMesssageHandler().handleMessage(message)).expectErrorSatisfies(ex -> assertThat(ex.getMessage().startsWith("Could not resolve method parameter at index 0")).as("Actual: " + ex.getMessage()).isTrue()).verify(Duration.ofSeconds(5));
}
Also used : CharSequenceEncoder(org.springframework.core.codec.CharSequenceEncoder) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) Decoder(org.springframework.core.codec.Decoder) PropertySource(org.springframework.core.env.PropertySource) DefaultDataBufferFactory(org.springframework.core.io.buffer.DefaultDataBufferFactory) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DestinationVariable(org.springframework.messaging.handler.annotation.DestinationVariable) DestinationPatternsMessageCondition(org.springframework.messaging.handler.DestinationPatternsMessageCondition) Controller(org.springframework.stereotype.Controller) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) SimpleRouteMatcher(org.springframework.util.SimpleRouteMatcher) Duration(java.time.Duration) Message(org.springframework.messaging.Message) AntPathMatcher(org.springframework.util.AntPathMatcher) Encoder(org.springframework.core.codec.Encoder) ReactiveAdapterRegistry(org.springframework.core.ReactiveAdapterRegistry) TestEncoderMethodReturnValueHandler(org.springframework.messaging.handler.invocation.reactive.TestEncoderMethodReturnValueHandler) MessageHeaderAccessor(org.springframework.messaging.support.MessageHeaderAccessor) StringDecoder(org.springframework.core.codec.StringDecoder) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Mono(reactor.core.publisher.Mono) DataBuffer(org.springframework.core.io.buffer.DataBuffer) MessageMapping(org.springframework.messaging.handler.annotation.MessageMapping) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) List(java.util.List) MapPropertySource(org.springframework.core.env.MapPropertySource) MessageExceptionHandler(org.springframework.messaging.handler.annotation.MessageExceptionHandler) GenericMessage(org.springframework.messaging.support.GenericMessage) Collections(java.util.Collections) MessageBuilder(org.springframework.messaging.support.MessageBuilder) EmbeddedValueResolver(org.springframework.beans.factory.config.EmbeddedValueResolver) GenericMessage(org.springframework.messaging.support.GenericMessage) SimpleRouteMatcher(org.springframework.util.SimpleRouteMatcher) AntPathMatcher(org.springframework.util.AntPathMatcher) Test(org.junit.jupiter.api.Test)

Example 19 with AntPathMatcher

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

the class MethodMessageHandlerTests method bestMatch.

@Test
@SuppressWarnings("unchecked")
public void bestMatch() throws NoSuchMethodException {
    TestMethodMessageHandler handler = new TestMethodMessageHandler();
    TestController controller = new TestController();
    handler.registerHandlerMethod(controller, TestController.class.getMethod("handleMessageMatch1"), "/bestmatch/{foo}/path");
    handler.registerHandlerMethod(controller, TestController.class.getMethod("handleMessageMatch2"), "/bestmatch/*/*");
    handler.afterPropertiesSet();
    Message<?> message = new GenericMessage<>("body", Collections.singletonMap(DestinationPatternsMessageCondition.LOOKUP_DESTINATION_HEADER, new SimpleRouteMatcher(new AntPathMatcher()).parseRoute("/bestmatch/bar/path")));
    handler.handleMessage(message).block(Duration.ofSeconds(5));
    StepVerifier.create((Publisher<Object>) handler.getLastReturnValue()).expectNext("handleMessageMatch1").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 20 with AntPathMatcher

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

the class MethodMessageHandlerTests method argumentResolution.

@Test
@SuppressWarnings("unchecked")
public void argumentResolution() {
    ArgumentResolverConfigurer configurer = new ArgumentResolverConfigurer();
    configurer.addCustomResolver(new StubArgumentResolver(String.class, "foo"));
    TestMethodMessageHandler handler = initMethodMessageHandler(theHandler -> theHandler.setArgumentResolverConfigurer(configurer), TestController.class);
    Message<?> message = new GenericMessage<>("body", Collections.singletonMap(DestinationPatternsMessageCondition.LOOKUP_DESTINATION_HEADER, new SimpleRouteMatcher(new AntPathMatcher()).parseRoute("/handleMessageWithArgument")));
    handler.handleMessage(message).block(Duration.ofSeconds(5));
    StepVerifier.create((Publisher<Object>) handler.getLastReturnValue()).expectNext("handleMessageWithArgument,payload=foo").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)

Aggregations

AntPathMatcher (org.springframework.util.AntPathMatcher)36 Test (org.junit.jupiter.api.Test)13 SimpleRouteMatcher (org.springframework.util.SimpleRouteMatcher)11 Test (org.junit.Test)5 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 Message (org.springframework.messaging.Message)3 DefaultMetadataExtractor (org.springframework.messaging.rsocket.DefaultMetadataExtractor)3 RSocketStrategies (org.springframework.messaging.rsocket.RSocketStrategies)3 MessageHeaderAccessor (org.springframework.messaging.support.MessageHeaderAccessor)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)3 PathMatcher (org.springframework.util.PathMatcher)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 BeanFactory (org.springframework.beans.factory.BeanFactory)2 CharSequenceEncoder (org.springframework.core.codec.CharSequenceEncoder)2