|
|
@ -13,6 +13,7 @@ |
|
|
|
* See the License for the specific language governing permissions and |
|
|
|
* See the License for the specific language governing permissions and |
|
|
|
* limitations under the License. |
|
|
|
* limitations under the License. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.web.socket.server.support; |
|
|
|
package org.springframework.web.socket.server.support; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
@ -20,7 +21,6 @@ import java.util.Collections; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
import javax.servlet.ServletException; |
|
|
|
import javax.servlet.ServletException; |
|
|
|
|
|
|
|
|
|
|
|
import org.junit.Before; |
|
|
|
|
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.http.server.ServerHttpRequest; |
|
|
|
import org.springframework.http.server.ServerHttpRequest; |
|
|
@ -42,24 +42,17 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Unit tests for {@link WebSocketHttpRequestHandler}. |
|
|
|
* Unit tests for {@link WebSocketHttpRequestHandler}. |
|
|
|
|
|
|
|
* |
|
|
|
* @author Rossen Stoyanchev |
|
|
|
* @author Rossen Stoyanchev |
|
|
|
* @since 5.1.9 |
|
|
|
* @since 5.1.9 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class WebSocketHttpRequestHandlerTests { |
|
|
|
public class WebSocketHttpRequestHandlerTests { |
|
|
|
|
|
|
|
|
|
|
|
private HandshakeHandler handshakeHandler; |
|
|
|
private final HandshakeHandler handshakeHandler = mock(HandshakeHandler.class); |
|
|
|
|
|
|
|
|
|
|
|
private WebSocketHttpRequestHandler requestHandler; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private MockHttpServletResponse response; |
|
|
|
private final WebSocketHttpRequestHandler requestHandler = new WebSocketHttpRequestHandler(mock(WebSocketHandler.class), this.handshakeHandler); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final MockHttpServletResponse response = new MockHttpServletResponse(); |
|
|
|
@Before |
|
|
|
|
|
|
|
public void setUp() { |
|
|
|
|
|
|
|
this.handshakeHandler = mock(HandshakeHandler.class); |
|
|
|
|
|
|
|
this.requestHandler = new WebSocketHttpRequestHandler(mock(WebSocketHandler.class), this.handshakeHandler); |
|
|
|
|
|
|
|
this.response = new MockHttpServletResponse(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -105,19 +98,11 @@ public class WebSocketHttpRequestHandlerTests { |
|
|
|
|
|
|
|
|
|
|
|
private final boolean allowHandshake; |
|
|
|
private final boolean allowHandshake; |
|
|
|
|
|
|
|
|
|
|
|
private Exception exception; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private TestInterceptor(boolean allowHandshake) { |
|
|
|
private TestInterceptor(boolean allowHandshake) { |
|
|
|
this.allowHandshake = allowHandshake; |
|
|
|
this.allowHandshake = allowHandshake; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Exception getException() { |
|
|
|
|
|
|
|
return this.exception; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, |
|
|
|
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, |
|
|
|
WebSocketHandler wsHandler, Map<String, Object> attributes) { |
|
|
|
WebSocketHandler wsHandler, Map<String, Object> attributes) { |
|
|
@ -131,7 +116,6 @@ public class WebSocketHttpRequestHandlerTests { |
|
|
|
WebSocketHandler wsHandler, Exception exception) { |
|
|
|
WebSocketHandler wsHandler, Exception exception) { |
|
|
|
|
|
|
|
|
|
|
|
response.getHeaders().add("exceptionHeaderName", "exceptionHeaderValue"); |
|
|
|
response.getHeaders().add("exceptionHeaderName", "exceptionHeaderValue"); |
|
|
|
this.exception = exception; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|