use of org.apache.openejb.testing.ApplicationComposers in project tomee by apache.
the class EnsureRequestScopeThreadLocalIsCleanUpTest method ensureRequestContextCanBeRestarted.
@Test
public void ensureRequestContextCanBeRestarted() throws Exception {
final ApplicationComposers composers = new ApplicationComposers(EnsureRequestScopeThreadLocalIsCleanUpTest.class);
composers.before(this);
final CdiAppContextsService contextsService = CdiAppContextsService.class.cast(WebBeansContext.currentInstance().getService(ContextsService.class));
final Context req1 = contextsService.getCurrentContext(RequestScoped.class);
assertNotNull(req1);
final Context session1 = contextsService.getCurrentContext(SessionScoped.class);
assertNotNull(session1);
contextsService.endContext(RequestScoped.class, null);
contextsService.startContext(RequestScoped.class, null);
final Context req2 = contextsService.getCurrentContext(RequestScoped.class);
assertNotSame(req1, req2);
final Context session2 = contextsService.getCurrentContext(SessionScoped.class);
assertSame(session1, session2);
composers.after();
assertNull(contextsService.getCurrentContext(RequestScoped.class));
assertNull(contextsService.getCurrentContext(SessionScoped.class));
}
use of org.apache.openejb.testing.ApplicationComposers in project tomee by apache.
the class ThreadDumpOnDestroyTest method run.
@Test
public void run() throws Exception {
final List<String> records = new ArrayList<>();
final Handler h = new Handler() {
@Override
public synchronized void publish(final LogRecord record) {
records.add(record.getMessage());
}
@Override
public void flush() {
// no-op
}
@Override
public void close() throws SecurityException {
// no-op
}
};
new ApplicationComposers(ThreadDumpOnDestroyTest.class).evaluate(this, new Runnable() {
@Override
public void run() {
Logger.getLogger("OpenEJB.startup").addHandler(h);
}
});
Logger.getLogger("OpenEJB.startup").removeHandler(h);
assertEquals("Can't destroy test in 3 seconds, giving up.", records.get(1));
assertTrue(records.get(2).contains("\"openejb-resource-destruction-test - 1\" suspended=false state=TIMED_WAITING"));
assertTrue(records.get(2).contains("org.apache.openejb.resource.ThreadDumpOnDestroyTest$WillFail.destroy"));
}
use of org.apache.openejb.testing.ApplicationComposers in project tomee by apache.
the class ApplicationRule method apply.
@Override
public Statement apply(final Statement statement, final Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
final Thread thread = Thread.currentThread();
final ClassLoader old = thread.getContextClassLoader();
final ApplicationComposers composers = new ApplicationOnlyApplicationComposers(instance);
composers.deployApp(instance);
try {
statement.evaluate();
} finally {
composers.stopApplication();
thread.setContextClassLoader(old);
}
}
};
}
use of org.apache.openejb.testing.ApplicationComposers in project tomee by apache.
the class CustomObjectNameMBeanTest method run.
@Test
public void run() throws Exception {
final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
mbeanState(server, false);
new ApplicationComposers(this).evaluate(this, new Runnable() {
@Override
public void run() {
try {
mbeanState(server, true);
assertEquals(1, server.getAttribute(new ObjectName("openejb.user.mbeans:application=openejb,group=org.apache.openejb.config,name=DefaultName"), "value"));
assertEquals(2, server.getAttribute(new ObjectName("foo:type=bar,custom=yes"), "value"));
} catch (final Exception e) {
throw new IllegalStateException(e);
}
}
});
mbeanState(server, false);
}
use of org.apache.openejb.testing.ApplicationComposers in project tomee by apache.
the class ResourceEventsTest method run.
@Test
public void run() throws Exception {
Listener.EVENTS.clear();
new ApplicationComposers(this).evaluate(this, new Callable<Object>() {
@Override
public Object call() throws Exception {
assertEquals(2, Listener.EVENTS.size());
for (final ResourceEvent re : Listener.EVENTS) {
assertTrue(ResourceCreated.class.isInstance(re));
assertNotNull(re.getResource());
assertTrue("base".equals(re.getName()) || "base2".equals(re.getName()));
}
Listener.EVENTS.clear();
assertTrue(Child.class.isInstance(base));
assertFalse(Child.class.isInstance(base2));
assertNotNull(Child.class.cast(base).parent);
return null;
}
});
assertEquals(2, Listener.EVENTS.size());
for (final ResourceEvent re : Listener.EVENTS) {
assertTrue(ResourceBeforeDestroyed.class.isInstance(re));
Object resource = re.getResource();
if (Assembler.ResourceInstance.class.isInstance(resource)) {
resource = Assembler.ResourceInstance.class.cast(resource).getObject();
}
assertNotNull(resource);
assertTrue("base".equals(re.getName()) || "base2".equals(re.getName()));
if ("base".equals(re.getName())) {
assertTrue(Child.class.isInstance(resource));
} else {
assertFalse(Child.class.isInstance(resource));
assertTrue(Base.class.isInstance(resource));
}
}
Listener.EVENTS.clear();
assertTrue(base2.stopped);
assertTrue(base.stopped);
assertTrue(Base.class.cast(Child.class.cast(base).parent).stopped);
}
Aggregations