tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lrese...@apache.org
Subject svn commit: r681918 - /tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/
Date Sat, 02 Aug 2008 00:24:51 GMT
Author: lresende
Date: Fri Aug  1 17:24:51 2008
New Revision: 681918

URL: http://svn.apache.org/viewvc?rev=681918&view=rev
Log:
TUSCANY-2500 - Applying Dhaval's patch

Added:
    tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomDeleteTestCase.java
  (with props)
    tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomGetTestCase.java
  (with props)
    tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPostTestCase.java
  (with props)
    tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPutTestCase.java
  (with props)
Modified:
    tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ConsumerProviderAtomTestCase.java
    tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerCollectionImpl.java

Added: tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomDeleteTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomDeleteTestCase.java?rev=681918&view=auto
==============================================================================
--- tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomDeleteTestCase.java
(added)
+++ tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomDeleteTestCase.java
Fri Aug  1 17:24:51 2008
@@ -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;
+    }
+
+}

Propchange: tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomDeleteTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomDeleteTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomGetTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomGetTestCase.java?rev=681918&view=auto
==============================================================================
--- tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomGetTestCase.java
(added)
+++ tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomGetTestCase.java
Fri Aug  1 17:24:51 2008
@@ -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;
+    }
+
+}

Propchange: tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomGetTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomGetTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPostTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPostTestCase.java?rev=681918&view=auto
==============================================================================
--- tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPostTestCase.java
(added)
+++ tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPostTestCase.java
Fri Aug  1 17:24:51 2008
@@ -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;
+    }
+
+}

Propchange: tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPostTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPostTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPutTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPutTestCase.java?rev=681918&view=auto
==============================================================================
--- tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPutTestCase.java
(added)
+++ tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPutTestCase.java
Fri Aug  1 17:24:51 2008
@@ -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;
+    }
+
+}

Propchange: tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPutTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/AtomPutTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ConsumerProviderAtomTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ConsumerProviderAtomTestCase.java?rev=681918&r1=681917&r2=681918&view=diff
==============================================================================
--- tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ConsumerProviderAtomTestCase.java
(original)
+++ tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ConsumerProviderAtomTestCase.java
Fri Aug  1 17:24:51 2008
@@ -120,7 +120,7 @@
 	        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");

Modified: tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerCollectionImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerCollectionImpl.java?rev=681918&r1=681917&r2=681918&view=diff
==============================================================================
--- tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerCollectionImpl.java
(original)
+++ tuscany/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerCollectionImpl.java
Fri Aug  1 17:24:51 2008
@@ -29,6 +29,7 @@
 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 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.setUpdated(new Date());
+           entries.put(id, entry);
 
-        entry.addLink("" + id, "edit");
-        entry.addLink("" + id, "alternate");
+            System.out.println(">>> CustomerCollectionImpl.post return id=" + id);
 
-        entry.setUpdated(new Date());
+            return entry;
 
-        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) {
@@ -70,17 +77,26 @@
         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() {



Mime
View raw message