Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
345 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
examples/tasks/src/main/velocity/freemarker/categories-short.ftl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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). | ||
*# | ||
<categories> | ||
<link href="self" href="${categoryCollectionResource.uriInfo.baseUri}category?start=${categoryCollectionResource.start}&limit=${categoryCollectionResource.limit}"/> | ||
#if ( $response.size() == $categoryCollectionResource.limit ) | ||
#set( $next = $categoryCollectionResource.start + $categoryCollectionResource.limit ) | ||
<link href="next" href="${categoryCollectionResource.uriInfo.baseUri}category?start=${next}&limit=${categoryCollectionResource.limit}"/> | ||
#end | ||
#if ( $categoryCollectionResource.start >= $categoryCollectionResource.limit ) | ||
#set( $previous = $categoryCollectionResource.start - $categoryCollectionResource.limit) | ||
<link href="previous" href="${categoryCollectionResource.uriInfo.baseUri}category?start=${previous}&limit=${categoryCollectionResource.limit}"/> | ||
#end | ||
#foreach( ${category} in ${response} ) | ||
<category> | ||
<name>${category.name}</name> | ||
<link rel="self" href="${categoryCollectionResource.uriInfo.baseUri}category/${category.name}"/> | ||
<tasks> | ||
#foreach ( $task in $category.tasks ) | ||
<task> | ||
<name>${task.name}</name> | ||
<link rel="self" href="${categoryCollectionResource.uriInfo.baseUri}task/${task.id}"/> | ||
</task> | ||
#end | ||
</tasks> | ||
</category> | ||
#end | ||
<categories> |
26 changes: 26 additions & 0 deletions
26
examples/tasks/src/main/velocity/freemarker/categories.ftl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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). | ||
*# | ||
<categories> | ||
<link href="self" href="${categoryCollectionResource.uriInfo.baseUri}category?start=${categoryCollectionResource.start}&limit=${categoryCollectionResource.limit}"/> | ||
#if ( $response.size() == $categoryCollectionResource.limit ) | ||
#set( $next = $categoryCollectionResource.start + $categoryCollectionResource.limit ) | ||
<link href="next" href="${categoryCollectionResource.uriInfo.baseUri}category?start=${next}&limit=${categoryCollectionResource.limit}"/> | ||
#end | ||
#if ( $categoryCollectionResource.start >= $categoryCollectionResource.limit ) | ||
#set( $previous = $categoryCollectionResource.start - $categoryCollectionResource.limit) | ||
<link href="previous" href="${categoryCollectionResource.uriInfo.baseUri}category?start=${previous}&limit=${categoryCollectionResource.limit}"/> | ||
#end | ||
#foreach( ${category} in ${response} ) | ||
<category> | ||
<name>${category.name}</name> | ||
<link rel="self" href="${categoryCollectionResource.uriInfo.baseUri}category/${category.name}"/> | ||
<tasks> | ||
#foreach ( $task in $category.tasks ) | ||
#parse("/freemarker/task.ftl") | ||
#end | ||
</tasks> | ||
</category> | ||
#end | ||
<categories> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.name}</name> | ||
<link rel="self" href="${taskCollectionResource.uriInfo.baseUri}task/${task.id}"/> | ||
<link rel="http://sfwk.org/rest/tasks/move" href="${taskCollectionResource.uriInfo.baseUri}task/${task.id}/move?category={category-name}"/> | ||
<link rel="edit" href="${taskCollectionResource.uriInfo.baseUri}task/${task.id}"/> | ||
<resolved>${task.isResolved()}</resolved> | ||
<created>${task.created}</created> | ||
<updated>${task.updated}</updated> | ||
</task> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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). | ||
*# | ||
<tasks> | ||
<link href="self" href="${taskCollectionResource.uriInfo.absolutePath}?start=${taskCollectionResource.start}&limit=${taskCollectionResource.limit}"/> | ||
#if ( $response.size() == $taskCollectionResource.limit) | ||
#set( $next = $taskCollectionResource.start + $taskCollectionResource.limit ) | ||
<link href="next" href="${taskCollectionResource.uriInfo.absolutePath}?start=${next}&limit=${taskCollectionResource.limit}"/> | ||
#end | ||
#if ( $taskCollectionResource.start >= $taskCollectionResource.limit ) | ||
#set( $previous = $taskCollectionResource.start - $taskCollectionResource.limit) | ||
<link href="previous" href="${taskCollectionResource.uriInfo.absolutePath}?start=${previous}&limit=${taskCollectionResource.limit}"/> | ||
#end | ||
#foreach( ${task} in ${response} ) | ||
#parse("/freemarker/task.ftl") | ||
#end | ||
</tasks> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...les/tasks/src/test/java/org/jboss/seam/rest/example/tasks/test/XmlRepresentationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <a href="http://community.jboss.org/people/jharting">Jozef Hartinger</a> | ||
* | ||
*/ | ||
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("<name>Build the Turing machine</name>")); | ||
assertTrue(representation.contains("<link rel=\"self\" href=\"http://localhost:8080/seam-tasks/api/task/2\"/>")); | ||
assertTrue(representation.contains("<link rel=\"http://sfwk.org/rest/tasks/move\" href=\"http://localhost:8080/seam-tasks/api/task/2/move?category={category-name}\"/>")); | ||
assertTrue(representation.contains("<link rel=\"edit\" href=\"http://localhost:8080/seam-tasks/api/task/2\"/>")); | ||
assertTrue(representation.contains("<resolved>false</resolved>")); | ||
} | ||
|
||
@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("<link href=\"self\" href=\"http://localhost:8080/seam-tasks/api/task?start=4&limit=1\"/>")); | ||
assertTrue(representation.contains("<link href=\"next\" href=\"http://localhost:8080/seam-tasks/api/task?start=5&limit=1\"/>")); | ||
assertTrue(representation.contains("<link href=\"previous\" href=\"http://localhost:8080/seam-tasks/api/task?start=3&limit=1\"/>")); | ||
assertTrue(representation.contains("<name>Pick up meal tickets</name>")); | ||
assertTrue(representation.contains("<link rel=\"self\" href=\"http://localhost:8080/seam-tasks/api/task/8\"/>")); | ||
assertTrue(representation.contains("<link rel=\"http://sfwk.org/rest/tasks/move\" href=\"http://localhost:8080/seam-tasks/api/task/8/move?category={category-name}\"/>")); | ||
assertTrue(representation.contains("<link rel=\"edit\" href=\"http://localhost:8080/seam-tasks/api/task/8\"/>")); | ||
} | ||
|
||
@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("<link href=\"self\" href=\"http://localhost:8080/seam-tasks/api/category?start=1&limit=1\"/>")); | ||
assertTrue(representation.contains("<link href=\"next\" href=\"http://localhost:8080/seam-tasks/api/category?start=2&limit=1\"/>")); | ||
assertTrue(representation.contains("<link href=\"previous\" href=\"http://localhost:8080/seam-tasks/api/category?start=0&limit=1\"/>")); | ||
assertTrue(representation.contains("<name>Work</name>")); | ||
assertTrue(representation.contains("<link rel=\"self\" href=\"http://localhost:8080/seam-tasks/api/category/Work\"/>")); | ||
assertTrue(representation.contains("<name>Pick up meal tickets</name>")); | ||
assertTrue(representation.contains("<link rel=\"self\" href=\"http://localhost:8080/seam-tasks/api/task/8\"/>")); | ||
assertTrue(representation.contains("<link rel=\"http://sfwk.org/rest/tasks/move\" href=\"http://localhost:8080/seam-tasks/api/task/8/move?category={category-name}\"/>")); | ||
assertTrue(representation.contains("<link rel=\"edit\" href=\"http://localhost:8080/seam-tasks/api/task/8\"/>")); | ||
assertTrue(representation.contains("<resolved>false</resolved>")); | ||
} | ||
|
||
@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("<link href=\"self\" href=\"http://localhost:8080/seam-tasks/api/category?start=1&limit=1\"/>")); | ||
assertTrue(representation.contains("<link href=\"next\" href=\"http://localhost:8080/seam-tasks/api/category?start=2&limit=1\"/>")); | ||
assertTrue(representation.contains("<link href=\"previous\" href=\"http://localhost:8080/seam-tasks/api/category?start=0&limit=1\"/>")); | ||
assertTrue(representation.contains("<name>Work</name>")); | ||
assertTrue(representation.contains("<link rel=\"self\" href=\"http://localhost:8080/seam-tasks/api/category/Work\"/>")); | ||
assertTrue(representation.contains("<name>Pick up meal tickets</name>")); | ||
assertTrue(representation.contains("<link rel=\"self\" href=\"http://localhost:8080/seam-tasks/api/task/8\"/>")); | ||
} | ||
|
||
} |
Oops, something went wrong.