Author: mrdon Date: Tue Jul 29 07:17:17 2008 New Revision: 680707 URL: http://svn.apache.org/viewvc?rev=680707&view=rev Log: Adding a few functional tests and test runs against multiple servers using my new maven-itblast-plugin WW-2471
Added: struts/struts2/trunk/apps/rest-showcase/src/test/ struts/struts2/trunk/apps/rest-showcase/src/test/java/ struts/struts2/trunk/apps/rest-showcase/src/test/java/it/ struts/struts2/trunk/apps/rest-showcase/src/test/java/it/org/ struts/struts2/trunk/apps/rest-showcase/src/test/java/it/org/apache/ struts/struts2/trunk/apps/rest-showcase/src/test/java/it/org/apache/struts2/ struts/struts2/trunk/apps/rest-showcase/src/test/java/it/org/apache/struts2/rest/ struts/struts2/trunk/apps/rest-showcase/src/test/java/it/org/apache/struts2/rest/example/ struts/struts2/trunk/apps/rest-showcase/src/test/java/it/org/apache/struts2/rest/example/GetOrdersTest.java struts/struts2/trunk/apps/rest-showcase/src/test/java/it/org/apache/struts2/rest/example/ListOrdersTest.java struts/struts2/trunk/apps/rest-showcase/src/test/java/it/org/apache/struts2/rest/example/PostOrderTest.java Modified: struts/struts2/trunk/apps/pom.xml struts/struts2/trunk/apps/rest-showcase/pom.xml Modified: struts/struts2/trunk/apps/pom.xml URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/pom.xml?rev=680707&r1=680706&r2=680707&view=diff ============================================================================== --- struts/struts2/trunk/apps/pom.xml (original) +++ struts/struts2/trunk/apps/pom.xml Tue Jul 29 07:17:17 2008 @@ -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> \ No newline at end of file +</project> Modified: struts/struts2/trunk/apps/rest-showcase/pom.xml URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/rest-showcase/pom.xml?rev=680707&r1=680706&r2=680707&view=diff ============================================================================== --- struts/struts2/trunk/apps/rest-showcase/pom.xml (original) +++ struts/struts2/trunk/apps/rest-showcase/pom.xml Tue Jul 29 07:17:17 2008 @@ -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> Added: struts/struts2/trunk/apps/rest-showcase/src/test/java/it/org/apache/struts2/rest/example/GetOrdersTest.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/rest-showcase/src/test/java/it/org/apache/struts2/rest/example/GetOrdersTest.java?rev=680707&view=auto ============================================================================== --- struts/struts2/trunk/apps/rest-showcase/src/test/java/it/org/apache/struts2/rest/example/GetOrdersTest.java (added) +++ struts/struts2/trunk/apps/rest-showcase/src/test/java/it/org/apache/struts2/rest/example/GetOrdersTest.java Tue Jul 29 07:17:17 2008 @@ -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\""); + } +} \ No newline at end of file Added: struts/struts2/trunk/apps/rest-showcase/src/test/java/it/org/apache/struts2/rest/example/ListOrdersTest.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/rest-showcase/src/test/java/it/org/apache/struts2/rest/example/ListOrdersTest.java?rev=680707&view=auto ============================================================================== --- struts/struts2/trunk/apps/rest-showcase/src/test/java/it/org/apache/struts2/rest/example/ListOrdersTest.java (added) +++ struts/struts2/trunk/apps/rest-showcase/src/test/java/it/org/apache/struts2/rest/example/ListOrdersTest.java Tue Jul 29 07:17:17 2008 @@ -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\""); + } +} Added: struts/struts2/trunk/apps/rest-showcase/src/test/java/it/org/apache/struts2/rest/example/PostOrderTest.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/rest-showcase/src/test/java/it/org/apache/struts2/rest/example/PostOrderTest.java?rev=680707&view=auto ============================================================================== --- struts/struts2/trunk/apps/rest-showcase/src/test/java/it/org/apache/struts2/rest/example/PostOrderTest.java (added) +++ struts/struts2/trunk/apps/rest-showcase/src/test/java/it/org/apache/struts2/rest/example/PostOrderTest.java Tue Jul 29 07:17:17 2008 @@ -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(); + } + } +} \ No newline at end of file