From 7ad16a07b4288227c531c485939318768129fb54 Mon Sep 17 00:00:00 2001 From: antelder Date: Wed, 3 Aug 2011 09:20:48 +0000 Subject: Tag debug mod for TUSCANY-3909 git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1153403 13f79535-47bb-0310-9956-ffa450edef68 --- .../gdata/GoogleContactsServiceTestCase.java | 168 +++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 sca-java-1.x/tags/1.6.1-TUSCANY-3909/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/GoogleContactsServiceTestCase.java (limited to 'sca-java-1.x/tags/1.6.1-TUSCANY-3909/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/GoogleContactsServiceTestCase.java') diff --git a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/GoogleContactsServiceTestCase.java b/sca-java-1.x/tags/1.6.1-TUSCANY-3909/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/GoogleContactsServiceTestCase.java new file mode 100644 index 0000000000..1f261dfc90 --- /dev/null +++ b/sca-java-1.x/tags/1.6.1-TUSCANY-3909/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/GoogleContactsServiceTestCase.java @@ -0,0 +1,168 @@ +/* + * 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.net.URL; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.google.gdata.client.Query; +import com.google.gdata.data.DateTime; +import com.google.gdata.data.Entry; +import com.google.gdata.data.Feed; +import com.google.gdata.data.PlainTextConstruct; + +public class GoogleContactsServiceTestCase { + + private static SCADomain scaDomainConsumer = null; + private static CustomerClient testService = null; + + public GoogleContactsServiceTestCase(){ + + } + + @BeforeClass + public static void setUp() throws Exception { + //Initialize the GData client service (Reference Binding test) + scaDomainConsumer = SCADomain.newInstance("org/apache/tuscany/sca/binding/gdata/ConsumerGoogleContacts.composite"); + testService = scaDomainConsumer.getService(CustomerClient.class, "CustomerClient"); + } + + @AfterClass + public static void tearDown(){ + scaDomainConsumer.close(); + } + + @Test + public void testClientGetFeed() throws Exception { + Feed feed = testService.clientGetFeed(); + System.out.println("feed title: " + feed.getTitle().getPlainText()); + Assert.assertEquals("Haibo Zhao's Contacts", feed.getTitle().getPlainText()); + } + + + @Test + public void testClientGetEntry() throws Exception { + String entryID = "12feeeb38ab87365"; + Entry contactEntry = testService.clientGetEntry(entryID); + //System.out.println("Entry ID: " + contactEntry.getId()); + Assert.assertTrue(contactEntry.getId().endsWith(entryID)); + } + + + @Test + public void testClientPut() throws Exception { + String entryID = "12feeeb38ab87365"; + String newBlogEntryTitle = "updatedTitleByGoogleContactsConsumerTestCase"; + testService.clientPut(entryID, newBlogEntryTitle); //update the title + Thread.sleep(Constants.SLEEP_INTERVAL); + Entry updatedEntry = testService.clientGetEntry(entryID); + Assert.assertEquals(newBlogEntryTitle, updatedEntry.getTitle().getPlainText()); + } + + + + @Test + public void testClientPost() throws Exception { + String blogEntryTitle = "titleByGoogleContactsTestcase"; + Entry newEntry = new Entry(); + newEntry.setTitle(new PlainTextConstruct(blogEntryTitle)); + newEntry.setContent(new PlainTextConstruct("contentByGoogleContactsTestCase")); + Entry postedEntry = testService.clientPost(newEntry); + Assert.assertEquals(blogEntryTitle, postedEntry.getTitle().getPlainText()); + } + + + @Test + public void testClientDelete() throws Exception { + + //This test case might fail + //because Google blogger service has limitation on new posts allowed everyday/every hour? + + //System.out.println("testClientDelete"); + //We create a new post, and then delete it + Entry newEntry = new Entry(); + newEntry.setTitle(new PlainTextConstruct("contactEntryShouldNotApear")); + newEntry.setContent(new PlainTextConstruct("contactByBloggerShouldNotAppear")); + Entry postedEntry = testService.clientPost(newEntry); + Thread.sleep(Constants.SLEEP_INTERVAL); + + //System.out.println("ID: " + postedEntry.getId()); + + int idStartPosition = postedEntry.getId().lastIndexOf("/"); + String postedEntryID = postedEntry.getId().substring(idStartPosition+1); + //System.out.println("postedEntryID: " + postedEntryID ); + + //Before deletion + for (int i = 0; i < 5; i++) { // make 5 attempts because of timing issues + try { + Entry entry00 = testService.clientGetEntry(postedEntryID); + //System.out.println("Before Deletion: " + entry00.getId()); + break; // get was successful + } catch (Exception e) { + if (i < 4) { + System.out.println("Get failed, retrying..."); + } else { + throw e; // final attempt, give up + } + } + } + + //Delete this entry + for (int i = 0; i < 5; i++) { // make 5 attempts because of timing issues + try { + testService.clientDelete(postedEntryID); + break; // delete was successful + } catch (Exception e) { + if (i < 4) { + System.out.println("Delete failed, retrying..."); + } else { + throw e; // final attempt, give up + } + } + } + + //Worked: this newly posted entry did not appear in the contact list + //But we need a Junit assertion here + //Link: http://haibotuscany.blogspot.com/feeds/posts/default/ + //FIXME: Need an assertion here + //Assert(....); + } + + + @Test + public void testClientQuery() throws Exception { + Query myQuery = new Query(new URL("http://www.google.com/m8/feeds/contacts/default/base")); + myQuery.setMaxResults(100); + //myQuery.setUpdatedMin(startTime); + myQuery.setUpdatedMax(DateTime.now()); + Feed resultFeed = testService.clientQuery(myQuery); + //System.out.println("Query result feed title: " + resultFeed.getTitle().getPlainText()); + //System.out.println("Query result entry number: "+ resultFeed.getEntries().size()); + //assertEquals("gdata binding tuscany test", resultFeed.getTitle().getPlainText()); + } + + +} -- cgit v1.2.3