|
@@ -1,5 +1,5 @@
|
|
|
/*
|
|
|
- * Copyright 2002-2016 the original author or authors.
|
|
|
+ * Copyright 2002-2018 the original author or authors.
|
|
|
*
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
* you may not use this file except in compliance with the License.
|
|
@@ -20,26 +20,40 @@ import org.junit.Test;
|
|
|
import org.junit.runner.RunWith;
|
|
|
import org.mockito.Mock;
|
|
|
import org.mockito.junit.MockitoJUnitRunner;
|
|
|
+import org.springframework.expression.EvaluationContext;
|
|
|
import org.springframework.expression.Expression;
|
|
|
+import org.springframework.messaging.Message;
|
|
|
+import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
|
|
|
+import org.springframework.messaging.support.MessageBuilder;
|
|
|
+import org.springframework.security.messaging.util.matcher.MessageMatcher;
|
|
|
+import org.springframework.security.messaging.util.matcher.SimpDestinationMessageMatcher;
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
-import static org.mockito.Mockito.when;
|
|
|
+import static org.mockito.Mockito.*;
|
|
|
|
|
|
@RunWith(MockitoJUnitRunner.class)
|
|
|
public class MessageExpressionConfigAttributeTests {
|
|
|
@Mock
|
|
|
Expression expression;
|
|
|
|
|
|
+ @Mock
|
|
|
+ MessageMatcher<?> matcher;
|
|
|
+
|
|
|
MessageExpressionConfigAttribute attribute;
|
|
|
|
|
|
@Before
|
|
|
public void setup() {
|
|
|
- attribute = new MessageExpressionConfigAttribute(expression);
|
|
|
+ attribute = new MessageExpressionConfigAttribute(expression, matcher);
|
|
|
}
|
|
|
|
|
|
@Test(expected = IllegalArgumentException.class)
|
|
|
public void constructorNullExpression() {
|
|
|
- new MessageExpressionConfigAttribute(null);
|
|
|
+ new MessageExpressionConfigAttribute(null, matcher);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test(expected = IllegalArgumentException.class)
|
|
|
+ public void constructorNullMatcher() {
|
|
|
+ new MessageExpressionConfigAttribute(expression, null);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -58,4 +72,16 @@ public class MessageExpressionConfigAttributeTests {
|
|
|
|
|
|
assertThat(attribute.toString()).isEqualTo(expression.getExpressionString());
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void postProcessContext() {
|
|
|
+ SimpDestinationMessageMatcher matcher = new SimpDestinationMessageMatcher("/topics/{topic}/**");
|
|
|
+ Message<?> message = MessageBuilder.withPayload("M").setHeader(SimpMessageHeaderAccessor.DESTINATION_HEADER, "/topics/someTopic/sub1").build();
|
|
|
+ EvaluationContext context = mock(EvaluationContext.class);
|
|
|
+
|
|
|
+ attribute = new MessageExpressionConfigAttribute(expression, matcher);
|
|
|
+ attribute.postProcess(context, message);
|
|
|
+
|
|
|
+ verify(context).setVariable("topic", "someTopic");
|
|
|
+ }
|
|
|
}
|