List of usage examples for org.springframework.mock.web MockHttpServletResponse setStatus
@Override public void setStatus(int status)
From source file:com.doitnext.http.router.responsehandlers.DefaultErrorHandlerTest.java
@Test public void testHandleValidStatusCode() throws IOException { DefaultErrorHandler h = new DefaultErrorHandler(); Exception responseData = new IllegalArgumentException("Hidey Ho!!", new NumberFormatException("3r3")); MockHttpServletResponse response = new MockHttpServletResponse(); response.setStatus(403); boolean handled = h.handleResponse(null, null, response, responseData); Assert.assertTrue(handled);//from w ww .ja va 2 s . c om Assert.assertEquals(403, response.getStatus()); }
From source file:guru.nidi.ramltester.HighlevelTestBase.java
protected MockHttpServletResponse jsonResponse(int code, String json, String contentType) throws UnsupportedEncodingException { final MockHttpServletResponse response = new MockHttpServletResponse(); response.setStatus(code); response.setContentType(contentType); response.getWriter().print(json);//w w w.j av a 2 s .com return response; }
From source file:com.doitnext.http.router.responsehandlers.DefaultErrorHandlerTest.java
@Test public void testHandleResponseWithExceptionHandlerAnnotation() throws Exception { DefaultErrorHandler h = new DefaultErrorHandler(); MockHttpServletResponse response = new MockHttpServletResponse(); PathTemplate pt = null;/*from w ww . ja v a 2 s .c om*/ Path path = new Path("a/b/c", "nice=winds", pt); Method method = this.getClass().getMethod("exceptionGeneratingMethod"); Route route = new Route(HttpMethod.GET, null, null, null, "application/json", pt, this.getClass(), method, null, this, null, h, false); PathMatch pm = new PathMatch(route, path); boolean handled = h.handleResponse(pm, null, response, new IllegalArgumentException()); Assert.assertTrue(handled); Assert.assertEquals(409, response.getStatus()); response.setStatus(0); handled = h.handleResponse(pm, null, response, new IOException()); Assert.assertTrue(handled); Assert.assertEquals(402, response.getStatus()); response.setStatus(0); handled = h.handleResponse(pm, null, response, new NullPointerException()); Assert.assertTrue(handled); Assert.assertEquals(500, response.getStatus()); }