public MessageMatcher<?> build() { if (type == null) { return new SimpDestinationMessageMatcher(pattern, pathMatcher); } else if (SimpMessageType.MESSAGE == type) { return SimpDestinationMessageMatcher.createMessageMatcher(pattern, pathMatcher); } else if (SimpMessageType.SUBSCRIBE == type) { return SimpDestinationMessageMatcher.createSubscribeMatcher(pattern, pathMatcher); } throw new IllegalStateException(type + " is not supported since it does not have a destination"); } }
/** * <p> * Creates a new instance with the specified pattern, {@link SimpMessageType}, and * {@link PathMatcher}. * * @param pattern the pattern to use * @param type the {@link SimpMessageType} to match on or null if any * {@link SimpMessageType} should be matched. * @param pathMatcher the {@link PathMatcher} to use. */ private SimpDestinationMessageMatcher(String pattern, SimpMessageType type, PathMatcher pathMatcher) { Assert.notNull(pattern, "pattern cannot be null"); Assert.notNull(pathMatcher, "pathMatcher cannot be null"); if (!isTypeWithDestination(type)) { throw new IllegalArgumentException("SimpMessageType " + type + " does not contain a destination and so cannot be matched on."); } this.matcher = pathMatcher; this.messageTypeMatcher = type == null ? ANY_MESSAGE : new SimpMessageTypeMatcher(type); this.pattern = pattern; }
/** * <p> * Creates a new instance with the specified pattern, * {@code SimpMessageType.SUBSCRIBE}, and {@link PathMatcher}. * * @param pattern the pattern to use * @param matcher the {@link PathMatcher} to use. */ public static SimpDestinationMessageMatcher createSubscribeMatcher(String pattern, PathMatcher matcher) { return new SimpDestinationMessageMatcher(pattern, SimpMessageType.SUBSCRIBE, matcher); }
@Test public void matchesFalseWithDestination() throws Exception { matcher = new SimpDestinationMessageMatcher("/nomatch"); messageBuilder.setHeader(SimpMessageHeaderAccessor.DESTINATION_HEADER, "/destination/1"); assertThat(matcher.matches(messageBuilder.build())).isFalse(); }
@Test public void matchesFalseMessageTypeNotDisconnectType() throws Exception { matcher = SimpDestinationMessageMatcher.createMessageMatcher("/match", pathMatcher); messageBuilder.setHeader(SimpMessageHeaderAccessor.MESSAGE_TYPE_HEADER, SimpMessageType.DISCONNECT); assertThat(matcher.matches(messageBuilder.build())).isFalse(); }
@Test public void typeConstructorParameterIsTransmitted() throws Exception { matcher = SimpDestinationMessageMatcher.createMessageMatcher("/match", pathMatcher); MessageMatcher<Object> expectedTypeMatcher = new SimpMessageTypeMatcher( SimpMessageType.MESSAGE); assertThat(matcher.getMessageTypeMatcher()).isEqualTo(expectedTypeMatcher); }
@Test public void matchesTrueSubscribeType() throws Exception { matcher = SimpDestinationMessageMatcher.createSubscribeMatcher("/match", pathMatcher); messageBuilder.setHeader(SimpMessageHeaderAccessor.DESTINATION_HEADER, "/match"); messageBuilder.setHeader(SimpMessageHeaderAccessor.MESSAGE_TYPE_HEADER, SimpMessageType.SUBSCRIBE); assertThat(matcher.matches(messageBuilder.build())).isTrue(); }
@Test public void matchesDoesNotMatchNullDestination() throws Exception { assertThat(matcher.matches(messageBuilder.build())).isFalse(); }
/** * <p> * Creates a new instance with the specified pattern, {@code SimpMessageType.MESSAGE}, * and {@link PathMatcher}. * * @param pattern the pattern to use * @param matcher the {@link PathMatcher} to use. */ public static SimpDestinationMessageMatcher createMessageMatcher(String pattern, PathMatcher matcher) { return new SimpDestinationMessageMatcher(pattern, SimpMessageType.MESSAGE, matcher); } }
@Test public void matchesSpecificWithDestination() throws Exception { matcher = new SimpDestinationMessageMatcher("/destination/1"); messageBuilder.setHeader(SimpMessageHeaderAccessor.DESTINATION_HEADER, "/destination/1"); assertThat(matcher.matches(messageBuilder.build())).isTrue(); }
@Test public void matchesTrueMessageType() throws Exception { matcher = SimpDestinationMessageMatcher.createMessageMatcher("/match", pathMatcher); messageBuilder.setHeader(SimpMessageHeaderAccessor.DESTINATION_HEADER, "/match"); messageBuilder.setHeader(SimpMessageHeaderAccessor.MESSAGE_TYPE_HEADER, SimpMessageType.MESSAGE); assertThat(matcher.matches(messageBuilder.build())).isTrue(); }
@Test public void matchesAllWithDestination() throws Exception { messageBuilder.setHeader(SimpMessageHeaderAccessor.DESTINATION_HEADER, "/destination/1"); assertThat(matcher.matches(messageBuilder.build())).isTrue(); }
public MessageMatcher<?> build() { if (type == null) { return new SimpDestinationMessageMatcher(pattern, pathMatcher); } else if (SimpMessageType.MESSAGE == type) { return SimpDestinationMessageMatcher.createMessageMatcher(pattern, pathMatcher); } else if (SimpMessageType.SUBSCRIBE == type) { return SimpDestinationMessageMatcher.createSubscribeMatcher(pattern, pathMatcher); } throw new IllegalStateException(type + " is not supported since it does not have a destination"); } }
public void constructorOnlyPathNoError() { new SimpDestinationMessageMatcher("/path"); }
@Test public void matchesNullMessageType() throws Exception { matcher = new SimpDestinationMessageMatcher("/match"); messageBuilder.setHeader(SimpMessageHeaderAccessor.DESTINATION_HEADER, "/match"); messageBuilder.setHeader(SimpMessageHeaderAccessor.MESSAGE_TYPE_HEADER, SimpMessageType.MESSAGE); assertThat(matcher.matches(messageBuilder.build())).isTrue(); }
/** * <p> * Creates a new instance with the specified pattern, {@link SimpMessageType}, and * {@link PathMatcher}. * * @param pattern the pattern to use * @param type the {@link SimpMessageType} to match on or null if any * {@link SimpMessageType} should be matched. * @param pathMatcher the {@link PathMatcher} to use. */ private SimpDestinationMessageMatcher(String pattern, SimpMessageType type, PathMatcher pathMatcher) { Assert.notNull(pattern, "pattern cannot be null"); Assert.notNull(pathMatcher, "pathMatcher cannot be null"); if (!isTypeWithDestination(type)) { throw new IllegalArgumentException("SimpMessageType " + type + " does not contain a destination and so cannot be matched on."); } this.matcher = pathMatcher; this.messageTypeMatcher = type == null ? ANY_MESSAGE : new SimpMessageTypeMatcher(type); this.pattern = pattern; }
public MessageMatcher<?> build() { if (type == null) { return new SimpDestinationMessageMatcher(pattern, pathMatcher); } else if (SimpMessageType.MESSAGE == type) { return SimpDestinationMessageMatcher.createMessageMatcher(pattern, pathMatcher); } else if (SimpMessageType.SUBSCRIBE == type) { return SimpDestinationMessageMatcher.createSubscribeMatcher(pattern, pathMatcher); } throw new IllegalStateException(type + " is not supported since it does not have a destination"); } }
@Test(expected = IllegalArgumentException.class) public void constructorPatternNull() { new SimpDestinationMessageMatcher(null); }
@Before public void setup() { messageBuilder = MessageBuilder.withPayload("M"); matcher = new SimpDestinationMessageMatcher("/**"); pathMatcher = new AntPathMatcher(); }
/** * <p> * Creates a new instance with the specified pattern, * {@code SimpMessageType.SUBSCRIBE}, and {@link PathMatcher}. * * @param pattern the pattern to use * @param matcher the {@link PathMatcher} to use. */ public static SimpDestinationMessageMatcher createSubscribeMatcher(String pattern, PathMatcher matcher) { return new SimpDestinationMessageMatcher(pattern, SimpMessageType.SUBSCRIBE, matcher); }