Polishing

This commit is contained in:
Juergen Hoeller 2016-11-04 13:37:06 +01:00
parent 2ac682e125
commit fe0249bf8f
2 changed files with 46 additions and 45 deletions

View File

@ -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");
* 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.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.NetworkConnector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@ -56,11 +54,12 @@ public class AbstractJettyServerTestCase {
protected static final String helloWorld = "H\u00e9llo W\u00f6rld";
protected static final MediaType textContentType = new MediaType("text", "plain",
Collections.singletonMap("charset", "UTF-8"));
protected static final MediaType textContentType =
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;
@ -71,7 +70,6 @@ public class AbstractJettyServerTestCase {
@BeforeClass
public static void startJettyServer() throws Exception {
// Let server pick its own random, available port.
jettyServer = new Server(0);
@ -114,39 +112,41 @@ public class AbstractJettyServerTestCase {
}
}
/** Servlet that sets the given status code. */
@SuppressWarnings("serial")
private static class StatusCodeServlet extends GenericServlet {
private final int sc;
private StatusCodeServlet(int sc) {
public StatusCodeServlet(int sc) {
this.sc = sc;
}
@Override
public void service(ServletRequest request, ServletResponse response) throws
ServletException, IOException {
public void service(ServletRequest request, ServletResponse response) throws IOException {
((HttpServletResponse) response).setStatus(sc);
}
}
/** Servlet that returns an error message for a given status code. */
@SuppressWarnings("serial")
private static class ErrorServlet extends GenericServlet {
private final int sc;
private ErrorServlet(int sc) {
public ErrorServlet(int sc) {
this.sc = sc;
}
@Override
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
public void service(ServletRequest request, ServletResponse response) throws IOException {
((HttpServletResponse) response).sendError(sc);
}
}
@SuppressWarnings("serial")
private static class GetServlet extends HttpServlet {
@ -154,14 +154,13 @@ public class AbstractJettyServerTestCase {
private final MediaType contentType;
private GetServlet(byte[] buf, MediaType contentType) {
public GetServlet(byte[] buf, MediaType contentType) {
this.buf = buf;
this.contentType = contentType;
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
if (contentType != null) {
response.setContentType(contentType.toString());
}
@ -170,10 +169,11 @@ public class AbstractJettyServerTestCase {
}
}
@SuppressWarnings("serial")
private static class PostServlet extends HttpServlet {
private final String s;
private final String content;
private final String location;
@ -181,20 +181,19 @@ public class AbstractJettyServerTestCase {
private final MediaType contentType;
private PostServlet(String s, String location, byte[] buf, MediaType contentType) {
this.s = s;
public PostServlet(String content, String location, byte[] buf, MediaType contentType) {
this.content = content;
this.location = location;
this.buf = buf;
this.contentType = contentType;
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
assertTrue("Invalid request content-length", request.getContentLength() > 0);
assertNotNull("No content-type", request.getContentType());
String body = FileCopyUtils.copyToString(request.getReader());
assertEquals("Invalid request body", s, body);
assertEquals("Invalid request body", content, body);
response.setStatus(HttpServletResponse.SC_CREATED);
response.setHeader("Location", baseUrl + location);
response.setContentLength(buf.length);
@ -203,6 +202,7 @@ public class AbstractJettyServerTestCase {
}
}
@SuppressWarnings("serial")
private static class JsonPostServlet extends HttpServlet {
@ -210,14 +210,13 @@ public class AbstractJettyServerTestCase {
private final MediaType contentType;
private JsonPostServlet(String location, MediaType contentType) {
public JsonPostServlet(String location, MediaType contentType) {
this.location = location;
this.contentType = contentType;
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
assertTrue("Invalid request content-length", request.getContentLength() > 0);
assertNotNull("No content-type", request.getContentType());
String body = FileCopyUtils.copyToString(request.getReader());
@ -230,18 +229,18 @@ public class AbstractJettyServerTestCase {
}
}
@SuppressWarnings("serial")
private static class PutServlet extends HttpServlet {
private final String s;
private PutServlet(String s, byte[] buf, MediaType contentType) {
public PutServlet(String s, byte[] buf, MediaType contentType) {
this.s = s;
}
@Override
protected void doPut(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
protected void doPut(HttpServletRequest request, HttpServletResponse response) throws IOException {
assertTrue("Invalid request content-length", request.getContentLength() > 0);
assertNotNull("No content-type", request.getContentType());
String body = FileCopyUtils.copyToString(request.getReader());
@ -250,17 +249,19 @@ public class AbstractJettyServerTestCase {
}
}
@SuppressWarnings("serial")
private static class UriServlet extends HttpServlet {
@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.setCharacterEncoding("utf-8");
resp.getWriter().write(req.getRequestURI());
}
}
@SuppressWarnings("serial")
private static class MultipartServlet extends HttpServlet {
@ -300,13 +301,13 @@ public class AbstractJettyServerTestCase {
}
}
@SuppressWarnings("serial")
private static class FormServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
assertEquals(MediaType.APPLICATION_FORM_URLENCODED_VALUE,
req.getContentType());
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
assertEquals(MediaType.APPLICATION_FORM_URLENCODED_VALUE, req.getContentType());
Map<String, String[]> parameters = req.getParameterMap();
assertEquals(2, parameters.size());
@ -322,15 +323,14 @@ public class AbstractJettyServerTestCase {
}
}
@SuppressWarnings("serial")
private static class DeleteServlet extends HttpServlet {
@Override
protected void doDelete(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws IOException {
resp.setStatus(200);
}
}
}

View File

@ -59,21 +59,22 @@ public class WebSocketStompClientTests {
private static final Charset UTF_8 = Charset.forName("UTF-8");
private TestWebSocketStompClient stompClient;
@Mock
private TaskScheduler taskScheduler;
@Mock
private ConnectionHandlingStompSession stompSession;
@Mock
private WebSocketSession webSocketSession;
private TestWebSocketStompClient stompClient;
private ArgumentCaptor<WebSocketHandler> webSocketHandlerCaptor;
private SettableListenableFuture<WebSocketSession> handshakeFuture;
@Mock
private WebSocketSession webSocketSession;
@Before
public void setUp() throws Exception {
@ -123,7 +124,7 @@ public class WebSocketStompClientTests {
}
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({"unchecked", "rawtypes"})
public void handleWebSocketMessage() throws Exception {
String text = "SEND\na:alpha\n\nMessage payload\0";
connect().handleMessage(this.webSocketSession, new TextMessage(text));
@ -141,7 +142,7 @@ public class WebSocketStompClientTests {
}
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({"unchecked", "rawtypes"})
public void handleWebSocketMessageSplitAcrossTwoMessage() throws Exception {
WebSocketHandler webSocketHandler = connect();
@ -166,7 +167,7 @@ public class WebSocketStompClientTests {
}
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({"unchecked", "rawtypes"})
public void handleWebSocketMessageBinary() throws Exception {
String text = "SEND\na:alpha\n\nMessage payload\0";
connect().handleMessage(this.webSocketSession, new BinaryMessage(text.getBytes(UTF_8)));
@ -249,7 +250,7 @@ public class WebSocketStompClientTests {
fail("Expected IllegalStateException");
}
catch (IllegalStateException ex) {
// Ignore
// ignore
}
}
@ -290,7 +291,7 @@ public class WebSocketStompClientTests {
}
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
public void cancelInactivityTasks() throws Exception {
TcpConnection<byte[]> tcpConnection = getTcpConnection();