From b7473f6b1ddd109393a4d65c38efd31375f30371 Mon Sep 17 00:00:00 2001 From: Jozef Hartinger Date: Mon, 7 Mar 2011 16:13:06 +0100 Subject: [PATCH] SEAMREST-29 --- examples/tasks/pom.xml | 85 +++++++++++++++---- examples/tasks/readme.txt | 11 ++- .../resource/CategoryCollectionResource.java | 19 +++++ .../resource/TaskCollectionResource.java | 15 ++++ .../main/resources/META-INF/seam-beans.xml | 2 +- .../velocity/freemarker/categories-short.ftl | 29 +++++++ .../main/velocity/freemarker/categories.ftl | 26 ++++++ .../src/main/velocity/freemarker/task.ftl | 13 +++ .../src/main/velocity/freemarker/tasks.ftl | 18 ++++ .../tasks/src/main/webapp/freemarker/task.ftl | 2 +- .../tasks/test/XmlRepresentationTest.java | 80 +++++++++++++++++ examples/tasks/src/test/resources/ftests.xml | 13 ++- pom.xml | 74 ++++++++++++---- 13 files changed, 345 insertions(+), 42 deletions(-) create mode 100644 examples/tasks/src/main/velocity/freemarker/categories-short.ftl create mode 100644 examples/tasks/src/main/velocity/freemarker/categories.ftl create mode 100644 examples/tasks/src/main/velocity/freemarker/task.ftl create mode 100644 examples/tasks/src/main/velocity/freemarker/tasks.ftl create mode 100644 examples/tasks/src/test/java/org/jboss/seam/rest/example/tasks/test/XmlRepresentationTest.java diff --git a/examples/tasks/pom.xml b/examples/tasks/pom.xml index f5aa457..3237be8 100644 --- a/examples/tasks/pom.xml +++ b/examples/tasks/pom.xml @@ -104,6 +104,11 @@ org.testng testng + + commons-httpclient + commons-httpclient + test + @@ -136,15 +141,6 @@ - - catch - - - org.jboss.seam.catch - seam-catch - - - jboss-remote-6 @@ -244,16 +240,73 @@ org.apache.maven.plugins maven-war-plugin - - - - src/main/jboss - - - + + + package-jboss + package + + war + + + false + src/main/jboss + + + + + + + + + + velocity + + + + org.apache.maven.plugins + maven-war-plugin + + + package-velocity + package + + war + + + false + src/main/velocity + + + + + + org.apache.velocity + velocity + + + org.apache.velocity + velocity-tools + + + + org.freemarker + freemarker + provided + + + + + + catch + + + org.jboss.seam.catch + seam-catch + + diff --git a/examples/tasks/readme.txt b/examples/tasks/readme.txt index 2618349..75b968d 100644 --- a/examples/tasks/readme.txt +++ b/examples/tasks/readme.txt @@ -7,8 +7,6 @@ mvn clean package cp target/seam-tasks.war $JBOSS_HOME/server/default/deploy $JBOSS_HOME/bin/run.sh -Djboss.i18n.generate-proxies=true -To turn on Seam Catch integration, use -Pcatch (e.g. mvn clean package -Pcatch) - Deploying to Glassfish ====================== mvn clean package -Pglassfish @@ -16,13 +14,18 @@ $GF_HOME/bin/asadmin start-database $GF_HOME/bin/asadmin start-domain $GF_HOME/bin/asadmin deploy target/seam-tasks.war - Deploying to Resin (not currently supported) ====================== mvn clean package -Presin cp target/seam-tasks.war $RESIN_HOME/webapps $RESIN_HOME/bin/resin.sh start +Build options +====================== +To turn on Seam Catch integration, use -Pcatch (e.g. mvn clean package -Pcatch) +To use Apache Velocity instead of FreeMarker, use -Pvelociry (e.g. mvn clean package -Pvelocity) +Build options can be combined and used during functional testsuite execution. + Running functional test from command line ====================== build & deploy the application (using steps above) @@ -42,4 +45,4 @@ arguments in the arguments tab: -Dmethod=* -Dbrowser=*firefoxproxy -Dcontext.root=http://localhost:8080/ -Dcontext.path=/seam-tasks/ -Dselenium.host=localhost -Dselenium.port=14444 -Dselenium.debug=false -Dselenium.maximize=false -Dselenium.timeout.default=30000 -Dselenium.timeout.gui=5000 -Dselenium.timeout.ajax=15000 -Dselenium.timeout.model=30000 -Dselenium.speed=0 -Dselenium.timeout=3000 -Dbasedir=. -Note that you need to add the arguments for every test class. \ No newline at end of file +Note that you need to add the arguments for every test class. diff --git a/examples/tasks/src/main/java/org/jboss/seam/rest/example/tasks/resource/CategoryCollectionResource.java b/examples/tasks/src/main/java/org/jboss/seam/rest/example/tasks/resource/CategoryCollectionResource.java index 1405ddd..e4c3d04 100644 --- a/examples/tasks/src/main/java/org/jboss/seam/rest/example/tasks/resource/CategoryCollectionResource.java +++ b/examples/tasks/src/main/java/org/jboss/seam/rest/example/tasks/resource/CategoryCollectionResource.java @@ -12,6 +12,8 @@ import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.UriInfo; import org.jboss.seam.rest.example.tasks.entity.Category; import org.jboss.seam.rest.templating.ResponseTemplate; @@ -38,6 +40,8 @@ public class CategoryCollectionResource @Min(value = 0, message = "limit must be a non-negative number") @Max(value = 100, message = "Cannot return more than 100 items") protected int limit; + @Context + protected UriInfo uriInfo; @GET @ValidateRequest @@ -50,4 +54,19 @@ public List getCategories() { return bean.getCategories(start, limit); } + + public int getStart() + { + return start; + } + + public int getLimit() + { + return limit; + } + + public UriInfo getUriInfo() + { + return uriInfo; + } } diff --git a/examples/tasks/src/main/java/org/jboss/seam/rest/example/tasks/resource/TaskCollectionResource.java b/examples/tasks/src/main/java/org/jboss/seam/rest/example/tasks/resource/TaskCollectionResource.java index c4aa4ca..a4b782f 100644 --- a/examples/tasks/src/main/java/org/jboss/seam/rest/example/tasks/resource/TaskCollectionResource.java +++ b/examples/tasks/src/main/java/org/jboss/seam/rest/example/tasks/resource/TaskCollectionResource.java @@ -73,4 +73,19 @@ public void setStatus(String status) { this.status = status; } + + public UriInfo getUriInfo() + { + return uriInfo; + } + + public int getStart() + { + return start; + } + + public int getLimit() + { + return limit; + } } diff --git a/examples/tasks/src/main/resources/META-INF/seam-beans.xml b/examples/tasks/src/main/resources/META-INF/seam-beans.xml index 3d9709d..c758012 100644 --- a/examples/tasks/src/main/resources/META-INF/seam-beans.xml +++ b/examples/tasks/src/main/resources/META-INF/seam-beans.xml @@ -1,7 +1,7 @@ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> - + diff --git a/examples/tasks/src/main/velocity/freemarker/categories-short.ftl b/examples/tasks/src/main/velocity/freemarker/categories-short.ftl new file mode 100644 index 0000000..8065fdb --- /dev/null +++ b/examples/tasks/src/main/velocity/freemarker/categories-short.ftl @@ -0,0 +1,29 @@ +#* + This file contains an Apache Velocity template. It uses FreeMarker's file extension (.ftl) + since we need to switch between FreeMarker / Velocity without changing the Java code (annotations). +*# + + +#if ( $response.size() == $categoryCollectionResource.limit ) + #set( $next = $categoryCollectionResource.start + $categoryCollectionResource.limit ) + +#end +#if ( $categoryCollectionResource.start >= $categoryCollectionResource.limit ) + #set( $previous = $categoryCollectionResource.start - $categoryCollectionResource.limit) + +#end +#foreach( ${category} in ${response} ) + + ${category.name} + + + #foreach ( $task in $category.tasks ) + + ${task.name} + + + #end + + +#end + \ No newline at end of file diff --git a/examples/tasks/src/main/velocity/freemarker/categories.ftl b/examples/tasks/src/main/velocity/freemarker/categories.ftl new file mode 100644 index 0000000..1cc2295 --- /dev/null +++ b/examples/tasks/src/main/velocity/freemarker/categories.ftl @@ -0,0 +1,26 @@ +#* + This file contains an Apache Velocity template. It uses FreeMarker's file extension (.ftl) + since we need to switch between FreeMarker / Velocity without changing the Java code (annotations). +*# + + +#if ( $response.size() == $categoryCollectionResource.limit ) + #set( $next = $categoryCollectionResource.start + $categoryCollectionResource.limit ) + +#end +#if ( $categoryCollectionResource.start >= $categoryCollectionResource.limit ) + #set( $previous = $categoryCollectionResource.start - $categoryCollectionResource.limit) + +#end +#foreach( ${category} in ${response} ) + + ${category.name} + + + #foreach ( $task in $category.tasks ) + #parse("/freemarker/task.ftl") + #end + + +#end + \ No newline at end of file diff --git a/examples/tasks/src/main/velocity/freemarker/task.ftl b/examples/tasks/src/main/velocity/freemarker/task.ftl new file mode 100644 index 0000000..670cbc4 --- /dev/null +++ b/examples/tasks/src/main/velocity/freemarker/task.ftl @@ -0,0 +1,13 @@ +#* + This file contains an Apache Velocity template. It uses FreeMarker's file extension (.ftl) + since we need to switch between FreeMarker / Velocity without changing the Java code (annotations). +*# + + ${task.name} + + + + ${task.isResolved()} + ${task.created} + ${task.updated} + diff --git a/examples/tasks/src/main/velocity/freemarker/tasks.ftl b/examples/tasks/src/main/velocity/freemarker/tasks.ftl new file mode 100644 index 0000000..5bf4d4e --- /dev/null +++ b/examples/tasks/src/main/velocity/freemarker/tasks.ftl @@ -0,0 +1,18 @@ +#* + This file contains an Apache Velocity template. It uses FreeMarker's file extension (.ftl) + since we need to switch between FreeMarker / Velocity without changing the Java code (annotations). +*# + + +#if ( $response.size() == $taskCollectionResource.limit) + #set( $next = $taskCollectionResource.start + $taskCollectionResource.limit ) + +#end +#if ( $taskCollectionResource.start >= $taskCollectionResource.limit ) + #set( $previous = $taskCollectionResource.start - $taskCollectionResource.limit) + +#end +#foreach( ${task} in ${response} ) + #parse("/freemarker/task.ftl") +#end + \ No newline at end of file diff --git a/examples/tasks/src/main/webapp/freemarker/task.ftl b/examples/tasks/src/main/webapp/freemarker/task.ftl index 3f02a1c..2f669db 100644 --- a/examples/tasks/src/main/webapp/freemarker/task.ftl +++ b/examples/tasks/src/main/webapp/freemarker/task.ftl @@ -1,7 +1,7 @@ ${task.name} - + ${task.isResolved()?string} ${task.created} diff --git a/examples/tasks/src/test/java/org/jboss/seam/rest/example/tasks/test/XmlRepresentationTest.java b/examples/tasks/src/test/java/org/jboss/seam/rest/example/tasks/test/XmlRepresentationTest.java new file mode 100644 index 0000000..d6e2f0a --- /dev/null +++ b/examples/tasks/src/test/java/org/jboss/seam/rest/example/tasks/test/XmlRepresentationTest.java @@ -0,0 +1,80 @@ +package org.jboss.seam.rest.example.tasks.test; + +import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertTrue; + +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.methods.GetMethod; +import org.testng.annotations.Test; + +/** + * This test verifies XML representations created by FreeMarker or Apache Velocity. + * @author Jozef Hartinger + * + */ +public class XmlRepresentationTest +{ + private HttpClient client = new HttpClient(); + + private String getRepresentation(String url, String accept) throws Exception + { + GetMethod get = new GetMethod(url); + get.setRequestHeader("Accept", accept); + assertEquals(200, client.executeMethod(get)); + return get.getResponseBodyAsString(); + } + + @Test + public void testTask() throws Exception + { + String representation = getRepresentation("http://localhost:8080/seam-tasks/api/task/2", "application/task+xml"); + assertTrue(representation.contains("Build the Turing machine")); + assertTrue(representation.contains("")); + assertTrue(representation.contains("")); + assertTrue(representation.contains("")); + assertTrue(representation.contains("false")); + } + + @Test + public void testTasks() throws Exception + { + String representation = getRepresentation("http://localhost:8080/seam-tasks/api/task?start=4&limit=1", "application/tasks+xml"); + assertTrue(representation.contains("")); + assertTrue(representation.contains("")); + assertTrue(representation.contains("")); + assertTrue(representation.contains("Pick up meal tickets")); + assertTrue(representation.contains("")); + assertTrue(representation.contains("")); + assertTrue(representation.contains("")); + } + + @Test + public void testCategories() throws Exception + { + String representation = getRepresentation("http://localhost:8080/seam-tasks/api/category?start=1&limit=1", "application/categories+xml"); + assertTrue(representation.contains("")); + assertTrue(representation.contains("")); + assertTrue(representation.contains("")); + assertTrue(representation.contains("Work")); + assertTrue(representation.contains("")); + assertTrue(representation.contains("Pick up meal tickets")); + assertTrue(representation.contains("")); + assertTrue(representation.contains("")); + assertTrue(representation.contains("")); + assertTrue(representation.contains("false")); + } + + @Test + public void testCategoriesShort() throws Exception + { + String representation = getRepresentation("http://localhost:8080/seam-tasks/api/category?start=1&limit=1", "application/categories-short+xml"); + assertTrue(representation.contains("")); + assertTrue(representation.contains("")); + assertTrue(representation.contains("")); + assertTrue(representation.contains("Work")); + assertTrue(representation.contains("")); + assertTrue(representation.contains("Pick up meal tickets")); + assertTrue(representation.contains("")); + } + +} diff --git a/examples/tasks/src/test/resources/ftests.xml b/examples/tasks/src/test/resources/ftests.xml index a029405..abfe383 100644 --- a/examples/tasks/src/test/resources/ftests.xml +++ b/examples/tasks/src/test/resources/ftests.xml @@ -1,8 +1,13 @@ - - - - + + + + + + + + + diff --git a/pom.xml b/pom.xml index 3c43823..2954fd4 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ 1.0.0.Beta2 1.1.1 3.1 - 5.12.1 + 5.14.2 1.6.1 2.1.0.GA 2.3.16 @@ -60,23 +60,23 @@ pom - - org.jboss.seam.rest - seam-rest-api - ${project.version} - + + org.jboss.seam.rest + seam-rest-api + ${project.version} + - - org.jboss.seam.rest - seam-rest-impl - ${project.version} - + + org.jboss.seam.rest + seam-rest-impl + ${project.version} + - - org.jboss.seam.rest - seam-rest - ${project.version} - + + org.jboss.seam.rest + seam-rest + ${project.version} + javax.ws.rs @@ -103,6 +103,48 @@ org.apache.velocity velocity-tools ${velocity.tools.version} + + + dom4j + dom4j + + + oro + oro + + + sslext + sslext + + + org.apache.struts + struts-core + + + org.apache.struts + struts-taglib + + + org.apache.struts + struts-tiles + + + commons-beanutils + commons-beanutils + + + commons-digester + commons-digester + + + commons-chain + commons-chain + + + commons-validator + commons-validator + +