mirror of
https://github.com/apache/struts.git
synced 2026-08-06 23:27:07 +00:00
Adding a few functional tests and test runs against multiple servers using my new maven-itblast-plugin
WW-2471 git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@680707 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
+1
-17
@@ -169,22 +169,6 @@
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.cargo</groupId>
|
||||
<artifactId>cargo-maven2-plugin</artifactId>
|
||||
<version>0.3.1</version>
|
||||
<configuration>
|
||||
<container>
|
||||
<containerId>tomcat5x</containerId>
|
||||
<home>${cargo.tomcat5x.home}</home>
|
||||
<log>${project.build.directory}/tomcat5x.log</log>
|
||||
<output>${project.build.directory}/tomcat5x.out</output>
|
||||
</container>
|
||||
<configuration>
|
||||
<home>${project.build.directory}/tomcat5x</home>
|
||||
</configuration>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- Include source code under WEB-INF/src/java -->
|
||||
<plugin>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
@@ -247,4 +231,4 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
|
||||
@@ -54,6 +54,33 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.jwebunit</groupId>
|
||||
<artifactId>jwebunit-core</artifactId>
|
||||
<version>1.4.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-httpclient</groupId>
|
||||
<artifactId>commons-httpclient</artifactId>
|
||||
<version>3.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.jwebunit</groupId>
|
||||
<artifactId>jwebunit-htmlunit-plugin</artifactId>
|
||||
<version>1.4.1</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>xom</groupId>
|
||||
<artifactId>xom</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
@@ -75,6 +102,39 @@
|
||||
<scanIntervalSeconds>10</scanIntervalSeconds>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.twdata.maven</groupId>
|
||||
<artifactId>maven-itblast-plugin</artifactId>
|
||||
<version>0.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>execute</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<containers>tomcat5x,jetty6x,jboss42x,resin3x</containers>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>it/**</exclude>
|
||||
<exclude>**/*$*</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>twdata-m2-repository</id>
|
||||
<name>twdata.org Maven Repository</name>
|
||||
<url>http://twdata-m2-repository.googlecode.com/svn/</url>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
</project>
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package it.org.apache.struts2.rest.example;
|
||||
|
||||
import net.sourceforge.jwebunit.junit.WebTestCase;
|
||||
|
||||
public class GetOrdersTest extends WebTestCase {
|
||||
|
||||
public void setUp() throws Exception {
|
||||
getTestContext().setBaseUrl("http://localhost:8080/struts2-rest-showcase");
|
||||
}
|
||||
|
||||
|
||||
public void testGetOrders() {
|
||||
beginAt("/orders/3");
|
||||
assertTextPresent("Bob");
|
||||
assertTextNotPresent("Sarah");
|
||||
}
|
||||
|
||||
public void testGetOrdersInHtml() {
|
||||
beginAt("/orders/3.xhtml");
|
||||
assertTextPresent("Bob");
|
||||
}
|
||||
|
||||
public void testGetOrdersInXml() {
|
||||
beginAt("/orders/3.xml");
|
||||
assertTextPresent("<clientName>Bob");
|
||||
}
|
||||
|
||||
public void testGetOrdersInJson() {
|
||||
beginAt("/orders/3.json");
|
||||
assertTextPresent("\"clientName\":\"Bob\"");
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package it.org.apache.struts2.rest.example;
|
||||
|
||||
import net.sourceforge.jwebunit.junit.WebTestCase;
|
||||
|
||||
public class ListOrdersTest extends WebTestCase {
|
||||
|
||||
public void setUp() throws Exception {
|
||||
getTestContext().setBaseUrl("http://localhost:8080/struts2-rest-showcase");
|
||||
}
|
||||
|
||||
|
||||
public void testListOrders() {
|
||||
beginAt("/orders");
|
||||
assertTextPresent("Bob");
|
||||
assertTextPresent("Sarah");
|
||||
assertTextPresent("Jim");
|
||||
}
|
||||
|
||||
public void testListOrdersInHtml() {
|
||||
beginAt("/orders.xhtml");
|
||||
assertTextPresent("Bob");
|
||||
assertTextPresent("Sarah");
|
||||
assertTextPresent("Jim");
|
||||
}
|
||||
|
||||
public void testListOrdersInXml() {
|
||||
beginAt("/orders.xml");
|
||||
assertTextPresent("<clientName>Bob");
|
||||
assertTextPresent("<clientName>Sarah");
|
||||
assertTextPresent("<clientName>Jim");
|
||||
}
|
||||
|
||||
public void testListOrdersInJson() {
|
||||
beginAt("/orders.json");
|
||||
assertTextPresent("\"clientName\":\"Bob\"");
|
||||
assertTextPresent("\"clientName\":\"Sarah\"");
|
||||
assertTextPresent("\"clientName\":\"Jim\"");
|
||||
}
|
||||
}
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
package it.org.apache.struts2.rest.example;
|
||||
|
||||
import net.sourceforge.jwebunit.junit.WebTestCase;
|
||||
import org.apache.commons.httpclient.HttpClient;
|
||||
import org.apache.commons.httpclient.methods.PostMethod;
|
||||
import org.apache.commons.httpclient.methods.StringRequestEntity;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
|
||||
|
||||
public class PostOrderTest extends WebTestCase {
|
||||
|
||||
public void setUp() throws Exception {
|
||||
getTestContext().setBaseUrl("http://localhost:8080/struts2-rest-showcase");
|
||||
}
|
||||
|
||||
|
||||
public void testPostOrder() {
|
||||
beginAt("/orders/new");
|
||||
setWorkingForm(0);
|
||||
setTextField("clientName", "Test1");
|
||||
setTextField("amount", "321");
|
||||
submit();
|
||||
assertTextPresent("Test1");
|
||||
assertLinkNotPresentWithText("Back to Orders");
|
||||
}
|
||||
|
||||
public void testPostOrderWithErrors() {
|
||||
beginAt("/orders/new");
|
||||
setWorkingForm(0);
|
||||
setTextField("amount", "321");
|
||||
try {
|
||||
submit();
|
||||
} catch (FailingHttpStatusCodeException ex) {
|
||||
// ignore;
|
||||
}
|
||||
assertTextPresent("client name is empty");
|
||||
assertTextFieldEquals("amount", "321");
|
||||
}
|
||||
|
||||
public void testPostOrderInHtml() {
|
||||
beginAt("/orders/new.xhtml");
|
||||
setWorkingForm(0);
|
||||
setTextField("clientName", "Test2");
|
||||
setTextField("amount", "321");
|
||||
try {
|
||||
submit();
|
||||
} catch (FailingHttpStatusCodeException ex) {
|
||||
// ignore;
|
||||
}
|
||||
assertTextPresent("Test2");
|
||||
assertLinkNotPresentWithText("Back to Orders");
|
||||
}
|
||||
|
||||
public void testPostOrderInXml() throws IOException {
|
||||
HttpClient client = new HttpClient();
|
||||
PostMethod method = null;
|
||||
try {
|
||||
method = new PostMethod("http://localhost:8080/struts2-rest-showcase/orders.xml");
|
||||
method.setRequestEntity(new StringRequestEntity("<org.apache.struts2.rest.example.Order>\n" +
|
||||
"<clientName>Test3</clientName>\n" +
|
||||
"<amount>3342</amount>\n" +
|
||||
"</org.apache.struts2.rest.example.Order>"));
|
||||
client.executeMethod(method);
|
||||
assertEquals(201, method.getStatusCode());
|
||||
assertTrue(method.getResponseHeader("Location").getValue().startsWith("http://localhost:8080/struts2-rest-showcase/orders/"));
|
||||
} finally {
|
||||
method.releaseConnection();
|
||||
}
|
||||
}
|
||||
|
||||
public void testPostOrderInXmlWithBadData() throws IOException {
|
||||
HttpClient client = new HttpClient();
|
||||
PostMethod method = null;
|
||||
try {
|
||||
method = new PostMethod("http://localhost:8080/struts2-rest-showcase/orders.xml");
|
||||
method.setRequestEntity(new StringRequestEntity("<org.apache.struts2.rest.example.Order>\n" +
|
||||
"<amount>3342</amount>\n" +
|
||||
"</org.apache.struts2.rest.example.Order>"));
|
||||
client.executeMethod(method);
|
||||
assertEquals(400, method.getStatusCode());
|
||||
String response = method.getResponseBodyAsString();
|
||||
assertTrue(response.contains("<string>The client name is empty"));
|
||||
assertNull(method.getResponseHeader("Location"));
|
||||
} finally {
|
||||
method.releaseConnection();
|
||||
}
|
||||
}
|
||||
|
||||
public void testPostOrderInJson() throws IOException {
|
||||
HttpClient client = new HttpClient();
|
||||
PostMethod method = null;
|
||||
try {
|
||||
method = new PostMethod("http://localhost:8080/struts2-rest-showcase/orders.json");
|
||||
method.setRequestEntity(new StringRequestEntity("{\"amount\":33,\"clientName\":\"Test4\"}"));
|
||||
client.executeMethod(method);
|
||||
assertEquals(201, method.getStatusCode());
|
||||
assertTrue(method.getResponseHeader("Location").getValue().startsWith("http://localhost:8080/struts2-rest-showcase/orders/"));
|
||||
} finally {
|
||||
method.releaseConnection();
|
||||
}
|
||||
}
|
||||
|
||||
public void testPostOrderInJsonWithBadData() throws IOException {
|
||||
HttpClient client = new HttpClient();
|
||||
PostMethod method = null;
|
||||
try {
|
||||
method = new PostMethod("http://localhost:8080/struts2-rest-showcase/orders.json");
|
||||
method.setRequestEntity(new StringRequestEntity("{\"amount\":33}"));
|
||||
client.executeMethod(method);
|
||||
String response = method.getResponseBodyAsString();
|
||||
assertEquals(400, method.getStatusCode());
|
||||
|
||||
assertEquals("{\"actionErrors\":[],\"fieldErrors\":{\"clientName\":[\"The client name is empty\"]}}", response);
|
||||
assertNull(method.getResponseHeader("Location"));
|
||||
} finally {
|
||||
method.releaseConnection();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user