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 2015/02/26 18:27:04 UTC

[02/16] incubator-usergrid git commit: Fixed browser compatibility tests

Fixed browser compatibility tests


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

Branch: refs/heads/USERGRID-273-indexbuffer
Commit: 17e12c4bbd99c910edfa8d902b4c88288355f010
Parents: bcabda2
Author: Rod Simpson <ro...@apigee.com>
Authored: Mon Jan 12 14:12:55 2015 -0700
Committer: Rod Simpson <ro...@apigee.com>
Committed: Mon Jan 12 14:12:55 2015 -0700

----------------------------------------------------------------------
 .../collection/BrowserCompatibilityTest.java    | 73 ++++++++++----------
 .../collection/groups/GroupResourceIT.java      |  4 +-
 .../endpoints/CollectionEndpoint.java           | 58 +++++++++++++---
 .../endpoints/EntityEndpoint.java               |  2 -
 .../rest/test/resource2point0/model/Entity.java |  2 +-
 5 files changed, 90 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/17e12c4b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/BrowserCompatibilityTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/BrowserCompatibilityTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/BrowserCompatibilityTest.java
index 3bca666..d0d436d 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/BrowserCompatibilityTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/BrowserCompatibilityTest.java
@@ -17,21 +17,15 @@
 package org.apache.usergrid.rest.applications.collection;
 
 
-import java.util.Map;
-import java.util.UUID;
-
-import com.fasterxml.jackson.databind.JsonNode;
 import java.io.IOException;
-import org.junit.Rule;
+import org.apache.usergrid.rest.test.resource2point0.model.Entity;
 import org.junit.Test;
 import org.apache.usergrid.cassandra.Concurrent;
-import org.apache.usergrid.rest.AbstractRestIT;
-import org.apache.usergrid.rest.TestContextSetup;
-import org.apache.usergrid.rest.test.resource.CustomCollection;
-
+import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT;
+import org.apache.usergrid.rest.test.resource2point0.model.Collection;
+import org.apache.usergrid.rest.test.resource2point0.model.Entity;
 import static junit.framework.Assert.assertNotNull;
 import static org.junit.Assert.assertEquals;
-import static org.apache.usergrid.utils.MapUtils.hashMap;
 
 
 /**
@@ -41,50 +35,59 @@ import static org.apache.usergrid.utils.MapUtils.hashMap;
 public class BrowserCompatibilityTest extends AbstractRestIT {
 
 
-    @Rule
-    public TestContextSetup context = new TestContextSetup( this );
-
-
+    /***
+     *
+     * Test to check chrome type accept headers
+     *
+     */
     @Test
     public void testChromeHtmlTypes() throws Exception {
         testBrowserAccept( "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" );
     }
 
 
+    /***
+     *
+     * Test to check firefox type accept headers
+     *
+     */
     @Test
     public void testFireFoxHtmlTypes() throws Exception {
         testBrowserAccept( "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" );
     }
 
 
+    /***
+     *
+     * Test to check safari type accept headers
+     *
+     */
     @Test
     public void testSafariTypes() throws Exception {
         testBrowserAccept( "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" );
     }
 
 
+    /***
+     *
+     * Helper method to run browser accept header tests
+     *
+     */
     private void testBrowserAccept( String acceptHeader ) throws IOException {
 
-
-        CustomCollection things = context.application().customCollection( "things" );
-
-        Map<String, String> entity = hashMap( "name", "thing1" );
-        JsonNode response = things.create( entity );
-
-        refreshIndex(context.getOrgName(), context.getAppName());
-
-        UUID entityId = getEntityId( response, 0 );
-
-        assertNotNull( entityId );
-
-        //now get it with "text/html" in the type
-
-        //now try and retrieve it
-        response = things.entity( entityId ).withAccept( acceptHeader ).get();
-
-        UUID returnedEntityId = getEntityId( response, 0 );
-
-
-        assertEquals( entityId, returnedEntityId );
+        //make anew entity and verify that it is accurate
+        String name = "thing1";
+        Entity payload = new Entity().chainPut("name", name);
+        Entity entity = this.app().collection("things").post(payload);
+        assertEquals(entity.get("name"), name);
+        String uuid = entity.getAsString("uuid");
+        this.refreshIndex();
+        
+        //now get this new entity with "text/html" in the accept header
+        Entity returnedEntity = this.app().collection("things").withAcceptHeader(acceptHeader).entity(entity).get();
+        String returnedUUID = returnedEntity.getAsString("uuid");
+
+        //and make sure we got the same entity back
+        assertEquals( uuid, returnedUUID );
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/17e12c4b/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 ed6876b..636ea9f 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
@@ -532,7 +532,7 @@ public class GroupResourceIT extends AbstractRestIT {
         // update that group by giving it a new title and using UUID in URL
         String evenNewerTitle = "Even New Title";
         group.put("title", newTitle);
-        String uuid = group.getString("uuid");
+        String uuid = group.getAsString("uuid");
         groupResponse = this.app().collection("groups").uniqueID(uuid).put(group);
         assertEquals(groupResponse.get("title"), evenNewerTitle);
         this.refreshIndex();
@@ -542,4 +542,4 @@ public class GroupResourceIT extends AbstractRestIT {
     }
 
 
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/17e12c4b/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 325a5fa..a37ac46 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
@@ -18,18 +18,22 @@ package org.apache.usergrid.rest.test.resource2point0.endpoints;
 
 import com.sun.jersey.api.client.WebResource;
 import org.apache.usergrid.rest.test.resource2point0.model.*;
+import org.apache.usergrid.rest.test.resource2point0.model.Collection;
 import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
 import org.apache.usergrid.services.ServiceParameter;
+import org.apache.usergrid.utils.StringUtils;
 
 import javax.ws.rs.core.MediaType;
-import java.util.List;
-import java.util.UUID;
+import java.util.*;
 
 
 /**
  * //myorg/myapp/mycollection
  */
 public class CollectionEndpoint extends NamedResource {
+
+    protected List<String> acceptHeaders = new ArrayList<String> ();
+
     public CollectionEndpoint(String name, ClientContext context, UrlResource parent) {
         super(name, context, parent);
     }
@@ -52,6 +56,10 @@ public class CollectionEndpoint extends NamedResource {
         return new EntityEndpoint(identifier, context, this);
     }
 
+    public CollectionEndpoint withAcceptHeader(final String acceptHeader) {
+        this.acceptHeaders.add(acceptHeader);
+        return this;
+    }
 
     /**
      *
@@ -99,9 +107,15 @@ public class CollectionEndpoint extends NamedResource {
     }
 
     public Collection get(final QueryParameters parameters, final boolean useToken){
+
+        String acceptHeader = MediaType.APPLICATION_JSON;
+        if (this.acceptHeaders.size() > 0) {
+           acceptHeader = StringUtils.join(this.acceptHeaders, ',');
+        }
+
         WebResource resource  = getResource(useToken);
         resource = addParametersToResource(resource, parameters);
-        ApiResponse response = resource.type( MediaType.APPLICATION_JSON_TYPE ).accept(MediaType.APPLICATION_JSON)
+        ApiResponse response = resource.type( MediaType.APPLICATION_JSON_TYPE ).accept(acceptHeader)
                 .get(ApiResponse.class);
 
         return new Collection(response);
@@ -124,6 +138,11 @@ public class CollectionEndpoint extends NamedResource {
      */
     //TODO: add queryParameters here
     public Collection getNextPage(Collection collection, QueryParameters passedParameters ,final boolean useToken) {
+        String acceptHeader = MediaType.APPLICATION_JSON;
+        if (this.acceptHeaders.size() > 0) {
+            acceptHeader = StringUtils.join(this.acceptHeaders, ',');
+        }
+
         WebResource resource = getResource(useToken);
         QueryParameters queryParameters = passedParameters;
         if( queryParameters == null){
@@ -133,7 +152,7 @@ public class CollectionEndpoint extends NamedResource {
         queryParameters.setCursor(collection.getCursor());
         resource = addParametersToResource(resource, queryParameters);
 
-        ApiResponse response = resource.type( MediaType.APPLICATION_JSON_TYPE ).accept(MediaType.APPLICATION_JSON)
+        ApiResponse response = resource.type( MediaType.APPLICATION_JSON_TYPE ).accept(acceptHeader)
                 .get(ApiResponse.class);
 
         return new Collection(response);
@@ -160,9 +179,14 @@ public class CollectionEndpoint extends NamedResource {
     }
 
     public ApiResponse delete(final QueryParameters parameters, final boolean useToken){
+        String acceptHeader = MediaType.APPLICATION_JSON;
+        if (this.acceptHeaders.size() > 0) {
+            acceptHeader = StringUtils.join(this.acceptHeaders, ',');
+        }
+
         WebResource resource  = getResource(useToken);
         resource = addParametersToResource(resource, parameters);
-        return resource.type( MediaType.APPLICATION_JSON_TYPE ).accept(MediaType.APPLICATION_JSON)
+        return resource.type( MediaType.APPLICATION_JSON_TYPE ).accept(acceptHeader)
                 .delete(ApiResponse.class);
     }
 
@@ -176,19 +200,31 @@ public class CollectionEndpoint extends NamedResource {
      *
      */
     public Entity post(Entity payload){
-        ApiResponse response = getResource(true).type( MediaType.APPLICATION_JSON_TYPE ).accept(MediaType.APPLICATION_JSON)
+        String acceptHeader = MediaType.APPLICATION_JSON;
+        if (this.acceptHeaders.size() > 0) {
+            acceptHeader = StringUtils.join(this.acceptHeaders, ',');
+        }
+        ApiResponse response = getResource(true).type( MediaType.APPLICATION_JSON_TYPE ).accept(acceptHeader)
                 .post(ApiResponse.class, payload);
         return new Entity(response);
     }
 
     public Entity post(){
-        ApiResponse response = getResource(true).type( MediaType.APPLICATION_JSON_TYPE ).accept(MediaType.APPLICATION_JSON)
+        String acceptHeader = MediaType.APPLICATION_JSON;
+        if (this.acceptHeaders.size() > 0) {
+            acceptHeader = StringUtils.join(this.acceptHeaders, ',');
+        }
+        ApiResponse response = getResource(true).type( MediaType.APPLICATION_JSON_TYPE ).accept(acceptHeader)
                 .post(ApiResponse.class);
         return new Entity(response);
     }
 
     public ApiResponse post(List<Entity> entityList){
-        ApiResponse response = getResource(true).type( MediaType.APPLICATION_JSON_TYPE ).accept(MediaType.APPLICATION_JSON)
+        String acceptHeader = MediaType.APPLICATION_JSON;
+        if (this.acceptHeaders.size() > 0) {
+            acceptHeader = StringUtils.join(this.acceptHeaders, ',');
+        }
+        ApiResponse response = getResource(true).type( MediaType.APPLICATION_JSON_TYPE ).accept(acceptHeader)
                 .post(ApiResponse.class,entityList);
         return response;
     }
@@ -208,9 +244,13 @@ public class CollectionEndpoint extends NamedResource {
     }
 
     public ApiResponse put(final QueryParameters parameters, final boolean useToken, Entity entity){
+        String acceptHeader = MediaType.APPLICATION_JSON;
+        if (this.acceptHeaders.size() > 0) {
+            acceptHeader = StringUtils.join(this.acceptHeaders, ',');
+        }
         WebResource resource  = getResource(useToken);
         addParametersToResource(getResource(), parameters);
-        return resource.type( MediaType.APPLICATION_JSON_TYPE ).accept(MediaType.APPLICATION_JSON)
+        return resource.type( MediaType.APPLICATION_JSON_TYPE ).accept(acceptHeader)
                 .put(ApiResponse.class, entity);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/17e12c4b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/EntityEndpoint.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/EntityEndpoint.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/EntityEndpoint.java
index 104809f..25965ac 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/EntityEndpoint.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/EntityEndpoint.java
@@ -36,8 +36,6 @@ public class EntityEndpoint extends NamedResource {
         super(identifier, context, parent);
     }
 
-    protected ObjectMapper mapper = new ObjectMapper();
-
 
     /**
      *

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/17e12c4b/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 635c7b4..12a99de 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
@@ -131,7 +131,7 @@ public class Entity implements Serializable, Map<String,Object> {
         //All values are strings , so doing the cast here saves doing the cast elsewhere
         return getDynamicProperties().get( key );
     }
-    public String getString( final Object key ) {
+    public String getAsString( final Object key ) {
         //All values are strings , so doing the cast here saves doing the cast elsewhere
         return (String) getDynamicProperties().get( key );
     }