Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
79ddba5d
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,体验更适合开发者的 AI 搜索 >>
提交
79ddba5d
编写于
9月 02, 2013
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish WebSocket integration tests
上级
fee3148b
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
20 addition
and
391 deletion
+20
-391
spring-messaging/src/test/java/org/springframework/messaging/simp/AbstractWebSocketIntegrationTests.java
...ork/messaging/simp/AbstractWebSocketIntegrationTests.java
+0
-147
spring-messaging/src/test/java/org/springframework/messaging/simp/JettyTestServer.java
...a/org/springframework/messaging/simp/JettyTestServer.java
+0
-74
spring-messaging/src/test/java/org/springframework/messaging/simp/TestServer.java
...t/java/org/springframework/messaging/simp/TestServer.java
+0
-38
spring-messaging/src/test/java/org/springframework/messaging/simp/TomcatTestServer.java
.../org/springframework/messaging/simp/TomcatTestServer.java
+0
-112
spring-messaging/src/test/java/org/springframework/messaging/simp/config/WebSocketMessageBrokerConfigurationTests.java
...simp/config/WebSocketMessageBrokerConfigurationTests.java
+5
-5
spring-websocket/src/test/java/org/springframework/web/socket/AbstractWebSocketIntegrationTests.java
...amework/web/socket/AbstractWebSocketIntegrationTests.java
+3
-3
spring-websocket/src/test/java/org/springframework/web/socket/JettyWebSocketTestServer.java
.../springframework/web/socket/JettyWebSocketTestServer.java
+3
-3
spring-websocket/src/test/java/org/springframework/web/socket/TomcatWebSocketTestServer.java
...springframework/web/socket/TomcatWebSocketTestServer.java
+3
-3
spring-websocket/src/test/java/org/springframework/web/socket/WebSocketTestServer.java
...a/org/springframework/web/socket/WebSocketTestServer.java
+2
-2
spring-websocket/src/test/java/org/springframework/web/socket/server/config/WebSocketConfigurationTests.java
...web/socket/server/config/WebSocketConfigurationTests.java
+4
-4
未找到文件。
spring-messaging/src/test/java/org/springframework/messaging/simp/AbstractWebSocketIntegrationTests.java
已删除
100644 → 0
浏览文件 @
fee3148b
/*
* Copyright 2002-2013 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.messaging.simp
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.runners.Parameterized.Parameter
;
import
org.springframework.context.Lifecycle
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
;
import
org.springframework.web.socket.client.WebSocketClient
;
import
org.springframework.web.socket.server.DefaultHandshakeHandler
;
import
org.springframework.web.socket.server.HandshakeHandler
;
import
org.springframework.web.socket.server.RequestUpgradeStrategy
;
import
org.springframework.web.socket.server.support.JettyRequestUpgradeStrategy
;
import
org.springframework.web.socket.server.support.TomcatRequestUpgradeStrategy
;
import
reactor.util.Assert
;
/**
* Base class for WebSocket integration tests.
*
* @author Rossen Stoyanchev
*/
public
abstract
class
AbstractWebSocketIntegrationTests
{
protected
Log
logger
=
LogFactory
.
getLog
(
getClass
());
private
static
Map
<
Class
<?>,
Class
<?>>
upgradeStrategyConfigTypes
=
new
HashMap
<
Class
<?>,
Class
<?>>();
static
{
upgradeStrategyConfigTypes
.
put
(
JettyTestServer
.
class
,
JettyUpgradeStrategyConfig
.
class
);
upgradeStrategyConfigTypes
.
put
(
TomcatTestServer
.
class
,
TomcatUpgradeStrategyConfig
.
class
);
}
@Parameter
(
0
)
public
TestServer
server
;
@Parameter
(
1
)
public
WebSocketClient
webSocketClient
;
protected
AnnotationConfigWebApplicationContext
wac
;
@Before
public
void
setup
()
throws
Exception
{
Class
<?>
upgradeStrategyConfigClass
=
upgradeStrategyConfigTypes
.
get
(
this
.
server
.
getClass
());
Assert
.
notNull
(
upgradeStrategyConfigClass
,
"No UpgradeStrategyConfig class"
);
this
.
wac
=
new
AnnotationConfigWebApplicationContext
();
this
.
wac
.
register
(
getAnnotatedConfigClasses
());
this
.
wac
.
register
(
upgradeStrategyConfigClass
);
this
.
wac
.
refresh
();
if
(
this
.
webSocketClient
instanceof
Lifecycle
)
{
((
Lifecycle
)
this
.
webSocketClient
).
start
();
}
this
.
server
.
deployConfig
(
this
.
wac
);
this
.
server
.
start
();
}
protected
abstract
Class
<?>[]
getAnnotatedConfigClasses
();
@After
public
void
teardown
()
throws
Exception
{
try
{
if
(
this
.
webSocketClient
instanceof
Lifecycle
)
{
((
Lifecycle
)
this
.
webSocketClient
).
stop
();
}
}
catch
(
Throwable
t
)
{
logger
.
error
(
"Failed to stop WebSocket client"
,
t
);
}
try
{
this
.
server
.
undeployConfig
();
}
catch
(
Throwable
t
)
{
logger
.
error
(
"Failed to undeploy application config"
,
t
);
}
try
{
this
.
server
.
stop
();
}
catch
(
Throwable
t
)
{
logger
.
error
(
"Failed to stop server"
,
t
);
}
}
protected
String
getWsBaseUrl
()
{
return
"ws://localhost:"
+
this
.
server
.
getPort
();
}
static
abstract
class
AbstractRequestUpgradeStrategyConfig
{
@Bean
public
HandshakeHandler
handshakeHandler
()
{
return
new
DefaultHandshakeHandler
(
requestUpgradeStrategy
());
}
public
abstract
RequestUpgradeStrategy
requestUpgradeStrategy
();
}
@Configuration
static
class
JettyUpgradeStrategyConfig
extends
AbstractRequestUpgradeStrategyConfig
{
@Bean
public
RequestUpgradeStrategy
requestUpgradeStrategy
()
{
return
new
JettyRequestUpgradeStrategy
();
}
}
@Configuration
static
class
TomcatUpgradeStrategyConfig
extends
AbstractRequestUpgradeStrategyConfig
{
@Bean
public
RequestUpgradeStrategy
requestUpgradeStrategy
()
{
return
new
TomcatRequestUpgradeStrategy
();
}
}
}
spring-messaging/src/test/java/org/springframework/messaging/simp/JettyTestServer.java
已删除
100644 → 0
浏览文件 @
fee3148b
/*
* Copyright 2002-2013 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.messaging.simp
;
import
org.eclipse.jetty.server.Server
;
import
org.eclipse.jetty.servlet.ServletContextHandler
;
import
org.eclipse.jetty.servlet.ServletHolder
;
import
org.springframework.util.SocketUtils
;
import
org.springframework.web.context.WebApplicationContext
;
import
org.springframework.web.servlet.DispatcherServlet
;
/**
* Jetty based {@link TestServer}.
*
* @author Rossen Stoyanchev
*/
public
class
JettyTestServer
implements
TestServer
{
private
final
Server
jettyServer
;
private
final
int
port
;
public
JettyTestServer
()
{
this
.
port
=
SocketUtils
.
findAvailableTcpPort
();
this
.
jettyServer
=
new
Server
(
this
.
port
);
}
@Override
public
int
getPort
()
{
return
this
.
port
;
}
@Override
public
void
deployConfig
(
WebApplicationContext
cxt
)
{
ServletContextHandler
contextHandler
=
new
ServletContextHandler
();
ServletHolder
servletHolder
=
new
ServletHolder
(
new
DispatcherServlet
(
cxt
));
contextHandler
.
addServlet
(
servletHolder
,
"/"
);
this
.
jettyServer
.
setHandler
(
contextHandler
);
}
@Override
public
void
undeployConfig
()
{
// Stopping jetty will undeploy the servlet
}
@Override
public
void
start
()
throws
Exception
{
this
.
jettyServer
.
start
();
}
@Override
public
void
stop
()
throws
Exception
{
if
(
this
.
jettyServer
.
isRunning
())
{
this
.
jettyServer
.
stop
();
}
}
}
spring-messaging/src/test/java/org/springframework/messaging/simp/TestServer.java
已删除
100644 → 0
浏览文件 @
fee3148b
/*
* Copyright 2002-2013 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.messaging.simp
;
import
org.springframework.web.context.WebApplicationContext
;
/**
* Contract for a test server to use for integration tests.
*
* @author Rossen Stoyanchev
*/
public
interface
TestServer
{
int
getPort
();
void
deployConfig
(
WebApplicationContext
cxt
);
void
undeployConfig
();
void
start
()
throws
Exception
;
void
stop
()
throws
Exception
;
}
\ No newline at end of file
spring-messaging/src/test/java/org/springframework/messaging/simp/TomcatTestServer.java
已删除
100644 → 0
浏览文件 @
fee3148b
/*
* Copyright 2002-2013 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.messaging.simp
;
import
java.io.File
;
import
java.io.IOException
;
import
org.apache.catalina.Context
;
import
org.apache.catalina.connector.Connector
;
import
org.apache.catalina.startup.Tomcat
;
import
org.apache.coyote.http11.Http11NioProtocol
;
import
org.apache.tomcat.util.descriptor.web.ApplicationListener
;
import
org.apache.tomcat.websocket.server.WsListener
;
import
org.springframework.core.NestedRuntimeException
;
import
org.springframework.util.SocketUtils
;
import
org.springframework.web.context.WebApplicationContext
;
import
org.springframework.web.servlet.DispatcherServlet
;
/**
* Tomcat based {@link TestServer}.
*
* @author Rossen Stoyanchev
*/
public
class
TomcatTestServer
implements
TestServer
{
private
static
final
ApplicationListener
WS_APPLICATION_LISTENER
=
new
ApplicationListener
(
WsListener
.
class
.
getName
(),
false
);
private
final
Tomcat
tomcatServer
;
private
final
int
port
;
private
Context
context
;
public
TomcatTestServer
()
{
this
.
port
=
SocketUtils
.
findAvailableTcpPort
();
Connector
connector
=
new
Connector
(
Http11NioProtocol
.
class
.
getName
());
connector
.
setPort
(
this
.
port
);
File
baseDir
=
createTempDir
(
"tomcat"
);
String
baseDirPath
=
baseDir
.
getAbsolutePath
();
this
.
tomcatServer
=
new
Tomcat
();
this
.
tomcatServer
.
setBaseDir
(
baseDirPath
);
this
.
tomcatServer
.
setPort
(
this
.
port
);
this
.
tomcatServer
.
getService
().
addConnector
(
connector
);
this
.
tomcatServer
.
setConnector
(
connector
);
}
private
File
createTempDir
(
String
prefix
)
{
try
{
File
tempFolder
=
File
.
createTempFile
(
prefix
+
"."
,
"."
+
getPort
());
tempFolder
.
delete
();
tempFolder
.
mkdir
();
tempFolder
.
deleteOnExit
();
return
tempFolder
;
}
catch
(
IOException
ex
)
{
throw
new
NestedRuntimeException
(
"Unable to create temp directory"
,
ex
)
{};
}
}
@Override
public
int
getPort
()
{
return
this
.
port
;
}
@Override
public
void
deployConfig
(
WebApplicationContext
wac
)
{
this
.
context
=
this
.
tomcatServer
.
addContext
(
""
,
System
.
getProperty
(
"java.io.tmpdir"
));
this
.
context
.
addApplicationListener
(
WS_APPLICATION_LISTENER
);
Tomcat
.
addServlet
(
context
,
"dispatcherServlet"
,
new
DispatcherServlet
(
wac
));
this
.
context
.
addServletMapping
(
"/"
,
"dispatcherServlet"
);
}
@Override
public
void
undeployConfig
()
{
if
(
this
.
context
!=
null
)
{
this
.
context
.
removeServletMapping
(
"/"
);
this
.
tomcatServer
.
getHost
().
removeChild
(
this
.
context
);
}
}
@Override
public
void
start
()
throws
Exception
{
this
.
tomcatServer
.
start
();
}
@Override
public
void
stop
()
throws
Exception
{
this
.
tomcatServer
.
stop
();
}
}
spring-messaging/src/test/java/org/springframework/messaging/simp/config/WebSocketMessageBrokerConfigurationTests.java
浏览文件 @
79ddba5d
...
...
@@ -29,14 +29,14 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.messaging.SubscribableChannel
;
import
org.springframework.messaging.handler.annotation.MessageMapping
;
import
org.springframework.messaging.simp.AbstractWebSocketIntegrationTests
;
import
org.springframework.messaging.simp.JettyTestServer
;
import
org.springframework.messaging.simp.TomcatTestServer
;
import
org.springframework.messaging.simp.stomp.StompCommand
;
import
org.springframework.messaging.simp.stomp.StompTextMessageBuilder
;
import
org.springframework.messaging.support.channel.ExecutorSubscribableChannel
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.socket.AbstractWebSocketIntegrationTests
;
import
org.springframework.web.socket.JettyWebSocketTestServer
;
import
org.springframework.web.socket.TextMessage
;
import
org.springframework.web.socket.TomcatWebSocketTestServer
;
import
org.springframework.web.socket.WebSocketHandler
;
import
org.springframework.web.socket.WebSocketSession
;
import
org.springframework.web.socket.adapter.TextWebSocketHandlerAdapter
;
...
...
@@ -60,8 +60,8 @@ public class WebSocketMessageBrokerConfigurationTests extends AbstractWebSocketI
@Parameters
public
static
Iterable
<
Object
[]>
arguments
()
{
return
Arrays
.
asList
(
new
Object
[][]
{
{
new
JettyTestServer
(),
new
JettyWebSocketClient
()},
{
new
TomcatTestServer
(),
new
StandardWebSocketClient
()}
{
new
Jetty
WebSocket
TestServer
(),
new
JettyWebSocketClient
()},
{
new
Tomcat
WebSocket
TestServer
(),
new
StandardWebSocketClient
()}
});
};
...
...
spring-websocket/src/test/java/org/springframework/web/socket/AbstractWebSocketIntegrationTests.java
浏览文件 @
79ddba5d
...
...
@@ -47,12 +47,12 @@ public abstract class AbstractWebSocketIntegrationTests {
private
static
Map
<
Class
<?>,
Class
<?>>
upgradeStrategyConfigTypes
=
new
HashMap
<
Class
<?>,
Class
<?>>();
static
{
upgradeStrategyConfigTypes
.
put
(
JettyTestServer
.
class
,
JettyUpgradeStrategyConfig
.
class
);
upgradeStrategyConfigTypes
.
put
(
TomcatTestServer
.
class
,
TomcatUpgradeStrategyConfig
.
class
);
upgradeStrategyConfigTypes
.
put
(
Jetty
WebSocket
TestServer
.
class
,
JettyUpgradeStrategyConfig
.
class
);
upgradeStrategyConfigTypes
.
put
(
Tomcat
WebSocket
TestServer
.
class
,
TomcatUpgradeStrategyConfig
.
class
);
}
@Parameter
(
0
)
public
TestServer
server
;
public
WebSocket
TestServer
server
;
@Parameter
(
1
)
public
WebSocketClient
webSocketClient
;
...
...
spring-websocket/src/test/java/org/springframework/web/socket/JettyTestServer.java
→
spring-websocket/src/test/java/org/springframework/web/socket/Jetty
WebSocket
TestServer.java
浏览文件 @
79ddba5d
...
...
@@ -25,18 +25,18 @@ import org.springframework.web.servlet.DispatcherServlet;
/**
* Jetty based {@link TestServer}.
* Jetty based {@link
WebSocket
TestServer}.
*
* @author Rossen Stoyanchev
*/
public
class
Jetty
TestServer
implements
TestServer
{
public
class
Jetty
WebSocketTestServer
implements
WebSocket
TestServer
{
private
final
Server
jettyServer
;
private
final
int
port
;
public
JettyTestServer
()
{
public
Jetty
WebSocket
TestServer
()
{
this
.
port
=
SocketUtils
.
findAvailableTcpPort
();
this
.
jettyServer
=
new
Server
(
this
.
port
);
}
...
...
spring-websocket/src/test/java/org/springframework/web/socket/TomcatTestServer.java
→
spring-websocket/src/test/java/org/springframework/web/socket/Tomcat
WebSocket
TestServer.java
浏览文件 @
79ddba5d
...
...
@@ -33,11 +33,11 @@ import org.springframework.web.servlet.DispatcherServlet;
/**
* Tomcat based {@link TestServer}.
* Tomcat based {@link
WebSocket
TestServer}.
*
* @author Rossen Stoyanchev
*/
public
class
Tomcat
TestServer
implements
TestServer
{
public
class
Tomcat
WebSocketTestServer
implements
WebSocket
TestServer
{
private
static
final
ApplicationListener
WS_APPLICATION_LISTENER
=
new
ApplicationListener
(
WsListener
.
class
.
getName
(),
false
);
...
...
@@ -49,7 +49,7 @@ public class TomcatTestServer implements TestServer {
private
Context
context
;
public
TomcatTestServer
()
{
public
Tomcat
WebSocket
TestServer
()
{
this
.
port
=
SocketUtils
.
findAvailableTcpPort
();
...
...
spring-websocket/src/test/java/org/springframework/web/socket/TestServer.java
→
spring-websocket/src/test/java/org/springframework/web/socket/
WebSocket
TestServer.java
浏览文件 @
79ddba5d
...
...
@@ -19,11 +19,11 @@ package org.springframework.web.socket;
import
org.springframework.web.context.WebApplicationContext
;
/**
* Contract for a test server to use for integration tests.
* Contract for a test server to use for
WebSocket
integration tests.
*
* @author Rossen Stoyanchev
*/
public
interface
TestServer
{
public
interface
WebSocket
TestServer
{
int
getPort
();
...
...
spring-websocket/src/test/java/org/springframework/web/socket/server/config/WebSocketConfigurationTests.java
浏览文件 @
79ddba5d
...
...
@@ -28,8 +28,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.socket.AbstractWebSocketIntegrationTests
;
import
org.springframework.web.socket.JettyTestServer
;
import
org.springframework.web.socket.TomcatTestServer
;
import
org.springframework.web.socket.Jetty
WebSocket
TestServer
;
import
org.springframework.web.socket.Tomcat
WebSocket
TestServer
;
import
org.springframework.web.socket.WebSocketSession
;
import
org.springframework.web.socket.adapter.WebSocketHandlerAdapter
;
import
org.springframework.web.socket.client.endpoint.StandardWebSocketClient
;
...
...
@@ -51,8 +51,8 @@ public class WebSocketConfigurationTests extends AbstractWebSocketIntegrationTes
@Parameters
public
static
Iterable
<
Object
[]>
arguments
()
{
return
Arrays
.
asList
(
new
Object
[][]
{
{
new
JettyTestServer
(),
new
JettyWebSocketClient
()},
{
new
TomcatTestServer
(),
new
StandardWebSocketClient
()}
{
new
Jetty
WebSocket
TestServer
(),
new
JettyWebSocketClient
()},
{
new
Tomcat
WebSocket
TestServer
(),
new
StandardWebSocketClient
()}
});
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录