diff options
Diffstat (limited to 'java/sca')
9 files changed, 313 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> diff --git a/java/sca/modules/binding-atom/pom.xml b/java/sca/modules/binding-atom/pom.xml index 85ccf15d13..3837632300 100644 --- a/java/sca/modules/binding-atom/pom.xml +++ b/java/sca/modules/binding-atom/pom.xml @@ -37,6 +37,20 @@ </dependency> <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-assembly-xml</artifactId> + <version>1.4-SNAPSHOT</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-sca-api</artifactId> + <version>1.4-SNAPSHOT</version> + <scope>test</scope> + </dependency> + + <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.2</version> diff --git a/java/sca/modules/binding-atom/src/test/java/org/apache/tuscany/sca/binding/atom/AtomBindingProcessorTestCase.java b/java/sca/modules/binding-atom/src/test/java/org/apache/tuscany/sca/binding/atom/AtomBindingProcessorTestCase.java new file mode 100644 index 0000000000..63dffd5522 --- /dev/null +++ b/java/sca/modules/binding-atom/src/test/java/org/apache/tuscany/sca/binding/atom/AtomBindingProcessorTestCase.java @@ -0,0 +1,89 @@ +/* + * 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.StringReader; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.monitor.impl.DefaultMonitorFactoryImpl; + +/** + * @version $Rev$ $Date$ + */ +public class AtomBindingProcessorTestCase extends TestCase { + + private static final String COMPOSITE = + "<?xml version=\"1.0\" encoding=\"ASCII\"?>" + + "<composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:tuscany=\"http://tuscany.apache.org/xmlns/sca/1.0\" targetNamespace=\"http://binding-atom\" name=\"binding-atom\">" + + " <component name=\"HelloWorldComponent\">" + + " <implementation.java class=\"services.HelloWorld\"/>" + + " <service name=\"HelloWorldService\">" + + " <tuscany:binding.atom uri=\"http://localhost:8080/feed\" title=\"Feed Title\"/>" + + " </service>" + + " </component>" + + "</composite>"; + + private XMLInputFactory inputFactory; + private StAXArtifactProcessor<Object> staxProcessor; + private Monitor monitor; + + @Override + protected void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + // Create a monitor + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl(); + if (monitorFactory != null) { + monitor = monitorFactory.createMonitor(); + utilities.addUtility(monitorFactory); + } + StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, monitor); + } + + /** + * Test parsing valid composite definition. Valid composite populated with correct values expected. + * @throws Exception + */ + public void testLoadValidComposite() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(COMPOSITE)); + + Composite composite = (Composite)staxProcessor.read(reader); + AtomBinding binding = (AtomBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + assertEquals("Feed Title", binding.getTitle()); + assertEquals("http://localhost:8080/feed", binding.getURI()); + } +} |