summaryrefslogtreecommitdiffstats
path: root/sca-java-1.x/trunk/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/GoogleCalendarServiceTestCase.java
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sca-java-1.x/trunk/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/GoogleCalendarServiceTestCase.java50
1 files changed, 47 insertions, 3 deletions
diff --git a/sca-java-1.x/trunk/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/GoogleCalendarServiceTestCase.java b/sca-java-1.x/trunk/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/GoogleCalendarServiceTestCase.java
index 9c3122e134..b64650aa7c 100644
--- a/sca-java-1.x/trunk/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/GoogleCalendarServiceTestCase.java
+++ b/sca-java-1.x/trunk/modules/binding-gdata-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/GoogleCalendarServiceTestCase.java
@@ -19,6 +19,7 @@
package org.apache.tuscany.sca.binding.gdata;
+import java.net.Socket;
import java.net.URL;
import junit.framework.Assert;
@@ -46,17 +47,25 @@ public class GoogleCalendarServiceTestCase {
@BeforeClass
public static void setUp() throws Exception {
//Initialize the GData client service (Reference Binding test)
- scaDomainConsumer = SCADomain.newInstance("org/apache/tuscany/sca/binding/gdata/ConsumerGoogleCalendar.composite");
- testService = scaDomainConsumer.getService(CustomerClient.class, "CustomerClient");
+ if (internetConnected()) {
+ scaDomainConsumer = SCADomain.newInstance("org/apache/tuscany/sca/binding/gdata/ConsumerGoogleCalendar.composite");
+ testService = scaDomainConsumer.getService(CustomerClient.class, "CustomerClient");
+ }
}
@AfterClass
public static void tearDown(){
- scaDomainConsumer.close();
+ if (scaDomainConsumer != null) {
+ scaDomainConsumer.close();
+ }
}
@Test
public void testClientGetFeed() throws Exception {
+ if (testService == null) {
+ // no internet connection
+ return;
+ }
Feed feed = testService.clientGetFeed();
//System.out.println("feed title: " + feed.getTitle().getPlainText());
Assert.assertEquals("gsoc gosc", feed.getTitle().getPlainText());
@@ -65,6 +74,10 @@ public class GoogleCalendarServiceTestCase {
@Test
public void testClientGetEntry() throws Exception {
+ if (testService == null) {
+ // no internet connection
+ return;
+ }
String entryID = "1c76lcl70jg9r0fm18rcbneea8";
Entry blogEntry = testService.clientGetEntry(entryID);
//System.out.println("Entry ID: " + blogEntry.getId());
@@ -75,6 +88,10 @@ public class GoogleCalendarServiceTestCase {
@Test
public void testClientPut() throws Exception {
+ if (testService == null) {
+ // no internet connection
+ return;
+ }
String entryID = "1c76lcl70jg9r0fm18rcbneea8";
String newBlogEntryTitle = "updatedTitleByGoogleContactsConsumerTestCase";
testService.clientPut(entryID, newBlogEntryTitle); //update the title
@@ -85,6 +102,10 @@ public class GoogleCalendarServiceTestCase {
@Test
public void testClientPost() throws Exception {
+ if (testService == null) {
+ // no internet connection
+ return;
+ }
String blogEntryTitle = "titleByGoogleCalendarTestcase";
Entry newEntry = new Entry();
newEntry.setTitle(new PlainTextConstruct(blogEntryTitle));
@@ -95,6 +116,10 @@ public class GoogleCalendarServiceTestCase {
@Test
public void testClientDelete() throws Exception {
+ if (testService == null) {
+ // no internet connection
+ return;
+ }
//This test case might fail
//because Google blogger service has limitation on new posts allowed everyday/every hour?
@@ -130,6 +155,10 @@ public class GoogleCalendarServiceTestCase {
@Test
public void testClientQuery() throws Exception {
+ if (testService == null) {
+ // no internet connection
+ return;
+ }
Query myQuery = new Query(new URL("http://www.google.com/calendar/feeds/haibotuscany@gmail.com/private/full"));
myQuery.setMaxResults(100);
//myQuery.setUpdatedMin(startTime);
@@ -145,5 +174,20 @@ public class GoogleCalendarServiceTestCase {
//assertEquals("gdata binding tuscany test", resultFeed.getTitle().getPlainText());
}
+ private static boolean internetConnected() {
+ try {
+ // see whether an internet connection is available
+ Socket testInternet = new Socket("tuscany.apache.org", 80);
+ testInternet.close();
+
+ // internet connection available
+ return true;
+
+ } catch (Exception e) {
+ // no internet connection
+ System.out.println("Unable to run test because no internet connection available");
+ return false;
+ }
+ }
}