Polish WebSocket samples

This commit is contained in:
Phillip Webb
2014-12-03 15:46:52 -08:00
parent 8928012943
commit c22aee9817
42 changed files with 1560 additions and 1533 deletions

View File

@@ -42,12 +42,11 @@ import org.springframework.web.socket.client.standard.StandardWebSocketClient;
import samples.websocket.client.GreetingService;
import samples.websocket.client.SimpleClientWebSocketHandler;
import samples.websocket.client.SimpleGreetingService;
import samples.websocket.config.SampleWebSocketsApplication;
import static org.junit.Assert.assertEquals;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = SampleWebSocketsApplication.class)
@SpringApplicationConfiguration(classes = SampleJettyWebSocketsApplication.class)
@WebAppConfiguration
@IntegrationTest("server.port:0")
@DirtiesContext

View File

@@ -42,16 +42,16 @@ import org.springframework.util.SocketUtils;
import org.springframework.web.socket.client.WebSocketConnectionManager;
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
import samples.websocket.SampleJettyWebSocketsApplication;
import samples.websocket.client.GreetingService;
import samples.websocket.client.SimpleClientWebSocketHandler;
import samples.websocket.client.SimpleGreetingService;
import samples.websocket.config.SampleWebSocketsApplication;
import samples.websocket.echo.CustomContainerWebSocketsApplicationTests.CustomContainerConfiguration;
import static org.junit.Assert.assertEquals;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = { SampleWebSocketsApplication.class,
@SpringApplicationConfiguration(classes = { SampleJettyWebSocketsApplication.class,
CustomContainerConfiguration.class })
@WebAppConfiguration
@IntegrationTest
@@ -63,14 +63,6 @@ public class CustomContainerWebSocketsApplicationTests {
private static int PORT = SocketUtils.findAvailableTcpPort();
@Configuration
protected static class CustomContainerConfiguration {
@Bean
public EmbeddedServletContainerFactory embeddedServletContainerFactory() {
return new JettyEmbeddedServletContainerFactory("/ws", PORT);
}
}
@Test
public void echoEndpoint() throws Exception {
ConfigurableApplicationContext context = new SpringApplicationBuilder(
@@ -99,6 +91,16 @@ public class CustomContainerWebSocketsApplicationTests {
assertEquals("Reversed: !dlrow olleH", messagePayloadReference.get());
}
@Configuration
protected static class CustomContainerConfiguration {
@Bean
public EmbeddedServletContainerFactory embeddedServletContainerFactory() {
return new JettyEmbeddedServletContainerFactory("/ws", PORT);
}
}
@Configuration
static class ClientConfiguration implements CommandLineRunner {
@@ -145,6 +147,7 @@ public class CustomContainerWebSocketsApplicationTests {
public GreetingService greetingService() {
return new SimpleGreetingService();
}
}
}

View File

@@ -37,4 +37,5 @@ public class SnakeTimerTests {
SnakeTimer.broadcast("");
assertThat(SnakeTimer.getSnakes().size(), is(0));
}
}