You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2022/11/30 08:28:15 UTC
[struts-examples] 01/01: Adjust examples to Struts 6.1.1
This is an automated email from the ASF dual-hosted git repository.
lukaszlenart pushed a commit to branch struts-611
in repository https://gitbox.apache.org/repos/asf/struts-examples.git
commit bebfd8c9177e658de001d64172a1f38dad494706
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Wed Nov 30 09:18:57 2022 +0100
Adjust examples to Struts 6.1.1
---
blank/src/test/java/example/ConfigTest.java | 2 +-
blank/src/test/java/example/HelloWorldTest.java | 9 +-
.../org/apache/struts/edit/action/EditAction.java | 20 ++--
control-tags/src/main/resources/struts.xml | 38 ++++---
control-tags/src/main/webapp/WEB-INF/web.xml | 8 +-
control-tags/src/main/webapp/index.jsp | 2 +-
control-tags/src/main/webapp/thankyou.jsp | 2 +-
.../apache/struts/register/action/Register.java | 17 +++
.../org/apache/struts/register/model/Person.java | 14 ++-
form-processing/src/main/resources/struts.xml | 4 +-
.../src/main/webapp/WEB-INF/register.jsp | 3 +
.../src/main/webapp/WEB-INF/thankyou.jsp | 1 +
.../helloworld/action/ExecAndWaitTestAction.java | 14 +++
helloworld/src/main/resources/struts.xml | 46 +++++---
helloworld/src/main/webapp/HelloWorld.jsp | 1 +
helloworld/src/main/webapp/WEB-INF/web.xml | 20 ++--
helloworld/src/main/webapp/execAndWaitTest.jsp | 16 +++
.../src/main/webapp/execAndWaitTest_wait.jsp | 20 ++++
helloworld/src/main/webapp/index.jsp | 16 ++-
pom.xml | 37 ++++---
.../struts/actions/IndexControllerTest.java | 29 ++++-
.../struts/actions/data/OrderControllerTest.java | 26 ++++-
text-provider/pom.xml | 4 -
.../struts/register/action/RegisterTest.java | 123 ++++++++++-----------
24 files changed, 307 insertions(+), 165 deletions(-)
diff --git a/blank/src/test/java/example/ConfigTest.java b/blank/src/test/java/example/ConfigTest.java
index 006f87b..5663474 100644
--- a/blank/src/test/java/example/ConfigTest.java
+++ b/blank/src/test/java/example/ConfigTest.java
@@ -24,8 +24,8 @@ import com.opensymphony.xwork2.config.RuntimeConfiguration;
import com.opensymphony.xwork2.config.entities.ActionConfig;
import com.opensymphony.xwork2.config.entities.ResultConfig;
import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider;
-import org.apache.struts2.StrutsTestCase;
import org.apache.struts2.config.StrutsXmlConfigurationProvider;
+import org.apache.struts2.junit.StrutsTestCase;
import java.util.List;
import java.util.Map;
diff --git a/blank/src/test/java/example/HelloWorldTest.java b/blank/src/test/java/example/HelloWorldTest.java
index fcc4e68..0ef5990 100644
--- a/blank/src/test/java/example/HelloWorldTest.java
+++ b/blank/src/test/java/example/HelloWorldTest.java
@@ -16,20 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package example;
import com.opensymphony.xwork2.ActionSupport;
-import org.apache.struts2.StrutsTestCase;
+import org.apache.struts2.junit.StrutsTestCase;
public class HelloWorldTest extends StrutsTestCase {
public void testHelloWorld() throws Exception {
HelloWorld hello_world = container.inject(HelloWorld.class);
String result = hello_world.execute();
- assertTrue("Expected a success result!",
- ActionSupport.SUCCESS.equals(result));
- assertTrue("Expected the default message!",
- hello_world.getText(HelloWorld.MESSAGE).equals(hello_world.getMessage()));
+ assertEquals("Expected a success result!", ActionSupport.SUCCESS, result);
+ assertEquals("Expected the default message!", hello_world.getText(HelloWorld.MESSAGE), hello_world.getMessage());
}
}
diff --git a/control-tags/src/main/java/org/apache/struts/edit/action/EditAction.java b/control-tags/src/main/java/org/apache/struts/edit/action/EditAction.java
index eaaf6f1..cc8ceee 100755
--- a/control-tags/src/main/java/org/apache/struts/edit/action/EditAction.java
+++ b/control-tags/src/main/java/org/apache/struts/edit/action/EditAction.java
@@ -17,33 +17,33 @@ import java.util.List;
*
*/
public class EditAction extends ActionSupport {
-
+
private static final long serialVersionUID = 1L;
-
+
private EditService editService = new EditServiceInMemory();
-
+
private Person personBean;
private String [] sports = {"football", "baseball", "basketball" };
private String [] genders = {"male", "female", "not sure" };
private List<State> states ;
private String [] carModelsAvailable = {"Ford","Chrysler","Toyota","Nissan"};
- public String execute() throws Exception {
+ public String save() throws Exception {
editService.savePerson( getPersonBean() );
-
+
return SUCCESS;
}
public String input() throws Exception {
setPersonBean( editService.getPerson() );
-
+
return INPUT;
}
-
+
public Person getPersonBean() {
return personBean;
}
-
+
public void setPersonBean(Person person) {
personBean = person;
}
@@ -51,7 +51,7 @@ public class EditAction extends ActionSupport {
public List<String> getSports() {
return Arrays.asList(sports);
}
-
+
public List<String> getGenders() {
return Arrays.asList(genders);
}
@@ -66,7 +66,7 @@ public class EditAction extends ActionSupport {
states.add( new State("FL", "Florida") );
states.add( new State("KS", "Kansas") );
states.add( new State("NY", "New York") );
-
+
return states;
}
diff --git a/control-tags/src/main/resources/struts.xml b/control-tags/src/main/resources/struts.xml
index 219494c..9bf7dc1 100755
--- a/control-tags/src/main/resources/struts.xml
+++ b/control-tags/src/main/resources/struts.xml
@@ -1,29 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
- "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
- "http://struts.apache.org/dtds/struts-2.5.dtd">
+ "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
+ "http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
- <constant name="struts.devMode" value="true" />
+ <constant name="struts.devMode" value="true"/>
+ <constant name="struts.enable.DynamicMethodInvocation" value="true"/>
- <package name="basicstruts2" extends="struts-default">
+ <package name="basicstruts2" extends="struts-default">
+ <default-action-ref name="index"/>
- <!-- If no class attribute is specified the framework will assume success and
+ <!-- If no class attribute is specified the framework will assume success and
render the result index.jsp -->
<!-- If no name value for the result node is specified the success value is the default -->
- <action name="index">
- <result>/index.jsp</result>
- </action>
+ <action name="index">
+ <result>/index.jsp</result>
+ </action>
- <action name="edit" class="org.apache.struts.edit.action.EditAction" method="input">
- <result name="input">/edit.jsp</result>
- </action>
-
- <action name="save" class="org.apache.struts.edit.action.EditAction" method="execute">
- <result name="input">/edit.jsp</result>
- <result name="success">/thankyou.jsp</result>
- </action>
+ <action name="edit" class="org.apache.struts.edit.action.EditAction" method="input">
+ <result name="input">/edit.jsp</result>
+ </action>
- </package>
+ <action name="save" class="org.apache.struts.edit.action.EditAction" method="save">
+ <result name="input">/edit.jsp</result>
+ <result name="success">/thankyou.jsp</result>
+ </action>
-</struts>
\ No newline at end of file
+ </package>
+
+</struts>
diff --git a/control-tags/src/main/webapp/WEB-INF/web.xml b/control-tags/src/main/webapp/WEB-INF/web.xml
index 2692584..f045032 100755
--- a/control-tags/src/main/webapp/WEB-INF/web.xml
+++ b/control-tags/src/main/webapp/WEB-INF/web.xml
@@ -2,10 +2,10 @@
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>control_tags</display-name>
<welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
+ <welcome-file>/index</welcome-file>
</welcome-file-list>
-
-
+
+
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
@@ -15,5 +15,5 @@
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
-
+
</web-app>
diff --git a/control-tags/src/main/webapp/index.jsp b/control-tags/src/main/webapp/index.jsp
index 70613c1..38130ec 100755
--- a/control-tags/src/main/webapp/index.jsp
+++ b/control-tags/src/main/webapp/index.jsp
@@ -10,6 +10,6 @@
<body>
<h1>Welcome To Struts 2!</h1>
-<p><a href='<s:url action="edit" />'>Edit your information</a></p>
+<p><a href='<s:url action="edit" includeParams="all" />'>Edit your information</a></p>
</body>
</html>
diff --git a/control-tags/src/main/webapp/thankyou.jsp b/control-tags/src/main/webapp/thankyou.jsp
index f186888..fb03f71 100755
--- a/control-tags/src/main/webapp/thankyou.jsp
+++ b/control-tags/src/main/webapp/thankyou.jsp
@@ -46,7 +46,7 @@
</s:iterator>
</table>
-<p><a href="<s:url action='index' />">Return to home page</a>.</p>
+<p><a href="<s:url action='index' includeParams="all"/>">Return to home page</a>.</p>
</body>
</html>
diff --git a/form-processing/src/main/java/org/apache/struts/register/action/Register.java b/form-processing/src/main/java/org/apache/struts/register/action/Register.java
index bfa99db..49974d8 100644
--- a/form-processing/src/main/java/org/apache/struts/register/action/Register.java
+++ b/form-processing/src/main/java/org/apache/struts/register/action/Register.java
@@ -3,15 +3,25 @@ package org.apache.struts.register.action;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts.register.model.Person;
+import java.util.ArrayList;
+import java.util.List;
+
public class Register extends ActionSupport {
private Person personBean;
+ private List<Integer> options;
public String execute2() throws Exception {
//call Service class to store personBean's state in database
return SUCCESS;
}
+ public String input() throws Exception {
+ this.options = new ArrayList<>();
+ this.options.add(3);
+ return INPUT;
+ }
+
public String cancel2() throws Exception {
return SUCCESS;
}
@@ -24,4 +34,11 @@ public class Register extends ActionSupport {
personBean = person;
}
+ public List<Integer> getOptions() {
+ return options;
+ }
+
+ public void setOptions(List<Integer> options) {
+ this.options = options;
+ }
}
diff --git a/form-processing/src/main/java/org/apache/struts/register/model/Person.java b/form-processing/src/main/java/org/apache/struts/register/model/Person.java
index ade6961..2103076 100644
--- a/form-processing/src/main/java/org/apache/struts/register/model/Person.java
+++ b/form-processing/src/main/java/org/apache/struts/register/model/Person.java
@@ -1,10 +1,13 @@
package org.apache.struts.register.model;
+import java.util.List;
+
public class Person {
private String firstName;
private String lastName;
private String email;
private int age;
+ private List<Integer> options;
public String getFirstName() {
return firstName;
@@ -38,10 +41,19 @@ public class Person {
this.age = age;
}
+ public List<Integer> getOptions() {
+ return options;
+ }
+
+ public void setOptions(List<Integer> options) {
+ this.options = options;
+ }
+
public String toString() {
return "First Name: " + getFirstName() +
" Last Name: " + getLastName() +
" Email: " + getEmail() +
- " Age: " + getAge();
+ " Age: " + getAge() +
+ " Options: " + getOptions();
}
}
diff --git a/form-processing/src/main/resources/struts.xml b/form-processing/src/main/resources/struts.xml
index 56f4999..3345180 100644
--- a/form-processing/src/main/resources/struts.xml
+++ b/form-processing/src/main/resources/struts.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
- "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
- "http://struts.apache.org/dtds/struts-2.5.dtd">
+ "-//Apache Software Foundation//DTD Struts Configuration 6.0//EN"
+ "https://struts.apache.org/dtds/struts-6.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.enable.DynamicMethodInvocation" value="true"/>
diff --git a/form-processing/src/main/webapp/WEB-INF/register.jsp b/form-processing/src/main/webapp/WEB-INF/register.jsp
index 5f17f61..25c056b 100644
--- a/form-processing/src/main/webapp/WEB-INF/register.jsp
+++ b/form-processing/src/main/webapp/WEB-INF/register.jsp
@@ -14,6 +14,9 @@
<s:textfield name="personBean.lastName" label="Last name"/>
<s:textfield name="personBean.email" label="Email"/>
<s:textfield name="personBean.age" label="Age"/>
+ <s:checkbox name="options[0]" fieldValue="1" label="1" />
+ <s:checkbox name="options[1]" fieldValue="2" label="2" />
+ <s:checkbox name="options[2]" fieldValue="3" label="3" />
<s:submit/>
<s:submit action="register-cancel" value="Cancel" />
</s:form>
diff --git a/form-processing/src/main/webapp/WEB-INF/thankyou.jsp b/form-processing/src/main/webapp/WEB-INF/thankyou.jsp
index 665339f..38fea5f 100644
--- a/form-processing/src/main/webapp/WEB-INF/thankyou.jsp
+++ b/form-processing/src/main/webapp/WEB-INF/thankyou.jsp
@@ -10,6 +10,7 @@
<h3>Thank you for registering for a prize.</h3>
<p>Your registration information: <s:property value="personBean" /> </p>
+ <p>Your registration information: <s:property value="options" /> </p>
<p><a href="<s:url action='index' />" >Return to home page</a>.</p>
</body>
diff --git a/helloworld/src/main/java/org/apache/struts/helloworld/action/ExecAndWaitTestAction.java b/helloworld/src/main/java/org/apache/struts/helloworld/action/ExecAndWaitTestAction.java
new file mode 100644
index 0000000..12e665d
--- /dev/null
+++ b/helloworld/src/main/java/org/apache/struts/helloworld/action/ExecAndWaitTestAction.java
@@ -0,0 +1,14 @@
+package org.apache.struts.helloworld.action;
+
+import com.opensymphony.xwork2.ActionSupport;
+
+import java.util.concurrent.TimeUnit;
+
+public class ExecAndWaitTestAction extends ActionSupport {
+
+ public String test() throws InterruptedException {
+ TimeUnit.SECONDS.sleep(15);
+ return SUCCESS;
+ }
+
+}
diff --git a/helloworld/src/main/resources/struts.xml b/helloworld/src/main/resources/struts.xml
index b0f3e63..8adf5e8 100755
--- a/helloworld/src/main/resources/struts.xml
+++ b/helloworld/src/main/resources/struts.xml
@@ -1,27 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
- "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
- "http://struts.apache.org/dtds/struts-2.5.dtd">
+ "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
+ "http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
- <constant name="struts.devMode" value="true" />
+ <constant name="struts.devMode" value="true"/>
+ <constant name="struts.action.extension" value=","/>
- <package name="basicstruts2" extends="struts-default">
+ <package name="basicstruts2" namespace="/" extends="struts-default">
+ <default-action-ref name="index"/>
- <!-- If no class attribute is specified the framework will assume success and
+ <!-- If no class attribute is specified the framework will assume success and
render the result index.jsp -->
<!-- If no name value for the result node is specified the success value is the default -->
- <action name="index">
- <result>/index.jsp</result>
- </action>
-
- <!-- If the URL is hello.action then call the execute method of class HelloWorldAction.
- If the result returned by the execute method is success render the HelloWorld.jsp -->
- <action name="hello" class="org.apache.struts.helloworld.action.HelloWorldAction" method="execute">
- <result name="success">/HelloWorld.jsp</result>
- </action>
-
- </package>
+ <action name="index">
+ <result>/index.jsp</result>
+ </action>
+
+ <!-- If the URL is hello.action then call the execute method of class HelloWorldAction.
+ If the result returned by the execute method is success render the HelloWorld.jsp -->
+ <action name="hello" class="org.apache.struts.helloworld.action.HelloWorldAction" method="execute">
+ <result name="success">/HelloWorld.jsp</result>
+ </action>
+
+ <!-- Executed And Wait Test -->
+ <action name="ExecAndWaitTest" class="org.apache.struts.helloworld.action.ExecAndWaitTestAction">
+ <interceptor-ref name="basicStack"/>
+ <result>/execAndWaitTest.jsp</result>
+ </action>
+ <action name="ExecAndWaitTest_test" class="org.apache.struts.helloworld.action.ExecAndWaitTestAction" method="test">
+ <interceptor-ref name="basicStack"/>
+ <interceptor-ref name="execAndWait"/>
+ <result name="wait">/execAndWaitTest_wait.jsp</result>
+ <result type="redirectAction">ExecAndWaitTest</result>
+ </action>
+
+ </package>
</struts>
diff --git a/helloworld/src/main/webapp/HelloWorld.jsp b/helloworld/src/main/webapp/HelloWorld.jsp
index db8e040..0ee7613 100755
--- a/helloworld/src/main/webapp/HelloWorld.jsp
+++ b/helloworld/src/main/webapp/HelloWorld.jsp
@@ -8,5 +8,6 @@
</head>
<body>
<h2><s:property value="messageStore.message" /></h2>
+ <p><a href="<s:url action="index"/>">Home</a></p>
</body>
</html>
diff --git a/helloworld/src/main/webapp/WEB-INF/web.xml b/helloworld/src/main/webapp/WEB-INF/web.xml
index 3bf270d..4fc7bc1 100755
--- a/helloworld/src/main/webapp/WEB-INF/web.xml
+++ b/helloworld/src/main/webapp/WEB-INF/web.xml
@@ -1,19 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
-<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
-<display-name>Hello World Struts 2</display-name>
- <welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
-
-
+<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+ <display-name>Hello World Struts 2</display-name>
+ <welcome-file-list>
+ <welcome-file>/index</welcome-file>
+ </welcome-file-list>
+
+
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
- <filter-mapping>
+ <filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
-
+
</web-app>
diff --git a/helloworld/src/main/webapp/execAndWaitTest.jsp b/helloworld/src/main/webapp/execAndWaitTest.jsp
new file mode 100644
index 0000000..7b18000
--- /dev/null
+++ b/helloworld/src/main/webapp/execAndWaitTest.jsp
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title>Basic Struts 2 Application - Welcome</title>
+</head>
+<body>
+
+<s:form name="frmLetterMenu" action="ExecAndWaitTest_test" accept-charset="utf-8">
+ <s:token/>
+ <s:submit value="Test Execute And Wait"/>
+</s:form>
+
+</body>
+</html>
diff --git a/helloworld/src/main/webapp/execAndWaitTest_wait.jsp b/helloworld/src/main/webapp/execAndWaitTest_wait.jsp
new file mode 100644
index 0000000..37ec9a1
--- /dev/null
+++ b/helloworld/src/main/webapp/execAndWaitTest_wait.jsp
@@ -0,0 +1,20 @@
+<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <!-- Refresh every 5 seconds -->
+ <meta http-equiv="refresh" content="5;url=<s:url includeParams="all"/>"/>
+ <title>Execute And Wait Test</title>
+</head>
+
+<body>
+<p>
+ Waiting...
+</p>
+<p>
+ Refresh URL (every 3 seconds): <!--s:url includeParams="all"/-->
+</p>
+</body>
+</html>
diff --git a/helloworld/src/main/webapp/index.jsp b/helloworld/src/main/webapp/index.jsp
index de471ed..54cb33d 100755
--- a/helloworld/src/main/webapp/index.jsp
+++ b/helloworld/src/main/webapp/index.jsp
@@ -2,12 +2,16 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
- <head>
+<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Basic Struts 2 Application - Welcome</title>
- </head>
- <body>
- <h1>Welcome To Struts 2!</h1>
- <p><a href="<s:url action='hello'/>">Hello World</a></p>
- </body>
+</head>
+<body>
+<h1>Welcome To Struts 2!</h1>
+<p><a href="<s:url action='hello'/>">Hello World</a></p>
+
+<h1>Execute and Wait Test</h1>
+<a><a href="<s:url action='ExecAndWaitTest'/>">Test Execute And Wait</a></p>
+
+</body>
</html>
diff --git a/pom.xml b/pom.xml
index 4bf20f1..3ace9ed 100644
--- a/pom.xml
+++ b/pom.xml
@@ -41,7 +41,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <struts2.version>6.0.3</struts2.version>
+ <struts2.version>6.1.1</struts2.version>
<log4j2.version>2.19.0</log4j2.version>
<jetty-plugin.version>9.4.46.v20220331</jetty-plugin.version>
<maven.javadoc.skip>true</maven.javadoc.skip>
@@ -118,21 +118,15 @@
<module>jasperreports</module>
</modules>
- <dependencies>
-
- <dependency>
- <groupId>org.apache.struts</groupId>
- <artifactId>struts2-core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-core</artifactId>
- </dependency>
-
- </dependencies>
-
<dependencyManagement>
<dependencies>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>3.1.0</version>
+ <scope>provided</scope>
+ </dependency>
+
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
@@ -159,6 +153,21 @@
</dependencies>
</dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.struts</groupId>
+ <artifactId>struts2-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ </dependency>
+ </dependencies>
+
<build>
<plugins>
diff --git a/rest-angular/src/test/java/org/apache/examples/struts/actions/IndexControllerTest.java b/rest-angular/src/test/java/org/apache/examples/struts/actions/IndexControllerTest.java
index 951b840..eab7c71 100644
--- a/rest-angular/src/test/java/org/apache/examples/struts/actions/IndexControllerTest.java
+++ b/rest-angular/src/test/java/org/apache/examples/struts/actions/IndexControllerTest.java
@@ -1,16 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.examples.struts.actions;
import com.opensymphony.xwork2.ActionProxy;
-import org.apache.struts2.StrutsRestTestCase;
+import org.apache.struts2.junit.StrutsRestTestCase;
import org.junit.Before;
import org.junit.Test;
-import static org.hamcrest.Matchers.*;
-import static org.junit.Assert.assertThat;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
public class IndexControllerTest extends StrutsRestTestCase<IndexController> {
-
@Before
public void init() throws Exception {
super.setUp();
@@ -27,4 +46,4 @@ public class IndexControllerTest extends StrutsRestTestCase<IndexController> {
assertThat(indexController.isUseMinifiedResources(), is(false));
}
-}
\ No newline at end of file
+}
diff --git a/rest-angular/src/test/java/org/apache/examples/struts/actions/data/OrderControllerTest.java b/rest-angular/src/test/java/org/apache/examples/struts/actions/data/OrderControllerTest.java
index 76eec4d..44685b3 100644
--- a/rest-angular/src/test/java/org/apache/examples/struts/actions/data/OrderControllerTest.java
+++ b/rest-angular/src/test/java/org/apache/examples/struts/actions/data/OrderControllerTest.java
@@ -1,23 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.examples.struts.actions.data;
import com.jayway.jsonpath.JsonPath;
import com.opensymphony.xwork2.ActionProxy;
import org.apache.examples.struts.models.Order;
import org.apache.struts2.ServletActionContext;
-import org.apache.struts2.StrutsRestTestCase;
+import org.apache.struts2.junit.StrutsRestTestCase;
import org.junit.Before;
import org.junit.Test;
import org.springframework.mock.web.MockHttpServletResponse;
import java.util.List;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
-import static org.junit.Assert.assertThat;
public class OrderControllerTest extends StrutsRestTestCase<OrderController> {
@@ -36,7 +54,9 @@ public class OrderControllerTest extends StrutsRestTestCase<OrderController> {
assertThat(model, notNullValue());
assertThat(model, is(instanceOf(List.class)));
+ @SuppressWarnings("unchecked")
List<Order> orders = (List<Order>) model;
+
assertThat("List contains 3 orders", orders.size(), is(greaterThanOrEqualTo(3)));
}
@@ -112,4 +132,4 @@ public class OrderControllerTest extends StrutsRestTestCase<OrderController> {
assertThat(order.getClientName(), is(equalTo("Grace Hopper")));
assertThat(order.getAmount(), is(equalTo(85)));
}
-}
\ No newline at end of file
+}
diff --git a/text-provider/pom.xml b/text-provider/pom.xml
index 1907b6e..5603bdd 100644
--- a/text-provider/pom.xml
+++ b/text-provider/pom.xml
@@ -23,10 +23,6 @@
<artifactId>struts2-convention-plugin</artifactId>
<version>${struts2.version}</version>
</dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-core</artifactId>
- </dependency>
</dependencies>
<build>
diff --git a/unit-testing/src/test/java/org/apache/struts/register/action/RegisterTest.java b/unit-testing/src/test/java/org/apache/struts/register/action/RegisterTest.java
index ae94936..d3ce410 100644
--- a/unit-testing/src/test/java/org/apache/struts/register/action/RegisterTest.java
+++ b/unit-testing/src/test/java/org/apache/struts/register/action/RegisterTest.java
@@ -1,80 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.struts.register.action;
-
import com.opensymphony.xwork2.ActionProxy;
import com.opensymphony.xwork2.ActionSupport;
-import org.apache.struts2.StrutsTestCase;
+import org.apache.struts2.junit.StrutsTestCase;
import org.junit.Test;
public class RegisterTest extends StrutsTestCase {
- @Test
- public void testExecuteValidationPasses() throws Exception {
-
- request.setParameter("personBean.firstName", "Bruce");
-
- request.setParameter("personBean.lastName", "Phillips");
-
- request.setParameter("personBean.email", "bphillips@ku.edu");
-
- request.setParameter("personBean.age", "19");
-
- ActionProxy actionProxy = getActionProxy("/register.action") ;
-
- Register action = (Register) actionProxy.getAction();
-
- assertNotNull("The action is null but should not be.", action);
+ @Test
+ public void testExecuteValidationPasses() throws Exception {
+ request.setParameter("personBean.firstName", "Bruce");
+ request.setParameter("personBean.lastName", "Phillips");
+ request.setParameter("personBean.email", "bphillips@ku.edu");
+ request.setParameter("personBean.age", "19");
+
+ ActionProxy actionProxy = getActionProxy("/register.action");
+
+ Register action = (Register) actionProxy.getAction();
+ assertNotNull("The action is null but should not be.", action);
+
+ String result = actionProxy.execute();
+ assertEquals("The execute method did not return " + ActionSupport.SUCCESS + " but should have.", ActionSupport.SUCCESS, result);
+ }
+
+ @Test
+ public void testExecuteValidationFailsMissingFirstName() throws Exception {
+ request.setParameter("personBean.firstName", "Bruce");
+ request.setParameter("personBean.lastName", "Phillips");
+ request.setParameter("personBean.email", "bphillips@ku.edu");
+ request.setParameter("personBean.age", "17");
+
+ ActionProxy actionProxy = getActionProxy("/register.action");
- String result = actionProxy.execute();
-
- assertEquals("The execute method did not return " + ActionSupport.SUCCESS + " but should have.", ActionSupport.SUCCESS, result);
+ Register action = (Register) actionProxy.getAction();
+ assertNotNull("The action is null but should not be.", action);
- }
-
- @Test
- public void testExecuteValidationFailsMissingFirstName() throws Exception {
-
- request.setParameter("personBean.firstName", "Bruce");
-
- request.setParameter("personBean.lastName", "Phillips");
-
- request.setParameter("personBean.email", "bphillips@ku.edu");
-
- request.setParameter("personBean.age", "17");
-
- ActionProxy actionProxy = getActionProxy("/register.action") ;
-
- Register action = (Register) actionProxy.getAction();
-
- assertNotNull("The action is null but should not be.", action);
+ String result = actionProxy.execute();
+ assertEquals("The execute method did not return " + ActionSupport.INPUT + " but should have.", ActionSupport.INPUT, result);
+ }
- String result = actionProxy.execute();
-
- assertEquals("The execute method did not return " + ActionSupport.INPUT + " but should have.", ActionSupport.INPUT, result);
+ @Test
+ public void testExecuteValidationFailsAgeToYoung() throws Exception {
+ request.setParameter("personBean.lastName", "Phillips");
+ request.setParameter("personBean.email", "bphillips@ku.edu");
+ request.setParameter("personBean.age", "19");
- }
-
-
- @Test
- public void testExecuteValidationFailsAgeToYoung() throws Exception {
-
-
- request.setParameter("personBean.lastName", "Phillips");
-
- request.setParameter("personBean.email", "bphillips@ku.edu");
-
- request.setParameter("personBean.age", "19");
-
- ActionProxy actionProxy = getActionProxy("/register.action") ;
-
- Register action = (Register) actionProxy.getAction();
-
- assertNotNull("The action is null but should not be.", action);
+ ActionProxy actionProxy = getActionProxy("/register.action");
- String result = actionProxy.execute();
-
- assertEquals("The execute method did not return " + ActionSupport.INPUT + " but should have.", ActionSupport.INPUT, result);
+ Register action = (Register) actionProxy.getAction();
+ assertNotNull("The action is null but should not be.", action);
- }
+ String result = actionProxy.execute();
+ assertEquals("The execute method did not return " + ActionSupport.INPUT + " but should have.", ActionSupport.INPUT, result);
+ }
}