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();
}
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();
}
Aggregations