Search in sources :

Example 1 with MinijaxApplication

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();
}
Also used : MinijaxApplication(org.minijax.MinijaxApplication) MinijaxRequestContext(org.minijax.MinijaxRequestContext) Minijax(org.minijax.Minijax) MockHttpServletRequest(org.minijax.test.MockHttpServletRequest) Widget(org.minijax.db.test.Widget) Test(org.junit.Test)

Example 2 with MinijaxApplication

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);
    }
}
Also used : MinijaxApplication(org.minijax.MinijaxApplication) MinijaxRequestContext(org.minijax.MinijaxRequestContext) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) Minijax(org.minijax.Minijax) MockHttpServletRequest(org.minijax.test.MockHttpServletRequest) AnnotatedEndpoint(io.undertow.websockets.jsr.annotated.AnnotatedEndpoint) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) Test(org.junit.Test)

Example 3 with MinijaxApplication

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();
}
Also used : MinijaxApplication(org.minijax.MinijaxApplication) MinijaxRequestContext(org.minijax.MinijaxRequestContext) Minijax(org.minijax.Minijax) MockHttpServletRequest(org.minijax.test.MockHttpServletRequest) Test(org.junit.Test)

Example 4 with MinijaxApplication

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);
    }
}
Also used : MinijaxApplication(org.minijax.MinijaxApplication) MinijaxRequestContext(org.minijax.MinijaxRequestContext) Minijax(org.minijax.Minijax) IOException(java.io.IOException)

Example 5 with MinijaxApplication

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;
}
Also used : MinijaxApplication(org.minijax.MinijaxApplication)

Aggregations

MinijaxApplication (org.minijax.MinijaxApplication)5 Minijax (org.minijax.Minijax)4 MinijaxRequestContext (org.minijax.MinijaxRequestContext)4 Test (org.junit.Test)3 MockHttpServletRequest (org.minijax.test.MockHttpServletRequest)3 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)1 WebSocketDeploymentInfo (io.undertow.websockets.jsr.WebSocketDeploymentInfo)1 AnnotatedEndpoint (io.undertow.websockets.jsr.annotated.AnnotatedEndpoint)1 IOException (java.io.IOException)1 ServerEndpointConfig (javax.websocket.server.ServerEndpointConfig)1 Widget (org.minijax.db.test.Widget)1