You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2015/08/29 00:33:32 UTC
usergrid git commit: USERGRID-918: add tests for connections query
parameter
Repository: usergrid
Updated Branches:
refs/heads/pr/367 [created] 579b692f2
USERGRID-918: add tests for connections query parameter
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/579b692f
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/579b692f
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/579b692f
Branch: refs/heads/pr/367
Commit: 579b692f27fd7056088418cacb83e6d3cde95efd
Parents: 2bb5324
Author: Mike Dunker <mi...@calbears.net>
Authored: Fri Aug 28 15:26:57 2015 -0700
Committer: Mike Dunker <mi...@calbears.net>
Committed: Fri Aug 28 15:26:57 2015 -0700
----------------------------------------------------------------------
.../usergrid/rest/CollectionMetadataIT.java | 142 +++++++++++++++++++
.../test/resource/endpoints/NamedResource.java | 6 +-
.../test/resource/model/QueryParameters.java | 8 ++
3 files changed, 155 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/usergrid/blob/579b692f/stack/rest/src/test/java/org/apache/usergrid/rest/CollectionMetadataIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/CollectionMetadataIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/CollectionMetadataIT.java
new file mode 100644
index 0000000..4ab5490
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/CollectionMetadataIT.java
@@ -0,0 +1,142 @@
+/*
+ * 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;
+
+
+import com.sun.jersey.api.client.UniformInterfaceException;
+import org.apache.usergrid.persistence.index.utils.UUIDUtils;
+import org.apache.usergrid.rest.test.resource.AbstractRestIT;
+import org.apache.usergrid.rest.test.resource.model.ApiResponse;
+import org.apache.usergrid.rest.test.resource.model.Entity;
+import org.apache.usergrid.rest.test.resource.model.QueryParameters;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.util.Map;
+
+import static org.junit.Assert.*;
+
+
+public class CollectionMetadataIT extends AbstractRestIT {
+
+ private static final Logger LOG = LoggerFactory.getLogger( CollectionMetadataIT.class );
+
+
+ public CollectionMetadataIT() throws Exception {
+ super();
+ }
+
+ private final String collectionName = "collectionQueryParameterCollection";
+
+ /**
+ * USERGRID-918: control inclusion/exclusion of connection metadata via query parameter
+ */
+ @Test
+ public void testCollectionQueryParameter() throws Exception {
+
+ // create entities
+ Entity e1 = new Entity();
+ e1.put("name", "entity1");
+ e1 = this.app().collection(collectionName).post(e1);
+ assertNotNull(e1);
+
+ Entity e2 = new Entity();
+ e2.put("name", "entity2");
+ e2 = this.app().collection(collectionName).post(e2);
+ assertNotNull(e2);
+
+ Entity e3 = new Entity();
+ e3.put("name", "entity3");
+ e3 = this.app().collection(collectionName).post(e3);
+ assertNotNull(e3);
+
+ refreshIndex();
+
+ // create connections
+ // e1 hates e3
+ // e2 likes e1
+ // e1 has 1 in (likes) & 1 out (hates) connection
+ // e2 has one out (likes) connection
+ // e3 has one in (hates) connection
+ this.app().collection(collectionName).entity(e1).connection("hates").entity(e3).post();
+ this.app().collection(collectionName).entity(e2).connection("likes").entity(e1).post();
+ refreshIndex();
+
+ // no query param, "all", and invalid param all the same
+ checkMetadata(e1, null, "hates", "likes");
+ checkMetadata(e1, "all", "hates", "likes");
+ checkMetadata(e1, "foo", "hates", "likes");
+ checkMetadata(e2, null, "likes", null);
+ checkMetadata(e2, "all", "likes", null);
+ checkMetadata(e2, "foo", "likes", null);
+ checkMetadata(e3, null, null, "hates");
+ checkMetadata(e3, "all", null, "hates");
+ checkMetadata(e3, "foo", null, "hates");
+
+ // "none" query param blocks connections and connecting
+ checkMetadata(e1, "none", null, null);
+ checkMetadata(e2, "none", null, null);
+ checkMetadata(e3, "none", null, null);
+
+ // "in" query param blocks connections
+ checkMetadata(e1, "in", null, "likes");
+ checkMetadata(e2, "in", null, null);
+ checkMetadata(e3, "in", null, "hates");
+
+ // "out" query param blocks connecting
+ checkMetadata(e1, "out", "hates", null);
+ checkMetadata(e2, "out", "likes", null);
+ checkMetadata(e3, "out", null, null);
+
+ }
+
+ /**
+ * validates that connections and connecting data are as expected
+ *
+ * if paramStr = null, means don't send query parameter
+ * if connectionsType or connectingType = null, means that section shouldn't exist
+ *
+ * unchecked warnings suppressed to avoid warnings casting payload entries to maps
+ */
+ @SuppressWarnings("unchecked")
+ private void checkMetadata(Entity origEntity, String paramStr, String connectionsType, String connectingType) throws Exception {
+ QueryParameters params = new QueryParameters();
+ if (paramStr != null)
+ params.setConnections(paramStr);
+
+ Entity e = this.app().collection(collectionName).entity(origEntity).get(params,true);
+
+ Map <String,Object> metadata = (Map<String,Object>)e.get("metadata");
+ assertNotNull(metadata);
+
+ Map <String,Object> connections = (Map<String,Object>)metadata.get("connections");
+ if (connectionsType != null) {
+ assertNotNull(connections);
+ assertNotNull(connections.get(connectionsType));
+ } else {
+ assertNull(connections);
+ }
+
+ Map <String,Object> connecting = (Map<String,Object>)metadata.get("connecting");
+ if (connectingType != null) {
+ assertNotNull(connecting);
+ assertNotNull(connecting.get(connectingType));
+ } else {
+ assertNull(connecting);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/579b692f/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/NamedResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/NamedResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/NamedResource.java
index 2258312..03f6b72 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/NamedResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/NamedResource.java
@@ -98,7 +98,11 @@ public class NamedResource implements UrlResource {
}
if ( parameters.getLimit() != null ) {
- resource = resource.queryParam("limit", parameters.getLimit().toString());
+ resource = resource.queryParam("limit", parameters.getLimit().toString());
+ }
+
+ if ( parameters.getConnections() != null ) {
+ resource = resource.queryParam("connections", parameters.getConnections());
}
//We can also post the params as queries
if ( parameters.getFormPostData().size() > 0){
http://git-wip-us.apache.org/repos/asf/usergrid/blob/579b692f/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/model/QueryParameters.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/model/QueryParameters.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/model/QueryParameters.java
index 5717ffd..551f3b3 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/model/QueryParameters.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/model/QueryParameters.java
@@ -35,6 +35,7 @@ public class QueryParameters {
private String cursor;
private UUID start;
private Integer limit;
+ private String connections;
private Map<String,String> formPostData = new HashMap<String,String>( );
public QueryParameters() {
@@ -76,6 +77,13 @@ public class QueryParameters {
return this;
}
+ public String getConnections() { return connections; }
+
+ public QueryParameters setConnections(String connections) {
+ this.connections = connections;
+ return this;
+ }
+
public Map<String,String> getFormPostData(){
return formPostData;
}