Package org.apache.myfaces.orchestra.conversation

Examples of org.apache.myfaces.orchestra.conversation.SimpleBean


        // The Spring configuration for dummyBean does not explicitly set a conversation name,
        // so conversation-name = bean-name
        final String CONVERSATION_NAME = BEAN_NAME;

        // create a proxy (but not the underlying bean)
        SimpleBean proxy = (SimpleBean) applicationContext.getBean(BEAN_NAME);

        assertTrue("should be a scoped object", proxy instanceof ScopedObject);
        assertFalse("conversation should not have been started yet", ConversationManager.getInstance().hasConversation(CONVERSATION_NAME));

        // Invoke a method on the proxy, forcing the real object to be created
        proxy.getData();
        assertTrue("conversation should have been started", ConversationManager.getInstance().hasConversation(CONVERSATION_NAME));

        // Obtain a reference to the real bean. The proxy and real bean will be different objects.
        SimpleBean real = (SimpleBean) _SpringUtils.getRealBean(proxy);
        assertTrue(real != proxy);
       
        // Check that the proxy maps to the real object by modifying via the proxy and reading via
        // the direct reference, and vice-versa
        assertEquals(null, real.getData());
        proxy.setData("proxy");
        assertEquals("proxy", real.getData());
        real.setData("real");
        assertEquals("real", proxy.getData());

        // After invalidating the conversation and recreating the bean, the proxy and
        // real are no longer the same object.
        Conversation conv = ConversationManager.getInstance().getConversation(CONVERSATION_NAME);
        conv.invalidate();
        proxy.setData("proxy");
        assertEquals("real", real.getData());
        real.setData("real");
        assertEquals("proxy", proxy.getData());
    }
View Full Code Here


        // The Spring configuration for dummyBean does not explicitly set a conversation name,
        // so conversation-name = bean-name
        final String CONVERSATION_NAME = BEAN_NAME;

        // create a scoped-proxy (but not the underlying bean)
        SimpleBean scopedProxy = (SimpleBean) applicationContext.getBean(BEAN_NAME);

        assertTrue("should be a scoped object", scopedProxy instanceof ScopedObject);
        assertTrue("should be a proxy", scopedProxy instanceof SpringProxy);
        assertFalse("conversation should not have been started yet", ConversationManager.getInstance().hasConversation(CONVERSATION_NAME));

        // Invoke a method on the scoped-proxy, forcing the conversation-proxy to be created, which will in turn
        // force the real bean to be created. The name "conversation-proxy" means the proxy to which the advices
        // are attached, including the CurrentConversationAdvice which sets up the conversation before the real
        // bean is invoked.
        scopedProxy.getData();
        assertTrue("conversation should have been started", ConversationManager.getInstance().hasConversation(CONVERSATION_NAME));

        // Obtain a reference to the conversation-proxy bean. The scoped-proxy and conversation-proxy will be different objects.
        SimpleBean convProxy = (SimpleBean) _SpringUtils.getTargetObject(scopedProxy);
        assertTrue("should be a proxy", convProxy instanceof SpringProxy);
        assertTrue(convProxy != scopedProxy);

        // Just for fun, obtain a reference to the real actual bean too.
        SimpleBean realBean = (SimpleBean) _SpringUtils.getTargetObject(convProxy);
        assertFalse("should not be a proxy", realBean instanceof SpringProxy);
        assertTrue(realBean != convProxy);

        // Check that the scoped-proxy maps all method-calls to the conversation-proxy which in turn maps the
        // real object by modifying data on the underlying object then reading  via the indirect reference, and
        // vice-versa
        assertEquals(null, convProxy.getData());
        scopedProxy.setData("proxy");
        assertEquals("proxy", realBean.getData());
        realBean.setData("real");
        assertEquals("real", scopedProxy.getData());

        // After invalidating the conversation and recreating the bean, the scopedProxy no longer refers
        // to the same object.
        Conversation conv = ConversationManager.getInstance().getConversation(CONVERSATION_NAME);
        conv.invalidate();
        assertEquals(null, scopedProxy.getData()); // this is a new object with reset data property
        SimpleBean newConvProxy = (SimpleBean) _SpringUtils.getTargetObject(scopedProxy);
        assertNotSame(convProxy, newConvProxy);

        // Writing via the proxy no longer touches the original realBean
        scopedProxy.setData("proxy");
        assertTrue("proxy".equals(scopedProxy.getData()));
View Full Code Here

TOP

Related Classes of org.apache.myfaces.orchestra.conversation.SimpleBean

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.