use of org.minijax.test.MockHttpServletResponse in project minijax by minijax.
the class ServletTest method testServletResponse.
@Test
public void testServletResponse() throws IOException {
final MultivaluedMap<String, String> headers = new MultivaluedHashMap<>();
final Cookie[] cookies = new Cookie[0];
final MockHttpServletRequest servletRequest = new MockHttpServletRequest("GET", URI.create("/servlet"), headers, null, cookies);
final MockHttpServletResponse servletResponse = new MockHttpServletResponse();
final MinijaxRequestContext context = new MinijaxRequestContext(null, servletRequest, servletResponse);
getServer().getDefaultApplication().handle(context, servletResponse);
assertEquals(200, servletResponse.getStatus());
assertEquals("text/plain", servletResponse.getContentType());
assertEquals("Hello world!", servletResponse.getOutput().trim());
}
use of org.minijax.test.MockHttpServletResponse in project minijax by minijax.
the class ServletTest method testNullResponse.
@Test
public void testNullResponse() throws IOException {
final MultivaluedMap<String, String> headers = new MultivaluedHashMap<>();
final Cookie[] cookies = new Cookie[0];
final MockHttpServletRequest servletRequest = new MockHttpServletRequest("GET", URI.create("/null"), headers, null, cookies);
final MockHttpServletResponse servletResponse = new MockHttpServletResponse();
final MinijaxRequestContext context = new MinijaxRequestContext(null, servletRequest, servletResponse);
getServer().getDefaultApplication().handle(context, servletResponse);
assertEquals(404, servletResponse.getStatus());
assertNull(servletResponse.getContentType());
}
use of org.minijax.test.MockHttpServletResponse in project minijax by minijax.
the class ServletFilterTest method testServletFilterMissingContext.
@Test
public void testServletFilterMissingContext() throws ServletException, IOException {
final Minijax minijax = new Minijax();
final MinijaxApplication application = minijax.getDefaultApplication();
final MinijaxServlet servlet = new MinijaxServlet(application);
final MockFilterChain chain = new MockFilterChain(servlet);
final MinijaxFilter filter = new MinijaxFilter(application);
filter.init(null);
final MockHttpServletRequest request = new MockHttpServletRequest("GET", URI.create("/"));
final MockHttpServletResponse response = new MockHttpServletResponse();
filter.doFilter(request, response, chain);
assertTrue(chain.success);
}
Aggregations