Package org.apache.deltaspike.cdise.api

Examples of org.apache.deltaspike.cdise.api.CdiContainer


     * 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());

        cdiContainer.getContextControl().stopContexts();

        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();
    }
View Full Code Here


    }

    @Test
    public void testShutdownWithInactiveContexts()
    {
        CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer();
        Assert.assertNotNull(cdiContainer);

        cdiContainer.boot();
        cdiContainer.getContextControl().startContexts();

        // now do some randmo 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);

        cdiContainer.getContextControl().startContexts();

        cdiContainer.shutdown();
    }
View Full Code Here

    protected abstract void shutdown() throws Exception;

    @Test
    public void testBootRequest() throws Exception
    {
        CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer();
        cdiContainer.boot();
        cdiContainer.getContextControl().startContexts();
        int port = createServer();
        testRead(port);
        shutdown();
    }
View Full Code Here

        contextControl.startContext(RequestScoped.class);
    }

    private ContextControl getContextControl()
    {
        CdiContainer container = CdiContainerLoader.getCdiContainer();
        return container.createContextControl();
    }
View Full Code Here

*/
public class Main {
    public static void main(String[] args) {
        Util.feedBack("Starting CDI Container");
        // Start the CDI container
        CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer();
        cdiContainer.boot();

        // Starting the application-context allows to use @ApplicationScoped beans
        ContextControl contextControl = cdiContainer.getContextControl();
        contextControl.startContext(ApplicationScoped.class);

        MainApplication main = BeanProvider.getContextualReference(MainApplication.class, false);

        main.run();
        // Stop de CDI container
        cdiContainer.shutdown();
    }
View Full Code Here

TOP

Related Classes of org.apache.deltaspike.cdise.api.CdiContainer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.