/** * Maps a {@link List} of {@link SimpDestinationMessageMatcher} instances. * * @param typesToMatch the {@link SimpMessageType} instance to match on * @return the {@link Constraint} associated to the matchers. */ public Constraint simpTypeMatchers(SimpMessageType... typesToMatch) { MessageMatcher<?>[] typeMatchers = new MessageMatcher<?>[typesToMatch.length]; for (int i = 0; i < typesToMatch.length; i++) { SimpMessageType typeToMatch = typesToMatch[i]; typeMatchers[i] = new SimpMessageTypeMatcher(typeToMatch); } return matchers(typeMatchers); }
@Test public void matchesMessageNullFalse() { Message<String> message = MessageBuilder.withPayload("Hi").build(); assertThat(matcher.matches(message)).isFalse(); } }
@Test public void matchesMessageMessageTrue() { Message<String> message = MessageBuilder .withPayload("Hi") .setHeader(SimpMessageHeaderAccessor.MESSAGE_TYPE_HEADER, SimpMessageType.MESSAGE).build(); assertThat(matcher.matches(message)).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; }
@Test public void matchesMessageConnectFalse() { Message<String> message = MessageBuilder .withPayload("Hi") .setHeader(SimpMessageHeaderAccessor.MESSAGE_TYPE_HEADER, SimpMessageType.CONNECT).build(); assertThat(matcher.matches(message)).isFalse(); }
@Test(expected = IllegalArgumentException.class) public void constructorNullType() { new SimpMessageTypeMatcher(null); }
@Before public void setup() { matcher = new SimpMessageTypeMatcher(SimpMessageType.MESSAGE); }
@Test public void typeConstructorParameterIsTransmitted() throws Exception { matcher = SimpDestinationMessageMatcher.createMessageMatcher("/match", pathMatcher); MessageMatcher<Object> expectedTypeMatcher = new SimpMessageTypeMatcher( SimpMessageType.MESSAGE); assertThat(matcher.getMessageTypeMatcher()).isEqualTo(expectedTypeMatcher); }
/** * Maps a {@link List} of {@link SimpDestinationMessageMatcher} instances. * * @param typesToMatch the {@link SimpMessageType} instance to match on * @return the {@link Constraint} associated to the matchers. */ public Constraint simpTypeMatchers(SimpMessageType... typesToMatch) { MessageMatcher<?>[] typeMatchers = new MessageMatcher<?>[typesToMatch.length]; for (int i = 0; i < typesToMatch.length; i++) { SimpMessageType typeToMatch = typesToMatch[i]; typeMatchers[i] = new SimpMessageTypeMatcher(typeToMatch); } return matchers(typeMatchers); }
/** * Maps a {@link List} of {@link SimpDestinationMessageMatcher} instances. * * @param typesToMatch the {@link SimpMessageType} instance to match on * @return the {@link Constraint} associated to the matchers. */ public Constraint simpTypeMatchers(SimpMessageType... typesToMatch) { MessageMatcher<?>[] typeMatchers = new MessageMatcher<?>[typesToMatch.length]; for (int i = 0; i < typesToMatch.length; i++) { SimpMessageType typeToMatch = typesToMatch[i]; typeMatchers[i] = new SimpMessageTypeMatcher(typeToMatch); } return matchers(typeMatchers); }
/** * <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; }