usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [2/3] incubator-usergrid git commit: Added missing comment to tests in OwnershipResourceIT Added revamped comments and cleaned the tests in ConnectionResourceTest
Date Thu, 08 Jan 2015 21:54:17 GMT
Added missing comment to tests in OwnershipResourceIT
Added revamped comments and cleaned the tests in ConnectionResourceTest


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

Branch: refs/heads/USERGRID-313
Commit: 944bcf9b1a480699a8343190a4820161b9f5ee3e
Parents: 0b89441
Author: grey <greyes@apigee.com>
Authored: Thu Jan 8 11:45:16 2015 -0800
Committer: grey <greyes@apigee.com>
Committed: Thu Jan 8 11:45:16 2015 -0800

----------------------------------------------------------------------
 .../users/ConnectionResourceTest.java           | 151 ++++++++++---------
 .../collection/users/OwnershipResourceIT.java   |   6 +-
 2 files changed, 84 insertions(+), 73 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/944bcf9b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java
index 2949b85..8ab63f7 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java
@@ -30,6 +30,8 @@ import org.apache.usergrid.rest.test.resource2point0.model.ApiResponse;
 import org.apache.usergrid.rest.test.resource2point0.model.Collection;
 import org.apache.usergrid.rest.test.resource2point0.model.Entity;
 import org.apache.usergrid.rest.test.resource2point0.model.User;
