diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2008-07-19 05:57:51 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2008-07-19 05:57:51 +0000 |
commit | 7299224d996b2c4fdde1b428247745c882ceab50 (patch) | |
tree | c41ef1ad1e34b907ce0e84899a7694d317ed0de9 /java/sca/modules/binding-atom-abdera/src/test | |
parent | 3fb8deffc5323a906994ec46d18a1710da562722 (diff) |
TUSCANY-2470 - Automating the consumer/provider test case and adding some atom binding model tests
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@678106 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/binding-atom-abdera/src/test')
7 files changed, 210 insertions, 119 deletions
diff --git a/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/Consumer.java b/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/Consumer.java deleted file mode 100644 index 34d3ed1d1c..0000000000 --- a/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/Consumer.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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.host.embedded.SCADomain; - -public class Consumer { - - public static void main(String[] args) throws Exception { - - SCADomain scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Consumer.composite"); - - CustomerClient testService = scaDomain.getService(CustomerClient.class, "CustomerClient"); - testService.testCustomerCollection(); - - scaDomain.close(); - } -} 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 new file mode 100644 index 0000000000..8d0f1697ee --- /dev/null +++ b/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ConsumerProviderAtomTestCase.java @@ -0,0 +1,155 @@ +/* + * 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.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Test case for the given package. + */ +public class ConsumerProviderAtomTestCase { + + 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 testEntry() throws Exception { + // System.out.println( getClass().getName() + ".testEntry entry" ); + Entry entry = abdera.newEntry(); + Assert.assertNotNull(entry); + + String testTitle = "Sponge Bob"; + entry.setTitle(testTitle); + Assert.assertEquals(testTitle, entry.getTitle()); + + String testContent = "This is the content"; + entry.setContent(testContent); + Assert.assertEquals(testContent, entry.getContent()); + + Date now = new Date(); + entry.setEdited(now); + Assert.assertEquals(now, entry.getEdited()); + + Date later = new Date(); + entry.setPublished(later); + Assert.assertEquals(later, entry.getPublished()); + + String testSummary = "This is the summary"; + entry.setSummary(testSummary); + Assert.assertEquals(testSummary, entry.getSummary()); + } + + @Test + public void testCustomerCollection() throws Exception { + System.out.println(getClass().getName() + ".testCustomerCollection entry"); + Collection resourceCollection = testService.getCustomerCollection(); + Assert.assertNotNull(resourceCollection); + + Entry newEntry = newEntry("Sponge Bob"); + System.out.println(">>> post entry=" + newEntry.getTitle()); + newEntry = resourceCollection.post(newEntry); + System.out.println("<<< post id=" + newEntry.getId() + " entry=" + newEntry.getTitle()); + + newEntry = newEntry("Jane Bond"); + System.out.println(">>> post entry=" + newEntry.getTitle()); + newEntry = resourceCollection.post(newEntry); + System.out.println("<<< post id=" + newEntry.getId() + " entry=" + newEntry.getTitle()); + + System.out.println(">>> get id=" + newEntry.getId()); + Entry entry = resourceCollection.get(newEntry.getId().toString()); + System.out.println("<<< get id=" + entry.getId() + " entry=" + entry.getTitle()); + + System.out.println(">>> put id=" + newEntry.getId() + " entry=" + entry.getTitle()); + resourceCollection.put(entry.getId().toString(), updateEntry(entry, "James Bond")); + System.out.println("<<< put id=" + entry.getId() + " entry=" + entry.getTitle()); + + System.out.println(">>> delete id=" + entry.getId()); + resourceCollection.delete(entry.getId().toString()); + System.out.println("<<< delete id=" + entry.getId()); + + System.out.println(">>> get collection"); + Feed feed = resourceCollection.getFeed(); + System.out.println("<<< get collection"); + for (Object o : feed.getEntries()) { + Entry e = (Entry)o; + System.out.println("id = " + e.getId() + " entry = " + e.getTitle()); + } + } + + private Entry newEntry(String value) { + Entry entry = abdera.newEntry(); + entry.setTitle("customer " + value); + + Content content = abdera.getFactory().newContent(); + content.setContentType(Content.Type.TEXT); + content.setValue(value); + entry.setContentElement(content); + + return entry; + } + + private Entry updateEntry(Entry entry, String value) { + entry.setTitle("customer " + value); + + Content content = abdera.getFactory().newContent(); + content.setContentType(Content.Type.TEXT); + content.setValue(value); + entry.setContentElement(content); + + return entry; + } +}
\ No newline at end of file diff --git a/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerClient.java b/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerClient.java index 5e9331ae06..bc32b91367 100644 --- a/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerClient.java +++ b/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerClient.java @@ -19,7 +19,11 @@ package org.apache.tuscany.sca.binding.atom; +import org.apache.tuscany.sca.binding.atom.collection.Collection; + public interface CustomerClient { void testCustomerCollection() throws Exception; + + Collection getCustomerCollection(); } diff --git a/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerClientImpl.java b/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerClientImpl.java index 7346612383..3e5705b14c 100644 --- a/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerClientImpl.java +++ b/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/CustomerClientImpl.java @@ -31,34 +31,34 @@ public class CustomerClientImpl implements CustomerClient { protected final Abdera abdera = new Abdera(); @Reference - public Collection resourceCollection; + public Collection customerCollection; public void testCustomerCollection() throws Exception { Entry newEntry = newEntry("Sponge Bob"); System.out.println(">>> post entry=" + newEntry.getTitle()); - newEntry = resourceCollection.post(newEntry); + 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 = resourceCollection.post(newEntry); + newEntry = customerCollection.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()); + 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()); - resourceCollection.put(entry.getId().toString(), updateEntry(entry, "James Bond")); + 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()); - resourceCollection.delete(entry.getId().toString()); + customerCollection.delete(entry.getId().toString()); System.out.println("<<< delete id=" + entry.getId()); System.out.println(">>> get collection"); - Feed feed = resourceCollection.getFeed(); + Feed feed = customerCollection.getFeed(); System.out.println("<<< get collection"); for (Object o : feed.getEntries()) { Entry e = (Entry)o; @@ -66,6 +66,10 @@ public class CustomerClientImpl implements CustomerClient { } } + public Collection getCustomerCollection() { + return customerCollection; + } + private Entry newEntry(String value) { Entry entry = this.abdera.newEntry(); 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 dcea5a9039..af1a1c1268 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 @@ -31,43 +31,24 @@ import org.apache.abdera.model.Feed; import org.apache.tuscany.sca.binding.atom.collection.Collection; import org.osoa.sca.annotations.Scope; - - @Scope("COMPOSITE") public class CustomerCollectionImpl implements Collection { - private final Abdera abdera = new Abdera(); + private final Abdera abdera = new Abdera(); private Map<String, Entry> entries = new HashMap<String, Entry>(); /** - * Default constructor that initializes collection with couple customer entries + * Default constructor that initializes collection with couple customer + * entries */ public CustomerCollectionImpl() { - - for (int i = 0; i < 4; i++) { - String id = "urn:uuid:customer-" + UUID.randomUUID().toString(); - - Entry entry = abdera.getFactory().newEntry(); - entry.setId(id); - entry.setTitle("customer " + "Jane Doe_" + String.valueOf(i)); - - Content content = this.abdera.getFactory().newContent(); - content.setContentType(Content.Type.TEXT); - content.setValue("Jane Doe_" + String.valueOf(i)); - - entry.setContentElement(content); - - entry.addLink("" + id, "edit"); - entry.addLink("" + id, "alternate"); - - entry.setUpdated(new Date()); - - entries.put(id, entry); - System.out.println(">>> id=" + id); - } + // Used for testing. + // for (int i = 0; i < 4; i++) { + // testPut( "Jane Doe_" + String.valueOf( i )); + // } } public Entry post(Entry entry) { - System.out.println(">>> ResourceCollectionImpl.post entry=" + entry.getTitle()); + System.out.println(">>> CustomerCollectionImpl.post entry=" + entry.getTitle()); String id = "urn:uuid:customer-" + UUID.randomUUID().toString(); entry.setId(id); @@ -79,49 +60,72 @@ public class CustomerCollectionImpl implements Collection { entries.put(id, entry); - System.out.println(">>> ResourceCollectionImpl.post return id=" + id); + System.out.println(">>> CustomerCollectionImpl.post return id=" + id); return entry; } public Entry get(String id) { - System.out.println(">>> ResourceCollectionImpl.get id=" + id); + System.out.println(">>> CustomerCollectionImpl.get id=" + id); return entries.get(id); } public void put(String id, Entry entry) { - System.out.println(">>> ResourceCollectionImpl.put id=" + id + " entry=" + entry.getTitle()); + System.out.println(">>> CustomerCollectionImpl.put id=" + id + " entry=" + entry.getTitle()); entry.setUpdated(new Date()); entries.put(id, entry); } public void delete(String id) { - System.out.println(">>> ResourceCollectionImpl.delete id=" + id); + System.out.println(">>> CustomerCollectionImpl.delete id=" + id); entries.remove(id); } @SuppressWarnings("unchecked") public Feed getFeed() { - System.out.println(">>> ResourceCollectionImpl.get collection"); + System.out.println(">>> CustomerCollectionImpl.getFeed"); Feed feed = this.abdera.getFactory().newFeed(); feed.setTitle("customers"); feed.setSubtitle("This is a sample feed"); feed.setUpdated(new Date()); feed.addLink(""); - feed.addLink("","self"); + feed.addLink("", "self"); for (Entry entry : entries.values()) { - feed.addEntry(entry); + feed.addEntry(entry); } return feed; } public Feed query(String queryString) { - System.out.println(">>> ResourceCollectionImpl.query collection " + 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/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/Provider.java b/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/Provider.java deleted file mode 100644 index 3e1bf543e5..0000000000 --- a/java/sca/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/Provider.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.host.embedded.SCADomain; - -public class Provider { - - public static void main(String[] args) { - - SCADomain scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Provider.composite"); - System.out.println("Provider.composite ready..."); - - try { - System.in.read(); - } catch (IOException e) { - e.printStackTrace(); - } - - scaDomain.close(); - } -} diff --git a/java/sca/modules/binding-atom-abdera/src/test/resources/org/apache/tuscany/sca/binding/atom/Consumer.composite b/java/sca/modules/binding-atom-abdera/src/test/resources/org/apache/tuscany/sca/binding/atom/Consumer.composite index 05037429a7..a2c50f872e 100644 --- a/java/sca/modules/binding-atom-abdera/src/test/resources/org/apache/tuscany/sca/binding/atom/Consumer.composite +++ b/java/sca/modules/binding-atom-abdera/src/test/resources/org/apache/tuscany/sca/binding/atom/Consumer.composite @@ -24,7 +24,7 @@ <component name="CustomerClient"> <implementation.java class="org.apache.tuscany.sca.binding.atom.CustomerClientImpl"/> - <reference name="resourceCollection"> + <reference name="customerCollection"> <tuscany:binding.atom uri="http://localhost:8084/customer"/> </reference> </component> |