You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by gr...@apache.org on 2014/12/19 18:04:00 UTC

incubator-usergrid git commit: Revert "Added uuid's to group test."

Repository: incubator-usergrid
Updated Branches:
  refs/heads/UG-rest-test-framework-overhaul 2a76dbc7b -> ab3ae1e1c


Revert "Added uuid's to group test."

This reverts commit 2a76dbc7b07af79d2854a0e90c60345cb36ea2ee.


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

Branch: refs/heads/UG-rest-test-framework-overhaul
Commit: ab3ae1e1c375589cb376bb983c7d08119068b683
Parents: 2a76dbc
Author: grey <gr...@apigee.com>
Authored: Fri Dec 19 09:03:16 2014 -0800
Committer: grey <gr...@apigee.com>
Committed: Fri Dec 19 09:03:16 2014 -0800

----------------------------------------------------------------------
 .../collection/groups/GroupResourceIT.java      | 201 +++++++++----------
 .../endpoints/CollectionEndpoint.java           |   4 +-
 .../rest/test/resource2point0/model/Entity.java | 184 ++++++++++++++++-
 3 files changed, 275 insertions(+), 114 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ab3ae1e1/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/groups/GroupResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/groups/GroupResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/groups/GroupResourceIT.java
index ea744af..79ce8c5 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/groups/GroupResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/groups/GroupResourceIT.java
@@ -17,16 +17,13 @@
 package org.apache.usergrid.rest.applications.collection.groups;
 
 
-import com.fasterxml.jackson.databind.JsonNode;
 import java.io.IOException;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.UUID;
 
+import com.fasterxml.jackson.databind.JsonNode;
 import com.sun.jersey.api.client.UniformInterfaceException;
-
-import org.apache.usergrid.persistence.index.utils.UUIDUtils;
 import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT;
 import org.apache.usergrid.rest.test.resource2point0.model.ApiResponse;
 import org.apache.usergrid.rest.test.resource2point0.model.Entity;
