Search in sources :

Example 1 with LockedCDIImplementation

use of org.apache.deltaspike.cdise.tck.control.LockedCDIImplementation in project deltaspike by apache.

the class ContainerCtrlTckTest method testShutdownWithInactiveContexts.

@Test
@LockedCDIImplementation(versions = { @LockedVersionRange(implementation = CdiImplementation.WELD11, versionRange = "[1.1.14,1.2)"), @LockedVersionRange(implementation = CdiImplementation.WELD20, versionRange = "[2.0.1.Final,2.1)") })
public void testShutdownWithInactiveContexts() {
    CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer();
    Assert.assertNotNull(cdiContainer);
    cdiContainer.boot();
    cdiContainer.getContextControl().startContexts();
    // now do some random stuff
    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());
    cdiContainer.shutdown();
}
Also used : CarRepair(org.apache.deltaspike.cdise.tck.beans.CarRepair) Car(org.apache.deltaspike.cdise.tck.beans.Car) BeanManager(javax.enterprise.inject.spi.BeanManager) CdiContainer(org.apache.deltaspike.cdise.api.CdiContainer) Bean(javax.enterprise.inject.spi.Bean) Test(org.junit.Test) LockedCDIImplementation(org.apache.deltaspike.cdise.tck.control.LockedCDIImplementation)

Aggregations

Bean (javax.enterprise.inject.spi.Bean)1 BeanManager (javax.enterprise.inject.spi.BeanManager)1 CdiContainer (org.apache.deltaspike.cdise.api.CdiContainer)1 Car (org.apache.deltaspike.cdise.tck.beans.Car)1 CarRepair (org.apache.deltaspike.cdise.tck.beans.CarRepair)1 LockedCDIImplementation (org.apache.deltaspike.cdise.tck.control.LockedCDIImplementation)1 Test (org.junit.Test)1