Merge branch 'master' into websocket-stomp

This commit is contained in:
Rossen Stoyanchev
2013-06-27 15:58:12 -04:00
307 changed files with 8375 additions and 4414 deletions

View File

@@ -24,7 +24,6 @@ import org.springframework.http.server.ServletServerHttpResponse;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse;
/**
* @author Rossen Stoyanchev
*/

View File

@@ -24,7 +24,6 @@ import org.springframework.web.socket.WebSocketHandler;
import static org.mockito.Mockito.*;
/**
* Test fixture for {@link JettyWebSocketListenerAdapter}.
*

View File

@@ -30,7 +30,6 @@ import static org.junit.Assert.*;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*;
/**
* Test fixture for {@link StandardEndpointAdapter}.
*
@@ -52,30 +51,30 @@ public class StandardEndpointAdapterTests {
this.session = mock(Session.class);
this.webSocketHandler = mock(WebSocketHandler.class);
this.webSocketSession = new StandardWebSocketSessionAdapter();
this.adapter = new StandardEndpointAdapter(webSocketHandler, webSocketSession);
this.adapter = new StandardEndpointAdapter(this.webSocketHandler, this.webSocketSession);
}
@Test
public void onOpen() throws Throwable {
this.adapter.onOpen(session, null);
this.adapter.onOpen(this.session, null);
verify(this.webSocketHandler).afterConnectionEstablished(this.webSocketSession);
verify(session, atLeast(2)).addMessageHandler(any(MessageHandler.Whole.class));
verify(this.session, atLeast(2)).addMessageHandler(any(MessageHandler.Whole.class));
when(session.getId()).thenReturn("123");
when(this.session.getId()).thenReturn("123");
assertEquals("123", this.webSocketSession.getId());
}
@Test
public void onClose() throws Throwable {
this.adapter.onClose(session, new CloseReason(CloseCodes.NORMAL_CLOSURE, "reason"));
this.adapter.onClose(this.session, new CloseReason(CloseCodes.NORMAL_CLOSURE, "reason"));
verify(this.webSocketHandler).afterConnectionClosed(this.webSocketSession, CloseStatus.NORMAL.withReason("reason"));
}
@Test
public void onError() throws Throwable {
Exception exception = new Exception();
this.adapter.onError(session, exception);
this.adapter.onError(this.session, exception);
verify(this.webSocketHandler).handleTransportError(this.webSocketSession, exception);
}

View File

@@ -33,7 +33,6 @@ import org.springframework.web.socket.support.WebSocketHandlerDecorator;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
/**
* Test fixture for {@link WebSocketConnectionManager}.
*
@@ -41,7 +40,6 @@ import static org.mockito.Mockito.*;
*/
public class WebSocketConnectionManagerTests {
@Test
public void openConnection() throws Exception {

View File

@@ -38,7 +38,6 @@ import org.springframework.web.socket.adapter.WebSocketHandlerAdapter;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
/**
* Test fixture for {@link StandardWebSocketClient}.
*
@@ -46,7 +45,6 @@ import static org.mockito.Mockito.*;
*/
public class StandardWebSocketClientTests {
@Test
public void doHandshake() throws Exception {

View File

@@ -31,7 +31,6 @@ import org.springframework.web.context.support.AnnotationConfigWebApplicationCon
import static org.mockito.Mockito.*;
/**
* Test fixture for {@link ServerEndpointExporter}.
*
@@ -51,7 +50,7 @@ public class ServerEndpointExporterTests {
this.serverContainer = mock(ServerContainer.class);
MockServletContext servletContext = new MockServletContext();
servletContext.setAttribute("javax.websocket.server.ServerContainer", serverContainer);
servletContext.setAttribute("javax.websocket.server.ServerContainer", this.serverContainer);
this.webAppContext = new AnnotationConfigWebApplicationContext();
this.webAppContext.register(Config.class);

View File

@@ -29,7 +29,6 @@ import org.springframework.context.annotation.Configuration;
import static org.junit.Assert.*;
/**
* Test fixture for {@link ServerEndpointRegistration}.
*

View File

@@ -32,10 +32,8 @@ import org.springframework.web.context.support.AnnotationConfigWebApplicationCon
import static org.junit.Assert.*;
public class SpringConfiguratorTests {
private MockServletContext servletContext;
private ContextLoader contextLoader;
@@ -50,7 +48,7 @@ public class SpringConfiguratorTests {
this.webAppContext = new AnnotationConfigWebApplicationContext();
this.webAppContext.register(Config.class);
this.contextLoader = new ContextLoader(webAppContext);
this.contextLoader = new ContextLoader(this.webAppContext);
this.contextLoader.initWebApplicationContext(this.servletContext);
}

View File

@@ -180,7 +180,7 @@ public class AbstractSockJsServiceTests extends AbstractHttpRequestTests {
assertTrue(this.servletResponse.getContentAsString().startsWith("<!DOCTYPE html>\n"));
assertEquals(496, this.servletResponse.getContentLength());
assertEquals("public, max-age=31536000", this.response.getHeaders().getCacheControl());
assertEquals("\"0da1ed070012f304e47b83c81c48ad620\"", response.getHeaders().getETag());
assertEquals("\"0da1ed070012f304e47b83c81c48ad620\"", this.response.getHeaders().getETag());
}
@Test

View File

@@ -29,7 +29,6 @@ import static org.junit.Assert.*;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*;
/**
* Test fixture for {@link AbstractSockJsSession}.
*

View File

@@ -23,7 +23,6 @@ import org.springframework.web.socket.WebSocketHandler;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
/**
* Base class for {@link AbstractSockJsSession} classes.
*

View File

@@ -19,7 +19,6 @@ package org.springframework.web.socket.sockjs;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
/**
* @author Rossen Stoyanchev
*/
@@ -34,7 +33,7 @@ public class StubSockJsConfig implements SockJsConfiguration {
@Override
public int getStreamBytesLimit() {
return streamBytesLimit;
return this.streamBytesLimit;
}
public void setStreamBytesLimit(int streamBytesLimit) {
@@ -43,7 +42,7 @@ public class StubSockJsConfig implements SockJsConfiguration {
@Override
public long getHeartbeatTime() {
return heartbeatTime;
return this.heartbeatTime;
}
public void setHeartbeatTime(long heartbeatTime) {
@@ -52,7 +51,7 @@ public class StubSockJsConfig implements SockJsConfiguration {
@Override
public TaskScheduler getTaskScheduler() {
return taskScheduler;
return this.taskScheduler;
}
public void setTaskScheduler(TaskScheduler taskScheduler) {

View File

@@ -23,7 +23,6 @@ import java.util.List;
import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.WebSocketHandler;
/**
* @author Rossen Stoyanchev
*/
@@ -95,7 +94,7 @@ public class TestSockJsSession extends AbstractSockJsSession {
protected void writeFrameInternal(SockJsFrame frame) throws Exception {
this.sockJsFramesWritten.add(frame);
if (this.exceptionOnWriteFrame != null) {
throw exceptionOnWriteFrame;
throw this.exceptionOnWriteFrame;
}
}

View File

@@ -20,13 +20,11 @@ import org.junit.Test;
import static org.junit.Assert.*;
/**
* @author Rossen Stoyanchev
*/
public class TransportTypeTests {
@Test
public void testFromValue() {
assertEquals(TransportType.WEBSOCKET, TransportType.fromValue("websocket"));

View File

@@ -48,7 +48,6 @@ import static org.mockito.Mockito.*;
*/
public class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
@Override
@Before
public void setUp() {

View File

@@ -62,24 +62,24 @@ public class HttpSendingTransportHandlerTests extends AbstractHttpRequestTests
public void handleRequestXhr() throws Exception {
XhrPollingTransportHandler transportHandler = new XhrPollingTransportHandler();
transportHandler.setSockJsConfiguration(sockJsConfig);
transportHandler.setSockJsConfiguration(this.sockJsConfig);
AbstractSockJsSession session = transportHandler.createSession("1", webSocketHandler);
transportHandler.handleRequest(request, response, webSocketHandler, session);
AbstractSockJsSession session = transportHandler.createSession("1", this.webSocketHandler);
transportHandler.handleRequest(this.request, this.response, this.webSocketHandler, session);
assertEquals("application/javascript;charset=UTF-8", this.response.getHeaders().getContentType().toString());
assertEquals("o\n", this.servletResponse.getContentAsString());
assertFalse("Polling request should complete after open frame", this.servletRequest.isAsyncStarted());
verify(webSocketHandler).afterConnectionEstablished(session);
verify(this.webSocketHandler).afterConnectionEstablished(session);
resetResponse();
transportHandler.handleRequest(request, response, webSocketHandler, session);
transportHandler.handleRequest(this.request, this.response, this.webSocketHandler, session);
assertTrue("Polling request should remain open", this.servletRequest.isAsyncStarted());
verify(this.taskScheduler).schedule(any(Runnable.class), any(Date.class));
resetRequestAndResponse();
transportHandler.handleRequest(request, response, webSocketHandler, session);
transportHandler.handleRequest(this.request, this.response, this.webSocketHandler, session);
assertFalse("Request should have been rejected", this.servletRequest.isAsyncStarted());
assertEquals("c[2010,\"Another connection still open\"]\n", this.servletResponse.getContentAsString());
@@ -89,70 +89,70 @@ public class HttpSendingTransportHandlerTests extends AbstractHttpRequestTests
public void jsonpTransport() throws Exception {
JsonpPollingTransportHandler transportHandler = new JsonpPollingTransportHandler();
transportHandler.setSockJsConfiguration(sockJsConfig);
PollingSockJsSession session = transportHandler.createSession("1", webSocketHandler);
transportHandler.setSockJsConfiguration(this.sockJsConfig);
PollingSockJsSession session = transportHandler.createSession("1", this.webSocketHandler);
transportHandler.handleRequest(request, response, webSocketHandler, session);
transportHandler.handleRequest(this.request, this.response, this.webSocketHandler, session);
assertEquals(500, this.servletResponse.getStatus());
assertEquals("\"callback\" parameter required", this.servletResponse.getContentAsString());
resetRequestAndResponse();
this.servletRequest.addParameter("c", "callback");
transportHandler.handleRequest(request, response, webSocketHandler, session);
transportHandler.handleRequest(this.request, this.response, this.webSocketHandler, session);
assertEquals("application/javascript;charset=UTF-8", this.response.getHeaders().getContentType().toString());
assertFalse("Polling request should complete after open frame", this.servletRequest.isAsyncStarted());
verify(webSocketHandler).afterConnectionEstablished(session);
verify(this.webSocketHandler).afterConnectionEstablished(session);
}
@Test
public void handleRequestXhrStreaming() throws Exception {
XhrStreamingTransportHandler transportHandler = new XhrStreamingTransportHandler();
transportHandler.setSockJsConfiguration(sockJsConfig);
AbstractSockJsSession session = transportHandler.createSession("1", webSocketHandler);
transportHandler.setSockJsConfiguration(this.sockJsConfig);
AbstractSockJsSession session = transportHandler.createSession("1", this.webSocketHandler);
transportHandler.handleRequest(request, response, webSocketHandler, session);
transportHandler.handleRequest(this.request, this.response, this.webSocketHandler, session);
assertEquals("application/javascript;charset=UTF-8", this.response.getHeaders().getContentType().toString());
assertTrue("Streaming request not started", this.servletRequest.isAsyncStarted());
verify(webSocketHandler).afterConnectionEstablished(session);
verify(this.webSocketHandler).afterConnectionEstablished(session);
}
@Test
public void htmlFileTransport() throws Exception {
HtmlFileTransportHandler transportHandler = new HtmlFileTransportHandler();
transportHandler.setSockJsConfiguration(sockJsConfig);
StreamingSockJsSession session = transportHandler.createSession("1", webSocketHandler);
transportHandler.setSockJsConfiguration(this.sockJsConfig);
StreamingSockJsSession session = transportHandler.createSession("1", this.webSocketHandler);
transportHandler.handleRequest(request, response, webSocketHandler, session);
transportHandler.handleRequest(this.request, this.response, this.webSocketHandler, session);
assertEquals(500, this.servletResponse.getStatus());
assertEquals("\"callback\" parameter required", this.servletResponse.getContentAsString());
resetRequestAndResponse();
this.servletRequest.addParameter("c", "callback");
transportHandler.handleRequest(request, response, webSocketHandler, session);
transportHandler.handleRequest(this.request, this.response, this.webSocketHandler, session);
assertEquals("text/html;charset=UTF-8", this.response.getHeaders().getContentType().toString());
assertTrue("Streaming request not started", this.servletRequest.isAsyncStarted());
verify(webSocketHandler).afterConnectionEstablished(session);
verify(this.webSocketHandler).afterConnectionEstablished(session);
}
@Test
public void eventSourceTransport() throws Exception {
EventSourceTransportHandler transportHandler = new EventSourceTransportHandler();
transportHandler.setSockJsConfiguration(sockJsConfig);
StreamingSockJsSession session = transportHandler.createSession("1", webSocketHandler);
transportHandler.setSockJsConfiguration(this.sockJsConfig);
StreamingSockJsSession session = transportHandler.createSession("1", this.webSocketHandler);
transportHandler.handleRequest(request, response, webSocketHandler, session);
transportHandler.handleRequest(this.request, this.response, this.webSocketHandler, session);
assertEquals("text/event-stream;charset=UTF-8", this.response.getHeaders().getContentType().toString());
assertTrue("Streaming request not started", this.servletRequest.isAsyncStarted());
verify(webSocketHandler).afterConnectionEstablished(session);
verify(this.webSocketHandler).afterConnectionEstablished(session);
}
@Test
@@ -162,23 +162,23 @@ public class HttpSendingTransportHandlerTests extends AbstractHttpRequestTests
SockJsFrame frame = SockJsFrame.openFrame();
FrameFormat format = new XhrPollingTransportHandler().getFrameFormat(request);
FrameFormat format = new XhrPollingTransportHandler().getFrameFormat(this.request);
SockJsFrame formatted = format.format(frame);
assertEquals(frame.getContent() + "\n", formatted.getContent());
format = new XhrStreamingTransportHandler().getFrameFormat(request);
format = new XhrStreamingTransportHandler().getFrameFormat(this.request);
formatted = format.format(frame);
assertEquals(frame.getContent() + "\n", formatted.getContent());
format = new HtmlFileTransportHandler().getFrameFormat(request);
format = new HtmlFileTransportHandler().getFrameFormat(this.request);
formatted = format.format(frame);
assertEquals("<script>\np(\"" + frame.getContent() + "\");\n</script>\r\n", formatted.getContent());
format = new EventSourceTransportHandler().getFrameFormat(request);
format = new EventSourceTransportHandler().getFrameFormat(this.request);
formatted = format.format(frame);
assertEquals("data: " + frame.getContent() + "\r\n\r\n", formatted.getContent());
format = new JsonpPollingTransportHandler().getFrameFormat(request);
format = new JsonpPollingTransportHandler().getFrameFormat(this.request);
formatted = format.format(frame);
assertEquals("callback(\"" + frame.getContent() + "\");\r\n", formatted.getContent());
}

View File

@@ -36,7 +36,6 @@ import static org.junit.Assert.*;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*;
/**
* Test fixture for {@link WebSocketServerSockJsSession}.
*

View File

@@ -26,8 +26,6 @@ import org.springframework.context.annotation.Configuration;
import static org.junit.Assert.*;
/**
* Test fixture for {@link BeanCreatingHandlerProvider}.
*

View File

@@ -26,7 +26,6 @@ import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.WebSocketMessage;
import org.springframework.web.socket.WebSocketSession;
/**
* A {@link WebSocketSession} for use in tests.
*
@@ -58,7 +57,7 @@ public class TestWebSocketSession implements WebSocketSession {
*/
@Override
public String getId() {
return id;
return this.id;
}
/**
@@ -73,7 +72,7 @@ public class TestWebSocketSession implements WebSocketSession {
*/
@Override
public URI getUri() {
return uri;
return this.uri;
}
/**
@@ -88,7 +87,7 @@ public class TestWebSocketSession implements WebSocketSession {
*/
@Override
public boolean isSecure() {
return secure;
return this.secure;
}
/**
@@ -103,7 +102,7 @@ public class TestWebSocketSession implements WebSocketSession {
*/
@Override
public Principal getPrincipal() {
return principal;
return this.principal;
}
/**
@@ -118,7 +117,7 @@ public class TestWebSocketSession implements WebSocketSession {
*/
@Override
public String getRemoteHostName() {
return remoteHostName;
return this.remoteHostName;
}
/**
@@ -133,7 +132,7 @@ public class TestWebSocketSession implements WebSocketSession {
*/
@Override
public String getRemoteAddress() {
return remoteAddress;
return this.remoteAddress;
}
/**
@@ -148,7 +147,7 @@ public class TestWebSocketSession implements WebSocketSession {
*/
@Override
public boolean isOpen() {
return open;
return this.open;
}
/**

View File

@@ -0,0 +1,41 @@
/*
* 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.web.socket.support;
import org.junit.Test;
import org.springframework.web.socket.adapter.WebSocketHandlerAdapter;
import static org.junit.Assert.*;
/**
* Test fixture for {@link WebSocketHandlerDecorator}.
*
* @author Rossen Stoyanchev
*/
public class WebSocketHandlerDecoratorTests {
@Test
public void getLastHandler() {
WebSocketHandlerAdapter h1 = new WebSocketHandlerAdapter();
WebSocketHandlerDecorator h2 = new WebSocketHandlerDecorator(h1);
WebSocketHandlerDecorator h3 = new WebSocketHandlerDecorator(h2);
assertSame(h1, h3.getLastHandler());
}
}