diff --git a/apps/pom.xml b/apps/pom.xml index f87e633dd..32504db5d 100644 --- a/apps/pom.xml +++ b/apps/pom.xml @@ -169,22 +169,6 @@ - - org.codehaus.cargo - cargo-maven2-plugin - 0.3.1 - - - tomcat5x - ${cargo.tomcat5x.home} - ${project.build.directory}/tomcat5x.log - ${project.build.directory}/tomcat5x.out - - - ${project.build.directory}/tomcat5x - - - maven-antrun-plugin @@ -247,4 +231,4 @@ - \ No newline at end of file + diff --git a/apps/rest-showcase/pom.xml b/apps/rest-showcase/pom.xml index 8f2df3bbc..bd8ddd4ac 100644 --- a/apps/rest-showcase/pom.xml +++ b/apps/rest-showcase/pom.xml @@ -54,6 +54,33 @@ test + + net.sourceforge.jwebunit + jwebunit-core + 1.4.1 + test + + + commons-httpclient + commons-httpclient + 3.1 + test + + + + + net.sourceforge.jwebunit + jwebunit-htmlunit-plugin + 1.4.1 + test + + + xom + xom + + + + @@ -75,6 +102,39 @@ 10 + + org.twdata.maven + maven-itblast-plugin + 0.3 + + + integration-test + + execute + + + tomcat5x,jetty6x,jboss42x,resin3x + + + + + + maven-surefire-plugin + + + it/** + **/*$* + + + + + + + twdata-m2-repository + twdata.org Maven Repository + http://twdata-m2-repository.googlecode.com/svn/ + + diff --git a/apps/rest-showcase/src/test/java/it/org/apache/struts2/rest/example/GetOrdersTest.java b/apps/rest-showcase/src/test/java/it/org/apache/struts2/rest/example/GetOrdersTest.java new file mode 100644 index 000000000..60dcd48e4 --- /dev/null +++ b/apps/rest-showcase/src/test/java/it/org/apache/struts2/rest/example/GetOrdersTest.java @@ -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("Bob"); + } + + public void testGetOrdersInJson() { + beginAt("/orders/3.json"); + assertTextPresent("\"clientName\":\"Bob\""); + } +} \ No newline at end of file diff --git a/apps/rest-showcase/src/test/java/it/org/apache/struts2/rest/example/ListOrdersTest.java b/apps/rest-showcase/src/test/java/it/org/apache/struts2/rest/example/ListOrdersTest.java new file mode 100644 index 000000000..d4e4f6678 --- /dev/null +++ b/apps/rest-showcase/src/test/java/it/org/apache/struts2/rest/example/ListOrdersTest.java @@ -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("Bob"); + assertTextPresent("Sarah"); + assertTextPresent("Jim"); + } + + public void testListOrdersInJson() { + beginAt("/orders.json"); + assertTextPresent("\"clientName\":\"Bob\""); + assertTextPresent("\"clientName\":\"Sarah\""); + assertTextPresent("\"clientName\":\"Jim\""); + } +} diff --git a/apps/rest-showcase/src/test/java/it/org/apache/struts2/rest/example/PostOrderTest.java b/apps/rest-showcase/src/test/java/it/org/apache/struts2/rest/example/PostOrderTest.java new file mode 100644 index 000000000..b0b770297 --- /dev/null +++ b/apps/rest-showcase/src/test/java/it/org/apache/struts2/rest/example/PostOrderTest.java @@ -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("\n" + + "Test3\n" + + "3342\n" + + "")); + 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("\n" + + "3342\n" + + "")); + client.executeMethod(method); + assertEquals(400, method.getStatusCode()); + String response = method.getResponseBodyAsString(); + assertTrue(response.contains("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