[seam-commits] Seam SVN: r8992 - in trunk/src: main/org/jboss/seam/navigation and 2 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Sun Sep 14 21:49:00 EDT 2008


Author: jacob.orshalick
Date: 2008-09-14 21:49:00 -0400 (Sun, 14 Sep 2008)
New Revision: 8992

Added:
   trunk/src/test/unit/org/jboss/seam/test/unit/PageConversationControlTest.java
Modified:
   trunk/src/main/org/jboss/seam/navigation/ConversationControl.java
   trunk/src/main/org/jboss/seam/navigation/Pages.java
   trunk/src/main/org/jboss/seam/pages-2.1.xsd
   trunk/src/test/unit/META-INF/pagesForPageActionsTest.xml
   trunk/src/test/unit/org/jboss/seam/test/unit/AbstractPageTest.java
Log:
JBSEAM-1943 added pages.xml support

Modified: trunk/src/main/org/jboss/seam/navigation/ConversationControl.java
===================================================================
--- trunk/src/main/org/jboss/seam/navigation/ConversationControl.java	2008-09-14 17:16:48 UTC (rev 8991)
+++ trunk/src/main/org/jboss/seam/navigation/ConversationControl.java	2008-09-15 01:49:00 UTC (rev 8992)
@@ -3,6 +3,7 @@
 import org.jboss.seam.core.Conversation;
 import org.jboss.seam.core.ConversationEntries;
 import org.jboss.seam.core.ConversationEntry;
