summaryrefslogtreecommitdiffstats
path: root/branches/sca-equinox/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTest.java
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2008-10-09 06:33:54 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2008-10-09 06:33:54 +0000
commitefe3363a815a777ecd283928900404dea84a7e1f (patch)
tree42522fd01e6af981f8ff94663d911d56744154d5 /branches/sca-equinox/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTest.java
parentaacabe1650e380595a8d701123394d791656d17d (diff)
Work in progress. Fixed implementation of NodeImpl, now working without dependencies on implementations from other bundles (except RuntimeAssemblyFactory, which will need to be cleaned up too). Started to remove dependencies on host-embedded and port code to NodeFactory and Node, as an interim step to bring them up, before porting them to the OSGi-enabled node launcher.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@703068 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-equinox/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTest.java')
-rw-r--r--branches/sca-equinox/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTest.java631
1 files changed, 320 insertions, 311 deletions
diff --git a/branches/sca-equinox/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTest.java b/branches/sca-equinox/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTest.java
index faa7d414f5..4c6c2a04c2 100644
--- a/branches/sca-equinox/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTest.java
+++ b/branches/sca-equinox/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTest.java
@@ -22,335 +22,344 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import junit.framework.Assert;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.abdera.Abdera;
-import org.apache.abdera.i18n.iri.IRI;
import org.apache.abdera.factory.Factory;
-import org.apache.abdera.model.Base;
+import org.apache.abdera.i18n.iri.IRI;
+import org.apache.abdera.model.Collection;
import org.apache.abdera.model.Content;
+import org.apache.abdera.model.Document;
import org.apache.abdera.model.Entry;
import org.apache.abdera.model.Feed;
-import org.apache.abdera.model.Document;
-import org.apache.abdera.model.Service;
-import org.apache.abdera.model.Collection;
+import org.apache.abdera.parser.Parser;
import org.apache.abdera.protocol.Response.ResponseType;
import org.apache.abdera.protocol.client.AbderaClient;
import org.apache.abdera.protocol.client.ClientResponse;
import org.apache.abdera.protocol.client.RequestOptions;
-import org.apache.abdera.protocol.client.util.BaseRequestEntity;
-import org.apache.abdera.util.EntityTag;
-import org.apache.abdera.parser.Parser;
+import org.apache.tuscany.sca.node.Contribution;
+import org.apache.tuscany.sca.node.ContributionLocationHelper;
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
/**
* Tests use of server provided feed entity tags for Atom binding in Tuscany.
- * Tests conditional gets (e.g. get if-none-match) or conditional posts (post if-match)
- * using entity tags and last modified entries in headers.
- * Uses the SCA provided Provider composite to act as a server.
- * Uses the Abdera provided Client to act as a client.
+ * Tests conditional gets (e.g. get if-none-match) or conditional posts (post
+ * if-match) using entity tags and last modified entries in headers. Uses the
+ * SCA provided Provider composite to act as a server. Uses the Abdera provided
+ * Client to act as a client.
*/
public class ProviderFeedEntityTagsTest {
- public final static String providerURI = "http://localhost:8084/customer";
- protected static SCADomain scaConsumerDomain;
- protected static SCADomain scaProviderDomain;
- protected static CustomerClient testService;
+ public final static String providerURI = "http://localhost:8084/customer";
+ protected static Node providerNode;
protected static Abdera abdera;
protected static AbderaClient client;
- protected static Parser abderaParser;
+ protected static Parser abderaParser;
protected static String eTag;
protected static Date lastModified;
- protected static final SimpleDateFormat dateFormat = new SimpleDateFormat( "EEE, dd MMM yyyy HH:mm:ss Z" ); // RFC 822 date time
-
- @BeforeClass
- public static void init() throws Exception {
- System.out.println(">>>ProviderFeedEntityTagsTest.init");
- scaProviderDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Provider.composite");
- abdera = new Abdera();
- client = new AbderaClient(abdera);
- abderaParser = Abdera.getNewParser();
- }
-
- @AfterClass
- public static void destroy() throws Exception {
- System.out.println(">>>ProviderFeedEntityTagsTest.destroy");
- scaProviderDomain.close();
- }
-
- @Test
- public void testPrelim() throws Exception {
- Assert.assertNotNull(scaProviderDomain);
- Assert.assertNotNull( client );
- }
-
- @Test
- public void testFeedBasics() throws Exception {
- System.out.println(">>>ProviderFeedEntityTagsTest.testFeedBasics");
- // Normal feed request
- ClientResponse res = client.get(providerURI);
- Assert.assertNotNull(res);
- try {
- // Asser feed provided since no predicates
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals(ResponseType.SUCCESS, res.getType());
- // AtomTestCaseUtils.printResponseHeaders( "Feed response headers:", " ", res );
- // System.out.println("Feed response content:");
- // AtomTestCaseUtils.prettyPrint(abdera, res.getDocument());
-
- // Perform other tests on feed.
- Document<Feed> doc = res.getDocument();
- Assert.assertNotNull( doc );
- Feed feed = doc.getRoot();
- Assert.assertNotNull( feed );
- printFeed( "Feed values", " ", feed );
- // RFC 4287 requires non-null id, title, updated elements
- Assert.assertNotNull( feed.getId() );
- Assert.assertNotNull( feed.getTitle() );
- Assert.assertNotNull( feed.getUpdated() );
-
- eTag = res.getHeader("ETag");
- Assert.assertNotNull( eTag );
- lastModified = res.getLastModified();
- Assert.assertNotNull( lastModified );
- } finally {
- res.release();
- }
- }
-
- @Test
- public void testUnmodifiedGetIfMatch() throws Exception {
- System.out.println(">>>ProviderFeedEntityTagsTest.testFeedUnmodifiedGetIfMatch");
- // Feed request with predicates
- RequestOptions opts = new RequestOptions();
- final String contentType = "application/atom+xml";
- opts.setContentType(contentType);
- opts.setHeader( "If-Match", eTag);
-
- ClientResponse res = client.get(providerURI, opts);
- Assert.assertNotNull(res);
- try {
- String thisETag = res.getHeader("ETag");
- Assert.assertNotNull( thisETag );
- Date thisLastModified = res.getLastModified();
- Assert.assertNotNull( thisLastModified );
-
- // Should return 200 - Feed provided since it matches etag.
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals(ResponseType.SUCCESS, res.getType());
- // AtomTestCaseUtils.printResponseHeaders( "Feed response headers:", " ", res );
- // System.out.println("Feed response content:");
- // AtomTestCaseUtils.prettyPrint(abdera, res.getDocument());
- } finally {
- res.release();
- }
- }
-
- @Test
- public void testUnmodifiedGetIfNoneMatch() throws Exception {
- System.out.println(">>>ProviderFeedEntityTagsTest.testFeedUnmodifiedGetIfNoneMatch");
- // Feed request with predicates
- RequestOptions opts = new RequestOptions();
- final String contentType = "application/atom+xml";
- opts.setContentType(contentType);
- opts.setHeader( "If-None-Match", eTag);
-
- ClientResponse res = client.get(providerURI, opts);
- Assert.assertNotNull(res);
- try {
- // Should return 304 - Feed not provided since it matches ETag.
- Assert.assertEquals(304, res.getStatus());
- } finally {
- res.release();
- }
- }
-
- @Test
- public void testUnmodifiedGetIfUnModified() throws Exception {
- System.out.println(">>>ProviderFeedEntityTagsTest.testFeedUnmodifiedGetIfUnModified");
- // Feed request with predicates
- RequestOptions opts = new RequestOptions();
- final String contentType = "application/atom+xml";
- opts.setContentType(contentType);
- opts.setHeader( "If-Unmodified-Since", dateFormat.format( new Date() ));
-
- ClientResponse res = client.get(providerURI, opts);
- Assert.assertNotNull(res);
- try {
- // Should return 304 - Feed not provided since feed is modified since.
- Assert.assertEquals(304, res.getStatus());
- } finally {
- res.release();
- }
- }
-
- @Test
- public void testUnmodifiedGetIfModified() throws Exception {
- System.out.println(">>>ProviderFeedEntityTagsTest.testFeedUnmodifiedGetIfModified");
- // Feed request with predicates
- RequestOptions opts = new RequestOptions();
- final String contentType = "application/atom+xml";
- opts.setContentType(contentType);
- opts.setHeader( "If-Modified-Since", dateFormat.format( new Date( 0 ) ));
-
- ClientResponse res = client.get(providerURI, opts);
- Assert.assertNotNull(res);
- try {
- // Should return 200 - Feed provided since feed is changed.
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals(ResponseType.SUCCESS, res.getType());
-
- String thisETag = res.getHeader("ETag");
- Assert.assertNotNull( thisETag );
- Date thisLastModified = res.getLastModified();
- Assert.assertNotNull( thisLastModified );
- } finally {
- res.release();
- }
- }
-
- @Test
- public void testModifiedGetIfNoneMatch() throws Exception {
- System.out.println(">>>ProviderFeedEntityTagsTest.testFeedModifiedGetIfNoneMatch");
- // Post some new content to the feed.
- Factory factory = abdera.getFactory();
- String customerName = "Fred Farkle";
- Entry entry = factory.newEntry();
- entry.setTitle("customer " + customerName);
- entry.setUpdated(new Date());
- entry.addAuthor("Apache Tuscany");
- Content content = abdera.getFactory().newContent();
- content.setContentType(Content.Type.TEXT);
- content.setValue(customerName);
- entry.setContentElement(content);
-
- RequestOptions opts = new RequestOptions();
- String contentType = "application/atom+xml; type=entry";
- opts.setContentType(contentType);
- IRI colUri = new IRI(providerURI).resolve("customer");
- ClientResponse res = client.post(colUri.toString(), entry, opts);
-
- // Feed request with predicates
- opts = new RequestOptions();
- contentType = "application/atom+xml";
- opts.setContentType(contentType);
- opts.setHeader( "If-None-Match", eTag);
-
- res = client.get(providerURI, opts);
- Assert.assertNotNull(res);
- try {
- String thisETag = res.getHeader("ETag");
- Assert.assertNotNull( thisETag );
- Date thisLastModified = res.getLastModified();
- Assert.assertNotNull( thisLastModified );
-
- // Should return 200 - value since feed is changed
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals(ResponseType.SUCCESS, res.getType());
-
- // AtomTestCaseUtils.printResponseHeaders( "Feed modified if-none-match response headers:", " ", res );
- // System.out.println("Feed response content:");
- // AtomTestCaseUtils.prettyPrint(abdera, res.getDocument());
- } finally {
- res.release();
- }
- }
-
- @Test
- public void testModifiedGetIfMatch() throws Exception {
- System.out.println(">>>ProviderFeedEntityTagsTest.testFeedModifiedGetIfMatch");
- // Feed request with predicates
- RequestOptions opts = new RequestOptions();
- final String contentType = "application/atom+xml";
- opts.setContentType(contentType);
- opts.setHeader( "If-Match", eTag);
-
- ClientResponse res = client.get(providerURI, opts);
- Assert.assertNotNull(res);
- try {
- // Should return 412 - Precondition failed since feed changed.
- Assert.assertEquals(412, res.getStatus());
- // AtomTestCaseUtils.printResponseHeaders( "Feed response headers:", " ", res );
- // System.out.println("Feed response content:");
- // AtomTestCaseUtils.prettyPrint(abdera, res.getDocument());
- } finally {
- res.release();
- }
- }
-
- @Test
- public void testModifiedGetIfUnModified() throws Exception {
- System.out.println(">>>ProviderFeedEntityTagsTest.testFeedUnmodifiedGetIfUnModified");
- // Feed request with predicates
- RequestOptions opts = new RequestOptions();
- final String contentType = "application/atom+xml";
- opts.setContentType(contentType);
- opts.setHeader( "If-Unmodified-Since", dateFormat.format( new Date() ));
-
- ClientResponse res = client.get(providerURI, opts);
- Assert.assertNotNull(res);
- try {
- // Should return 304 - Feed not provided since feed is modified since.
- Assert.assertEquals(304, res.getStatus());
- } finally {
- res.release();
- }
- }
-
- @Test
- public void testModifiedGetIfModified() throws Exception {
- System.out.println(">>>ProviderFeedEntityTagsTest.testFeedUnmodifiedGetIfModified");
- // Feed request with predicates
- RequestOptions opts = new RequestOptions();
- final String contentType = "application/atom+xml";
- opts.setContentType(contentType);
- opts.setHeader( "If-Modified-Since", dateFormat.format( lastModified ));
-
- ClientResponse res = client.get(providerURI, opts);
- Assert.assertNotNull(res);
- try {
- // Should return 200 - Feed provided since feed is changed.
- Assert.assertEquals(200, res.getStatus());
- Assert.assertEquals(ResponseType.SUCCESS, res.getType());
-
- String thisETag = res.getHeader("ETag");
- Assert.assertNotNull( thisETag );
- Date thisLastModified = res.getLastModified();
- Assert.assertNotNull( thisLastModified );
- } finally {
- res.release();
- }
- }
-
-
- public static void printFeed( String title, String indent, Feed feed ) {
- if ( feed == null ) {
- System.out.println( title + " feed is null");
- return;
- }
-
- System.out.println( title );
- System.out.println( indent + "id=" + feed.getId() );
- System.out.println( indent + "title=" + feed.getTitle() );
- System.out.println( indent + "updated=" + feed.getUpdated() );
- System.out.println( indent + "author=" + feed.getAuthor() );
- Collection collection = feed.getCollection();
- if ( collection == null ) {
- System.out.println( indent + "collection=null" );
- } else {
- System.out.println( indent + "collection=" + collection );
- }
- // System.out.println( indent + "collection size=" + feed.getCollection() );
- // for (Collection collection : workspace.getCollections()) {
- // if (collection.getTitle().equals("customers")) {
- // String expected = uri + "customers";
- // String actual = collection.getResolvedHref().toString();
- // assertEquals(expected, actual);
- // }
- // }
-
- }
+ protected static final SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z"); // RFC
+ // 822
+ // date
+ // time
+
+ @BeforeClass
+ public static void init() throws Exception {
+ System.out.println(">>>ProviderFeedEntityTagsTest.init");
+ String contribution = ContributionLocationHelper.getContributionLocation(AtomDeleteTestCase.class);
+ providerNode = NodeFactory.newInstance().createNode(
+ "org/apache/tuscany/sca/binding/atom/Provider.composite", new Contribution("provider", contribution));
+ providerNode.start();
+ abdera = new Abdera();
+ client = new AbderaClient(abdera);
+ abderaParser = Abdera.getNewParser();
+ }
+
+ @AfterClass
+ public static void destroy() throws Exception {
+ System.out.println(">>>ProviderFeedEntityTagsTest.destroy");
+ providerNode.stop();
+ providerNode.destroy();
+ }
+
+ @Test
+ public void testPrelim() throws Exception {
+ Assert.assertNotNull(providerNode);
+ Assert.assertNotNull(client);
+ }
+
+ @Test
+ public void testFeedBasics() throws Exception {
+ System.out.println(">>>ProviderFeedEntityTagsTest.testFeedBasics");
+ // Normal feed request
+ ClientResponse res = client.get(providerURI);
+ Assert.assertNotNull(res);
+ try {
+ // Asser feed provided since no predicates
+ Assert.assertEquals(200, res.getStatus());
+ Assert.assertEquals(ResponseType.SUCCESS, res.getType());
+ // AtomTestCaseUtils.printResponseHeaders( "Feed response headers:",
+ // " ", res );
+ // System.out.println("Feed response content:");
+ // AtomTestCaseUtils.prettyPrint(abdera, res.getDocument());
+
+ // Perform other tests on feed.
+ Document<Feed> doc = res.getDocument();
+ Assert.assertNotNull(doc);
+ Feed feed = doc.getRoot();
+ Assert.assertNotNull(feed);
+ printFeed("Feed values", " ", feed);
+ // RFC 4287 requires non-null id, title, updated elements
+ Assert.assertNotNull(feed.getId());
+ Assert.assertNotNull(feed.getTitle());
+ Assert.assertNotNull(feed.getUpdated());
+
+ eTag = res.getHeader("ETag");
+ Assert.assertNotNull(eTag);
+ lastModified = res.getLastModified();
+ Assert.assertNotNull(lastModified);
+ } finally {
+ res.release();
+ }
+ }
+
+ @Test
+ public void testUnmodifiedGetIfMatch() throws Exception {
+ System.out.println(">>>ProviderFeedEntityTagsTest.testFeedUnmodifiedGetIfMatch");
+ // Feed request with predicates
+ RequestOptions opts = new RequestOptions();
+ final String contentType = "application/atom+xml";
+ opts.setContentType(contentType);
+ opts.setHeader("If-Match", eTag);
+
+ ClientResponse res = client.get(providerURI, opts);
+ Assert.assertNotNull(res);
+ try {
+ String thisETag = res.getHeader("ETag");
+ Assert.assertNotNull(thisETag);
+ Date thisLastModified = res.getLastModified();
+ Assert.assertNotNull(thisLastModified);
+
+ // Should return 200 - Feed provided since it matches etag.
+ Assert.assertEquals(200, res.getStatus());
+ Assert.assertEquals(ResponseType.SUCCESS, res.getType());
+ // AtomTestCaseUtils.printResponseHeaders( "Feed response headers:",
+ // " ", res );
+ // System.out.println("Feed response content:");
+ // AtomTestCaseUtils.prettyPrint(abdera, res.getDocument());
+ } finally {
+ res.release();
+ }
+ }
+
+ @Test
+ public void testUnmodifiedGetIfNoneMatch() throws Exception {
+ System.out.println(">>>ProviderFeedEntityTagsTest.testFeedUnmodifiedGetIfNoneMatch");
+ // Feed request with predicates
+ RequestOptions opts = new RequestOptions();
+ final String contentType = "application/atom+xml";
+ opts.setContentType(contentType);
+ opts.setHeader("If-None-Match", eTag);
+
+ ClientResponse res = client.get(providerURI, opts);
+ Assert.assertNotNull(res);
+ try {
+ // Should return 304 - Feed not provided since it matches ETag.
+ Assert.assertEquals(304, res.getStatus());
+ } finally {
+ res.release();
+ }
+ }
+
+ @Test
+ public void testUnmodifiedGetIfUnModified() throws Exception {
+ System.out.println(">>>ProviderFeedEntityTagsTest.testFeedUnmodifiedGetIfUnModified");
+ // Feed request with predicates
+ RequestOptions opts = new RequestOptions();
+ final String contentType = "application/atom+xml";
+ opts.setContentType(contentType);
+ opts.setHeader("If-Unmodified-Since", dateFormat.format(new Date()));
+
+ ClientResponse res = client.get(providerURI, opts);
+ Assert.assertNotNull(res);
+ try {
+ // Should return 304 - Feed not provided since feed is modified
+ // since.
+ Assert.assertEquals(304, res.getStatus());
+ } finally {
+ res.release();
+ }
+ }
+
+ @Test
+ public void testUnmodifiedGetIfModified() throws Exception {
+ System.out.println(">>>ProviderFeedEntityTagsTest.testFeedUnmodifiedGetIfModified");
+ // Feed request with predicates
+ RequestOptions opts = new RequestOptions();
+ final String contentType = "application/atom+xml";
+ opts.setContentType(contentType);
+ opts.setHeader("If-Modified-Since", dateFormat.format(new Date(0)));
+
+ ClientResponse res = client.get(providerURI, opts);
+ Assert.assertNotNull(res);
+ try {
+ // Should return 200 - Feed provided since feed is changed.
+ Assert.assertEquals(200, res.getStatus());
+ Assert.assertEquals(ResponseType.SUCCESS, res.getType());
+
+ String thisETag = res.getHeader("ETag");
+ Assert.assertNotNull(thisETag);
+ Date thisLastModified = res.getLastModified();
+ Assert.assertNotNull(thisLastModified);
+ } finally {
+ res.release();
+ }
+ }
+
+ @Test
+ public void testModifiedGetIfNoneMatch() throws Exception {
+ System.out.println(">>>ProviderFeedEntityTagsTest.testFeedModifiedGetIfNoneMatch");
+ // Post some new content to the feed.
+ Factory factory = abdera.getFactory();
+ String customerName = "Fred Farkle";
+ Entry entry = factory.newEntry();
+ entry.setTitle("customer " + customerName);
+ entry.setUpdated(new Date());
+ entry.addAuthor("Apache Tuscany");
+ Content content = abdera.getFactory().newContent();
+ content.setContentType(Content.Type.TEXT);
+ content.setValue(customerName);
+ entry.setContentElement(content);
+
+ RequestOptions opts = new RequestOptions();
+ String contentType = "application/atom+xml; type=entry";
+ opts.setContentType(contentType);
+ IRI colUri = new IRI(providerURI).resolve("customer");
+ ClientResponse res = client.post(colUri.toString(), entry, opts);
+
+ // Feed request with predicates
+ opts = new RequestOptions();
+ contentType = "application/atom+xml";
+ opts.setContentType(contentType);
+ opts.setHeader("If-None-Match", eTag);
+
+ res = client.get(providerURI, opts);
+ Assert.assertNotNull(res);
+ try {
+ String thisETag = res.getHeader("ETag");
+ Assert.assertNotNull(thisETag);
+ Date thisLastModified = res.getLastModified();
+ Assert.assertNotNull(thisLastModified);
+
+ // Should return 200 - value since feed is changed
+ Assert.assertEquals(200, res.getStatus());
+ Assert.assertEquals(ResponseType.SUCCESS, res.getType());
+
+ // AtomTestCaseUtils.printResponseHeaders(
+ // "Feed modified if-none-match response headers:", " ", res );
+ // System.out.println("Feed response content:");
+ // AtomTestCaseUtils.prettyPrint(abdera, res.getDocument());
+ } finally {
+ res.release();
+ }
+ }
+
+ @Test
+ public void testModifiedGetIfMatch() throws Exception {
+ System.out.println(">>>ProviderFeedEntityTagsTest.testFeedModifiedGetIfMatch");
+ // Feed request with predicates
+ RequestOptions opts = new RequestOptions();
+ final String contentType = "application/atom+xml";
+ opts.setContentType(contentType);
+ opts.setHeader("If-Match", eTag);
+
+ ClientResponse res = client.get(providerURI, opts);
+ Assert.assertNotNull(res);
+ try {
+ // Should return 412 - Precondition failed since feed changed.
+ Assert.assertEquals(412, res.getStatus());
+ // AtomTestCaseUtils.printResponseHeaders( "Feed response headers:",
+ // " ", res );
+ // System.out.println("Feed response content:");
+ // AtomTestCaseUtils.prettyPrint(abdera, res.getDocument());
+ } finally {
+ res.release();
+ }
+ }
+
+ @Test
+ public void testModifiedGetIfUnModified() throws Exception {
+ System.out.println(">>>ProviderFeedEntityTagsTest.testFeedUnmodifiedGetIfUnModified");
+ // Feed request with predicates
+ RequestOptions opts = new RequestOptions();
+ final String contentType = "application/atom+xml";
+ opts.setContentType(contentType);
+ opts.setHeader("If-Unmodified-Since", dateFormat.format(new Date()));
+
+ ClientResponse res = client.get(providerURI, opts);
+ Assert.assertNotNull(res);
+ try {
+ // Should return 304 - Feed not provided since feed is modified
+ // since.
+ Assert.assertEquals(304, res.getStatus());
+ } finally {
+ res.release();
+ }
+ }
+
+ @Test
+ public void testModifiedGetIfModified() throws Exception {
+ System.out.println(">>>ProviderFeedEntityTagsTest.testFeedUnmodifiedGetIfModified");
+ // Feed request with predicates
+ RequestOptions opts = new RequestOptions();
+ final String contentType = "application/atom+xml";
+ opts.setContentType(contentType);
+ opts.setHeader("If-Modified-Since", dateFormat.format(lastModified));
+
+ ClientResponse res = client.get(providerURI, opts);
+ Assert.assertNotNull(res);
+ try {
+ // Should return 200 - Feed provided since feed is changed.
+ Assert.assertEquals(200, res.getStatus());
+ Assert.assertEquals(ResponseType.SUCCESS, res.getType());
+
+ String thisETag = res.getHeader("ETag");
+ Assert.assertNotNull(thisETag);
+ Date thisLastModified = res.getLastModified();
+ Assert.assertNotNull(thisLastModified);
+ } finally {
+ res.release();
+ }
+ }
+
+ public static void printFeed(String title, String indent, Feed feed) {
+ if (feed == null) {
+ System.out.println(title + " feed is null");
+ return;
+ }
+
+ System.out.println(title);
+ System.out.println(indent + "id=" + feed.getId());
+ System.out.println(indent + "title=" + feed.getTitle());
+ System.out.println(indent + "updated=" + feed.getUpdated());
+ System.out.println(indent + "author=" + feed.getAuthor());
+ Collection collection = feed.getCollection();
+ if (collection == null) {
+ System.out.println(indent + "collection=null");
+ } else {
+ System.out.println(indent + "collection=" + collection);
+ }
+ // System.out.println( indent + "collection size=" +
+ // feed.getCollection() );
+ // for (Collection collection : workspace.getCollections()) {
+ // if (collection.getTitle().equals("customers")) {
+ // String expected = uri + "customers";
+ // String actual = collection.getResolvedHref().toString();
+ // assertEquals(expected, actual);
+ // }
+ // }
+
+ }
}