Search in sources :

Example 1 with MinijaxTestRequestContext

use of org.minijax.rs.test.MinijaxTestRequestContext in project minijax by minijax.

the class PersistenceContextTest method testPersistenceContextInject.

@Test
void testPersistenceContextInject() throws IOException {
    final Minijax container = new Minijax().register(PersistenceFeature.class).register(PersistenceContextDao.class);
    final MinijaxApplication application = container.getDefaultApplication();
    try (MinijaxRequestContext context = new MinijaxTestRequestContext(application, GET, "/")) {
        final PersistenceContextDao dao = context.getResource(PersistenceContextDao.class);
        final Widget widget = new Widget();
        widget.setId(123);
        widget.setName("test");
        final Widget result = dao.create(widget);
        assertNotNull(result);
        assertEquals(123, result.getId());
    }
    container.getInjector().close();
}
Also used : MinijaxApplication(org.minijax.rs.MinijaxApplication) MinijaxRequestContext(org.minijax.rs.MinijaxRequestContext) Minijax(org.minijax.Minijax) MinijaxTestRequestContext(org.minijax.rs.test.MinijaxTestRequestContext) Test(org.junit.jupiter.api.Test)

Example 2 with MinijaxTestRequestContext

use of org.minijax.rs.test.MinijaxTestRequestContext in project minijax by minijax.

the class RequestScopedTest method testRequestScoped.

@Test
void testRequestScoped() throws IOException {
    final Minijax container = new Minijax();
    final MinijaxApplication application = container.getDefaultApplication();
    A a1;
    A a2;
    try (MinijaxRequestContext context = new MinijaxTestRequestContext(application, GET, "/")) {
        a1 = context.getResource(A.class);
        assertNotNull(a1);
        a2 = context.getResource(A.class);
        assertEquals(a1, a2);
        assertSame(a1, a2);
    }
    A a3;
    A a4;
    try (MinijaxRequestContext context = new MinijaxTestRequestContext(application, GET, "/")) {
        a3 = context.getResource(A.class);
        assertNotNull(a3);
        a4 = context.getResource(A.class);
        assertEquals(a3, a4);
        assertSame(a3, a4);
    }
    assertNotEquals(a1, a3);
    assertNotSame(a1, a3);
    container.getInjector().close();
}
Also used : MinijaxApplication(org.minijax.rs.MinijaxApplication) MinijaxRequestContext(org.minijax.rs.MinijaxRequestContext) Minijax(org.minijax.Minijax) MinijaxTestRequestContext(org.minijax.rs.test.MinijaxTestRequestContext) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)2 Minijax (org.minijax.Minijax)2 MinijaxApplication (org.minijax.rs.MinijaxApplication)2 MinijaxRequestContext (org.minijax.rs.MinijaxRequestContext)2 MinijaxTestRequestContext (org.minijax.rs.test.MinijaxTestRequestContext)2