use of org.minijax.test.MockHttpServletRequest in project minijax by minijax.
the class PersistenceContextTest method testPersistenceContextInject.
@Test
public void testPersistenceContextInject() throws IOException {
final Minijax container = new Minijax().register(PersistenceFeature.class).register(PersistenceContextDao.class);
final MinijaxApplication application = container.getDefaultApplication();
final MockHttpServletRequest request = new MockHttpServletRequest("GET", URI.create("/"));
try (MinijaxRequestContext context = new MinijaxRequestContext(application, request, null)) {
final PersistenceContextDao dao = container.getResource(PersistenceContextDao.class);
final Widget widget = new Widget();
widget.setName("test");
final Widget result = dao.create(widget);
assertNotNull(result);
assertNotNull(result.getId());
}
container.getInjector().close();
}
use of org.minijax.test.MockHttpServletRequest in project minijax by minijax.
the class WebSocketTest method testRun.
@Test
public void testRun() throws Exception {
final Minijax minijax = createMinijax();
minijax.register(WebSocketResource.class);
minijax.start();
final MinijaxApplication application = minijax.getDefaultApplication();
final DeploymentInfo deploymentInfo = new DeploymentInfo();
MinijaxWebSocketUtils.init(deploymentInfo, application);
final WebSocketDeploymentInfo webSocketDeploymentInfo = (WebSocketDeploymentInfo) deploymentInfo.getServletContextAttributes().get(WebSocketDeploymentInfo.ATTRIBUTE_NAME);
final ServerEndpointConfig endpointConfig = webSocketDeploymentInfo.getProgramaticEndpoints().get(0);
final MinijaxWebSocketConfigurator configurator = (MinijaxWebSocketConfigurator) endpointConfig.getConfigurator();
final MockHttpServletRequest request = new MockHttpServletRequest("GET", URI.create("/echo"));
try (MinijaxRequestContext context = new MinijaxRequestContext(application, request, null)) {
configurator.modifyHandshake(endpointConfig, null, null);
final AnnotatedEndpoint endpoint = configurator.getEndpointInstance(AnnotatedEndpoint.class);
assertNotNull(endpoint);
}
}
use of org.minijax.test.MockHttpServletRequest in project minijax by minijax.
the class ServletRequestContextTest method testAcceptableMediaTypes.
@Test
public void testAcceptableMediaTypes() throws IOException {
final MultivaluedMap<String, String> mockHeaders = new MultivaluedHashMap<>();
mockHeaders.add("Accept", "text/plain");
final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", URI.create("/"), mockHeaders, null, null);
try (final MinijaxRequestContext context = new MinijaxRequestContext(null, mockRequest, null)) {
final List<MediaType> mediaTypes = context.getAcceptableMediaTypes();
assertEquals(1, mediaTypes.size());
assertEquals("text/plain", mediaTypes.get(0).toString());
// Assert that same cached object
assertTrue(mediaTypes == context.getAcceptableMediaTypes());
}
}
use of org.minijax.test.MockHttpServletRequest in project minijax by minijax.
the class ServletRequestContextTest method testCookies.
@Test
public void testCookies() throws IOException {
final javax.servlet.http.Cookie[] mockCookies = new javax.servlet.http.Cookie[] { new javax.servlet.http.Cookie("a", "b") };
final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", URI.create("/"), null, null, mockCookies);
try (final MinijaxRequestContext context = new MinijaxRequestContext(null, mockRequest, null)) {
final Map<String, Cookie> cookies = context.getCookies();
assertEquals("b", cookies.get("a").getValue());
// Assert that same cached object
assertTrue(cookies == context.getCookies());
}
}
use of org.minijax.test.MockHttpServletRequest in project minijax by minijax.
the class ServletRequestContextTest method testUrlEncodedForm.
@Test
public void testUrlEncodedForm() throws IOException {
final MultivaluedMap<String, String> mockHeaders = new MultivaluedHashMap<>();
mockHeaders.add("Content-Type", "application/x-www-form-urlencoded");
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)) {
final MinijaxForm form = context.getForm();
assertTrue(form instanceof MinijaxUrlEncodedForm);
assertEquals("b", form.getString("a"));
// Assert that same cached object
assertTrue(form == context.getForm());
}
}
Aggregations