craigmcc 01/12/26 13:55:55
Modified: . build.xml
src/test/org/apache/struts/action TestActionServlet.java
src/test/org/apache/struts/taglib/logic TestEqualTag.java
TestNotPresentTag.java TestPresentTag.java
Added: src/test/org/apache/struts/config TestApplicationConfig.java
struts-config.xml
Log:
Add a basic unit test for parsing struts-config.xml and creating an
ApplicationConfig object.
Revision Changes Path
1.57 +60 -0 jakarta-struts/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-struts/build.xml,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -r1.56 -r1.57
--- build.xml 2001/09/19 03:01:26 1.56
+++ build.xml 2001/12/26 21:55:54 1.57
@@ -39,6 +39,8 @@
jdbc20ext.jar (required). The path to the JAR file
for the JDBC 2.0 Optional Package APIs.
+ junit.jar (optional) JUnit for "test".
+
servlet.jar (required). The path to the Servlet API
classes to compile against (currently,
either version 2.2 or 2.3 supported).
@@ -120,6 +122,9 @@
<!-- Source directory for core struts library -->
<property name="src.share.dir" value="${src.dir}/share"/>
+ <!-- Source directory for non-Cactus unit tests -->
+ <property name="src.test.dir" value="${src.dir}/test"/>
+
<!-- Directory where core struts library configurations files are stored -->
<property name="conf.share.dir" value="conf/share"/>
@@ -142,6 +147,31 @@
</path>
+<!-- ========== Test Execution Defaults =================================== -->
+
+
+ <!-- Construct unit test classpath -->
+ <path id="test.classpath">
+ <pathelement location="${build.home}/library/classes"/>
+ <pathelement location="${build.home}/test/classes"/>
+ <pathelement location="${cactus.jar}"/>
+ <pathelement location="${commons-beanutils.jar}"/>
+ <pathelement location="${commons-collections.jar}"/>
+ <pathelement location="${commons-digester.jar}"/>
+ <pathelement location="${servlet.jar}"/>
+ <pathelement location="${junit.jar}"/>
+ <pathelement location="${jdbc20ext.jar}"/>
+ <pathelement location="${servlet.jar}"/>
+ <pathelement location="${xerces.jar}"/>
+ </path>
+
+ <!-- Should all tests fail if one does? -->
+ <property name="test.failonerror" value="true"/>
+
+ <!-- The test runner to execute -->
+ <property name="test.runner" value="junit.textui.TestRunner"/>
+
+
<!-- ========== Executable Targets ======================================== -->
@@ -458,5 +488,35 @@
<ant antfile="build-tests.xml" target="test.tomcat.40"/>
</target>
+
+ <!-- ========== Non-Cactus Unit Tests ================================= -->
+
+ <target name="test" depends="test.compile,test.config"
+ description="Run all non-Cactus based unit tests">
+ </target>
+
+ <target name="test.compile">
+ <mkdir dir="${build.home}/test/classes"/>
+ <javac srcdir="${src.test.dir}"
+ destdir="${build.home}/test/classes"
+ debug="${compile.debug}"
+ optimize="${compile.optimize}"
+ deprecation="${compile.deprecation}">
+ <classpath refid="test.classpath"/>
+ </javac>
+ <copy todir="${build.home}/test/classes">
+ <fileset dir="${src.test.dir}" excludes="**/*.java"/>
+ </copy>
+ </target>
+
+ <target name="test.config">
+ <echo message="Running Config Package tests ..."/>
+ <java classname="${test.runner}" fork="yes"
+ failonerror="${test.failonerror}">
+ <arg value="org.apache.struts.config.TestApplicationConfig"/>
+ <classpath refid="test.classpath"/>
+ </java>
+ </target>
+
</project>
1.2 +1 -1
jakarta-struts/src/test/org/apache/struts/action/TestActionServlet.java
Index: TestActionServlet.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/test/org/apache/struts/action/TestActionServlet.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestActionServlet.java 2001/05/06 12:07:32 1.1
+++ TestActionServlet.java 2001/12/26 21:55:55 1.2
@@ -57,7 +57,7 @@
import javax.servlet.*;
import junit.framework.*;
-import org.apache.commons.cactus.*;
+import org.apache.cactus.*;
/**
* Suite of unit tests for the
1.1
jakarta-struts/src/test/org/apache/struts/config/TestApplicationConfig.java
Index: TestApplicationConfig.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.struts.config;
import java.io.InputStream;
import java.net.URL;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.commons.digester.Digester;
import org.apache.struts.action.Action;
/**
* Unit tests for the <code>org.apache.struts.config</code> package.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2001/12/26 21:55:55 $
*/
public class TestApplicationConfig extends TestCase {
// ----------------------------------------------------- Instance Variables
/**
* The ApplicationConfig we are testing.
*/
protected ApplicationConfig config = null;
// ----------------------------------------------------------- Constructors
/**
* Construct a new instance of this test case.
*
* @param name Name of the test case
*/
public TestApplicationConfig(String name) {
super(name);
}
// --------------------------------------------------------- Public Methods
/**
* Set up instance variables required by this test case.
*/
public void setUp() {
config = new ApplicationConfig("", null);
}
/**
* Return the tests included in this test suite.
*/
public static Test suite() {
return (new TestSuite(TestApplicationConfig.class));
}
/**
* Tear down instance variables required by this test case.
*/
public void tearDown() {
config = null;
}
// ------------------------------------------------ Individual Test Methods
/**
* Test parsing of a struts-config.xml file.
*/
public void testParse() {
// Prepare a Digester for parsing a struts-config.xml file
Digester digester = new Digester();
digester.push(config);
digester.setDebug(0);
digester.setNamespaceAware(true);
digester.setValidating(true);
digester.addRuleSet(new ConfigRuleSet());
digester.register
("-//Apache Software Foundation//DTD Struts Configuration 1.1//EN",
this.getClass().getResource
("/org/apache/struts/resources/struts-config_1_1.dtd").toString());
// Parse the test struts-config.xml file
try {
InputStream input = this.getClass().getResourceAsStream
("/org/apache/struts/config/struts-config.xml");
assertNotNull("Got an input stream for struts-config.xml", input);
digester.parse(input);
input.close();
} catch (Throwable t) {
t.printStackTrace(System.out);
fail("Parsing threw exception: " + t);
}
// Perform assertion tests on the parsed information
DataSourceConfig dsc =
config.findDataSourceConfig(Action.DATA_SOURCE_KEY);
assertNotNull("Found our data source configuration", dsc);
assertEquals("Data source description",
"Example Data Source Configuration",
dsc.getDescription());
FormBeanConfig fbcs[] = config.findFormBeanConfigs();
assertNotNull("Found our form bean configurations", fbcs);
assertEquals("Found three form bean configurations",
3, fbcs.length);
ForwardConfig fcs[] = config.findForwardConfigs();
assertNotNull("Found our forward configurations", fcs);
assertEquals("Found three forward configurations",
3, fcs.length);
ActionConfig logon = config.findActionConfig("/logon");
assertNotNull("Found logon action configuration", logon);
assertEquals("Found correct logon configuration",
"logonForm",
logon.getName());
}
}
1.1
jakarta-struts/src/test/org/apache/struts/config/struts-config.xml
Index: struts-config.xml
===================================================================
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<!--
This is the Struts configuration file for the example application,
using the proposed new syntax.
NOTE: You would only flesh out the details in the "form-bean"
declarations if you had a generator tool that used them to create
the corresponding Java classes for you. Otherwise, you would
need only the "form-bean" element itself, with the corresponding
"name" and "type" attributes.
-->
<struts-config>
<!-- ========== Data Source Configuration =============================== -->
<data-sources>
<data-source>
<set-property property="autoCommit"
value="false"/>
<set-property property="description"
value="Example Data Source Configuration"/>
<set-property property="driverClass"
value="org.postgresql.Driver"/>
<set-property property="maxCount"
value="4"/>
<set-property property="minCount"
value="2"/>
<set-property property="password"
value="mypassword"/>
<set-property property="url"
value="jdbc:postgresql://localhost/mydatabase"/>
<set-property property="user"
value="myusername"/>
</data-source>
</data-sources>
<!-- ========== Form Bean Definitions =================================== -->
<form-beans>
<!-- Logon form bean -->
<form-bean name="logonForm"
type="org.apache.struts.webapp.example.LogonForm"/>
<!-- Registration form bean -->
<form-bean name="registrationForm"
type="org.apache.struts.webapp.example.RegistrationForm"/>
<!-- Subscription form bean -->
<form-bean name="subscriptionForm"
type="org.apache.struts.webapp.example.SubscriptionForm"/>
</form-beans>
<!-- ========== Global Forward Definitions ============================== -->
<global-forwards>
<forward name="logoff" path="/logoff.do"/>
<forward name="logon" path="/logon.jsp"/>
<forward name="success" path="/mainMenu.jsp"/>
</global-forwards>
<!-- ========== Action Mapping Definitions ============================== -->
<action-mappings>
<!-- Edit user registration -->
<action path="/editRegistration"
type="org.apache.struts.webapp.example.EditRegistrationAction"
attribute="registrationForm"
scope="request"
validate="false">
<forward name="success" path="/registration.jsp"/>
</action>
<!-- Edit mail subscription -->
<action path="/editSubscription"
type="org.apache.struts.webapp.example.EditSubscriptionAction"
attribute="subscriptionForm"
scope="request"
validate="false">
<forward name="failure" path="/mainMenu.jsp"/>
<forward name="success" path="/subscription.jsp"/>
</action>
<!-- Process a user logoff -->
<action path="/logoff"
type="org.apache.struts.webapp.example.LogoffAction">
<forward name="success" path="/index.jsp"/>
</action>
<!-- Process a user logon -->
<action path="/logon"
type="org.apache.struts.webapp.example.LogonAction"
name="logonForm"
scope="request"
input="/logon.jsp">
</action>
<!-- Save user registration -->
<action path="/saveRegistration"
type="org.apache.struts.webapp.example.SaveRegistrationAction"
name="registrationForm"
scope="request"
input="/registration.jsp"/>
<!-- Save mail subscription -->
<action path="/saveSubscription"
type="org.apache.struts.webapp.example.SaveSubscriptionAction"
name="subscriptionForm"
scope="request"
input="/subscription.jsp">
<forward name="success" path="/editRegistration.do?action=Edit"/>
</action>
<!-- Display the "walking tour" documentation -->
<action path="/tour"
forward="/tour.htm">
</action>
<!-- The standard administrative actions available with Struts -->
<!-- These would be either omitted or protected by security -->
<!-- in a real application deployment -->
<action path="/admin/addFormBean"
type="org.apache.struts.actions.AddFormBeanAction"/>
<action path="/admin/addForward"
type="org.apache.struts.actions.AddForwardAction"/>
<action path="/admin/addMapping"
type="org.apache.struts.actions.AddMappingAction"/>
<action path="/admin/reload"
type="org.apache.struts.actions.ReloadAction"/>
<action path="/admin/removeFormBean"
type="org.apache.struts.actions.RemoveFormBeanAction"/>
<action path="/admin/removeForward"
type="org.apache.struts.actions.RemoveForwardAction"/>
<action path="/admin/removeMapping"
type="org.apache.struts.actions.RemoveMappingAction"/>
</action-mappings>
</struts-config>
1.2 +1 -1
jakarta-struts/src/test/org/apache/struts/taglib/logic/TestEqualTag.java
Index: TestEqualTag.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/test/org/apache/struts/taglib/logic/TestEqualTag.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestEqualTag.java 2001/07/11 02:20:50 1.1
+++ TestEqualTag.java 2001/12/26 21:55:55 1.2
@@ -57,7 +57,7 @@
import javax.servlet.*;
import junit.framework.*;
-import org.apache.commons.cactus.*;
+import org.apache.cactus.*;
/**
* Suite of unit tests for the
1.3 +1 -1
jakarta-struts/src/test/org/apache/struts/taglib/logic/TestNotPresentTag.java
Index: TestNotPresentTag.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/test/org/apache/struts/taglib/logic/TestNotPresentTag.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestNotPresentTag.java 2001/07/11 03:33:57 1.2
+++ TestNotPresentTag.java 2001/12/26 21:55:55 1.3
@@ -60,7 +60,7 @@
import junit.framework.*;
-import org.apache.commons.cactus.*;
+import org.apache.cactus.*;
/**
* Suite of unit tests for the
1.3 +1 -1
jakarta-struts/src/test/org/apache/struts/taglib/logic/TestPresentTag.java
Index: TestPresentTag.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/test/org/apache/struts/taglib/logic/TestPresentTag.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestPresentTag.java 2001/07/11 03:29:52 1.2
+++ TestPresentTag.java 2001/12/26 21:55:55 1.3
@@ -60,7 +60,7 @@
import junit.framework.*;
-import org.apache.commons.cactus.*;
+import org.apache.cactus.*;
/**
* Suite of unit tests for the
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>