use of org.minijax.test.MockHttpServletRequest 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);
}
use of org.minijax.test.MockHttpServletRequest in project minijax by minijax.
the class ServletRequestContextTest method testFormMissingContentType.
@Test
public void testFormMissingContentType() throws IOException {
final ByteArrayInputStream mockContentBody = new ByteArrayInputStream("a=b".getBytes(StandardCharsets.UTF_8));
final MockHttpServletRequest mockRequest = new MockHttpServletRequest("POST", URI.create("/"), null, mockContentBody, null);
try (final MinijaxRequestContext context = new MinijaxRequestContext(null, mockRequest, null)) {
assertNull(context.getForm());
}
}
use of org.minijax.test.MockHttpServletRequest in project minijax by minijax.
the class ServletRequestContextTest method testMultipartForm.
@Test
public void testMultipartForm() throws IOException {
final MultivaluedMap<String, String> mockHeaders = new MultivaluedHashMap<>();
mockHeaders.add("Content-Type", "multipart/form-data");
final String mockContent = "------WebKitFormBoundarycTqA2AimXQHBAJbZ\n" + "Content-Disposition: form-data; name=\"a\"\n" + "\n" + "b\n" + "------WebKitFormBoundarycTqA2AimXQHBAJbZ";
final ByteArrayInputStream mockContentBody = new ByteArrayInputStream(mockContent.getBytes(StandardCharsets.UTF_8));
final MockHttpServletRequest mockRequest = new MockHttpServletRequest("POST", URI.create("/"), mockHeaders, mockContentBody, null);
try (final MinijaxRequestContext context = new MinijaxRequestContext(null, mockRequest, null)) {
final MinijaxForm form = context.getForm();
assertTrue(form instanceof MinijaxMultipartForm);
assertEquals("b", form.getString("a"));
// Assert that same cached object
assertTrue(form == context.getForm());
}
}
use of org.minijax.test.MockHttpServletRequest in project minijax by minijax.
the class ServletRequestContextTest method testHeaders.
@Test
public void testHeaders() throws IOException {
final MultivaluedMap<String, String> mockHeaders = new MultivaluedHashMap<>();
mockHeaders.add("a", "b");
final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", URI.create("/"), mockHeaders, null, null);
try (final MinijaxRequestContext context = new MinijaxRequestContext(null, mockRequest, null)) {
final MultivaluedMap<String, String> headers = context.getHeaders();
assertEquals("b", headers.get("a").get(0));
// Assert that same cached object
assertTrue(headers == context.getHeaders());
}
}
use of org.minijax.test.MockHttpServletRequest in project minijax by minijax.
the class ServletRequestContextTest method testFormUnknownContentType.
@Test(expected = BadRequestException.class)
public void testFormUnknownContentType() throws IOException {
final MultivaluedMap<String, String> mockHeaders = new MultivaluedHashMap<>();
mockHeaders.add("Content-Type", "text/plain");
final ByteArrayInputStream mockContentBody = new ByteArrayInputStream("a=b".getBytes(StandardCharsets.UTF_8));
final MockHttpServletRequest mockRequest = new MockHttpServletRequest("POST", URI.create("/"), mockHeaders, mockContentBody, null);
try (final MinijaxRequestContext context = new MinijaxRequestContext(null, mockRequest, null)) {
context.getForm();
}
}
Aggregations