Author: craigmcc
Date: Sun Feb  6 14:59:47 2005
New Revision: 151632

URL: http://svn.apache.org/viewcvs?view=rev&rev=151632
Log:
Add the first JUnit unit test (for the Select view controller bean), using
the Shale Test Framework that contains the relevant mock objects and
convenient base classes.

Added:
    struts/shale/trunk/use-cases/src/test/
    struts/shale/trunk/use-cases/src/test/org/
    struts/shale/trunk/use-cases/src/test/org/apache/
    struts/shale/trunk/use-cases/src/test/org/apache/shale/
    struts/shale/trunk/use-cases/src/test/org/apache/shale/usecases/
    struts/shale/trunk/use-cases/src/test/org/apache/shale/usecases/locale/
    
struts/shale/trunk/use-cases/src/test/org/apache/shale/usecases/locale/SelectTestCase.java
Modified:
    struts/shale/trunk/use-cases/build.xml
    
struts/shale/trunk/use-cases/src/java/org/apache/shale/usecases/view/BaseDialogController.java

Modified: struts/shale/trunk/use-cases/build.xml
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/use-cases/build.xml?view=diff&r1=151631&r2=151632
==============================================================================
--- struts/shale/trunk/use-cases/build.xml (original)
+++ struts/shale/trunk/use-cases/build.xml Sun Feb  6 14:59:47 2005
@@ -59,6 +59,7 @@
   <property name="junit.jar"        value="${junit.home}/junit.jar"/>
   <property name="servlet-api.jar"  
value="${server.home}/common/lib/servlet-api.jar"/>
   <property name="shale.jar"        
value="${basedir}/../core-library/target/lib/shale.jar"/>
+  <property name="shale-test.jar"   
value="${basedir}/../test-framework/target/lib/shale-test.jar"/>
   <property name="standard.jar"     value="${jstl.home}/lib/standard.jar"/>
 
 
@@ -101,6 +102,25 @@
   </path>
 
 
+  <!-- Test Classpath -->
+  <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-logging.jar}"/>
+    <pathelement location="${jsf-api.jar}"/>
+    <pathelement location="${jsp-api.jar}"/>
+    <pathelement location="${jstl.jar}"/>
+    <pathelement location="${junit.jar}"/>
+    <pathelement location="${servlet.jar}"/>
+    <pathelement location="${shale.jar}"/>
+    <pathelement location="${shale-test.jar}"/>
+    <pathelement location="${build.home}/${context.path}/WEB-INF/classes"/>
+    <pathelement location="${build.home}/test-classes"/>
+  </path>
+
+
   <!-- Custom Tomcat Integration -->
   <taskdef  name="deploy"   classname="org.apache.catalina.ant.DeployTask"/>
   <taskdef  name="install"  classname="org.apache.catalina.ant.InstallTask"/>
@@ -361,6 +381,54 @@
    description="Undeploy webapp from Tomcat">
     <remove url="${url}" username="${username}" password="${password}"
             path="/${context.path}"/>
+  </target>
+
+
+  <!-- ========================== Unit Tests =============================== 
-->
+
+
+  <target         name="test.compile" depends="compile">
+
+    <mkdir         dir="${build.home}/test-classes"/>
+
+    <!-- Compile Java Sources -->
+    <javac      srcdir="src/test"
+               destdir="${build.home}/test-classes"
+                 debug="${compile.debug}"
+           deprecation="${compile.deprecation}"
+              optimize="${compile.optimize}">
+      <classpath refid="test.classpath" />
+    </javac>
+
+    <!-- Copy non-Java Sources -->
+    <copy        todir="${build.home}/test-classes">
+      <fileset     dir="src/test">
+        <exclude  name="**/*.java"/>
+      </fileset>
+    </copy>
+
+  </target>
+
+
+  <target name="test" depends="test.compile"
+   description="Execute unit tests">
+
+    <mkdir          dir="${build.home}/test-results"/>
+
+    <echo       message="Running unit tests ..."/>
+    <junit printSummary="no" fork="yes"
+          haltonfailure="yes" haltonerror="yes">
+      <classpath  refid="test.classpath"/>
+      <formatter   type="plain"
+                usefile="false"/>
+      <formatter   type="xml"
+                usefile="true"/>
+      <batchtest todir="${build.home}/test-results">
+        <fileset    dir="${build.home}/test-classes"
+               includes="org/apache/shale/usecases/*/*TestCase.class"/>
+      </batchtest>
+    </junit>
+
   </target>
 
 

Modified: 
struts/shale/trunk/use-cases/src/java/org/apache/shale/usecases/view/BaseDialogController.java
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/use-cases/src/java/org/apache/shale/usecases/view/BaseDialogController.java?view=diff&r1=151631&r2=151632
==============================================================================
--- 
struts/shale/trunk/use-cases/src/java/org/apache/shale/usecases/view/BaseDialogController.java
 (original)