@@ -51,18 +48,17 @@ public class GroupResourceIT extends AbstractRestIT {
     @Test()
     public void createGroupValidation() throws IOException {
 
-        String groupName = "testgroup"+ UUIDUtils.newTimeUUID();
-        String groupPath = groupName;
+        String groupName = "testgroup";
+        String groupPath = "testgroup";
 
-        Entity group = new Entity();
-        group.put("name", groupName);
-        group.put("path", groupPath);
-        Entity groupResponse = null;
+        Entity payload = new Entity();
+        payload.put("name", groupName);
+        payload.put("path", groupPath);
 
-        groupResponse = this.app().collection( "groups" ).post( group );
+        Entity group = this.app().collection("groups").post(payload);
 
-        assertEquals( groupPath, groupResponse.get( "path" ) );
-        assertEquals( groupName, groupResponse.get("name"));
+        assertEquals(group.get("path"), groupPath);
+        assertEquals(group.get("name"), groupName);
 
     }
 
@@ -73,15 +69,20 @@ public class GroupResourceIT extends AbstractRestIT {
 
     @Test()
     public void createGroupSlashInNameAndPathValidation() throws IOException {
-/*
+
         //create the group with a slash in the name
         String groupNameSlash = "test/group";
         String groupPathSlash = "test/group";
-        Group group = new Group(groupNameSlash, groupPathSlash);
-        Group testGroup = this.app().groups().post(group);
-        assertNull(testGroup.get("errors"));
-        assertEquals(testGroup.get("path"), groupPathSlash);
-*/
+
+        Entity payload = new Entity();
+        payload.put("name", groupNameSlash);
+        payload.put("path", groupPathSlash);
+
+        Entity group = this.app().collection("groups").post(payload);
+
+        assertEquals(group.get("name"), groupNameSlash);
+        assertEquals(group.get("path"), groupPathSlash);
+
     }
 
     /***
@@ -91,15 +92,20 @@ public class GroupResourceIT extends AbstractRestIT {
 
     @Test()
     public void createGroupSpaceInNameValidation() throws IOException {
-/*
+
         //create the group with a space in the name
         String groupSpaceName = "test group";
         String groupPath = "testgroup";
-        Group group = new Group(groupSpaceName, groupPath);
-        Group testGroup = this.app().groups().post(group);
-        assertNull(testGroup.getError());
-        assertEquals(testGroup.get("path"), groupPath);
-*/
+
+        Entity payload = new Entity();
+        payload.put("name", groupSpaceName);
+        payload.put("path", groupPath);
+
+        Entity group = this.app().collection("groups").post(payload);
+
+        assertEquals(group.get("name"), groupSpaceName);
+        assertEquals(group.get("path"), groupPath);
+
     }
 
     /***
@@ -112,128 +118,80 @@ public class GroupResourceIT extends AbstractRestIT {
 
         String groupName = "testgroup";
         String groupSpacePath = "test group";
-        //Group group = new Group(groupName, groupSpacePath);
 
-        /*
+        Entity payload = new Entity();
+        payload.put("name", groupName);
+        payload.put("path", groupSpacePath);
+
+
         try {
-            Group testGroup = this.app().groups().post(group);
+            this.app().collection("groups").post(payload);
+            fail("Should not be able to create a group with a space in the path");
         } catch (UniformInterfaceException e) {
             //verify the correct error was returned
             JsonNode node = mapper.readTree( e.getResponse().getEntity( String.class ));
             assertEquals( "illegal_argument", node.get( "error" ).textValue() );
         }
-*/
-        /*
-        Group testGroup = this.app().groups().post(group);
-
-        group.save();
 
-        group.connect()..
-
-        String error = testGroup.getError();
-        String errorCode = testGroup.getErrorCode();
-        String errorDescription = testGroup.getErrorDescription();
-        assertEquals(testGroup.getError(), "illegal_argument");
-*/
     }
 
     /***
      *
      * Verify that we can create a group and then change the name
-     *//*
+     */
     @Test()
     public void changeGroupNameValidation() throws IOException {
 
         String groupName = "testgroup";
         String groupPath = "testgroup";
         String newGroupPath = "newtestgroup";
-        Group testGroup = this.app().groups().post(new Group(groupName, groupPath));
-        assertNull(testGroup.get("errors"));
-        assertEquals(testGroup.get("path"), groupPath);
-        /** connections
-         *   this.app().groups()
-         .entityResource("carlovers")
-         .connections("likes","cars")
-         .connection("ferraris").delete();
-         */
-    /*
-        //now change the name
-        testGroup.put("path", newGroupPath);
-        Group group = this.app().groups().uniqueID(testGroup.getName()).put(testGroup);
-        Group group = this.app().collection("groups").uniqueID(testGroup.get("username")).put(testGroup);
-
-        assertNull(testGroup.get("errors"));
-        assertEquals(testGroup.get("path"), newGroupPath);
-
-
-        //now delete the group
-        this.app().groups().uniqueID(testGroup.getName()).delete();
-
-
-        Group newGroup = this.app().groups().uniqueID(groupName).get();
-        if (newGroup.hasError()) {
-            assertEquals(newGroup.ErrorMessage(), "some error");
-            assertNotEquals(newGroup.ErrorCode(), "400");
-
-        }
-            /*
-            if (newgroup.ErrorMessage() == "some error") {
-
-            }
-
 
+        Entity payload = new Entity();
+        payload.put("name", groupName);
+        payload.put("path", groupPath);
 
-            if (newGroup.errorCode() == "400") {
+        Entity group = this.app().collection("groups").post(payload);
+        assertEquals(group.get("path"), groupPath);
 
+        //now change the name
+        group.put("path", newGroupPath);
+        this.app().collection("groups").entity(group).put(group);
+        assertEquals(group.get("path"), newGroupPath);
 
-            } else if (newGroup.errorCode() == "500") {
+        //now delete the group
+        ApiResponse response = this.app().collection("groups").entity(group).delete();
 
-            }
-        }
 
-        /*
         try {
-            //now get the group again
-
-            Group newGroup = this.app().groups().uniqueID(groupName).get();
-            fail("doh!");
-
-
-
+            Entity newGroup = this.app().collection("groups").uniqueID(groupName).get();
+            fail("Entity still exists");
         } catch (UniformInterfaceException e) {
             //verify the correct error was returned
             JsonNode node = mapper.readTree( e.getResponse().getEntity( String.class ));
             assertEquals( "illegal_argument", node.get( "error" ).textValue() );
         }
-        */
-   // }
 
+    }
 
     /***
      *
-     * Verify that we cannot create a group with a space in the path
+     * Verify that we can create a group and then add a user to it
      */
