You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by ie...@apache.org on 2008/08/29 00:46:20 UTC

svn commit: r690036 [2/2] - in /incubator/shindig/trunk/java: common/src/main/java/org/apache/shindig/common/util/ common/src/test/java/org/apache/shindig/common/util/ social-api/src/main/java/org/apache/shindig/social/ social-api/src/main/java/org/apa...

Modified: incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/PersonHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/PersonHandlerTest.java?rev=690036&r1=690035&r2=690036&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/PersonHandlerTest.java (original)
+++ incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/PersonHandlerTest.java Thu Aug 28 15:46:19 2008
@@ -20,21 +20,25 @@
 import org.apache.shindig.common.testing.FakeGadgetToken;
 import org.apache.shindig.common.util.ImmediateFuture;
 import org.apache.shindig.social.ResponseError;
+import org.apache.shindig.social.core.model.PersonImpl;
 import org.apache.shindig.social.opensocial.model.Person;
 import org.apache.shindig.social.opensocial.spi.CollectionOptions;
 import org.apache.shindig.social.opensocial.spi.GroupId;
 import org.apache.shindig.social.opensocial.spi.PersonService;
 import org.apache.shindig.social.opensocial.spi.RestfulCollection;
-import org.apache.shindig.social.opensocial.spi.RestfulItem;
 import org.apache.shindig.social.opensocial.spi.UserId;
