use of org.minijax.test.MockHttpServletRequest in project minijax by minijax.
the class ServletRequestContextTest method testProperties.
@Test
public void testProperties() throws IOException {
final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", URI.create("/"));
try (final MinijaxRequestContext context = new MinijaxRequestContext(null, mockRequest, null)) {
context.setProperty("a", "b");
assertEquals("b", context.getProperty("a"));
assertEquals("a", new ArrayList<>(context.getPropertyNames()).get(0));
context.removeProperty("a");
assertTrue(context.getPropertyNames().isEmpty());
}
}
use of org.minijax.test.MockHttpServletRequest in project minijax by minijax.
the class ServletRequestContextTest method testAcceptableLanguages.
@Test
public void testAcceptableLanguages() throws IOException {
final MultivaluedMap<String, String> mockHeaders = new MultivaluedHashMap<>();
mockHeaders.add("Accept-Language", "en-US");
final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", URI.create("/"), mockHeaders, null, null);
try (final MinijaxRequestContext context = new MinijaxRequestContext(null, mockRequest, null)) {
final List<Locale> locales = context.getAcceptableLanguages();
assertEquals(1, locales.size());
assertEquals("en-US", locales.get(0).toLanguageTag());
// Assert that same cached object
assertTrue(locales == context.getAcceptableLanguages());
}
}
use of org.minijax.test.MockHttpServletRequest 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.MockHttpServletRequest 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.MockHttpServletRequest in project minijax by minijax.
the class HttpHeadersTest method testContentLength.
@Test
public void testContentLength() {
final MultivaluedMap<String, String> headers = new MultivaluedHashMap<>();
headers.add("Content-Length", "1024");
final MockHttpServletRequest request = new MockHttpServletRequest("GET", URI.create("/"), headers, null, null);
final MinijaxHttpHeaders httpHeaders = new MinijaxHttpHeaders(request);
assertEquals(1024, httpHeaders.getLength());
}
Aggregations