usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [33/42] git commit: Issues fix for USERGRID-3011. Added test cases proving issue by deleting entities with preexisting connections.
Date Wed, 05 Feb 2014 01:21:43 GMT
Issues fix for USERGRID-3011.
Added test cases proving issue by deleting entities with preexisting connections.


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/443438fc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/443438fc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/443438fc

Branch: refs/pull/27/merge
Commit: 443438fc3072e6ca70a22e6f6a485c209c2d632f
Parents: 304cd69
Author: GERey <greyes@apigee.com>
Authored: Thu Jan 30 09:32:57 2014 -0800
Committer: GERey <greyes@apigee.com>
Committed: Thu Jan 30 09:32:57 2014 -0800

----------------------------------------------------------------------
 .../cassandra/RelationManagerImpl.java          | 28 ++++++++-----
 .../users/ConnectionResourceTest.java           | 43 ++++++++++++++++++++
 2 files changed, 61 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/443438fc/stack/core/src/main/java/org/usergrid/persistence/cassandra/RelationManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/usergrid/persistence/cassandra/RelationManagerImpl.java
b/stack/core/src/main/java/org/usergrid/persistence/cassandra/RelationManagerImpl.java
index 4f565c7..3414139 100644
--- a/stack/core/src/main/java/org/usergrid/persistence/cassandra/RelationManagerImpl.java
+++ b/stack/core/src/main/java/org/usergrid/persistence/cassandra/RelationManagerImpl.java
@@ -1086,22 +1086,30 @@ public class RelationManagerImpl implements RelationManager {
 
 
         PagingResultsIterator itr =
-                new PagingResultsIterator( getConnectingEntities( headEntity, null, null,
Level.REFS ) );
+                new PagingResultsIterator( getConnectedEntities( headEntity, null, null,
Level.REFS ) );
 
-        ConnectionRefImpl connection;
+        ConnectionRefImpl connection = null;
 
         while ( itr.hasNext() ) {
-            connection = ( ConnectionRefImpl ) itr.next();
+            Object itrObj = itr.next();
+            if ( itrObj instanceof ConnectionRefImpl ) {
+                connection = (ConnectionRefImpl) itrObj;
+            }
+            else if ( itrObj instanceof SimpleEntityRef ) {
+                connection = new ConnectionRefImpl( (SimpleEntityRef) itrObj );
+            }
+            else {
+                if ( itrObj instanceof EntityRef ) {
+                    connection = new ConnectionRefImpl( new SimpleEntityRef((EntityRef) itr.next()));
+                }
+                else if ( itrObj instanceof UUID ) {
+                    connection = new ConnectionRefImpl( new SimpleEntityRef((UUID)itr.next()));
+                }
+            }
+
 
             batchUpdateEntityConnection( batch, true, connection, timestampUuid );
         }
-        //
-        //    List<ConnectionRefImpl> connections = getConnectionsWithEntity(headEntity.getUuid());
-        //    if (connections != null) {
-        //      for (ConnectionRefImpl connection : connections) {
-        //        batchUpdateEntityConnection(batch, true, connection, timestampUuid);
-        //      }
-        //    }
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/443438fc/stack/rest/src/test/java/org/usergrid/rest/applications/users/ConnectionResourceTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/usergrid/rest/applications/users/ConnectionResourceTest.java
b/stack/rest/src/test/java/org/usergrid/rest/applications/users/ConnectionResourceTest.java
index ab29ea8..af8e8b0 100644
--- a/stack/rest/src/test/java/org/usergrid/rest/applications/users/ConnectionResourceTest.java
+++ b/stack/rest/src/test/java/org/usergrid/rest/applications/users/ConnectionResourceTest.java
@@ -17,6 +17,7 @@ import org.usergrid.rest.test.resource.CustomCollection;
 import com.sun.jersey.api.client.ClientResponse;
 import com.sun.jersey.api.client.UniformInterfaceException;
 
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.usergrid.utils.MapUtils.hashMap;
@@ -190,4 +191,46 @@ public class ConnectionResourceTest extends AbstractRestIT {
 
         assertEquals( "Should point to thing2 as an entity connection", thing2Id, returned
);
     }
+
+    @Test //USERGRID-3011
+    public void connectionsDeleteSecondEntityInConnectionTest() {
+
+        CustomCollection things = context.collection( "things" );
+
+        UUID thing1Id = getEntityId( things.create( hashMap( "name", "thing1" ) ), 0 );
+
+        UUID thing2Id = getEntityId( things.create( hashMap( "name", "thing2" ) ), 0 );
+
+        //create the connection
+        things.entity( thing1Id ).connection( "likes" ).entity( thing2Id ).post();
+
+        JsonNode response = things.entity( "thing2" ).delete();
+
+        JsonNode node = things.entity ( "thing2" ).get();
+
+        assertNull(node);
+
+    }
+
+    @Test //USERGRID-3011
+    public void connectionsDeleteFirstEntityInConnectionTest() {
+
+        CustomCollection things = context.collection( "things" );
+
+        UUID thing1Id = getEntityId( things.create( hashMap( "name", "thing1" ) ), 0 );
+
+        UUID thing2Id = getEntityId( things.create( hashMap( "name", "thing2" ) ), 0 );
+
+        //create the connection
+        things.entity( thing1Id ).connection( "likes" ).entity( thing2Id ).post();
+
+        JsonNode response = things.entity( "thing1" ).delete();
+
+        JsonNode node = things.entity ( "thing1" ).get();
+
+        assertNull(node);
+
+    }
+
+
 }


Mime
View raw message