summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomDeleteTestCase.java92
-rw-r--r--java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomGetTestCase.java97
-rw-r--r--java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPostTestCase.java86
-rw-r--r--java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPutTestCase.java104
-rw-r--r--java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ConsumerProviderAtomTestCase.java2
-rw-r--r--java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerCollectionImpl.java50
6 files changed, 413 insertions, 18 deletions
diff --git a/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomDeleteTestCase.java b/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomDeleteTestCase.java
new file mode 100644
index 0000000000..8d5a8da188
--- /dev/null
+++ b/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomDeleteTestCase.java
@@ -0,0 +1,92 @@
+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.apache.tuscany.sca.host.embedded.SCADomain;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class AtomDeleteTestCase {
+ protected static SCADomain scaConsumerDomain;
+ protected static SCADomain scaProviderDomain;
+ protected static CustomerClient testService;
+ protected static Abdera abdera;
+
+ @BeforeClass
+ public static void init() throws Exception {
+ System.out.println(">>>AtomBindingIntegratedTestCase.init entry");
+ scaProviderDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Provider.composite");
+ scaConsumerDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Consumer.composite");
+ testService = scaConsumerDomain.getService(CustomerClient.class, "CustomerClient");
+ abdera = new Abdera();
+ }
+
+ @AfterClass
+ public static void destroy() throws Exception {
+ // System.out.println(">>>AtomBindingIntegratedTestCase.destroy entry");
+ scaConsumerDomain.close();
+ scaProviderDomain.close();
+ }
+
+ @Test
+ public void testPrelim() throws Exception {
+ Assert.assertNotNull(scaProviderDomain);
+ Assert.assertNotNull(scaConsumerDomain);
+ 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/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomGetTestCase.java b/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomGetTestCase.java
new file mode 100644
index 0000000000..5e827df59a
--- /dev/null
+++ b/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomGetTestCase.java
@@ -0,0 +1,97 @@
+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.apache.tuscany.sca.host.embedded.SCADomain;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class AtomGetTestCase {
+ protected static SCADomain scaConsumerDomain;
+ protected static SCADomain scaProviderDomain;
+ protected static CustomerClient testService;
+ protected static Abdera abdera;
+
+ @BeforeClass
+ public static void init() throws Exception {
+ System.out.println(">>>AtomBindingIntegratedTestCase.init entry");
+ scaProviderDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Provider.composite");
+ scaConsumerDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Consumer.composite");
+ testService = scaConsumerDomain.getService(CustomerClient.class, "CustomerClient");
+ abdera = new Abdera();
+ }
+
+ @AfterClass
+ public static void destroy() throws Exception {
+ // System.out.println(">>>AtomBindingIntegratedTestCase.destroy entry");
+ scaConsumerDomain.close();
+ scaProviderDomain.close();
+ }
+
+ @Test
+ public void testPrelim() throws Exception {
+ Assert.assertNotNull(scaProviderDomain);
+ Assert.assertNotNull(scaConsumerDomain);
+ 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/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPostTestCase.java b/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPostTestCase.java
new file mode 100644
index 0000000000..a165dc5128
--- /dev/null
+++ b/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPostTestCase.java
@@ -0,0 +1,86 @@
+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.apache.tuscany.sca.host.embedded.SCADomain;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class AtomPostTestCase {
+ protected static SCADomain scaConsumerDomain;
+ protected static SCADomain scaProviderDomain;
+ protected static CustomerClient testService;
+ protected static Abdera abdera;
+
+ @BeforeClass
+ public static void init() throws Exception {
+ System.out.println(">>>AtomBindingIntegratedTestCase.init entry");
+ scaProviderDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Provider.composite");
+ scaConsumerDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Consumer.composite");
+ testService = scaConsumerDomain.getService(CustomerClient.class, "CustomerClient");
+ abdera = new Abdera();
+ }
+
+ @AfterClass
+ public static void destroy() throws Exception {
+ System.out.println(">>>AtomBindingIntegratedTestCase.destroy entry");
+ scaConsumerDomain.close();
+ scaProviderDomain.close();
+ }
+
+ @Test
+ public void testPrelim() throws Exception {
+ Assert.assertNotNull(scaProviderDomain);
+ Assert.assertNotNull(scaConsumerDomain);
+ 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/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPutTestCase.java b/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPutTestCase.java
new file mode 100644
index 0000000000..5077352e93
--- /dev/null
+++ b/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPutTestCase.java
@@ -0,0 +1,104 @@
+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.apache.tuscany.sca.host.embedded.SCADomain;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class AtomPutTestCase {
+ protected static SCADomain scaConsumerDomain;
+ protected static SCADomain scaProviderDomain;
+ protected static CustomerClient testService;
+ protected static Abdera abdera;
+
+ @BeforeClass
+ public static void init() throws Exception {
+ System.out.println(">>>AtomBindingIntegratedTestCase.init entry");
+ scaProviderDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Provider.composite");
+ scaConsumerDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Consumer.composite");
+ testService = scaConsumerDomain.getService(CustomerClient.class, "CustomerClient");
+ abdera = new Abdera();
+ }
+
+ @AfterClass
+ public static void destroy() throws Exception {
+ // System.out.println(">>>AtomBindingIntegratedTestCase.destroy entry");
+ scaConsumerDomain.close();
+ scaProviderDomain.close();
+ }
+
+ @Test
+ public void testPrelim() throws Exception {
+ Assert.assertNotNull(scaProviderDomain);
+ Assert.assertNotNull(scaConsumerDomain);
+ 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/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ConsumerProviderAtomTestCase.java b/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ConsumerProviderAtomTestCase.java
index 8d0f1697ee..9af85a970c 100644
--- a/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ConsumerProviderAtomTestCase.java
+++ b/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ConsumerProviderAtomTestCase.java
@@ -120,7 +120,7 @@ public class ConsumerProviderAtomTestCase {
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");
diff --git a/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerCollectionImpl.java b/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerCollectionImpl.java
index af1a1c1268..d994e0af73 100644
--- a/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerCollectionImpl.java
+++ b/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerCollectionImpl.java
@@ -29,6 +29,7 @@ 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.osoa.sca.annotations.Scope;
@Scope("COMPOSITE")
@@ -50,19 +51,25 @@ public class CustomerCollectionImpl implements Collection {
public Entry post(Entry entry) {
System.out.println(">>> CustomerCollectionImpl.post entry=" + entry.getTitle());
- String id = "urn:uuid:customer-" + UUID.randomUUID().toString();
- entry.setId(id);
+ 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");
+ entry.addLink("" + id, "edit");
+ entry.addLink("" + id, "alternate");
+ entry.setUpdated(new Date());
+ entries.put(id, entry);
- entry.setUpdated(new Date());
+ System.out.println(">>> CustomerCollectionImpl.post return id=" + id);
- entries.put(id, entry);
-
- System.out.println(">>> CustomerCollectionImpl.post return id=" + id);
+ return entry;
- return entry;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Exception in Post method");
+ }
}
public Entry get(String id) {
@@ -70,17 +77,26 @@ public class CustomerCollectionImpl implements Collection {
return entries.get(id);
}
- public void put(String id, Entry entry) {
+ public void put(String id, Entry entry) throws NotFoundException {
System.out.println(">>> CustomerCollectionImpl.put id=" + id + " entry=" + entry.getTitle());
+ if(entries.containsKey(id)){
+ entry.setUpdated(new Date());
+ entries.put(id, entry);
+ }
+ else {
+ throw new NotFoundException();
+ }
+ }
- entry.setUpdated(new Date());
- entries.put(id, entry);
- }
-
- public void delete(String id) {
+ public void delete(String id) throws NotFoundException {
System.out.println(">>> CustomerCollectionImpl.delete id=" + id);
- entries.remove(id);
- }
+ if(entries.containsKey(id)){
+ entries.remove(id);
+ }
+ else {
+ throw new NotFoundException();
+ }
+ }
@SuppressWarnings("unchecked")
public Feed getFeed() {