You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by cr...@apache.org on 2005/05/01 06:27:29 UTC

svn commit: r165455 - in /struts/shale/trunk/core-library: ./ src/test/ src/test/org/ src/test/org/apache/ src/test/org/apache/shale/ src/test/org/apache/shale/dialog/ src/test/org/apache/shale/dialog/faces/

Author: craigmcc
Date: Sat Apr 30 21:27:28 2005
New Revision: 165455

URL: http://svn.apache.org/viewcvs?rev=165455&view=rev
Log:
Initial unit tests for the core library, focused on DialogNavigationHandler.

Added:
    struts/shale/trunk/core-library/src/test/
    struts/shale/trunk/core-library/src/test/org/
    struts/shale/trunk/core-library/src/test/org/apache/
    struts/shale/trunk/core-library/src/test/org/apache/shale/
    struts/shale/trunk/core-library/src/test/org/apache/shale/dialog/
    struts/shale/trunk/core-library/src/test/org/apache/shale/dialog/faces/
    struts/shale/trunk/core-library/src/test/org/apache/shale/dialog/faces/DialogNavigationHandlerTestCase.java
    struts/shale/trunk/core-library/src/test/org/apache/shale/dialog/faces/TestBean.java
    struts/shale/trunk/core-library/src/test/org/apache/shale/dialog/faces/dialog-config.xml
Modified:
    struts/shale/trunk/core-library/build.xml

Modified: struts/shale/trunk/core-library/build.xml
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/build.xml?rev=165455&r1=165454&r2=165455&view=diff
==============================================================================
--- struts/shale/trunk/core-library/build.xml (original)
+++ struts/shale/trunk/core-library/build.xml Sat Apr 30 21:27:28 2005
@@ -33,13 +33,15 @@
 
 
   <!-- Dependency home directory defaults -->
-  <property name="shale-test.home"  value="${basedir}/../struts-shale-test/dist"/>
+  <property name="shale-test.home"  value="${basedir}/../test-framework/dist"/>
 
   <!-- Dependency library defaults -->
   <property name="commons-beanutils.jar"
                                     value="${beanutils.home}/commons-beanutils.jar"/>
   <property name="commons-chain.jar"
                                     value="${chain.home}/commons-chain-1.0.jar"/>
+  <property name="commons-collections.jar"
+                                    value="${collections.home}/commons-collections.jar"/>
   <property name="commons-digester.jar"
                                     value="${digester.home}/commons-digester.jar"/>
 <!--
@@ -93,6 +95,7 @@
   <path id="compile.classpath">
     <pathelement location="${commons-beanutils.jar}"/>
     <pathelement location="${commons-chain.jar}"/>
+    <pathelement location="${commons-collections.jar}"/>
     <pathelement location="${commons-digester.jar}"/>
 <!--
     <pathelement location="${commons-fileupload.jar}"/>
@@ -115,6 +118,7 @@
   <path id="findbugs.classpath">
     <pathelement location="${commons-beanutils.jar}"/>
     <pathelement location="${commons-chain.jar}"/>
+    <pathelement location="${commons-collections.jar}"/>
     <pathelement location="${commons-digester.jar}"/>
     <pathelement location="${commons-logging.jar}"/>
     <pathelement location="${findbugs.home}/lib/findbugs-ant.jar"/>
@@ -132,6 +136,7 @@
   <path id="test.classpath">
     <pathelement location="${commons-beanutils.jar}"/>
     <pathelement location="${commons-chain.jar}"/>
+    <pathelement location="${commons-collections.jar}"/>
     <pathelement location="${commons-digester.jar}"/>
 <!--
     <pathelement location="${commons-fileupload.jar}"/>
@@ -190,12 +195,14 @@
     <filter  token="version"  value="${project.version}"/>
     <echo  message="commons-beanutils.jar =  ${commons-beanutils.jar}"/>
     <echo  message="commons-chain.jar =      ${commons-chain.jar}"/>