+++ 
struts/shale/trunk/use-cases/src/java/org/apache/shale/usecases/view/BaseDialogController.java
 Sun Feb  6 14:59:47 2005
@@ -33,6 +33,16 @@
     // -------------------------------------------------------------- 
Properties
 
 
+    /**
+     * <p>The attribute key under which this instance was stored in session
+     * scope by the managed bean facility.</p>
+     */
+    private String attributeKey = null;
+    public String getAttributeKey() { return this.attributeKey; }
+    public void setAttributeKey(String attributeKey)
+    { this.attributeKey = attributeKey; }
+
+
     // ---------------------------------------------------------- Event 
Handlers
 
 

Added: 
struts/shale/trunk/use-cases/src/test/org/apache/shale/usecases/locale/SelectTestCase.java
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/use-cases/src/test/org/apache/shale/usecases/locale/SelectTestCase.java?view=auto&rev=151632
==============================================================================
--- 
struts/shale/trunk/use-cases/src/test/org/apache/shale/usecases/locale/SelectTestCase.java
 (added)
+++ 
struts/shale/trunk/use-cases/src/test/org/apache/shale/usecases/locale/SelectTestCase.java
 Sun Feb  6 14:59:47 2005
@@ -0,0 +1,160 @@
+/*
+ * 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.usecases.locale;
+
+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.shale.test.base.AbstractViewControllerTestCase;
+
+/**
+ * <p>Test case for the [EMAIL PROTECTED] Select} ViewController 
implementation.</p>
+ *
+ * $Id$
+ */
+public class SelectTestCase extends AbstractViewControllerTestCase {
+
+
+    // ------------------------------------------------------------ 
Constructors
+
+
+    // Construct a new instance of this test case.
+    public SelectTestCase(String name) {
+        super(name);
+    }
+
+
+    // ---------------------------------------------------- Overall Test 
Methods
+
+
+    // Set up instance variables required by this test case.
+    public void setUp() {
+
+        super.setUp();
+
+        // Configure the supported locales for this application
+        List list = new ArrayList();
+        list.add(new Locale("en"));
+        list.add(new Locale("fr"));
+        list.add(new Locale("de"));
+        list.add(new Locale("es"));
+        application.setSupportedLocales(list);
+
+        // Construct a new ViewController instance
+        vc = new Select();
+
+    }
+
+    // Return the tests included in this test case.
+    public static Test suite() {
+
+        return (new TestSuite(SelectTestCase.class));
+
+    }
+
+
+    // Tear down instance variables required by this test case.
+    public void tearDown() {
+
+        vc = null;
+        super.tearDown();
+
+    }
+
+
+    // ------------------------------------------------------ Instance 
Variables
+
+
+    // The instance to be tested
+    Select vc = null;
+
+
+    // ------------------------------------------------------------ Test 
Methods
+
+
+    // Test behavior of prerender() method
+    public void testPrerender() {
+
+        Locale locale = new Locale("en");
+        facesContext.getViewRoot().setLocale(locale);
+        vc.init();
+        vc.prerender();
+        assertEquals(locale.toString(), vc.getLocale());
+
+    }
+
+
+    // Test a pristine instance of [EMAIL PROTECTED] Select}
+    public void testPristine() {
+
+        assertNull(vc.getLocale());
+
+    }
+
+
+    // Test behavior of select() with an invalid value
+    public void testSelectInvalid() {
+
+        Locale locale = new Locale("en");
+        facesContext.getViewRoot().setLocale(locale);
+        vc.init();
+        vc.preprocess();
+        vc.setLocale("it");
+        String result = vc.select();
+        assertEquals(Select.FAILURE, result);
+        checkMessageCount(1);
+        assertEquals(locale, facesContext.getViewRoot().getLocale());
+
+    }
+
+
+    // Test behavior of select() with no input value at all
+    public void testSelectNull() {
+
+        Locale locale = new Locale("en");
+        facesContext.getViewRoot().setLocale(locale);
+        vc.init();
+        vc.preprocess();
+        vc.setLocale(null);
+        String result = vc.select();
+        assertNull(result);
+        checkMessageCount(1);
+        assertEquals(locale, facesContext.getViewRoot().getLocale());
+
+    }
+
+
+    // Test behavior of select() with a valid value
+    public void testSelectValid() {
+
+        Locale locale = new Locale("en");
+        facesContext.getViewRoot().setLocale(locale);
+        vc.init();
+        vc.preprocess();
+        vc.setLocale("de");
+        String result = vc.select();
+        assertEquals(result, Select.SUCCESS);
+        checkMessageCount(0);
+        assertEquals(new Locale("de"), facesContext.getViewRoot().getLocale());
+
+    }
+
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to