You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sk...@apache.org on 2008/10/08 14:40:20 UTC

svn commit: r702846 - /myfaces/orchestra/trunk/core/src/test/java/org/apache/myfaces/orchestra/conversation/spring/TestSpringUtils.java

Author: skitching
Date: Wed Oct  8 05:40:20 2008
New Revision: 702846

URL: http://svn.apache.org/viewvc?rev=702846&view=rev
Log:
Improve unit test

Modified:
    myfaces/orchestra/trunk/core/src/test/java/org/apache/myfaces/orchestra/conversation/spring/TestSpringUtils.java

Modified: myfaces/orchestra/trunk/core/src/test/java/org/apache/myfaces/orchestra/conversation/spring/TestSpringUtils.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/test/java/org/apache/myfaces/orchestra/conversation/spring/TestSpringUtils.java?rev=702846&r1=702845&r2=702846&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/test/java/org/apache/myfaces/orchestra/conversation/spring/TestSpringUtils.java (original)
+++ myfaces/orchestra/trunk/core/src/test/java/org/apache/myfaces/orchestra/conversation/spring/TestSpringUtils.java Wed Oct  8 05:40:20 2008
@@ -73,21 +73,30 @@
         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 advisedProxy to be created, which will in turn
-        // force the real bean to be created.
+        // 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 real-proxy bean. The scoped-proxy and conversation-proxy will be different objects.
+        // 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);
-        
-        // Check that the proxy maps all method-calls to the real object by modifying data on the underlying
-        // object then reading  via the indirect reference, and vice-versa
+
+        // 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", convProxy.getData());
-        convProxy.setData("real");
+        assertEquals("proxy", realBean.getData());
+        realBean.setData("real");
         assertEquals("real", scopedProxy.getData());
 
         // After invalidating the conversation and recreating the bean, the scopedProxy no longer refers
@@ -98,6 +107,11 @@
         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()));
+        assertFalse("proxy".equals(realBean.getData()));
+        
         // And accessing the old proxy is no longer allowed. Note that this condition isn't normally
         // possible in user code as users don't use non-public api _SpringUtils.getTargetObject to
         // unwrap proxies.