+
+import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
@@ -42,86 +44,98 @@ import static org.junit.Assert.*;
 
 
 /**
- * // TODO: Document this
- *
- * @author ApigeeCorporation
- * @since 4.0
+ * Contains tests that center around using connections with entities and users.
  */
 public class ConnectionResourceTest extends AbstractRestIT {
 
+    private CollectionEndpoint thingsResource;
+    private UUID thing1Id;
+    private UUID thing2Id;
 
 
-    @Test
-    public void connectionsQueryTest() throws IOException {
+    /**
+     * Setup two thing objects for use in the following tests
+     */
+    @Before
+    public void setup(){
+        this.thingsResource =  this.app().collection("things");
+
+        thing1Id =  thingsResource.post( new Entity().chainPut("name", "thing1") ).getUuid();
+
+        thing2Id = thingsResource.post( new Entity().chainPut("name", "thing2") ).getUuid();
 
+        refreshIndex();
+    }
+    /**
+     * Checks to see that a connection associated with one user cannot be retrieved by a
different user.
+     * @throws IOException
+     */
+    @Test
+    public void connectionMisMatchTest() throws IOException {
 
+        //Creates collection and posts a chicken entity to it.
         CollectionEndpoint activities = this.app().collection("peeps");
 
         Entity stuff = new Entity().chainPut("name", "chicken").chainPut("type","chicken");
 
         activities.post(stuff);
 
-
+        //Create two users
         User payload = new User("todd", "todd", "todd@apigee.com", "password");
-        payload.put("username", "todd");
         this.app().collection("users").post(payload);
         payload = new User("scott", "scott", "scott@apigee.com", "password");
         this.app().collection("users").post(payload);
 
         refreshIndex();
 
-        /*finish setting up the two users */
-
+        //Set user Todd  to connect to the chicken entity.
         Entity entity = this.app().collection("users").entity("todd").connection("likes").collection("peeps").entity("chicken").post();
 
         assertNotNull(entity);
 
         refreshIndex();
 
+        //Get the collection and get the chicken entity.
         Collection collection = this.app().collection("peeps").get();
 
         String uuid = collection.next().get("uuid").toString();
 
-
+        //Set user Scott to get back a nonexistant connection.
         try {
-            entity = this.app().collection("users").entity("scott").connection("likes").entity(uuid).get();
+            this.app().collection("users").entity("scott").connection("likes").entity(uuid).get();
 
             assert ( false );
         }
         catch ( UniformInterfaceException uie ) {
-            assertEquals( 404, uie.getResponse().getClientResponseStatus().getStatusCode()
);
+            assertEquals( 404, uie.getResponse().getStatus() );
         }
     }
 
 
+    /**
+     * Checks that we can setup a connection loop and that we can retrieve both entities
from the loop.
+     * @throws IOException
+     */
     @Test
     public void connectionsLoopbackTest() throws IOException {
 
-        CollectionEndpoint things = this.app().collection("things");
-
-        UUID thing1Id =  things.post( new Entity().chainPut("name", "thing1") ).getUuid();
-
-        UUID thing2Id = things.post( new Entity().chainPut("name", "thing2") ).getUuid();
-
-        refreshIndex();
-
-        //create the connection
-        things.entity( thing1Id ).connection( "likes" ).entity( thing2Id ).post();
-        things.entity( thing2Id ).connection( "likes" ).entity( thing1Id ).post();
+        //create a connection loop by having thing1 connect to thing2 and vise versa.
+        thingsResource.entity( thing1Id ).connection( "likes" ).entity( thing2Id ).post();
+        thingsResource.entity( thing2Id ).connection( "likes" ).entity( thing1Id ).post();
 
         refreshIndex();
 
-        //test we have the "likes" in our connection meta data response
-
+        //Do a get on thing1 to make sure we have the connection present
         Collection collection =this.app().collection("things").entity(thing1Id).connection(
"likes" ).get();
 
         assertTrue("Connection url returned in entity", collection.hasNext());
 
+        //Verify that thing1 is connected to thing2
         UUID returnedUUID  = collection.next().getUuid();
 
         assertEquals( thing2Id, returnedUUID );
 
-        //now follow the loopback, which should be pointers to the other entity
+        //now follow the loopback from thing2, which should be pointers to thing1
 
         collection  = this.app().collection("things").entity(thing2Id).connection("likes").get();
 
@@ -131,38 +145,32 @@ public class ConnectionResourceTest extends AbstractRestIT {
     }
 
 
+    /**
+     * Checks that we can get a valid uuid from a connection url and follow it to the correct
entity.
+     * @throws IOException
+     */
     @Test
-    public void connectionsUUIDTest() throws IOException {
-
-        CollectionEndpoint things = this.app().collection("things");
-
-        UUID thing1Id =   things.post( new Entity().chainPut("name", "thing1") ).getUuid();
+    public void connectionsUrlTest() throws IOException {
 
-        UUID thing2Id =  things.post( new Entity().chainPut("name", "thing2") ).getUuid();
+        //Create a connection between thing1 and thing2
+        thingsResource.entity( thing1Id ).connection( "likes" ).entity( thing2Id ).post();
 
 
         refreshIndex();
 
-        //create the connection
-        things.entity( thing1Id ).connection( "likes" ).entity( thing2Id ).post();
-
-
-        refreshIndex();
-
-        //test we have the "likes" in our connection meta data response
-
-        Entity response = things.entity( "thing1" ).get();
+        //Do a get on thing1 to make sure we have the connection present
+        Entity response = thingsResource.entity( "thing1" ).get();
 
         String url =((Map) ((Map)response.get( "metadata" )).get( "connections" )).get("likes").toString();
 
 
         assertNotNull( "Connection url returned in entity", url );
 
-        //trim off the start /
+        //trim off the starting / from the url.
         url = url.substring( 1 );
 
 
-        //now that we know the URl is correct, follow it
+        //now that we know the URl is correct, follow it to get the entity in the connection
 
         Collection collection = this.app().collection(url).get();
 
@@ -170,38 +178,37 @@ public class ConnectionResourceTest extends AbstractRestIT {
 
         assertEquals( thing2Id, returnedUUID );
 
-        //get on the collection works, now get it directly by uuid
-
-        //now we should get thing1 from the loopback url
-
-        response = things.entity( thing1Id ).connection( "likes" ).entity( thing2Id ).get();
+        //get on the collection works, now get it directly by uuid. We should also get thing1
from the loopback url.
+        response = thingsResource.entity( thing1Id ).connection( "likes" ).entity( thing2Id
).get();
 
         UUID returned = response.getUuid();
 
         assertEquals( "Should point to thing2 as an entity connection", thing2Id, returned
);
     }
 
-    @Test //USERGRID-3011
-    public void connectionsDeleteSecondEntityInConnectionTest() throws IOException {
-
-        CollectionEndpoint things = this.app().collection("things");
 
-        UUID thing1Id =  things.post( new Entity().chainPut("name", "thing1") ).getUuid();
+    /**
+     * Deletes the connected to entity and make sure the delete persists.
+     * @throws IOException
+     */
+    @Test //USERGRID-3011
+    public void deleteConnectedEntity() throws IOException {
 
-        UUID thing2Id = things.post( new Entity().chainPut("name", "thing2") ).getUuid();
+        //create the connection
+        thingsResource.entity( thing1Id ).connection( "likes" ).entity( thing2Id ).post();
 
         refreshIndex();
 
-        //create the connection
-        things.entity( thing1Id ).connection( "likes" ).entity( thing2Id ).post();
-
-        ApiResponse response = things.entity( "thing2" ).delete();
+        //Delete the connected entity.
+        thingsResource.entity( "thing2" ).delete();
 
         refreshIndex();
 
+        //Make sure that we can no longer retrieve the entity.
         int status = 0;
         try {
-            Entity node = things.entity("thing2").get();
+            thingsResource.entity("thing2").get();
+            fail( "Entity should have been deleted." );
         }catch (UniformInterfaceException e){
             status = e.getResponse().getStatus();
         }
@@ -210,27 +217,29 @@ public class ConnectionResourceTest extends AbstractRestIT {
 
     }
 
-    @Test //USERGRID-3011
-    public void connectionsDeleteFirstEntityInConnectionTest() throws IOException {
-
-        CollectionEndpoint things = this.app().collection("things");
 
-        UUID thing1Id =   things.post( new Entity().chainPut("name", "thing1") ).getUuid();
+    /**
+     * Delete the connecting entity and make sure the delete persists.
+     * @throws IOException
+     */
+    @Test //USERGRID-3011
+    public void deleteConnectingEntity() throws IOException {
 
-        UUID thing2Id =   things.post( new Entity().chainPut("name", "thing2") ).getUuid();
+        //create the connection
+        thingsResource.entity( thing1Id ).connection( "likes" ).entity( thing2Id ).post();
 
         refreshIndex();
 
-        //create the connection
-        things.entity( thing1Id ).connection( "likes" ).entity( thing2Id ).post();
-
-        ApiResponse response = things.entity( "thing1" ).delete();
+        //Delete the connecting entity
+        thingsResource.entity( "thing1" ).delete();
 
         refreshIndex();
 
+        //Make sure that we can no longer retrieve the entity.
         int status = 0;
         try {
-            Entity node = things.entity("thing1").get();
+            thingsResource.entity("thing1").get();
+            fail( "Entity should have been deleted." );
         }catch (UniformInterfaceException e){
             status = e.getResponse().getStatus();
         }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/944bcf9b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java
index 30b12f1..52e27c7 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/OwnershipResourceIT.java
@@ -218,7 +218,8 @@ public class OwnershipResourceIT extends AbstractRestIT {
 
 
     /**
-     *
+     * Tests that we can have our own personal connections without being seen by other users,
but are still visible
+     * from a root context. 
      * @throws IOException
      */
     @Test
@@ -373,7 +374,8 @@ public class OwnershipResourceIT extends AbstractRestIT {
 
 
     /**
-     *
+     * Checks that a once guests permissions are opened up that a user can view the connections/entities
+     * and get/post/delete things on that connection.
      * @throws IOException
      */
     @Test


Mime
View raw message