shindig-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rbaxte...@apache.org
Subject svn commit: r1349598 - in /shindig/trunk/java/social-api/src: main/java/org/apache/shindig/social/opensocial/spi/GroupId.java test/java/org/apache/shindig/social/opensocial/spi/GroupIdTest.java
Date Wed, 13 Jun 2012 00:30:05 GMT
Author: rbaxter85
Date: Wed Jun 13 00:30:04 2012
New Revision: 1349598

URL: http://svn.apache.org/viewvc?rev=1349598&view=rev
Log:
SHINDIG-1796
Using custom @ ids GroupIds throws IllegalArgumentException

Modified:
    shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/spi/GroupId.java
    shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/spi/GroupIdTest.java

Modified: shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/spi/GroupId.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/spi/GroupId.java?rev=1349598&r1=1349597&r2=1349598&view=diff
==============================================================================
--- shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/spi/GroupId.java
(original)
+++ shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/spi/GroupId.java
Wed Jun 13 00:30:04 2012
@@ -31,7 +31,8 @@ public class GroupId {
     objectId  (0),
     self      (1),
     friends   (2),
-    all       (3);
+    all       (3),
+    custom   (4);
 
     private final int id;
     Type(int id) { this.id = id; }
@@ -56,7 +57,7 @@ public class GroupId {
       this.objectId = (ObjectId) objectId;
     // Else it must be a string, store as such
     } else {
-      if(getType(objectId).equals(Type.objectId)) {
+      if(Type.objectId.equals(getType(objectId))) {
         this.objectId = new ObjectId(objectId.toString());
       } else {
         this.objectId = objectId.toString();
@@ -76,6 +77,9 @@ public class GroupId {
     if(type.equals(Type.objectId)) {
       this.objectId = new ObjectId(objectId);
     // Else store the string representation of the type
+    } else if(Type.custom.equals(type)){
+      //Custom @ id
+      this.objectId = objectId; 
     } else {
       this.objectId = typeToString(type);
     }
@@ -88,9 +92,9 @@ public class GroupId {
    * @return JSON string value
    */
   private String typeToString(Type type) {
-    if(type.equals(Type.all)) {
+    if(Type.all.equals(type)) {
       return "@all";
-    } else if(type.equals(Type.friends)) {
+    } else if(Type.friends.equals(type)) {
       return "@friends";
     } else {
       return "@self";
@@ -119,6 +123,10 @@ public class GroupId {
       return Type.friends;
     } else if(type.equals("all")) {
       return Type.all;
+    } else if(objectId instanceof String && ((String)objectId).startsWith("@")) {
+    	// Could be a custom @ id, and it certainly is not an object id
+    	// return null we don't know the type
+    	return Type.custom;
     } else {
       return Type.objectId;
     }

Modified: shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/spi/GroupIdTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/spi/GroupIdTest.java?rev=1349598&r1=1349597&r2=1349598&view=diff
==============================================================================
--- shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/spi/GroupIdTest.java
(original)
+++ shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/spi/GroupIdTest.java
Wed Jun 13 00:30:04 2012
@@ -19,6 +19,7 @@
 
 package org.apache.shindig.social.opensocial.spi;
 
+import org.apache.shindig.social.opensocial.spi.GroupId.Type;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -38,6 +39,10 @@ public class GroupIdTest extends Assert 
     GroupId group = GroupId.fromJson("superbia");
     assertEquals(GroupId.Type.objectId, group.getType());
     assertEquals("superbia", group.getObjectId().toString());
+
+    GroupId unknown = GroupId.fromJson("@foo");
+    assertEquals(Type.custom, unknown.getType());
+    assertEquals("@foo", unknown.getObjectId().toString());
   }
 
   @Test
@@ -51,6 +56,31 @@ public class GroupIdTest extends Assert 
 
     assertEquals(g1.getType(), g2.getType());
     assertEquals(g1.getObjectId().toString(), g2.getObjectId().toString());
+
+    GroupId g3 =  new GroupId("@foo");
+    assertEquals(Type.custom, g3.getType());
+    assertEquals("@foo", g3.getObjectId().toString());
+
+    GroupId g4 = new GroupId(Type.objectId, "example.com:195mg90a39v");
+    assertEquals(Type.objectId, g4.getType());
+    assertEquals("example.com:195mg90a39v", g4.getObjectId().toString());
+
+    GroupId g5 = new GroupId(Type.custom, "@foo");
+    assertEquals(Type.custom, g5.getType());
+    assertEquals("@foo", g5.getObjectId().toString());
+
+    GroupId g6 = new GroupId(Type.all, "something");
+    assertEquals(Type.all, g6.getType());
+    assertEquals("@all", g6.getObjectId().toString());
+
+    GroupId g7 = new GroupId(Type.self, null);
+    assertEquals(Type.self, g7.getType());
+    assertEquals("@self", g7.getObjectId().toString());
+
+    GroupId g8 = new GroupId(Type.friends, "bar");
+    assertEquals(Type.friends, g8.getType());
+    assertEquals("@friends", g8.getObjectId().toString());
+
   }
 
   @Test(expected=IllegalArgumentException.class)



Mime
View raw message