diff options
Diffstat (limited to 'java/sca')
-rw-r--r-- | java/sca/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java | 1 | ||||
-rw-r--r-- | java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderEntryEntityTagsTestCase.java (renamed from java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderEntryEntityTagsTest.java) | 50 | ||||
-rw-r--r-- | java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTestCase.java (renamed from java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTest.java) | 94 | ||||
-rw-r--r-- | java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderServiceDocumentTestCase.java (renamed from java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderServiceDocumentTest.java) | 43 |
4 files changed, 116 insertions, 72 deletions
diff --git a/java/sca/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java b/java/sca/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java index f6d74d3047..c67d9450dd 100644 --- a/java/sca/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java +++ b/java/sca/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java @@ -47,6 +47,7 @@ import org.apache.abdera.i18n.iri.IRI; import org.apache.abdera.model.Category; import org.apache.abdera.model.Collection; import org.apache.abdera.model.Document; +import org.apache.abdera.model.Element; import org.apache.abdera.model.Feed; import org.apache.abdera.model.Link; import org.apache.abdera.model.Service; diff --git a/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderEntryEntityTagsTest.java b/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderEntryEntityTagsTestCase.java index fbdf9a05f7..703419f527 100644 --- a/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderEntryEntityTagsTest.java +++ b/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderEntryEntityTagsTestCase.java @@ -53,7 +53,7 @@ import org.apache.abdera.parser.Parser; * Uses the SCA provided Provider composite to act as a server. * Uses the Abdera provided Client to act as a client. */ -public class ProviderEntryEntityTagsTest { +public class ProviderEntryEntityTagsTestCase { public final static String providerURI = "http://localhost:8084/customer"; protected static SCADomain scaConsumerDomain; protected static SCADomain scaProviderDomain; @@ -67,7 +67,7 @@ public class ProviderEntryEntityTagsTest { @BeforeClass public static void init() throws Exception { - System.out.println(">>>ProviderEntryEntityTagsTest.init"); + System.out.println(">>>ProviderEntryEntityTagsTestCase.init"); scaProviderDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Provider.composite"); abdera = new Abdera(); client = new AbderaClient(abdera); @@ -76,7 +76,7 @@ public class ProviderEntryEntityTagsTest { @AfterClass public static void destroy() throws Exception { - System.out.println(">>>ProviderEntryEntityTagsTest.destroy"); + System.out.println(">>>ProviderEntryEntityTagsTestCase.destroy"); scaProviderDomain.close(); } @@ -200,7 +200,7 @@ public class ProviderEntryEntityTagsTest { opts.setContentType(contentType); opts.setHeader( "If-None-Match", eTag); - AtomTestCaseUtils.printRequestHeaders( "Put request headers", " ", opts ); + // AtomTestCaseUtils.printRequestHeaders( "Put request headers", " ", opts ); IRI colUri = new IRI(providerURI).resolve("customer"); // res = client.post(colUri.toString() + "?test=foo", entry, opts); id = eTag.substring( 1, eTag.length()-1); @@ -364,7 +364,7 @@ public class ProviderEntryEntityTagsTest { @Test public void testUpToDateUnModGet() throws Exception { - // 3) Conditional GET example (get with If-Unmod. entry is up to date) + // 3) Conditional GET example (get with If-Unmod. entry is not modified (< predicate date). // User client GET request // GET /edit/first-post.atom HTTP/1.1 // > If-Unmodified-Since: Sat, 29 Oct 2025 19:43:31 GMT @@ -382,19 +382,24 @@ public class ProviderEntryEntityTagsTest { ClientResponse res = client.get(colUri.toString() + "/" + id, opts); // Atom server response (item was up to date) - // > HTTP/1.1 304 Not Modified - // Date: Sat, 24 Feb 2007 13:17:11 GMT + // > HTTP/1.1 200 OK + // Date: Sat, 24 Feb 2007 13:17:11 GMT + // > ETag: "bb4f5e86e92ddb8549604a0df0763581" + // > Last-Modified: Mon, 28 Jul 2008 10:25:37 -0500 - // Assert response status code is 304 Not Modified. - // Assert.assertEquals(304, res.getStatus()); - // TODO Update when If-Unmodified-Since enabled. + // Assert response status code is 200 OK. + // Assert header Content-Type: application/atom+xml;type=entry + // Assert header Location: http://example.org/edit/first-post.atom + // Assert header Content-Location: http://example.org/edit/first-post.atom + // Assert header ETag: "e180ee84f0671b1" + // Assert header Last-Modified: Less than If-Unmod Assert.assertEquals(200, res.getStatus()); res.release(); } @Test public void testOutOfDateUnModGet() throws Exception { - // 4) Conditional GET example (get with If-Unmod. entry is not to date) + // 4) Conditional GET example (get with If-Unmod. entry is modified (> predicate date) // User client GET request // GET /edit/first-post.atom HTTP/1.1 // Host: example.org @@ -413,24 +418,11 @@ public class ProviderEntryEntityTagsTest { ClientResponse res = client.get(colUri.toString() + "/" + id, opts); // Atom server response (item was up to date) - // > HTTP/1.1 200 OK - // Date: Sat, 24 Feb 2007 13:17:11 GMT - // > ETag: "bb4f5e86e92ddb8549604a0df0763581" - // > Last-Modified: Mon, 28 Jul 2008 10:25:37 -0500 + // > HTTP/1.1 304 Not Modified + // Date: Sat, 24 Feb 2007 13:17:11 GMT - // Assert response status code is 200 OK. - // Assert header Content-Type: application/atom+xml;type=entry - // Assert header Location: http://example.org/edit/first-post.atom - // Assert header Content-Location: http://example.org/edit/first-post.atom - // Assert header ETag: "e180ee84f0671b1" - // Assert header Last-Modified: Less than If-Unmod - Assert.assertEquals(200, res.getStatus()); - Assert.assertEquals(contentType, res.getContentType().toString().trim()); - // Assert.assertNotNull( res.getLocation().toString() ); - // Assert.assertEquals( "", res.getContentLocation().toString() ); - Assert.assertNotNull( res.getHeader( "ETag" ) ); - lastModified = res.getLastModified(); - Assert.assertNotNull(lastModified); - res.release(); + // Assert response status code is 304 Not Modified. + Assert.assertEquals(304, res.getStatus()); + res.release(); } } diff --git a/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTest.java b/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTestCase.java index faa7d414f5..4915f7426e 100644 --- a/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTest.java +++ b/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTestCase.java @@ -18,6 +18,12 @@ */ package org.apache.tuscany.sca.binding.atom; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.StringReader; +import java.net.Socket; import java.text.SimpleDateFormat; import java.util.Date; @@ -53,7 +59,7 @@ import org.apache.abdera.parser.Parser; * 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 class ProviderFeedEntityTagsTestCase { public final static String providerURI = "http://localhost:8084/customer"; protected static SCADomain scaConsumerDomain; protected static SCADomain scaProviderDomain; @@ -67,7 +73,7 @@ public class ProviderFeedEntityTagsTest { @BeforeClass public static void init() throws Exception { - System.out.println(">>>ProviderFeedEntityTagsTest.init"); + System.out.println(">>>ProviderFeedEntityTagsTestCase.init"); scaProviderDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Provider.composite"); abdera = new Abdera(); client = new AbderaClient(abdera); @@ -76,7 +82,7 @@ public class ProviderFeedEntityTagsTest { @AfterClass public static void destroy() throws Exception { - System.out.println(">>>ProviderFeedEntityTagsTest.destroy"); + System.out.println(">>>ProviderFeedEntityTagsTestCase.destroy"); scaProviderDomain.close(); } @@ -88,12 +94,12 @@ public class ProviderFeedEntityTagsTest { @Test public void testFeedBasics() throws Exception { - System.out.println(">>>ProviderFeedEntityTagsTest.testFeedBasics"); + System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedBasics"); // Normal feed request ClientResponse res = client.get(providerURI); Assert.assertNotNull(res); try { - // Asser feed provided since no predicates + // Assert feed provided since no predicates Assert.assertEquals(200, res.getStatus()); Assert.assertEquals(ResponseType.SUCCESS, res.getType()); // AtomTestCaseUtils.printResponseHeaders( "Feed response headers:", " ", res ); @@ -101,15 +107,13 @@ public class ProviderFeedEntityTagsTest { // 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 ); + // Warning. AbderaClient.getEntityTag is very particular on tag pattern. + // Document<Feed> doc = res.getDocument(); + String body = read( res.getInputStream() ); // RFC 4287 requires non-null id, title, updated elements - Assert.assertNotNull( feed.getId() ); - Assert.assertNotNull( feed.getTitle() ); - Assert.assertNotNull( feed.getUpdated() ); + Assert.assertTrue( -1 != body.indexOf( "</id>" )); + Assert.assertTrue( -1 != body.indexOf( "</title>" )); + Assert.assertTrue( -1 != body.indexOf( "</updated>" )); eTag = res.getHeader("ETag"); Assert.assertNotNull( eTag ); @@ -122,7 +126,7 @@ public class ProviderFeedEntityTagsTest { @Test public void testUnmodifiedGetIfMatch() throws Exception { - System.out.println(">>>ProviderFeedEntityTagsTest.testFeedUnmodifiedGetIfMatch"); + System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedUnmodifiedGetIfMatch"); // Feed request with predicates RequestOptions opts = new RequestOptions(); final String contentType = "application/atom+xml"; @@ -150,7 +154,7 @@ public class ProviderFeedEntityTagsTest { @Test public void testUnmodifiedGetIfNoneMatch() throws Exception { - System.out.println(">>>ProviderFeedEntityTagsTest.testFeedUnmodifiedGetIfNoneMatch"); + System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedUnmodifiedGetIfNoneMatch"); // Feed request with predicates RequestOptions opts = new RequestOptions(); final String contentType = "application/atom+xml"; @@ -169,7 +173,7 @@ public class ProviderFeedEntityTagsTest { @Test public void testUnmodifiedGetIfUnModified() throws Exception { - System.out.println(">>>ProviderFeedEntityTagsTest.testFeedUnmodifiedGetIfUnModified"); + System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedUnmodifiedGetIfUnModified"); // Feed request with predicates RequestOptions opts = new RequestOptions(); final String contentType = "application/atom+xml"; @@ -188,7 +192,7 @@ public class ProviderFeedEntityTagsTest { @Test public void testUnmodifiedGetIfModified() throws Exception { - System.out.println(">>>ProviderFeedEntityTagsTest.testFeedUnmodifiedGetIfModified"); + System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedUnmodifiedGetIfModified"); // Feed request with predicates RequestOptions opts = new RequestOptions(); final String contentType = "application/atom+xml"; @@ -213,7 +217,7 @@ public class ProviderFeedEntityTagsTest { @Test public void testModifiedGetIfNoneMatch() throws Exception { - System.out.println(">>>ProviderFeedEntityTagsTest.testFeedModifiedGetIfNoneMatch"); + System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedModifiedGetIfNoneMatch"); // Post some new content to the feed. Factory factory = abdera.getFactory(); String customerName = "Fred Farkle"; @@ -241,16 +245,9 @@ public class ProviderFeedEntityTagsTest { 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 ); + // Should return 304 - Feed not provided since it matches ETag. + Assert.assertEquals(304, res.getStatus()); + // AtomTestCaseUtils.printResponseHeaders( "Feed response headers:", " ", res ); // System.out.println("Feed response content:"); // AtomTestCaseUtils.prettyPrint(abdera, res.getDocument()); } finally { @@ -260,7 +257,7 @@ public class ProviderFeedEntityTagsTest { @Test public void testModifiedGetIfMatch() throws Exception { - System.out.println(">>>ProviderFeedEntityTagsTest.testFeedModifiedGetIfMatch"); + System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedModifiedGetIfMatch"); // Feed request with predicates RequestOptions opts = new RequestOptions(); final String contentType = "application/atom+xml"; @@ -270,9 +267,16 @@ public class ProviderFeedEntityTagsTest { 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 ); + 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 { @@ -282,7 +286,7 @@ public class ProviderFeedEntityTagsTest { @Test public void testModifiedGetIfUnModified() throws Exception { - System.out.println(">>>ProviderFeedEntityTagsTest.testFeedUnmodifiedGetIfUnModified"); + System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedUnmodifiedGetIfUnModified"); // Feed request with predicates RequestOptions opts = new RequestOptions(); final String contentType = "application/atom+xml"; @@ -301,7 +305,7 @@ public class ProviderFeedEntityTagsTest { @Test public void testModifiedGetIfModified() throws Exception { - System.out.println(">>>ProviderFeedEntityTagsTest.testFeedUnmodifiedGetIfModified"); + System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedUnmodifiedGetIfModified"); // Feed request with predicates RequestOptions opts = new RequestOptions(); final String contentType = "application/atom+xml"; @@ -353,4 +357,26 @@ public class ProviderFeedEntityTagsTest { } + /** + * Read response ream from the given socket. + * @param socket + * @return + * @throws IOException + */ + private static String read(InputStream inputStream) throws IOException { + BufferedReader reader = null; + try { + reader = new BufferedReader(new InputStreamReader( inputStream )); + StringBuffer sb = new StringBuffer(); + String str; + while ((str = reader.readLine()) != null) { + sb.append(str); + } + return sb.toString(); + } finally { + if (reader != null) { + reader.close(); + } + } + } } diff --git a/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderServiceDocumentTest.java b/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderServiceDocumentTestCase.java index 816be8b6e5..96ea508210 100644 --- a/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderServiceDocumentTest.java +++ b/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderServiceDocumentTestCase.java @@ -18,6 +18,10 @@ */ package org.apache.tuscany.sca.binding.atom; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; @@ -49,7 +53,7 @@ import org.apache.abdera.parser.Parser; * Uses the SCA provided Provider composite to act as a server. * Uses the Abdera provided Client to act as a client. */ -public class ProviderServiceDocumentTest { +public class ProviderServiceDocumentTestCase { public final static String providerURI = "http://localhost:8084/customer"; protected static SCADomain scaProviderDomain; protected static SCADomain scaConsumerDomain; @@ -93,15 +97,13 @@ public class ProviderServiceDocumentTest { // 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 ); + // Warning. AbderaClient.getEntityTag is very particular on tag pattern. + // Document<Feed> doc = res.getDocument(); + String body = read( res.getInputStream() ); // RFC 4287 requires non-null id, title, updated elements - Assert.assertNotNull( feed.getId() ); - Assert.assertNotNull( feed.getTitle() ); - Assert.assertNotNull( feed.getUpdated() ); + Assert.assertTrue( -1 != body.indexOf( "</id>" )); + Assert.assertTrue( -1 != body.indexOf( "</title>" )); + Assert.assertTrue( -1 != body.indexOf( "</updated>" )); } finally { res.release(); } @@ -181,4 +183,27 @@ public class ProviderServiceDocumentTest { return entry; } + + /** + * Read response ream from the given socket. + * @param socket + * @return + * @throws IOException + */ + private static String read(InputStream inputStream) throws IOException { + BufferedReader reader = null; + try { + reader = new BufferedReader(new InputStreamReader( inputStream )); + StringBuffer sb = new StringBuffer(); + String str; + while ((str = reader.readLine()) != null) { + sb.append(str); + } + return sb.toString(); + } finally { + if (reader != null) { + reader.close(); + } + } + } } |