SEC-2827: Clean up MessageMatcher Ambiguities
This commit is contained in:
+20
-5
@@ -22,6 +22,8 @@ import org.junit.Test;
|
||||
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
|
||||
import org.springframework.messaging.simp.SimpMessageType;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
import org.springframework.util.PathMatcher;
|
||||
|
||||
|
||||
public class SimpDestinationMessageMatcherTests {
|
||||
@@ -29,10 +31,13 @@ public class SimpDestinationMessageMatcherTests {
|
||||
|
||||
SimpDestinationMessageMatcher matcher;
|
||||
|
||||
PathMatcher pathMatcher;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
messageBuilder = MessageBuilder.withPayload("M");
|
||||
matcher = new SimpDestinationMessageMatcher("/**");
|
||||
pathMatcher = new AntPathMatcher();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@@ -72,7 +77,7 @@ public class SimpDestinationMessageMatcherTests {
|
||||
|
||||
@Test
|
||||
public void matchesFalseMessageTypeNotDisconnectType() throws Exception {
|
||||
matcher = new SimpDestinationMessageMatcher("/match", SimpMessageType.MESSAGE);
|
||||
matcher = SimpDestinationMessageMatcher.createMessageMatcher("/match", pathMatcher);
|
||||
|
||||
messageBuilder.setHeader(SimpMessageHeaderAccessor.MESSAGE_TYPE_HEADER, SimpMessageType.DISCONNECT);
|
||||
|
||||
@@ -81,7 +86,7 @@ public class SimpDestinationMessageMatcherTests {
|
||||
|
||||
@Test
|
||||
public void matchesTrueMessageType() throws Exception {
|
||||
matcher = new SimpDestinationMessageMatcher("/match", SimpMessageType.MESSAGE);
|
||||
matcher = SimpDestinationMessageMatcher.createMessageMatcher("/match", pathMatcher);
|
||||
|
||||
messageBuilder.setHeader(SimpMessageHeaderAccessor.DESTINATION_HEADER,"/match");
|
||||
messageBuilder.setHeader(SimpMessageHeaderAccessor.MESSAGE_TYPE_HEADER, SimpMessageType.MESSAGE);
|
||||
@@ -89,9 +94,19 @@ public class SimpDestinationMessageMatcherTests {
|
||||
assertThat(matcher.matches(messageBuilder.build())).isTrue();
|
||||
}
|
||||
|
||||
@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 matchesNullMessageType() throws Exception {
|
||||
matcher = new SimpDestinationMessageMatcher("/match", null);
|
||||
matcher = new SimpDestinationMessageMatcher("/match");
|
||||
|
||||
messageBuilder.setHeader(SimpMessageHeaderAccessor.DESTINATION_HEADER,"/match");
|
||||
messageBuilder.setHeader(SimpMessageHeaderAccessor.MESSAGE_TYPE_HEADER, SimpMessageType.MESSAGE);
|
||||
@@ -101,11 +116,11 @@ public class SimpDestinationMessageMatcherTests {
|
||||
|
||||
@Test
|
||||
public void typeConstructorParameterIsTransmitted() throws Exception {
|
||||
matcher = new SimpDestinationMessageMatcher("/match", SimpMessageType.MESSAGE);
|
||||
matcher = SimpDestinationMessageMatcher.createMessageMatcher("/match", pathMatcher);
|
||||
|
||||
MessageMatcher<Object> expectedTypeMatcher = new SimpMessageTypeMatcher(SimpMessageType.MESSAGE);
|
||||
|
||||
assertThat(matcher.getMessageTypeMatcher()).isEqualTo(expectedTypeMatcher);
|
||||
assertThat(matcher.getMessageTypeMatcher()).isEqualTo(expectedTypeMatcher);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user