diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/AbstractWebSocketIntegrationTests.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/AbstractWebSocketIntegrationTests.java deleted file mode 100644 index 07e3551219a66fa0d5d44f7b45c3ab79124ced18..0000000000000000000000000000000000000000 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/AbstractWebSocketIntegrationTests.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * 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> upgradeStrategyConfigTypes = new HashMap, 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(); - } - } - -} diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/JettyTestServer.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/JettyTestServer.java deleted file mode 100644 index 9d28c8f3a3dd65ee38e42f29f581471c9d981892..0000000000000000000000000000000000000000 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/JettyTestServer.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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(); - } - } - -} diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/TestServer.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/TestServer.java deleted file mode 100644 index a366849f17dabe52d8a43c6299297d370344f9b3..0000000000000000000000000000000000000000 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/TestServer.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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 diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/TomcatTestServer.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/TomcatTestServer.java deleted file mode 100644 index 2144fa039b1b7461ea19b12ac09512cd70175ee9..0000000000000000000000000000000000000000 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/TomcatTestServer.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * 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(); - } - -} diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/config/WebSocketMessageBrokerConfigurationTests.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/config/WebSocketMessageBrokerConfigurationTests.java index fc10dae77965b6384474527ce94babddc07af6c2..a2e2f530d8e887956933878098856f0efd6f2057 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/config/WebSocketMessageBrokerConfigurationTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/simp/config/WebSocketMessageBrokerConfigurationTests.java @@ -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 arguments() { return Arrays.asList(new Object[][] { - {new JettyTestServer(), new JettyWebSocketClient()}, - {new TomcatTestServer(), new StandardWebSocketClient()} + {new JettyWebSocketTestServer(), new JettyWebSocketClient()}, + {new TomcatWebSocketTestServer(), new StandardWebSocketClient()} }); }; diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/AbstractWebSocketIntegrationTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/AbstractWebSocketIntegrationTests.java index 7ce356184571a5a8c607984291824676c8e92438..3a068f827133eaf5b48f2fceb5eac463c1c058dd 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/AbstractWebSocketIntegrationTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/AbstractWebSocketIntegrationTests.java @@ -47,12 +47,12 @@ public abstract class AbstractWebSocketIntegrationTests { private static Map, Class> upgradeStrategyConfigTypes = new HashMap, Class>(); static { - upgradeStrategyConfigTypes.put(JettyTestServer.class, JettyUpgradeStrategyConfig.class); - upgradeStrategyConfigTypes.put(TomcatTestServer.class, TomcatUpgradeStrategyConfig.class); + upgradeStrategyConfigTypes.put(JettyWebSocketTestServer.class, JettyUpgradeStrategyConfig.class); + upgradeStrategyConfigTypes.put(TomcatWebSocketTestServer.class, TomcatUpgradeStrategyConfig.class); } @Parameter(0) - public TestServer server; + public WebSocketTestServer server; @Parameter(1) public WebSocketClient webSocketClient; diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/JettyTestServer.java b/spring-websocket/src/test/java/org/springframework/web/socket/JettyWebSocketTestServer.java similarity index 92% rename from spring-websocket/src/test/java/org/springframework/web/socket/JettyTestServer.java rename to spring-websocket/src/test/java/org/springframework/web/socket/JettyWebSocketTestServer.java index 5854db8eac32a471e405a71b39b405a0c5fbcc4a..bfbe8e1333efb61d3cb756a8aeec00a2e81028bd 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/JettyTestServer.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/JettyWebSocketTestServer.java @@ -25,18 +25,18 @@ import org.springframework.web.servlet.DispatcherServlet; /** - * Jetty based {@link TestServer}. + * Jetty based {@link WebSocketTestServer}. * * @author Rossen Stoyanchev */ -public class JettyTestServer implements TestServer { +public class JettyWebSocketTestServer implements WebSocketTestServer { private final Server jettyServer; private final int port; - public JettyTestServer() { + public JettyWebSocketTestServer() { this.port = SocketUtils.findAvailableTcpPort(); this.jettyServer = new Server(this.port); } diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/TomcatTestServer.java b/spring-websocket/src/test/java/org/springframework/web/socket/TomcatWebSocketTestServer.java similarity index 95% rename from spring-websocket/src/test/java/org/springframework/web/socket/TomcatTestServer.java rename to spring-websocket/src/test/java/org/springframework/web/socket/TomcatWebSocketTestServer.java index 62a8fab66cc28880e3fbe0ad116b0f52c53fadef..dcd41b39704fffcfba0178d3eec0de0b30eedac5 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/TomcatTestServer.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/TomcatWebSocketTestServer.java @@ -33,11 +33,11 @@ import org.springframework.web.servlet.DispatcherServlet; /** - * Tomcat based {@link TestServer}. + * Tomcat based {@link WebSocketTestServer}. * * @author Rossen Stoyanchev */ -public class TomcatTestServer implements TestServer { +public class TomcatWebSocketTestServer implements WebSocketTestServer { 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 TomcatWebSocketTestServer() { this.port = SocketUtils.findAvailableTcpPort(); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/TestServer.java b/spring-websocket/src/test/java/org/springframework/web/socket/WebSocketTestServer.java similarity index 89% rename from spring-websocket/src/test/java/org/springframework/web/socket/TestServer.java rename to spring-websocket/src/test/java/org/springframework/web/socket/WebSocketTestServer.java index ae2e6d378a58add73854fd69a1f1656be1d93e1b..0de0efa81c5f9d96ed21bf193818ed15b5e677f5 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/TestServer.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/WebSocketTestServer.java @@ -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 WebSocketTestServer { int getPort(); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/server/config/WebSocketConfigurationTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/server/config/WebSocketConfigurationTests.java index 0a736193955bca8242291fcae964bf83717678f3..62c40f01a0e07eb311500defb066034ef8b1e3cd 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/server/config/WebSocketConfigurationTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/server/config/WebSocketConfigurationTests.java @@ -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.JettyWebSocketTestServer; +import org.springframework.web.socket.TomcatWebSocketTestServer; 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 arguments() { return Arrays.asList(new Object[][] { - {new JettyTestServer(), new JettyWebSocketClient()}, - {new TomcatTestServer(), new StandardWebSocketClient()} + {new JettyWebSocketTestServer(), new JettyWebSocketClient()}, + {new TomcatWebSocketTestServer(), new StandardWebSocketClient()} }); };