diff options
23 files changed, 1347 insertions, 1285 deletions
diff --git a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AbstractProviderConsumerTestCase.java b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AbstractProviderConsumerTestCase.java index d60cc5bed2..19c100483c 100644 --- a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AbstractProviderConsumerTestCase.java +++ b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AbstractProviderConsumerTestCase.java @@ -24,16 +24,20 @@ import org.apache.tuscany.sca.node.ContributionLocationHelper; import org.apache.tuscany.sca.node.Node; import org.apache.tuscany.sca.node.NodeFactory; +/** + * + * @version $Rev$ $Date$ + */ public abstract class AbstractProviderConsumerTestCase { protected static Node scaProviderNode; protected static Node scaConsumerNode; - + protected static void initTestEnvironment(Class<?> testClazz) throws Exception { String contribution = ContributionLocationHelper.getContributionLocation(testClazz); - + scaProviderNode = NodeFactory.newInstance().createNode("org/apache/tuscany/sca/binding/atom/Provider.composite", new Contribution("provider", contribution)); scaProviderNode.start(); - + scaConsumerNode = NodeFactory.newInstance().createNode("org/apache/tuscany/sca/binding/atom/Consumer.composite", new Contribution("consumer", contribution)); scaConsumerNode.start(); } diff --git a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomDeleteTestCase.java b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomDeleteTestCase.java index 510a6958db..da3c8b7594 100644 --- a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomDeleteTestCase.java +++ b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomDeleteTestCase.java @@ -30,15 +30,19 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; +/** + * + * @version $Rev$ $Date$ + */ public class AtomDeleteTestCase extends AbstractProviderConsumerTestCase { - + protected static CustomerClient testService; protected static Abdera abdera; @BeforeClass public static void init() throws Exception { try { - //System.out.println(">>>AtomDeleteTestCase.init entry"); + // System.out.println(">>>AtomDeleteTestCase.init entry"); initTestEnvironment(AtomDeleteTestCase.class); @@ -53,7 +57,7 @@ public class AtomDeleteTestCase extends AbstractProviderConsumerTestCase { @AfterClass public static void destroy() throws Exception { // System.out.println(">>>AtomDeleteTestCase.destroy entry"); - + destroyTestEnvironment(); } @@ -71,12 +75,12 @@ public class AtomDeleteTestCase extends AbstractProviderConsumerTestCase { Assert.assertNotNull(resourceCollection); Entry postEntry = postEntry("Sponge Bob"); - //System.out.println(">>> post entry= " + postEntry.getTitle()); + // System.out.println(">>> post entry= " + postEntry.getTitle()); Entry newEntry = resourceCollection.post(postEntry); - //System.out.println("<<< Entry posted for " + newEntry.getTitle()); + // System.out.println("<<< Entry posted for " + newEntry.getTitle()); - //System.out.println(">>> get id=" + newEntry.getId()); + // System.out.println(">>> get id=" + newEntry.getId()); resourceCollection.delete(newEntry.getId().toString()); diff --git a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomFeedNonCollectionTest.java b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomFeedNonCollectionTest.java index 608ce4a697..da7683d84a 100644 --- a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomFeedNonCollectionTest.java +++ b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomFeedNonCollectionTest.java @@ -42,6 +42,8 @@ import org.junit.Test; /** * Test cases for using an Atom feed that does not implement * the Collections interface but does have a getAll() method. + * + * @version $Rev$ $Date$ */ public class AtomFeedNonCollectionTest { /** @@ -68,7 +70,7 @@ public class AtomFeedNonCollectionTest { * The number of test feed entries. */ private static final int FEED_ENTRY_COUNT = FEED_ENTRY_TITLES.length; - + protected static Node scaProviderNode; protected static Node scaConsumerNode; @@ -78,12 +80,12 @@ public class AtomFeedNonCollectionTest { public static void init() throws Exception { try { //System.out.println(">>>AtomFeedNonCollectionTest.init entry"); - + String contribution = ContributionLocationHelper.getContributionLocation(AtomFeedNonCollectionTest.class); - + scaProviderNode = NodeFactory.newInstance().createNode("org/apache/tuscany/sca/binding/atom/ProviderNonCollection.composite", new Contribution("provider", contribution)); scaProviderNode.start(); - + scaConsumerNode = NodeFactory.newInstance().createNode("org/apache/tuscany/sca/binding/atom/Consumer.composite", new Contribution("consumer", contribution)); scaConsumerNode.start(); diff --git a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomGetTestCase.java b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomGetTestCase.java index 0e86f0658e..7f74ef019d 100644 --- a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomGetTestCase.java +++ b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomGetTestCase.java @@ -28,8 +28,12 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; +/** + * + * @version $Rev$ $Date$ + */ public class AtomGetTestCase extends AbstractProviderConsumerTestCase { - + protected static CustomerClient testService; protected static Abdera abdera; @@ -37,7 +41,7 @@ public class AtomGetTestCase extends AbstractProviderConsumerTestCase { public static void init() throws Exception { try { //System.out.println(">>>AtomGetTestCase.init entry"); - + initTestEnvironment(AtomFeedNonCollectionTest.class); testService = scaConsumerNode.getService(CustomerClient.class, "CustomerClient"); diff --git a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPostTestCase.java b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPostTestCase.java index 152f2433e2..50a684beba 100644 --- a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPostTestCase.java +++ b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPostTestCase.java @@ -28,6 +28,10 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; +/** + * + * @version $Rev$ $Date$ + */ public class AtomPostTestCase extends AbstractProviderConsumerTestCase { protected static CustomerClient testService; protected static Abdera abdera; @@ -49,7 +53,7 @@ public class AtomPostTestCase extends AbstractProviderConsumerTestCase { @AfterClass public static void destroy() throws Exception { //System.out.println(">>>AtomPostTestCase.destroy entry"); - + destroyTestEnvironment(); } diff --git a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPutTestCase.java b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPutTestCase.java index 24dae0c6ba..4e09eea032 100644 --- a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPutTestCase.java +++ b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPutTestCase.java @@ -30,6 +30,10 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; +/** + * + * @version $Rev$ $Date$ + */ public class AtomPutTestCase extends AbstractProviderConsumerTestCase { protected static CustomerClient testService; @@ -41,7 +45,7 @@ public class AtomPutTestCase extends AbstractProviderConsumerTestCase { //System.out.println(">>>AtomPutTestCase.init entry"); initTestEnvironment(AtomPutTestCase.class); - + testService = scaConsumerNode.getService(CustomerClient.class, "CustomerClient"); abdera = new Abdera(); } catch(Exception e) { @@ -52,7 +56,7 @@ public class AtomPutTestCase extends AbstractProviderConsumerTestCase { @AfterClass public static void destroy() throws Exception { // System.out.println(">>>AtomPutTestCase.destroy entry"); - + destroyTestEnvironment(); } diff --git a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/Consumer.java b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/Consumer.java index fd5b3a16e1..e93c1aeea6 100644 --- a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/Consumer.java +++ b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/Consumer.java @@ -24,6 +24,10 @@ import org.apache.tuscany.sca.node.ContributionLocationHelper; import org.apache.tuscany.sca.node.Node; import org.apache.tuscany.sca.node.NodeFactory; +/** + * + * @version $Rev$ $Date$ + */ public class Consumer { public static void main(String[] args) throws Exception { diff --git a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ConsumerProviderAtomTestCase.java b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ConsumerProviderAtomTestCase.java index 0759555dc1..07909388e1 100644 --- a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ConsumerProviderAtomTestCase.java +++ b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ConsumerProviderAtomTestCase.java @@ -33,125 +33,127 @@ import org.junit.Test; /** * Test case for the given package. + * + * @version $Rev$ $Date$ */ public class ConsumerProviderAtomTestCase extends AbstractProviderConsumerTestCase { - protected static CustomerClient testService; - protected static Abdera abdera; - - @BeforeClass - public static void init() throws Exception { - try { - //System.out.println(">>>AtomBindingIntegratedTestCase.init entry"); - - initTestEnvironment(ConsumerProviderAtomTestCase.class); - - testService = scaConsumerNode.getService(CustomerClient.class,"CustomerClient"); - abdera = new Abdera(); - } catch(Exception e) { - e.printStackTrace(); - } - } - - @AfterClass - public static void destroy() throws Exception { - //System.out.println(">>>AtomBindingIntegratedTestCase.destroy entry"); - - destroyTestEnvironment(); - } - - @Test - public void testPrelim() throws Exception { - Assert.assertNotNull(scaProviderNode); - Assert.assertNotNull(scaConsumerNode); - Assert.assertNotNull(testService); - Assert.assertNotNull(abdera); - } - - @Test - public void testEntry() throws Exception { - // System.out.println( getClass().getName() + ".testEntry entry" ); - Entry entry = abdera.newEntry(); - Assert.assertNotNull(entry); - - String testTitle = "Sponge Bob"; - entry.setTitle(testTitle); - Assert.assertEquals(testTitle, entry.getTitle()); - - String testContent = "This is the content"; - entry.setContent(testContent); - Assert.assertEquals(testContent, entry.getContent()); - - Date now = new Date(); - entry.setEdited(now); - Assert.assertEquals(now, entry.getEdited()); - - Date later = new Date(); - entry.setPublished(later); - Assert.assertEquals(later, entry.getPublished()); - - String testSummary = "This is the summary"; - entry.setSummary(testSummary); - Assert.assertEquals(testSummary, entry.getSummary()); - } - - @Test - public void testCustomerCollection() throws Exception { - System.out.println(getClass().getName() + ".testCustomerCollection entry"); - Collection resourceCollection = testService.getCustomerCollection(); - Assert.assertNotNull(resourceCollection); - - Entry newEntry = newEntry("Sponge Bob"); - //System.out.println(">>> post entry=" + newEntry.getTitle()); - newEntry = resourceCollection.post(newEntry); - //System.out.println("<<< post id=" + newEntry.getId() + " entry=" + newEntry.getTitle()); - - newEntry = newEntry("Jane Bond"); - //System.out.println(">>> post entry=" + newEntry.getTitle()); - newEntry = resourceCollection.post(newEntry); - //System.out.println("<<< post id=" + newEntry.getId() + " entry=" + newEntry.getTitle()); - - //System.out.println(">>> get id=" + newEntry.getId()); - Entry entry = resourceCollection.get(newEntry.getId().toString()); - //System.out.println("<<< get id=" + entry.getId() + " entry=" + entry.getTitle()); - - //System.out.println(">>> put id=" + newEntry.getId() + " entry=" + entry.getTitle()); - resourceCollection.put(entry.getId().toString(), updateEntry(entry, "James Bond")); - //System.out.println("<<< put id=" + entry.getId() + " entry=" + entry.getTitle()); - - //System.out.println(">>> delete id=" + entry.getId()); - resourceCollection.delete(entry.getId().toString()); - //System.out.println("<<< delete id=" + entry.getId()); - - //System.out.println(">>> get collection"); - Feed feed = resourceCollection.getFeed(); - //System.out.println("<<< get collection"); - for (Object o : feed.getEntries()) { - Entry e = (Entry)o; - //System.out.println("id = " + e.getId() + " entry = " + e.getTitle()); - } - } - - private Entry newEntry(String value) { - Entry entry = abdera.newEntry(); - entry.setTitle("customer " + value); - - Content content = abdera.getFactory().newContent(); - content.setContentType(Content.Type.TEXT); - content.setValue(value); - entry.setContentElement(content); - - return entry; - } - - private Entry updateEntry(Entry entry, String value) { - entry.setTitle("customer " + value); - - Content content = abdera.getFactory().newContent(); - content.setContentType(Content.Type.TEXT); - content.setValue(value); - entry.setContentElement(content); - - return entry; - } + protected static CustomerClient testService; + protected static Abdera abdera; + + @BeforeClass + public static void init() throws Exception { + try { + //System.out.println(">>>AtomBindingIntegratedTestCase.init entry"); + + initTestEnvironment(ConsumerProviderAtomTestCase.class); + + testService = scaConsumerNode.getService(CustomerClient.class,"CustomerClient"); + abdera = new Abdera(); + } catch(Exception e) { + e.printStackTrace(); + } + } + + @AfterClass + public static void destroy() throws Exception { + //System.out.println(">>>AtomBindingIntegratedTestCase.destroy entry"); + + destroyTestEnvironment(); + } + + @Test + public void testPrelim() throws Exception { + Assert.assertNotNull(scaProviderNode); + Assert.assertNotNull(scaConsumerNode); + Assert.assertNotNull(testService); + Assert.assertNotNull(abdera); + } + + @Test + public void testEntry() throws Exception { + // System.out.println( getClass().getName() + ".testEntry entry" ); + Entry entry = abdera.newEntry(); + Assert.assertNotNull(entry); + + String testTitle = "Sponge Bob"; + entry.setTitle(testTitle); + Assert.assertEquals(testTitle, entry.getTitle()); + + String testContent = "This is the content"; + entry.setContent(testContent); + Assert.assertEquals(testContent, entry.getContent()); + + Date now = new Date(); + entry.setEdited(now); + Assert.assertEquals(now, entry.getEdited()); + + Date later = new Date(); + entry.setPublished(later); + Assert.assertEquals(later, entry.getPublished()); + + String testSummary = "This is the summary"; + entry.setSummary(testSummary); + Assert.assertEquals(testSummary, entry.getSummary()); + } + + @Test + public void testCustomerCollection() throws Exception { + System.out.println(getClass().getName() + ".testCustomerCollection entry"); + Collection resourceCollection = testService.getCustomerCollection(); + Assert.assertNotNull(resourceCollection); + + Entry newEntry = newEntry("Sponge Bob"); + //System.out.println(">>> post entry=" + newEntry.getTitle()); + newEntry = resourceCollection.post(newEntry); + //System.out.println("<<< post id=" + newEntry.getId() + " entry=" + newEntry.getTitle()); + + newEntry = newEntry("Jane Bond"); + //System.out.println(">>> post entry=" + newEntry.getTitle()); + newEntry = resourceCollection.post(newEntry); + //System.out.println("<<< post id=" + newEntry.getId() + " entry=" + newEntry.getTitle()); + + //System.out.println(">>> get id=" + newEntry.getId()); + Entry entry = resourceCollection.get(newEntry.getId().toString()); + //System.out.println("<<< get id=" + entry.getId() + " entry=" + entry.getTitle()); + + //System.out.println(">>> put id=" + newEntry.getId() + " entry=" + entry.getTitle()); + resourceCollection.put(entry.getId().toString(), updateEntry(entry, "James Bond")); + //System.out.println("<<< put id=" + entry.getId() + " entry=" + entry.getTitle()); + + //System.out.println(">>> delete id=" + entry.getId()); + resourceCollection.delete(entry.getId().toString()); + //System.out.println("<<< delete id=" + entry.getId()); + + //System.out.println(">>> get collection"); + Feed feed = resourceCollection.getFeed(); + //System.out.println("<<< get collection"); + for (Object o : feed.getEntries()) { + Entry e = (Entry)o; + //System.out.println("id = " + e.getId() + " entry = " + e.getTitle()); + } + } + + private Entry newEntry(String value) { + Entry entry = abdera.newEntry(); + entry.setTitle("customer " + value); + + Content content = abdera.getFactory().newContent(); + content.setContentType(Content.Type.TEXT); + content.setValue(value); + entry.setContentElement(content); + + return entry; + } + + private Entry updateEntry(Entry entry, String value) { + entry.setTitle("customer " + value); + + Content content = abdera.getFactory().newContent(); + content.setContentType(Content.Type.TEXT); + content.setValue(value); + entry.setContentElement(content); + + return entry; + } }
\ No newline at end of file diff --git a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ContentNegotiationTest.java b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ContentNegotiationTest.java index d4d925ee01..b707c71d2b 100644 --- a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ContentNegotiationTest.java +++ b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ContentNegotiationTest.java @@ -49,209 +49,211 @@ import org.junit.Test; * Tests use of content negotiation for Atom binding in Tuscany.
* Uses the SCA provided Provider composite to act as a server.
* Uses the Abdera provided Client to act as a client.
+ *
+ * @version $Rev$ $Date$
*/
public class ContentNegotiationTest {
public final static String providerURI = "http://localhost:8084/customer";
-
+
protected static Node scaProviderNode;
-
+
protected static CustomerClient testService;
protected static Abdera abdera;
protected static AbderaClient client;
protected static Parser abderaParser;
protected static String lastId;
- @BeforeClass
- public static void init() throws Exception {
- try {
- //System.out.println(">>>ContentNegotiationTest.init");
- String contribution = ContributionLocationHelper.getContributionLocation(ContentNegotiationTest.class);
-
- scaProviderNode = NodeFactory.newInstance().createNode("org/apache/tuscany/sca/binding/atom/Provider.composite", new Contribution("provider", contribution));
- scaProviderNode.start();
-
- abdera = new Abdera();
- client = new AbderaClient(abdera);
- abderaParser = Abdera.getNewParser();
- } catch(Exception e) {
- e.printStackTrace();
- }
- }
+ @BeforeClass
+ public static void init() throws Exception {
+ try {
+ //System.out.println(">>>ContentNegotiationTest.init");
+ String contribution = ContributionLocationHelper.getContributionLocation(ContentNegotiationTest.class);
+
+ scaProviderNode = NodeFactory.newInstance().createNode("org/apache/tuscany/sca/binding/atom/Provider.composite", new Contribution("provider", contribution));
+ scaProviderNode.start();
+
+ abdera = new Abdera();
+ client = new AbderaClient(abdera);
+ abderaParser = Abdera.getNewParser();
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+ }
- @AfterClass
- public static void destroy() throws Exception {
- //System.out.println(">>>ContentNegotiationTest.destroy");
- if (scaProviderNode != null) {
- scaProviderNode.stop();
- scaProviderNode.destroy();
- }
- }
+ @AfterClass
+ public static void destroy() throws Exception {
+ //System.out.println(">>>ContentNegotiationTest.destroy");
+ if (scaProviderNode != null) {
+ scaProviderNode.stop();
+ scaProviderNode.destroy();
+ }
+ }
- @Test
- public void testPrelim() throws Exception {
- Assert.assertNotNull(scaProviderNode);
- Assert.assertNotNull( client );
- }
-
@Test
- public void testPost() throws Exception {
- //System.out.println(">>>ContentNegotiationTest.testPost");
- // Testing of entry creation
- Factory factory = abdera.getFactory();
- String customerName = "Fred Farkle";
- Entry entry = factory.newEntry();
- entry.setTitle("customer " + customerName);
- entry.setUpdated(new Date());
- entry.addAuthor("Apache Tuscany");
- // ID created by collection.
- Content content = abdera.getFactory().newContent();
- content.setContentType(Content.Type.TEXT);
- content.setValue(customerName);
- entry.setContentElement(content);
+ public void testPrelim() throws Exception {
+ Assert.assertNotNull(scaProviderNode);
+ Assert.assertNotNull( client );
+ }
+
+ @Test
+ public void testPost() throws Exception {
+ //System.out.println(">>>ContentNegotiationTest.testPost");
+ // Testing of entry creation
+ Factory factory = abdera.getFactory();
+ String customerName = "Fred Farkle";
+ Entry entry = factory.newEntry();
+ entry.setTitle("customer " + customerName);
+ entry.setUpdated(new Date());
+ entry.addAuthor("Apache Tuscany");
+ // ID created by collection.
+ Content content = abdera.getFactory().newContent();
+ content.setContentType(Content.Type.TEXT);
+ content.setValue(customerName);
+ entry.setContentElement(content);
+
+ RequestOptions opts = new RequestOptions();
+ final String contentType = "application/atom+xml; type=entry";
+ opts.setContentType(contentType);
+ // AtomTestCaseUtils.printRequestHeaders( "Post request headers", " ", opts );
+ IRI colUri = new IRI(providerURI).resolve("customer");
+ // res = client.post(colUri.toString() + "?test=foo", entry, opts);
+ ClientResponse res = client.post(colUri.toString(), entry, opts);
+
+ // Assert response status code is 201-OK.
+ // Assert response header Content-Type: application/atom+xml; charset=UTF-8
+ Assert.assertEquals(201, res.getStatus());
+ String returnedContentType = res.getContentType().toString().trim();
+ Assert.assertEquals(contentType, returnedContentType );
- RequestOptions opts = new RequestOptions();
- final String contentType = "application/atom+xml; type=entry";
- opts.setContentType(contentType);
- // AtomTestCaseUtils.printRequestHeaders( "Post request headers", " ", opts );
- IRI colUri = new IRI(providerURI).resolve("customer");
- // res = client.post(colUri.toString() + "?test=foo", entry, opts);
- ClientResponse res = client.post(colUri.toString(), entry, opts);
-
- // Assert response status code is 201-OK.
- // Assert response header Content-Type: application/atom+xml; charset=UTF-8
- Assert.assertEquals(201, res.getStatus());
- String returnedContentType = res.getContentType().toString().trim();
- Assert.assertEquals(contentType, returnedContentType );
+ String eTag = res.getHeader( "ETag" );
+ if ( eTag != null)
+ lastId = eTag.substring( 1, eTag.length()-1);
- String eTag = res.getHeader( "ETag" );
- if ( eTag != null)
- lastId = eTag.substring( 1, eTag.length()-1);
-
- // AtomTestCaseUtils.printResponseHeaders( "Entry post response headers:", " ", res );
- // System.out.println("Entry post response content:");
- // AtomTestCaseUtils.prettyPrint(abdera, res.getDocument());
- }
+ // AtomTestCaseUtils.printResponseHeaders( "Entry post response headers:", " ", res );
+ // System.out.println("Entry post response content:");
+ // AtomTestCaseUtils.prettyPrint(abdera, res.getDocument());
+ }
- @Test
- public void testXMLEntryGet() throws Exception {
- //System.out.println(">>>ContentNegotiationTest.testXMLEntryGet");
- RequestOptions opts = new RequestOptions();
- opts.setHeader( "Accept", "application/atom+xml" );
-
- IRI colUri = new IRI(providerURI).resolve("customer");
- ClientResponse res = client.get(colUri.toString() + "/" + lastId, opts);
- Assert.assertEquals(200, res.getStatus());
- String returnedContentType = res.getContentType().toString().trim();
- // Assert.assertEquals(contentType, returnedContentType );
- res.release();
- }
+ @Test
+ public void testXMLEntryGet() throws Exception {
+ //System.out.println(">>>ContentNegotiationTest.testXMLEntryGet");
+ RequestOptions opts = new RequestOptions();
+ opts.setHeader( "Accept", "application/atom+xml" );
+
+ IRI colUri = new IRI(providerURI).resolve("customer");
+ ClientResponse res = client.get(colUri.toString() + "/" + lastId, opts);
+ Assert.assertEquals(200, res.getStatus());
+ String returnedContentType = res.getContentType().toString().trim();
+ // Assert.assertEquals(contentType, returnedContentType );
+ res.release();
+ }
- @Test
- public void testJSONEntryGet() throws Exception {
- //System.out.println(">>>ContentNegotiationTest.testJSONEntryGet");
- RequestOptions opts = new RequestOptions();
- opts.setHeader( "Accept", "application/json" );
-
- IRI colUri = new IRI(providerURI).resolve("customer");
- ClientResponse res = client.get(colUri.toString() + "/" + lastId, opts);
- try {
- Assert.assertEquals(200, res.getStatus());
- // Abdera 0.4 throws exception on getContentType with application/json.
- // System.out.println( "ContentNegotiationTest.testJSONEntryGet contentType=" + res.getContentType());
- String contentType = res.getHeader( "Content-Type");
- Assert.assertTrue( -1 < contentType.indexOf( "application/json" ));
- // Following is a poor man's JSONObject test to avoid dependency on JSON libs.
- // JSONObject jsonResp = new JSONObject(res.);
- // Assert.assertEquals(12345, jsonResp.getInt("result"));
- String responseBody = readResponse( res.getReader() );
- Assert.assertTrue( responseBody.startsWith( "{") );
- Assert.assertTrue( responseBody.endsWith( "}") );
- Assert.assertTrue( -1 < responseBody.indexOf( "\"id\"" ));
- Assert.assertTrue( -1 < responseBody.indexOf( "\"title\"" ));
- Assert.assertTrue( -1 < responseBody.indexOf( "\"updated\"" ));
- // AtomTestCaseUtils.printResponseHeaders( "JSON Entry response headers:", " ", res );
- // System.out.println( "ContentNegotiationTest.testJSONEntryGet JSON entry body=" + responseBody );
- } finally {
- res.release();
- }
- }
+ @Test
+ public void testJSONEntryGet() throws Exception {
+ //System.out.println(">>>ContentNegotiationTest.testJSONEntryGet");
+ RequestOptions opts = new RequestOptions();
+ opts.setHeader( "Accept", "application/json" );
- @Test
+ IRI colUri = new IRI(providerURI).resolve("customer");
+ ClientResponse res = client.get(colUri.toString() + "/" + lastId, opts);
+ try {
+ Assert.assertEquals(200, res.getStatus());
+ // Abdera 0.4 throws exception on getContentType with application/json.
+ // System.out.println( "ContentNegotiationTest.testJSONEntryGet contentType=" + res.getContentType());
+ String contentType = res.getHeader( "Content-Type");
+ Assert.assertTrue( -1 < contentType.indexOf( "application/json" ));
+ // Following is a poor man's JSONObject test to avoid dependency on JSON libs.
+ // JSONObject jsonResp = new JSONObject(res.);
+ // Assert.assertEquals(12345, jsonResp.getInt("result"));
+ String responseBody = readResponse( res.getReader() );
+ Assert.assertTrue( responseBody.startsWith( "{") );
+ Assert.assertTrue( responseBody.endsWith( "}") );
+ Assert.assertTrue( -1 < responseBody.indexOf( "\"id\"" ));
+ Assert.assertTrue( -1 < responseBody.indexOf( "\"title\"" ));
+ Assert.assertTrue( -1 < responseBody.indexOf( "\"updated\"" ));
+ // AtomTestCaseUtils.printResponseHeaders( "JSON Entry response headers:", " ", res );
+ // System.out.println( "ContentNegotiationTest.testJSONEntryGet JSON entry body=" + responseBody );
+ } finally {
+ res.release();
+ }
+ }
+
+ @Test
public void testXMLFeedGet() throws Exception {
- //System.out.println(">>>ContentNegotiationTest.testXMLFeedGet");
- RequestOptions opts = new RequestOptions();
- opts.setHeader( "Accept", "application/atom+xml" );
-
- // Atom feed request
- ClientResponse res = client.get(providerURI, opts);
- 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());
+ //System.out.println(">>>ContentNegotiationTest.testXMLFeedGet");
+ RequestOptions opts = new RequestOptions();
+ opts.setHeader( "Accept", "application/atom+xml" );
- // Perform other tests on feed.
- Document<Feed> doc = res.getDocument();
- Assert.assertNotNull( doc );
- Feed feed = doc.getRoot();
- Assert.assertNotNull( feed );
- // RFC 4287 requires non-null id, title, updated elements
- Assert.assertNotNull( feed.getId() );
- Assert.assertNotNull( feed.getTitle() );
- Assert.assertNotNull( feed.getUpdated() );
- // AtomTestCaseUtils.printFeed( "Feed values", " ", feed );
- } finally {
- res.release();
- }
- }
+ // Atom feed request
+ ClientResponse res = client.get(providerURI, opts);
+ 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());
- @Test
+ // Perform other tests on feed.
+ Document<Feed> doc = res.getDocument();
+ Assert.assertNotNull( doc );
+ Feed feed = doc.getRoot();
+ Assert.assertNotNull( feed );
+ // RFC 4287 requires non-null id, title, updated elements
+ Assert.assertNotNull( feed.getId() );
+ Assert.assertNotNull( feed.getTitle() );
+ Assert.assertNotNull( feed.getUpdated() );
+ // AtomTestCaseUtils.printFeed( "Feed values", " ", feed );
+ } finally {
+ res.release();
+ }
+ }
+
+ @Test
public void testJSONFeedGet() throws Exception {
- //System.out.println(">>>ContentNegotiationTest.testJSONFeedGet");
- RequestOptions opts = new RequestOptions();
- opts.setHeader( "Accept", "application/json" );
-
- // JSON feed request
- ClientResponse res = client.get(providerURI, opts);
- Assert.assertNotNull(res);
- try {
- // Assert feed provided since no predicates
- Assert.assertEquals(200, res.getStatus());
- // Abdera 0.4 throws exception on getContentType with application/json.
- // System.out.println( "ContentNegotiationTest.testJSONEntryGet contentType=" + res.getContentType());
- String contentType = res.getHeader( "Content-Type");
- Assert.assertTrue( -1 < contentType.indexOf( "application/json" ));
- // Following is a poor man's JSONObject test to avoid dependency on JSON libs.
- // JSONObject jsonResp = new JSONObject(res.);
- // Assert.assertEquals(12345, jsonResp.getInt("result"));
- String responseBody = readResponse( res.getReader() );
- Assert.assertTrue( responseBody.startsWith( "{") );
- Assert.assertTrue( responseBody.endsWith( "}") );
- Assert.assertTrue( -1 < responseBody.indexOf( "\"id\"" ));
- Assert.assertTrue( -1 < responseBody.indexOf( "\"title\"" ));
- Assert.assertTrue( -1 < responseBody.indexOf( "\"updated\"" ));
- Assert.assertTrue( -1 < responseBody.indexOf( "\"entries\"" ));
- // AtomTestCaseUtils.printResponseHeaders( "JSON Entry response headers:", " ", res );
- // System.out.println( "ContentNegotiationTest.testJSONEntryGet JSON entry body=" + responseBody );
- } finally {
- res.release();
- }
- }
-
- protected String readResponse( Reader responseReader ) {
- if ( responseReader == null ) return "";
- StringBuffer sb = new StringBuffer(1024);
- try {
- int charValue = 0;
- while ((charValue = responseReader.read()) != -1) {
- //result = result + (char) charValue;
- sb.append((char)charValue);
- }
- } catch ( IOException e ) {
- }
- return sb.toString();
- }
+ //System.out.println(">>>ContentNegotiationTest.testJSONFeedGet");
+ RequestOptions opts = new RequestOptions();
+ opts.setHeader( "Accept", "application/json" );
+
+ // JSON feed request
+ ClientResponse res = client.get(providerURI, opts);
+ Assert.assertNotNull(res);
+ try {
+ // Assert feed provided since no predicates
+ Assert.assertEquals(200, res.getStatus());
+ // Abdera 0.4 throws exception on getContentType with application/json.
+ // System.out.println( "ContentNegotiationTest.testJSONEntryGet contentType=" + res.getContentType());
+ String contentType = res.getHeader( "Content-Type");
+ Assert.assertTrue( -1 < contentType.indexOf( "application/json" ));
+ // Following is a poor man's JSONObject test to avoid dependency on JSON libs.
+ // JSONObject jsonResp = new JSONObject(res.);
+ // Assert.assertEquals(12345, jsonResp.getInt("result"));
+ String responseBody = readResponse( res.getReader() );
+ Assert.assertTrue( responseBody.startsWith( "{") );
+ Assert.assertTrue( responseBody.endsWith( "}") );
+ Assert.assertTrue( -1 < responseBody.indexOf( "\"id\"" ));
+ Assert.assertTrue( -1 < responseBody.indexOf( "\"title\"" ));
+ Assert.assertTrue( -1 < responseBody.indexOf( "\"updated\"" ));
+ Assert.assertTrue( -1 < responseBody.indexOf( "\"entries\"" ));
+ // AtomTestCaseUtils.printResponseHeaders( "JSON Entry response headers:", " ", res );
+ // System.out.println( "ContentNegotiationTest.testJSONEntryGet JSON entry body=" + responseBody );
+ } finally {
+ res.release();
+ }
+ }
+
+ protected String readResponse( Reader responseReader ) {
+ if ( responseReader == null ) return "";
+ StringBuffer sb = new StringBuffer(1024);
+ try {
+ int charValue = 0;
+ while ((charValue = responseReader.read()) != -1) {
+ //result = result + (char) charValue;
+ sb.append((char)charValue);
+ }
+ } catch ( IOException e ) {
+ }
+ return sb.toString();
+ }
}
diff --git a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerClient.java b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerClient.java index bc32b91367..85c4d4f56a 100644 --- a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerClient.java +++ b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerClient.java @@ -21,9 +21,13 @@ package org.apache.tuscany.sca.binding.atom; import org.apache.tuscany.sca.binding.atom.collection.Collection; +/** + * + * @version $Rev$ $Date$ + */ public interface CustomerClient { void testCustomerCollection() throws Exception; - + Collection getCustomerCollection(); } diff --git a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerClientImpl.java b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerClientImpl.java index c671954689..4e3b8241f8 100644 --- a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerClientImpl.java +++ b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerClientImpl.java @@ -26,10 +26,14 @@ import org.apache.abdera.model.Feed; import org.apache.tuscany.sca.binding.atom.collection.Collection; import org.oasisopen.sca.annotation.Reference; +/** + * + * @version $Rev$ $Date$ + */ public class CustomerClientImpl implements CustomerClient { protected final Abdera abdera = new Abdera(); - + @Reference public Collection customerCollection; @@ -67,9 +71,9 @@ public class CustomerClientImpl implements CustomerClient { } public Collection getCustomerCollection() { - return customerCollection; + return customerCollection; } - + private Entry newEntry(String value) { Entry entry = this.abdera.newEntry(); @@ -78,7 +82,7 @@ public class CustomerClientImpl implements CustomerClient { Content content = this.abdera.getFactory().newContent(); content.setContentType(Content.Type.TEXT); content.setValue(value); - + entry.setContentElement(content); return entry; diff --git a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerCollectionImpl.java b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerCollectionImpl.java index f62ad6110f..9e50cbbae7 100644 --- a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerCollectionImpl.java +++ b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerCollectionImpl.java @@ -32,12 +32,16 @@ import org.apache.tuscany.sca.binding.atom.collection.Collection; import org.apache.tuscany.sca.binding.atom.collection.NotFoundException; import org.oasisopen.sca.annotation.Scope; +/** + * + * @version $Rev$ $Date$ + */ @Scope("COMPOSITE") public class CustomerCollectionImpl implements Collection { private final Abdera abdera = new Abdera(); private Map<String, Entry> entries = new HashMap<String, Entry>(); public Date lastModified = new Date(); - + /** * Default constructor */ @@ -50,15 +54,15 @@ public class CustomerCollectionImpl implements Collection { if(!("Exception_Test".equalsIgnoreCase(entry.getTitle()))) { - String id = "urn:uuid:customer-" + UUID.randomUUID().toString(); - entry.setId(id); - - entry.addLink("" + id, "edit"); - entry.addLink("" + id, "alternate"); - Date now = new Date(); - entry.setUpdated(now); - lastModified = now; - entries.put(id, entry); + String id = "urn:uuid:customer-" + UUID.randomUUID().toString(); + entry.setId(id); + + entry.addLink("" + id, "edit"); + entry.addLink("" + id, "alternate"); + Date now = new Date(); + entry.setUpdated(now); + lastModified = now; + entries.put(id, entry); //System.out.println(">>> CustomerCollectionImpl.post return id=" + id); @@ -67,7 +71,7 @@ public class CustomerCollectionImpl implements Collection { } else { - throw new IllegalArgumentException("Exception in Post method"); + throw new IllegalArgumentException("Exception in Post method"); } } @@ -79,26 +83,26 @@ public class CustomerCollectionImpl implements Collection { public void put(String id, Entry entry) throws NotFoundException { //System.out.println(">>> CustomerCollectionImpl.put id=" + id + " entry=" + entry.getTitle()); if(entries.containsKey(id)){ - Date now = new Date(); - entry.setUpdated(now); - lastModified = now; + Date now = new Date(); + entry.setUpdated(now); + lastModified = now; entries.put(id, entry); } else { - throw new NotFoundException(); + throw new NotFoundException(); } - } + } public void delete(String id) throws NotFoundException { //System.out.println(">>> CustomerCollectionImpl.delete id=" + id); if(entries.containsKey(id)){ - entries.remove(id); - lastModified = new Date(); + entries.remove(id); + lastModified = new Date(); } else { - throw new NotFoundException(); - } - } + throw new NotFoundException(); + } + } public Feed getFeed() { //System.out.println(">>> CustomerCollectionImpl.getFeed"); diff --git a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerNonCollectionImpl.java b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerNonCollectionImpl.java index 643596147b..dbf6b5aed5 100644 --- a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerNonCollectionImpl.java +++ b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerNonCollectionImpl.java @@ -26,6 +26,8 @@ import org.oasisopen.sca.annotation.Scope; * Implementation of an Atom feed that does not implement the Collections * interface but does have a getAll() method that will be used by the Atom * binding to get the feed entries. + * + * @version $Rev$ $Date$ */ @Scope("COMPOSITE") public class CustomerNonCollectionImpl { diff --git a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/MediaCollectionImpl.java b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/MediaCollectionImpl.java index 606d97fefe..8ff89030db 100644 --- a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/MediaCollectionImpl.java +++ b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/MediaCollectionImpl.java @@ -36,27 +36,31 @@ import org.apache.tuscany.sca.binding.atom.collection.MediaCollection; import org.apache.tuscany.sca.binding.atom.collection.NotFoundException; import org.oasisopen.sca.annotation.Scope; +/** + * + * @version $Rev$ $Date$ + */ @Scope("COMPOSITE") public class MediaCollectionImpl implements MediaCollection { private final Abdera abdera = new Abdera(); private Map<String, Entry> entries = new HashMap<String, Entry>(); private Map<String, String> mediaFiles = new HashMap<String, String>(); public Date lastModified = new Date(); - + public Entry post(Entry entry) { //System.out.println(">>> MediaCollectionImpl.post entry=" + entry.getTitle()); if(!("Exception_Test".equalsIgnoreCase(entry.getTitle()))) { - String id = "urn:uuid:customer-" + UUID.randomUUID().toString(); - entry.setId(id); - - entry.addLink("" + id, "edit"); - entry.addLink("" + id, "alternate"); - Date now = new Date(); - entry.setUpdated(now); - lastModified = now; - entries.put(id, entry); + String id = "urn:uuid:customer-" + UUID.randomUUID().toString(); + entry.setId(id); + + entry.addLink("" + id, "edit"); + entry.addLink("" + id, "alternate"); + Date now = new Date(); + entry.setUpdated(now); + lastModified = now; + entries.put(id, entry); //System.out.println(">>> MediaCollectionImpl.post return id=" + id); @@ -65,7 +69,7 @@ public class MediaCollectionImpl implements MediaCollection { } else { - throw new IllegalArgumentException("Exception in Post method"); + throw new IllegalArgumentException("Exception in Post method"); } } @@ -77,26 +81,26 @@ public class MediaCollectionImpl implements MediaCollection { public void put(String id, Entry entry) throws NotFoundException { //System.out.println(">>> MediaCollectionImpl.put id=" + id + " entry=" + entry.getTitle()); if(entries.containsKey(id)){ - Date now = new Date(); - entry.setUpdated(now); - lastModified = now; + Date now = new Date(); + entry.setUpdated(now); + lastModified = now; entries.put(id, entry); } else { - throw new NotFoundException(); + throw new NotFoundException(); } - } + } public void delete(String id) throws NotFoundException { //System.out.println(">>> MediaCollectionImpl.delete id=" + id); if(entries.containsKey(id)){ - entries.remove(id); - lastModified = new Date(); + entries.remove(id); + lastModified = new Date(); } else { - throw new NotFoundException(); - } - } + throw new NotFoundException(); + } + } public Feed getFeed() { //System.out.println(">>> MediaCollectionImpl.getFeed"); @@ -163,21 +167,21 @@ public class MediaCollectionImpl implements MediaCollection { // </entry> // Normalize title - entry.setTitle( title ); + entry.setTitle( title ); String normalTitle = title.replace( " ", "_" ); String hostURL = "http://media.example.org/"; int lastDelimiterPos = contentType != null ? contentType.lastIndexOf( "/" ) : -1; String extension = ""; if ( lastDelimiterPos != -1 ) { - extension = contentType.substring( lastDelimiterPos + 1 ); + extension = contentType.substring( lastDelimiterPos + 1 ); } else { - extension = contentType; + extension = contentType; } long mediaLength = -1; try { - mediaLength = media.skip( Long.MAX_VALUE ); + mediaLength = media.skip( Long.MAX_VALUE ); } catch ( IOException e ){} - + // A true implementation would store the media to a repository, e.g. file system. // This implementation record's the id and the location. String id = "urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a-" + mediaFiles.size(); @@ -185,14 +189,14 @@ public class MediaCollectionImpl implements MediaCollection { mediaFiles.put( id, reposLocation ); // Build entry for media link. - entry.setUpdated( new Date() ); - entry.setId( id ); - // Convention. Return header properties as key values. - entry.setSummary( "Content-Type=" + contentType + ",Content-Length=" + mediaLength ); - entry.setContent( new IRI( hostURL + normalTitle + "." + extension ), contentType ); - entry.addLink( reposLocation + ".atom", "edit" ); - entry.addLink( reposLocation + "." + extension, "edit-media" ); - return entry; + entry.setUpdated( new Date() ); + entry.setId( id ); + // Convention. Return header properties as key values. + entry.setSummary( "Content-Type=" + contentType + ",Content-Length=" + mediaLength ); + entry.setContent( new IRI( hostURL + normalTitle + "." + extension ), contentType ); + entry.addLink( reposLocation + ".atom", "edit" ); + entry.addLink( reposLocation + "." + extension, "edit-media" ); + return entry; } public void putMedia(String id, String contentType, InputStream media) throws NotFoundException { @@ -201,8 +205,8 @@ public class MediaCollectionImpl implements MediaCollection { // Must responsd with success or not found as per Atom Pub spec (http://tools.ietf.org/html/rfc5023#section-9.6) // Body is null. if ( !id.endsWith( "0" ) ) - throw new NotFoundException( "Media at id=" + id + " not found." ); - + throw new NotFoundException( "Media at id=" + id + " not found." ); + // A true implementation would update the media in the media repository. } diff --git a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/MediaCollectionTestCase.java b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/MediaCollectionTestCase.java index a7f6ab6291..2870002c66 100644 --- a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/MediaCollectionTestCase.java +++ b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/MediaCollectionTestCase.java @@ -51,6 +51,8 @@ import org.junit.Test; * using entity tags or last modified header entries. * Uses the SCA provided Provider composite to act as a server. * Uses the Abdera provided Client to act as a client. + * + * @version $Rev$ $Date$ */ public class MediaCollectionTestCase { public final static String providerURI = "http://localhost:8084/receipt"; @@ -66,22 +68,22 @@ public class MediaCollectionTestCase { protected static String mediaId; 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 { - try { - //System.out.println(">>>MediaCollectionTestCase.init"); - String contribution = ContributionLocationHelper.getContributionLocation(MediaCollectionTestCase.class); - - scaProviderNode = NodeFactory.newInstance().createNode("org/apache/tuscany/sca/binding/atom/ReceiptProvider.composite", new Contribution("provider", contribution)); - scaProviderNode.start(); - - abdera = new Abdera(); - client = new AbderaClient(abdera); - abderaParser = Abdera.getNewParser(); - } catch(Exception e) { - e.printStackTrace(); - } - } + @BeforeClass + public static void init() throws Exception { + try { + //System.out.println(">>>MediaCollectionTestCase.init"); + String contribution = ContributionLocationHelper.getContributionLocation(MediaCollectionTestCase.class); + + scaProviderNode = NodeFactory.newInstance().createNode("org/apache/tuscany/sca/binding/atom/ReceiptProvider.composite", new Contribution("provider", contribution)); + scaProviderNode.start(); + + abdera = new Abdera(); + client = new AbderaClient(abdera); + abderaParser = Abdera.getNewParser(); + } catch(Exception e) { + e.printStackTrace(); + } + } @AfterClass public static void destroy() throws Exception { @@ -92,30 +94,30 @@ public class MediaCollectionTestCase { } } - @Test - public void testPrelim() throws Exception { - Assert.assertNotNull(scaProviderNode); - Assert.assertNotNull( client ); - } - @Test - public void testMediaEntryPost() throws Exception { - // Pseudo Code (see APP (http://tools.ietf.org/html/rfc5023#section-9.6) - // Post request - // POST /edit/ HTTP/1.1 + public void testPrelim() throws Exception { + Assert.assertNotNull(scaProviderNode); + Assert.assertNotNull( client ); + } + + @Test + public void testMediaEntryPost() throws Exception { + // Pseudo Code (see APP (http://tools.ietf.org/html/rfc5023#section-9.6) + // Post request + // POST /edit/ HTTP/1.1 // Host: media.example.org // Content-Type: image/png // Slug: The Beach // Content-Length: nnn // ...binary data... - - // Testing of entry creation - String receiptName = "Auto Repair Bill"; - String fileName = "target/test-classes/ReceiptToms.gif"; - File input = new File( fileName ); - boolean exists = input.exists(); - Assert.assertTrue( exists ); - + + // Testing of entry creation + String receiptName = "Auto Repair Bill"; + String fileName = "target/test-classes/ReceiptToms.gif"; + File input = new File( fileName ); + boolean exists = input.exists(); + Assert.assertTrue( exists ); + // Prepare HTTP post // PostMethod post = new PostMethod( colUri.toString() ); PostMethod post = new PostMethod( providerURI ); @@ -123,45 +125,45 @@ public class MediaCollectionTestCase { post.addRequestHeader( "Title", "Title " + receiptName + "" ); post.addRequestHeader( "Slug", "Slug " + receiptName + "" ); post.setRequestEntity( new InputStreamRequestEntity( new FileInputStream( input ), "image/gif" ) ); - + // Get HTTP client HttpClient httpclient = new HttpClient(); try { // Execute request int result = httpclient.executeMethod(post); // Pseudo Code (see APP (http://tools.ietf.org/html/rfc5023#section-9.6) - // Post response + // Post response // Tuscany responds with proper media links. Note that the media is - // stored in a different location than the media information which is - // stored in the Atom feed. + // stored in a different location than the media information which is + // stored in the Atom feed. // HTTP/1.1 201 Created // Display status code // System.out.println("Response status code: " + result + ", status text=" + post.getStatusText() ); - Assert.assertEquals(201, result ); + Assert.assertEquals(201, result ); // Display response // System.out.println("Response body: "); // System.out.println(post.getResponseBodyAsString()); // Warning: BodyAsString recommends BodyAsStream // Location: http://example.org/media/edit/the_beach.atom (REQUIRED) // System.out.println( "Response Location=" + post.getResponseHeader( "Location" ).getValue() + "." ); - Header header = post.getResponseHeader( "Location" ); - Assert.assertNotNull( header ); - Assert.assertNotNull( header.getValue() ); + Header header = post.getResponseHeader( "Location" ); + Assert.assertNotNull( header ); + Assert.assertNotNull( header.getValue() ); // ContentLocation: http://example.org/media/edit/the_beach.jpg (REQUIRED) // System.out.println( "Response Content-Location=" + post.getResponseHeader( "Content-Location" ).getValue() ); - header = post.getResponseHeader( "Content-Location" ); - Assert.assertNotNull( header ); - Assert.assertNotNull( header.getValue() ); + header = post.getResponseHeader( "Content-Location" ); + Assert.assertNotNull( header ); + Assert.assertNotNull( header.getValue() ); // Content-Type: application/atom+xml;type=entry;charset="utf-8" // System.out.println( "Response Content-Type=" + post.getResponseHeader( "Content-Type" ).getValue()); - header = post.getResponseHeader( "Content-Type" ); - Assert.assertNotNull( header ); - Assert.assertNotNull( header.getValue() ); + header = post.getResponseHeader( "Content-Type" ); + Assert.assertNotNull( header ); + Assert.assertNotNull( header.getValue() ); // Content-Length: nnn (OPTIONAL) // System.out.println( "Response Content-Length=" + post.getResponseHeader( "Content-Length" ).getValue() ); - header = post.getResponseHeader( "Content-Length" ); - Assert.assertNotNull( header ); - Assert.assertNotNull( header.getValue() ); + header = post.getResponseHeader( "Content-Length" ); + Assert.assertNotNull( header ); + Assert.assertNotNull( header.getValue() ); // <?xml version="1.0"?> // <entry xmlns="http://www.w3.org/2005/Atom"> // <title>The Beach</title> (REQUIRED) @@ -193,15 +195,15 @@ public class MediaCollectionTestCase { // System.out.println( "mediaPost entry.content.src=" + contentSrc + ", type=" + entry.getContentType()); Assert.assertNotNull( contentSrc ); Link editLink = entry.getEditLink(); - // System.out.println( "mediaPost entry.editLink" + " rel=" + editLink.getRel() + ", href=" + editLink.getHref() ); - Assert.assertNotNull( editLink ); - Assert.assertNotNull( editLink.getRel() ); - Assert.assertNotNull( editLink.getHref() ); + // System.out.println( "mediaPost entry.editLink" + " rel=" + editLink.getRel() + ", href=" + editLink.getHref() ); + Assert.assertNotNull( editLink ); + Assert.assertNotNull( editLink.getRel() ); + Assert.assertNotNull( editLink.getHref() ); Link editMediaLink = entry.getEditMediaLink(); - // System.out.println( "mediaPost entry.editMediaLink" + " rel=" + editMediaLink.getRel() + ", href=" + editMediaLink.getHref() ); - Assert.assertNotNull( editMediaLink ); - Assert.assertNotNull( editMediaLink.getRel() ); - Assert.assertNotNull( editMediaLink.getHref() ); + // System.out.println( "mediaPost entry.editMediaLink" + " rel=" + editMediaLink.getRel() + ", href=" + editMediaLink.getHref() ); + Assert.assertNotNull( editMediaLink ); + Assert.assertNotNull( editMediaLink.getRel() ); + Assert.assertNotNull( editMediaLink.getHref() ); } finally { // Release current connection to the connection pool once you are done @@ -209,29 +211,29 @@ public class MediaCollectionTestCase { } } - @Test - public void testMediaEntryPutFound() throws Exception { - // Pseudo Code (see APP (http://tools.ietf.org/html/rfc5023#section-9.6) - // Testing of entry update - String receiptName = "Value Autoglass Bill"; - String fileName = "target/test-classes/ReceiptValue.jpg"; - File input = new File( fileName ); - boolean exists = input.exists(); - Assert.assertTrue( exists ); - + @Test + public void testMediaEntryPutFound() throws Exception { + // Pseudo Code (see APP (http://tools.ietf.org/html/rfc5023#section-9.6) + // Testing of entry update + String receiptName = "Value Autoglass Bill"; + String fileName = "target/test-classes/ReceiptValue.jpg"; + File input = new File( fileName ); + boolean exists = input.exists(); + Assert.assertTrue( exists ); + // Prepare HTTP put request - // PUT /edit/the_beach.png HTTP/1.1 - // Host: media.example.org - // Content-Type: image/png - // Content-Length: nnn - // ...binary data... + // PUT /edit/the_beach.png HTTP/1.1 + // Host: media.example.org + // Content-Type: image/png + // Content-Length: nnn + // ...binary data... PutMethod put = new PutMethod( providerURI + "/" + mediaId ); put.addRequestHeader( "Content-Type", "image/jpg" ); put.addRequestHeader( "Title", "Title " + receiptName + "" ); put.addRequestHeader( "Slug", "Slug " + receiptName + "" ); put.setRequestEntity( - new InputStreamRequestEntity( new FileInputStream( input ), "image/jpg" ) ); - + new InputStreamRequestEntity( new FileInputStream( input ), "image/jpg" ) ); + // Get HTTP client HttpClient httpclient = new HttpClient(); try { @@ -240,7 +242,7 @@ public class MediaCollectionTestCase { // Pseudo Code (see APP (http://tools.ietf.org/html/rfc5023#section-9.6) // Display status code // System.out.println("Response status code: " + result + ", status text=" + put.getStatusText() ); - Assert.assertEquals(200, result ); + Assert.assertEquals(200, result ); // Display response. Should be empty for put. // System.out.println("Response body: "); // System.out.println(put.getResponseBodyAsString()); // Warning: BodyAsString recommends BodyAsStream @@ -248,31 +250,31 @@ public class MediaCollectionTestCase { // Release current connection to the connection pool once you are done put.releaseConnection(); } - } - - @Test - public void testMediaEntryPutNotFound() throws Exception { - // Pseudo Code (see APP (http://tools.ietf.org/html/rfc5023#section-9.6) - // Testing of entry update - String receiptName = "Value Autoglass Bill"; - String fileName = "target/test-classes/ReceiptValue.jpg"; - File input = new File( fileName ); - boolean exists = input.exists(); - Assert.assertTrue( exists ); - + } + + @Test + public void testMediaEntryPutNotFound() throws Exception { + // Pseudo Code (see APP (http://tools.ietf.org/html/rfc5023#section-9.6) + // Testing of entry update + String receiptName = "Value Autoglass Bill"; + String fileName = "target/test-classes/ReceiptValue.jpg"; + File input = new File( fileName ); + boolean exists = input.exists(); + Assert.assertTrue( exists ); + // Prepare HTTP put request - // PUT /edit/the_beach.png HTTP/1.1 - // Host: media.example.org - // Content-Type: image/png - // Content-Length: nnn - // ...binary data... + // PUT /edit/the_beach.png HTTP/1.1 + // Host: media.example.org + // Content-Type: image/png + // Content-Length: nnn + // ...binary data... PutMethod put = new PutMethod( providerURI + "/" + mediaId + "-bogus" ); // Does not exist. put.addRequestHeader( "Content-Type", "image/jpg" ); put.addRequestHeader( "Title", "Title " + receiptName + "" ); put.addRequestHeader( "Slug", "Slug " + receiptName + "" ); put.setRequestEntity( - new InputStreamRequestEntity( new FileInputStream( input ), "image/jpg" ) ); - + new InputStreamRequestEntity( new FileInputStream( input ), "image/jpg" ) ); + // Get HTTP client HttpClient httpclient = new HttpClient(); try { @@ -281,7 +283,7 @@ public class MediaCollectionTestCase { // Pseudo Code (see APP (http://tools.ietf.org/html/rfc5023#section-9.6) // Display status code // System.out.println("Response status code: " + result + ", status text=" + put.getStatusText() ); - Assert.assertEquals(404, result ); + Assert.assertEquals(404, result ); // Display response. Should be empty for put. // System.out.println("Response body: "); // System.out.println(put.getResponseBodyAsString()); // Warning: BodyAsString recommends BodyAsStream @@ -289,5 +291,5 @@ public class MediaCollectionTestCase { // Release current connection to the connection pool once you are done put.releaseConnection(); } - } + } } diff --git a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/Provider.java b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/Provider.java index d116b97adc..f802d3891f 100644 --- a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/Provider.java +++ b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/Provider.java @@ -26,6 +26,10 @@ import org.apache.tuscany.sca.node.ContributionLocationHelper; import org.apache.tuscany.sca.node.Node; import org.apache.tuscany.sca.node.NodeFactory; +/** + * + * @version $Rev$ $Date$ + */ public class Provider { public static void main(String[] args) { diff --git a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderEntryEntityTagsTestCase.java b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderEntryEntityTagsTestCase.java index 9ffd98c283..534c2c901f 100644 --- a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderEntryEntityTagsTestCase.java +++ b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderEntryEntityTagsTestCase.java @@ -47,6 +47,8 @@ import org.junit.Test; * using entity tags or last modified header entries. * Uses the SCA provided Provider composite to act as a server. * Uses the Abdera provided Client to act as a client. + * + * @version $Rev$ $Date$ */ public class ProviderEntryEntityTagsTestCase { public final static String providerURI = "http://localhost:8084/customer"; @@ -61,18 +63,18 @@ public class ProviderEntryEntityTagsTestCase { 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(">>>ProviderEntryEntityTagsTestCase.init"); - String contribution = ContributionLocationHelper.getContributionLocation(ProviderEntryEntityTagsTestCase.class); + @BeforeClass + public static void init() throws Exception { + //System.out.println(">>>ProviderEntryEntityTagsTestCase.init"); + String contribution = ContributionLocationHelper.getContributionLocation(ProviderEntryEntityTagsTestCase.class); + + scaProviderNode = NodeFactory.newInstance().createNode("org/apache/tuscany/sca/binding/atom/Provider.composite", new Contribution("provider", contribution)); + scaProviderNode.start(); - scaProviderNode = NodeFactory.newInstance().createNode("org/apache/tuscany/sca/binding/atom/Provider.composite", new Contribution("provider", contribution)); - scaProviderNode.start(); - - abdera = new Abdera(); - client = new AbderaClient(abdera); - abderaParser = Abdera.getNewParser(); - } + abdera = new Abdera(); + client = new AbderaClient(abdera); + abderaParser = Abdera.getNewParser(); + } @AfterClass public static void destroy() throws Exception { @@ -83,349 +85,349 @@ public class ProviderEntryEntityTagsTestCase { } } - @Test - public void testPrelim() throws Exception { - Assert.assertNotNull(scaProviderNode); - Assert.assertNotNull( client ); - } - @Test - public void testEmptyCachePost() throws Exception { - // Pseudo-code - // 1) Example HTTP POST request (new entry put, new etag response) - // User client post request - // POST /myblog/entries HTTP/1.1 - // Slug: First Post - // - // <?xml version="1.0" ?> - // <entry xmlns="http://www.w3.org/2005/Atom"> - // <title>Atom-Powered Robots Run Amok</title> - // <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id> - // <updated>2007-02-123T17:09:02Z</updated> - // <author><name>Captain Lansing</name></author> - // <content>It's something moving... solid metal</content> - // </entry> - - // Expected Atom server response (note unique ETag) - // HTTP/1.1 201 Created - // Date: Fri, 23 Feb 2007 21:17:11 GMT - // Content-Length: nnn - // Content-Type: application/atom+xml;type=entry - // Location: http://example.org/edit/first-post.atom - // Content-Location: http://example.org/edit/first-post.atom - // ETag: "e180ee84f0671b1" - // Last-Modified: Fri, 25 Jul 2008 14:36:44 -0500 - // - // <?xml version="1.0" ?> - // <entry xmlns="http://www.w3.org/2005/Atom"> - // <title>Atom-Powered Robots Run Amok</title> - // <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id> - // <updated>2007-02-123T17:09:02Z</updated> - // <author><name>Captain Lansing</name></author> - // <content>It's something moving... solid metal</content> - // </entry> - - // Testing of entry creation - Factory factory = abdera.getFactory(); - String customerName = "Fred Farkle"; - Entry entry = factory.newEntry(); - entry.setTitle("customer " + customerName); - entry.setUpdated(new Date()); - entry.addAuthor("Apache Tuscany"); - // ID created by collection. + public void testPrelim() throws Exception { + Assert.assertNotNull(scaProviderNode); + Assert.assertNotNull( client ); + } + + @Test + public void testEmptyCachePost() throws Exception { + // Pseudo-code + // 1) Example HTTP POST request (new entry put, new etag response) + // User client post request + // POST /myblog/entries HTTP/1.1 + // Slug: First Post + // + // <?xml version="1.0" ?> + // <entry xmlns="http://www.w3.org/2005/Atom"> + // <title>Atom-Powered Robots Run Amok</title> + // <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id> + // <updated>2007-02-123T17:09:02Z</updated> + // <author><name>Captain Lansing</name></author> + // <content>It's something moving... solid metal</content> + // </entry> + + // Expected Atom server response (note unique ETag) + // HTTP/1.1 201 Created + // Date: Fri, 23 Feb 2007 21:17:11 GMT + // Content-Length: nnn + // Content-Type: application/atom+xml;type=entry + // Location: http://example.org/edit/first-post.atom + // Content-Location: http://example.org/edit/first-post.atom + // ETag: "e180ee84f0671b1" + // Last-Modified: Fri, 25 Jul 2008 14:36:44 -0500 + // + // <?xml version="1.0" ?> + // <entry xmlns="http://www.w3.org/2005/Atom"> + // <title>Atom-Powered Robots Run Amok</title> + // <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id> + // <updated>2007-02-123T17:09:02Z</updated> + // <author><name>Captain Lansing</name></author> + // <content>It's something moving... solid metal</content> + // </entry> + + // Testing of entry creation + Factory factory = abdera.getFactory(); + String customerName = "Fred Farkle"; + Entry entry = factory.newEntry(); + entry.setTitle("customer " + customerName); + entry.setUpdated(new Date()); + entry.addAuthor("Apache Tuscany"); + // ID created by collection. // entry.setId(id); // auto-provided // entry.addLink("" + id, "edit"); // auto-provided // entry.addLink("" + id, "alternate"); // auto-provided - Content content = abdera.getFactory().newContent(); - content.setContentType(Content.Type.TEXT); - content.setValue(customerName); - entry.setContentElement(content); - - RequestOptions opts = new RequestOptions(); - final String contentType = "application/atom+xml; type=entry"; - opts.setContentType(contentType); - // AtomTestCaseUtils.printRequestHeaders( "Post request headers", " ", opts ); - IRI colUri = new IRI(providerURI).resolve("customer"); - // res = client.post(colUri.toString() + "?test=foo", entry, opts); - ClientResponse res = client.post(colUri.toString(), entry, opts); - - // Assert response status code is 201-OK. - // Assert response header Content-Type: application/atom+xml; charset=UTF-8 - // Assert response header Location: http://example.org/edit/first-post.atom - // Assert response header Content-Location: http://example.org/edit/first-post.atom - // Assert response header ETag: "e180ee84f0671b1" - // Assert response header Last-Modified: Fri, 25 Jul 2008 14:36:44 -0500 - // Assert collection size is 1. - Assert.assertEquals(201, res.getStatus()); - Assert.assertEquals(contentType, res.getContentType().toString().trim()); - // Assert.assertNotNull( res.getLocation().toString() ); - // Assert.assertEquals( "", res.getContentLocation().toString() ); - // Save eTag for subsequent tests; - eTag = res.getHeader( "ETag" ); - Assert.assertNotNull( eTag ); - lastModified = res.getLastModified(); - Assert.assertNotNull(lastModified); - } - - @Test - public void testDirtyCachePut() throws Exception { - // 2) Conditional PUT request (post with etag. entry provided is stale) - // User client PUT request - // PUT /edit/first-post.atom HTTP/1.1 - // > If-Match: "e180ee84f0671b1" - // - // <?xml version="1.0" ?> - // <entry xmlns="http://www.w3.org/2005/Atom"> - // <title>Atom-Powered Robots Run Amok</title> - // <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id> - // <updated>2007-02-24T16:34:06Z</updated> - // <author><name>Captain Lansing</name></author> - // <content>Update: it's a hoax!</content> - // </entry> - // Testing of entry creation - Factory factory = abdera.getFactory(); - String customerName = "Molly Ringwald"; - Entry entry = factory.newEntry(); - entry.setTitle("customer " + customerName); - entry.setUpdated( new Date()); - entry.addAuthor("Apache Tuscany"); - String id = eTag.substring( 1, eTag.length()-1); + Content content = abdera.getFactory().newContent(); + content.setContentType(Content.Type.TEXT); + content.setValue(customerName); + entry.setContentElement(content); + + RequestOptions opts = new RequestOptions(); + final String contentType = "application/atom+xml; type=entry"; + opts.setContentType(contentType); + // AtomTestCaseUtils.printRequestHeaders( "Post request headers", " ", opts ); + IRI colUri = new IRI(providerURI).resolve("customer"); + // res = client.post(colUri.toString() + "?test=foo", entry, opts); + ClientResponse res = client.post(colUri.toString(), entry, opts); + + // Assert response status code is 201-OK. + // Assert response header Content-Type: application/atom+xml; charset=UTF-8 + // Assert response header Location: http://example.org/edit/first-post.atom + // Assert response header Content-Location: http://example.org/edit/first-post.atom + // Assert response header ETag: "e180ee84f0671b1" + // Assert response header Last-Modified: Fri, 25 Jul 2008 14:36:44 -0500 + // Assert collection size is 1. + Assert.assertEquals(201, res.getStatus()); + Assert.assertEquals(contentType, res.getContentType().toString().trim()); + // Assert.assertNotNull( res.getLocation().toString() ); + // Assert.assertEquals( "", res.getContentLocation().toString() ); + // Save eTag for subsequent tests; + eTag = res.getHeader( "ETag" ); + Assert.assertNotNull( eTag ); + lastModified = res.getLastModified(); + Assert.assertNotNull(lastModified); + } + + @Test + public void testDirtyCachePut() throws Exception { + // 2) Conditional PUT request (post with etag. entry provided is stale) + // User client PUT request + // PUT /edit/first-post.atom HTTP/1.1 + // > If-Match: "e180ee84f0671b1" + // + // <?xml version="1.0" ?> + // <entry xmlns="http://www.w3.org/2005/Atom"> + // <title>Atom-Powered Robots Run Amok</title> + // <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id> + // <updated>2007-02-24T16:34:06Z</updated> + // <author><name>Captain Lansing</name></author> + // <content>Update: it's a hoax!</content> + // </entry> + // Testing of entry creation + Factory factory = abdera.getFactory(); + String customerName = "Molly Ringwald"; + Entry entry = factory.newEntry(); + entry.setTitle("customer " + customerName); + entry.setUpdated( new Date()); + entry.addAuthor("Apache Tuscany"); + String id = eTag.substring( 1, eTag.length()-1); entry.setId(id); // auto-provided // entry.addLink("" + id, "edit"); // auto-provided // entry.addLink("" + id, "alternate"); // auto-provided - Content content = abdera.getFactory().newContent(); - content.setContentType(Content.Type.TEXT); - content.setValue(customerName); - entry.setContentElement(content); - - RequestOptions opts = new RequestOptions(); - final String contentType = "application/atom+xml; type=entry"; - opts.setContentType(contentType); - opts.setHeader( "If-None-Match", eTag); - - // 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); - // Warning. AbderaClient.put(String uri,Base base,RequestOptions options) caches on the client side. - // ClientResponse res = client.put(colUri.toString() + id, entry, opts); - ClientResponse res = client.put(colUri.toString() + "/" + id, new BaseRequestEntity( entry ), opts); - // Expected Atom server response (item was edited by another user) - // > HTTP/1.1 412 Precondition Failed - // Date: Sat, 24 Feb 2007 16:34:11 GMT - - // If-Match Assert response status code is 412. Precondition failed. - // If-None-Match Assert response status code is 200. OK - Assert.assertEquals(200, res.getStatus()); - // Put provides null body and no etags. - res.release(); - } - - @Test - public void testETagMissGet() throws Exception { - // 4) Conditional GET example (get with etag. etag not in cache) - // User client GET request - // GET /edit/first-post.atom HTTP/1.1 - // > If-None-Match: "e180ee84f0671b1" - - RequestOptions opts = new RequestOptions(); - final String contentType = "application/atom+xml; type=entry"; - opts.setContentType(contentType); - opts.setHeader( "If-None-Match", "123456"); - opts.setHeader( "Pragma", "no-cache"); // turn off client caching - - IRI colUri = new IRI(providerURI).resolve("customer"); - // res = client.post(colUri.toString() + "?test=foo", entry, opts); - String id = eTag.substring( 1, eTag.length()-1); - // Warning. AbderaClient.put(String uri,Base base,RequestOptions options) caches on the client side. - // ClientResponse res = client.put(colUri.toString() + id, entry, opts); - ClientResponse res = client.get(colUri.toString() + "/" + id, opts); - // Expected Atom server response (item was edited by another user) - // > HTTP/1.1 412 Precondition Failed - // Date: Sat, 24 Feb 2007 16:34:11 GMT - - // 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 - - // 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: "555555" (etag response != etag request) - // Assert header Last-Modified: Fri, 25 Jul 2008 14:36:44 -0500 - 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(); - } - - @Test - public void testETagHitGet() throws Exception { - // 3) Conditional GET example (get with etag. etag match) - // User client GET request - // GET /edit/first-post.atom HTTP/1.1 - // > If-None-Match: "e180ee84f0671b1" - - RequestOptions opts = new RequestOptions(); - final String contentType = "application/atom+xml; type=entry"; - opts.setContentType(contentType); - opts.setHeader( "If-None-Match", eTag); - opts.setHeader( "Pragma", "no-cache"); // turn off client caching - - IRI colUri = new IRI(providerURI).resolve("customer"); - // res = client.post(colUri.toString() + "?test=foo", entry, opts); - String id = eTag.substring( 1, eTag.length()-1); - // Warning. AbderaClient.put(String uri,Base base,RequestOptions options) caches on the client side. - // ClientResponse res = client.put(colUri.toString() + id, entry, opts); - 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 - - // Assert response status code is 304 Not Modified. - // Assert header ETag: "e180ee84f0671b1" - // Assert header Last-Modified: Fri, 25 Jul 2008 14:36:44 -0500 - // Assert.assertEquals(304, res.getStatus()); - res.release(); - } - - - @Test - public void testUpToDateGet() throws Exception { - // 3) Conditional GET example (get with If-Mod. entry is up to date) - // User client GET request - // GET /edit/first-post.atom HTTP/1.1 - // > If-Modified-Since: Sat, 29 Oct 2025 19:43:31 GMT - RequestOptions opts = new RequestOptions(); - final String contentType = "application/atom+xml; type=entry"; - opts.setContentType(contentType); - opts.setHeader( "If-Modified-Since", "Sat, 29 Oct 2025 19:43:31 GMT"); // "EEE, dd MMM yyyy HH:mm:ss Z // RFC 822 Date - opts.setHeader( "Pragma", "no-cache"); // turn off client caching - - IRI colUri = new IRI(providerURI).resolve("customer"); - // res = client.post(colUri.toString() + "?test=foo", entry, opts); - String id = eTag.substring( 1, eTag.length()-1); - // Warning. AbderaClient.put(String uri,Base base,RequestOptions options) caches on the client side. - // ClientResponse res = client.put(colUri.toString() + id, entry, opts); - // Warning. AbderaClient.put(String uri,Base base,RequestOptions options) caches on the client side. - // ClientResponse res = client.get(colUri.toString() + "/" + id, opts); - ClientResponse res = client.execute( "GET", colUri.toString(), (BaseRequestEntity)null, opts); - - // Atom server response (item was up to date) - // > HTTP/1.1 304 Not Modified - // Date: Sat, 24 Feb 2007 13:17:11 GMT - - // Assert response status code is 304 Not Modified. - Assert.assertEquals(304, res.getStatus()); - res.release(); - } - - @Test - public void testOutOfDateGet() throws Exception { - // 4) Conditional GET example (get with If-Mod. entry is not to date) - // User client GET request - // GET /edit/first-post.atom HTTP/1.1 - // > If-Modified-Since: Sat, 29 Oct 1844 19:43:31 GMT - RequestOptions opts = new RequestOptions(); - final String contentType = "application/atom+xml; type=entry"; - opts.setContentType(contentType); - opts.setHeader( "If-Modified-Since", "Sat, 29 Oct 1844 19:43:31 GMT"); // "EEE, dd MMM yyyy HH:mm:ss Z // RFC 822 Date - opts.setHeader( "Pragma", "no-cache"); // turn off client caching - - IRI colUri = new IRI(providerURI).resolve("customer"); - // res = client.post(colUri.toString() + "?test=foo", entry, opts); - String id = eTag.substring( 1, eTag.length()-1); - // Warning. AbderaClient.put(String uri,Base base,RequestOptions options) caches on the client side. - // ClientResponse res = client.put(colUri.toString() + id, entry, opts); - 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 - - // Assert response status code is 200 OK. - // Assert header ETag: "e180ee84f0671b1" - // Assert header Last-Modified: Greater than If-Mod - 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(); - } - - @Test - public void testUpToDateUnModGet() throws Exception { - // 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 - RequestOptions opts = new RequestOptions(); - final String contentType = "application/atom+xml; type=entry"; - opts.setContentType(contentType); - opts.setHeader( "If-Unmodified-Since", "Sat, 29 Oct 2050 19:43:31 GMT" ); - opts.setHeader( "Pragma", "no-cache"); // turn off client caching - - IRI colUri = new IRI(providerURI).resolve("customer"); - // res = client.post(colUri.toString() + "?test=foo", entry, opts); - String id = eTag.substring( 1, eTag.length()-1); - // Warning. AbderaClient.put(String uri,Base base,RequestOptions options) caches on the client side. - // ClientResponse res = client.put(colUri.toString() + id, entry, opts); - 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 - - // 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 modified (> predicate date) - // User client GET request - // GET /edit/first-post.atom HTTP/1.1 - // Host: example.org - // > If-Unmodified-Since: Sat, 29 Oct 1844 19:43:31 GMT - RequestOptions opts = new RequestOptions(); - final String contentType = "application/atom+xml; type=entry"; - opts.setContentType(contentType); - opts.setHeader( "If-Unmodified-Since", "Sat, 29 Oct 1844 19:43:31 GMT" ); - opts.setHeader( "Pragma", "no-cache"); // turn off client caching - - IRI colUri = new IRI(providerURI).resolve("customer"); - // res = client.post(colUri.toString() + "?test=foo", entry, opts); - String id = eTag.substring( 1, eTag.length()-1); - // Warning. AbderaClient.put(String uri,Base base,RequestOptions options) caches on the client side. - // ClientResponse res = client.put(colUri.toString() + id, entry, opts); - 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 - - // Assert response status code is 304 Not Modified. - Assert.assertEquals(304, res.getStatus()); - res.release(); - } + Content content = abdera.getFactory().newContent(); + content.setContentType(Content.Type.TEXT); + content.setValue(customerName); + entry.setContentElement(content); + + RequestOptions opts = new RequestOptions(); + final String contentType = "application/atom+xml; type=entry"; + opts.setContentType(contentType); + opts.setHeader( "If-None-Match", eTag); + + // 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); + // Warning. AbderaClient.put(String uri,Base base,RequestOptions options) caches on the client side. + // ClientResponse res = client.put(colUri.toString() + id, entry, opts); + ClientResponse res = client.put(colUri.toString() + "/" + id, new BaseRequestEntity( entry ), opts); + // Expected Atom server response (item was edited by another user) + // > HTTP/1.1 412 Precondition Failed + // Date: Sat, 24 Feb 2007 16:34:11 GMT + + // If-Match Assert response status code is 412. Precondition failed. + // If-None-Match Assert response status code is 200. OK + Assert.assertEquals(200, res.getStatus()); + // Put provides null body and no etags. + res.release(); + } + + @Test + public void testETagMissGet() throws Exception { + // 4) Conditional GET example (get with etag. etag not in cache) + // User client GET request + // GET /edit/first-post.atom HTTP/1.1 + // > If-None-Match: "e180ee84f0671b1" + + RequestOptions opts = new RequestOptions(); + final String contentType = "application/atom+xml; type=entry"; + opts.setContentType(contentType); + opts.setHeader( "If-None-Match", "123456"); + opts.setHeader( "Pragma", "no-cache"); // turn off client caching + + IRI colUri = new IRI(providerURI).resolve("customer"); + // res = client.post(colUri.toString() + "?test=foo", entry, opts); + String id = eTag.substring( 1, eTag.length()-1); + // Warning. AbderaClient.put(String uri,Base base,RequestOptions options) caches on the client side. + // ClientResponse res = client.put(colUri.toString() + id, entry, opts); + ClientResponse res = client.get(colUri.toString() + "/" + id, opts); + // Expected Atom server response (item was edited by another user) + // > HTTP/1.1 412 Precondition Failed + // Date: Sat, 24 Feb 2007 16:34:11 GMT + + // 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 + + // 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: "555555" (etag response != etag request) + // Assert header Last-Modified: Fri, 25 Jul 2008 14:36:44 -0500 + 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(); + } + + @Test + public void testETagHitGet() throws Exception { + // 3) Conditional GET example (get with etag. etag match) + // User client GET request + // GET /edit/first-post.atom HTTP/1.1 + // > If-None-Match: "e180ee84f0671b1" + + RequestOptions opts = new RequestOptions(); + final String contentType = "application/atom+xml; type=entry"; + opts.setContentType(contentType); + opts.setHeader( "If-None-Match", eTag); + opts.setHeader( "Pragma", "no-cache"); // turn off client caching + + IRI colUri = new IRI(providerURI).resolve("customer"); + // res = client.post(colUri.toString() + "?test=foo", entry, opts); + String id = eTag.substring( 1, eTag.length()-1); + // Warning. AbderaClient.put(String uri,Base base,RequestOptions options) caches on the client side. + // ClientResponse res = client.put(colUri.toString() + id, entry, opts); + 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 + + // Assert response status code is 304 Not Modified. + // Assert header ETag: "e180ee84f0671b1" + // Assert header Last-Modified: Fri, 25 Jul 2008 14:36:44 -0500 + // Assert.assertEquals(304, res.getStatus()); + res.release(); + } + + + @Test + public void testUpToDateGet() throws Exception { + // 3) Conditional GET example (get with If-Mod. entry is up to date) + // User client GET request + // GET /edit/first-post.atom HTTP/1.1 + // > If-Modified-Since: Sat, 29 Oct 2025 19:43:31 GMT + RequestOptions opts = new RequestOptions(); + final String contentType = "application/atom+xml; type=entry"; + opts.setContentType(contentType); + opts.setHeader( "If-Modified-Since", "Sat, 29 Oct 2025 19:43:31 GMT"); // "EEE, dd MMM yyyy HH:mm:ss Z // RFC 822 Date + opts.setHeader( "Pragma", "no-cache"); // turn off client caching + + IRI colUri = new IRI(providerURI).resolve("customer"); + // res = client.post(colUri.toString() + "?test=foo", entry, opts); + String id = eTag.substring( 1, eTag.length()-1); + // Warning. AbderaClient.put(String uri,Base base,RequestOptions options) caches on the client side. + // ClientResponse res = client.put(colUri.toString() + id, entry, opts); + // Warning. AbderaClient.put(String uri,Base base,RequestOptions options) caches on the client side. + // ClientResponse res = client.get(colUri.toString() + "/" + id, opts); + ClientResponse res = client.execute( "GET", colUri.toString(), (BaseRequestEntity)null, opts); + + // Atom server response (item was up to date) + // > HTTP/1.1 304 Not Modified + // Date: Sat, 24 Feb 2007 13:17:11 GMT + + // Assert response status code is 304 Not Modified. + Assert.assertEquals(304, res.getStatus()); + res.release(); + } + + @Test + public void testOutOfDateGet() throws Exception { + // 4) Conditional GET example (get with If-Mod. entry is not to date) + // User client GET request + // GET /edit/first-post.atom HTTP/1.1 + // > If-Modified-Since: Sat, 29 Oct 1844 19:43:31 GMT + RequestOptions opts = new RequestOptions(); + final String contentType = "application/atom+xml; type=entry"; + opts.setContentType(contentType); + opts.setHeader( "If-Modified-Since", "Sat, 29 Oct 1844 19:43:31 GMT"); // "EEE, dd MMM yyyy HH:mm:ss Z // RFC 822 Date + opts.setHeader( "Pragma", "no-cache"); // turn off client caching + + IRI colUri = new IRI(providerURI).resolve("customer"); + // res = client.post(colUri.toString() + "?test=foo", entry, opts); + String id = eTag.substring( 1, eTag.length()-1); + // Warning. AbderaClient.put(String uri,Base base,RequestOptions options) caches on the client side. + // ClientResponse res = client.put(colUri.toString() + id, entry, opts); + 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 + + // Assert response status code is 200 OK. + // Assert header ETag: "e180ee84f0671b1" + // Assert header Last-Modified: Greater than If-Mod + 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(); + } + + @Test + public void testUpToDateUnModGet() throws Exception { + // 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 + RequestOptions opts = new RequestOptions(); + final String contentType = "application/atom+xml; type=entry"; + opts.setContentType(contentType); + opts.setHeader( "If-Unmodified-Since", "Sat, 29 Oct 2050 19:43:31 GMT" ); + opts.setHeader( "Pragma", "no-cache"); // turn off client caching + + IRI colUri = new IRI(providerURI).resolve("customer"); + // res = client.post(colUri.toString() + "?test=foo", entry, opts); + String id = eTag.substring( 1, eTag.length()-1); + // Warning. AbderaClient.put(String uri,Base base,RequestOptions options) caches on the client side. + // ClientResponse res = client.put(colUri.toString() + id, entry, opts); + 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 + + // 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 modified (> predicate date) + // User client GET request + // GET /edit/first-post.atom HTTP/1.1 + // Host: example.org + // > If-Unmodified-Since: Sat, 29 Oct 1844 19:43:31 GMT + RequestOptions opts = new RequestOptions(); + final String contentType = "application/atom+xml; type=entry"; + opts.setContentType(contentType); + opts.setHeader( "If-Unmodified-Since", "Sat, 29 Oct 1844 19:43:31 GMT" ); + opts.setHeader( "Pragma", "no-cache"); // turn off client caching + + IRI colUri = new IRI(providerURI).resolve("customer"); + // res = client.post(colUri.toString() + "?test=foo", entry, opts); + String id = eTag.substring( 1, eTag.length()-1); + // Warning. AbderaClient.put(String uri,Base base,RequestOptions options) caches on the client side. + // ClientResponse res = client.put(colUri.toString() + id, entry, opts); + 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 + + // Assert response status code is 304 Not Modified. + Assert.assertEquals(304, res.getStatus()); + res.release(); + } } diff --git a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTestCase.java b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTestCase.java index a5f6d3074e..79a8fe23dd 100644 --- a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTestCase.java +++ b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTestCase.java @@ -53,6 +53,8 @@ import org.junit.Test; * 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. + * + * @version $Rev$ $Date$ */ public class ProviderFeedEntityTagsTestCase { public final static String providerURI = "http://localhost:8084/customer"; @@ -67,18 +69,18 @@ public class ProviderFeedEntityTagsTestCase { 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(">>>ProviderFeedEntityTagsTestCase.init"); - String contribution = ContributionLocationHelper.getContributionLocation(ProviderEntryEntityTagsTestCase.class); + @BeforeClass + public static void init() throws Exception { + //System.out.println(">>>ProviderFeedEntityTagsTestCase.init"); + String contribution = ContributionLocationHelper.getContributionLocation(ProviderEntryEntityTagsTestCase.class); - scaProviderNode = NodeFactory.newInstance().createNode("org/apache/tuscany/sca/binding/atom/Provider.composite", new Contribution("provider", contribution)); - scaProviderNode.start(); + scaProviderNode = NodeFactory.newInstance().createNode("org/apache/tuscany/sca/binding/atom/Provider.composite", new Contribution("provider", contribution)); + scaProviderNode.start(); - abdera = new Abdera(); - client = new AbderaClient(abdera); - abderaParser = Abdera.getNewParser(); - } + abdera = new Abdera(); + client = new AbderaClient(abdera); + abderaParser = Abdera.getNewParser(); + } @AfterClass public static void destroy() throws Exception { @@ -89,297 +91,297 @@ public class ProviderFeedEntityTagsTestCase { } } - @Test - public void testPrelim() throws Exception { - Assert.assertNotNull(scaProviderNode); - Assert.assertNotNull( client ); - } - - @Test + @Test + public void testPrelim() throws Exception { + Assert.assertNotNull(scaProviderNode); + Assert.assertNotNull( client ); + } + + @Test public void testFeedBasics() throws Exception { - // System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedBasics"); - // Normal feed request - ClientResponse res = client.get(providerURI); - Assert.assertNotNull(res); - try { - // Assert 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. - // 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.assertTrue( -1 != body.indexOf( "</id>" )); - Assert.assertTrue( -1 != body.indexOf( "</title>" )); - Assert.assertTrue( -1 != body.indexOf( "</updated>" )); - - eTag = res.getHeader("ETag"); - Assert.assertNotNull( eTag ); - lastModified = res.getLastModified(); - Assert.assertNotNull( lastModified ); - } finally { - res.release(); - } - } - - @Test + // System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedBasics"); + // Normal feed request + ClientResponse res = client.get(providerURI); + Assert.assertNotNull(res); + try { + // Assert 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. + // 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.assertTrue( -1 != body.indexOf( "</id>" )); + Assert.assertTrue( -1 != body.indexOf( "</title>" )); + Assert.assertTrue( -1 != body.indexOf( "</updated>" )); + + 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(">>>ProviderFeedEntityTagsTestCase.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 + //System.out.println(">>>ProviderFeedEntityTagsTestCase.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(">>>ProviderFeedEntityTagsTestCase.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 + //System.out.println(">>>ProviderFeedEntityTagsTestCase.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(">>>ProviderFeedEntityTagsTestCase.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 + //System.out.println(">>>ProviderFeedEntityTagsTestCase.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(">>>ProviderFeedEntityTagsTestCase.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 + //System.out.println(">>>ProviderFeedEntityTagsTestCase.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(">>>ProviderFeedEntityTagsTestCase.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 { - // 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 { - res.release(); - } - } - - @Test + //System.out.println(">>>ProviderFeedEntityTagsTestCase.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 { + // 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 { + res.release(); + } + } + + @Test public void testModifiedGetIfMatch() throws Exception { - //System.out.println(">>>ProviderFeedEntityTagsTestCase.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 { - 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 + //System.out.println(">>>ProviderFeedEntityTagsTestCase.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 { + 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 testModifiedGetIfUnModified() throws Exception { - //System.out.println(">>>ProviderFeedEntityTagsTestCase.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 + //System.out.println(">>>ProviderFeedEntityTagsTestCase.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(">>>ProviderFeedEntityTagsTestCase.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); - // } - // } - - } - - /** - * 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(); - } - } - } + //System.out.println(">>>ProviderFeedEntityTagsTestCase.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); + // } + // } + + } + + /** + * 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-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderServiceDocumentTestCase.java b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderServiceDocumentTestCase.java index 89bd8ade4e..f94df3cff8 100644 --- a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderServiceDocumentTestCase.java +++ b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderServiceDocumentTestCase.java @@ -44,6 +44,8 @@ import org.junit.Test; * Tests use of service documents provided by atom binding based collections. * Uses the SCA provided Provider composite to act as a server. * Uses the Abdera provided Client to act as a client. + * + * @version $Rev$ $Date$ */ public class ProviderServiceDocumentTestCase extends AbstractProviderConsumerTestCase { public final static String providerURI = "http://localhost:8084/customer"; @@ -53,54 +55,54 @@ public class ProviderServiceDocumentTestCase extends AbstractProviderConsumerTes protected static AbderaClient client; protected static Parser abderaParser; - @BeforeClass - public static void init() throws Exception { - initTestEnvironment(AtomPostTestCase.class); + @BeforeClass + public static void init() throws Exception { + initTestEnvironment(AtomPostTestCase.class); - testService = scaConsumerNode.getService(CustomerClient.class, "CustomerClient"); + testService = scaConsumerNode.getService(CustomerClient.class, "CustomerClient"); - abdera = new Abdera(); - client = new AbderaClient(abdera); - abderaParser = Abdera.getNewParser(); - } + abdera = new Abdera(); + client = new AbderaClient(abdera); + abderaParser = Abdera.getNewParser(); + } @AfterClass public static void destroy() throws Exception { destroyTestEnvironment(); } - @Test - public void testPrelim() throws Exception { - Assert.assertNotNull(scaProviderNode); - Assert.assertNotNull(scaConsumerNode); - Assert.assertNotNull( client ); - } - - @Test + @Test + public void testPrelim() throws Exception { + Assert.assertNotNull(scaProviderNode); + Assert.assertNotNull(scaConsumerNode); + Assert.assertNotNull( client ); + } + + @Test public void testFeedBasics() throws Exception { - // Normal feed request - ClientResponse res = client.get(providerURI); - Assert.assertNotNull(res); - try { - // Assert 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. - // 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.assertTrue( -1 != body.indexOf( "</id>" )); - Assert.assertTrue( -1 != body.indexOf( "</title>" )); - Assert.assertTrue( -1 != body.indexOf( "</updated>" )); - } finally { - res.release(); - } - } + // Normal feed request + ClientResponse res = client.get(providerURI); + Assert.assertNotNull(res); + try { + // Assert 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. + // 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.assertTrue( -1 != body.indexOf( "</id>" )); + Assert.assertTrue( -1 != body.indexOf( "</title>" )); + Assert.assertTrue( -1 != body.indexOf( "</updated>" )); + } finally { + res.release(); + } + } @Test public void testServiceDocumentGet() throws Exception { @@ -114,56 +116,56 @@ public class ProviderServiceDocumentTestCase extends AbstractProviderConsumerTes postEntry = postEntry("Count Dracula"); newEntry = resourceCollection.post(postEntry); - // Service document - ClientResponse res = client.get(providerURI + "/atomsvc"); - Assert.assertNotNull(res); - try { - // Asser feed provided since no predicates - Assert.assertEquals(200, res.getStatus()); - Assert.assertEquals(ResponseType.SUCCESS, res.getType()); - - // Perform other tests on feed. - // AtomTestCaseUtils.prettyPrint(abdera, res.getDocument()); - Document<Service> serviceDoc = res.getDocument(); - Service service = serviceDoc.getRoot(); - Assert.assertNotNull( service ); - org.apache.abdera.model.Collection collection = service.getCollection( "workspace", "customers" ); - String title = collection.getTitle(); - Assert.assertEquals("customers", title); - String href = collection.getHref().toString(); - Assert.assertTrue( href.contains( "customer") ); - } finally { - res.release(); - } + // Service document + ClientResponse res = client.get(providerURI + "/atomsvc"); + Assert.assertNotNull(res); + try { + // Asser feed provided since no predicates + Assert.assertEquals(200, res.getStatus()); + Assert.assertEquals(ResponseType.SUCCESS, res.getType()); + + // Perform other tests on feed. + // AtomTestCaseUtils.prettyPrint(abdera, res.getDocument()); + Document<Service> serviceDoc = res.getDocument(); + Service service = serviceDoc.getRoot(); + Assert.assertNotNull( service ); + org.apache.abdera.model.Collection collection = service.getCollection( "workspace", "customers" ); + String title = collection.getTitle(); + Assert.assertEquals("customers", title); + String href = collection.getHref().toString(); + Assert.assertTrue( href.contains( "customer") ); + } 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); - // } - // } - - } + 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); + // } + // } + + } private Entry postEntry(String value) { Entry entry = abdera.newEntry(); @@ -178,25 +180,25 @@ public class ProviderServiceDocumentTestCase extends AbstractProviderConsumerTes } /** - * 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(); - } - } - } + * 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-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/AggregatorImpl.java b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/AggregatorImpl.java index 7bd4892372..781a670f57 100644 --- a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/AggregatorImpl.java +++ b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/AggregatorImpl.java @@ -39,7 +39,7 @@ public class AggregatorImpl implements Aggregator { @Reference(required = false) public Collection<String, Item> atomFeed1; - + @Reference(required = false) public Collection<String, Item> atomFeed2; diff --git a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/AggregatorTestCase.java b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/AggregatorTestCase.java index b407d5aac5..98e4e0ee48 100644 --- a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/AggregatorTestCase.java +++ b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/AggregatorTestCase.java @@ -63,19 +63,19 @@ public class AggregatorTestCase { node.destroy(); } } - + @Test public void testPing() throws Exception { new Socket("127.0.0.1", 8085); } - + @Test public void testAggregator() throws Exception { Entry<String, Item>[] entries = aggregatorService.getAll(); - + Assert.assertNotNull(entries); Assert.assertTrue(entries.length > 0); - + for(int pos = 0; pos < entries.length; pos++) { System.out.println(">>> Entry[" + pos + "] - " + entries[pos].getData().getTitle()); } diff --git a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/SortImpl.java b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/SortImpl.java index 13bd7fbb0e..022b1269fd 100644 --- a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/SortImpl.java +++ b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/SortImpl.java @@ -43,10 +43,10 @@ public class SortImpl implements Sort { entriesArray = (Entry<String,Item>[])entries.toArray(entriesArray);
Arrays.sort(entriesArray, new Comparator() {
public int compare(final Object xObj, final Object yObj) {
- Entry x = (Entry) xObj;
- Entry y = (Entry) yObj;
- Item xItem = (Item) x.getData();
- Item yItem = (Item) y.getData();
+ Entry x = (Entry) xObj;
+ Entry y = (Entry) yObj;
+ Item xItem = (Item) x.getData();
+ Item yItem = (Item) y.getData();
Date xDate = xItem.getDate();
Date yDate = yItem.getDate();
if (xDate == null)
diff --git a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/util/AtomTestCaseUtils.java b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/util/AtomTestCaseUtils.java index ec79fb61b9..1afad216e3 100644 --- a/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/util/AtomTestCaseUtils.java +++ b/java/sca/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/util/AtomTestCaseUtils.java @@ -31,6 +31,8 @@ import org.apache.abdera.writer.WriterFactory; /** * Utilities to help print and test various aspects of entity tag support. + * + * @version $Rev$ $Date$ */ public class AtomTestCaseUtils { @@ -39,58 +41,58 @@ public class AtomTestCaseUtils { Writer writer = factory.getWriter("prettyxml"); writer.writeTo(doc, System.out); System.out.println(); - } + } public static void printRequestHeaders( String title, String indent, RequestOptions request ) { - System.out.println( title ); - if ( request == null ) { - System.out.println( indent + " request is null"); - return; - } - String [] headerNames = request.getHeaderNames(); - for ( String headerName: headerNames) { - String header = request.getHeader(headerName); - System.out.println( indent + " header name,value=" + headerName + "," + header ); - } - } - - public static void printResponseHeaders( String title, String indent, ClientResponse response ) { - System.out.println( title ); - if ( response == null ) { - System.out.println( indent + " response is null"); - return; - } - String [] headerNames = response.getHeaderNames(); - for ( String headerName: headerNames) { - String header = response.getHeader(headerName); - System.out.println( indent + " header name,value=" + headerName + "," + header ); - } - - } + System.out.println( title ); + if ( request == null ) { + System.out.println( indent + " request is null"); + return; + } + String [] headerNames = request.getHeaderNames(); + for ( String headerName: headerNames) { + String header = request.getHeader(headerName); + System.out.println( indent + " header name,value=" + headerName + "," + header ); + } + } + + public static void printResponseHeaders( String title, String indent, ClientResponse response ) { + System.out.println( title ); + if ( response == null ) { + System.out.println( indent + " response is null"); + return; + } + String [] headerNames = response.getHeaderNames(); + for ( String headerName: headerNames) { + String header = response.getHeader(headerName); + System.out.println( indent + " header name,value=" + headerName + "," + header ); + } + + } + + public static Entry newEntry(String value) { + Abdera abdera = new Abdera(); + Entry entry = abdera.newEntry(); + entry.setTitle("customer " + value); - public static Entry newEntry(String value) { - Abdera abdera = new Abdera(); - Entry entry = abdera.newEntry(); - entry.setTitle("customer " + value); + Content content = abdera.getFactory().newContent(); + content.setContentType(Content.Type.TEXT); + content.setValue(value); + entry.setContentElement(content); - Content content = abdera.getFactory().newContent(); - content.setContentType(Content.Type.TEXT); - content.setValue(value); - entry.setContentElement(content); + return entry; + } - return entry; - } + public static Entry updateEntry(Entry entry, String value) { + Abdera abdera = new Abdera(); + entry.setTitle("customer " + value); - public static Entry updateEntry(Entry entry, String value) { - Abdera abdera = new Abdera(); - entry.setTitle("customer " + value); + Content content = abdera.getFactory().newContent(); + content.setContentType(Content.Type.TEXT); + content.setValue(value); + entry.setContentElement(content); - Content content = abdera.getFactory().newContent(); - content.setContentType(Content.Type.TEXT); - content.setValue(value); - entry.setContentElement(content); + return entry; + } - return entry; - } - } |