Package org.apache.webbeans.context

Examples of org.apache.webbeans.context.ContextFactory


    }

    @Test
    public void testSecureAndTransactionalInterceptor()
    {
        ContextFactory contextFactory = WebBeansContext.getInstance().getContextFactory();
        contextFactory.initSessionContext(null);
        defineInterceptor(SecureAndTransactionalInterceptor.class);
       
        Bean<SecureAndTransactionalComponent> bean = defineManagedBean(SecureAndTransactionalComponent.class);
        SecureAndTransactionalComponent payment = getManager().getInstance(bean);
       
        Assert.assertFalse(SecureAndTransactionalComponent.getCALL());
       
        payment.pay();
       
        Assert.assertTrue(SecureAndTransactionalComponent.getCALL());


        contextFactory.destroySessionContext(null);
    }
View Full Code Here


{

    public AbstractContext getRequestContext()
    {
        WebBeansContext webBeansContext = WebBeansContext.getInstance();
        ContextFactory contextFactory = webBeansContext.getContextFactory();

        RequestContext ctx =  (RequestContext)contextFactory.getStandardContext(RequestScoped.class);
       
        if(ctx == null)
        {
            contextFactory.initRequestContext(null);
        }
       
        return (AbstractContext) contextFactory.getStandardContext(ContextTypes.REQUEST);
    }
View Full Code Here

        defineManagedBean(TypeLiteralComponent.class);
        defineManagedBean(InjectedTypeLiteralComponent.class);
        List<AbstractOwbBean<?>> comps = getComponents();

        ContextFactory contextFactory = WebBeansContext.getInstance().getContextFactory();
        contextFactory.initRequestContext(null);

        Assert.assertEquals(2, comps.size());

        TypeLiteralComponent userComponent = (TypeLiteralComponent) getManager().getInstance(comps.get(0));
        InjectedTypeLiteralComponent tc = (InjectedTypeLiteralComponent) getManager().getInstance(comps.get(1));

        Assert.assertNotNull(tc.getComponent());
        Assert.assertNotNull(userComponent);

        Assert.assertTrue(tc.getComponent() instanceof TypeLiteralComponent);

        contextFactory.destroyRequestContext(null);
    }
View Full Code Here

        defineManagedBean(DependentComponent.class);
        defineManagedBean(DependentOwnerComponent.class);
        defineManagedBean(NewComponent.class);

        ContextFactory contextFactory = WebBeansContext.getInstance().getContextFactory();
        contextFactory.initRequestContext(null);

        List<AbstractOwbBean<?>> comps = getComponents();

        Assert.assertEquals(3, comps.size());

        NewComponent comp = (NewComponent) getManager().getInstance(comps.get(2));

        DependentOwnerComponent own = comp.owner();

        Assert.assertNotNull(own);

        contextFactory.destroyRequestContext(null);
    }
View Full Code Here

        clear();

        defineManagedBean(TypeLiteralComponent.class);
        List<AbstractOwbBean<?>> comps = getComponents();

        ContextFactory contextFactory = WebBeansContext.getInstance().getContextFactory();
        contextFactory.initRequestContext(null);

        Assert.assertEquals(1, comps.size());

        TypeLiteral<ITypeLiteralComponent<List<String>>> tl = new TypeLiteral<ITypeLiteralComponent<List<String>>>()
        {
        };

        Annotation[] anns = new Annotation[1];
        anns[0] = new AnnotationLiteral<Default>()
        {

        };

        Bean<?> s = WebBeansContext.getInstance().getBeanManagerImpl().resolveByType(tl, anns).iterator().next();
        Assert.assertNotNull(s);

        contextFactory.destroyRequestContext(null);
    }
View Full Code Here

        defineManagedBean(Producer1.class);
        defineManagedBean(Producer1ConsumerComponent.class);

        List<AbstractOwbBean<?>> comps = getComponents();

        ContextFactory contextFactory = WebBeansContext.getInstance().getContextFactory();
        contextFactory.initRequestContext(null);
        contextFactory.initApplicationContext(null);

        Assert.assertEquals(7, getDeployedComponents());

        Object obj = getManager().getInstance(comps.get(0));
       
        Assert.assertNotNull(obj);

        getInstanceByName("service");

        getManager().getInstance(comps.get(1));

        Object object = getManager().getInstance(comps.get(2));

        Assert.assertTrue(object instanceof Producer1ConsumerComponent);

        Producer1ConsumerComponent single = (Producer1ConsumerComponent) object;

        IService service = single.getService();

        Assert.assertNotNull(service);

        contextFactory.destroyApplicationContext(null);
        contextFactory.destroyRequestContext(null);
    }
View Full Code Here

        clear();

        defineManagedBean(BookShop.class);
        List<AbstractOwbBean<?>> comps = getComponents();

        ContextFactory contextFactory = WebBeansContext.getInstance().getContextFactory();
        contextFactory.initRequestContext(null);

        Assert.assertEquals(1, comps.size());

        AbstractOwbBean<?> obj = comps.get(0);

        Object instance = getManager().getInstance(obj);
        Assert.assertTrue(instance instanceof Shop);

        @SuppressWarnings("unchecked")
        Shop<Book> shop = (Shop<Book>) instance;
        shop.shop();

        contextFactory.destroyRequestContext(null);
    }
View Full Code Here

        defineManagedBean(CheckWithCheckPayment.class);
        defineManagedBean(ScopeAdaptorComponent.class);
        defineManagedBean(ScopeAdaptorInjectorComponent.class);

        Object session = getSession();
        ContextFactory contextFactory = WebBeansContext.getInstance().getContextFactory();
        contextFactory.initRequestContext(null);
        contextFactory.initSessionContext(session);
        contextFactory.initApplicationContext(null);

        List<AbstractOwbBean<?>> comps = getComponents();

        Assert.assertEquals(7, getDeployedComponents());

        getManager().getInstance(comps.get(0));
        getManager().getInstance(comps.get(1));
        getInstanceByName("scope");
        getManager().getInstance(comps.get(2));

        contextFactory.destroyApplicationContext(null);
        contextFactory.destroySessionContext(session);
        contextFactory.destroyRequestContext(null);

    }
View Full Code Here

        defineManagedBean(Singleton.class);
        List<AbstractOwbBean<?>> comps = getComponents();

        Object session = getSession();

        ContextFactory contextFactory = WebBeansContext.getInstance().getContextFactory();
        contextFactory.initSessionContext(session);

        Assert.assertEquals(2, comps.size());

        getManager().getInstance(comps.get(0));
        Object object = getManager().getInstance(comps.get(1));

        Assert.assertTrue(object instanceof Singleton);

        Singleton single = (Singleton) object;

        Assert.assertEquals("debug", single.logDebug());
        Assert.assertEquals("info", single.logInfoo());

        ITyped2 t = single.getType();

        Assert.assertNotNull(t);

        contextFactory.destroySessionContext(session);
    }
View Full Code Here

    @Test
    public void testDisposal1()
    {
        clear();

        ContextFactory contextFactory = WebBeansContext.getInstance().getContextFactory();
        contextFactory.initRequestContext(null);
        contextFactory.initSessionContext(null);

        defineManagedBean(Disposal1.class);

        @SuppressWarnings("unchecked")
        List<Integer> list = (List<Integer>) getManager().getInstanceByName("createBinding1");
        Assert.assertNotNull(list);
        Assert.assertTrue(list.size() == 1);
        contextFactory.destroyRequestContext(null);

        Assert.assertTrue(Disposal1.getDISPOSCALL());

    }
View Full Code Here

TOP

Related Classes of org.apache.webbeans.context.ContextFactory

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.