Search in sources :

Example 1 with TestUser

use of org.apache.deltaspike.cdise.tck.beans.TestUser 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();
}
Also used : CarRepair(org.apache.deltaspike.cdise.tck.beans.CarRepair) Car(org.apache.deltaspike.cdise.tck.beans.Car) ContextNotActiveException(javax.enterprise.context.ContextNotActiveException) BeanManager(javax.enterprise.inject.spi.BeanManager) TestUser(org.apache.deltaspike.cdise.tck.beans.TestUser) CdiContainer(org.apache.deltaspike.cdise.api.CdiContainer) Test(org.junit.Test)

Aggregations

ContextNotActiveException (javax.enterprise.context.ContextNotActiveException)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 TestUser (org.apache.deltaspike.cdise.tck.beans.TestUser)1 Test (org.junit.Test)1