Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
0db2f79b
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0db2f79b
编写于
1月 22, 2014
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish message method handling tests
上级
db9b6fa2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
38 addition
and
41 deletion
+38
-41
spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/MethodMessageHandlerTests.java
...ssaging/handler/invocation/MethodMessageHandlerTests.java
+29
-36
spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandlerTests.java
...tion/support/SimpAnnotationMethodMessageHandlerTests.java
+6
-3
spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompWebSocketIntegrationTests.java
.../web/socket/messaging/StompWebSocketIntegrationTests.java
+3
-2
未找到文件。
spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/
Abstract
MethodMessageHandlerTests.java
→
spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/MethodMessageHandlerTests.java
浏览文件 @
0db2f79b
...
...
@@ -20,7 +20,6 @@ import org.hamcrest.Matchers;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.beans.DirectFieldAccessor
;
import
org.springframework.context.support.StaticApplicationContext
;
import
org.springframework.messaging.Message
;
import
org.springframework.messaging.handler.DestinationPatternsMessageCondition
;
...
...
@@ -28,7 +27,6 @@ import org.springframework.messaging.handler.HandlerMethod;
import
org.springframework.messaging.handler.HandlerMethodSelector
;
import
org.springframework.messaging.handler.annotation.support.MessageMethodArgumentResolver
;
import
org.springframework.messaging.support.MessageBuilder
;
import
org.springframework.messaging.support.MessageHeaderAccessor
;
import
org.springframework.util.AntPathMatcher
;
import
org.springframework.util.PathMatcher
;
import
org.springframework.util.ReflectionUtils.MethodFilter
;
...
...
@@ -41,26 +39,31 @@ import static org.junit.Assert.assertNotNull;
import
static
org
.
junit
.
Assert
.
assertThat
;
/**
* Test fixture for {@link org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler}.
* Test fixture for
* {@link org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler}.
*
* @author Brian Clozel
* @author Rossen Stoyanchev
*/
public
class
Abstract
MethodMessageHandlerTests
{
public
class
MethodMessageHandlerTests
{
private
static
final
String
DESTINATION_HEADER
=
"
testD
estination"
;
private
static
final
String
DESTINATION_HEADER
=
"
d
estination"
;
private
My
MethodMessageHandler
messageHandler
;
private
Test
MethodMessageHandler
messageHandler
;
private
TestController
testController
;
@Before
public
void
setup
()
{
List
<
String
>
destinationPrefixes
=
new
ArrayList
<
String
>();
destinationPrefixes
.
add
(
"/test/"
);
this
.
messageHandler
=
new
MyMethodMessageHandler
();
List
<
String
>
destinationPrefixes
=
Arrays
.
asList
(
"/test"
);
this
.
messageHandler
=
new
TestMethodMessageHandler
();
this
.
messageHandler
.
setApplicationContext
(
new
StaticApplicationContext
());
this
.
messageHandler
.
setDestinationPrefixes
(
destinationPrefixes
);
this
.
messageHandler
.
afterPropertiesSet
();
this
.
testController
=
new
TestController
();
this
.
messageHandler
.
registerHandler
(
this
.
testController
);
}
...
...
@@ -73,9 +76,7 @@ public class AbstractMethodMessageHandlerTests {
@Test
public
void
registeredMappings
()
{
DirectFieldAccessor
fieldAccessor
=
new
DirectFieldAccessor
(
this
.
messageHandler
);
Map
<
String
,
HandlerMethod
>
handlerMethods
=
(
Map
<
String
,
HandlerMethod
>)
fieldAccessor
.
getPropertyValue
(
"handlerMethods"
);
Map
<
String
,
HandlerMethod
>
handlerMethods
=
this
.
messageHandler
.
getHandlerMethods
();
assertNotNull
(
handlerMethods
);
assertThat
(
handlerMethods
.
keySet
(),
Matchers
.
hasSize
(
3
));
...
...
@@ -85,12 +86,9 @@ public class AbstractMethodMessageHandlerTests {
public
void
antPatchMatchWildcard
()
throws
Exception
{
Method
method
=
this
.
testController
.
getClass
().
getMethod
(
"handlerPathMatchWildcard"
);
this
.
messageHandler
.
registerHandlerMethod
(
this
.
testController
,
method
,
"/handlerPathMatch*
*
"
);
this
.
messageHandler
.
registerHandlerMethod
(
this
.
testController
,
method
,
"/handlerPathMatch*"
);
MessageHeaderAccessor
headers
=
new
MessageHeaderAccessor
();
headers
.
setHeader
(
DESTINATION_HEADER
,
"/test/handlerPathMatchFoo"
);
Message
<?>
message
=
MessageBuilder
.
withPayload
(
new
byte
[
0
]).
setHeaders
(
headers
).
build
();
this
.
messageHandler
.
handleMessage
(
message
);
this
.
messageHandler
.
handleMessage
(
toDestination
(
"/test/handlerPathMatchFoo"
));
assertEquals
(
"pathMatchWildcard"
,
this
.
testController
.
method
);
}
...
...
@@ -104,39 +102,34 @@ public class AbstractMethodMessageHandlerTests {
method
=
this
.
testController
.
getClass
().
getMethod
(
"secondBestMatch"
);
this
.
messageHandler
.
registerHandlerMethod
(
this
.
testController
,
method
,
"/bestmatch/*/*"
);
MessageHeaderAccessor
headers
=
new
MessageHeaderAccessor
();
headers
.
setHeader
(
DESTINATION_HEADER
,
"/test/bestmatch/bar/path"
);
Message
<?>
message
=
MessageBuilder
.
withPayload
(
new
byte
[
0
]).
setHeaders
(
headers
).
build
();
this
.
messageHandler
.
handleMessage
(
message
);
this
.
messageHandler
.
handleMessage
(
toDestination
(
"/test/bestmatch/bar/path"
));
assertEquals
(
"bestMatch"
,
this
.
testController
.
method
);
}
@Test
public
void
argumentResol
ver
()
{
public
void
argumentResol
ution
()
{
MessageHeaderAccessor
headers
=
new
MessageHeaderAccessor
();
headers
.
setHeader
(
DESTINATION_HEADER
,
"/test/handlerArgumentResolver"
);
Message
<?>
message
=
MessageBuilder
.
withPayload
(
new
byte
[
0
]).
setHeaders
(
headers
).
build
();
this
.
messageHandler
.
handleMessage
(
message
);
this
.
messageHandler
.
handleMessage
(
toDestination
(
"/test/handlerArgumentResolver"
));
assertEquals
(
"handlerArgumentResolver"
,
this
.
testController
.
method
);
assertNotNull
(
this
.
testController
.
arguments
.
get
(
"message"
));
}
@Test
public
void
exception
Resolver
()
{
public
void
exception
Handled
()
{
MessageHeaderAccessor
headers
=
new
MessageHeaderAccessor
();
headers
.
setHeader
(
DESTINATION_HEADER
,
"/test/handlerThrowsExc"
);
Message
<?>
message
=
MessageBuilder
.
withPayload
(
new
byte
[
0
]).
setHeaders
(
headers
).
build
();
this
.
messageHandler
.
handleMessage
(
message
);
this
.
messageHandler
.
handleMessage
(
toDestination
(
"/test/handlerThrowsExc"
));
assertEquals
(
"illegalStateException"
,
this
.
testController
.
method
);
assertNotNull
(
this
.
testController
.
arguments
.
get
(
"exception"
));
}
private
Message
<?>
toDestination
(
String
destination
)
{
return
MessageBuilder
.
withPayload
(
new
byte
[
0
]).
setHeader
(
DESTINATION_HEADER
,
destination
).
build
();
}
private
static
class
TestController
{
public
String
method
;
...
...
@@ -179,7 +172,7 @@ public class AbstractMethodMessageHandlerTests {
}
private
static
class
My
MethodMessageHandler
extends
AbstractMethodMessageHandler
<
String
>
{
private
static
class
Test
MethodMessageHandler
extends
AbstractMethodMessageHandler
<
String
>
{
private
PathMatcher
pathMatcher
=
new
AntPathMatcher
();
...
...
@@ -245,7 +238,7 @@ public class AbstractMethodMessageHandlerTests {
}
@Override
protected
Comparator
<
String
>
getMappingComparator
(
Message
<?>
message
)
{
protected
Comparator
<
String
>
getMappingComparator
(
final
Message
<?>
message
)
{
return
new
Comparator
<
String
>()
{
@Override
public
int
compare
(
String
info1
,
String
info2
)
{
...
...
@@ -258,13 +251,13 @@ public class AbstractMethodMessageHandlerTests {
@Override
protected
AbstractExceptionHandlerMethodResolver
createExceptionHandlerMethodResolverFor
(
Class
<?>
beanType
)
{
return
new
My
ExceptionHandlerMethodResolver
(
beanType
);
return
new
Test
ExceptionHandlerMethodResolver
(
beanType
);
}
}
private
static
class
My
ExceptionHandlerMethodResolver
extends
AbstractExceptionHandlerMethodResolver
{
private
static
class
Test
ExceptionHandlerMethodResolver
extends
AbstractExceptionHandlerMethodResolver
{
public
My
ExceptionHandlerMethodResolver
(
Class
<?>
handlerType
)
{
public
Test
ExceptionHandlerMethodResolver
(
Class
<?>
handlerType
)
{
super
(
initExceptionMappings
(
handlerType
));
}
...
...
spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandlerTests.java
浏览文件 @
0db2f79b
...
...
@@ -43,7 +43,9 @@ import org.springframework.validation.annotation.Validated;
import
static
org
.
junit
.
Assert
.*;
/**
* Test fixture for {@link org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler}.
* Test fixture for
* {@link org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler}.
*
* @author Rossen Stoyanchev
* @author Brian Clozel
*/
...
...
@@ -56,8 +58,10 @@ public class SimpAnnotationMethodMessageHandlerTests {
@Before
public
void
setup
()
{
SubscribableChannel
channel
=
Mockito
.
mock
(
SubscribableChannel
.
class
);
SimpMessageSendingOperations
brokerTemplate
=
new
SimpMessagingTemplate
(
channel
);
this
.
messageHandler
=
new
TestSimpAnnotationMethodMessageHandler
(
brokerTemplate
,
channel
,
channel
);
this
.
messageHandler
.
setApplicationContext
(
new
StaticApplicationContext
());
this
.
messageHandler
.
setValidator
(
new
StringNotEmptyValidator
());
...
...
@@ -98,8 +102,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
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
();
Message
<?>
message
=
MessageBuilder
.
withPayload
(
new
byte
[
0
]).
copyHeaders
(
headers
.
toMap
()).
build
();
this
.
messageHandler
.
handleMessage
(
message
);
assertEquals
(
"subscribeEventDestinationVariable"
,
this
.
testController
.
method
);
...
...
spring-websocket/src/test/java/org/springframework/web/socket/messaging/S
impAnnotationMethod
IntegrationTests.java
→
spring-websocket/src/test/java/org/springframework/web/socket/messaging/S
tompWebSocket
IntegrationTests.java
浏览文件 @
0db2f79b
...
...
@@ -55,10 +55,11 @@ import static org.springframework.web.socket.messaging.StompTextMessageBuilder.*
/**
* Integration tests with annotated message-handling methods.
*
* @author Rossen Stoyanchev
*/
@RunWith
(
Parameterized
.
class
)
public
class
S
impAnnotationMethod
IntegrationTests
extends
AbstractWebSocketIntegrationTests
{
public
class
S
tompWebSocket
IntegrationTests
extends
AbstractWebSocketIntegrationTests
{
@Parameters
public
static
Iterable
<
Object
[]>
arguments
()
{
...
...
@@ -198,7 +199,7 @@ public class SimpAnnotationMethodIntegrationTests extends AbstractWebSocketInteg
}
@Configuration
@ComponentScan
(
basePackageClasses
=
S
impAnnotationMethod
IntegrationTests
.
class
,
@ComponentScan
(
basePackageClasses
=
S
tompWebSocket
IntegrationTests
.
class
,
useDefaultFilters
=
false
,
includeFilters
=
@ComponentScan
.
Filter
(
IntegrationTestController
.
class
))
static
class
TestMessageBrokerConfigurer
extends
AbstractWebSocketMessageBrokerConfigurer
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录