usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject incubator-usergrid git commit: Start of an AppDeleteTest does not pass yet.
Date Mon, 02 Mar 2015 19:48:50 GMT
Repository: incubator-usergrid
Updated Branches:
  refs/heads/USERGRID-361 [created] de17a098a


Start of an AppDeleteTest does not pass yet.


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

Branch: refs/heads/USERGRID-361
Commit: de17a098a00074ca8aae96caeb5a469bf776268a
Parents: 489bf45
Author: Dave Johnson <dmjohnson@apigee.com>
Authored: Mon Mar 2 14:48:34 2015 -0500
Committer: Dave Johnson <dmjohnson@apigee.com>
Committed: Mon Mar 2 14:48:34 2015 -0500

----------------------------------------------------------------------
 .../apache/usergrid/rest/IndexResourceIT.java   |   1 +
 .../applications/ApplicationDeleteTest.java     | 170 +++++++++++++++++--
 .../endpoints/mgmt/ApplicationsResource.java    |  41 +++++
 .../endpoints/mgmt/OrganizationResource.java    |   6 +-
 4 files changed, 200 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/de17a098/stack/rest/src/test/java/org/apache/usergrid/rest/IndexResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/IndexResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/IndexResourceIT.java
index 7f8d085..e0b7d0d 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/IndexResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/IndexResourceIT.java
@@ -53,6 +53,7 @@ public class IndexResourceIT extends AbstractRestIT {
     @Ignore( "will finish when tests are working from rest" )
     @Test
     public void TestAddIndex() throws Exception{
+
         String superToken = superAdminToken();
 
         Map<String, Object> data = new HashMap<String, Object>();

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/de17a098/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteTest.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteTest.java
index e74b324..e6a8448 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteTest.java
@@ -18,37 +18,175 @@
 package org.apache.usergrid.rest.applications;
 
 
-import org.apache.usergrid.rest.AbstractRestIT;
+import com.sun.jersey.api.client.UniformInterfaceException;
 import org.apache.usergrid.rest.TestContextSetup;
+import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT;
+import org.apache.usergrid.rest.test.resource2point0.model.*;
+import org.junit.Assert;
 import org.junit.Rule;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.ws.rs.core.MediaType;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.UUID;
+
 
 public class ApplicationDeleteTest  extends AbstractRestIT {
-    private static final Logger log = LoggerFactory.getLogger(ApplicationDeleteTest.class);
+    private static final Logger logger = LoggerFactory.getLogger(ApplicationDeleteTest.class);
 
     @Rule
     public TestContextSetup context = new TestContextSetup( this );
 
+
     @Test
     public void testBasicOperation() throws Exception {
 
-        // create a user
-        
-        // crete an organization 
-        
-        // create an application
-        
-        // create a collection with two entities
-        
-        // test that we can query those entities
-        
-        // delete the application
-        
+        // create app with a collection of "things"
+
+        String orgName = clientSetup.getOrganization().getName();
+        String appToDelete = clientSetup.getAppName() + "_appToDelete";
+        Token orgAdminToken = getAdminToken( clientSetup.getUsername(), clientSetup.getUsername());
+
+        ApiResponse appCreateResponse = clientSetup.getRestClient()
+            .management().orgs().organization( orgName ).app().getResource()
+            .queryParam( "access_token", orgAdminToken.getAccessToken() )
+            .type( MediaType.APPLICATION_JSON )
+            .post( ApiResponse.class, new Application( appToDelete ) );
+        UUID appToDeleteId = appCreateResponse.getEntities().get(0).getUuid();
+
+        List<Entity> entities = new ArrayList<>();
+        for ( int i=0; i<10; i++ ) {
+
+            final String entityName = "entity" + i;
+            Entity entity = new Entity();
+            entity.setProperties(new HashMap<String, Object>() {{
+                put("name", entityName );
+            }});
+
+            ApiResponse createResponse = clientSetup.getRestClient()
+                .org(orgName).app( appToDelete ).collection("things").getResource()
+                .queryParam("access_token", orgAdminToken.getAccessToken())
+                .type(MediaType.APPLICATION_JSON)
+                .post( ApiResponse.class, entity );
+
+            entities.add( createResponse.getEntities().get(0) );
+        }
+
+        // delete the app
+
+        clientSetup.getRestClient()
+            .org(orgName).app(appToDeleteId.toString() ).getResource()
+            .queryParam("access_token", orgAdminToken.getAccessToken() )
+            .delete();
+
+        // test that we can no longer get the app
+
+        try {
+            clientSetup.getRestClient()
+                .org(orgName).app(appToDelete).getResource()
+                .queryParam("access_token", orgAdminToken.getAccessToken())
+                .type(MediaType.APPLICATION_JSON)
+                .get(ApiResponse.class);
+
+            Assert.fail("Must not be able to get deleted app");
+
+        } catch ( UniformInterfaceException expected ) {
+            Assert.assertEquals("Error must be 400", 400, expected.getResponse().getStatus()
);
+        }
+
+        // test that we can no longer get deleted app's collection
+
+        try {
+            clientSetup.getRestClient()
+                .org(orgName).app(appToDelete).collection("things").getResource()
+                .queryParam("access_token", orgAdminToken.getAccessToken() )
+                .type(MediaType.APPLICATION_JSON )
+                .get(ApiResponse.class);
+
+            Assert.fail("Must not be able to get deleted app's collection");
+
+        } catch ( UniformInterfaceException expected ) {
+            Assert.assertEquals("Error must be 400", 400, expected.getResponse().getStatus()
);
+        }
+
+        // test that we can no longer get an app entity
+
+        try {
+            UUID entityId = entities.get(0).getUuid();
+            clientSetup.getRestClient()
+                .org(orgName).app(appToDelete).collection("things").entity( entityId ).getResource()
+                .queryParam( "access_token", orgAdminToken.getAccessToken())
+                .type( MediaType.APPLICATION_JSON)
+                .get(ApiResponse.class);
+
+            Assert.fail("Must not be able to get deleted app entity");
+
+        } catch ( UniformInterfaceException expected ) {
+            Assert.assertEquals("Error must be 400", 400, expected.getResponse().getStatus()
);
+        }
+
+        // test that we cannot see the application in the list of applications
+
+        ApiResponse getAppsResponse = clientSetup.getRestClient()
+            .management().orgs().organization(orgName).apps().getResource()
+            .queryParam( "access_token", orgAdminToken.getAccessToken())
+            .type( MediaType.APPLICATION_JSON)
+            .get(ApiResponse.class);
+
+        for ( Entity appEntity : getAppsResponse.getEntities() ) {
+            if ( appEntity.get("name").equals( appToDelete ) ) {
+                Assert.fail("Application still exists in Organization's collection");
+            }
+        }
+
         // test that we cannot delete the application a second time
-        
-        // test that we can no longer query for those entities
+
+        clientSetup.getRestClient()
+            .org(orgName).app(appToDeleteId.toString() ).getResource()
+            .queryParam("access_token", orgAdminToken.getAccessToken() )
+            .delete();
+
+        // test that we can create a new application with the same name
+
+        ApiResponse appCreateAgainResponse = clientSetup.getRestClient()
+            .management().orgs().organization( orgName ).app().getResource()
+            .queryParam( "access_token", orgAdminToken.getAccessToken() )
+            .type( MediaType.APPLICATION_JSON )
+            .post( ApiResponse.class, new Application( appToDelete ) );
+
+        Assert.assertEquals("Must be able to create app with same name as deleted app",
+            "CREATED", appCreateAgainResponse.getStatus().toUpperCase());
+    }
+
+
+    @Test
+    public void testAppRestore() throws Exception {
+
+        // create and delete app
+
+        // restore the app
+
+        // test that app appears in list of apps
+
+        // test that application's collection exists
+    }
+
+
+
+    @Test
+    public void testAppRestoreConflict() throws Exception {
+
+        // create and delete app
+
+        // create new app with same name
+
+        // attempt to restore original app
+
+        // test that HTTP 409 CONFLICT and informative error message is received
+
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/de17a098/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ApplicationsResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ApplicationsResource.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ApplicationsResource.java
new file mode 100644
index 0000000..705f5aa
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ApplicationsResource.java
@@ -0,0 +1,41 @@
+/*
+ *
+ *  * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  *  contributor license agreements.  The ASF licenses this file to You
+ *  * under the Apache License, Version 2.0 (the "License"); you may not
+ *  * use this file except in compliance with the License.
+ *  * You may obtain a copy of the License at
+ *  *
+ *  *     http://www.apache.org/licenses/LICENSE-2.0
+ *  *
+ *  * Unless required by applicable law or agreed to in writing, software
+ *  * distributed under the License is distributed on an "AS IS" BASIS,
+ *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  * See the License for the specific language governing permissions and
+ *  * limitations under the License.  For additional information regarding
+ *  * copyright in this work, please see the NOTICE file in the top level
+ *  * directory of this distribution.
+ *
+ */
+
+package org.apache.usergrid.rest.test.resource2point0.endpoints.mgmt;
+
+import org.apache.usergrid.rest.test.resource2point0.endpoints.NamedResource;
+import org.apache.usergrid.rest.test.resource2point0.endpoints.UrlResource;
+import org.apache.usergrid.rest.test.resource2point0.model.ApiResponse;
+import org.apache.usergrid.rest.test.resource2point0.model.Application;
+import org.apache.usergrid.rest.test.resource2point0.model.Entity;
+import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
+
+import javax.ws.rs.core.MediaType;
+
+
+/**
+ * Management end-point for getting list of applications in organization.
+ */
+public class ApplicationsResource extends NamedResource {
+
+    public ApplicationsResource( final ClientContext context, final UrlResource parent )
{
+        super( "apps", context, parent );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/de17a098/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrganizationResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrganizationResource.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrganizationResource.java
index 9281ad2..ef07118 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrganizationResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrganizationResource.java
@@ -24,6 +24,7 @@ import org.apache.usergrid.rest.test.resource2point0.model.Organization;
 import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
 
 import javax.ws.rs.core.MediaType;
+import java.util.List;
 import java.util.Map;
 
 
@@ -81,10 +82,11 @@ public class OrganizationResource extends NamedResource {
         return new CredentialsResource(context, this);
     }
 
-    public ApplicationResource apps(String appName){
-        return new ApplicationResource(  appName, context ,this );
+    public ApplicationsResource apps() {
+        return new ApplicationsResource( context, this );
     }
 
+
     public ApplicationResource addToPath( String pathPart ) {
         return new ApplicationResource( pathPart, context, this );
     }


Mime
View raw message