usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From toddn...@apache.org
Subject [10/10] usergrid git commit: adding rest test
Date Thu, 27 Aug 2015 22:16:05 GMT
adding rest test


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

Branch: refs/heads/two-dot-o-dev
Commit: a11aaa03d2237d0d2c8fa02ba1f8e32b44e37ee7
Parents: bed924f
Author: Shawn Feldman <sfeldman@apache.org>
Authored: Wed Aug 26 17:50:15 2015 -0600
Committer: Shawn Feldman <sfeldman@apache.org>
Committed: Wed Aug 26 17:50:15 2015 -0600

----------------------------------------------------------------------
 .../applications/ApplicationResource.java       | 13 +++---
 .../rest/management/ManagementResourceIT.java   | 44 ++++++++++++++------
 .../rest/test/resource/model/Entity.java        |  2 +
 3 files changed, 41 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/a11aaa03/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java
index fcb01d7..df98b43 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java
@@ -50,10 +50,7 @@ import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-import java.util.UUID;
+import java.util.*;
 
 import static javax.servlet.http.HttpServletResponse.SC_ACCEPTED;
 import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
@@ -175,7 +172,9 @@ public class ApplicationResource extends AbstractContextResource {
         long size = management.getApplicationSize(this.applicationId);
         Map<String,Object> map = new HashMap<>();
         Map<String,Object> innerMap = new HashMap<>();
-        innerMap.put("application",size);
+        Map<String,Object> sumMap = new HashMap<>();
+        sumMap.put("sum",size);
+        innerMap.put("application",sumMap);
         map.put("aggregation",innerMap);
         response.setMetadata(map);
         return new JSONWithPadding( response, callback );
@@ -194,7 +193,9 @@ public class ApplicationResource extends AbstractContextResource {
         long size = management.getCollectionSize(this.applicationId ,collection_name);
         Map<String,Object> map = new HashMap<>();
         Map<String,Object> innerMap = new HashMap<>();
-        innerMap.put(collection_name,size);
+        Map<String,Object> sumMap = new HashMap<>();
+        sumMap.put("sum",size);
+        innerMap.put(collection_name,sumMap);
         map.put("aggregation",innerMap);
         response.setMetadata(map);
         return new JSONWithPadding( response, callback );

http://git-wip-us.apache.org/repos/asf/usergrid/blob/a11aaa03/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java
index 1fe4974..99d2089 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java
@@ -89,7 +89,7 @@ public class ManagementResourceIT extends AbstractRestIT {
         data.clear();
         data.put( "oldpassword", "foo" );
         data.put( "newpassword", "test" );
-        management.users().user("test"+uuid).password().post(Entity.class,data);
+        management.users().user("test"+uuid).password().post(Entity.class, data);
     }
 
 
@@ -111,7 +111,7 @@ public class ManagementResourceIT extends AbstractRestIT {
         Organization organization = new Organization(orgName,username,email,name,password,payload);
 
         Organization node = management().orgs().post(  organization );
-        management.token().get(clientSetup.getUsername(),clientSetup.getPassword());
+        management.token().get(clientSetup.getUsername(), clientSetup.getPassword());
 
         // check that the test admin cannot access the new org info
 
@@ -125,8 +125,8 @@ public class ManagementResourceIT extends AbstractRestIT {
             status = uie.getResponse().getClientResponseStatus();
         }
 
-        assertNotNull( status );
-        assertEquals( Status.UNAUTHORIZED, status );
+        assertNotNull(status);
+        assertEquals(Status.UNAUTHORIZED, status);
 
         // this admin should have access to test org
         status = null;
@@ -137,7 +137,7 @@ public class ManagementResourceIT extends AbstractRestIT {
             status = uie.getResponse().getClientResponseStatus();
         }
 
-        assertNull( status );
+        assertNull(status);
 
         //test getting the organization by org
 
@@ -149,7 +149,7 @@ public class ManagementResourceIT extends AbstractRestIT {
             status = uie.getResponse().getClientResponseStatus();
         }
 
-        assertNull( status );
+        assertNull(status);
     }
 
 
@@ -238,10 +238,10 @@ public class ManagementResourceIT extends AbstractRestIT {
         //post follow
         Entity entity = this.app()
             .collection( "users" )
-            .entity( user )
-            .collection( "following" )
-            .collection( "users" )
-            .entity( followUser )
+            .entity(user)
+            .collection("following")
+            .collection("users")
+            .entity(followUser)
             .post();
     }
 
@@ -256,8 +256,8 @@ public class ManagementResourceIT extends AbstractRestIT {
         activityPayload.put("actor", actorMap);
         Entity entity = this.app()
             .collection( "users" )
-            .entity( user )
-            .collection( "activities" )
+            .entity(user)
+            .collection("activities")
             .post( new Entity( activityPayload ) );
     }
 
@@ -306,6 +306,26 @@ public class ManagementResourceIT extends AbstractRestIT {
 
         assertEquals( "Roles", roles.get("title").toString() );
         assertEquals(4, roles.size());
+
+    }
+
+    @Test
+    public void checkSizes() throws Exception {
+        final String appname = clientSetup.getAppName();
+        this.app().collection("testCollection").post(new Entity().chainPut("name","test"));
+        refreshIndex();
+        Entity size = management().orgs().org( clientSetup.getOrganizationName() ).app().addToPath(appname).addToPath("size").get();
+        Entity rolesSize = management().orgs().org(clientSetup.getOrganizationName()).app().addToPath(appname).addToPath("size/roles").get();
+        assertTrue(size != null);
+        assertTrue(rolesSize != null);
+        int sum =  (int)((LinkedHashMap)((LinkedHashMap)size.metadata().get("aggregation")).get("application")).get("sum");
+        int sumRoles = (int)((LinkedHashMap)((LinkedHashMap)rolesSize.metadata().get("aggregation")).get("roles")).get("sum");
+
+        assertTrue(size != null);
+        assertTrue(rolesSize != null);
+
+        assertNotEquals(sum,sumRoles);
+        assertTrue(sum>sumRoles);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/usergrid/blob/a11aaa03/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/model/Entity.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/model/Entity.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/model/Entity.java
index 3707967..a56e398 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/model/Entity.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/model/Entity.java
@@ -193,6 +193,8 @@ public class Entity implements Serializable, Map<String,Object>
{
         return getDynamicProperties().entrySet();
     }
 
+    public Map<String,Object> metadata(){return (Map<String,Object>)get("metadata");}
+
     public UUID getUuid(){
         return UUID.fromString( ( String ) get( "uuid" ) );
     }


Mime
View raw message