[seam-commits] Seam SVN: r8620 - in trunk/src: main/org/jboss/seam/navigation and 2 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Wed Aug 6 23:44:42 EDT 2008
Author: jacob.orshalick
Date: 2008-08-06 23:44:41 -0400 (Wed, 06 Aug 2008)
New Revision: 8620
Added:
trunk/src/test/unit/org/jboss/seam/test/unit/AbstractPageTest.java
trunk/src/test/unit/org/jboss/seam/test/unit/PageDescriptionsTest.java
Modified:
trunk/src/main/org/jboss/seam/faces/FacesManager.java
trunk/src/main/org/jboss/seam/navigation/Pages.java
trunk/src/test/unit/META-INF/pagesForPageActionsTest.xml
trunk/src/test/unit/org/jboss/seam/test/unit/PageActionsTest.java
trunk/src/test/unit/org/jboss/seam/test/unit/testng.xml
Log:
JBSEAM-2432
Modified: trunk/src/main/org/jboss/seam/faces/FacesManager.java
===================================================================
--- trunk/src/main/org/jboss/seam/faces/FacesManager.java 2008-08-06 19:18:35 UTC (rev 8619)
+++ trunk/src/main/org/jboss/seam/faces/FacesManager.java 2008-08-07 03:44:41 UTC (rev 8620)
@@ -279,6 +279,10 @@
{
conversation.setDescription( pageEntry.renderDescription() );
}
+ else if(pages.hasDescription(viewId))
+ {
+ conversation.setDescription( pages.renderDescription(viewId) );
+ }
conversation.setTimeout( pages.getTimeout(viewId) );
}
}
Modified: trunk/src/main/org/jboss/seam/navigation/Pages.java
===================================================================
--- trunk/src/main/org/jboss/seam/navigation/Pages.java 2008-08-06 19:18:35 UTC (rev 8619)
+++ trunk/src/main/org/jboss/seam/navigation/Pages.java 2008-08-07 03:44:41 UTC (rev 8620)
@@ -42,6 +42,7 @@
import org.jboss.seam.core.Events;
import org.jboss.seam.core.Expressions;
import org.jboss.seam.core.Init;
+import org.jboss.seam.core.Interpolator;
import org.jboss.seam.core.Manager;
import org.jboss.seam.core.ResourceLoader;
import org.jboss.seam.core.Expressions.MethodExpression;
@@ -567,8 +568,29 @@
if (page.getScheme() != null) return page.getScheme();
}
return null;
- }
+ }
+ public boolean hasDescription(String viewId)
+ {
+ return getDescription(viewId)!=null;
+ }
+
+ public String getDescription(String viewId)
+ {
+ List<Page> stack = getPageStack(viewId);
+ for ( int i = stack.size() - 1; i >= 0; i-- )
+ {
+ Page page = stack.get(i);
+ if (page.hasDescription()) return page.getDescription();
+ }
+ return null;
+ }
+
+ public String renderDescription(String viewId)
+ {
+ return Interpolator.instance().interpolate( getDescription(viewId) );
+ }
+
protected void noConversation()
{
Events.instance().raiseEvent("org.jboss.seam.noConversation");
Modified: trunk/src/test/unit/META-INF/pagesForPageActionsTest.xml
===================================================================
--- trunk/src/test/unit/META-INF/pagesForPageActionsTest.xml 2008-08-06 19:18:35 UTC (rev 8619)
+++ trunk/src/test/unit/META-INF/pagesForPageActionsTest.xml 2008-08-07 03:44:41 UTC (rev 8620)
@@ -10,10 +10,12 @@
</page>
<page view-id="/action-test01b.xhtml" action="#{testActions.nonNullActionA}">
+ <description>#{fineDescription}</description>
<action execute="#{testActions.nonNullActionB}" />
</page>
<page view-id="/action-test01*">
+ <description>coarse-description</description>
<navigation from-action="#{testActions.nonNullActionA}">
<rule if-outcome="outcomeA">
<render view-id="/pageA.xhtml" />
Added: trunk/src/test/unit/org/jboss/seam/test/unit/AbstractPageTest.java
===================================================================
--- trunk/src/test/unit/org/jboss/seam/test/unit/AbstractPageTest.java (rev 0)
+++ trunk/src/test/unit/org/jboss/seam/test/unit/AbstractPageTest.java 2008-08-07 03:44:41 UTC (rev 8620)
@@ -0,0 +1,86 @@
+package org.jboss.seam.test.unit;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.seam.Component;
+import org.jboss.seam.Seam;
+import org.jboss.seam.contexts.Context;
+import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.contexts.FacesLifecycle;
+import org.jboss.seam.contexts.Lifecycle;
+import org.jboss.seam.core.Expressions;
+import org.jboss.seam.core.Init;
+import org.jboss.seam.core.Interpolator;
+import org.jboss.seam.core.ResourceLoader;
+import org.jboss.seam.mock.MockApplication;
+import org.jboss.seam.mock.MockExternalContext;
+import org.jboss.seam.mock.MockFacesContext;
+import org.jboss.seam.navigation.Pages;
+import org.jboss.seam.test.unit.PageActionsTest.NoRedirectFacesManager;
+import org.jboss.seam.test.unit.component.TestActions;
+import org.jboss.seam.util.Conversions;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+
+/**
+ * Abstract class that provides the setup and tear-down necessary to initialize the context for performing tests
+ * against the Pages component.
+ */
+public abstract class AbstractPageTest
+{
+ @BeforeMethod
+ public void setup()
+ {
+ // create main application map
+ Lifecycle.beginApplication(new HashMap<String, Object>());
+
+ // start all the contexts
+ Lifecycle.beginCall();
+
+ // establish the FacesContext
+ new MockFacesContext(new MockExternalContext(), new MockApplication()).setCurrent().createViewRoot();
+ FacesLifecycle.resumePage();
+
+ // install key components
+ installComponents(Contexts.getApplicationContext());
+
+ // initialize pages
+ // the descriptor file locations are set using the property: org.jboss.seam.navigation.pages.resources
+ // this setup of this test sets this property value to: /META-INF/pagesForPageActionsTest.xml
+ Pages.instance();
+
+ // mark the application as started
+ Lifecycle.mockApplication();
+ }
+
+ @AfterMethod
+ public void tearDown()
+ {
+ Lifecycle.endApplication();
+ Lifecycle.unmockApplication();
+ }
+
+ private void installComponents(Context appContext)
+ {
+ Init init = new Init();
+ init.setTransactionManagementEnabled(false);
+ 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"));
+
+ installComponent(appContext, NoRedirectFacesManager.class);
+ installComponent(appContext, ResourceLoader.class);
+ installComponent(appContext, Expressions.class);
+ installComponent(appContext, Pages.class);
+ installComponent(appContext, Interpolator.class);
+
+ installComponent(appContext, TestActions.class);
+ }
+
+ private void installComponent(Context appContext, Class clazz)
+ {
+ appContext.set(Seam.getComponentName(clazz) + ".component", new Component(clazz));
+ }
+}
Modified: trunk/src/test/unit/org/jboss/seam/test/unit/PageActionsTest.java
===================================================================
--- trunk/src/test/unit/org/jboss/seam/test/unit/PageActionsTest.java 2008-08-06 19:18:35 UTC (rev 8619)
+++ trunk/src/test/unit/org/jboss/seam/test/unit/PageActionsTest.java 2008-08-07 03:44:41 UTC (rev 8620)
@@ -2,30 +2,16 @@
import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
-import org.jboss.seam.Seam;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
-import org.jboss.seam.contexts.Context;
import org.jboss.seam.contexts.Contexts;
-import org.jboss.seam.contexts.FacesLifecycle;
-import org.jboss.seam.contexts.Lifecycle;
-import org.jboss.seam.core.Expressions;
-import org.jboss.seam.core.Init;
-import org.jboss.seam.core.ResourceLoader;
import org.jboss.seam.faces.FacesManager;
-import org.jboss.seam.mock.MockApplication;
-import org.jboss.seam.mock.MockExternalContext;
-import org.jboss.seam.mock.MockFacesContext;
import org.jboss.seam.navigation.Pages;
import org.jboss.seam.test.unit.component.TestActions;
-import org.jboss.seam.util.Conversions;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import javax.faces.context.FacesContext;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -34,40 +20,8 @@
* a page action triggers a navigation event, subsequent page actions in the chain
* should be short circuited.
*/
-public class PageActionsTest
+public class PageActionsTest extends AbstractPageTest
{
- @BeforeMethod
- public void setup()
- {
- // create main application map
- Lifecycle.beginApplication(new HashMap<String, Object>());
-
- // start all the contexts
- Lifecycle.beginCall();
-
- // establish the FacesContext
- new MockFacesContext(new MockExternalContext(), new MockApplication()).setCurrent().createViewRoot();
- FacesLifecycle.resumePage();
-
- // install key components
- installComponents(Contexts.getApplicationContext());
-
- // initialize pages
- // the descriptor file locations are set using the property: org.jboss.seam.navigation.pages.resources
- // this setup of this test sets this property value to: /META-INF/pagesForPageActionsTest.xml
- Pages.instance();
-
- // mark the application as started
- Lifecycle.mockApplication();
- }
-
- @AfterMethod
- public void tearDown()
- {
- Lifecycle.endApplication();
- Lifecycle.unmockApplication();
- }
-
/**
* This test verifies that a non-null outcome will short-circuit the page
* actions. It tests two difference variations. The first variation includes
@@ -214,28 +168,6 @@
Contexts.getEventContext().remove(Component.getComponentName(TestActions.class));
}
- private void installComponents(Context appContext)
- {
- Init init = new Init();
- init.setTransactionManagementEnabled(false);
- 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"));
-
- installComponent(appContext, NoRedirectFacesManager.class);
- installComponent(appContext, ResourceLoader.class);
- installComponent(appContext, Expressions.class);
- installComponent(appContext, Pages.class);
-
- installComponent(appContext, TestActions.class);
- }
-
- private void installComponent(Context appContext, Class clazz)
- {
- appContext.set(Seam.getComponentName(clazz) + ".component", new Component(clazz));
- }
-
@Scope(ScopeType.EVENT)
@Name("org.jboss.seam.core.manager")
@BypassInterceptors
Added: trunk/src/test/unit/org/jboss/seam/test/unit/PageDescriptionsTest.java
===================================================================
--- trunk/src/test/unit/org/jboss/seam/test/unit/PageDescriptionsTest.java (rev 0)
+++ trunk/src/test/unit/org/jboss/seam/test/unit/PageDescriptionsTest.java 2008-08-07 03:44:41 UTC (rev 8620)
@@ -0,0 +1,45 @@
+package org.jboss.seam.test.unit;
+
+import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.navigation.Pages;
+import org.testng.annotations.Test;
+
+/**
+ * This test verifies that the descriptions returned by the Pages component are based on the matching
+ * Page definition as well as any matching wild-card pages in the page stack.
+ *
+ */
+public class PageDescriptionsTest extends AbstractPageTest
+{
+ /**
+ * Verify that the Pages component determines when a description exists in the Page stack and when
+ * it does not.
+ */
+ @Test(enabled = true)
+ public void testHasDescription()
+ {
+ Pages pages = Pages.instance();
+
+ assert pages.hasDescription("/action-test01b.xhtml");
+ assert pages.hasDescription("/action-test01a.xhtml");
+ assert !pages.hasDescription("/action-test02.xhtml");
+ }
+
+ /**
+ * Verify that the description can be retrieved from the page stack when a wild-card view-id
+ * description has been specified. Also verifies that a description specific to a page overrides
+ * the wild-card description.
+ */
+ @Test(enabled = true)
+ public void testGetAndResolveDescription()
+ {
+ Pages pages = Pages.instance();
+ String fineDescription = "fine-description";
+ Contexts.getEventContext().set("fineDescription", fineDescription);
+
+ assert "coarse-description".equals(pages.getDescription("/action-test01a.xhtml")) :
+ "Expecting the wild-card description to be returned as no description was provided for the view-id";
+ assert fineDescription.equals(pages.renderDescription("/action-test01b.xhtml")) :
+ "Expecting the description for the view-id to be returned";
+ }
+}
Modified: trunk/src/test/unit/org/jboss/seam/test/unit/testng.xml
===================================================================
--- trunk/src/test/unit/org/jboss/seam/test/unit/testng.xml 2008-08-06 19:18:35 UTC (rev 8619)
+++ trunk/src/test/unit/org/jboss/seam/test/unit/testng.xml 2008-08-07 03:44:41 UTC (rev 8620)
@@ -29,6 +29,7 @@
<test name="Seam Unit Tests: Pages dot xml">
<classes>
<class name="org.jboss.seam.test.unit.PageActionsTest" />
+ <class name="org.jboss.seam.test.unit.PageDescriptionsTest" />
<class name="org.jboss.seam.test.unit.PageParamTest" />
</classes>
</test>
More information about the seam-commits
mailing list