Polishing
This commit is contained in:
parent
2ac682e125
commit
fe0249bf8f
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -33,13 +33,11 @@ import org.apache.commons.fileupload.FileItemFactory;
|
||||||
import org.apache.commons.fileupload.FileUploadException;
|
import org.apache.commons.fileupload.FileUploadException;
|
||||||
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
||||||
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||||
|
|
||||||
import org.eclipse.jetty.server.Connector;
|
import org.eclipse.jetty.server.Connector;
|
||||||
import org.eclipse.jetty.server.NetworkConnector;
|
import org.eclipse.jetty.server.NetworkConnector;
|
||||||
import org.eclipse.jetty.server.Server;
|
import org.eclipse.jetty.server.Server;
|
||||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||||
import org.eclipse.jetty.servlet.ServletHolder;
|
import org.eclipse.jetty.servlet.ServletHolder;
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
|
||||||
|
@ -56,11 +54,12 @@ public class AbstractJettyServerTestCase {
|
||||||
|
|
||||||
protected static final String helloWorld = "H\u00e9llo W\u00f6rld";
|
protected static final String helloWorld = "H\u00e9llo W\u00f6rld";
|
||||||
|
|
||||||
protected static final MediaType textContentType = new MediaType("text", "plain",
|
protected static final MediaType textContentType =
|
||||||
Collections.singletonMap("charset", "UTF-8"));
|
new MediaType("text", "plain", Collections.singletonMap("charset", "UTF-8"));
|
||||||
|
|
||||||
|
protected static final MediaType jsonContentType =
|
||||||
|
new MediaType("application", "json", Collections.singletonMap("charset", "UTF-8"));
|
||||||
|
|
||||||
protected static final MediaType jsonContentType = new MediaType("application",
|
|
||||||
"json", Collections.singletonMap("charset", "utf-8"));
|
|
||||||
|
|
||||||
private static Server jettyServer;
|
private static Server jettyServer;
|
||||||
|
|
||||||
|
@ -71,7 +70,6 @@ public class AbstractJettyServerTestCase {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void startJettyServer() throws Exception {
|
public static void startJettyServer() throws Exception {
|
||||||
|
|
||||||
// Let server pick its own random, available port.
|
// Let server pick its own random, available port.
|
||||||
jettyServer = new Server(0);
|
jettyServer = new Server(0);
|
||||||
|
|
||||||
|
@ -114,39 +112,41 @@ public class AbstractJettyServerTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Servlet that sets the given status code. */
|
/** Servlet that sets the given status code. */
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
private static class StatusCodeServlet extends GenericServlet {
|
private static class StatusCodeServlet extends GenericServlet {
|
||||||
|
|
||||||
private final int sc;
|
private final int sc;
|
||||||
|
|
||||||
private StatusCodeServlet(int sc) {
|
public StatusCodeServlet(int sc) {
|
||||||
this.sc = sc;
|
this.sc = sc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void service(ServletRequest request, ServletResponse response) throws
|
public void service(ServletRequest request, ServletResponse response) throws IOException {
|
||||||
ServletException, IOException {
|
|
||||||
((HttpServletResponse) response).setStatus(sc);
|
((HttpServletResponse) response).setStatus(sc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Servlet that returns an error message for a given status code. */
|
/** Servlet that returns an error message for a given status code. */
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
private static class ErrorServlet extends GenericServlet {
|
private static class ErrorServlet extends GenericServlet {
|
||||||
|
|
||||||
private final int sc;
|
private final int sc;
|
||||||
|
|
||||||
private ErrorServlet(int sc) {
|
public ErrorServlet(int sc) {
|
||||||
this.sc = sc;
|
this.sc = sc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
|
public void service(ServletRequest request, ServletResponse response) throws IOException {
|
||||||
((HttpServletResponse) response).sendError(sc);
|
((HttpServletResponse) response).sendError(sc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
private static class GetServlet extends HttpServlet {
|
private static class GetServlet extends HttpServlet {
|
||||||
|
|
||||||
|
@ -154,14 +154,13 @@ public class AbstractJettyServerTestCase {
|
||||||
|
|
||||||
private final MediaType contentType;
|
private final MediaType contentType;
|
||||||
|
|
||||||
private GetServlet(byte[] buf, MediaType contentType) {
|
public GetServlet(byte[] buf, MediaType contentType) {
|
||||||
this.buf = buf;
|
this.buf = buf;
|
||||||
this.contentType = contentType;
|
this.contentType = contentType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||||
throws ServletException, IOException {
|
|
||||||
if (contentType != null) {
|
if (contentType != null) {
|
||||||
response.setContentType(contentType.toString());
|
response.setContentType(contentType.toString());
|
||||||
}
|
}
|
||||||
|
@ -170,10 +169,11 @@ public class AbstractJettyServerTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
private static class PostServlet extends HttpServlet {
|
private static class PostServlet extends HttpServlet {
|
||||||
|
|
||||||
private final String s;
|
private final String content;
|
||||||
|
|
||||||
private final String location;
|
private final String location;
|
||||||
|
|
||||||
|
@ -181,20 +181,19 @@ public class AbstractJettyServerTestCase {
|
||||||
|
|
||||||
private final MediaType contentType;
|
private final MediaType contentType;
|
||||||
|
|
||||||
private PostServlet(String s, String location, byte[] buf, MediaType contentType) {
|
public PostServlet(String content, String location, byte[] buf, MediaType contentType) {
|
||||||
this.s = s;
|
this.content = content;
|
||||||
this.location = location;
|
this.location = location;
|
||||||
this.buf = buf;
|
this.buf = buf;
|
||||||
this.contentType = contentType;
|
this.contentType = contentType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doPost(HttpServletRequest request, HttpServletResponse response)
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||||
throws ServletException, IOException {
|
|
||||||
assertTrue("Invalid request content-length", request.getContentLength() > 0);
|
assertTrue("Invalid request content-length", request.getContentLength() > 0);
|
||||||
assertNotNull("No content-type", request.getContentType());
|
assertNotNull("No content-type", request.getContentType());
|
||||||
String body = FileCopyUtils.copyToString(request.getReader());
|
String body = FileCopyUtils.copyToString(request.getReader());
|
||||||
assertEquals("Invalid request body", s, body);
|
assertEquals("Invalid request body", content, body);
|
||||||
response.setStatus(HttpServletResponse.SC_CREATED);
|
response.setStatus(HttpServletResponse.SC_CREATED);
|
||||||
response.setHeader("Location", baseUrl + location);
|
response.setHeader("Location", baseUrl + location);
|
||||||
response.setContentLength(buf.length);
|
response.setContentLength(buf.length);
|
||||||
|
@ -203,6 +202,7 @@ public class AbstractJettyServerTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
private static class JsonPostServlet extends HttpServlet {
|
private static class JsonPostServlet extends HttpServlet {
|
||||||
|
|
||||||
|
@ -210,14 +210,13 @@ public class AbstractJettyServerTestCase {
|
||||||
|
|
||||||
private final MediaType contentType;
|
private final MediaType contentType;
|
||||||
|
|
||||||
private JsonPostServlet(String location, MediaType contentType) {
|
public JsonPostServlet(String location, MediaType contentType) {
|
||||||
this.location = location;
|
this.location = location;
|
||||||
this.contentType = contentType;
|
this.contentType = contentType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doPost(HttpServletRequest request, HttpServletResponse response)
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||||
throws ServletException, IOException {
|
|
||||||
assertTrue("Invalid request content-length", request.getContentLength() > 0);
|
assertTrue("Invalid request content-length", request.getContentLength() > 0);
|
||||||
assertNotNull("No content-type", request.getContentType());
|
assertNotNull("No content-type", request.getContentType());
|
||||||
String body = FileCopyUtils.copyToString(request.getReader());
|
String body = FileCopyUtils.copyToString(request.getReader());
|
||||||
|
@ -230,18 +229,18 @@ public class AbstractJettyServerTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
private static class PutServlet extends HttpServlet {
|
private static class PutServlet extends HttpServlet {
|
||||||
|
|
||||||
private final String s;
|
private final String s;
|
||||||
|
|
||||||
private PutServlet(String s, byte[] buf, MediaType contentType) {
|
public PutServlet(String s, byte[] buf, MediaType contentType) {
|
||||||
this.s = s;
|
this.s = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doPut(HttpServletRequest request, HttpServletResponse response)
|
protected void doPut(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||||
throws ServletException, IOException {
|
|
||||||
assertTrue("Invalid request content-length", request.getContentLength() > 0);
|
assertTrue("Invalid request content-length", request.getContentLength() > 0);
|
||||||
assertNotNull("No content-type", request.getContentType());
|
assertNotNull("No content-type", request.getContentType());
|
||||||
String body = FileCopyUtils.copyToString(request.getReader());
|
String body = FileCopyUtils.copyToString(request.getReader());
|
||||||
|
@ -250,17 +249,19 @@ public class AbstractJettyServerTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
private static class UriServlet extends HttpServlet {
|
private static class UriServlet extends HttpServlet {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||||
resp.setContentType("text/plain");
|
resp.setContentType("text/plain");
|
||||||
resp.setCharacterEncoding("utf-8");
|
resp.setCharacterEncoding("utf-8");
|
||||||
resp.getWriter().write(req.getRequestURI());
|
resp.getWriter().write(req.getRequestURI());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
private static class MultipartServlet extends HttpServlet {
|
private static class MultipartServlet extends HttpServlet {
|
||||||
|
|
||||||
|
@ -300,13 +301,13 @@ public class AbstractJettyServerTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
private static class FormServlet extends HttpServlet {
|
private static class FormServlet extends HttpServlet {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||||
assertEquals(MediaType.APPLICATION_FORM_URLENCODED_VALUE,
|
assertEquals(MediaType.APPLICATION_FORM_URLENCODED_VALUE, req.getContentType());
|
||||||
req.getContentType());
|
|
||||||
|
|
||||||
Map<String, String[]> parameters = req.getParameterMap();
|
Map<String, String[]> parameters = req.getParameterMap();
|
||||||
assertEquals(2, parameters.size());
|
assertEquals(2, parameters.size());
|
||||||
|
@ -322,15 +323,14 @@ public class AbstractJettyServerTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
private static class DeleteServlet extends HttpServlet {
|
private static class DeleteServlet extends HttpServlet {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doDelete(HttpServletRequest req, HttpServletResponse resp)
|
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||||
throws ServletException, IOException {
|
|
||||||
resp.setStatus(200);
|
resp.setStatus(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,21 +59,22 @@ public class WebSocketStompClientTests {
|
||||||
private static final Charset UTF_8 = Charset.forName("UTF-8");
|
private static final Charset UTF_8 = Charset.forName("UTF-8");
|
||||||
|
|
||||||
|
|
||||||
private TestWebSocketStompClient stompClient;
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private TaskScheduler taskScheduler;
|
private TaskScheduler taskScheduler;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private ConnectionHandlingStompSession stompSession;
|
private ConnectionHandlingStompSession stompSession;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private WebSocketSession webSocketSession;
|
||||||
|
|
||||||
|
|
||||||
|
private TestWebSocketStompClient stompClient;
|
||||||
|
|
||||||
private ArgumentCaptor<WebSocketHandler> webSocketHandlerCaptor;
|
private ArgumentCaptor<WebSocketHandler> webSocketHandlerCaptor;
|
||||||
|
|
||||||
private SettableListenableFuture<WebSocketSession> handshakeFuture;
|
private SettableListenableFuture<WebSocketSession> handshakeFuture;
|
||||||
|
|
||||||
@Mock
|
|
||||||
private WebSocketSession webSocketSession;
|
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
@ -123,7 +124,7 @@ public class WebSocketStompClientTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
public void handleWebSocketMessage() throws Exception {
|
public void handleWebSocketMessage() throws Exception {
|
||||||
String text = "SEND\na:alpha\n\nMessage payload\0";
|
String text = "SEND\na:alpha\n\nMessage payload\0";
|
||||||
connect().handleMessage(this.webSocketSession, new TextMessage(text));
|
connect().handleMessage(this.webSocketSession, new TextMessage(text));
|
||||||
|
@ -141,7 +142,7 @@ public class WebSocketStompClientTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
public void handleWebSocketMessageSplitAcrossTwoMessage() throws Exception {
|
public void handleWebSocketMessageSplitAcrossTwoMessage() throws Exception {
|
||||||
WebSocketHandler webSocketHandler = connect();
|
WebSocketHandler webSocketHandler = connect();
|
||||||
|
|
||||||
|
@ -166,7 +167,7 @@ public class WebSocketStompClientTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
public void handleWebSocketMessageBinary() throws Exception {
|
public void handleWebSocketMessageBinary() throws Exception {
|
||||||
String text = "SEND\na:alpha\n\nMessage payload\0";
|
String text = "SEND\na:alpha\n\nMessage payload\0";
|
||||||
connect().handleMessage(this.webSocketSession, new BinaryMessage(text.getBytes(UTF_8)));
|
connect().handleMessage(this.webSocketSession, new BinaryMessage(text.getBytes(UTF_8)));
|
||||||
|
@ -249,7 +250,7 @@ public class WebSocketStompClientTests {
|
||||||
fail("Expected IllegalStateException");
|
fail("Expected IllegalStateException");
|
||||||
}
|
}
|
||||||
catch (IllegalStateException ex) {
|
catch (IllegalStateException ex) {
|
||||||
// Ignore
|
// ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,7 +291,7 @@ public class WebSocketStompClientTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||||
public void cancelInactivityTasks() throws Exception {
|
public void cancelInactivityTasks() throws Exception {
|
||||||
TcpConnection<byte[]> tcpConnection = getTcpConnection();
|
TcpConnection<byte[]> tcpConnection = getTcpConnection();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue