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

[2/2] incubator-usergrid git commit: add test abstractions

add test abstractions


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

Branch: refs/heads/UG-rest-test-framework-overhaul
Commit: 802d7dc3985920c429e4fdee4a39b0f3a890521e
Parents: ed25b25
Author: Shawn Feldman <sf...@apache.org>
Authored: Tue Dec 16 13:45:55 2014 -0700
Committer: Shawn Feldman <sf...@apache.org>
Committed: Tue Dec 16 13:45:55 2014 -0700

----------------------------------------------------------------------
 .../test/resource2point0/AbstractRestIT.java    |   5 +-
 .../rest/test/resource2point0/ClientSetup.java  |   6 -
 .../endpoints/ApplicationResource.java          | 116 ++++---------------
 .../endpoints/ApplicationsResource.java         |  88 ++++++++++++++
 .../endpoints/OrganizationResource.java         |   9 +-
 .../rest/test/resource2point0/model/Entity.java |   3 +-
 6 files changed, 115 insertions(+), 112 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/802d7dc3/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/AbstractRestIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/AbstractRestIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/AbstractRestIT.java
index 102de4b..1e0aa30 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/AbstractRestIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/AbstractRestIT.java
@@ -21,9 +21,8 @@ import java.net.URI;
 import java.net.URLClassLoader;
 import java.util.Arrays;
 
-import org.apache.usergrid.rest.test.resource2point0.endpoints.ApplicationResource;
+import org.apache.usergrid.rest.test.resource2point0.endpoints.ApplicationsResource;
 import org.apache.usergrid.rest.test.resource2point0.endpoints.OrganizationResource;
-import org.junit.BeforeClass;
 import org.junit.ClassRule;
 import org.junit.Rule;
 
@@ -100,7 +99,7 @@ public class AbstractRestIT extends JerseyTest {
         return clientSetup.restClient.org(clientSetup.getOrganization().getName());
     }
 
-    protected ApplicationResource getApplicationResource(){
+    protected ApplicationsResource getApplicationResource(){
         return clientSetup.restClient.org(clientSetup.getOrganization().getName()).app(clientSetup.getAppName());
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/802d7dc3/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/ClientSetup.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/ClientSetup.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/ClientSetup.java
index 0b1c860..278ad69 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/ClientSetup.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/ClientSetup.java
@@ -22,10 +22,7 @@ package org.apache.usergrid.rest.test.resource2point0;
 
 
 import java.io.IOException;
-import java.util.Map;
 
-import org.apache.usergrid.rest.test.resource2point0.endpoints.ApplicationResource;
-import org.apache.usergrid.rest.test.resource2point0.endpoints.OrganizationResource;
 import org.apache.usergrid.rest.test.resource2point0.model.Application;
 import org.apache.usergrid.rest.test.resource2point0.model.Token;
 import org.junit.rules.TestRule;
@@ -33,10 +30,7 @@ import org.junit.runner.Description;
 import org.junit.runners.model.Statement;
 
 import org.apache.usergrid.persistence.index.utils.UUIDUtils;
-import org.apache.usergrid.rest.test.resource2point0.model.ApiResponse;
 import org.apache.usergrid.rest.test.resource2point0.model.Organization;
-import org.apache.usergrid.rest.test.security.TestAdminUser;
-import org.apache.usergrid.utils.MapUtils;
 
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/802d7dc3/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/ApplicationResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/ApplicationResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/ApplicationResource.java
index a724a48..e8754ac 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/ApplicationResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/ApplicationResource.java
@@ -1,112 +1,40 @@
 /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * 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
+ *  * 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.
  *
- * 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.
  */
-package org.apache.usergrid.rest.test.resource2point0.endpoints;
 
+package org.apache.usergrid.rest.test.resource2point0.endpoints;
 
-import org.apache.usergrid.rest.test.resource.app.Collection;
 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.state.ClientContext;
 
-import javax.ws.rs.core.MediaType;
-
-
 /**
- * Holds the information required for building and chaining application objects to collections.
- * Should also contain the GET,PUT,POST,DELETE methods of functioning in here.
- * This class also holds how we're currently interaction with collections.
+ * Classy class class.
  */
-public class ApplicationResource extends NamedResource {
-
-
-    public ApplicationResource( final String name,final ClientContext context,  final UrlResource parent ) {
-        super( name, context, parent );
-    }
-
-
-
-
-    public Application post(Application application){
-        ApiResponse response =getResource(true).type( MediaType.APPLICATION_JSON_TYPE ).accept( MediaType.APPLICATION_JSON )
-                .post( ApiResponse.class, application );
-
-        return new Application(response);
-
-    }
-
-    public Application put(Application application){
-        ApiResponse response =getResource(true).type( MediaType.APPLICATION_JSON_TYPE ).accept( MediaType.APPLICATION_JSON )
-                .put(ApiResponse.class, application );
-
-        return new Application(response);
+public class ApplicationResource extends AbstractEntityResource<Application> {
 
+    public ApplicationResource(String identifier, ClientContext context, UrlResource parent) {
+        super(identifier, context, parent);
     }
 
-
-    public Application get(){
-        ApiResponse response =getResource(true).type( MediaType.APPLICATION_JSON_TYPE ).accept( MediaType.APPLICATION_JSON )
-                .get(ApiResponse.class);
-
+    @Override
+    protected Application instantiateT(ApiResponse response) {
         return new Application(response);
-
     }
-
-    public void delete(Application application){
-        ApiResponse response =getResource(true).type( MediaType.APPLICATION_JSON_TYPE ).accept( MediaType.APPLICATION_JSON )
-                .delete(ApiResponse.class );
-    }
-
-
-    public CollectionResource collection(final String name){ return new CollectionResource(name,context,this);}
-
-    /**
-     * Currently hardcoded to users, this is because we expect to create and chain different cases of collections.
-     * The pattern should look like: orgs.apps.users , orgs.apps.groups and so on...
-     * @return
-     */
-    public CollectionResource users(){
-        return new CollectionResource("users", context , this);
-    }
-
-    /**
-     * Currently hardcoded to users, this is because we expect to create and chain different cases of collections.
-     * The pattern should look like: orgs.apps.users , orgs.apps.groups and so on...
-     * @return
-     */
-    public CollectionResource roles(){
-        return new CollectionResource("roles", context , this);
-    }
-
-    /**
-     * Currently hardcoded to users, this is because we expect to create and chain different cases of collections.
-     * The pattern should look like: orgs.apps.users , orgs.apps.groups and so on...
-     * @return
-     */
-    public CollectionResource permissions(){
-        return new CollectionResource("permissions", context , this);
-    }
-
-    /**
-     * Currently hardcoded to users, this is because we expect to create and chain different cases of collections.
-     * The pattern should look like: orgs.apps.users , orgs.apps.groups and so on...
-     * @return
-     */
-    public CollectionResource notifications(){
-        return new CollectionResource("notifications", context , this);
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/802d7dc3/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/ApplicationsResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/ApplicationsResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/ApplicationsResource.java
new file mode 100644
index 0000000..5825f4f
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/ApplicationsResource.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * 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.
+ */
+package org.apache.usergrid.rest.test.resource2point0.endpoints;
+
+
+import org.apache.usergrid.rest.test.resource.app.Collection;
+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.state.ClientContext;
+
+import javax.ws.rs.core.MediaType;
+
+
+/**
+ * Holds the information required for building and chaining application objects to collections.
+ * Should also contain the GET,PUT,POST,DELETE methods of functioning in here.
+ * This class also holds how we're currently interaction with collections.
+ */
+public class ApplicationsResource extends AbstractCollectionResource<Application,ApplicationResource> {
+
+
+    public ApplicationsResource(final String name, final ClientContext context, final UrlResource parent) {
+        super( name, context, parent );
+    }
+
+    @Override
+    protected Application instantiateT(ApiResponse response) {
+        return new Application(response);
+    }
+
+    @Override
+    protected ApplicationResource instantiateK(String identifier, ClientContext context, UrlResource parent) {
+        return new ApplicationResource(identifier,context,parent);
+    }
+
+    public CollectionResource collection(final String name){ return new CollectionResource(name,context,this);}
+
+    /**
+     * Currently hardcoded to users, this is because we expect to create and chain different cases of collections.
+     * The pattern should look like: orgs.apps.users , orgs.apps.groups and so on...
+     * @return
+     */
+    public CollectionResource users(){
+        return new CollectionResource("users", context , this);
+    }
+
+    /**
+     * Currently hardcoded to users, this is because we expect to create and chain different cases of collections.
+     * The pattern should look like: orgs.apps.users , orgs.apps.groups and so on...
+     * @return
+     */
+    public CollectionResource roles(){
+        return new CollectionResource("roles", context , this);
+    }
+
+    /**
+     * Currently hardcoded to users, this is because we expect to create and chain different cases of collections.
+     * The pattern should look like: orgs.apps.users , orgs.apps.groups and so on...
+     * @return
+     */
+    public CollectionResource permissions(){
+        return new CollectionResource("permissions", context , this);
+    }
+
+    /**
+     * Currently hardcoded to users, this is because we expect to create and chain different cases of collections.
+     * The pattern should look like: orgs.apps.users , orgs.apps.groups and so on...
+     * @return
+     */
+    public CollectionResource notifications(){
+        return new CollectionResource("notifications", context , this);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/802d7dc3/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/OrganizationResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/OrganizationResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/OrganizationResource.java
index d862892..9834b6b 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/OrganizationResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/OrganizationResource.java
@@ -24,11 +24,6 @@ import javax.ws.rs.core.MediaType;
 import org.apache.usergrid.rest.test.resource2point0.model.ApiResponse;
 import org.apache.usergrid.rest.test.resource2point0.model.Organization;
 import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
-import org.apache.usergrid.utils.MapUtils;
-
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.UniformInterfaceException;
-import com.sun.jersey.api.client.WebResource;
 
 
 /**
@@ -42,8 +37,8 @@ public class OrganizationResource extends NamedResource {
         super( name, context, parent );
     }
 
-    public ApplicationResource app(final String app){
-        return new ApplicationResource( app, context ,this );
+    public ApplicationsResource app(final String app){
+        return new ApplicationsResource( app, context ,this );
     }
 
     public void post(Map<String,String> organization) {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/802d7dc3/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 77218f3..9ccdb8f 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
@@ -66,8 +66,7 @@ public class Entity implements Serializable, Map<String,Object> {
      */
     public void save(){
         targetResource.put(this);
-        ApiResponse response = targetResource.entity(this.getName()).get();
-        Entity entity = new Entity(response);
+        Entity entity = targetResource.entity(this.getName()).get();
         this.dynamic_properties.putAll(entity.getDynamicProperties());
     }