Package javax.enterprise.context.spi

Examples of javax.enterprise.context.spi.Context


            return;
        }

        final ContextsService contextsService = webBeansContext.getContextsService();

        final Context requestContext = contextsService.getCurrentContext(RequestScoped.class);

        if (requestContext == null) {
            contextsService.startContext(RequestScoped.class, null);
            newContext.set(DestroyContext.class, new DestroyContext(contextsService, newContext));
        }
View Full Code Here


    protected Object getContextualInstance()
    {
        Object webbeansInstance;

        //Context of the bean
        Context webbeansContext = beanManager.getContext(bean.getScope());

        //Already saved in context?
        webbeansInstance = webbeansContext.get(bean);
        if (webbeansInstance != null)
        {
            // voila, we are finished if we found an existing contextual instance
            return webbeansInstance;
        }

        // finally, we create a new contextual instance
        CreationalContext cc = beanManager.createCreationalContext(bean);
        webbeansInstance = webbeansContext.get(bean, cc);

        if (webbeansInstance == null)
        {
            throw new UnproxyableResolutionException("Cannot find a contextual instance of bean " + bean.toString());
        }
View Full Code Here

    }

    @Test(groups = LIFECYCLE)
    @SpecAssertions({ @SpecAssertion(section = "6.5.2", id = "a"), @SpecAssertion(section = "6.5.2", id = "b") })
    public void testContextCreatesNewInstanceForInjection() {
        Context requestContext = getCurrentManager().getContext(RequestScoped.class);
        Bean<Tuna> tunaBean = getBeans(Tuna.class).iterator().next();
        assert requestContext.get(tunaBean) == null;
        TunaFarm tunaFarm = getCurrentConfiguration().getEl().evaluateValueExpression(getCurrentManager(), "#{tunaFarm}",
                TunaFarm.class);
        assert tunaFarm.tuna != null;
        long timestamp = tunaFarm.tuna.getTimestamp();
        // Lookup once again - do not create new instance - contextual instance already exists
        Tuna tuna = requestContext.get(tunaBean);
        assert tuna != null;
        assert timestamp == tuna.getTimestamp();
    }
View Full Code Here

    @Test(groups = INTEGRATION, expectedExceptions = { ContextNotActiveException.class, IllegalStateException.class })
    @SpecAssertions({ @SpecAssertion(section = "5.4.2", id = "ab"), @SpecAssertion(section = "6.5.4", id = "a") })
    public void testInactiveScope() throws Exception {
        assert getCurrentConfiguration().getContexts().getRequestContext().isActive();
        Context ctx = getCurrentConfiguration().getContexts().getRequestContext();
        setContextInactive(ctx);
        assert !getCurrentConfiguration().getContexts().getRequestContext().isActive();
        try {
            getInstanceByType(TunedTuna.class).getState();
        } finally {
View Full Code Here

    }

    @Test
    @SpecAssertion(section = "11.5.2", id = "f")
    public void testAddContext() {
        Context context = getCurrentManager().getContext(SuperScoped.class);
        assertNotNull(context);
        assertTrue(context.isActive());
        assertTrue(context instanceof SuperContext);
    }
View Full Code Here

    @SpecAssertion(section = "6.4", id = "e")
    public void testContextGetWithCreationalContextReturnsNewInstance() {
        Set<Bean<Fox>> foxBeans = getBeans(Fox.class);
        assert foxBeans.size() == 1;
        Bean<Fox> foxBean = foxBeans.iterator().next();
        Context context = getCurrentManager().getContext(Dependent.class);
        assert context.get(foxBean, new MockCreationalContext<Fox>()) != null;
        assert context.get(foxBean, new MockCreationalContext<Fox>()) instanceof Fox;
    }
View Full Code Here

    @SpecAssertion(section = "6.4", id = "f")
    public void testContextGetWithCreateFalseReturnsNull() {
        Set<Bean<Fox>> foxBeans = getBeans(Fox.class);
        assert foxBeans.size() == 1;
        Bean<Fox> foxBean = foxBeans.iterator().next();
        Context context = getCurrentManager().getContext(Dependent.class);
        assert context.get(foxBean, null) == null;
    }
View Full Code Here

    @Test
    @SpecAssertion(section = "6.2", id = "r")
    public void testDestroyForSameCreationalContextOnly() {
        // Check that the mock cc is called (via cc.release()) when we request a context destroyed
        // Note that this is an indirect effect
        Context sessionContext = getCurrentManager().getContext(SessionScoped.class);

        Bean<AnotherSessionBean> sessionBean = getBeans(AnotherSessionBean.class).iterator().next();

        MockCreationalContext.reset();
        CreationalContext<AnotherSessionBean> creationalContext = new MockCreationalContext<AnotherSessionBean>();
        AnotherSessionBean instance = sessionContext.get(sessionBean, creationalContext);
        instance.ping();

        destroyContext(sessionContext);
        assert MockCreationalContext.isReleaseCalled();
View Full Code Here

    @Test(groups = { CONTEXTS })
    @SpecAssertions({ @SpecAssertion(section = "2.4.1", id = "aa"), @SpecAssertion(section = "2.4.1", id = "ab"),
            @SpecAssertion(section = "2.4.1", id = "ac"), @SpecAssertion(section = "2.4.1", id = "ca"),
            @SpecAssertion(section = "11.3.15", id = "a") })
    public void testBuiltInContexts() {
        Context context = getCurrentManager().getContext(Dependent.class);
        assert context != null;
        context = getCurrentManager().getContext(RequestScoped.class);
        assert context != null;
        context = getCurrentManager().getContext(SessionScoped.class);
        assert context != null;
View Full Code Here

        assert getBeans(MySessionBean.class).size() == 1;
        Bean<MySessionBean> mySessionBean = getBeans(MySessionBean.class).iterator().next();
        CreationalContext<MySessionBean> sessionCreationalContext = getCurrentManager().createCreationalContext(mySessionBean);
        MySessionBean beanInstance = mySessionBean.create(sessionCreationalContext);
        assert beanInstance != null;
        Context sessionContext = getCurrentManager().getContext(SessionScoped.class);
        destroyContext(sessionContext);
        setContextActive(sessionContext);

        beanInstance = sessionContext.get(mySessionBean);
        assert beanInstance == null;
    }
View Full Code Here

TOP

Related Classes of javax.enterprise.context.spi.Context

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.