/** * <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); }
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 boolean matches(Message<? extends T> message) { for (MessageMatcher<T> matcher : getMessageMatchers()) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Trying to match using " + matcher); } if (!matcher.matches(message)) { LOGGER.debug("Did not match"); return false; } } LOGGER.debug("All messageMatchers returned true"); return true; } }
@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); }
public boolean matches(Message<? extends T> message) { for (MessageMatcher<T> matcher : getMessageMatchers()) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Trying to match using " + matcher); } if (matcher.matches(message)) { LOGGER.debug("matched"); return true; } } LOGGER.debug("No matches found"); return false; } }
@Test public void matchesSingleFalse() { when(delegate.matches(message)).thenReturn(false); matcher = new AndMessageMatcher<>(delegate); assertThat(matcher.matches(message)).isFalse(); }
@SuppressWarnings("unchecked") @Test(expected = IllegalArgumentException.class) public void constructorEmptyArray() { new OrMessageMatcher<>((MessageMatcher<Object>[]) new MessageMatcher[0]); }
@SuppressWarnings("unchecked") @Test(expected = IllegalArgumentException.class) public void constructorEmptyArray() { new AndMessageMatcher<>((MessageMatcher<Object>[]) new MessageMatcher[0]); }
/** * <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(expected = IllegalArgumentException.class) public void constructorNullType() { new SimpMessageTypeMatcher(null); }
@Test(expected = IllegalArgumentException.class) public void constructorNullList() { new OrMessageMatcher<>((List<MessageMatcher<Object>>) null); }
@Test(expected = IllegalArgumentException.class) public void constructorNullList() { new AndMessageMatcher<>((List<MessageMatcher<Object>>) null); }
public void constructorOnlyPathNoError() { new SimpDestinationMessageMatcher("/path"); }
@Before public void setup() { matcher = new SimpMessageTypeMatcher(SimpMessageType.MESSAGE); }
@Test(expected = NullPointerException.class) public void constructorNullArray() { new OrMessageMatcher<>((MessageMatcher<Object>[]) null); }
@Test(expected = IllegalArgumentException.class) public void constructorArrayContainsNull() { new AndMessageMatcher<>((MessageMatcher<Object>) null); }
@Test(expected = IllegalArgumentException.class) public void constructorPatternNull() { new SimpDestinationMessageMatcher(null); }
@Test(expected = IllegalArgumentException.class) public void constructorArrayContainsNull() { new OrMessageMatcher<>((MessageMatcher<Object>) null); }
@Test(expected = NullPointerException.class) public void constructorNullArray() { new AndMessageMatcher<>((MessageMatcher<Object>[]) null); }