diff --git a/struts2/pom.xml b/struts2/pom.xml
index 9b9adeaf46..0ae054ef38 100644
--- a/struts2/pom.xml
+++ b/struts2/pom.xml
@@ -1,48 +1,59 @@
- 4.0.0
- com.baeldung
- struts2
- 0.0.1-SNAPSHOT
- war
- struts2
-
-
- src
-
-
- src
-
- **/*.java
-
-
-
-
-
- maven-compiler-plugin
- 3.5.1
-
- 1.8
- 1.8
-
-
-
- maven-war-plugin
- 3.0.0
-
- WebContent
-
-
-
-
-
-
-
-
- org.apache.struts
- struts2-core
- 2.5.5
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ 4.0.0
+ com.baeldung
+ MyStrutsApp
+ 0.0.1-SNAPSHOT
+ war
+ MyStrutsApp
+
+ src
+
+
+ src
+
+
+
+
+ maven-compiler-plugin
+ 3.5.1
+
+ 1.8
+ 1.8
+
+
+
+ maven-war-plugin
+ 3.0.0
+
+ WebContent
+
+
+
+
+
+
+
+ org.apache.struts
+ struts2-core
+ 2.5.5
+
+
+
+ org.apache.struts
+ struts2-junit-plugin
+ 2.5.5
+
+
+
+ org.apache.struts
+ struts2-convention-plugin
+ 2.5.8
+
+
+ javax.servlet
+ javax.servlet-api
+ 3.0.1
-
-
+
\ No newline at end of file
diff --git a/struts2/src/com/baeldung/struts/CarAction.java b/struts2/src/com/baeldung/struts/CarAction.java
index a96aa440b6..0b9266339c 100644
--- a/struts2/src/com/baeldung/struts/CarAction.java
+++ b/struts2/src/com/baeldung/struts/CarAction.java
@@ -1,7 +1,14 @@
package com.baeldung.struts;
-public class CarAction {
+import org.apache.struts2.convention.annotation.Action;
+import org.apache.struts2.convention.annotation.Namespace;
+import org.apache.struts2.convention.annotation.Result;
+import org.apache.struts2.convention.annotation.ResultPath;
+@Namespace("/tutorial")
+@Action("/car")
+@Result(name = "success", location = "/result.jsp")
+public class CarAction {
private String carName;
private String carMessage;
private CarMessageService carMessageService = new CarMessageService();
diff --git a/struts2/src/com/baeldung/struts/CarMessageService.java b/struts2/src/com/baeldung/struts/CarMessageService.java
index fef9c1719d..34d3ca3d76 100644
--- a/struts2/src/com/baeldung/struts/CarMessageService.java
+++ b/struts2/src/com/baeldung/struts/CarMessageService.java
@@ -4,12 +4,15 @@ public class CarMessageService {
public String getMessage(String carName) {
System.out.println("inside getMessage()" + carName);
- if (carName.equalsIgnoreCase("ferrari"))
+ if (carName.equalsIgnoreCase("ferrari")){
return "Ferrari Fan!";
- else if (carName.equalsIgnoreCase("bmw"))
+ }
+ else if (carName.equalsIgnoreCase("bmw")){
return "BMW Fan!";
- else
+ }
+ else{
return "please choose ferrari Or bmw";
+ }
}
}
diff --git a/struts2/src/com/baeldung/struts/test/TestCarAction.java b/struts2/src/com/baeldung/struts/test/TestCarAction.java
new file mode 100644
index 0000000000..ec21bd689a
--- /dev/null
+++ b/struts2/src/com/baeldung/struts/test/TestCarAction.java
@@ -0,0 +1,32 @@
+package com.baeldung.struts.test;
+import org.apache.struts2.StrutsTestCase;
+import org.junit.Test;
+
+
+import com.baeldung.struts.CarAction;
+import com.opensymphony.xwork2.ActionProxy;
+
+public class TestCarAction extends StrutsTestCase {
+
+ @Test
+ public void test_givenCarOptions_WhenferrariSelected_ThenShowMessage() throws Exception {
+ request.setParameter("carName", "ferrari");
+ ActionProxy proxy = getActionProxy("/tutorial/car.action");
+ CarAction carAction = (CarAction) proxy.getAction();
+ String result = proxy.execute();
+ assertEquals(result,"success");
+ assertEquals(carAction.getCarMessage(), "Ferrari Fan!");
+ }
+
+
+ public void test_givenCarOptions_WhenbmwSelected_ThenShowMessage() throws Exception {
+ request.setParameter("carName", "bmw");
+ ActionProxy proxy = getActionProxy("/tutorial/car.action");
+ CarAction carAction = (CarAction) proxy.getAction();
+ String result = proxy.execute();
+ assertEquals(result,"success");
+ assertEquals(carAction.getCarMessage(), "BMW Fan!");
+ }
+
+
+}
diff --git a/struts2/src/struts.xml b/struts2/src/struts.xml
deleted file mode 100644
index 1c117ac900..0000000000
--- a/struts2/src/struts.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
- /result.jsp
-
-
-
\ No newline at end of file