summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-11-20 23:53:35 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-11-20 23:53:35 +0000
commita3c48da9bb8971497d414f86e352123d95b9c3da (patch)
treefdf0f3636b65946c061c8b2e89d657b488be274e /sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache
parentcc7496466097c3cb8e793ebf3e332b025705aaa7 (diff)
Moving 2.x trunk
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@882795 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache')
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AbstractProviderConsumerTestCase.java55
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomDeleteTestCase.java118
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomFeedNonCollectionTest.java221
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomGetTestCase.java121
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPostTestCase.java110
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPutTestCase.java129
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/Consumer.java44
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ConsumerProviderAtomTestCase.java159
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ContentNegotiationTest.java259
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerClient.java33
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerClientImpl.java103
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerCollectionImpl.java153
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerNonCollectionImpl.java55
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/MediaCollectionImpl.java213
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/MediaCollectionTestCase.java295
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/Provider.java50
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderEntryEntityTagsTestCase.java433
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTestCase.java387
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderServiceDocumentTestCase.java204
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/Aggregator.java35
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/AggregatorImpl.java135
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/AggregatorTestCase.java83
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/Sort.java39
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/SortImpl.java62
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/news/Headline.java54
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/news/NewsService.java28
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/news/NewsServiceImpl.java90
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/news/NewsServiceTestCase.java78
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/util/AtomTestCaseUtils.java98
29 files changed, 3844 insertions, 0 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AbstractProviderConsumerTestCase.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AbstractProviderConsumerTestCase.java
new file mode 100644
index 0000000000..19c100483c
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AbstractProviderConsumerTestCase.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.binding.atom;
+
+import org.apache.tuscany.sca.node.Contribution;
+import org.apache.tuscany.sca.node.ContributionLocationHelper;
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+
+/**
+ *
+ * @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();
+ }
+
+ protected static void destroyTestEnvironment() throws Exception {
+ if (scaConsumerNode != null) {
+ scaConsumerNode.stop();
+ scaConsumerNode.destroy();
+ }
+ if (scaProviderNode != null) {
+ scaProviderNode.stop();
+ scaProviderNode.destroy();
+ }
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomDeleteTestCase.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomDeleteTestCase.java
new file mode 100644
index 0000000000..da3c8b7594
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomDeleteTestCase.java
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.binding.atom;
+
+import java.util.UUID;
+
+import junit.framework.Assert;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Content;
+import org.apache.abdera.model.Entry;
+import org.apache.tuscany.sca.binding.atom.collection.Collection;
+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");
+
+ initTestEnvironment(AtomDeleteTestCase.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(">>>AtomDeleteTestCase.destroy entry");
+
+ destroyTestEnvironment();
+ }
+
+ @Test
+ public void testPrelim() throws Exception {
+ Assert.assertNotNull(scaProviderNode);
+ Assert.assertNotNull(scaConsumerNode);
+ Assert.assertNotNull(testService);
+ Assert.assertNotNull(abdera);
+ }
+
+ @Test
+ public void testAtomDelete() throws Exception {
+ Collection resourceCollection = testService.getCustomerCollection();
+ Assert.assertNotNull(resourceCollection);
+
+ Entry postEntry = postEntry("Sponge Bob");
+ // System.out.println(">>> post entry= " + postEntry.getTitle());
+
+ Entry newEntry = resourceCollection.post(postEntry);
+ // System.out.println("<<< Entry posted for " + newEntry.getTitle());
+
+ // System.out.println(">>> get id=" + newEntry.getId());
+
+ resourceCollection.delete(newEntry.getId().toString());
+
+ }
+
+ @Test
+ public void testAtomDeleteException() throws Exception {
+ Collection resourceCollection = testService.getCustomerCollection();
+ Assert.assertNotNull(resourceCollection);
+
+ try {
+ // Generates custom ID
+ String id = "urn:uuid:customer-" + UUID.randomUUID().toString();
+ resourceCollection.delete(id);
+ } catch (Exception e) {
+ // ID doesn't match with the existing IDs and NotFoundException is
+ // thrown
+ Assert.assertEquals("NotFoundException", e.getClass().getSimpleName());
+ }
+
+ }
+
+ private Entry postEntry(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;
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomFeedNonCollectionTest.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomFeedNonCollectionTest.java
new file mode 100644
index 0000000000..da7683d84a
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomFeedNonCollectionTest.java
@@ -0,0 +1,221 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.binding.atom;
+
+import java.util.Date;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import junit.framework.Assert;
+
+import org.apache.abdera.model.Link;
+import org.apache.tuscany.sca.binding.atom.collection.Collection;
+import org.apache.tuscany.sca.data.collection.Entry;
+import org.apache.tuscany.sca.data.collection.Item;
+import org.apache.tuscany.sca.node.Contribution;
+import org.apache.tuscany.sca.node.ContributionLocationHelper;
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+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 {
+ /**
+ * Used to generate unique IDs for the feed entries.
+ */
+ private static final AtomicInteger ID_GEN = new AtomicInteger();
+
+ /**
+ * Data used for creating test feed entries.
+ */
+ private static final String[] FEED_ENTRY_TITLES = {"Apache Tuscany", "Apache"};
+
+ /**
+ * Data used for creating test feed entries.
+ */
+ private static final String[] FEED_ENTRY_CONTENT = {"This is Apache Tuscany", "This is Apache"};
+
+ /**
+ * Data used for creating test feed entries.
+ */
+ private static final String[] FEED_ENTRY_LINK = {"http://tuscany.apache.org", "http://www.apache.org"};
+
+ /**
+ * 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;
+
+ private static CustomerClient testService;
+
+ @BeforeClass
+ 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();
+
+ testService = scaConsumerNode.getService(CustomerClient.class, "CustomerClient");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @AfterClass
+ public static void destroy() throws Exception {
+ if (scaConsumerNode != null) {
+ scaConsumerNode.stop();
+ scaConsumerNode.destroy();
+ }
+ if (scaProviderNode != null) {
+ scaProviderNode.stop();
+ scaProviderNode.destroy();
+ }
+ }
+
+ /**
+ * Make sure everything has been initialized correctly.
+ */
+ @SuppressWarnings("unchecked")
+ @Before
+ public void testPrelim() {
+ Assert.assertNotNull(scaConsumerNode);
+ Assert.assertNotNull(scaProviderNode);
+ Assert.assertNotNull(testService);
+
+ // Add some entries to the Atom feed
+ final Entry<Object, Object>[] testEntries = new Entry[FEED_ENTRY_COUNT];
+ for (int i = 0; i < FEED_ENTRY_COUNT; i++) {
+ testEntries[i] = createFeedEntry(FEED_ENTRY_TITLES[i], FEED_ENTRY_CONTENT[i], FEED_ENTRY_LINK[i]);
+ }
+ CustomerNonCollectionImpl.entries = testEntries;
+ }
+
+ /**
+ * Post test cleanup
+ */
+ @After
+ public void testPostCleanup()
+ {
+ // Clear any old feed entries that have been added by previous tests
+ CustomerNonCollectionImpl.entries = null;
+ }
+
+ /**
+ * Test that we can retrieve entries from a feed that does not implement
+ * the Collection interface.
+ */
+ @Test
+ public void testThatCanGetFeedEntriesFromNonCollectionImplementation() {
+ // Get the entries from the feed
+ final Collection resourceCollection = testService.getCustomerCollection();
+ Assert.assertNotNull(resourceCollection);
+ final List<org.apache.abdera.model.Entry> entries = resourceCollection.getFeed().getEntries();
+
+ // Validate the feed entries
+ Assert.assertNotNull(entries);
+ Assert.assertEquals(FEED_ENTRY_COUNT, entries.size());
+ for (int i = 0; i < FEED_ENTRY_COUNT; i++) {
+ final org.apache.abdera.model.Entry entry = entries.get(i);
+ Assert.assertEquals(FEED_ENTRY_TITLES[i], entry.getTitle());
+ Assert.assertEquals(FEED_ENTRY_CONTENT[i], entry.getContent());
+ final List<Link> links = entry.getLinks();
+ Assert.assertNotNull(links);
+ Assert.assertEquals(1, links.size());
+ final Link link = links.get(0);
+ final String linkStr = link.getHref().toString();
+ Assert.assertEquals(FEED_ENTRY_LINK[i], linkStr);
+ }
+ }
+
+ /**
+ * Tests that the title of the feed can be set by the title
+ * attribute on the binding.atom
+ */
+ @Test
+ public void testThatFeedTitleSet() {
+ final String expectedFeedTitle = "Atom binding Non Collection";
+
+ // Get the title of the feed
+ final Collection resourceCollection = testService.getCustomerCollection();
+ Assert.assertNotNull(resourceCollection);
+ final String feedTitle = resourceCollection.getFeed().getTitle();
+
+ // Validate the title
+ Assert.assertEquals(expectedFeedTitle, feedTitle);
+ }
+
+ /**
+ * Tests that the description of the feed can be set by the description
+ * attribute on the binding.atom
+ */
+ @Test
+ public void testThatFeedDescriptionSet() {
+ final String expectedFeedDescription = "Feed used for unit testing";
+
+ // Get the description of the feed
+ final Collection resourceCollection = testService.getCustomerCollection();
+ Assert.assertNotNull(resourceCollection);
+ final String feedDescription = resourceCollection.getFeed().getSubtitle();
+
+ // Validate the description
+ Assert.assertEquals(expectedFeedDescription, feedDescription);
+ }
+
+ /**
+ * Creates a feed entry.
+ *
+ * @param title Title for the feed entry
+ * @param content Contents of the feed entry
+ * @param link Link for the feed entry
+ * @return A new feed entry.
+ */
+ private Entry<Object, Object> createFeedEntry(String title, String content, String link) {
+ final Item item = new Item(title, content, link, null, new Date());
+ final Entry<Object, Object> entry = new Entry<Object, Object>(nextFeedID(), item);
+ return entry;
+ }
+
+ /**
+ * Generates the feed entry ID.
+ *
+ * @return Next feed entry ID
+ */
+ private String nextFeedID() {
+ return Integer.toString(ID_GEN.incrementAndGet());
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomGetTestCase.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomGetTestCase.java
new file mode 100644
index 0000000000..7f74ef019d
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomGetTestCase.java
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.binding.atom;
+
+import junit.framework.Assert;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Content;
+import org.apache.abdera.model.Entry;
+import org.apache.tuscany.sca.binding.atom.collection.Collection;
+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;
+
+ @BeforeClass
+ public static void init() throws Exception {
+ try {
+ //System.out.println(">>>AtomGetTestCase.init entry");
+
+ initTestEnvironment(AtomFeedNonCollectionTest.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(">>>AtomGetTestCase.destroy entry");
+ destroyTestEnvironment();
+ }
+
+ @Test
+ public void testPrelim() throws Exception {
+ Assert.assertNotNull(scaProviderNode);
+ Assert.assertNotNull(scaConsumerNode);
+ Assert.assertNotNull(testService);
+ Assert.assertNotNull(abdera);
+ }
+
+ @Test
+ public void testAtomGet() throws Exception {
+ Collection resourceCollection = testService.getCustomerCollection();
+ Assert.assertNotNull(resourceCollection);
+
+ Entry postEntry = postEntry("Sponge Bob");
+ //System.out.println(">>> post entry= " + postEntry.getTitle());
+
+ Entry newEntry = resourceCollection.post(postEntry);
+ //System.out.println("<<< Entry posted for " + newEntry.getTitle());
+
+ //System.out.println(">>> get id=" + newEntry.getId());
+
+ Entry getEntry = resourceCollection.get(newEntry.getId().toString());
+
+ Assert.assertEquals(newEntry.getTitle(), getEntry.getTitle());
+ //System.out.println("<<< get id=" + getEntry.getId() + " entry=" + getEntry.getTitle());
+ }
+
+ @Test
+ public void testAtomGetException() throws Exception {
+ Collection resourceCollection = testService.getCustomerCollection();
+ Assert.assertNotNull(resourceCollection);
+
+ Entry postEntry = postEntry("Sponge Bob");
+ //System.out.println(">>> post entry= " + postEntry.getTitle());
+
+ Entry newEntry = resourceCollection.post(postEntry);
+ //System.out.println("<<< Entry posted for " + newEntry.getTitle());
+ //System.out.println(newEntry.getId());
+
+ // Delete the entry to force the Collection to throw NotFoundException
+ resourceCollection.delete(newEntry.getId().toString());
+
+ try {
+ resourceCollection.get(newEntry.getId().toString());
+ } catch (Exception e) {
+ Assert.assertEquals("NotFoundException", e.getClass().getSimpleName());
+ }
+ }
+
+ private Entry postEntry(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;
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPostTestCase.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPostTestCase.java
new file mode 100644
index 0000000000..50a684beba
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPostTestCase.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.binding.atom;
+
+import junit.framework.Assert;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Content;
+import org.apache.abdera.model.Entry;
+import org.apache.tuscany.sca.binding.atom.collection.Collection;
+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;
+
+ @BeforeClass
+ public static void init() throws Exception {
+ try {
+ //System.out.println(">>>AtomPostTestCase.init entry");
+
+ initTestEnvironment(AtomPostTestCase.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(">>>AtomPostTestCase.destroy entry");
+
+ destroyTestEnvironment();
+ }
+
+ @Test
+ public void testPrelim() throws Exception {
+ Assert.assertNotNull(scaProviderNode);
+ Assert.assertNotNull(scaConsumerNode);
+ Assert.assertNotNull(testService);
+ Assert.assertNotNull(abdera);
+ }
+
+ @Test
+ public void testAtomPost() throws Exception {
+ Collection resourceCollection = testService.getCustomerCollection();
+ Assert.assertNotNull(resourceCollection);
+
+ Entry postEntry = postEntry("Sponge Bob");
+ //System.out.println(">>> post entry= " + postEntry.getTitle());
+
+ Entry newEntry = resourceCollection.post(postEntry);
+
+ Assert.assertEquals(postEntry.getTitle(), newEntry.getTitle());
+
+ //System.out.println("<<< new entry= " + newEntry.getTitle());
+
+ }
+
+ @Test
+ public void testAtomPostException() throws Exception {
+ Collection resourceCollection = testService.getCustomerCollection();
+ Assert.assertNotNull(resourceCollection);
+
+ Entry postEntry = postEntry("Exception_Test");
+
+ try {
+ resourceCollection.post(postEntry);
+ } catch (Exception e) {
+ Assert.assertEquals("HTTP status code: 500", e.getMessage());
+ }
+ }
+
+ private Entry postEntry(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;
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPutTestCase.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPutTestCase.java
new file mode 100644
index 0000000000..4e09eea032
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPutTestCase.java
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.binding.atom;
+
+import java.util.UUID;
+
+import junit.framework.Assert;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Content;
+import org.apache.abdera.model.Entry;
+import org.apache.tuscany.sca.binding.atom.collection.Collection;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class AtomPutTestCase extends AbstractProviderConsumerTestCase {
+
+ protected static CustomerClient testService;
+ protected static Abdera abdera;
+
+ @BeforeClass
+ public static void init() throws Exception {
+ try {
+ //System.out.println(">>>AtomPutTestCase.init entry");
+
+ initTestEnvironment(AtomPutTestCase.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(">>>AtomPutTestCase.destroy entry");
+
+ destroyTestEnvironment();
+ }
+
+ @Test
+ public void testPrelim() throws Exception {
+ Assert.assertNotNull(scaProviderNode);
+ Assert.assertNotNull(scaConsumerNode);
+ Assert.assertNotNull(testService);
+ Assert.assertNotNull(abdera);
+ }
+
+ @Test
+ public void testAtomPut() throws Exception {
+ Collection resourceCollection = testService.getCustomerCollection();
+ Assert.assertNotNull(resourceCollection);
+
+ Entry postEntry = postEntry("Sponge Bob");
+ //System.out.println(">>> post entry= " + postEntry.getTitle());
+
+ Entry newEntry = resourceCollection.post(postEntry);
+ //System.out.println("<<< Entry posted for " + newEntry.getTitle());
+ //System.out.println(newEntry.getId());
+
+ //System.out.println(">>> put id=" + newEntry.getId() + " entry=" + newEntry.getTitle());
+ resourceCollection.put(newEntry.getId().toString(), updateEntry(newEntry, "James Bond"));
+ //System.out.println("<<< put id=" + newEntry.getId() + " entry=" + newEntry.getTitle());
+ }
+
+ @Test
+ public void testAtomPutException() throws Exception {
+ Collection resourceCollection = testService.getCustomerCollection();
+ Assert.assertNotNull(resourceCollection);
+
+ Entry postEntry = postEntry("Sponge Bob");
+ //System.out.println(">>> post entry= " + postEntry.getTitle());
+
+ // Generate random ID to pass as parameter in PUT() --
+ String id = "urn:uuid:customer-" + UUID.randomUUID().toString();
+ try {
+ // ID doesn't match with the existing IDs and NotFoundException is thrown
+ resourceCollection.put(id, updateEntry(postEntry, "James Bond"));
+ } catch (Exception e) {
+ Assert.assertEquals("NotFoundException", e.getClass().getSimpleName());
+ }
+ }
+
+ private Entry postEntry(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;
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/Consumer.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/Consumer.java
new file mode 100644
index 0000000000..e93c1aeea6
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/Consumer.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.binding.atom;
+
+import org.apache.tuscany.sca.node.Contribution;
+import org.apache.tuscany.sca.node.ContributionLocationHelper;
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class Consumer {
+
+ public static void main(String[] args) throws Exception {
+
+ String contribution = ContributionLocationHelper.getContributionLocation(Consumer.class);
+ Node node = NodeFactory.newInstance().createNode("org/apache/tuscany/sca/binding/atom/Consumer.composite",new Contribution("c1", contribution));
+
+ CustomerClient testService = node.getService(CustomerClient.class, "CustomerClient");
+ testService.testCustomerCollection();
+
+ node.stop();
+ node.destroy();
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ConsumerProviderAtomTestCase.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ConsumerProviderAtomTestCase.java
new file mode 100644
index 0000000000..07909388e1
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ConsumerProviderAtomTestCase.java
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.binding.atom;
+
+import java.util.Date;
+
+import junit.framework.Assert;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Content;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+import org.apache.tuscany.sca.binding.atom.collection.Collection;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+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;
+ }
+} \ No newline at end of file
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ContentNegotiationTest.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ContentNegotiationTest.java
new file mode 100644
index 0000000000..b707c71d2b
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ContentNegotiationTest.java
@@ -0,0 +1,259 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.binding.atom;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.util.Date;
+
+import junit.framework.Assert;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.factory.Factory;
+import org.apache.abdera.i18n.iri.IRI;
+import org.apache.abdera.model.Content;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+import org.apache.abdera.parser.Parser;
+import org.apache.abdera.protocol.Response.ResponseType;
+import org.apache.abdera.protocol.client.AbderaClient;
+import org.apache.abdera.protocol.client.ClientResponse;
+import org.apache.abdera.protocol.client.RequestOptions;
+import org.apache.tuscany.sca.node.Contribution;
+import org.apache.tuscany.sca.node.ContributionLocationHelper;
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+
+/**
+ * Tests use of 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();
+ }
+ }
+
+ @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);
+
+ 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);
+
+ // 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 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 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());
+
+ // 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();
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerClient.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerClient.java
new file mode 100644
index 0000000000..85c4d4f56a
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerClient.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+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/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerClientImpl.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerClientImpl.java
new file mode 100644
index 0000000000..4e3b8241f8
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerClientImpl.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.binding.atom;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Content;
+import org.apache.abdera.model.Entry;
+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;
+
+ public void testCustomerCollection() throws Exception {
+
+ Entry newEntry = newEntry("Sponge Bob");
+ //System.out.println(">>> post entry=" + newEntry.getTitle());
+ newEntry = customerCollection.post(newEntry);
+ //System.out.println("<<< post id=" + newEntry.getId() + " entry=" + newEntry.getTitle());
+
+ newEntry = newEntry("Jane Bond");
+ //System.out.println(">>> post entry=" + newEntry.getTitle());
+ newEntry = customerCollection.post(newEntry);
+ //System.out.println("<<< post id=" + newEntry.getId() + " entry=" + newEntry.getTitle());
+
+ //System.out.println(">>> get id=" + newEntry.getId());
+ Entry entry = customerCollection.get(newEntry.getId().toString());
+ //System.out.println("<<< get id=" + entry.getId() + " entry=" + entry.getTitle());
+
+ //System.out.println(">>> put id=" + newEntry.getId() + " entry=" + entry.getTitle());
+ customerCollection.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());
+ customerCollection.delete(entry.getId().toString());
+ //System.out.println("<<< delete id=" + entry.getId());
+
+ //System.out.println(">>> get collection");
+ Feed feed = customerCollection.getFeed();
+ //System.out.println("<<< get collection");
+ for (Object o : feed.getEntries()) {
+ Entry e = (Entry)o;
+ //System.out.println("id = " + e.getId() + " entry = " + e.getTitle());
+ }
+ }
+
+ public Collection getCustomerCollection() {
+ return customerCollection;
+ }
+
+ private Entry newEntry(String value) {
+
+ Entry entry = this.abdera.newEntry();
+ entry.setTitle("customer " + value);
+
+ Content content = this.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 = this.abdera.getFactory().newContent();
+ content.setContentType(Content.Type.TEXT);
+ content.setValue(value);
+
+ entry.setContentElement(content);
+
+ return entry;
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerCollectionImpl.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerCollectionImpl.java
new file mode 100644
index 0000000000..9e50cbbae7
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerCollectionImpl.java
@@ -0,0 +1,153 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.binding.atom;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Content;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+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
+ */
+ public CustomerCollectionImpl() {
+
+ }
+
+ public Entry post(Entry entry) {
+ //System.out.println(">>> CustomerCollectionImpl.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);
+
+ //System.out.println(">>> CustomerCollectionImpl.post return id=" + id);
+
+ return entry;
+
+ }
+ else
+ {
+ throw new IllegalArgumentException("Exception in Post method");
+ }
+ }
+
+ public Entry get(String id) {
+ //System.out.println(">>> CustomerCollectionImpl.get id=" + id);
+ return entries.get(id);
+ }
+
+ 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;
+ entries.put(id, entry);
+ }
+ else {
+ 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();
+ }
+ else {
+ throw new NotFoundException();
+ }
+ }
+
+ public Feed getFeed() {
+ //System.out.println(">>> CustomerCollectionImpl.getFeed");
+
+ Feed feed = this.abdera.getFactory().newFeed();
+ feed.setId("customers" + this.hashCode() ); // provide unique id for feed instance.
+ feed.setTitle("customers");
+ feed.setSubtitle("This is a sample feed");
+ feed.setUpdated(lastModified);
+ feed.addLink("");
+ feed.addLink("", "self");
+
+ for (Entry entry : entries.values()) {
+ feed.addEntry(entry);
+ }
+
+ return feed;
+ }
+
+ public Feed query(String queryString) {
+ //System.out.println(">>> CustomerCollectionImpl.query collection " + queryString);
+ return getFeed();
+ }
+
+ // This method used for testing.
+ protected void testPut(String value) {
+ String id = "urn:uuid:customer-" + UUID.randomUUID().toString();
+
+ Entry entry = abdera.getFactory().newEntry();
+ entry.setId(id);
+ entry.setTitle("customer " + value);
+
+ Content content = this.abdera.getFactory().newContent();
+ content.setContentType(Content.Type.TEXT);
+ content.setValue(value);
+
+ entry.setContentElement(content);
+
+ entry.addLink("" + id, "edit");
+ entry.addLink("" + id, "alternate");
+
+ entry.setUpdated(new Date());
+
+ entries.put(id, entry);
+ System.out.println(">>> id=" + id);
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerNonCollectionImpl.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerNonCollectionImpl.java
new file mode 100644
index 0000000000..dbf6b5aed5
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerNonCollectionImpl.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.binding.atom;
+
+import org.apache.tuscany.sca.data.collection.Entry;
+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 {
+ /**
+ * All feed entries.
+ * This is set directly by the unit tests.
+ * @see AtomFeedNonCollectionTest
+ */
+ public static Entry<Object, Object>[] entries;
+
+ /**
+ * Default constructor
+ */
+ public CustomerNonCollectionImpl() {
+ }
+
+ /**
+ * Get all entries for this feed.
+ *
+ * @return All entries for this feed
+ */
+ public Entry<Object, Object>[] getAll() {
+ return entries;
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/MediaCollectionImpl.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/MediaCollectionImpl.java
new file mode 100644
index 0000000000..8ff89030db
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/MediaCollectionImpl.java
@@ -0,0 +1,213 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.binding.atom;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.factory.Factory;
+import org.apache.abdera.i18n.iri.IRI;
+import org.apache.abdera.model.Content;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+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);
+
+ //System.out.println(">>> MediaCollectionImpl.post return id=" + id);
+
+ return entry;
+
+ }
+ else
+ {
+ throw new IllegalArgumentException("Exception in Post method");
+ }
+ }
+
+ public Entry get(String id) {
+ //System.out.println(">>> MediaCollectionImpl.get id=" + id);
+ return entries.get(id);
+ }
+
+ 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;
+ entries.put(id, entry);
+ }
+ else {
+ 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();
+ }
+ else {
+ throw new NotFoundException();
+ }
+ }
+
+ public Feed getFeed() {
+ //System.out.println(">>> MediaCollectionImpl.getFeed");
+
+ Feed feed = this.abdera.getFactory().newFeed();
+ feed.setId("customers" + this.hashCode() ); // provide unique id for feed instance.
+ feed.setTitle("customers");
+ feed.setSubtitle("This is a sample feed");
+ feed.setUpdated(lastModified);
+ feed.addLink("");
+ feed.addLink("", "self");
+
+ for (Entry entry : entries.values()) {
+ feed.addEntry(entry);
+ }
+
+ return feed;
+ }
+
+ public Feed query(String queryString) {
+ //System.out.println(">>> MediaCollectionImpl.query collection " + queryString);
+ return getFeed();
+ }
+
+ // This method used for testing.
+ protected void testPut(String value) {
+ String id = "urn:uuid:customer-" + UUID.randomUUID().toString();
+
+ Entry entry = abdera.getFactory().newEntry();
+ entry.setId(id);
+ entry.setTitle("customer " + value);
+
+ Content content = this.abdera.getFactory().newContent();
+ content.setContentType(Content.Type.TEXT);
+ content.setValue(value);
+
+ entry.setContentElement(content);
+
+ entry.addLink("" + id, "edit");
+ entry.addLink("" + id, "alternate");
+
+ entry.setUpdated(new Date());
+
+ entries.put(id, entry);
+ System.out.println(">>> id=" + id);
+ }
+
+ // MediaCollection role
+ public Entry postMedia(String title, String slug, String contentType, InputStream media) {
+ //System.out.println(">>> MediaCollectionImpl.postMedia title=" + title + ", slug=" + slug + ", contentType=" + contentType );
+
+ Factory factory = abdera.getFactory();
+ Entry entry = factory.newEntry();
+ // Must provide entry to media as per Atom Pub spec (http://tools.ietf.org/html/rfc5023#section-9.6)
+ // <?xml version="1.0"?>
+ // <entry xmlns="http://www.w3.org/2005/Atom">
+ // <title>The Beach</title> (REQUIRED)
+ // <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id> (REQUIRED)
+ // <updated>2005-10-07T17:17:08Z</updated>
+ // <summary type="text" /> (REQUIRED, OPTIONAL to populate
+ // <content type="image/png" src="http://media.example.org/the_beach.png"/>
+ // <link rel="edit-media" href="http://media.example.org/edit/the_beach.png" />
+ // <link rel="edit" href="http://example.org/media/edit/the_beach.atom" />
+ // </entry>
+
+ // Normalize 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 );
+ } else {
+ extension = contentType;
+ }
+ long mediaLength = -1;
+ try {
+ 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();
+ String reposLocation = hostURL + "edit/" + normalTitle;
+ 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;
+ }
+
+ public void putMedia(String id, String contentType, InputStream media) throws NotFoundException {
+ //System.out.println(">>> MediaCollectionImpl.putMedia id=" + id + ", contentType=" + contentType );
+
+ // 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." );
+
+ // A true implementation would update the media in the media repository.
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/MediaCollectionTestCase.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/MediaCollectionTestCase.java
new file mode 100644
index 0000000000..2870002c66
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/MediaCollectionTestCase.java
@@ -0,0 +1,295 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.binding.atom;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import junit.framework.Assert;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.i18n.iri.IRI;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Link;
+import org.apache.abdera.parser.Parser;
+import org.apache.abdera.protocol.client.AbderaClient;
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.tuscany.sca.node.Contribution;
+import org.apache.tuscany.sca.node.ContributionLocationHelper;
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Tests use of server provided entry entity tags for Atom binding in Tuscany.
+ * Tests conditional gets (e.g. get if-none-match) or conditional posts (post if-match)
+ * using entity tags 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";
+
+ protected static Node scaProviderNode;
+
+ protected static CustomerClient testService;
+ protected static Abdera abdera;
+ protected static AbderaClient client;
+ protected static Parser abderaParser;
+ protected static String eTag;
+ protected static Date lastModified;
+ 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();
+ }
+ }
+
+ @AfterClass
+ public static void destroy() throws Exception {
+ System.out.println(">>>MediaCollectionTestCase.destroy");
+ if (scaProviderNode != null) {
+ scaProviderNode.stop();
+ scaProviderNode.destroy();
+ }
+ }
+
+ @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
+ // 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 );
+
+ // Prepare HTTP post
+ // PostMethod post = new PostMethod( colUri.toString() );
+ PostMethod post = new PostMethod( providerURI );
+ post.addRequestHeader( "Content-Type", "image/gif" );
+ 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
+ // 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.
+ // HTTP/1.1 201 Created
+ // Display status code
+ // System.out.println("Response status code: " + result + ", status text=" + post.getStatusText() );
+ 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() );
+ // 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() );
+ // 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() );
+ // 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() );
+ // <?xml version="1.0"?>
+ // <entry xmlns="http://www.w3.org/2005/Atom">
+ // <title>The Beach</title> (REQUIRED)
+ // <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id> (REQUIRED)
+ // <updated>2005-10-07T17:17:08Z</updated>
+ // <author><name>Daffy</name></author>
+ // <summary type="text" /> (REQUIRED, OPTIONAL to populate
+ // <content type="image/png" src="http://media.example.org/the_beach.png"/>
+ // <link rel="edit-media" href="http://media.example.org/edit/the_beach.png" />
+ // <link rel="edit" href="http://example.org/media/edit/the_beach.atom" />
+ // </entry>
+ Document<Entry> document = abderaParser.parse( post.getResponseBodyAsStream() );
+ Entry entry = document.getRoot();
+ String title = entry.getTitle();
+ // System.out.println( "mediaPost entry.title=" + title );
+ Assert.assertNotNull( title );
+ IRI id = entry.getId();
+ // System.out.println( "mediaPost entry.id=" + id );
+ Assert.assertNotNull( id );
+ mediaId = id.toString();
+ Assert.assertNotNull( mediaId ); // Save for put/update request
+ Date updated = entry.getUpdated();
+ // System.out.println( "mediaPost entry.updated=" + updated);
+ Assert.assertNotNull( updated );
+ String summary = entry.getSummary();
+ // System.out.println( "mediaPost entry.summary=" + summary);
+ Assert.assertNotNull( summary );
+ IRI contentSrc = entry.getContentSrc();
+ // 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() );
+ 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() );
+
+ } finally {
+ // Release current connection to the connection pool once you are done
+ post.releaseConnection();
+ }
+ }
+
+ @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...
+ 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" ) );
+
+ // Get HTTP client
+ HttpClient httpclient = new HttpClient();
+ try {
+ // Execute request
+ int result = httpclient.executeMethod(put);
+ // 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 );
+ // Display response. Should be empty for put.
+ // System.out.println("Response body: ");
+ // System.out.println(put.getResponseBodyAsString()); // Warning: BodyAsString recommends BodyAsStream
+ } finally {
+ // 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 );
+
+ // 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...
+ 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" ) );
+
+ // Get HTTP client
+ HttpClient httpclient = new HttpClient();
+ try {
+ // Execute request
+ int result = httpclient.executeMethod(put);
+ // 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 );
+ // Display response. Should be empty for put.
+ // System.out.println("Response body: ");
+ // System.out.println(put.getResponseBodyAsString()); // Warning: BodyAsString recommends BodyAsStream
+ } finally {
+ // Release current connection to the connection pool once you are done
+ put.releaseConnection();
+ }
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/Provider.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/Provider.java
new file mode 100644
index 0000000000..f802d3891f
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/Provider.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.binding.atom;
+
+import java.io.IOException;
+
+import org.apache.tuscany.sca.node.Contribution;
+import org.apache.tuscany.sca.node.ContributionLocationHelper;
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class Provider {
+
+ public static void main(String[] args) {
+
+ String contribution = ContributionLocationHelper.getContributionLocation(Provider.class);
+ Node node = NodeFactory.newInstance().createNode("org/apache/tuscany/sca/binding/atom/Provider.composite", new Contribution("c1", contribution));
+ System.out.println("Provider.composite ready...");
+
+ try {
+ System.in.read();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ node.stop();
+ node.destroy();
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderEntryEntityTagsTestCase.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderEntryEntityTagsTestCase.java
new file mode 100644
index 0000000000..534c2c901f
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderEntryEntityTagsTestCase.java
@@ -0,0 +1,433 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.binding.atom;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import junit.framework.Assert;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.factory.Factory;
+import org.apache.abdera.i18n.iri.IRI;
+import org.apache.abdera.model.Content;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.parser.Parser;
+import org.apache.abdera.protocol.client.AbderaClient;
+import org.apache.abdera.protocol.client.ClientResponse;
+import org.apache.abdera.protocol.client.RequestOptions;
+import org.apache.abdera.protocol.client.util.BaseRequestEntity;
+import org.apache.tuscany.sca.node.Contribution;
+import org.apache.tuscany.sca.node.ContributionLocationHelper;
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Tests use of server provided entry entity tags for Atom binding in Tuscany.
+ * Tests conditional gets (e.g. get if-none-match) or conditional posts (post if-match)
+ * using entity tags 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";
+
+ protected static Node scaProviderNode;
+
+ protected static CustomerClient testService;
+ protected static Abdera abdera;
+ protected static AbderaClient client;
+ protected static Parser abderaParser;
+ protected static String eTag;
+ protected static Date lastModified;
+ protected static final SimpleDateFormat dateFormat = new SimpleDateFormat( "EEE, dd MMM yyyy HH:mm:ss Z" ); // RFC 822 date time
+
+ @BeforeClass
+ public static void init() throws Exception {
+ //System.out.println(">>>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();
+
+ abdera = new Abdera();
+ client = new AbderaClient(abdera);
+ abderaParser = Abdera.getNewParser();
+ }
+
+ @AfterClass
+ public static void destroy() throws Exception {
+ //System.out.println(">>>ProviderEntryEntityTagsTestCase.destroy");
+ if (scaProviderNode != null) {
+ scaProviderNode.stop();
+ scaProviderNode.destroy();
+ }
+ }
+
+ @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.
+ // 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);
+ 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();
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTestCase.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTestCase.java
new file mode 100644
index 0000000000..b091045b8c
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTestCase.java
@@ -0,0 +1,387 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.binding.atom;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import junit.framework.Assert;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.factory.Factory;
+import org.apache.abdera.i18n.iri.IRI;
+import org.apache.abdera.model.Collection;
+import org.apache.abdera.model.Content;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+import org.apache.abdera.parser.Parser;
+import org.apache.abdera.protocol.Response.ResponseType;
+import org.apache.abdera.protocol.client.AbderaClient;
+import org.apache.abdera.protocol.client.ClientResponse;
+import org.apache.abdera.protocol.client.RequestOptions;
+import org.apache.tuscany.sca.node.Contribution;
+import org.apache.tuscany.sca.node.ContributionLocationHelper;
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Tests use of server provided feed entity tags for Atom binding in Tuscany.
+ * Tests conditional gets (e.g. get if-none-match) or conditional posts (post if-match)
+ * using entity tags and last modified entries in headers.
+ * Uses the SCA provided Provider composite to act as a server.
+ * Uses the Abdera provided Client to act as a client.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ProviderFeedEntityTagsTestCase {
+ 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 eTag;
+ protected static Date lastModified;
+ protected static final SimpleDateFormat dateFormat = new SimpleDateFormat( "EEE, dd MMM yyyy HH:mm:ss Z" ); // RFC 822 date time
+
+ @BeforeClass
+ public static void init() throws Exception {
+ //System.out.println(">>>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();
+
+ abdera = new Abdera();
+ client = new AbderaClient(abdera);
+ abderaParser = Abdera.getNewParser();
+ }
+
+ @AfterClass
+ public static void destroy() throws Exception {
+ //System.out.println(">>>ProviderFeedEntityTagsTestCase.destroy");
+ if (scaProviderNode != null) {
+ scaProviderNode.stop();
+ scaProviderNode.destroy();
+ }
+ }
+
+ @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
+ 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
+ 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 @Ignore Intermitently fails, see TUSCANY-3299
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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();
+ }
+ }
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderServiceDocumentTestCase.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderServiceDocumentTestCase.java
new file mode 100644
index 0000000000..f94df3cff8
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderServiceDocumentTestCase.java
@@ -0,0 +1,204 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.binding.atom;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+import junit.framework.Assert;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Content;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+import org.apache.abdera.model.Service;
+import org.apache.abdera.parser.Parser;
+import org.apache.abdera.protocol.Response.ResponseType;
+import org.apache.abdera.protocol.client.AbderaClient;
+import org.apache.abdera.protocol.client.ClientResponse;
+import org.apache.tuscany.sca.binding.atom.collection.Collection;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+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";
+
+ protected static CustomerClient testService;
+ protected static Abdera abdera;
+ protected static AbderaClient client;
+ protected static Parser abderaParser;
+
+ @BeforeClass
+ public static void init() throws Exception {
+ initTestEnvironment(AtomPostTestCase.class);
+
+ testService = scaConsumerNode.getService(CustomerClient.class, "CustomerClient");
+
+ 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
+ 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();
+ }
+ }
+
+ @Test
+ public void testServiceDocumentGet() throws Exception {
+ Collection resourceCollection = testService.getCustomerCollection();
+ Assert.assertNotNull(resourceCollection);
+
+ Entry postEntry = postEntry("Sponge Bob");
+ Entry newEntry = resourceCollection.post(postEntry);
+ postEntry = postEntry("Austin Powers");
+ newEntry = resourceCollection.post(postEntry);
+ 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();
+ }
+ }
+
+ 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();
+ entry.setTitle("customer " + value);
+
+ Content content = abdera.getFactory().newContent();
+ content.setContentType(Content.Type.TEXT);
+ content.setValue(value);
+ entry.setContentElement(content);
+
+ return entry;
+ }
+
+ /**
+ * Read response ream from the given socket.
+ * @param socket
+ * @return
+ * @throws IOException
+ */
+ private static String read(InputStream inputStream) throws IOException {
+ BufferedReader reader = null;
+ try {
+ reader = new BufferedReader(new InputStreamReader( inputStream ));
+ StringBuffer sb = new StringBuffer();
+ String str;
+ while ((str = reader.readLine()) != null) {
+ sb.append(str);
+ }
+ return sb.toString();
+ } finally {
+ if (reader != null) {
+ reader.close();
+ }
+ }
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/Aggregator.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/Aggregator.java
new file mode 100644
index 0000000000..e10d442953
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/Aggregator.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.binding.atom.aggregator;
+
+import org.apache.tuscany.sca.data.collection.Collection;
+import org.apache.tuscany.sca.data.collection.Item;
+import org.oasisopen.sca.annotation.Remotable;
+
+
+/**
+ * Aggreator interface
+ *
+ * @version $Rev$ $Date$
+ */
+@Remotable
+public interface Aggregator extends Collection<String, Item>{
+
+}
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/AggregatorImpl.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/AggregatorImpl.java
new file mode 100644
index 0000000000..781a670f57
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/AggregatorImpl.java
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.binding.atom.aggregator;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.data.collection.Collection;
+import org.apache.tuscany.sca.data.collection.Entry;
+import org.apache.tuscany.sca.data.collection.Item;
+import org.apache.tuscany.sca.data.collection.NotFoundException;
+import org.oasisopen.sca.annotation.Property;
+import org.oasisopen.sca.annotation.Reference;
+
+
+/**
+ * Aggregator impl
+ *
+ * @version $Rev$ $Date$
+ */
+public class AggregatorImpl implements Aggregator {
+
+ @Reference(required = false)
+ public Collection<String, Item> atomFeed1;
+
+ @Reference(required = false)
+ public Collection<String, Item> atomFeed2;
+
+ @Reference(required = false)
+ public Sort sort;
+
+ @Property
+ public String feedTitle = "Aggregated Feed";
+ @Property
+ public String feedDescription = "Anonymous Aggregated Feed";
+ @Property
+ public String feedAuthor = "anonymous";
+
+ public Item get(String id) {
+
+ try {
+ if (atomFeed1.get(id) != null)
+ return atomFeed1.get(id);
+ } catch (NotFoundException ex) {
+ ex.printStackTrace();
+ }
+
+ try {
+ if (atomFeed2.get(id) != null)
+ return atomFeed2.get(id);
+ } catch (NotFoundException ex) {
+ ex.printStackTrace();
+ }
+
+ return null;
+
+ }
+
+ @SuppressWarnings("unchecked")
+ public Entry<String, Item>[] getAll() {
+
+ // Aggregate entries from atomFeed1, atomFeed2, rssFeed1 and rssFeed2
+ List<Entry> entries = new ArrayList<Entry>();
+ if (atomFeed1 != null) {
+ try {
+ for (Entry entry : atomFeed1.getAll()) {
+ entries.add(entry);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ if (atomFeed2 != null) {
+ try {
+ for (Entry entry : atomFeed2.getAll()) {
+ entries.add(entry);
+ }
+ } catch (Exception e) {
+ }
+ }
+
+ // Sort entries by published date
+ if (sort != null) {
+ entries = sort.sort(entries);
+ }
+
+ return entries.toArray(new Entry[entries.size()]);
+
+ }
+
+ public String post(String key, Item entry) {
+ return null;
+ }
+
+ public void put(String id, Item entry) {
+ }
+
+ @SuppressWarnings("unchecked")
+ public Entry<String, Item>[] query(String queryString) {
+ ArrayList<Entry> entries = new ArrayList<Entry>();
+
+ Entry<String, Item>[] allFeed = getAll();
+ if (queryString.startsWith("title=")) {
+ String title = queryString.substring(6);
+
+ for (Entry<String, Item> entry : allFeed) {
+ if (entry.getData().getTitle().contains(title)) {
+ entries.add(entry);
+ }
+ }
+ }
+ return entries.toArray(new Entry[entries.size()]);
+ }
+
+ public void delete(String id) {
+
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/AggregatorTestCase.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/AggregatorTestCase.java
new file mode 100644
index 0000000000..98e4e0ee48
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/AggregatorTestCase.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.binding.atom.aggregator;
+
+import java.net.Socket;
+
+import org.apache.tuscany.sca.data.collection.Entry;
+import org.apache.tuscany.sca.data.collection.Item;
+import org.apache.tuscany.sca.node.Contribution;
+import org.apache.tuscany.sca.node.ContributionLocationHelper;
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Agregattor test case
+ *
+ * @version $Rev$ $Date$
+ */
+public class AggregatorTestCase {
+ private static Node node;
+
+ private static Aggregator aggregatorService;
+
+ @BeforeClass
+ public static void init() throws Exception {
+ try {
+ String contribution = ContributionLocationHelper.getContributionLocation(AggregatorTestCase.class);
+ node = NodeFactory.newInstance().createNode("org/apache/tuscany/sca/binding/atom/aggregator/FeedAggregator.composite", new Contribution("test", contribution));
+ node.start();
+
+ aggregatorService = node.getService(Aggregator.class, "AtomAggregator/Aggregator");
+ Assert.assertNotNull(aggregatorService);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @AfterClass
+ public static void destroy() throws Exception {
+ if(node != null) {
+ node.stop();
+ 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/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/Sort.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/Sort.java
new file mode 100644
index 0000000000..28ea465968
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/Sort.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.binding.atom.aggregator;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.data.collection.Entry;
+
+/**
+ * The Sort service business interface.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Sort {
+
+ /**
+ * Sort feed entries by published date.
+ * @param entries
+ * @return
+ */
+ @SuppressWarnings("unchecked")
+ List<Entry> sort(List<Entry> entries);
+}
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/SortImpl.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/SortImpl.java
new file mode 100644
index 0000000000..022b1269fd
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/aggregator/SortImpl.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.binding.atom.aggregator;
+
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.tuscany.sca.data.collection.Entry;
+import org.apache.tuscany.sca.data.collection.Item;
+import org.oasisopen.sca.annotation.Property;
+
+/**
+ * Implementation of a Feed Sort service component.
+ *
+ * @version $Rev$ $Date$
+ */
+public class SortImpl implements Sort {
+
+ @Property
+ public boolean newFirst = true;
+
+ @SuppressWarnings("unchecked")
+ public List<Entry> sort(List<Entry> entries) {
+ Entry[] entriesArray = new Entry[entries.size()];
+ 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();
+ Date xDate = xItem.getDate();
+ Date yDate = yItem.getDate();
+ if (xDate == null)
+ return -1;
+ if (newFirst)
+ return yDate.compareTo(xDate);
+ else
+ return xDate.compareTo(yDate);
+ }
+ });
+ return Arrays.asList(entriesArray);
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/news/Headline.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/news/Headline.java
new file mode 100644
index 0000000000..95152af73d
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/news/Headline.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.binding.atom.news;
+
+import java.io.Serializable;
+
+public class Headline implements Serializable {
+ private static final long serialVersionUID = 2516853242307046775L;
+
+ private String text;
+ private String source;
+
+ public Headline() {
+
+ }
+
+ public Headline(String text, String source) {
+ this.text = text;
+ this.source = text;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setSoure(String source) {
+ this.source = source;
+ }
+
+ public String getSource() {
+ return source;
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/news/NewsService.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/news/NewsService.java
new file mode 100644
index 0000000000..ab97f4e340
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/news/NewsService.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.binding.atom.news;
+
+import org.apache.tuscany.sca.data.collection.Collection;
+import org.oasisopen.sca.annotation.Remotable;
+
+@Remotable
+public interface NewsService extends Collection<String, Headline>{
+
+}
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/news/NewsServiceImpl.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/news/NewsServiceImpl.java
new file mode 100644
index 0000000000..7e40bb797d
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/news/NewsServiceImpl.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.binding.atom.news;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.sca.data.collection.Entry;
+import org.apache.tuscany.sca.data.collection.NotFoundException;
+import org.oasisopen.sca.annotation.Init;
+import org.oasisopen.sca.annotation.Service;
+
+@Service(NewsService.class)
+public class NewsServiceImpl implements NewsService {
+ private Map<String, Headline> headlines = new HashMap<String,Headline>();
+
+ @Init
+ public void init() {
+ Headline headline;
+
+ headline = new Headline();
+ headline.setSoure("http://www.domain.com/source1");
+ headline.setText("headline text 1111");
+
+ headlines.put("h1", headline);
+
+
+ headline = new Headline();
+ headline.setSoure("http://www.domain.com/source2");
+ headline.setText("headline text 2222");
+
+ headlines.put("h2", headline);
+ }
+
+ public Entry<String, Headline>[] getAll() {
+ Entry<String, Headline>[] entries = new Entry[headlines.size()];
+ int i = 0;
+ for (Map.Entry<String, Headline> e: headlines.entrySet()) {
+ entries[i++] = new Entry<String, Headline>(e.getKey(), e.getValue());
+ }
+ return entries;
+ }
+
+ public Headline get(String key) throws NotFoundException {
+ Headline item = headlines.get(key);
+ if (item == null) {
+ throw new NotFoundException(key);
+ } else {
+ return item;
+ }
+ }
+
+ public String post(String key, Headline item) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void put(String key, Headline item) throws NotFoundException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public Entry<String, Headline>[] query(String queryString) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void delete(String key) throws NotFoundException {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/news/NewsServiceTestCase.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/news/NewsServiceTestCase.java
new file mode 100644
index 0000000000..5b9e0848a0
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/news/NewsServiceTestCase.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.binding.atom.news;
+
+import java.net.Socket;
+
+import org.apache.tuscany.sca.binding.atom.aggregator.AggregatorTestCase;
+import org.apache.tuscany.sca.data.collection.Entry;
+import org.apache.tuscany.sca.node.Contribution;
+import org.apache.tuscany.sca.node.ContributionLocationHelper;
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class NewsServiceTestCase {
+ private static Node node;
+ private static NewsService newsService;
+
+ @BeforeClass
+ public static void init() throws Exception {
+ try {
+ String contribution = ContributionLocationHelper.getContributionLocation(AggregatorTestCase.class);
+ node = NodeFactory.newInstance().createNode("org/apache/tuscany/sca/binding/atom/news/news.composite", new Contribution("test", contribution));
+ node.start();
+
+ newsService = node.getService(NewsService.class, "NewsService");
+ Assert.assertNotNull(newsService);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @AfterClass
+ public static void destroy() throws Exception {
+ if(node != null) {
+ node.stop();
+ node.destroy();
+ }
+ }
+
+ @Test
+ public void testPing() throws Exception {
+ new Socket("127.0.0.1", 8085);
+ // System.in.read();
+ }
+
+ @Test
+ public void testNewsService() throws Exception {
+ Entry<String, Headline>[] entries = newsService.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().getText());
+ }
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/util/AtomTestCaseUtils.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/util/AtomTestCaseUtils.java
new file mode 100644
index 0000000000..1afad216e3
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/util/AtomTestCaseUtils.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.binding.atom.util;
+
+import java.io.IOException;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Base;
+import org.apache.abdera.model.Content;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.protocol.client.ClientResponse;
+import org.apache.abdera.protocol.client.RequestOptions;
+import org.apache.abdera.writer.Writer;
+import org.apache.abdera.writer.WriterFactory;
+
+/**
+ * Utilities to help print and test various aspects of entity tag support.
+ *
+ * @version $Rev$ $Date$
+ */
+public class AtomTestCaseUtils {
+
+ public static void prettyPrint(Abdera abdera, Base doc) throws IOException {
+ WriterFactory factory = abdera.getWriterFactory();
+ 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 );
+ }
+
+ }
+
+ 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);
+
+ return entry;
+ }
+
+ 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);
+
+ return entry;
+ }
+
+}