-    /*
-    @Test
-    public void postGroupActivity() throws IOException {
-
-
-        //1. create a group
-        GroupsCollection groups = context.groups();
-
-        //create a group with a normal name
-        String groupName = "groupTitle";
-        String groupPath = "groupPath";
-        JsonNode testGroup = groups.create(groupName, groupPath);
-        //verify the group was created
-        assertNull(testGroup.get("errors"));
-        assertEquals(testGroup.get("path").asText(), groupPath);
+    @Test()
+    public void createGroupAndAddAUserValidation() throws IOException {
 
-        //2. post group activity
+    }
+    /***
+     *
+     * Verify that we can create a group and then add a role to it
+     */
+    @Test()
+    public void createGroupAndAddARoleValidation() throws IOException {
 
-        //TODO: actually post a group activity
     }
 
+    /*
+
     @Test
     public void addRemovePermission() throws IOException {
 
@@ -386,4 +344,33 @@ public class GroupResourceIT extends AbstractRestIT {
     }
     */
 
+
+    /***
+     *
+     * Post a group activity
+     */
+
+    @Test
+    public void postGroupActivity() throws IOException {
+
+        /*
+
+        //1. create a group
+        GroupsCollection groups = context.groups();
+
+        //create a group with a normal name
+        String groupName = "groupTitle";
+        String groupPath = "groupPath";
+        JsonNode testGroup = groups.create(groupName, groupPath);
+        //verify the group was created
+        assertNull(testGroup.get("errors"));
+        assertEquals(testGroup.get("path").asText(), groupPath);
+
+        //2. post group activity
+
+        //TODO: actually post a group activity
+        */
+    }
+
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ab3ae1e1/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/CollectionEndpoint.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/CollectionEndpoint.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/CollectionEndpoint.java
index b96e999..c060536 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/CollectionEndpoint.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/CollectionEndpoint.java
@@ -16,8 +16,6 @@
  */
 package org.apache.usergrid.rest.test.resource2point0.endpoints;
 
-import java.util.Map;
-
 import com.sun.jersey.api.client.WebResource;
 import org.apache.usergrid.rest.test.resource2point0.model.ApiResponse;
 import org.apache.usergrid.rest.test.resource2point0.model.Collection;