+import org.apache.shindig.social.opensocial.spi.SocialSpiException;
 
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 import junit.framework.TestCase;
 import org.easymock.classextension.EasyMock;
 
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.ExecutionException;
 
 public class PersonHandlerTest extends TestCase {
   private PersonService personService;
@@ -98,7 +102,8 @@
   public void testHandleGetAllNoParams() throws Exception {
     setPath("/people/john.doe/@all");
 
-    RestfulCollection<Person> data = new RestfulCollection<Person>(null, null);
+    List<Person> personList = ImmutableList.of();
+    RestfulCollection<Person> data = new RestfulCollection<Person>(personList);
 
     EasyMock.expect(personService.getPeople(
         JOHN_DOE,
@@ -116,7 +121,8 @@
   public void testHandleGetFriendsNoParams() throws Exception {
     setPath("/people/john.doe/@friends");
 
-    RestfulCollection<Person> data = new RestfulCollection<Person>(null, null);
+    List<Person> personList = ImmutableList.of();
+    RestfulCollection<Person> data = new RestfulCollection<Person>(personList);
     EasyMock.expect(personService.getPeople(
         JOHN_DOE,
         new GroupId(GroupId.Type.friends, null),
@@ -152,7 +158,8 @@
 
     setPathAndParams("/people/john.doe/@friends", params);
 
-    RestfulCollection<Person> data = new RestfulCollection<Person>(null, null);
+    List<Person> people = ImmutableList.of();
+    RestfulCollection<Person> data = new RestfulCollection<Person>(people);
     EasyMock.expect(personService.getPeople(
         JOHN_DOE,
         new GroupId(GroupId.Type.friends, null), options,
@@ -167,7 +174,7 @@
   public void testHandleGetFriendById() throws Exception {
     setPath("/people/john.doe/@friends/jane.doe");
 
-    RestfulItem<Person> data = new RestfulItem<Person>(null);
+    Person data = new PersonImpl();
     // TODO: We aren't passing john.doe to the service yet.
     EasyMock.expect(personService.getPerson(new UserId(UserId.Type.userId, "jane.doe"),
         DEFAULT_FIELDS, token)).andReturn(ImmediateFuture.newInstance(data));
@@ -180,7 +187,7 @@
   public void testHandleGetSelf() throws Exception {
     setPath("/people/john.doe/@self");
 
-    RestfulItem<Person> data = new RestfulItem<Person>(null);
+    Person data = new PersonImpl();
     EasyMock.expect(personService.getPerson(JOHN_DOE.iterator().next(),
         DEFAULT_FIELDS, token)).andReturn(ImmediateFuture.newInstance(data));
 
@@ -192,7 +199,8 @@
   public void testHandleGetPlural() throws Exception {
     setPath("/people/john.doe,jane.doe/@self");
 
-    RestfulCollection<Person> data = new RestfulCollection<Person>(null, null);
+    List<Person> people = ImmutableList.of();
+    RestfulCollection<Person> data = new RestfulCollection<Person>(people);
     Set<UserId> userIdSet = Sets.newLinkedHashSet(JOHN_DOE);
     userIdSet.add(new UserId(UserId.Type.userId, "jane.doe"));
     EasyMock.expect(personService.getPeople(userIdSet,
@@ -208,19 +216,39 @@
 
   public void testHandleDelete() throws Exception {
     replay();
-    assertEquals(ResponseError.BAD_REQUEST, handler.handleDelete(request).get().getError());
+    try {
+      handler.handleDelete(request);
+      fail();
+    } catch (SocialSpiException spe) {
+      assertEquals(ResponseError.BAD_REQUEST, spe.getError());
+    }
+
     verify();
   }
 
   public void testHandlePut() throws Exception {
     replay();
-    assertEquals(ResponseError.NOT_IMPLEMENTED, handler.handlePut(request).get().getError());
+
+    try {
+      handler.handlePut(request).get();
+      fail();
+    } catch (SocialSpiException spe) {
+      assertEquals(ResponseError.NOT_IMPLEMENTED, spe.getError());
+    }
+
     verify();
   }
 
   public void testHandlePost() throws Exception {
     replay();
-    assertEquals(ResponseError.NOT_IMPLEMENTED, handler.handlePost(request).get().getError());
+
+    try {
+      handler.handlePost(request).get();
+      fail();
+    } catch (SocialSpiException spe) {
+      assertEquals(ResponseError.NOT_IMPLEMENTED, spe.getError());
+    }
+
     verify();
   }
 }

Modified: incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/spi/DataRequestHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/spi/DataRequestHandlerTest.java?rev=690036&r1=690035&r2=690036&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/spi/DataRequestHandlerTest.java (original)
+++ incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/spi/DataRequestHandlerTest.java Thu Aug 28 15:46:19 2008
@@ -17,15 +17,15 @@
  */
 package org.apache.shindig.social.opensocial.spi;
 
+import junit.framework.TestCase;
+
 import org.apache.shindig.common.util.ImmediateFuture;
 import org.apache.shindig.social.ResponseError;
-import org.apache.shindig.social.ResponseItem;
 import org.apache.shindig.social.opensocial.service.DataRequestHandler;
 import org.apache.shindig.social.opensocial.service.RequestItem;
 import org.apache.shindig.social.opensocial.service.RestfulRequestItem;
 
-import junit.framework.TestCase;
-
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 
 public class DataRequestHandlerTest extends TestCase {
@@ -35,20 +35,20 @@
   @Override
   protected void setUp() throws Exception {
     drh = new DataRequestHandler() {
-      protected Future<? extends ResponseItem> handleDelete(RequestItem request) {
-        return ImmediateFuture.newInstance(new RestfulItem<String>("DELETE"));
+      protected Future<?> handleDelete(RequestItem request) {
+        return ImmediateFuture.newInstance("DELETE");
       }
 
-      protected Future<? extends ResponseItem> handlePut(RequestItem request) {
-        return ImmediateFuture.newInstance(new RestfulItem<String>("PUT"));
+      protected Future<?> handlePut(RequestItem request) {
+        return ImmediateFuture.newInstance("PUT");
       }
 
-      protected Future<? extends ResponseItem> handlePost(RequestItem request) {
-        return ImmediateFuture.newInstance(new RestfulItem<String>("POST"));
+      protected Future<?> handlePost(RequestItem request) {
+        return ImmediateFuture.newInstance("POST");
       }
 
-      protected Future<? extends ResponseItem> handleGet(RequestItem request) {
-        return ImmediateFuture.newInstance(new RestfulItem<String>("GET"));
+      protected Future<?> handleGet(RequestItem request) {
+        return ImmediateFuture.newInstance("GET");
       }
     };
   }
@@ -62,19 +62,7 @@
 
   private void verifyItemDispatchMethodCalled(String methodName) throws Exception {
     RestfulRequestItem request = new RestfulRequestItem(null, methodName, null, null);
-    assertEquals(methodName, ((RestfulItem<String>) drh.handleItem(request).get()).getEntry());
-  }
-
-  public void testHandleMethodSuccess() throws Exception {
-    verifyDispatchMethodCalled("DELETE");
-    verifyDispatchMethodCalled("PUT");
-    verifyDispatchMethodCalled("POST");
-    verifyDispatchMethodCalled("GET");
-  }
-
-  private void verifyDispatchMethodCalled(String methodName) throws Exception {
-    RestfulRequestItem request = new RestfulRequestItem(null, methodName, null, null);
-    assertEquals(methodName, ((RestfulItem<String>) drh.handleItem(request).get()).getEntry());
+    assertEquals(methodName, drh.handleItem(request).get());
   }
 
   public void testHandleMethodWithInvalidMethod() throws Exception {
@@ -85,7 +73,13 @@
 
   private void verifyExceptionThrown(String methodName) throws Exception {
     RestfulRequestItem request = new RestfulRequestItem(null, methodName, null, null);
-    Future<? extends ResponseItem> err = drh.handleItem(request);
-    assertEquals(err.get().getError(), ResponseError.NOT_IMPLEMENTED);
+    Future<?> err = drh.handleItem(request);
+    try {
+      err.get();
+    } catch (ExecutionException ee) {
+      assertTrue(ee.getCause() instanceof SocialSpiException);
+      SocialSpiException spe = (SocialSpiException) ee.getCause();
+      assertEquals(ResponseError.NOT_IMPLEMENTED, spe.getError());
+    }
   }
 }

Modified: incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialServiceTest.java?rev=690036&r1=690035&r2=690036&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialServiceTest.java (original)
+++ incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialServiceTest.java Thu Aug 28 15:46:19 2008
@@ -18,24 +18,26 @@
  */
 package org.apache.shindig.social.sample.spi;
 
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+
+import junit.framework.TestCase;
+
 import org.apache.shindig.common.SecurityToken;
 import org.apache.shindig.common.testing.FakeGadgetToken;
 import org.apache.shindig.social.SocialApiTestsGuiceModule;
+import org.apache.shindig.social.ResponseError;
 import org.apache.shindig.social.opensocial.model.Activity;
 import org.apache.shindig.social.opensocial.model.Person;
+import org.apache.shindig.social.opensocial.spi.CollectionOptions;
 import org.apache.shindig.social.opensocial.spi.DataCollection;
 import org.apache.shindig.social.opensocial.spi.GroupId;
 import org.apache.shindig.social.opensocial.spi.PersonService;
 import org.apache.shindig.social.opensocial.spi.RestfulCollection;
-import org.apache.shindig.social.opensocial.spi.RestfulItem;
 import org.apache.shindig.social.opensocial.spi.UserId;
-import org.apache.shindig.social.opensocial.spi.CollectionOptions;
-
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import junit.framework.TestCase;
+import org.apache.shindig.social.opensocial.spi.SocialSpiException;
 
 import java.util.Collections;
 
@@ -62,20 +64,20 @@
   }
 
   public void testGetPersonDefaultFields() throws Exception {
-    RestfulItem<Person> personResponseItem = db
+    Person person = db
         .getPerson(CANON_USER, Person.Field.DEFAULT_FIELDS, token).get();
 
-    assertNotNull("Canonical user not found", personResponseItem.getEntry());
-    assertNotNull("Canonical user has no id", personResponseItem.getEntry().getId());
-    assertNotNull("Canonical user has no name", personResponseItem.getEntry().getName());
+    assertNotNull("Canonical user not found", person);
+    assertNotNull("Canonical user has no id", person.getId());
+    assertNotNull("Canonical user has no name", person.getName());
     assertNotNull("Canonical user has no thumbnail",
-        personResponseItem.getEntry().getThumbnailUrl());
+        person.getThumbnailUrl());
   }
 
   public void testGetPersonAllFields() throws Exception {
-    RestfulItem<Person> personResponseItem = db
+    Person person = db
         .getPerson(CANON_USER, Person.Field.ALL_FIELDS, token).get();
-    assertNotNull("Canonical user not found", personResponseItem.getEntry());
+    assertNotNull("Canonical user not found", person);
   }
 
   public void testGetExpectedFriends() throws Exception {
@@ -133,14 +135,13 @@
   }
 
   public void testGetExpectedActivity() throws Exception {
-    RestfulItem<Activity> responseItem = db.getActivity(
+    Activity activity = db.getActivity(
         CANON_USER, SELF_GROUP, APP_ID,
         Sets.newHashSet("appId", "body", "mediaItems"), APP_ID, new FakeGadgetToken()).get();
-    assertTrue(responseItem != null);
-    assertTrue(responseItem.getEntry() != null);
+    assertNotNull(activity);
     // Check that some fields are fetched and others are not
-    assertTrue(responseItem.getEntry().getBody() != null);
-    assertTrue(responseItem.getEntry().getBodyId() == null);
+    assertNotNull(activity.getBody());
+    assertNull(activity.getBodyId());
   }
 
   public void testDeleteExpectedActivity() throws Exception {
@@ -148,10 +149,14 @@
         new FakeGadgetToken());
 
     // Try to fetch the activity
-    RestfulItem<Activity> responseItem = db.getActivity(
-        CANON_USER, SELF_GROUP, APP_ID,
-        Sets.newHashSet("appId", "body", "mediaItems"), APP_ID, new FakeGadgetToken()).get();
-    assertTrue(responseItem.getEntry() == null);
+    try {
+      db.getActivity(
+          CANON_USER, SELF_GROUP, APP_ID,
+          Sets.newHashSet("appId", "body", "mediaItems"), APP_ID, new FakeGadgetToken()).get();
+      fail();
+    } catch (SocialSpiException sse) {
+      assertEquals(ResponseError.BAD_REQUEST, sse.getError());
+    }
   }
 
   public void testGetExpectedAppData() throws Exception {