+    <echo  message="commons-collections.jar =${commons-collections.jar}"/>
     <echo  message="commons-digester.jar =   ${commons-digester.jar}"/>
     <echo  message="commons-logging.jar =    ${commons-logging.jar}"/>
     <echo  message="jsf-api.jar =            ${jsf-api.jar}"/>
     <echo  message="jsf-impl.jar =           ${jsf-impl.jar}"/>
     <echo  message="jsp-api.jar =            ${jsp-api.jar}"/>
     <echo  message="servlet-api.jar =        ${servlet-api.jar}"/>
+    <echo  message="shale-test.jar =         ${shale-test.jar}"/>
     <echo  message="jsfri.present =  ${jsfri.present}"/>
     <echo  message="myfaces.present= ${myfaces.present}"/>
     <echo  message="spring.present=  ${spring.present}"/>
@@ -418,7 +425,7 @@
                usefile="false"/>
       <batchtest  fork="yes">
         <fileset   dir="${build.home}/test-classes"
-              includes="org/apache/shale/*/*TestCase.class"/>
+              includes="org/apache/shale/**/*TestCase.class"/>
       </batchtest>
 
     </junit>

Added: struts/shale/trunk/core-library/src/test/org/apache/shale/dialog/faces/DialogNavigationHandlerTestCase.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/test/org/apache/shale/dialog/faces/DialogNavigationHandlerTestCase.java?rev=165455&view=auto
==============================================================================
--- struts/shale/trunk/core-library/src/test/org/apache/shale/dialog/faces/DialogNavigationHandlerTestCase.java (added)
+++ struts/shale/trunk/core-library/src/test/org/apache/shale/dialog/faces/DialogNavigationHandlerTestCase.java Sat Apr 30 21:27:28 2005
@@ -0,0 +1,284 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shale.dialog.faces;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import junit.framework.TestCase;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.commons.chain.impl.ContextBase;
+import org.apache.shale.dialog.Globals;
+import org.apache.shale.dialog.config.ConfigurationInit;
+import org.apache.shale.test.base.AbstractJsfTestCase;
+import org.apache.shale.test.mock.MockNavigationHandler;
+import org.apache.shale.test.mock.MockPropertyResolver;
+
+/**
+ * <p>Test case for {@link DialogNavigationHandler}.</p>
+ *
+ * $Id$
+ */
+
+public class DialogNavigationHandlerTestCase extends AbstractJsfTestCase {
+
+
+    // ------------------------------------------------------------ Constructors
+
+
+    // Construct a new instance of this test case.
+    public DialogNavigationHandlerTestCase(String name) {
+        super(name);
+    }
+
+
+    // ---------------------------------------------------- Overall Test Methods
+
+
+    // Set up instance variables required by this test case.
+    public void setUp() {
+
+        super.setUp();
+
+        // Configure ourselves as the NavigationHandler for this application
+        orig = (MockNavigationHandler) application.getNavigationHandler();
+        nh = new DialogNavigationHandler(orig);
+        application.setNavigationHandler(nh);
+
+        // Configure the test dialogs we will be using
+        servletContext.addInitParameter
+          (Globals.CONFIGURATION_PARAM,
+           "/org/apache/shale/dialog/faces/dialog-config.xml");
+        Context context = new ContextBase();
+        context.put("context", servletContext);
+        Command command = new ConfigurationInit();
+        try {
+            command.execute(context);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+
+        // Cache an instance of our event handling bean
+        test = new TestBean();
+        externalContext.getRequestMap().put("test", test);
+
+    }
+
+
+    // Return the tests included in this test case.
+    public static Test suite() {
+
+        return (new TestSuite(DialogNavigationHandlerTestCase.class));
+
+    }
+
+
+    // Tear down instance variables required by this test case.
+    public void tearDown() {
+
+        nh = null;
+        orig = null;
+        test = null;
+        super.tearDown();
+
+    }
+
+
+    // ------------------------------------------------------ Instance Variables
+
+
+    // The instance to be tested
+    DialogNavigationHandler nh = null;
+
+
+    // The original NavigationHandler for this application
+    MockNavigationHandler orig = null;
+
+
+    // Test bean for action method calls
+    TestBean test = null;
+
+
+    // ------------------------------------------------------------ Test Methods
+
+
+    // Test explicit transitions on each action
+    public void testExplicitTransitions() {
+
+        // Estabish origin point
+        facesContext.setViewRoot
+          (facesContext.getApplication().getViewHandler().createView(facesContext, "/page1.jsp"));
+        assertEquals("/page1.jsp", facesContext.getViewRoot().getViewId());
+
+        // Execute navigation
+        nh.handleNavigation(facesContext, null, "dialog:testExplicitTransitions");
+
+        // Confirm outcome
+        assertEquals("/first/previous/next/last", test.log());
+
+    }
+
+
+    // Test implicit transitions on each action
+    public void testImplicitTransitions() {
+
+        // Estabish origin point
+        facesContext.setViewRoot
+          (facesContext.getApplication().getViewHandler().createView(facesContext, "/page1.jsp"));
+        assertEquals("/page1.jsp", facesContext.getViewRoot().getViewId());
+
+        // Execute navigation
+        nh.handleNavigation(facesContext, null, "dialog:testImplicitTransitions");
+
+        // Confirm outcome
+        assertEquals("/first/previous/next/last", test.log());
+
+    }
+
+
+    // Test mixture of explicit and implicit transitions on each action
+    public void testMixedTransitions() {
+
+        // Estabish origin point
+        facesContext.setViewRoot
+          (facesContext.getApplication().getViewHandler().createView(facesContext, "/page1.jsp"));
+        assertEquals("/page1.jsp", facesContext.getViewRoot().getViewId());
+
+        // Execute navigation
+        nh.handleNavigation(facesContext, null, "dialog:testMixedTransitions");
+
+        // Confirm outcome
+        assertEquals("/first/previous/next/last", test.log());
+
+    }
+
+
+    // Test nested subdialog
+    public void testNestedSubdialog() {
+
+        // Estabish origin point
+        facesContext.setViewRoot
+          (facesContext.getApplication().getViewHandler().createView(facesContext, "/page1.jsp"));
+        assertEquals("/page1.jsp", facesContext.getViewRoot().getViewId());
+
+        // Execute navigation
+        nh.handleNavigation(facesContext, null, "dialog:testNestedSubdialog");
+
+        // Confirm outcome
+        assertEquals("/first/first/previous/next/last/last", test.log());
+
+    }
+
+
+    // Test a pristine instance
+    public void testPristine() {
+
+        assertNotNull(orig);
+        assertTrue(nh == application.getNavigationHandler());
+        assertTrue(test == externalContext.getRequestMap().get("test"));
+
+    }
+
+
+    // Test delegation for standard navigation scenarios (failure transition)
+    public void testStandardNavigationFailure() {
+
+        // Establish mapping rule
+        orig.addDestination("success", "/page2.jsp");
+
+        // Estabish origin point
+        facesContext.setViewRoot
+          (facesContext.getApplication().getViewHandler().createView(facesContext, "/page1.jsp"));
+        assertEquals("/page1.jsp", facesContext.getViewRoot().getViewId());
+
+        // Execute navigation
+        nh.handleNavigation(facesContext, null, "failure");
+
+        // Confirm outcome
+        assertEquals("/page1.jsp", facesContext.getViewRoot().getViewId());
+
+    }
+
+
+    // Test delegation for standard navigation scenarios (null transition)
+    public void testStandardNavigationNull() {
+
+        // Establish mapping rule
+        orig.addDestination("success", "/page2.jsp");
+
+        // Estabish origin point
+        facesContext.setViewRoot
+          (facesContext.getApplication().getViewHandler().createView(facesContext, "/page1.jsp"));
+        assertEquals("/page1.jsp", facesContext.getViewRoot().getViewId());
+
+        // Execute navigation
+        nh.handleNavigation(facesContext, null, null);
+
+        // Confirm outcome
+        assertEquals("/page1.jsp", facesContext.getViewRoot().getViewId());
+
+    }
+
+
+    // Test delegation for standard navigation scenarios (successful transition)
+    public void testStandardNavigationSuccess() {
+
+        // Establish mapping rule
+        orig.addDestination("success", "/page2.jsp");
+
+        // Estabish origin point
+        facesContext.setViewRoot
+          (facesContext.getApplication().getViewHandler().createView(facesContext, "/page1.jsp"));
+        assertEquals("/page1.jsp", facesContext.getViewRoot().getViewId());
+
+        // Execute navigation
+        nh.handleNavigation(facesContext, null, "success");
+
+        // Confirm outcome
+        assertEquals("/page2.jsp", facesContext.getViewRoot().getViewId());
+
+    }
+
+
+    // Test with intermixed view states
+    public void testViewStates() {
+
+        // Estabish origin point
+        facesContext.setViewRoot
+          (facesContext.getApplication().getViewHandler().createView(facesContext, "/page1.jsp"));
+        assertEquals("/page1.jsp", facesContext.getViewRoot().getViewId());
+
+        // Execute navigation and check view as needed
+        String outcome = null;
+        nh.handleNavigation(facesContext, null, "dialog:testViewStates");
+        assertEquals("/page2.jsp", facesContext.getViewRoot().getViewId());
+        outcome = test.previous(); // Pretend to click button and invoke this action
+        nh.handleNavigation(facesContext, null, outcome);
+        assertEquals("/page3.jsp", facesContext.getViewRoot().getViewId());
+        outcome = test.next(); // Pretend to click button and invoke this action
+        nh.handleNavigation(facesContext, null, outcome);
+
+        // Confirm outcome
+        assertEquals("/first/previous/next/last", test.log());
+
+    }
+
+
+}

Added: struts/shale/trunk/core-library/src/test/org/apache/shale/dialog/faces/TestBean.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/test/org/apache/shale/dialog/faces/TestBean.java?rev=165455&view=auto
==============================================================================
--- struts/shale/trunk/core-library/src/test/org/apache/shale/dialog/faces/TestBean.java (added)
+++ struts/shale/trunk/core-library/src/test/org/apache/shale/dialog/faces/TestBean.java Sat Apr 30 21:27:28 2005
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shale.dialog.faces;
+
+/**
+ * <p>Test bean for validating behavior of DialogNavigationHandler.</p>
+ */
+
+public class TestBean {
+    
+
+    public String first() {
+        log("/first");
+        return "first";
+    }
+
+
+    public String last() {
+        log("/last");
+        return "last";
+    }
+
+
+    public String next() {
+        log("/next");
+        return "next";
+    }
+
+
+    public String previous() {
+        log("/previous");
+        return "previous";
+    }
+
+    private StringBuffer log = new StringBuffer();
+
+
+    private void log(String message) {
+        log.append(message);
+    }
+
+
+    public String log() {
+        return log.toString();
+    }
+
+}

Added: struts/shale/trunk/core-library/src/test/org/apache/shale/dialog/faces/dialog-config.xml
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/test/org/apache/shale/dialog/faces/dialog-config.xml?rev=165455&view=auto
==============================================================================
--- struts/shale/trunk/core-library/src/test/org/apache/shale/dialog/faces/dialog-config.xml (added)
+++ struts/shale/trunk/core-library/src/test/org/apache/shale/dialog/faces/dialog-config.xml Sat Apr 30 21:27:28 2005
@@ -0,0 +1,202 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+
+  Copyright 2004-2005 The Apache Software Foundation.
+ 
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+ 
+      http://www.apache.org/licenses/LICENSE-2.0
+ 
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+  $Id$
+
+-->
+
+<!--
+
+  Dialog definitions for DialogNavigationHandlerTestCase
+
+-->
+
+<!DOCTYPE dialogs PUBLIC
+  "-//Apache Software Foundation//DTD Shale Dialog Configuration 1.0//EN"
+  "http://struts.apache.org/dtds/shale-dialog-config-1_0.dtd">
+
+<dialogs>
+
+
+  <!-- Explict transitions for each state -->
+  <dialog                name="testExplicitTransitions"
+                        start="first">
+
+    <action              name="first"
+                       method="#{test.first}">
+      <transition     outcome="first"
+                       target="previous"/>
+    </action>
+
+    <action              name="previous"
+                       method="#{test.previous}">
+      <transition     outcome="previous"
+                       target="next"/>
+    </action>
+
+    <action              name="next"
+                       method="#{test.next}">
+      <transition     outcome="next"
+                       target="last"/>
+    </action>
+
+    <action              name="last"
+                       method="#{test.last}">
+      <transition     outcome="last"
+                       target="finish"/>
+    </action>
+
+    <end                 name="finish"/>
+
+  </dialog>
+
+
+  <!-- Implict transitions for each state -->
+  <dialog                name="testImplicitTransitions"
+                        start="first">
+
+    <transition       outcome="first"
+                       target="previous"/>
+
+    <transition       outcome="previous"
+                       target="next"/>
+
+    <transition       outcome="next"
+                       target="last"/>
+
+    <transition       outcome="last"
+                       target="finish"/>
+
+    <action              name="first"
+                       method="#{test.first}"/>
+
+    <action              name="previous"
+                       method="#{test.previous}"/>
+
+    <action              name="next"
+                       method="#{test.next}"/>
+
+    <action              name="last"
+                       method="#{test.last}"/>
+
+    <end                 name="finish"/>
+
+  </dialog>
+
+
+  <!-- Mixed transitions for each state -->
+  <dialog                name="testMixedTransitions"
+                        start="first">
+
+    <transition       outcome="first"
+                       target="previous"/>
+
+    <!-- Should not fire -->
+    <transition       outcome="previous"
+                       target="finish"/>
+
+    <!-- Should not fire -->
+    <transition       outcome="next"
+                       target="finish"/>
+
+    <transition       outcome="last"
+                       target="finish"/>
+
+    <action              name="first"
+                       method="#{test.first}"/>
+
+    <action              name="previous"
+                       method="#{test.previous}">
+      <transition     outcome="previous"
+                       target="next"/>
+    </action>
+
+    <action              name="next"
+                       method="#{test.next}">
+      <transition     outcome="next"
+                       target="last"/>
+    </action>
+
+    <action              name="last"
+                       method="#{test.last}"/>
+
+    <end                 name="finish"/>
+
+  </dialog>
+
+
+  <!-- Nested subdialog -->
+  <dialog                name="testNestedSubdialog"
+                        start="first">
+
+    <action              name="first"
+                       method="#{test.first}">
+      <transition     outcome="first"
+                       target="nested"/>
+    </action>
+
+    <subdialog           name="nested"
+                   dialogName="testExplicitTransitions">
+      <transition     outcome="last"
+                       target="last"/>
+    </subdialog>
+
+    <action              name="last"
+                       method="#{test.last}">
+      <transition     outcome="last"
+                       target="finish"/>
+    </action>
+
+    <end                 name="finish"/>
+
+  </dialog>
+
+
+  <dialog                name="testViewStates"
+                        start="first">
+
+    <action              name="first"
+                       method="#{test.first}">
+      <transition     outcome="first"
+                       target="previous"/>
+    </action>
+
+    <view                name="previous"
+                       viewId="/page2.jsp">
+      <transition     outcome="previous"
+                       target="next"/>
+    </view>
+
+    <view                name="next"
+                       viewId="/page3.jsp">
+      <transition     outcome="next"
+                       target="last"/>
+    </view>
+
+    <action              name="last"
+                       method="#{test.last}">
+      <transition     outcome="last"
+                       target="finish"/>
+    </action>
+
+    <end                 name="finish"/>
+
+  </dialog>
+
+
+</dialogs>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org