@@ -179,7 +177,7 @@ public class CollectionEndpoint extends NamedResource {
      */
     public Entity post(Entity payload){
         ApiResponse response = getResource(true).type( MediaType.APPLICATION_JSON_TYPE ).accept(MediaType.APPLICATION_JSON)
-                .post(ApiResponse.class, payload);
+                .post(ApiResponse.class, payload.getDynamicProperties());
         return new Entity(response);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ab3ae1e1/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Entity.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Entity.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Entity.java
index be6efca..22217f8 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Entity.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Entity.java
@@ -39,6 +39,7 @@ import static org.apache.usergrid.persistence.Schema.PROPERTY_NAME;
  * minumum of what other classes use. Such as . users or groups.
  */
 
+@XmlRootElement
 public class Entity implements Serializable, Map<String,Object> {
 
 
@@ -56,12 +57,86 @@ public class Entity implements Serializable, Map<String,Object> {
         this.response = response;
 
         if(response.getEntities() !=null &&  response.getEntities().size()>=1){
-                    List<Entity>  entities =  response.getEntities();
-                    Map<String,Object> entity = entities.get(0);
-                    this.putAll(entity);
-                }
+            List<Entity>  entities =  response.getEntities();
+            Map<String,Object> entity = entities.get(0);
+            this.putAll(entity);
+        }
     }
 
+    public UUID getUuid(){
+        return  UUID.fromString( (String) get("uuid") );
+    }
+
+
+    public void setUuid( UUID uuid ) {
+        put("uuid", uuid);
+    }
+
+    //TODO: see if this is needed
+    //    @JsonSerialize( include = JsonSerialize.Inclusion.NON_NULL )
+    public String getType() {
+        return (String) get( "type" );
+    }
+
+
+    public void setType( String type ) {
+        put("type",type);
+    }
+
+    public Long getCreated() {
+        return (Long) get( "created" );
+    }
+
+
+    public void setCreated( Long created ) {
+        if ( created == null ) {
+            created = System.currentTimeMillis();
+        }
+        put( "created", created );
+    }
+
+
+    public Long getModified() {
+        return (Long) get( "modified" );
+    }
+
+
+    public void setModified( Long modified ) {
+        if ( modified == null ) {
+            modified = System.currentTimeMillis();
+        }
+        put( "modified", modified );
+    }
+
+
+    public String getName() {
+        Object value = getProperty( PROPERTY_NAME );
+
+        if ( value instanceof UUID ) {
+            // fixes existing data that uses UUID in USERGRID-2099
+            return value.toString();
+        }
+
+        return (String) get( "name" );
+    }
+
+
+    @JsonIgnore
+    public Map<String, Object> getProperties() {
+        return dynamic_properties;
+    }
+
+
+    public final Object getProperty( String propertyName ) {
+        return get( propertyName );
+    }
+
+
+
+    public Entity addProperty(String key, Object value){
+        put(key,value);
+        return this;
+    }
     public void setProperties( Map<String, Object> properties ) {
         putAll( properties );
     }
@@ -75,6 +150,107 @@ public class Entity implements Serializable, Map<String,Object> {
         return this;
     }
 
+    public Object getMetadata( String key ) {
+        return getDataset( "metadata", key );
+    }
+
+
+    public void setMetadata( String key, Object value ) {
+        setDataset( "metadata", key, value );
+    }
+
+
+    public void mergeMetadata( Map<String, Object> new_metadata ) {
+        mergeDataset( "metadata", new_metadata );
+    }
+
+
+    public void clearMetadata() {
+        clearDataset("metadata");
+    }
+
+
+    public <T> T getDataset( String property, String key ) {
+        Object md = get( property );
+        if ( md == null ) {
+            return null;
+        }
+        if ( !( md instanceof Map<?, ?> ) ) {
+            return null;
+        }
+        @SuppressWarnings( "unchecked" ) Map<String, T> metadata = ( Map<String, T> ) md;
+        return metadata.get( key );
+    }
+
+
+    public <T> void setDataset( String property, String key, T value ) {
+        if ( key == null ) {
+            return;
+        }
+        Object md = get( property );
+        if ( !( md instanceof Map<?, ?> ) ) {
+            md = new HashMap<String, T>();
+            put( property, md );
+        }
+        @SuppressWarnings( "unchecked" ) Map<String, T> metadata = ( Map<String, T> ) md;
+        metadata.put(key, value);
+    }
+
+
+    public <T> void mergeDataset( String property, Map<String, T> new_metadata ) {
+        Object md = get( property );
+        if ( !( md instanceof Map<?, ?> ) ) {
+            md = new HashMap<String, T>();
+            put( property, md );
+        }
+        @SuppressWarnings( "unchecked" ) Map<String, T> metadata = ( Map<String, T> ) md;
+        metadata.putAll( new_metadata );
+    }
+
+
+    public void clearDataset( String property ) {
+        remove(property);
+    }
+
+
+    public List<org.apache.usergrid.persistence.Entity> getCollections( String key ) {
+        return getDataset( "collections", key );
+    }
+
+
+    public void setCollections( String key, List<org.apache.usergrid.persistence.Entity> results ) {
+        setDataset("collections", key, results);
+    }
+
+
+    public List<org.apache.usergrid.persistence.Entity> getConnections( String key ) {
+        return getDataset( "connections", key );
+    }
+
+
+    public void setConnections( String key, List<org.apache.usergrid.persistence.Entity> results ) {
+        setDataset( "connections", key, results );
+    }
+
+
+    public String toString() {
+        return "Entity(" + getProperties() + ")";
+    }
+
+    @JsonAnySetter
+    public void setDynamicProperty( String key, Object value ) {
+        if ( value == null || value.equals( "" ) ) {
+            if ( containsKey( key ) ) {
+                remove( key );
+            }
+        }
+        else {
+            put( key, value );
+        }
+    }
+
+
+    @JsonAnyGetter
     public Map<String, Object> getDynamicProperties() {
         return dynamic_properties;
     }