@Test public void testDoDeleteReturnsError() throws Exception { /* setup mock request to return URI */ when(request.getPathInfo()).thenReturn("?"); // send POST instead of GET so we should get an error when(request.getMethod()).thenReturn("DELETE"); FilterScriptManagerServlet servlet = new FilterScriptManagerServlet(); servlet.service(request, response); // a 405 because POST with those arguments is invalid verify(response).setStatus(405); // test that the usage docs were output verify(response).getWriter(); verify(responseWriter).write(getUsageDoc()); }
@Test public void testErrorWithUsageIfIncorrectArguments1() throws Exception { /* setup mock request to return URI */ when(request.getPathInfo()).thenReturn("?"); when(request.getMethod()).thenReturn("GET"); FilterScriptManagerServlet servlet = new FilterScriptManagerServlet(); servlet.service(request, response); System.out.println("--------------------------------------------------------"); System.out.println(getUsageDoc()); System.out.println("--------------------------------------------------------"); // a 400 because the resource exists, but arguments are incorrect verify(response).setStatus(400); // test that the usage docs were output verify(response).getWriter(); verify(responseWriter).write("ERROR: Invalid arguments.\n\n"); verify(responseWriter).write(getUsageDoc()); }
@Test public void testErrorWithUsageIfIncorrectArguments2() throws Exception { /* setup mock request to return URI */ when(request.getPathInfo()).thenReturn("?action=UNKNOWN"); when(request.getParameter("action")).thenReturn("UNKNOWN"); when(request.getMethod()).thenReturn("GET"); FilterScriptManagerServlet servlet = new FilterScriptManagerServlet(); servlet.service(request, response); // a 400 because the resource exists, but arguments are incorrect verify(response).setStatus(400); // test that the usage docs were output verify(response).getWriter(); verify(responseWriter).write("ERROR: Unknown action type.\n\n"); verify(responseWriter).write(getUsageDoc()); }
@Test public void testErrorWithUsageIfIncorrectMethod() throws Exception { /* setup mock request to return URI */ when(request.getPathInfo()).thenReturn("?action=LIST&filter=unknown:type"); when(request.getParameter("action")).thenReturn("LIST"); // send POST instead of GET so we should get an error when(request.getMethod()).thenReturn("POST"); FilterScriptManagerServlet servlet = new FilterScriptManagerServlet(); servlet.service(request, response); // a 405 because POST with those arguments is invalid verify(response).setStatus(405); // test that the usage docs were output verify(response).getWriter(); verify(responseWriter).write("ERROR: Invalid HTTP method for action type.\n\n"); verify(responseWriter).write(getUsageDoc()); }
private FilterScriptManagerServlet getEndpointScriptManagerImplementation(ZuulFilterDAO dao) { return new FilterScriptManagerServlet(dao, new DynamicBooleanProperty("test.admin.enabled", true)); }