diff options
Diffstat (limited to 'java/sca/modules/binding-gdata-runtime-gsoc/src/test')
7 files changed, 489 insertions, 0 deletions
diff --git a/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/Consumer.java b/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/Consumer.java new file mode 100644 index 0000000000..3e1b9490a9 --- /dev/null +++ b/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/Consumer.java @@ -0,0 +1,41 @@ +/* + * 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.gdata; + +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/gdata/Consumer.composite"); + + CustomerClient testService = scaDomain.getService(CustomerClient.class, "CustomerClient"); + + //testService.testCustomerCollection(); + + testService.testGetFeed(); // Tested, worked + testService.testGetEntry(); // Tested, worked + testService.testPost(); // Tested, worked + testService.testGetFeed(); // Tested, worked + + scaDomain.close(); + } +} diff --git a/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClient.java b/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClient.java new file mode 100644 index 0000000000..501183d7be --- /dev/null +++ b/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClient.java @@ -0,0 +1,34 @@ +/* + * 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.gdata; + +public interface CustomerClient { + + // void testCustomerCollection() throws Exception; + + void testGetFeed() throws Exception; + + void testGetEntry() throws Exception; + + void testPost() throws Exception; + + // void testCustomerGetEntry() throws Exception; + +} diff --git a/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClientImpl.java b/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClientImpl.java new file mode 100644 index 0000000000..c9fb844bb1 --- /dev/null +++ b/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerClientImpl.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.gdata; + +import org.apache.abdera.Abdera; +import org.apache.tuscany.sca.binding.gdata.collection.Collection; +import org.osoa.sca.annotations.Reference; + +import com.google.gdata.data.DateTime; +import com.google.gdata.data.Entry; +import com.google.gdata.data.PlainTextConstruct; + +public class CustomerClientImpl implements CustomerClient { + + protected final Abdera abdera = new Abdera(); + + @Reference + public Collection resourceCollection; + + // Test Collection.getFeed() + public void testGetFeed() throws Exception { + // Get all the entries from the provider + System.out.println("\n\n+++++++++++ get the feed from the provider service +++++++++++"); + com.google.gdata.data.Feed feed = resourceCollection.getFeed(); + System.out.println("\n\n\n!!!Fetched feed title: " + feed.getTitle().getPlainText()); + int i = 0; + for (Object o : feed.getEntries()) { + com.google.gdata.data.Entry e = (com.google.gdata.data.Entry)o; + System.out.print("Entry" + i + "\t"); + System.out.println(" id = " + e.getId() + "\t title = " + e.getTitle().getPlainText()); + i++; + } + System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); + System.out.println("\n\n\n"); + } + + // Test Collection.get(entryID) + public void testGetEntry() throws Exception { + + // Get an existing entry based on its id + System.out.println("+++++++++++ get an existing entry from the provider service +++++++++++"); + System.out.println(">>> get an entry based on its id"); + Entry entry = resourceCollection.get("urn:uuid:customer-0"); + System.out.println("\n\n\n!!! Entry retrieved with id=" + entry.getId() + + " title=" + + entry.getTitle().getPlainText()); + System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); + System.out.println("\n\n\n"); + + } + + // Test Collection.post(newEntry) + public void testPost() throws Exception { + + // Put a new entry to the provider + System.out.println("+++++++++++ post a new entry to the provider service +++++++++++"); + Entry newEntry = new Entry(); + newEntry.setTitle(new PlainTextConstruct("NewEntry title")); + newEntry.setContent(new PlainTextConstruct("NewEntry Content")); + System.out.println(">>> post a new entry: title=" + newEntry.getTitle().getPlainText()); + Entry confirmedNewEntry = resourceCollection.post(newEntry); + System.out.println("!!! New entry posted with id=" + confirmedNewEntry.getId() + + " title=" + + confirmedNewEntry.getTitle()); + System.out.println("\n"); + } + + /* + * public void testCustomerCollection() throws Exception { //Put a new entry + * to the provider System.out.println("\n\n+++++++++++ post a new entry to + * the provider service +++++++++++"); Entry newEntry = + * newEntry("newtitle"); newEntry.addAuthor("newAuthor"); + * System.out.println(">>> post a new entry: title=" + newEntry.getTitle() + " + * author=" + newEntry.getAuthor().getName()); newEntry = + * resourceCollection.post(newEntry); System.out.println("!!! New entry + * posted with id=" + newEntry.getId() + " title=" + newEntry.getTitle()); + * System.out.println("\n"); //Put a new entry to the provider + * System.out.println("+++++++++++ post a new entry to the provider service + * +++++++++++"); newEntry = newEntry("newtitleTemp"); + * newEntry.addAuthor("newAuthorTemp"); System.out.println(">>> post a new + * entry: title=" + newEntry.getTitle() + " author=" + + * newEntry.getAuthor().getName()); newEntry = + * resourceCollection.post(newEntry); System.out.println("!!! New entry + * posted with id=" + newEntry.getId() + " title=" + newEntry.getTitle()); + * System.out.println("\n"); //Get an existing entry based on its id + * System.out.println("+++++++++++ get an existing entry from the provider + * service +++++++++++"); System.out.println(">>> get an entry based on its + * id"); Entry entry = resourceCollection.get(newEntry.getId().toString()); + * System.out.println("!!! Entry retrieved with id=" + entry.getId() + " + * title=" + entry.getTitle()); System.out.println("\n"); //Update an + * existing entry based on its id System.out.println("+++++++++++ update an + * existing entry in the provider service +++++++++++"); + * System.out.println(">>> put id=" + entry.getId() + " + * title=updatedTitle"); resourceCollection.put(entry.getId().toString(), + * updateEntry(entry, "updatedTitle")); System.out.println("!!! Updated + * entry with id=" + entry.getId() + " title=" + entry.getTitle()); + * System.out.println("\n"); System.out.println("+++++++++++ delete an + * existing entry from the provider service +++++++++++"); + * System.out.println(">>> delete id=" + entry.getId()); + * resourceCollection.delete(entry.getId().toString()); + * System.out.println("!!! entry deleted"); //Get all the entries from the + * provider System.out.println("\n\n+++++++++++ get all the entries from the + * provider service +++++++++++"); Feed feed = resourceCollection.getFeed(); + * int i=0; for (Object o : feed.getEntries()) { Entry e = (Entry)o; + * System.out.print("Entry" + i + "\t"); System.out.println(" id = " + + * e.getId() + "\t title = " + e.getTitle()+ "\t author = " + + * e.getAuthor().getName()); i++; } } + */ + + private Entry newEntry(String value) { + /* + * Entry entry = this.abdera.newEntry(); entry.setTitle(value); Content + * content = this.abdera.getFactory().newContent(); + * content.setContentType(Content.Type.TEXT); content.setValue(value); + * entry.setContentElement(content); + */ + + Entry entry = new Entry(); + entry.setTitle(new PlainTextConstruct(value)); + entry.setContent(new PlainTextConstruct(value)); + entry.setUpdated(DateTime.now()); + // entry.addHtmlLink("http://www.google.com", "languageType", "title"); + return entry; + } + + private Entry updateEntry(Entry entry, String value) { + /* + * entry.setTitle(value); Content content = + * this.abdera.getFactory().newContent(); + * content.setContentType(Content.Type.TEXT); content.setValue(value); + * entry.setContentElement(content); + */ + entry.setTitle(new PlainTextConstruct("Entry title: " + value)); + entry.setContent(new PlainTextConstruct(value)); + return entry; + } + +} diff --git a/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerCollectionImpl.java b/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/CustomerCollectionImpl.java new file mode 100644 index 0000000000..79149ddc57 --- /dev/null +++ b/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/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.gdata; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.apache.tuscany.sca.binding.gdata.collection.Collection; +import org.osoa.sca.annotations.Scope; + +import com.google.gdata.data.DateTime; +import com.google.gdata.data.Entry; +import com.google.gdata.data.Feed; +import com.google.gdata.data.PlainTextConstruct; + +@Scope("COMPOSITE") +public class CustomerCollectionImpl implements Collection { + + // private final Abdera abdera = new Abdera(); + private Map<String, Entry> entries = new HashMap<String, Entry>(); + + /** + * Default constructor that initializes collection with couple customer + * entries + */ + public CustomerCollectionImpl() { + + for (int i = 0; i < 4; i++) { + // id is supposed to be generated in a random way, but for the + // purpose of testing + // I just make them as static ids + // String id = "urn:uuid:customer-" + UUID.randomUUID().toString(); + + String id = "urn:uuid:customer-" + String.valueOf(i); + + Entry entry = new Entry(); + entry.setId(id); + entry.setTitle(new PlainTextConstruct("EntryTitle_" + i)); + entry.setContent(new PlainTextConstruct("content_" + i)); + entry.setUpdated(DateTime.now()); + + // FIXME: The following three lines of code need to be fixed to add + // HTML links. + + // entry.addHtmlLink(""+id, "application/atom+xml", "title"); + // entry.addHtmlLink(""+id, "", "edit"); + // entry.addHtmlLink(""+id, "", "alternate"); + + /* + * Entry entry = abdera.getFactory().newEntry(); entry.setId(id); + * entry.setTitle("title_" + String.valueOf(i)); + * entry.addAuthor("author_" + String.valueOf(i)); entry.addLink("" + + * id, "edit"); entry.addLink("" + id, "alternate"); + * entry.setUpdated(new Date()); + */ + + entries.put(id, entry); + System.out.println(">>> id=" + id); + } + } + + public Entry post(Entry entry) { + System.out.println(">>> ResourceCollectionImpl.post entry=" + 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()); + */ + entry.setUpdated(DateTime.now()); + // entry.addHtmlLink("http://www.google.com", "languageType", "edit"); + // entry.addHtmlLink("http://www.google.com", "languageType", + // "alternate"); + + entries.put(id, entry); + System.out.println(">>> ResourceCollectionImpl.post return id=" + id); + return entry; + } + + public Entry get(String id) { + System.out.println(">>> ResourceCollectionImpl.get id=" + id); + return entries.get(id); + } + + public void put(String id, Entry entry) { + System.out.println(">>> ResourceCollectionImpl.put id=" + id + " entry=" + entry.getTitle()); + + // entry.setUpdated(new Date()); + entry.setUpdated(DateTime.now()); + + entries.put(id, entry); + } + + public void delete(String id) { + System.out.println(">>> ResourceCollectionImpl.delete id=" + id); + entries.remove(id); + } + + @SuppressWarnings("unchecked") + public Feed getFeed() { + System.out.println(">>> ResourceCollectionImpl.get collection"); + + /* + * 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 feed = new Feed(); + feed.setTitle(new PlainTextConstruct("Feedtitle")); + feed.setSubtitle(new PlainTextConstruct("Subtitle: This is a sample feed")); + feed.setUpdated(DateTime.now()); + + // FIXME: The following two lines of code need to be fixed + // feed.addHtmlLink("", "", ""); + // feed.addHtmlLink("", "languageType", "self"); + + ArrayList<Entry> entryList = new ArrayList<Entry>(); + for (Entry entry : entries.values()) { + entryList.add(entry); + } + feed.setEntries(entryList); + + return feed; + } + + public Feed query(String queryString) { + System.out.println(">>> ResourceCollectionImpl.query collection " + queryString); + return getFeed(); + } + +} diff --git a/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/Provider.java b/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/Provider.java new file mode 100644 index 0000000000..21bff30256 --- /dev/null +++ b/java/sca/modules/binding-gdata-runtime-gsoc/src/test/java/org/apache/tuscany/sca/binding/gdata/Provider.java @@ -0,0 +1,41 @@ +/* + * 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.gdata; + +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/gdata/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-gdata-runtime-gsoc/src/test/resources/org/apache/tuscany/sca/binding/gdata/Consumer.composite b/java/sca/modules/binding-gdata-runtime-gsoc/src/test/resources/org/apache/tuscany/sca/binding/gdata/Consumer.composite new file mode 100644 index 0000000000..93e5798f46 --- /dev/null +++ b/java/sca/modules/binding-gdata-runtime-gsoc/src/test/resources/org/apache/tuscany/sca/binding/gdata/Consumer.composite @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" + xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0" + targetNamespace="http://customer" + name="Consumer"> + + <component name="CustomerClient"> + <implementation.java class="org.apache.tuscany.sca.binding.gdata.CustomerClientImpl"/> + <reference name="resourceCollection"> + <tuscany:binding.gdata uri="http://localhost:8084/customer"/> + </reference> + </component> + +</composite> diff --git a/java/sca/modules/binding-gdata-runtime-gsoc/src/test/resources/org/apache/tuscany/sca/binding/gdata/Provider.composite b/java/sca/modules/binding-gdata-runtime-gsoc/src/test/resources/org/apache/tuscany/sca/binding/gdata/Provider.composite new file mode 100644 index 0000000000..a4cf00dc84 --- /dev/null +++ b/java/sca/modules/binding-gdata-runtime-gsoc/src/test/resources/org/apache/tuscany/sca/binding/gdata/Provider.composite @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" + xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0" + targetNamespace = "http://customer" + name="Provider"> + + <service name="customer" promote="CustomerCollection"> + <tuscany:binding.gdata uri = "http://localhost:8084/customer"/> + </service> + + <component name="CustomerCollection"> + <implementation.java class="org.apache.tuscany.sca.binding.gdata.CustomerCollectionImpl"/> + </component> + +</composite> |