Fix bug in WebSocketClient implementations

This commit is contained in:
Rossen Stoyanchev
2013-05-16 19:12:27 -04:00
parent fb4e34fce4
commit 87a9602f65
6 changed files with 42 additions and 45 deletions

View File

@@ -27,7 +27,6 @@ import org.springframework.http.HttpHeaders;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.adapter.WebSocketHandlerAdapter;
import org.springframework.web.socket.support.ExceptionWebSocketHandlerDecorator;
import org.springframework.web.socket.support.LoggingWebSocketHandlerDecorator;
import org.springframework.web.socket.support.WebSocketHandlerDecorator;
@@ -69,11 +68,7 @@ public class WebSocketConnectionManagerTests {
WebSocketHandlerDecorator loggingHandler = captor.getValue();
assertEquals(LoggingWebSocketHandlerDecorator.class, loggingHandler.getClass());
WebSocketHandlerDecorator exceptionHandler = (WebSocketHandlerDecorator) loggingHandler.getDelegate();
assertNotNull(exceptionHandler);
assertEquals(ExceptionWebSocketHandlerDecorator.class, exceptionHandler.getClass());
assertSame(handler, exceptionHandler.getDelegate());
assertSame(handler, loggingHandler.getDelegate());
}
@Test

View File

@@ -34,7 +34,6 @@ import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.adapter.StandardEndpointAdapter;
import org.springframework.web.socket.adapter.WebSocketHandlerAdapter;
import org.springframework.web.socket.client.endpoint.StandardWebSocketClient;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
@@ -60,18 +59,15 @@ public class StandardWebSocketClientTests {
WebSocketHandler handler = new WebSocketHandlerAdapter();
WebSocketContainer webSocketContainer = mock(WebSocketContainer.class);
StandardWebSocketClient client = new StandardWebSocketClient();
client.setWebSocketContainer(webSocketContainer);
StandardWebSocketClient client = new StandardWebSocketClient(webSocketContainer);
WebSocketSession session = client.doHandshake(handler, headers, uri);
ArgumentCaptor<Endpoint> endpointArg = ArgumentCaptor.forClass(Endpoint.class);
ArgumentCaptor<ClientEndpointConfig> configArg = ArgumentCaptor.forClass(ClientEndpointConfig.class);
ArgumentCaptor<URI> uriArg = ArgumentCaptor.forClass(URI.class);
verify(webSocketContainer).connectToServer(endpointArg.capture(), configArg.capture(), uriArg.capture());
assertNotNull(endpointArg.getValue());
assertEquals(StandardEndpointAdapter.class, endpointArg.getValue().getClass());
@@ -86,4 +82,5 @@ public class StandardWebSocketClientTests {
assertEquals(uri, session.getUri());
assertEquals("example.com", session.getRemoteHostName());
}
}