+import org.jboss.seam.core.Manager;
 import org.jboss.seam.core.Expressions.ValueExpression;
 import org.jboss.seam.pageflow.Pageflow;
 /**
@@ -16,6 +17,7 @@
    private boolean isBeginConversation;
    private boolean isEndConversation;
    private boolean isEndConversationBeforeRedirect;
+   private boolean isEndRootConversation;
    private boolean join;
    private boolean nested;
    private FlushModeType flushMode;
@@ -44,13 +46,20 @@
    {
       if ( endConversation() )
       {
+         Conversation conversation = Conversation.instance();
+         
+         if (isEndRootConversation && conversation.isNested())
+         {
+            conversation.root();
+         }
+
          if (isEndConversationBeforeRedirect)
          {
-            Conversation.instance().endBeforeRedirect();
+            conversation.endBeforeRedirect();
          }
          else
          {
-            Conversation.instance().end();
+            conversation.end();
          }
       }
       if ( beginConversation() )
@@ -131,6 +140,14 @@
    {
       this.isEndConversationBeforeRedirect = isEndConversationBeforeRedirect;
    }
+   public boolean isEndRootConversation()
+   {
+      return isEndConversationBeforeRedirect;
+   }
+   public void setEndRootConversation(boolean isEndRootConversation)
+   {
+      this.isEndRootConversation = isEndRootConversation;
+   }
    public ValueExpression<Boolean> getBeginConversationCondition()
    {
       return beginConversationCondition;

Modified: trunk/src/main/org/jboss/seam/navigation/Pages.java
===================================================================
--- trunk/src/main/org/jboss/seam/navigation/Pages.java	2008-09-14 17:16:48 UTC (rev 8991)
+++ trunk/src/main/org/jboss/seam/navigation/Pages.java	2008-09-15 01:49:00 UTC (rev 8992)
@@ -1267,6 +1267,7 @@
       {
          control.setEndConversation(true);
          control.setEndConversationBeforeRedirect( "true".equals( endConversation.attributeValue("before-redirect") ) );
+         control.setEndRootConversation( "true".equals( endConversation.attributeValue("root") ) );
          String expression = endConversation.attributeValue("if");
          if (expression!=null)
          {

Modified: trunk/src/main/org/jboss/seam/pages-2.1.xsd
===================================================================
--- trunk/src/main/org/jboss/seam/pages-2.1.xsd	2008-09-14 17:16:48 UTC (rev 8991)
+++ trunk/src/main/org/jboss/seam/pages-2.1.xsd	2008-09-15 01:49:00 UTC (rev 8992)
@@ -325,6 +325,14 @@
                     <xs:enumeration value="false"/>
                 </xs:restriction>
             </xs:simpleType>
+        </xs:attribute>
+        <xs:attribute name="root" default="false">
+            <xs:simpleType>
+                <xs:restriction base="xs:token">
+                    <xs:enumeration value="true"/>
+                    <xs:enumeration value="false"/>
+                </xs:restriction>
+            </xs:simpleType>
         </xs:attribute>
         <xs:attribute name="if"/>
     </xs:attributeGroup>

Modified: trunk/src/test/unit/META-INF/pagesForPageActionsTest.xml
===================================================================
--- trunk/src/test/unit/META-INF/pagesForPageActionsTest.xml	2008-09-14 17:16:48 UTC (rev 8991)
+++ trunk/src/test/unit/META-INF/pagesForPageActionsTest.xml	2008-09-15 01:49:00 UTC (rev 8992)
@@ -108,5 +108,13 @@
 			</rule>
 		</navigation>
 	</page>
+	
+	<page view-id="/end-conversation-test.xhtml">
+		<end-conversation />
+	</page>
+	
+	<page view-id="/end-root-conversation-test.xhtml">
+		<end-conversation root="true" />
+	</page>
 
 </pages>

Modified: trunk/src/test/unit/org/jboss/seam/test/unit/AbstractPageTest.java
===================================================================
--- trunk/src/test/unit/org/jboss/seam/test/unit/AbstractPageTest.java	2008-09-14 17:16:48 UTC (rev 8991)
+++ trunk/src/test/unit/org/jboss/seam/test/unit/AbstractPageTest.java	2008-09-15 01:49:00 UTC (rev 8992)
@@ -29,6 +29,8 @@
  */
 public abstract class AbstractPageTest
 {
+   private static final String TEST_PAGES_DOT_XML = "/META-INF/pagesForPageActionsTest.xml";
+   
    @BeforeMethod
    public void setup()
    {
@@ -68,7 +70,7 @@
       appContext.set(Seam.getComponentName(Init.class), init);
       Map<String, Conversions.PropertyValue> properties = new HashMap<String, Conversions.PropertyValue>();
       appContext.set(Component.PROPERTIES, properties);
-      properties.put(Seam.getComponentName(Pages.class) + ".resources", new Conversions.FlatPropertyValue("/META-INF/pagesForPageActionsTest.xml"));
+      properties.put(Seam.getComponentName(Pages.class) + ".resources", new Conversions.FlatPropertyValue(TEST_PAGES_DOT_XML));
 
       installComponent(appContext, NoRedirectFacesManager.class);
       installComponent(appContext, ResourceLoader.class);
@@ -79,7 +81,13 @@
       installComponent(appContext, TestActions.class);
    }
 
-   private void installComponent(Context appContext, Class clazz)
+   /**
+    * Installs a component for use in the current test context.
+    * 
+    * @param appContext
+    * @param clazz
+    */
+   protected void installComponent(Context appContext, Class clazz)
    {
       appContext.set(Seam.getComponentName(clazz) + ".component", new Component(clazz));
    }

Added: trunk/src/test/unit/org/jboss/seam/test/unit/PageConversationControlTest.java
===================================================================
--- trunk/src/test/unit/org/jboss/seam/test/unit/PageConversationControlTest.java	                        (rev 0)
+++ trunk/src/test/unit/org/jboss/seam/test/unit/PageConversationControlTest.java	2008-09-15 01:49:00 UTC (rev 8992)
@@ -0,0 +1,105 @@
+package org.jboss.seam.test.unit;
+
+import javax.faces.context.FacesContext;
+import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.contexts.FacesLifecycle;
+import org.jboss.seam.core.Conversation;
+import org.jboss.seam.core.ConversationEntries;
+import org.jboss.seam.core.Events;
+import org.jboss.seam.core.Manager;
+import org.jboss.seam.faces.FacesMessages;
+import org.jboss.seam.navigation.Pages;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * Tests that validate the ConversationControl component as initialized for a Page instance.
+ * 
+ * @author Jacob Orshalick
+ */
+public class PageConversationControlTest extends AbstractPageTest
+{
+   /**
+    * Override the base setup to add the required conversation components included in testing.
+    */
+   @BeforeMethod
+   @Override
+   public void setup()
+   {
+      super.setup();
+      
+      installComponent(Contexts.getApplicationContext(), ConversationEntries.class);
+      installComponent(Contexts.getApplicationContext(), Conversation.class);
+      installComponent(Contexts.getApplicationContext(), FacesMessages.class);
+      installComponent(Contexts.getApplicationContext(), Manager.class);
+      installComponent(Contexts.getApplicationContext(), Events.class);
+      
+      Manager.instance().initializeTemporaryConversation();
+      FacesLifecycle.resumeConversation(FacesContext.getCurrentInstance().getExternalContext());
+   }
+
+   /**
+    * Tests that when a nested conversation encounters an end-conversation tag the nested conversation is
+    * demoted to temporary.
+    */
+   @Test
+   public void testBeginNestedAndEndConversation() {
+      Manager.instance().beginConversation();
+      Manager.instance().beginNestedConversation();
+      
+      assert Manager.instance().isLongRunningConversation();
+      assert Manager.instance().isNestedConversation();
+      
+      FacesContext facesContext = FacesContext.getCurrentInstance();
+
+      facesContext.getViewRoot().setViewId("/end-conversation-test.xhtml");
+      Pages.instance().preRender(facesContext);
+      
+      // nested conversation should be demoted to temporary
+      assert !Manager.instance().isLongRunningConversation();
+      assert Manager.instance().isNestedConversation();
+   }
+   
+   /**
+    * Tests that when a non-nested conversation encounters an end-conversation tag specifying that the root 
+    * should be ended the current conversation is simply demoted to temporary.
+    */
+   @Test
+   public void testBeginAndEndRootConversation() {
+      Manager.instance().beginConversation();
+      
+      assert Manager.instance().isLongRunningConversation();
+      
+      FacesContext facesContext = FacesContext.getCurrentInstance();
+
+      facesContext.getViewRoot().setViewId("/end-root-conversation-test.xhtml");
+      Pages.instance().preRender(facesContext);
+      
+      assert !Manager.instance().isLongRunningConversation();
+   }
+   
+   /**
+    * Tests that when a nested conversation encounters an end-conversation tag specifying that the root 
+    * should be ended the root is ended thereby destroying the conversation stack.
+    */
+   @Test
+   public void testBeginNestedAndEndRootConversation() {
+      Manager.instance().beginConversation();
+      String rootConversationId = Manager.instance().getCurrentConversationId();
+      
+      Manager.instance().beginNestedConversation();
+
+      assert !Manager.instance().getCurrentConversationId().equals(rootConversationId);
+      assert Manager.instance().isLongRunningConversation();
+      assert Manager.instance().isNestedConversation();
+      
+      FacesContext facesContext = FacesContext.getCurrentInstance();
+
+      facesContext.getViewRoot().setViewId("/end-root-conversation-test.xhtml");
+      Pages.instance().preRender(facesContext);
+
+      assert Manager.instance().getCurrentConversationId().equals(rootConversationId);
+      assert !Manager.instance().isLongRunningConversation();
+      assert !Manager.instance().isNestedConversation();
+   }
+}




More information about the seam-commits mailing list