Author: mrdon
Date: Sat Sep 23 19:27:41 2006
New Revision: 449344
URL: http://svn.apache.org/viewvc?view=rev&rev=449344
Log:
Adds a legacy library to support Struts 1.3 Actions and ActionForms as is
running in Struts
WW-1452
Added:
struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/legacy/
struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/legacy/EditGangsterAction.java
struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/legacy/GangsterForm.java
struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/legacy/SaveGangsterAction.java
struts/struts2/trunk/apps/showcase/src/main/resources/struts-legacy.xml
struts/struts2/trunk/apps/showcase/src/main/webapp/legacy/
struts/struts2/trunk/apps/showcase/src/main/webapp/legacy/modelDriven.jsp
struts/struts2/trunk/apps/showcase/src/main/webapp/legacy/modelDrivenResult.jsp
struts/struts2/trunk/legacy/ (with props)
struts/struts2/trunk/legacy/pom.xml
struts/struts2/trunk/legacy/src/
struts/struts2/trunk/legacy/src/main/
struts/struts2/trunk/legacy/src/main/java/
struts/struts2/trunk/legacy/src/main/java/org/
struts/struts2/trunk/legacy/src/main/resources/
struts/struts2/trunk/legacy/src/main/resources/struts-default.xml
struts/struts2/trunk/legacy/src/test/
struts/struts2/trunk/legacy/src/test/java/
struts/struts2/trunk/legacy/src/test/java/org/
struts/struts2/trunk/legacy/src/test/java/org/apache/
struts/struts2/trunk/legacy/src/test/java/org/apache/struts2/
struts/struts2/trunk/legacy/src/test/java/org/apache/struts2/legacy/
struts/struts2/trunk/legacy/src/test/java/org/apache/struts2/legacy/DynaBeanPropertyAccessorTest.java
struts/struts2/trunk/legacy/src/test/java/org/apache/struts2/legacy/ScopedModelDrivenInterceptorTest.java
struts/struts2/trunk/legacy/src/test/java/org/apache/struts2/legacy/StrutsFactoryTest.java
struts/struts2/trunk/legacy/src/test/resources/
struts/struts2/trunk/legacy/src/test/resources/org/
struts/struts2/trunk/legacy/src/test/resources/org/apache/
struts/struts2/trunk/legacy/src/test/resources/org/apache/struts2/
struts/struts2/trunk/legacy/src/test/resources/org/apache/struts2/legacy/
struts/struts2/trunk/legacy/src/test/resources/org/apache/struts2/legacy/test-struts-factory.xml
- copied, changed from r449318,
struts/sandbox/trunk/ti/phase1/jars/legacy/src/test/org/apache/ti/legacy/test-struts-factory.xml
Modified:
struts/struts2/trunk/apps/showcase/pom.xml
struts/struts2/trunk/apps/showcase/src/main/resources/struts.xml
struts/struts2/trunk/apps/showcase/src/main/webapp/showcase.jsp
struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsConstants.java
struts/struts2/trunk/pom.xml
Modified: struts/struts2/trunk/apps/showcase/pom.xml
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/pom.xml?view=diff&rev=449344&r1=449343&r2=449344
==============================================================================
--- struts/struts2/trunk/apps/showcase/pom.xml (original)
+++ struts/struts2/trunk/apps/showcase/pom.xml Sat Sep 23 19:27:41 2006
@@ -25,6 +25,13 @@
<dependencies>
<dependency>
+ <groupId>org.apache.struts</groupId>
+ <artifactId>struts2-legacy</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+
+
+ <dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
Added:
struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/legacy/EditGangsterAction.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/legacy/EditGangsterAction.java?view=auto&rev=449344
==============================================================================
---
struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/legacy/EditGangsterAction.java
(added)
+++
struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/legacy/EditGangsterAction.java
Sat Sep 23 19:27:41 2006
@@ -0,0 +1,40 @@
+/*
+ * $Id: Gangster.java 418530 2006-07-01 23:58:13Z mrdon $
+ *
+ * Copyright 2006 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.struts2.showcase.legacy;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.struts.action.Action;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+
+public class EditGangsterAction extends Action {
+
+ /* (non-Javadoc)
+ * @see
org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping,
org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
+ */
+ @Override
+ public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
+ // Some code to load the gangster from the db as necessary
+ return mapping.findForward("success");
+ }
+
+
+}
Added:
struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/legacy/GangsterForm.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/legacy/GangsterForm.java?view=auto&rev=449344
==============================================================================
---
struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/legacy/GangsterForm.java
(added)
+++
struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/legacy/GangsterForm.java
Sat Sep 23 19:27:41 2006
@@ -0,0 +1,87 @@
+package org.apache.struts2.showcase.legacy;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.struts.action.ActionErrors;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionMapping;
+import org.apache.struts.action.ActionMessage;
+
+public class GangsterForm extends ActionForm {
+
+ private String name;
+ private String age;
+ private String description;
+ private boolean bustedBefore;
+
+ /* (non-Javadoc)
+ * @see
org.apache.struts.action.ActionForm#reset(org.apache.struts.action.ActionMapping,
javax.servlet.http.HttpServletRequest)
+ */
+ @Override
+ public void reset(ActionMapping arg0, HttpServletRequest arg1) {
+ bustedBefore = false;
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping,
javax.servlet.http.HttpServletRequest)
+ */
+ @Override
+ public ActionErrors validate(ActionMapping arg0, HttpServletRequest arg1) {
+ ActionErrors errors = new ActionErrors();
+ if (name == null || name.length() == 0) {
+ errors.add("name", new ActionMessage("The name must not be
blank"));
+ }
+ return errors;
+ }
+
+ /**
+ * @return the age
+ */
+ public String getAge() {
+ return age;
+ }
+ /**
+ * @param age the age to set
+ */
+ public void setAge(String age) {
+ this.age = age;
+ }
+ /**
+ * @return the bustedBefore
+ */
+ public boolean isBustedBefore() {
+ return bustedBefore;
+ }
+ /**
+ * @param bustedBefore the bustedBefore to set
+ */
+ public void setBustedBefore(boolean bustedBefore) {
+ this.bustedBefore = bustedBefore;
+ }
+ /**
+ * @return the description
+ */
+ public String getDescription() {
+ return description;
+ }
+ /**
+ * @param description the description to set
+ */
+ public void setDescription(String description) {
+ this.description = description;
+ }
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+
+}
Added:
struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/legacy/SaveGangsterAction.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/legacy/SaveGangsterAction.java?view=auto&rev=449344
==============================================================================
---
struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/legacy/SaveGangsterAction.java
(added)
+++
struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/legacy/SaveGangsterAction.java
Sat Sep 23 19:27:41 2006
@@ -0,0 +1,48 @@
+/*
+ * $Id: Gangster.java 418530 2006-07-01 23:58:13Z mrdon $
+ *
+ * Copyright 2006 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.struts2.showcase.legacy;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.struts.action.Action;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+import org.apache.struts.action.ActionMessage;
+import org.apache.struts.action.ActionMessages;
+
+public class SaveGangsterAction extends Action {
+
+ /* (non-Javadoc)
+ * @see
org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping,
org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
+ */
+ @Override
+ public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
+
+ // Some code to save the gangster to the db as necessary
+ GangsterForm gform = (GangsterForm) form;
+ ActionMessages messages = new ActionMessages();
+ messages.add("msg", new ActionMessage("Gangster "+gform.getName()+"
added successfully"));
+ addMessages(request, messages);
+
+ return mapping.findForward("success");
+ }
+
+
+}
Added: struts/struts2/trunk/apps/showcase/src/main/resources/struts-legacy.xml
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/resources/struts-legacy.xml?view=auto&rev=449344
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/resources/struts-legacy.xml
(added)
+++ struts/struts2/trunk/apps/showcase/src/main/resources/struts-legacy.xml Sat
Sep 23 19:27:41 2006
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!DOCTYPE struts PUBLIC
+ "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
+ "http://struts.apache.org/dtds/struts-2.0.dtd">
+
+<struts>
+ <package name="legacy" extends="struts-default,struts-legacy-default"
namespace="/legacy">
+
+ <interceptors>
+ <interceptor name="gangsterForm"
class="org.apache.struts2.legacy.ScopedModelDrivenInterceptor">
+ <param name="scope">request</param>
+ <param name="name">gangsterForm</param>
+ <param
name="className">org.apache.struts2.showcase.legacy.GangsterForm</param>
+ </interceptor>
+
+ <interceptor-stack name="legacy">
+ <interceptor-ref name="static-params"/>
+ <interceptor-ref name="gangsterForm"/>
+ <interceptor-ref name="model-driven"/>
+ <interceptor-ref name="actionForm-reset"/>
+ <interceptor-ref name="basicStack"/>
+ <interceptor-ref name="actionForm-validation"/>
+ <interceptor-ref name="workflow"/>
+ </interceptor-stack>
+ </interceptors>
+
+ <default-interceptor-ref name="legacy" />
+ <default-action-ref name="editGangster" />
+
+ <!-- Diplay entry page that uses Model-Driven technique -->
+ <action name="editGangster"
class="org.apache.struts2.legacy.LegacyAction">
+ <param
name="className">org.apache.struts2.showcase.legacy.EditGangsterAction</param>
+ <result>modelDriven.jsp</result>
+ </action>
+
+ <!-- Display the result page whose content is populated using
the Model-Driven technique -->
+ <action name="saveGangster"
class="org.apache.struts2.legacy.LegacyAction">
+ <param
name="className">org.apache.struts2.showcase.legacy.SaveGangsterAction</param>
+ <param name="validate">true</param>
+ <result name="input">modelDriven.jsp</result>
+ <result>modelDrivenResult.jsp</result>
+ </action>
+
+ </package>
+</struts>
+
\ No newline at end of file
Modified: struts/struts2/trunk/apps/showcase/src/main/resources/struts.xml
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/resources/struts.xml?view=diff&rev=449344&r1=449343&r2=449344
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/resources/struts.xml (original)
+++ struts/struts2/trunk/apps/showcase/src/main/resources/struts.xml Sat Sep 23
19:27:41 2006
@@ -38,6 +38,8 @@
<include file="struts-model-driven.xml" />
+ <include file="struts-legacy.xml" />
+
<include file="struts-filedownload.xml" />
<include file="struts-conversion.xml" />
Added: struts/struts2/trunk/apps/showcase/src/main/webapp/legacy/modelDriven.jsp
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/webapp/legacy/modelDriven.jsp?view=auto&rev=449344
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/webapp/legacy/modelDriven.jsp
(added)
+++ struts/struts2/trunk/apps/showcase/src/main/webapp/legacy/modelDriven.jsp
Sat Sep 23 19:27:41 2006
@@ -0,0 +1,31 @@
+<[EMAIL PROTECTED] prefix="s" uri="/struts-tags" %>
+
+<html>
+<head>
+<title>Showcase - Legacy Example</title>
+<s:head/>
+</head>
+<body>
+
+<s:form action="saveGangster" method="POST" namespace="/legacy">
+
+ <s:textfield
+ label="Gangster Name"
+ name="name" />
+ <s:textfield
+ label="Gangster Age"
+ name="age" />
+ <s:checkbox
+ label="Gangster Busted Before"
+ name="bustedBefore" />
+ <s:textarea
+ cols="30"
+ rows="5"
+ label="Gangster Description"
+ name="description" />
+ <s:submit />
+
+</s:form>
+
+</body>
+</html>
\ No newline at end of file
Added:
struts/struts2/trunk/apps/showcase/src/main/webapp/legacy/modelDrivenResult.jsp
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/webapp/legacy/modelDrivenResult.jsp?view=auto&rev=449344
==============================================================================
---
struts/struts2/trunk/apps/showcase/src/main/webapp/legacy/modelDrivenResult.jsp
(added)
+++
struts/struts2/trunk/apps/showcase/src/main/webapp/legacy/modelDrivenResult.jsp
Sat Sep 23 19:27:41 2006
@@ -0,0 +1,24 @@
+<[EMAIL PROTECTED] prefix="s" uri="/struts-tags" %>
+
+<html>
+<head>
+<title>Showcase - Legacy Example</title>
+<s:head/>
+</head>
+<body>
+ <s:actionmessage />
+ <s:label
+ label="Gangster Name"
+ name="name" /><br/>
+ <s:label
+ label="Gangster Age"
+ name="age" /><br/>
+ <s:label
+ label="Busted Before"
+ name="bustedBefore" /><br/>
+ <s:label
+ label="Gangster Description"
+ name="description" /><br/>
+
+</body>
+</html>
Modified: struts/struts2/trunk/apps/showcase/src/main/webapp/showcase.jsp
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/webapp/showcase.jsp?view=diff&rev=449344&r1=449343&r2=449344
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/webapp/showcase.jsp (original)
+++ struts/struts2/trunk/apps/showcase/src/main/webapp/showcase.jsp Sat Sep 23
19:27:41 2006
@@ -66,6 +66,9 @@
<!-- JavaServer Faces -->
<li><s:url id="url" value="/jsf" /><s:a href="%{#url}">JavaServer
Faces Example</s:a></li>
+ <!-- Legacy -->
+ <li><s:url id="url" value="/legacy" /><s:a href="%{#url}">Legacy
Struts 1.3 Example</s:a></li>
+
<!-- Chat (AJAX) Example -->
<li><s:url id="url" value="/chat" /><s:a href="%{#url}">Chat (AJAX)
Example</s:a></li>
Modified:
struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsConstants.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsConstants.java?view=diff&rev=449344&r1=449343&r2=449344
==============================================================================
---
struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsConstants.java
(original)
+++
struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsConstants.java
Sat Sep 23 19:27:41 2006
@@ -50,10 +50,10 @@
/** The default includeParams method to generate Struts URLs */
public static final String STRUTS_URL_INCLUDEPARAMS =
"struts.url.includeParams";
- /** The com.opensymphony.xwork.ObjectFactory implementation class */
+ /** The com.opensymphony.xwork2.ObjectFactory implementation class */
public static final String STRUTS_OBJECTFACTORY = "struts.objectFactory";
- /** The com.opensymphony.xwork.util.ObjectTypeDeterminer implementation
class */
+ /** The com.opensymphony.xwork2.util.ObjectTypeDeterminer implementation
class */
public static final String STRUTS_OBJECTTYPEDETERMINER =
"struts.objectTypeDeterminer";
/** The package containing actions that use Rife continuations */
Propchange: struts/struts2/trunk/legacy/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Sep 23 19:27:41 2006
@@ -0,0 +1 @@
+target
Added: struts/struts2/trunk/legacy/pom.xml
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/legacy/pom.xml?view=auto&rev=449344
==============================================================================
--- struts/struts2/trunk/legacy/pom.xml (added)
+++ struts/struts2/trunk/legacy/pom.xml Sat Sep 23 19:27:41 2006
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.struts</groupId>
+ <artifactId>struts2-parent</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </parent>
+ <groupId>org.apache.struts</groupId>
+ <artifactId>struts2-legacy</artifactId>
+ <packaging>jar</packaging>
+ <name>Struts Legacy</name>
+
+ <distributionManagement>
+ <site>
+ <id>apache-site</id>
+
<url>scp://people.apache.org/www/struts.apache.org/2.x/struts-legacy</url>
+ </site>
+ </distributionManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.4</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.struts</groupId>
+ <artifactId>struts2-core</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.struts</groupId>
+ <artifactId>struts-core</artifactId>
+ <version>1.3.5</version>
+ </dependency>
+
+ <dependency>
+ <groupId>mockobjects</groupId>
+ <artifactId>mockobjects-core</artifactId>
+ <version>0.09</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
Added: struts/struts2/trunk/legacy/src/main/resources/struts-default.xml
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/legacy/src/main/resources/struts-default.xml?view=auto&rev=449344
==============================================================================
--- struts/struts2/trunk/legacy/src/main/resources/struts-default.xml (added)
+++ struts/struts2/trunk/legacy/src/main/resources/struts-default.xml Sat Sep
23 19:27:41 2006
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!DOCTYPE struts PUBLIC
+ "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
+ "http://struts.apache.org/dtds/struts-2.0.dtd">
+
+<struts>
+ <package name="struts-legacy-default">
+
+ <interceptors>
+ <interceptor name="actionForm-reset"
class="org.apache.struts2.legacy.ActionFormResetInterceptor"/>
+ <interceptor name="actionForm-validation"
class="org.apache.struts2.legacy.ActionFormValidationInterceptor"/>
+ </interceptors>
+ </package>
+
+</struts>
Added:
struts/struts2/trunk/legacy/src/test/java/org/apache/struts2/legacy/DynaBeanPropertyAccessorTest.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/legacy/src/test/java/org/apache/struts2/legacy/DynaBeanPropertyAccessorTest.java?view=auto&rev=449344
==============================================================================
---
struts/struts2/trunk/legacy/src/test/java/org/apache/struts2/legacy/DynaBeanPropertyAccessorTest.java
(added)
+++
struts/struts2/trunk/legacy/src/test/java/org/apache/struts2/legacy/DynaBeanPropertyAccessorTest.java
Sat Sep 23 19:27:41 2006
@@ -0,0 +1,134 @@
+package org.apache.struts2.legacy;
+
+import junit.framework.*;
+import java.io.*;
+import java.util.*;
+import org.apache.commons.beanutils.*;
+
+import ognl.*;
+
+/** Description of the Class */
+public class DynaBeanPropertyAccessorTest extends TestCase {
+
+ protected DynaBean bean = null;
+
+ public DynaBeanPropertyAccessorTest(String name) throws Exception {
+ super(name);
+ }
+
+
+ public static void main(String args[]) {
+ junit.textui.TestRunner.run(DynaBeanPropertyAccessorTest.class);
+ }
+
+ /**
+ * Set up instance variables required by this test case.
+ */
+ public void setUp() throws Exception {
+
+ // Instantiate a new DynaBean instance
+ DynaClass dynaClass = createDynaClass();
+ bean = dynaClass.newInstance();
+
+ // Initialize the DynaBean's property values (like TestBean)
+ bean.set("booleanProperty", new Boolean(true));
+ bean.set("booleanSecond", new Boolean(true));
+ bean.set("doubleProperty", new Double(321.0));
+ bean.set("floatProperty", new Float((float) 123.0));
+ int intArray[] = { 0, 10, 20, 30, 40 };
+ bean.set("intArray", intArray);
+ int intIndexed[] = { 0, 10, 20, 30, 40 };
+ bean.set("intIndexed", intIndexed);
+ bean.set("intProperty", new Integer(123));
+ List listIndexed = new ArrayList();
+ listIndexed.add("String 0");
+ listIndexed.add("String 1");
+ listIndexed.add("String 2");
+ listIndexed.add("String 3");
+ listIndexed.add("String 4");
+ bean.set("listIndexed", listIndexed);
+ bean.set("longProperty", new Long((long) 321));
+ HashMap mappedProperty = new HashMap();
+ mappedProperty.put("First Key", "First Value");
+ mappedProperty.put("Second Key", "Second Value");
+ bean.set("mappedProperty", mappedProperty);
+ HashMap mappedIntProperty = new HashMap();
+ mappedIntProperty.put("One", new Integer(1));
+ mappedIntProperty.put("Two", new Integer(2));
+ bean.set("mappedIntProperty", mappedIntProperty);
+ // Property "nullProperty" is not initialized, so it should return null
+ bean.set("shortProperty", new Short((short) 987));
+ String stringArray[] =
+ { "String 0", "String 1", "String 2", "String 3", "String 4" };
+ bean.set("stringArray", stringArray);
+ String stringIndexed[] =
+ { "String 0", "String 1", "String 2", "String 3", "String 4" };
+ bean.set("stringIndexed", stringIndexed);
+ bean.set("stringProperty", "This is a string");
+
+ }
+
+
+
+
+ public void testGetProperty() throws Exception {
+
+ DynaBeanPropertyAccessor trans = new DynaBeanPropertyAccessor();
+ assertTrue("This is a string".equals(trans.getProperty(null, bean,
"stringProperty")));
+ assertTrue(trans.getProperty(null, bean, "listIndexed") instanceof
List);
+
+ }
+
+ public void testSetProperty() throws Exception {
+
+ DynaBeanPropertyAccessor trans = new DynaBeanPropertyAccessor();
+ trans.setProperty(null, bean, "stringProperty", "bob");
+ assertTrue("bob".equals(trans.getProperty(null, bean,
"stringProperty")));
+
+ }
+
+ public void testOGNL() throws Exception {
+
+ OgnlRuntime.setPropertyAccessor(DynaBean.class, new
DynaBeanPropertyAccessor());
+
+ assertTrue("This is a string".equals(Ognl.getValue("stringProperty",
bean)));
+
+ }
+
+
+ /**
+ * Create and return a <code>DynaClass</code> instance for our test
+ * <code>DynaBean</code>.
+ */
+ protected DynaClass createDynaClass() {
+
+ int intArray[] = new int[0];
+ String stringArray[] = new String[0];
+
+ DynaClass dynaClass = new BasicDynaClass
+ ("TestDynaClass", null,
+ new DynaProperty[]{
+ new DynaProperty("booleanProperty", Boolean.TYPE),
+ new DynaProperty("booleanSecond", Boolean.TYPE),
+ new DynaProperty("doubleProperty", Double.TYPE),
+ new DynaProperty("floatProperty", Float.TYPE),
+ new DynaProperty("intArray", intArray.getClass()),
+ new DynaProperty("intIndexed",
intArray.getClass()),
+ new DynaProperty("intProperty", Integer.TYPE),
+ new DynaProperty("listIndexed", List.class),
+ new DynaProperty("longProperty", Long.TYPE),
+ new DynaProperty("mappedProperty", Map.class),
+ new DynaProperty("mappedIntProperty", Map.class),
+ new DynaProperty("nullProperty", String.class),
+ new DynaProperty("shortProperty", Short.TYPE),
+ new DynaProperty("stringArray",
stringArray.getClass()),
+ new DynaProperty("stringIndexed",
stringArray.getClass()),
+ new DynaProperty("stringProperty", String.class),
+ });
+ return (dynaClass);
+
+ }
+
+
+}
+
Added:
struts/struts2/trunk/legacy/src/test/java/org/apache/struts2/legacy/ScopedModelDrivenInterceptorTest.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/legacy/src/test/java/org/apache/struts2/legacy/ScopedModelDrivenInterceptorTest.java?view=auto&rev=449344
==============================================================================
---
struts/struts2/trunk/legacy/src/test/java/org/apache/struts2/legacy/ScopedModelDrivenInterceptorTest.java
(added)
+++
struts/struts2/trunk/legacy/src/test/java/org/apache/struts2/legacy/ScopedModelDrivenInterceptorTest.java
Sat Sep 23 19:27:41 2006
@@ -0,0 +1,53 @@
+package org.apache.struts2.legacy;
+
+import junit.framework.*;
+import java.io.*;
+import java.util.*;
+import org.apache.commons.beanutils.*;
+import com.opensymphony.xwork2.ObjectFactory;
+import ognl.*;
+
+/** Description of the Class */
+public class ScopedModelDrivenInterceptorTest extends TestCase {
+
+ protected ScopedModelDrivenInterceptor inter = null;
+
+ public ScopedModelDrivenInterceptorTest(String name) throws Exception {
+ super(name);
+ }
+
+
+ public static void main(String args[]) {
+ junit.textui.TestRunner.run(ScopedModelDrivenInterceptorTest.class);
+ }
+
+ /**
+ * Set up instance variables required by this test case.
+ */
+ public void setUp() throws Exception {
+
+ inter = new ScopedModelDrivenInterceptor();
+ }
+
+
+
+
+ public void testResolveModel() throws Exception {
+ ObjectFactory factory = ObjectFactory.getObjectFactory();
+ Object obj = inter.resolveModel(factory, null, "java.lang.String",
"request", null);
+ assertNotNull(obj);
+ assertTrue(obj instanceof String);
+
+ HashMap session = new HashMap();
+ obj = inter.resolveModel(factory, session, "java.lang.String",
"session", "foo");
+ assertNotNull(obj);
+ assertTrue(obj instanceof String);
+ assertTrue(obj == session.get("foo"));
+
+ obj = inter.resolveModel(factory, session, "java.lang.String",
"session", "foo");
+ assertNotNull(obj);
+ assertTrue(obj instanceof String);
+ assertTrue(obj == session.get("foo"));
+ }
+}
+
Added:
struts/struts2/trunk/legacy/src/test/java/org/apache/struts2/legacy/StrutsFactoryTest.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/legacy/src/test/java/org/apache/struts2/legacy/StrutsFactoryTest.java?view=auto&rev=449344
==============================================================================
---
struts/struts2/trunk/legacy/src/test/java/org/apache/struts2/legacy/StrutsFactoryTest.java
(added)
+++
struts/struts2/trunk/legacy/src/test/java/org/apache/struts2/legacy/StrutsFactoryTest.java
Sat Sep 23 19:27:41 2006
@@ -0,0 +1,231 @@
+package org.apache.struts2.legacy;
+
+import junit.framework.*;
+import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider;
+import com.opensymphony.xwork2.config.ConfigurationManager;
+import com.opensymphony.xwork2.config.Configuration;
+import com.opensymphony.xwork2.config.ConfigurationProvider;
+import com.opensymphony.xwork2.config.entities.PackageConfig;
+import com.opensymphony.xwork2.config.entities.ResultConfig;
+import com.opensymphony.xwork2.config.entities.ExceptionMappingConfig;
+import com.opensymphony.xwork2.ActionSupport;
+import org.apache.struts.action.*;
+import org.apache.struts.config.*;
+import org.apache.struts2.config.StrutsXMLConfigurationProvider;
+
+import java.io.InputStream;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+
+/**
+ * Test of StrutsFactory, which creates Struts 1.x wrappers around XWork
config objects.
+ */
+public class StrutsFactoryTest extends TestCase {
+
+ private static final String PACKAGE_NAME = "org/apache/struts2/legacy";
+
+ protected StrutsFactory factory = null;
+ protected Configuration config;
+
+ public StrutsFactoryTest(String name) throws Exception {
+ super(name);
+ }
+
+
+ public static void main(String args[]) {
+ junit.textui.TestRunner.run(StrutsFactoryTest.class);
+ }
+
+ /**
+ * Set up instance variables required by this test case.
+ */
+ public void setUp() {
+ ConfigurationManager manager = new ConfigurationManager();
+ ConfigurationProvider provider = new
StrutsXMLConfigurationProvider(PACKAGE_NAME + "/test-struts-factory.xml", true);
+ manager.addConfigurationProvider(provider);
+ config = manager.getConfiguration();
+ factory = new StrutsFactory(config);
+ }
+
+ /**
+ * Test the creation of a Struts 1.x ModuleConfig wrapper around an XWork
PackageConfig.
+ * The PackageConfig is loaded from test-struts-factory.xml.
+ */
+ public void testCreateModuleConfig() {
+ ModuleConfig moduleConfig = factory.createModuleConfig(PACKAGE_NAME);
+ assertNotNull(moduleConfig);
+
+ assertEquals("/"+PACKAGE_NAME, moduleConfig.getPrefix());
+
+ ActionConfig actionConfig = moduleConfig.findActionConfig("/action1");
+ assertNotNull(actionConfig);
+ assertEquals("/action1", actionConfig.getPath());
+
+ ActionConfig[] actionConfigs = moduleConfig.findActionConfigs();
+ assertNotNull(actionConfigs);
+ assertEquals(2, actionConfigs.length);
+
+ ExceptionConfig exceptionConfig =
moduleConfig.findExceptionConfig(Exception.class.getName());
+ assertNotNull(exceptionConfig);
+ assertEquals(Exception.class.getName(), exceptionConfig.getType());
+
+ ExceptionConfig[] exceptionConfigs =
moduleConfig.findExceptionConfigs();
+ assertNotNull(exceptionConfigs);
+ assertEquals(1, exceptionConfigs.length);
+
+ ForwardConfig fwdConfig =
moduleConfig.findForwardConfig("globalResult");
+ assertNotNull(fwdConfig);
+ assertEquals("globalResult", fwdConfig.getName());
+
+ // These methods are currently not implemented -- replace as
functionality is added.
+ assertNYI(moduleConfig, "getControllerConfig", null);
+ assertNYI(moduleConfig, "getActionFormBeanClass", null);
+ assertNYI(moduleConfig, "getActionMappingClass", null);
+ assertNYI(moduleConfig, "getActionForwardClass", null);
+ assertNYI(moduleConfig, "findException", Class.class);
+ assertNYI(moduleConfig, "findFormBeanConfig", String.class);
+ assertNYI(moduleConfig, "findFormBeanConfigs", null);
+ assertNYI(moduleConfig, "findMessageResourcesConfig", String.class);
+ assertNYI(moduleConfig, "findMessageResourcesConfigs", null);
+ assertNYI(moduleConfig, "findPlugInConfigs", null);
+ }
+
+ /**
+ * Test the creation of a Struts 1.x ActionMapping wrapper around an XWork
ActionConfig.
+ * The ActionConfig is loaded from test-struts-factory.xml.
+ */
+ public void testCreateActionMapping() {
+ PackageConfig packageConfig = config.getPackageConfig(PACKAGE_NAME);
+ com.opensymphony.xwork2.config.entities.ActionConfig actionConfig =
+ (com.opensymphony.xwork2.config.entities.ActionConfig)
packageConfig.getActionConfigs().get("action1");
+ ActionMapping mapping = factory.createActionMapping(actionConfig);
+ assertNotNull(mapping);
+
+ assertNotNull(mapping.findForward("result1"));
+ assertNotNull(mapping.findForwardConfig("result2"));
+
+ ForwardConfig[] configs = mapping.findForwardConfigs();
+ assertNotNull(configs);
+ assertEquals(2, configs.length);
+
+ String[] forwards = mapping.findForwards();
+ assertNotNull(forwards);
+ assertEquals(2, forwards.length);
+
+ ActionForward fwd = mapping.findForward("result1");
+ assertNotNull(fwd);
+ assertEquals("result1", fwd.getName());
+
+ assertNotNull(mapping.findException(NullPointerException.class));
+
assertNotNull(mapping.findExceptionConfig("java.lang.IllegalStateException"));
+
+ ExceptionConfig[] exceptionConfigs = mapping.findExceptionConfigs();
+ assertNotNull(exceptionConfigs);
+ assertEquals(3, exceptionConfigs.length);
+
+ ModuleConfig moduleConfig = mapping.getModuleConfig();
+ assertNotNull(moduleConfig);
+
+ // For now, the path will be null if the ActionMapping was created on
its own (as opposed to from a
+ // WrapperModuleConfig, which knows the path).
+ assertNull(mapping.getPath());
+
+ // These methods are currently not implemented -- replace as
functionality is added.
+ assertNYI(mapping, "getInputForward", null);
+ assertNYI(mapping, "getAttribute", null);
+ assertNYI(mapping, "getForward", null);
+ assertNYI(mapping, "getInclude", null);
+ assertNYI(mapping, "getInput", null);
+ assertNYI(mapping, "getMultipartClass", null);
+ assertNYI(mapping, "getName", null);
+ assertNYI(mapping, "getParameter", null);
+ assertNYI(mapping, "getPrefix", null);
+ assertNYI(mapping, "getRoles", null);
+ assertNYI(mapping, "getRoleNames", null);
+ assertNYI(mapping, "getScope", null);
+ assertNYI(mapping, "getSuffix", null);
+ assertNYI(mapping, "getType", null);
+ assertNYI(mapping, "getUnknown", null);
+ assertNYI(mapping, "getValidate", null);
+ }
+
+ /**
+ * Test the creation of a Struts 1.x ActionForward wrapper around an XWork
ResultConfig.
+ * The ResultConfig is loaded from test-struts-factory.xml.
+ */
+ public void testCreateActionForward() {
+ PackageConfig packageConfig = config.getPackageConfig(PACKAGE_NAME);
+ ResultConfig resultConfig = (ResultConfig)
packageConfig.getGlobalResultConfigs().get("globalResult");
+ ActionForward fwd = factory.createActionForward(resultConfig);
+ assertNotNull(fwd);
+ assertEquals("globalResult", fwd.getName());
+
+ // These methods are currently not implemented -- replace as
functionality is added.
+ assertNYI(fwd, "getPath", null);
+ assertNYI(fwd, "getModule", null);
+ assertNYI(fwd, "getRedirect", null);
+ }
+
+ /**
+ * Test the creation of a Struts 1.x ExceptionConfig wrapper around an
XWork ExceptionHandlerConfig.
+ * The ExceptionConfig is loaded from test-struts-factory.xml.
+ */
+ public void testCreateExceptionConfig() {
+ PackageConfig packageConfig = config.getPackageConfig(PACKAGE_NAME);
+ ExceptionMappingConfig cfg = (ExceptionMappingConfig)
packageConfig.getGlobalExceptionMappingConfigs().get(0);
+ ExceptionConfig exceptionConfig = factory.createExceptionConfig(cfg);
+ assertNotNull(exceptionConfig);
+ assertEquals(Exception.class.getName(), exceptionConfig.getType());
+
+ assertNYI(exceptionConfig, "getBundle", null);
+ assertNYI(exceptionConfig, "getHandler", null);
+ assertNYI(exceptionConfig, "getKey", null);
+ assertNYI(exceptionConfig, "getPath", null);
+ assertNYI(exceptionConfig, "getScope", null);
+ }
+
+ public void testConvertErrors() throws Exception {
+
+ ActionMessage err1 = new ActionMessage("error1");
+ ActionMessage err2 = new ActionMessage("error2", new Integer(1));
+ ActionErrors errors = new ActionErrors();
+ errors.add(errors.GLOBAL_MESSAGE, err1);
+ errors.add("foo", err2);
+
+ ActionSupport action = new ActionSupport();
+ factory.convertErrors(errors, action);
+
+ assertTrue(1 == action.getActionErrors().size());
+ assertTrue(1 == action.getFieldErrors().size());
+ }
+
+ /**
+ * Assert that the given method throws UnsupportedOperationException.
+ */
+ private void assertNYI(Object o, String methodName, Class argType) {
+ try {
+ Class[] argTypes = argType != null ? new Class[]{argType} : null;
+
+ Object[] args = null;
+ if (argType != null) {
+ if (Class.class == argType) {
+ args = new Object[]{argType};
+ } else {
+ args = new Object[]{argType.newInstance()};
+ }
+ }
+ o.getClass().getMethod(methodName, argTypes).invoke(o, args);
+ } catch (InvocationTargetException e) {
+ Throwable cause = e.getCause();
+ assertEquals(cause.getMessage(),
UnsupportedOperationException.class, cause.getClass());
+
+ // OK -- it's what we expected
+ return;
+ } catch (Exception e) {
+ fail(e.getClass().getName() + ": " + e.getMessage());
+ }
+
+ fail("Expected UnsupportedOperationException for " + methodName + "()
on " + o.getClass().getName());
+ }
+}
Copied:
struts/struts2/trunk/legacy/src/test/resources/org/apache/struts2/legacy/test-struts-factory.xml
(from r449318,
struts/sandbox/trunk/ti/phase1/jars/legacy/src/test/org/apache/ti/legacy/test-struts-factory.xml)
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/legacy/src/test/resources/org/apache/struts2/legacy/test-struts-factory.xml?view=diff&rev=449344&p1=struts/sandbox/trunk/ti/phase1/jars/legacy/src/test/org/apache/ti/legacy/test-struts-factory.xml&r1=449318&p2=struts/struts2/trunk/legacy/src/test/resources/org/apache/struts2/legacy/test-struts-factory.xml&r2=449344
==============================================================================
---
struts/sandbox/trunk/ti/phase1/jars/legacy/src/test/org/apache/ti/legacy/test-struts-factory.xml
(original)
+++
struts/struts2/trunk/legacy/src/test/resources/org/apache/struts2/legacy/test-struts-factory.xml
Sat Sep 23 19:27:41 2006
@@ -1,11 +1,14 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.0//EN"
"http://www.opensymphony.com/xwork/xwork-1.1.dtd">
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!DOCTYPE struts PUBLIC
+ "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
+ "http://struts.apache.org/dtds/struts-2.0.dtd">
<!-- Used by the TestStrutsFactory TestCase. -->
-<xwork>
- <package name="/org/apache/ti/legacy" namespace="/org/apache/ti/legacy">
+<struts>
+ <package name="org/apache/struts2/legacy"
namespace="/org/apache/struts2/legacy">
<result-types>
- <result-type
class="com.opensymphony.webwork.dispatcher.ServletDispatcherResult"
name="servletDispatcherResult"/>
+ <result-type
class="org.apache.struts2.dispatcher.ServletDispatcherResult"
name="servletDispatcherResult"/>
</result-types>
<global-results>
<result name="globalResult" type="servletDispatcherResult">
@@ -18,7 +21,7 @@
exception="java.lang.Exception"
result="globalResult"/>
</global-exception-mappings>
- <action class="com.opensymphony.xwork.ActionSupport" name="action1">
+ <action class="com.opensymphony.xwork2.ActionSupport" name="action1">
<result name="result1" type="servletDispatcherResult">
<param name="location">result1.jsp</param>
</result>
@@ -34,7 +37,7 @@
exception="java.lang.IllegalStateException"
result="anotherResult"/>
</action>
- <action class="com.opensymphony.xwork.ActionSupport" name="action2"/>
+ <action class="com.opensymphony.xwork2.ActionSupport" name="action2"/>
</package>
-</xwork>
+</struts>
Modified: struts/struts2/trunk/pom.xml
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/pom.xml?view=diff&rev=449344&r1=449343&r2=449344
==============================================================================
--- struts/struts2/trunk/pom.xml (original)
+++ struts/struts2/trunk/pom.xml Sat Sep 23 19:27:41 2006
@@ -77,6 +77,7 @@
<modules>
<module>core</module>
+ <module>legacy</module>
<!--<module>assembly</module>-->
<module>api</module>
</modules>