Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

SEAMREST-52

  • Loading branch information...
commit e20a18aecd8df97528d991ad89049b4440cb7819 1 parent 7cc3273
@jharting jharting authored
View
92 ...es/tasks/src/test/java/org/jboss/seam/rest/examples/tasks/test/XmlRepresentationTest.java
@@ -1,6 +1,10 @@
package org.jboss.seam.rest.examples.tasks.test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
import java.net.URL;
+import java.util.regex.Pattern;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
@@ -11,9 +15,6 @@
import org.junit.Test;
import org.junit.runner.RunWith;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
/**
* This test verifies XML representations created by FreeMarker or Apache Velocity.
*
@@ -37,65 +38,54 @@ private String getRepresentation(String segment, String accept) throws Exception
@Test
public void testTask() throws Exception {
String representation = getRepresentation("/rest-tasks/api/task/2", "application/task+xml");
- assertTrue(representation.contains("<name>Build the Turing machine</name>"));
- assertTrue(representation.contains("<link rel=\"self\" href=\"/rest-tasks/api/task/2\"/>"));
- assertTrue(representation
- .contains("<link rel=\"http://sfwk.org/rest/tasks/move\" href=\"/rest-tasks/api/task/2/move?category={category-name}\"/>"));
- assertTrue(representation.contains("<link rel=\"edit\" href=\"/rest-tasks/api/task/2\"/>"));
- assertTrue(representation.contains("<resolved>false</resolved>"));
+ assertTrue(contains(representation, "<name>Build the Turing machine</name>"));
+ assertTrue(contains(representation, "<link rel=\"self\" href=\".*/rest-tasks/api/task/2\"/>"));
+ assertTrue(contains(representation, "<link rel=\"http://sfwk\\.org/rest/tasks/move\" href=\".*/rest-tasks/api/task/2/move\\?category=\\{category-name\\}\"/>"));
+ assertTrue(contains(representation, "<link rel=\"edit\" href=\".*/rest-tasks/api/task/2\"/>"));
+ assertTrue(contains(representation, "<resolved>false</resolved>"));
}
-
+
@Test
public void testTasks() throws Exception {
- String representation = getRepresentation("/rest-tasks/api/task?start=4&limit=1",
- "application/tasks+xml");
- assertTrue(representation
- .contains("<link href=\"self\" href=\"/rest-tasks/api/task?start=4&limit=1\"/>"));
- assertTrue(representation
- .contains("<link href=\"next\" href=\"/rest-tasks/api/task?start=5&limit=1\"/>"));
- assertTrue(representation
- .contains("<link href=\"previous\" href=\"/rest-tasks/api/task?start=3&limit=1\"/>"));
- assertTrue(representation.contains("<name>Pick up meal tickets</name>"));
- assertTrue(representation.contains("<link rel=\"self\" href=\"/rest-tasks/api/task/8\"/>"));
- assertTrue(representation
- .contains("<link rel=\"http://sfwk.org/rest/tasks/move\" href=\"/rest-tasks/api/task/8/move?category={category-name}\"/>"));
- assertTrue(representation.contains("<link rel=\"edit\" href=\"/rest-tasks/api/task/8\"/>"));
+ String representation = getRepresentation("/rest-tasks/api/task?start=4&limit=1", "application/tasks+xml");
+ assertTrue(contains(representation, "<link href=\"self\" href=\".*/rest-tasks/api/task\\?start=4&limit=1\"/>"));
+ assertTrue(contains(representation, "<link href=\"next\" href=\".*/rest-tasks/api/task\\?start=5&limit=1\"/>"));
+ assertTrue(contains(representation, "<link href=\"previous\" href=\".*/rest-tasks/api/task\\?start=3&limit=1\"/>"));
+ assertTrue(contains(representation, "<name>Pick up meal tickets</name>"));
+ assertTrue(contains(representation, "<link rel=\"self\" href=\".*/rest-tasks/api/task/8\"/>"));
+ assertTrue(contains(representation, "<link rel=\"http://sfwk\\.org/rest/tasks/move\" href=\".*/rest-tasks/api/task/8/move\\?category=\\{category-name\\}\"/>"));
+ assertTrue(contains(representation, "<link rel=\"edit\" href=\".*/rest-tasks/api/task/8\"/>"));
}
@Test
public void testCategories() throws Exception {
- String representation = getRepresentation("/rest-tasks/api/category?start=1&limit=1",
- "application/categories+xml");
- assertTrue(representation
- .contains("<link href=\"self\" href=\"/rest-tasks/api/category?start=1&limit=1\"/>"));
- assertTrue(representation
- .contains("<link href=\"next\" href=\"/rest-tasks/api/category?start=2&limit=1\"/>"));
- assertTrue(representation
- .contains("<link href=\"previous\" href=\"/rest-tasks/api/category?start=0&limit=1\"/>"));
- assertTrue(representation.contains("<name>Work</name>"));
- assertTrue(representation.contains("<link rel=\"self\" href=\"/rest-tasks/api/category/Work\"/>"));
- assertTrue(representation.contains("<name>Pick up meal tickets</name>"));
- assertTrue(representation.contains("<link rel=\"self\" href=\"/rest-tasks/api/task/8\"/>"));
- assertTrue(representation
- .contains("<link rel=\"http://sfwk.org/rest/tasks/move\" href=\"/rest-tasks/api/task/8/move?category={category-name}\"/>"));
- assertTrue(representation.contains("<link rel=\"edit\" href=\"/rest-tasks/api/task/8\"/>"));
- assertTrue(representation.contains("<resolved>false</resolved>"));
+ String representation = getRepresentation("/rest-tasks/api/category?start=1&limit=1", "application/categories+xml");
+ assertTrue(contains(representation, "<link href=\"self\" href=\".*/rest-tasks/api/category\\?start=1&limit=1\"/>"));
+ assertTrue(contains(representation, "<link href=\"next\" href=\".*/rest-tasks/api/category\\?start=2&limit=1\"/>"));
+ assertTrue(contains(representation, "<link href=\"previous\" href=\".*/rest-tasks/api/category\\?start=0&limit=1\"/>"));
+ assertTrue(contains(representation, "<name>Work</name>"));
+ assertTrue(contains(representation, "<link rel=\"self\" href=\".*/rest-tasks/api/category/Work\"/>"));
+ assertTrue(contains(representation, "<name>Pick up meal tickets</name>"));
+ assertTrue(contains(representation, "<link rel=\"self\" href=\".*/rest-tasks/api/task/8\"/>"));
+ assertTrue(contains(representation, "<link rel=\"http://sfwk\\.org/rest/tasks/move\" href=\".*/rest-tasks/api/task/8/move\\?category=\\{category-name\\}\"/>"));
+ assertTrue(contains(representation, "<link rel=\"edit\" href=\".*/rest-tasks/api/task/8\"/>"));
+ assertTrue(contains(representation, "<resolved>false</resolved>"));
}
@Test
public void testCategoriesShort() throws Exception {
- String representation = getRepresentation("/rest-tasks/api/category?start=1&limit=1",
- "application/categories-short+xml");
- assertTrue(representation
- .contains("<link href=\"self\" href=\"/rest-tasks/api/category?start=1&limit=1\"/>"));
- assertTrue(representation
- .contains("<link href=\"next\" href=\"/rest-tasks/api/category?start=2&limit=1\"/>"));
- assertTrue(representation
- .contains("<link href=\"previous\" href=\"/rest-tasks/api/category?start=0&limit=1\"/>"));
- assertTrue(representation.contains("<name>Work</name>"));
- assertTrue(representation.contains("<link rel=\"self\" href=\"/rest-tasks/api/category/Work\"/>"));
- assertTrue(representation.contains("<name>Pick up meal tickets</name>"));
- assertTrue(representation.contains("<link rel=\"self\" href=\"/rest-tasks/api/task/8\"/>"));
+ String representation = getRepresentation("/rest-tasks/api/category?start=1&limit=1", "application/categories-short+xml");
+ assertTrue(contains(representation, "<link href=\"self\" href=\".*/rest-tasks/api/category\\?start=1&limit=1\"/>"));
+ assertTrue(contains(representation, "<link href=\"next\" href=\".*/rest-tasks/api/category\\?start=2&limit=1\"/>"));
+ assertTrue(contains(representation, "<link href=\"previous\" href=\".*/rest-tasks/api/category\\?start=0&limit=1\"/>"));
+ assertTrue(contains(representation, "<name>Work</name>"));
+ assertTrue(contains(representation, "<link rel=\"self\" href=\".*/rest-tasks/api/category/Work\"/>"));
+ assertTrue(contains(representation, "<name>Pick up meal tickets</name>"));
+ assertTrue(contains(representation, "<link rel=\"self\" href=\".*/rest-tasks/api/task/8\"/>"));
}
+ private boolean contains(String value, String regex)
+ {
+ return Pattern.compile(regex).matcher(value).find();
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.