Skip to content

Commit 491d36e

Browse files
ravi-devgobletmaibin
authored andcommitted
BAEL-524:after review comments (eugenp#1154)
* BAEL-524 * BAEL-524 * BAEL-524 * BAEL-524 * BAEL-524 resolving build failure * BAEL-524 do not exclude test class
1 parent 5ef3b14 commit 491d36e

5 files changed

Lines changed: 103 additions & 62 deletions

File tree

‎struts2/pom.xml‎

Lines changed: 56 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,59 @@
11
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3-
<modelVersion>4.0.0</modelVersion>
4-
<groupId>com.baeldung</groupId>
5-
<artifactId>struts2</artifactId>
6-
<version>0.0.1-SNAPSHOT</version>
7-
<packaging>war</packaging>
8-
<name>struts2</name>
9-
10-
<build>
11-
<sourceDirectory>src</sourceDirectory>
12-
<resources>
13-
<resource>
14-
<directory>src</directory>
15-
<excludes>
16-
<exclude>**/*.java</exclude>
17-
</excludes>
18-
</resource>
19-
</resources>
20-
<plugins>
21-
<plugin>
22-
<artifactId>maven-compiler-plugin</artifactId>
23-
<version>3.5.1</version>
24-
<configuration>
25-
<source>1.8</source>
26-
<target>1.8</target>
27-
</configuration>
28-
</plugin>
29-
<plugin>
30-
<artifactId>maven-war-plugin</artifactId>
31-
<version>3.0.0</version>
32-
<configuration>
33-
<warSourceDirectory>WebContent</warSourceDirectory>
34-
</configuration>
35-
</plugin>
36-
</plugins>
37-
</build>
38-
39-
<dependencies>
40-
<!-- https://mvnrepository.com/artifact/org.apache.struts/struts2-core -->
41-
<dependency>
42-
<groupId>org.apache.struts</groupId>
43-
<artifactId>struts2-core</artifactId>
44-
<version>2.5.5</version>
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.baeldung</groupId>
5+
<artifactId>MyStrutsApp</artifactId>
6+
<version>0.0.1-SNAPSHOT</version>
7+
<packaging>war</packaging>
8+
<name>MyStrutsApp</name>
9+
<build>
10+
<sourceDirectory>src</sourceDirectory>
11+
<resources>
12+
<resource>
13+
<directory>src</directory>
14+
</resource>
15+
</resources>
16+
<plugins>
17+
<plugin>
18+
<artifactId>maven-compiler-plugin</artifactId>
19+
<version>3.5.1</version>
20+
<configuration>
21+
<source>1.8</source>
22+
<target>1.8</target>
23+
</configuration>
24+
</plugin>
25+
<plugin>
26+
<artifactId>maven-war-plugin</artifactId>
27+
<version>3.0.0</version>
28+
<configuration>
29+
<warSourceDirectory>WebContent</warSourceDirectory>
30+
</configuration>
31+
</plugin>
32+
</plugins>
33+
</build>
34+
<dependencies>
35+
<!-- http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22struts2-core%22 -->
36+
<dependency>
37+
<groupId>org.apache.struts</groupId>
38+
<artifactId>struts2-core</artifactId>
39+
<version>2.5.5</version>
40+
</dependency>
41+
<!-- http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22struts2-core%22 -->
42+
<dependency>
43+
<groupId>org.apache.struts</groupId>
44+
<artifactId>struts2-junit-plugin</artifactId>
45+
<version>2.5.5</version>
46+
</dependency>
47+
<!-- http://search.maven.org/#search%7Cga%7C1%7Cstruts2-convention-plugin -->
48+
<dependency>
49+
<groupId>org.apache.struts</groupId>
50+
<artifactId>struts2-convention-plugin</artifactId>
51+
<version>2.5.8</version>
52+
</dependency>
53+
<dependency>
54+
<groupId>javax.servlet</groupId>
55+
<artifactId>javax.servlet-api</artifactId>
56+
<version>3.0.1</version>
4557
</dependency>
46-
</dependencies>
47-
58+
</dependencies>
4859
</project>

‎struts2/src/com/baeldung/struts/CarAction.java‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
package com.baeldung.struts;
22

3-
public class CarAction {
4-
3+
import org.apache.struts2.convention.annotation.Action;
4+
import org.apache.struts2.convention.annotation.Namespace;
5+
import org.apache.struts2.convention.annotation.Result;
6+
import org.apache.struts2.convention.annotation.ResultPath;
7+
8+
@Namespace("/tutorial")
9+
@Action("/car")
10+
@Result(name = "success", location = "/result.jsp")
11+
public class CarAction {
512
private String carName;
613
private String carMessage;
714
private CarMessageService carMessageService = new CarMessageService();

‎struts2/src/com/baeldung/struts/CarMessageService.java‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ public class CarMessageService {
44

55
public String getMessage(String carName) {
66
System.out.println("inside getMessage()" + carName);
7-
if (carName.equalsIgnoreCase("ferrari"))
7+
if (carName.equalsIgnoreCase("ferrari")){
88
return "Ferrari Fan!";
9-
else if (carName.equalsIgnoreCase("bmw"))
9+
}
10+
else if (carName.equalsIgnoreCase("bmw")){
1011
return "BMW Fan!";
11-
else
12+
}
13+
else{
1214
return "please choose ferrari Or bmw";
15+
}
1316
}
1417

1518
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.baeldung.struts.test;
2+
import org.apache.struts2.StrutsTestCase;
3+
import org.junit.Test;
4+
5+
6+
import com.baeldung.struts.CarAction;
7+
import com.opensymphony.xwork2.ActionProxy;
8+
9+
public class TestCarAction extends StrutsTestCase {
10+
11+
@Test
12+
public void test_givenCarOptions_WhenferrariSelected_ThenShowMessage() throws Exception {
13+
request.setParameter("carName", "ferrari");
14+
ActionProxy proxy = getActionProxy("/tutorial/car.action");
15+
CarAction carAction = (CarAction) proxy.getAction();
16+
String result = proxy.execute();
17+
assertEquals(result,"success");
18+
assertEquals(carAction.getCarMessage(), "Ferrari Fan!");
19+
}
20+
21+
22+
public void test_givenCarOptions_WhenbmwSelected_ThenShowMessage() throws Exception {
23+
request.setParameter("carName", "bmw");
24+
ActionProxy proxy = getActionProxy("/tutorial/car.action");
25+
CarAction carAction = (CarAction) proxy.getAction();
26+
String result = proxy.execute();
27+
assertEquals(result,"success");
28+
assertEquals(carAction.getCarMessage(), "BMW Fan!");
29+
}
30+
31+
32+
}

‎struts2/src/struts.xml‎

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)