use of org.apache.deltaspike.cdise.api.CdiContainer in project deltaspike by apache.
the class ContainerCtrlTckTest method testRestartContexts.
/**
* Stops and starts: application-, session- and request-scope.
* <p/>
* application-scoped instance has a ref to
* request-scoped instance which has a ref to
* session-scoped instance.
* <p/>
* If the deepest ref has the expected value, all levels in between were resetted correctly.
*/
@Test
public void testRestartContexts() {
CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer();
Assert.assertNotNull(cdiContainer);
cdiContainer.boot();
cdiContainer.getContextControl().startContexts();
BeanManager beanManager = cdiContainer.getBeanManager();
Assert.assertNotNull(beanManager);
Set<Bean<?>> beans = beanManager.getBeans(CarRepair.class);
Bean<?> bean = beanManager.resolve(beans);
CarRepair carRepair = (CarRepair) beanManager.getReference(bean, CarRepair.class, beanManager.createCreationalContext(bean));
Assert.assertNotNull(carRepair);
Car car = carRepair.getCar();
Assert.assertNotNull(car);
Assert.assertNotNull(car.getUser());
carRepair.getCar().getUser().setName("tester");
Assert.assertEquals("tester", car.getUser().getName());
Assert.assertFalse(CarRepair.isPreDestroyCalled());
Assert.assertFalse(Car.isPreDestroyCalled());
Assert.assertFalse(TestUser.isPreDestroyCalled());
cdiContainer.getContextControl().stopContexts();
Assert.assertTrue(CarRepair.isPreDestroyCalled());
Assert.assertTrue(Car.isPreDestroyCalled());
Assert.assertTrue(TestUser.isPreDestroyCalled());
try {
car.getUser();
// accessing the car should have triggered a ContextNotActiveException
Assert.fail();
} catch (ContextNotActiveException e) {
//do nothing - exception expected
}
cdiContainer.getContextControl().startContexts();
carRepair = (CarRepair) beanManager.getReference(bean, CarRepair.class, beanManager.createCreationalContext(bean));
Assert.assertNotNull(carRepair.getCar());
Assert.assertNotNull(carRepair.getCar().getUser());
Assert.assertNull(carRepair.getCar().getUser().getName());
cdiContainer.shutdown();
}
use of org.apache.deltaspike.cdise.api.CdiContainer in project deltaspike by apache.
the class ContainerCtrlTckTest method testNewRequests.
@Test
public void testNewRequests() {
CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer();
Assert.assertNotNull(cdiContainer);
cdiContainer.boot();
cdiContainer.getContextControl().startContext(SessionScoped.class);
cdiContainer.getContextControl().startContext(RequestScoped.class);
BeanManager beanManager = cdiContainer.getBeanManager();
Assert.assertNotNull(beanManager);
TestUser testUser = resolveInstance(beanManager, TestUser.class);
Assert.assertNotNull(testUser);
testUser.setName("tester");
CarRepair carRepair = resolveInstance(beanManager, CarRepair.class);
Assert.assertNotNull(carRepair);
Car car = carRepair.getCar();
Assert.assertNotNull(car);
Assert.assertNotNull(car.getUser());
Assert.assertEquals("tester", car.getUser().getName());
carRepair.getCar().getUser().setName("tck-tester");
Assert.assertEquals("tck-tester", testUser.getName());
cdiContainer.getContextControl().stopContext(RequestScoped.class);
cdiContainer.getContextControl().startContext(RequestScoped.class);
try {
testUser = resolveInstance(beanManager, TestUser.class);
Assert.assertNotNull(testUser);
Assert.assertNotNull(testUser.getName());
Assert.assertEquals("tck-tester", testUser.getName());
} catch (ContextNotActiveException e) {
Assert.fail(e.getMessage());
}
try {
carRepair = resolveInstance(beanManager, CarRepair.class);
Assert.assertNotNull(carRepair);
car = carRepair.getCar();
Assert.assertNotNull(car);
Assert.assertNotNull(car.getUser());
Assert.assertNotNull(car.getUser().getName());
Assert.assertEquals("tck-tester", car.getUser().getName());
} catch (ContextNotActiveException e) {
Assert.fail(e.getMessage());
}
cdiContainer.shutdown();
}
use of org.apache.deltaspike.cdise.api.CdiContainer in project deltaspike by apache.
the class EmbeddedServletContainer method testBootRequest.
@Test
public void testBootRequest() throws Exception {
CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer();
cdiContainer.boot();
cdiContainer.getContextControl().startContexts();
int port = createServer();
testRead(port);
try {
shutdown();
} finally {
//also calls #stopContexts
cdiContainer.shutdown();
}
}
use of org.apache.deltaspike.cdise.api.CdiContainer in project deltaspike by apache.
the class CdiTestSuiteRunner method run.
@Override
public void run(RunNotifier notifier) {
if (this.testSuiteClass == null) {
throw new IllegalStateException("no test-suite class found");
}
CdiContainer container = CdiContainerLoader.getCdiContainer();
if (!containerStarted) {
container.boot(getTestContainerConfig());
containerStarted = true;
}
notifier.addListener(new LogRunListener());
try {
super.run(notifier);
} finally {
if (STOP_CONTAINER) {
container.shutdown();
containerStarted = false;
}
}
}
use of org.apache.deltaspike.cdise.api.CdiContainer in project activemq-artemis by apache.
the class CDIExample method main.
public static void main(final String[] args) throws Exception {
CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer();
cdiContainer.boot();
cdiContainer.shutdown();
}
Aggregations