use of org.minijax.MinijaxApplication 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.MinijaxApplication 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.MinijaxApplication in project minijax by minijax.
the class RequestScopedTest method testRequestScoped.
@Test
public void testRequestScoped() throws IOException {
final Minijax container = new Minijax();
final MinijaxApplication application = container.getDefaultApplication();
final MockHttpServletRequest r1 = new MockHttpServletRequest("GET", URI.create("/"));
A a1;
A a2;
try (MinijaxRequestContext context = new MinijaxRequestContext(application, r1, null)) {
a1 = container.getResource(A.class);
assertNotNull(a1);
a2 = container.getResource(A.class);
assertEquals(a1, a2);
assertTrue(a1 == a2);
}
final MockHttpServletRequest r2 = new MockHttpServletRequest("GET", URI.create("/"));
A a3;
A a4;
try (MinijaxRequestContext context = new MinijaxRequestContext(application, r2, null)) {
a3 = container.getResource(A.class);
assertNotNull(a3);
a4 = container.getResource(A.class);
assertEquals(a3, a4);
assertTrue(a3 == a4);
}
assertNotEquals(a1, a3);
assertTrue(a1 != a3);
container.getInjector().close();
}
use of org.minijax.MinijaxApplication in project minijax by minijax.
the class MinijaxInvocationBuilder method method.
@Override
public Response method(final String name) {
final Minijax container = target.getServer();
final MinijaxApplication application = container.getApplication(target.getUri());
try {
final MockHttpServletRequest request = new MockHttpServletRequest(name, target.getUri(), headers, getEntityInputStream(), CookieUtils.convertJaxToServlet(cookies));
final MockHttpServletResponse response = new MockHttpServletResponse();
try (final MinijaxRequestContext context = new MinijaxRequestContext(application, request, response)) {
return application.handle(context);
}
} catch (final IOException ex) {
throw ExceptionUtils.toWebAppException(ex);
}
}
use of org.minijax.MinijaxApplication in project minijax by minijax.
the class PersistenceFeature method configure.
@Override
public boolean configure(final FeatureContext context) {
if (!(context instanceof MinijaxApplication)) {
throw new IllegalArgumentException("Minijax PersistenceFeature only compatible with MinijaxApplication");
}
final MinijaxApplication app = (MinijaxApplication) context;
app.getInjector().registerPersistence();
return true;
}
Aggregations