Rename @[Path/Destination]Variable in spring-messaging

Issue: SPR-11208
This commit is contained in:
Rossen Stoyanchev
2013-12-11 14:44:57 -05:00
parent a9605a11e9
commit 92dad1849f
6 changed files with 70 additions and 66 deletions

View File

@@ -29,18 +29,19 @@ import org.springframework.core.MethodParameter;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandlingException;
import org.springframework.messaging.handler.annotation.PathVariable;
import org.springframework.messaging.handler.annotation.DestinationVariable;
import org.springframework.messaging.support.MessageBuilder;
import static org.junit.Assert.*;
/**
* Test fixture for {@link PathVariableMethodArgumentResolver} tests.
* Test fixture for {@link DestinationVariableMethodArgumentResolver} tests.
*
* @author Brian Clozel
*/
public class PathVariableMethodArgumentResolverTests {
public class DestinationVariableMethodArgumentResolverTests {
private PathVariableMethodArgumentResolver resolver;
private DestinationVariableMethodArgumentResolver resolver;
private MethodParameter paramAnnotated;
private MethodParameter paramAnnotatedValue;
@@ -49,7 +50,7 @@ public class PathVariableMethodArgumentResolverTests {
@Before
public void setup() throws Exception {
this.resolver = new PathVariableMethodArgumentResolver(new DefaultConversionService());
this.resolver = new DestinationVariableMethodArgumentResolver(new DefaultConversionService());
Method method = getClass().getDeclaredMethod("handleMessage", String.class, String.class, String.class);
this.paramAnnotated = new MethodParameter(method, 0);
@@ -57,9 +58,9 @@ public class PathVariableMethodArgumentResolverTests {
this.paramNotAnnotated = new MethodParameter(method, 2);
this.paramAnnotated.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
GenericTypeResolver.resolveParameterType(this.paramAnnotated, PathVariableMethodArgumentResolver.class);
GenericTypeResolver.resolveParameterType(this.paramAnnotated, DestinationVariableMethodArgumentResolver.class);
this.paramAnnotatedValue.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
GenericTypeResolver.resolveParameterType(this.paramAnnotatedValue, PathVariableMethodArgumentResolver.class);
GenericTypeResolver.resolveParameterType(this.paramAnnotatedValue, DestinationVariableMethodArgumentResolver.class);
}
@Test
@@ -71,13 +72,17 @@ public class PathVariableMethodArgumentResolverTests {
@Test
public void resolveArgument() throws Exception {
Map<String, Object> pathParams = new HashMap<String, Object>();
pathParams.put("foo", "bar");
pathParams.put("name", "value");
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("foo", "bar");
vars.put("name", "value");
Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).setHeader(
PathVariableMethodArgumentResolver.PATH_TEMPLATE_VARIABLES_HEADER, pathParams).build();
DestinationVariableMethodArgumentResolver.DESTINATION_TEMPLATE_VARIABLES_HEADER, vars).build();
Object result = this.resolver.resolveArgument(this.paramAnnotated, message);
assertEquals("bar", result);
result = this.resolver.resolveArgument(this.paramAnnotatedValue, message);
assertEquals("value", result);
}
@@ -89,6 +94,10 @@ public class PathVariableMethodArgumentResolverTests {
}
@SuppressWarnings("unused")
private void handleMessage(@PathVariable String foo, @PathVariable(value = "name") String param1, String param3) {
private void handleMessage(
@DestinationVariable String foo,
@DestinationVariable(value = "name") String param1,
String param3) {
}
}

View File

@@ -26,17 +26,16 @@ import org.springframework.context.support.StaticApplicationContext;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.SubscribableChannel;
import org.springframework.messaging.handler.annotation.DestinationVariable;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.PathVariable;
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.messaging.simp.SimpMessageSendingOperations;
import org.springframework.messaging.simp.SimpMessageType;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.messaging.simp.annotation.SubscribeMapping;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler;
import org.springframework.stereotype.Controller;
import static org.junit.Assert.*;
@@ -86,26 +85,26 @@ public class SimpAnnotationMethodMessageHandlerTests {
}
@Test
public void messageMappingPathVariableResolution() {
public void messageMappingDestinationVariableResolution() {
SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create();
headers.setDestination("/pre/message/bar/value");
Message<?> message = MessageBuilder.withPayload(new byte[0]).setHeaders(headers).build();
this.messageHandler.handleMessage(message);
assertEquals("messageMappingPathVariable", this.testController.method);
assertEquals("messageMappingDestinationVariable", this.testController.method);
assertEquals("bar", this.testController.arguments.get("foo"));
assertEquals("value", this.testController.arguments.get("name"));
}
@Test
public void subscribeEventPathVariableResolution() {
public void subscribeEventDestinationVariableResolution() {
SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create(SimpMessageType.SUBSCRIBE);
headers.setDestination("/pre/sub/bar/value");
Message<?> message = MessageBuilder.withPayload(new byte[0])
.copyHeaders(headers.toMap()).build();
this.messageHandler.handleMessage(message);
assertEquals("subscribeEventPathVariable", this.testController.method);
assertEquals("subscribeEventDestinationVariable", this.testController.method);
assertEquals("bar", this.testController.arguments.get("foo"));
assertEquals("value", this.testController.arguments.get("name"));
}
@@ -175,17 +174,17 @@ public class SimpAnnotationMethodMessageHandlerTests {
}
@MessageMapping("/message/{foo}/{name}")
public void messageMappingPathVariable(@PathVariable("foo") String param1,
@PathVariable("name") String param2) {
this.method = "messageMappingPathVariable";
public void messageMappingDestinationVariable(@DestinationVariable("foo") String param1,
@DestinationVariable("name") String param2) {
this.method = "messageMappingDestinationVariable";
this.arguments.put("foo", param1);
this.arguments.put("name", param2);
}
@SubscribeMapping("/sub/{foo}/{name}")
public void subscribeEventPathVariable(@PathVariable("foo") String param1,
@PathVariable("name") String param2) {
this.method = "subscribeEventPathVariable";
public void subscribeEventDestinationVariable(@DestinationVariable("foo") String param1,
@DestinationVariable("name") String param2) {
this.method = "subscribeEventDestinationVariable";
this.arguments.put("foo", param1);
this.arguments.put("name", param2);
}
@@ -196,7 +195,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
}
@MessageMapping("/bestmatch/{foo}/path")
public void bestMatch(@PathVariable("foo") String param1) {
public void bestMatch(@DestinationVariable("foo") String param1) {
this.method = "bestMatch";
this.arguments.put("foo", param1);
}
@@ -207,7 +206,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
}
@MessageMapping("/binding/id/{id}")
public void simpleBinding(@PathVariable("id") Long id) {
public void simpleBinding(@DestinationVariable("id") Long id) {
this.method = "simpleBinding";
this.arguments.put("id", id);
}