organized rest IT
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/3993f081 Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/3993f081 Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/3993f081 Branch: refs/heads/two-dot-o-rest-refactor Commit: 3993f081d6fd09d5ad475b9cb379e74e690b8046 Parents: f42ebde Author: amuramoto <[email protected]> Authored: Wed Sep 17 13:39:38 2014 -0700 Committer: amuramoto <[email protected]> Committed: Wed Sep 17 13:39:38 2014 -0700 ---------------------------------------------------------------------- .../main/dist/init_instance/init_db_server.sh | 3 + .../main/dist/init_instance/init_rest_server.sh | 20 +- .../dist/init_instance/install_elasticsearch.sh | 8 +- .../usergrid/rest/ConcurrentRestITSuite.java | 18 +- .../org/apache/usergrid/rest/RestITSuite.java | 18 +- .../ApplicationRequestCounterIT.java | 97 -- .../rest/applications/DevicesResourceIT.java | 87 -- .../collection/BadGrammarQueryTest.java | 79 - .../collection/CollectionsResourceIT.java | 205 +++ .../collection/PagingResourceIT.java | 239 --- .../activities/ActivityResourceIT.java | 188 +++ .../collection/activities/AndOrQueryTest.java | 203 --- .../collection/activities/OrderByTest.java | 172 --- .../activities/PagingEntitiesTest.java | 141 -- .../collection/devices/DevicesResourceIT.java | 87 ++ .../collection/groups/GeoPagingTest.java | 133 -- .../collection/groups/GroupResourceIT.java | 295 ++++ .../collection/paging/PagingEntitiesTest.java | 141 ++ .../collection/paging/PagingResourceIT.java | 239 +++ .../users/ConnectionResourceTest.java | 271 ++++ .../collection/users/OwnershipResourceIT.java | 379 +++++ .../collection/users/PermissionsResourceIT.java | 768 ++++++++++ .../collection/users/RetrieveUsersTest.java | 87 ++ .../collection/users/UserResourceIT.java | 1418 ++++++++++++++++++ .../users/extensions/TestResource.java | 51 + .../events/ApplicationRequestCounterIT.java | 97 ++ .../applications/queries/AndOrQueryTest.java | 203 +++ .../queries/BadGrammarQueryTest.java | 79 + .../applications/queries/GeoPagingTest.java | 133 ++ .../applications/queries/MatrixQueryTests.java | 202 +++ .../rest/applications/queries/OrderByTest.java | 172 +++ .../applications/users/ActivityResourceIT.java | 188 --- .../users/CollectionsResourceIT.java | 205 --- .../users/ConnectionResourceTest.java | 271 ---- .../applications/users/GroupResourceIT.java | 295 ---- .../applications/users/MatrixQueryTests.java | 202 --- .../applications/users/OwnershipResourceIT.java | 379 ----- .../users/PermissionsResourceIT.java | 768 ---------- .../applications/users/RetrieveUsersTest.java | 87 -- .../rest/applications/users/UserResourceIT.java | 1418 ------------------ .../users/extensions/TestResource.java | 51 - 41 files changed, 5050 insertions(+), 5047 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3993f081/stack/awscluster/src/main/dist/init_instance/init_db_server.sh ---------------------------------------------------------------------- diff --git a/stack/awscluster/src/main/dist/init_instance/init_db_server.sh b/stack/awscluster/src/main/dist/init_instance/init_db_server.sh index b9c4f56..3ffca66 100644 --- a/stack/awscluster/src/main/dist/init_instance/init_db_server.sh +++ b/stack/awscluster/src/main/dist/init_instance/init_db_server.sh @@ -67,6 +67,9 @@ cd /usr/share/usergrid/init_instance cd /usr/share/usergrid/init_instance ./create_keyspaces.sh +#Increase file descriptors for Elasticsearch +sed -i.bak "s/#@student - maxlogins 4/*\t\t\-\tnofile\t\t${NOFILE}\nroot\t\t\-\tnofile\t\t10000"/ /etc/security/limits.conf + # tag last so we can see in the console that the script ran to completion cd /usr/share/usergrid/scripts groovy tag_instance.groovy http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3993f081/stack/awscluster/src/main/dist/init_instance/init_rest_server.sh ---------------------------------------------------------------------- diff --git a/stack/awscluster/src/main/dist/init_instance/init_rest_server.sh b/stack/awscluster/src/main/dist/init_instance/init_rest_server.sh index fdc83cd..5cdf10a 100644 --- a/stack/awscluster/src/main/dist/init_instance/init_rest_server.sh +++ b/stack/awscluster/src/main/dist/init_instance/init_rest_server.sh @@ -51,7 +51,8 @@ cd /usr/share/usergrid/init_instance ./install_yourkit.sh # set Tomcat memory and threads based on instance type -export NOFILE=100000 +export NOFILE=50000 +export TOMCAT_CONNECTIONS=10000 case `(curl http://169.254.169.254/latest/meta-data/instance-type)` in 'm1.small' ) export TOMCAT_RAM=1250M @@ -69,30 +70,29 @@ case `(curl http://169.254.169.254/latest/meta-data/instance-type)` in export TOMCAT_RAM=12G export TOMCAT_THREADS=2000 ;; -'m3.xlarge' ) - export TOMCAT_RAM=12G - export TOMCAT_THREADS=3300 -;; 'm3.large' ) export TOMCAT_RAM=6G - export TOMCAT_THREADS=1600 + export TOMCAT_THREADS=6000 +;; +'m3.xlarge' ) + export TOMCAT_RAM=12G + export TOMCAT_THREADS=8000 ;; 'c3.2xlarge' ) export TOMCAT_RAM=12G - export TOMCAT_THREADS=2000 + export TOMCAT_THREADS=10000 ;; 'c3.4xlarge' ) export TOMCAT_RAM=24G - export TOMCAT_THREADS=4000 + export TOMCAT_THREADS=12000 esac -export TOMCAT_CONNECTIONS=10000 sed -i.bak "s/Xmx128m/Xmx${TOMCAT_RAM} -Xms${TOMCAT_RAM} -Dlog4j\.configuration=file:\/usr\/share\/usergrid\/lib\/log4j\.properties/g" /etc/default/tomcat7 sed -i.bak "s/<Connector/<Connector maxThreads=\"${TOMCAT_THREADS}\" acceptCount=\"${TOMCAT_THREADS}\" maxConnections=\"${TOMCAT_CONNECTIONS}\"/g" /var/lib/tomcat7/conf/server.xml # set file limits sed -i.bak "s/# \/etc\/init\.d\/tomcat7 -- startup script for the Tomcat 6 servlet engine/ulimit -n ${NOFILE}/" /etc/init.d/tomcat7 -sed -i.bak "s/@student/a *\t\thard\tnofile\t\t${NOFILE}\n*\t\tsoft\tnofile\t\t${NOFILE}" /etc/security/limits.conf +sed -i.bak "s/#@student - maxlogins 4/*\t\t\-\tnofile\t\t${NOFILE}\nroot\t\t\-\tnofile\t\t${NOFILE}"/ /etc/security/limits.conf echo "$NOFILE" | sudo tee > /proc/sys/fs/nr_open echo "$NOFILE" | sudo tee > /proc/sys/fs/file-max cat >> /etc/pam.d/su << EOF http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3993f081/stack/awscluster/src/main/dist/init_instance/install_elasticsearch.sh ---------------------------------------------------------------------- diff --git a/stack/awscluster/src/main/dist/init_instance/install_elasticsearch.sh b/stack/awscluster/src/main/dist/init_instance/install_elasticsearch.sh index d398591..51f7c60 100644 --- a/stack/awscluster/src/main/dist/init_instance/install_elasticsearch.sh +++ b/stack/awscluster/src/main/dist/init_instance/install_elasticsearch.sh @@ -57,16 +57,16 @@ case `(curl http://169.254.169.254/latest/meta-data/instance-type)` in export ES_HEAP_SIZE=5G ;; 'm3.xlarge' ) - export ES_HEAP_SIZE=5G + export ES_HEAP_SIZE=10G ;; 'm3.large' ) - export ES_HEAP_SIZE=2G + export ES_HEAP_SIZE=5G ;; 'c3.2xlarge' ) - export ES_HEAP_SIZE=4G + export ES_HEAP_SIZE=10G ;; 'c3.4xlarge' ) - export ES_HEAP_SIZE=12G + export ES_HEAP_SIZE=15G esac cat >> /etc/default/elasticsearch << EOF http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3993f081/stack/rest/src/test/java/org/apache/usergrid/rest/ConcurrentRestITSuite.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/ConcurrentRestITSuite.java b/stack/rest/src/test/java/org/apache/usergrid/rest/ConcurrentRestITSuite.java index 4456054..c6d2705 100644 --- a/stack/rest/src/test/java/org/apache/usergrid/rest/ConcurrentRestITSuite.java +++ b/stack/rest/src/test/java/org/apache/usergrid/rest/ConcurrentRestITSuite.java @@ -23,18 +23,18 @@ import org.junit.runners.Suite; import org.apache.usergrid.cassandra.CassandraResource; import org.apache.usergrid.cassandra.Concurrent; import org.apache.usergrid.cassandra.ConcurrentSuite; -import org.apache.usergrid.rest.applications.ApplicationRequestCounterIT; +import org.apache.usergrid.rest.applications.events.ApplicationRequestCounterIT; import org.apache.usergrid.rest.applications.ApplicationResourceIT; -import org.apache.usergrid.rest.applications.DevicesResourceIT; +import org.apache.usergrid.rest.applications.collection.devices.DevicesResourceIT; import org.apache.usergrid.rest.applications.assets.AssetResourceIT; -import org.apache.usergrid.rest.applications.collection.PagingResourceIT; +import org.apache.usergrid.rest.applications.collection.paging.PagingResourceIT; import org.apache.usergrid.rest.applications.events.EventsResourceIT; -import org.apache.usergrid.rest.applications.users.ActivityResourceIT; -import org.apache.usergrid.rest.applications.users.CollectionsResourceIT; -import org.apache.usergrid.rest.applications.users.GroupResourceIT; -import org.apache.usergrid.rest.applications.users.OwnershipResourceIT; -import org.apache.usergrid.rest.applications.users.PermissionsResourceIT; -import org.apache.usergrid.rest.applications.users.UserResourceIT; +import org.apache.usergrid.rest.applications.collection.activities.ActivityResourceIT; +import org.apache.usergrid.rest.applications.collection.CollectionsResourceIT; +import org.apache.usergrid.rest.applications.collection.groups.GroupResourceIT; +import org.apache.usergrid.rest.applications.collection.users.OwnershipResourceIT; +import org.apache.usergrid.rest.applications.collection.users.PermissionsResourceIT; +import org.apache.usergrid.rest.applications.collection.users.UserResourceIT; import org.apache.usergrid.rest.filters.ContentTypeResourceIT; import org.apache.usergrid.rest.management.ManagementResourceIT; import org.apache.usergrid.rest.management.RegistrationIT; http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3993f081/stack/rest/src/test/java/org/apache/usergrid/rest/RestITSuite.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/RestITSuite.java b/stack/rest/src/test/java/org/apache/usergrid/rest/RestITSuite.java index dbf8834..a28fa89 100644 --- a/stack/rest/src/test/java/org/apache/usergrid/rest/RestITSuite.java +++ b/stack/rest/src/test/java/org/apache/usergrid/rest/RestITSuite.java @@ -22,17 +22,17 @@ import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.apache.usergrid.cassandra.CassandraResource; import org.apache.usergrid.cassandra.Concurrent; -import org.apache.usergrid.rest.applications.ApplicationRequestCounterIT; -import org.apache.usergrid.rest.applications.DevicesResourceIT; +import org.apache.usergrid.rest.applications.events.ApplicationRequestCounterIT; +import org.apache.usergrid.rest.applications.collection.devices.DevicesResourceIT; import org.apache.usergrid.rest.applications.assets.AssetResourceIT; -import org.apache.usergrid.rest.applications.collection.PagingResourceIT; +import org.apache.usergrid.rest.applications.collection.paging.PagingResourceIT; import org.apache.usergrid.rest.applications.events.EventsResourceIT; -import org.apache.usergrid.rest.applications.users.ActivityResourceIT; -import org.apache.usergrid.rest.applications.users.CollectionsResourceIT; -import org.apache.usergrid.rest.applications.users.GroupResourceIT; -import org.apache.usergrid.rest.applications.users.OwnershipResourceIT; -import org.apache.usergrid.rest.applications.users.PermissionsResourceIT; -import org.apache.usergrid.rest.applications.users.UserResourceIT; +import org.apache.usergrid.rest.applications.collection.activities.ActivityResourceIT; +import org.apache.usergrid.rest.applications.collection.CollectionsResourceIT; +import org.apache.usergrid.rest.applications.collection.groups.GroupResourceIT; +import org.apache.usergrid.rest.applications.collection.users.OwnershipResourceIT; +import org.apache.usergrid.rest.applications.collection.users.PermissionsResourceIT; +import org.apache.usergrid.rest.applications.collection.users.UserResourceIT; import org.apache.usergrid.rest.filters.ContentTypeResourceIT; import org.apache.usergrid.rest.management.organizations.AdminEmailEncodingIT; import org.apache.usergrid.rest.management.users.organizations.UsersOrganizationsResourceIT; http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3993f081/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationRequestCounterIT.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationRequestCounterIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationRequestCounterIT.java deleted file mode 100644 index 007741a..0000000 --- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationRequestCounterIT.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * 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.applications; - - -import java.util.UUID; - -import javax.ws.rs.core.MediaType; - -import com.fasterxml.jackson.databind.JsonNode; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.apache.usergrid.cassandra.Concurrent; -import org.apache.usergrid.persistence.EntityManager; -import org.apache.usergrid.persistence.EntityManagerFactory; -import org.apache.usergrid.persistence.index.query.Query; -import org.apache.usergrid.persistence.Results; -import org.apache.usergrid.persistence.index.query.CounterResolution; -import org.apache.usergrid.rest.AbstractRestIT; -import org.apache.usergrid.services.ServiceManager; -import org.apache.usergrid.utils.UUIDUtils; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - - -/** - * Invoke application request counters - * - * @author realbeast - */ -@Concurrent() -public class ApplicationRequestCounterIT extends AbstractRestIT { - private static final Logger log = LoggerFactory.getLogger( ApplicationRequestCounterIT.class ); - long ts = System.currentTimeMillis() - ( 24 * 60 * 60 * 1000 ); - - - @Test - public void applicationrequestInternalCounters() throws Exception { - // Get application id - JsonNode node = mapper.readTree( resource().path( "/test-organization/test-app" ).queryParam( "access_token", access_token ) - .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ).get( String.class )); - - assertNotNull( node.get( "entities" ) ); - - String uuid = node.get( "application" ).asText(); - assertEquals( true, UUIDUtils.isUUID( uuid ) ); - - refreshIndex("test-organization", "test-app"); - - UUID applicationId = UUID.fromString( uuid ); - EntityManagerFactory emf = setup.getEmf(); - EntityManager em = emf.getEntityManager( applicationId ); - - int beforeTotalCall = getCounter( em, ServiceManager.APPLICATION_REQUESTS ); - int beforeCall = getCounter( em, ServiceManager.APPLICATION_REQUESTS_PER.concat( "get" ) ); - - // call - node = mapper.readTree( resource().path( "/test-organization/test-app/counters" ).queryParam( "resolution", "all" ) - .queryParam( "counter", "application.requests" ).queryParam( "access_token", adminToken() ) - .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ).get( String.class )); - - assertNotNull( node.get( "counters" ) ); - - int afterTotalCall = getCounter( em, ServiceManager.APPLICATION_REQUESTS ); - int afterCall = getCounter( em, ServiceManager.APPLICATION_REQUESTS_PER.concat( "get" ) ); - - assertEquals( 1, afterCall - beforeCall ); - assertEquals( 1, afterTotalCall - beforeTotalCall ); - } - - - private int getCounter( EntityManager em, String key ) throws Exception { - Query query = new Query(); - query.addCounterFilter( key + ":*:*:*" ); - query.setStartTime( ts ); - query.setFinishTime( System.currentTimeMillis() ); - query.setResolution( CounterResolution.ALL ); - Results r = em.getAggregateCounters( query ); - return ( int ) r.getCounters().get( 0 ).getValues().get( 0 ).getValue(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3993f081/stack/rest/src/test/java/org/apache/usergrid/rest/applications/DevicesResourceIT.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/DevicesResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/DevicesResourceIT.java deleted file mode 100644 index f63244a..0000000 --- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/DevicesResourceIT.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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.applications; - - -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -import com.fasterxml.jackson.databind.JsonNode; -import org.junit.Test; -import org.apache.usergrid.cassandra.Concurrent; -import org.apache.usergrid.rest.AbstractRestIT; - -import com.sun.jersey.api.client.UniformInterfaceException; -import java.io.IOException; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; -import org.junit.Ignore; - - -@Concurrent() -public class DevicesResourceIT extends AbstractRestIT { - - @Test - @Ignore("cannot be supported with Core Persistence which requires time based UUIDs") - public void putWithUUIDShouldCreateAfterDelete() throws IOException { - - Map<String, String> payload = new HashMap<String, String>(); - UUID uuid = UUID.randomUUID(); - payload.put( "name", "foo" ); - - String path = "devices/" + uuid; - - refreshIndex("test-organization", "test-app"); - - JsonNode response = mapper.readTree( appPath( path ).put( String.class, payload )); - - // create - JsonNode entity = getEntity( response, 0 ); - assertNotNull( entity ); - String newUuid = entity.get( "uuid" ).textValue(); - assertEquals( uuid.toString(), newUuid ); - - // delete - response = mapper.readTree( appPath( path ).delete( String.class )); - assertNotNull( getEntity( response, 0 ) ); - - refreshIndex("test-organization", "test-app"); - - // check deleted - try { - response = mapper.readTree( appPath( path ).get( String.class )); - fail( "should get 404 error" ); - } - catch ( UniformInterfaceException e ) { - assertEquals( 404, e.getResponse().getStatus() ); - } - - // create again - response = mapper.readTree( appPath( path ).put( String.class, payload )); - entity = getEntity( response, 0 ); - assertNotNull( entity ); - - refreshIndex("test-organization", "test-app"); - - // check existence - response = mapper.readTree( appPath( path ).get( String.class )); - assertNotNull( getEntity( response, 0 ) ); - } -} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3993f081/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/BadGrammarQueryTest.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/BadGrammarQueryTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/BadGrammarQueryTest.java deleted file mode 100644 index bd95fd8..0000000 --- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/BadGrammarQueryTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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.applications.collection; - - -import java.util.HashMap; -import java.util.Map; - -import com.fasterxml.jackson.databind.JsonNode; -import org.junit.Rule; -import org.junit.Test; -import org.apache.usergrid.rest.AbstractRestIT; -import org.apache.usergrid.rest.TestContextSetup; -import org.apache.usergrid.rest.test.resource.CustomCollection; - -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.UniformInterfaceException; -import java.io.IOException; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; -import static org.apache.usergrid.utils.MapUtils.hashMap; - - -/** - * @author tnine - */ -public class BadGrammarQueryTest extends AbstractRestIT { - - @Rule - public TestContextSetup context = new TestContextSetup( this ); - - - @Test - public void catchBadQueryGrammar() throws IOException { - - CustomCollection things = context.collection( "things" ); - - Map actor = hashMap( "displayName", "Erin" ); - Map props = new HashMap(); - props.put( "actor", actor ); - props.put( "content", "bragh" ); - - JsonNode activity = things.create( props ); - - refreshIndex(context.getOrgName(), context.getAppName()); - - String query = "select * where name != 'go'"; - - ClientResponse.Status status = null; - - try { - - JsonNode incorrectNode = things.query( query, "limit", Integer.toString( 10 ) ); - fail( "This should throw an exception" ); - } - catch ( UniformInterfaceException uie ) { - status = uie.getResponse().getClientResponseStatus(); - - - } - - assertEquals( 400, status.getStatusCode() ); - } -} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3993f081/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java new file mode 100644 index 0000000..72639ca --- /dev/null +++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java @@ -0,0 +1,205 @@ +/* + * 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.applications.collection; + + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import javax.ws.rs.core.MediaType; + +import com.fasterxml.jackson.databind.JsonNode; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.apache.usergrid.cassandra.Concurrent; +import org.apache.usergrid.rest.AbstractRestIT; +import org.apache.usergrid.utils.UUIDUtils; + +import com.sun.jersey.api.client.UniformInterfaceException; +import java.io.IOException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.apache.usergrid.utils.MapUtils.hashMap; + + +/** + * @author zznate + * @author tnine + */ +@Concurrent() +public class CollectionsResourceIT extends AbstractRestIT { + + private static Logger log = LoggerFactory.getLogger( CollectionsResourceIT.class ); + + + @Test + public void postToBadPath() throws IOException { + Map<String, String> payload = hashMap( "name", "Austin" ).map( "state", "TX" ); + JsonNode node = null; + try { + node = mapper.readTree( resource().path( "/test-organization/test-organization/test-app/cities" ) + .queryParam( "access_token", access_token ).accept( MediaType.APPLICATION_JSON ) + .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload )); + } + catch ( UniformInterfaceException e ) { + assertEquals( "Should receive a 400 Not Found", 400, e.getResponse().getStatus() ); + } + } + + + @Test + public void postToEmptyCollection() throws IOException { + Map<String, String> payload = new HashMap<String, String>(); + + JsonNode node = mapper.readTree( resource().path( "/test-organization/test-app/cities" ).queryParam( "access_token", access_token ) + .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ) + .post( String.class, payload )); + assertNull( getEntity( node, 0 ) ); + assertNull( node.get( "count" ) ); + } + + + /** + * emails with "me" in them are causing errors. Test we can post to a colleciton after creating a user with this + * email + * <p/> + * USERGRID-689 + */ + @Test + public void permissionWithMeInString() throws Exception { + // user is created get a token + createUser( "[email protected]", "[email protected]", "secret", "Sumeet Agarwal" ); + refreshIndex("test-organization", "test-app"); + + String token = userToken( "[email protected]", "secret" ); + + + //create a permission with the path "me" in it + Map<String, String> data = new HashMap<String, String>(); + + data.put( "permission", "get,post,put,delete:/users/[email protected]/**" ); + + String path = "/test-organization/test-app/users/[email protected]/permissions"; + JsonNode posted = mapper.readTree( resource().path( path ).queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) + .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, data )); + + + //now post data + data = new HashMap<String, String>(); + + data.put( "name", "profile-sumeet" ); + data.put( "firstname", "sumeet" ); + data.put( "lastname", "agarwal" ); + data.put( "mobile", "122" ); + + + posted = mapper.readTree( resource().path( "/test-organization/test-app/nestprofiles" ).queryParam( "access_token", token ) + .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ) + .post( String.class, data )); + + refreshIndex("test-organization", "test-app"); + + JsonNode response = mapper.readTree( resource().path( "/test-organization/test-app/nestprofiles" ).queryParam( "access_token", token ) + .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ) + .get( String.class )); + + assertNotNull( getEntity( response, 0 ) ); + assertNotNull( response.get( "count" ) ); + } + + + @Test + public void stringWithSpaces() throws IOException { + Map<String, String> payload = hashMap( "summaryOverview", "My Summary" ).map( "caltype", "personal" ); + + JsonNode node = mapper.readTree( resource().path( "/test-organization/test-app/calendarlists" ) + .queryParam( "access_token", access_token ).accept( MediaType.APPLICATION_JSON ) + .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload )); + + + UUID id = getEntityId( node, 0 ); + + //post a second entity + + + payload = hashMap( "summaryOverview", "Your Summary" ).map( "caltype", "personal" ); + + node = mapper.readTree( resource().path( "/test-organization/test-app/calendarlists" ).queryParam( "access_token", access_token ) + .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ) + .post( String.class, payload )); + + + refreshIndex("test-organization", "test-app"); + + //query for the first entity + + String query = "summaryOverview = 'My Summary'"; + + + JsonNode queryResponse = mapper.readTree( resource().path( "/test-organization/test-app/calendarlists" ) + .queryParam( "access_token", access_token ).queryParam( "ql", query ) + .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ).get( String.class )); + + + UUID returnedId = getEntityId( queryResponse, 0 ); + + assertEquals( id, returnedId ); + + assertEquals( 1, queryResponse.get( "entities" ).size() ); + } + + + /** + * Test to verify "name property returns twice in AppServices response" is fixed. + * https://apigeesc.atlassian.net/browse/USERGRID-2318 + */ + @Test + public void testNoDuplicateFields() throws Exception { + + { + // create an "app_user" object with name fred + Map<String, String> payload = hashMap( "type", "app_user" ).map( "name", "fred" ); + + JsonNode node = mapper.readTree( resource().path( "/test-organization/test-app/app_users" ) + .queryParam( "access_token", access_token ).accept( MediaType.APPLICATION_JSON ) + .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload )); + + String uuidString = node.get( "entities" ).get( 0 ).get( "uuid" ).asText(); + UUID entityId = UUIDUtils.tryGetUUID( uuidString ); + Assert.assertNotNull( entityId ); + } + + refreshIndex("test-organization", "test-app"); + + { + // check REST API response for duplicate name property + // have to look at raw response data, Jackson will remove dups + String s = resource().path( "/test-organization/test-app/app_users/fred" ) + .queryParam( "access_token", access_token ).accept( MediaType.APPLICATION_JSON ) + .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ); + + int firstFred = s.indexOf( "fred" ); + int secondFred = s.indexOf( "fred", firstFred + 4 ); + Assert.assertEquals( "Should not be more than one name property", -1, secondFred ); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3993f081/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/PagingResourceIT.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/PagingResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/PagingResourceIT.java deleted file mode 100644 index c7a7a84..0000000 --- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/PagingResourceIT.java +++ /dev/null @@ -1,239 +0,0 @@ -/* - * 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.applications.collection; - - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import org.apache.usergrid.cassandra.Concurrent; -import org.apache.usergrid.java.client.entities.Entity; -import org.apache.usergrid.java.client.response.ApiResponse; -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.resource.EntityResource; -import static org.apache.usergrid.utils.MapUtils.hashMap; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -/** Simple tests to test querying at the REST tier */ -@Concurrent() -public class PagingResourceIT extends AbstractRestIT { - - private static final Logger logger = LoggerFactory.getLogger( PagingResourceIT.class ); - - @Rule - public TestContextSetup context = new TestContextSetup( this ); - - - @Test - public void collectionPaging() throws Exception { - - CustomCollection things = context.application().collection( "test1things" ); - - int size = 40; - - List<Map<String, String>> created = new ArrayList<Map<String, String>>( size ); - - for ( int i = 0; i < size; i++ ) { - Map<String, String> entity = hashMap( "name", String.valueOf( i ) ); - things.create( entity ); - - created.add( entity ); - } - - refreshIndex(context.getOrgName(), context.getAppName()); - - // now page them all - ApiResponse response = null; - Iterator<Map<String, String>> entityItr = created.iterator(); - - do { - - response = parse( things.get() ); - - for ( Entity e : response.getEntities() ) { - assertTrue( entityItr.hasNext() ); - assertEquals( entityItr.next().get( "name" ), e.getProperties().get( "name" ).asText() ); - logger.debug("Got item value {}", e.getProperties().get( "name" ).asText()); - } - - logger.debug("response cursor: " + response.getCursor() ); - - things = things.withCursor( response.getCursor() ); - } - while ( response != null && response.getCursor() != null ); - - assertFalse("Should have paged them all", entityItr.hasNext() ); - } - - - @Test - @Ignore("ignored because currently startPaging is only be supported for queues and not for " - + "generic collections as this test assumes. " - + "see also: https://issues.apache.org/jira/browse/USERGRID-211 ") - public void startPaging() throws Exception { - - CustomCollection things = context.application().collection( "test2things" ); - - int size = 40; - - List<Map<String, String>> created = new ArrayList<Map<String, String>>( size ); - - for ( int i = 0; i < size; i++ ) { - Map<String, String> entity = hashMap( "name", String.valueOf( i ) ); - things.create( entity ); - - created.add( entity ); - } - - refreshIndex(context.getOrgName(), context.getAppName()); - - // now page them all - ApiResponse response = null; - - UUID start = null; - int index = 0; - - do { - - response = parse( things.get() ); - - for ( Entity e : response.getEntities() ) { - logger.debug("Getting item {} value {}", index, e.getProperties().get( "name" ).asText()); - assertEquals( created.get( index ).get( "name" ), e.getProperties().get( "name" ).asText() ); - index++; - } - - // decrement since we'll get this one again - index--; - - start = response.getEntities().get( response.getEntities().size() - 1 ).getUuid(); - - things = things.withStart( start ); - } - while ( response != null && response.getEntities().size() > 1 ); - - // we paged them all - assertEquals( created.size() - 1, index ); - } - - - @Test - public void collectionBatchDeleting() throws Exception { - - CustomCollection things = context.application().collection( "test3things" ); - - int size = 40; - - List<Map<String, String>> created = new ArrayList<Map<String, String>>( size ); - - for ( int i = 0; i < size; i++ ) { - Map<String, String> entity = hashMap( "name", String.valueOf( i ) ); - things.create( entity ); - - created.add( entity ); - } - - refreshIndex(context.getOrgName(), context.getAppName()); - - ApiResponse response; - int deletePageSize = 10; - - things = things.withLimit( deletePageSize ); - - for ( int i = 0; i < size / deletePageSize; i++ ) { - response = parse( things.delete() ); - - refreshIndex(context.getOrgName(), context.getAppName()); - - assertEquals( "Only 10 entities should have been deleted", 10, response.getEntityCount() ); - } - - response = parse( things.get() ); - - assertEquals( "All entities should have been removed", 0, response.getEntityCount() ); - - //now do 1 more delete, we should get any results - - response = parse( things.delete() ); - - assertEquals( "No more entities deleted", 0, response.getEntityCount() ); - } - - - @Test - public void emptyQlandLimitIgnored() throws Exception { - - CustomCollection things = context.application().collection( "test4things" ); - - Map<String, String> data = hashMap( "name", "thing1" ); - JsonNode response = things.create( data ); - - refreshIndex(context.getOrgName(), context.getAppName()); - - JsonNode entity = getEntity( response, 0 ); - - String uuid = entity.get( "uuid" ).asText(); - - EntityResource entityRequest = things.entity( "thing1" ).withParam( "ql", "" ).withParam( "limit", "" ); - - JsonNode returnedEntity = getEntity( entityRequest.get(), 0 ); - - assertEquals( entity, returnedEntity ); - - entityRequest = things.entity( uuid ).withParam( "ql", "" ).withParam( "limit", "" ); - - returnedEntity = getEntity( entityRequest.get(), 0 ); - - assertEquals( entity, returnedEntity ); - - // now do a delete - returnedEntity = getEntity( entityRequest.delete(), 0 ); - - assertEquals( entity, returnedEntity ); - - refreshIndex(context.getOrgName(), context.getAppName()); - - // verify it's gone - returnedEntity = getEntity( things.entity( uuid ).get(), 0 ); - - assertNull( returnedEntity ); - } - - - private static ObjectMapper mapper = new ObjectMapper(); - - - private static final ApiResponse parse( JsonNode response ) throws Exception { - String jsonResponseString = mapper.writeValueAsString( response ); - return mapper.readValue( jsonResponseString, ApiResponse.class ); - } -} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3993f081/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/activities/ActivityResourceIT.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/activities/ActivityResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/activities/ActivityResourceIT.java new file mode 100644 index 0000000..49fa7bb --- /dev/null +++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/activities/ActivityResourceIT.java @@ -0,0 +1,188 @@ +/* + * 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.applications.collection.activities; + + +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.apache.usergrid.cassandra.Concurrent; +import org.apache.usergrid.java.client.Client.Query; +import org.apache.usergrid.java.client.entities.Entity; +import org.apache.usergrid.java.client.entities.User; +import org.apache.usergrid.java.client.response.ApiResponse; +import org.apache.usergrid.rest.AbstractRestIT; +import org.apache.usergrid.utils.UUIDUtils; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + + +/** @author tnine */ +@Concurrent() +public class ActivityResourceIT extends AbstractRestIT { + private static Logger log = LoggerFactory.getLogger( ActivityResourceIT.class ); + + private static final String GROUP = "testGroup"; + + private static final String USER = "edanuff"; + + private static boolean groupCreated = false; + + + public ActivityResourceIT() throws Exception { + + } + + + @Before + public void setupGroup() { + if ( groupCreated ) { + return; + } + + client.createGroup( GROUP ); + + refreshIndex("test-organization", "test-app"); + + groupCreated = true; + } + + + @Test + public void postNullActivityToGroup() { + + boolean fail = false; + try { + ApiResponse groupActivity = client.postGroupActivity( GROUP, null ); + fail = (groupActivity.getError() != null); + + } + catch ( Exception e ) { + fail = true; + } + assertTrue( fail ); + } + + + @Test + public void postGroupActivity() { + + // don't populate the user, it will use the currently authenticated user. + + String activityTitle = "testTitle" + UUIDUtils.newTimeUUID(); + String activityDesc = "testActivity" + UUIDUtils.newTimeUUID(); + + client.postGroupActivity( GROUP, "POST", + activityTitle, activityDesc, "testCategory", null, null, null, null, null ); + + refreshIndex("test-organization", "test-app"); + + Query results = client.queryActivityFeedForGroup( GROUP ); + + ApiResponse response = results.getResponse(); + + Entity result = response.getEntities().get( 0 ); + + assertEquals( "POST", result.getProperties().get( "verb" ).asText() ); + assertEquals( activityTitle, result.getProperties().get( "title" ).asText() ); + assertEquals( activityDesc, result.getProperties().get( "content" ).asText() ); + + // now pull the activity directly, we should find it + + results = client.queryActivity(); + + response = results.getResponse(); + + result = response.getEntities().get( 0 ); + + assertEquals( "POST", result.getProperties().get( "verb" ).asText() ); + assertEquals( activityTitle, result.getProperties().get( "title" ).asText() ); + assertEquals( activityDesc, result.getProperties().get( "content" ).asText() ); + } + + + @Test + public void postUserActivity() { + + // don't populate the user, it will use the currently authenticated + // user. + + User current = client.getLoggedInUser(); + + String activityTitle = "testTitle" + UUIDUtils.newTimeUUID(); + String activityDesc = "testActivity" + UUIDUtils.newTimeUUID(); + + client.postUserActivity( "POST", activityTitle, activityDesc, "testCategory", current, null, null, null, null ); + + refreshIndex("test-organization", "test-app"); + + Query results = client.queryActivityFeedForUser( USER ); + + ApiResponse response = results.getResponse(); + + Entity result = response.getEntities().get( 0 ); + + assertEquals( "POST", result.getProperties().get( "verb" ).asText() ); + assertEquals( activityTitle, result.getProperties().get( "title" ).asText() ); + assertEquals( activityDesc, result.getProperties().get( "content" ).asText() ); + assertEquals( current.getUuid().toString(), result.getProperties().get( "actor" ).get( "uuid" ).asText() ); + + // now pull the activity directly, we should find it + + results = client.queryActivity(); + + response = results.getResponse(); + + result = response.getEntities().get( 0 ); + + assertEquals( "POST", result.getProperties().get( "verb" ).asText() ); + assertEquals( activityTitle, result.getProperties().get( "title" ).asText() ); + assertEquals( activityDesc, result.getProperties().get( "content" ).asText() ); + } + + + @Test + public void postActivity() { + + // don't populate the user, it will use the currently authenticated + // user. + + User current = client.getLoggedInUser(); + + String activityTitle = "testTitle" + UUIDUtils.newTimeUUID(); + String activityDesc = "testActivity" + UUIDUtils.newTimeUUID(); + + client.postActivity( "POST", activityTitle, activityDesc, "testCategory", current, null, null, null, null ); + + refreshIndex("test-organization", "test-app"); + + Query results = client.queryActivity(); + + ApiResponse response = results.getResponse(); + + Entity result = response.getEntities().get( 0 ); + + assertEquals( "POST", result.getProperties().get( "verb" ).asText() ); + assertEquals( activityTitle, result.getProperties().get( "title" ).asText() ); + assertEquals( activityDesc, result.getProperties().get( "content" ).asText() ); + + //ACTOR isn't coming back, why? + assertEquals( current.getUuid().toString(), result.getProperties().get( "actor" ).get( "uuid" ).asText() ); + } +} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3993f081/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/activities/AndOrQueryTest.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/activities/AndOrQueryTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/activities/AndOrQueryTest.java deleted file mode 100644 index 5eda243..0000000 --- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/activities/AndOrQueryTest.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * 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.applications.collection.activities; - - -import java.util.HashMap; -import java.util.Map; - -import com.fasterxml.jackson.databind.JsonNode; -import java.io.IOException; -import org.apache.commons.lang.RandomStringUtils; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.apache.usergrid.rest.AbstractRestIT; -import org.apache.usergrid.rest.TestContextSetup; -import org.apache.usergrid.rest.test.resource.CustomCollection; - -import static org.junit.Assert.assertEquals; -import static org.apache.usergrid.utils.MapUtils.hashMap; - - -/** - * // TODO: Document this - * - * @author ApigeeCorporation - * @since 4.0 - */ -public class AndOrQueryTest extends AbstractRestIT { - - @Rule - public TestContextSetup context = new TestContextSetup( this ); - - - @Test //USERGRID-900 - public void queriesWithAndPastLimit() throws IOException { - - CustomCollection activities = context.collection( "activities" ); - - long created = 0; - Map actor = hashMap( "displayName", "Erin" ); - Map props = new HashMap(); - - props.put( "actor", actor ); - props.put( "verb", "go" ); - props.put( "content", "bragh" ); - - - for ( int i = 0; i < 2000; i++ ) { - if ( i < 1000 ) { - props.put( "madeup", false ); - } - else { - props.put( "madeup", true ); - } - - props.put( "ordinal", i ); - JsonNode activity = activities.create( props ); - if ( i == 0 ) { - created = activity.findValue( "created" ).longValue(); - } - } - - this.refreshIndex( context.getAppUuid() ); - - String errorQuery = "select * where created >= " + created + "AND madeup = true"; - JsonNode incorrectNode = activities.withQuery( errorQuery ).get(); - - assertEquals( 10, incorrectNode.get( "entities" ).size() ); - } - - - @Test //USERGRID-1475 - public void displayFullQueriesInLimit() throws IOException { - - CustomCollection activities = context.collection( "activities" ); - - Map actor = hashMap( "displayName", "Erin" ); - Map props = new HashMap(); - props.put( "actor", actor ); - props.put( "content", "bragh" ); - - for ( int i = 0; i < 20; i++ ) { - - if ( i < 10 ) { - props.put( "verb", "go" ); - } - else { - props.put( "verb", "stop" ); - } - - props.put( "ordinal", i ); - JsonNode activity = activities.create( props ); - } - - this.refreshIndex( context.getAppUuid() ); - - String query = "select * where not verb = 'go'"; - JsonNode incorrectNode = activities.query( query, "limit", Integer.toString( 10 ) ); - - assertEquals( 10, incorrectNode.get( "entities" ).size() ); - - for ( int i = 0; i < 10; i++ ) { - assertEquals( 19 - i, incorrectNode.get( "entities" ).get( i ).get( "ordinal" ).intValue() ); - assertEquals( "stop", incorrectNode.get( "entities" ).get( i ).get( "verb" ).textValue() ); - } - } - - - @Test //USERGRID-1615 - public void queryReturnCount() throws Exception { - - CustomCollection activities = context.collection( "activities" ); - - Map actor = hashMap( "displayName", "Erin" ); - Map props = new HashMap(); - - int numValuesTested = 20; - - - props.put( "actor", actor ); - props.put( "verb", "go" ); - props.put( "content", "bragh" ); - - JsonNode[] correctValues = activities.createEntitiesWithOrdinal( props, numValuesTested ); - - this.refreshIndex( context.getAppUuid() ); - - String inCorrectQuery = "select * where verb = 'go' and ordinal >= 10 "; - - activities.verificationOfQueryResults( correctValues, true, inCorrectQuery ); - } - - - @Test //Check to make sure that asc works - public void queryCheckAsc() throws Exception { - - CustomCollection madeupStuff = context.collection( "imagination" + RandomStringUtils.randomAlphabetic(5)); - Map character = hashMap( "WhoHelpedYou", "Ruff" ); - - JsonNode[] correctValues; - correctValues = madeupStuff.createEntitiesWithOrdinal( character, 10 ); - - this.refreshIndex( context.getAppUuid() ); - - String inquisitiveQuery = "select * where Ordinal gte 0 and Ordinal lte 10 " - + "or WhoHelpedYou eq 'Ruff' ORDER BY Ordinal asc"; - - int totalEntitiesContained = madeupStuff.verificationOfQueryResults( correctValues, false, inquisitiveQuery ); - - assertEquals( 10, totalEntitiesContained ); - } - - - @Ignore("Test to make sure all 1000 exist with a regular query") - public void queryReturnCheck() throws Exception { - CustomCollection madeupStuff = context.collection( "imagination" ); - Map character = hashMap( "WhoHelpedYou", "Ruff" ); - - int numOfEntities = 1000; - - JsonNode[] correctValues = madeupStuff.createEntitiesWithOrdinal( character, numOfEntities ); - - this.refreshIndex( context.getAppUuid() ); - - String inquisitiveQuery = "select * where Ordinal >= 0 and Ordinal <= 2000 or WhoHelpedYou = 'Ruff'"; - - int totalEntitiesContained = madeupStuff.verificationOfQueryResults( correctValues, true, inquisitiveQuery ); - - assertEquals( numOfEntities, totalEntitiesContained ); - } - - - @Ignore - public void queryReturnCheckWithShortHand() throws IOException { - CustomCollection madeupStuff = context.collection( "imagination" ); - Map character = hashMap( "WhoHelpedYou", "Ruff" ); - - madeupStuff.createEntitiesWithOrdinal( character, 1000 ); - - this.refreshIndex( context.getAppUuid() ); - - String inquisitiveQuery = "select * where Ordinal gte 0 and Ordinal lte 2000 or WhoHelpedYou eq 'Ruff'"; - - int totalEntitiesContained = madeupStuff.countEntities( inquisitiveQuery ); - - assertEquals( 1000, totalEntitiesContained ); - } -} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3993f081/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/activities/OrderByTest.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/activities/OrderByTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/activities/OrderByTest.java deleted file mode 100644 index 7e96818..0000000 --- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/activities/OrderByTest.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * 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.applications.collection.activities; - - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import com.fasterxml.jackson.databind.JsonNode; -import java.io.IOException; -import org.junit.Rule; -import org.junit.Test; -import org.apache.usergrid.rest.AbstractRestIT; -import org.apache.usergrid.rest.TestContextSetup; -import org.apache.usergrid.rest.test.resource.CustomCollection; - -import static org.junit.Assert.assertEquals; -import static org.apache.usergrid.utils.MapUtils.hashMap; - - -/** - * // TODO: Document this - * - * @author ApigeeCorporation - * @since 4.0 - */ -public class OrderByTest extends AbstractRestIT { - - @Rule - public TestContextSetup context = new TestContextSetup( this ); - - - @Test - // USERGRID-1400 - public void orderByShouldNotAffectResults() throws IOException { - - CustomCollection activities = context.collection( "activities" ); - - long created = 0; - Map actor = hashMap( "displayName", "Erin" ); - Map props = new HashMap(); - props.put( "actor", actor ); - props.put( "verb", "go" ); - props.put( "content", "bragh" ); - for ( int i = 0; i < 20; i++ ) { - props.put( "ordinal", i ); - JsonNode activity = activities.create( props ); - if ( i == 5 ) { - created = activity.findValue( "created" ).longValue(); - } - } - - refreshIndex(context.getOrgName(), context.getAppName()); - - String query = "select * where created > " + created; - JsonNode node = activities.withQuery( query ).get(); - assertEquals( 10, node.get( "entities" ).size() ); - - query = query + " order by created desc"; - node = activities.withQuery( query ).get(); - assertEquals( 10, node.get( "entities" ).size() ); - } - - - @Test - // USERGRID-1520 - public void orderByComesBeforeLimitResult() throws IOException { - - CustomCollection activities = context.collection( "activities" ); - - Map actor = hashMap( "displayName", "Erin" ); - Map props = new HashMap(); - int checkResultsNum = 0; - - props.put( "actor", actor ); - props.put( "verb", "go" ); - props.put( "content", "bragh" ); - - for ( int i = 0; i < 20; i++ ) { - props.put( "ordinal", i ); - JsonNode activity = activities.create( props ); - } - - refreshIndex(context.getOrgName(), context.getAppName()); - - String query = "select * where created > " + 1 + " order by created desc"; - - JsonNode incorrectNode = activities.withQuery( query ).withLimit( 5 ).get(); - - assertEquals( 5, incorrectNode.get( "entities" ).size() ); - - while ( checkResultsNum < 5 ) { - assertEquals( activities.entityIndex( query, checkResultsNum ), - activities.entityIndexLimit( query, 5, checkResultsNum ) ); - checkResultsNum++; - } - } - - /* - * public JsonNode entityIndex(JsonNode container, int index) { return - * container.get("entities").get(index); } - */ - - - @Test - // USERGRID-1521 - public void orderByReturnCorrectResults() throws IOException { - - CustomCollection activities = context.collection( "activities" ); - - int size = 200; - - Map<String, String> actor = hashMap( "displayName", "Erin" ); - Map<String, Object> props = new HashMap<String, Object>(); - - props.put( "actor", actor ); - props.put( "verb", "go" ); - props.put( "content", "bragh" ); - - List<JsonNode> activites = new ArrayList<JsonNode>( size ); - - for ( int i = 0; i < size; i++ ) { - props.put( "ordinal", i ); - JsonNode activity = activities.create( props ).get( "entities" ).get( 0 ); - activites.add( activity ); - } - - refreshIndex(context.getOrgName(), context.getAppName()); - - long lastCreated = activites.get( activites.size() - 1 ).get( "created" ).asLong(); - - String errorQuery = String.format( "select * where created <= %d order by created desc", lastCreated ); - String cursor = null; - int index = size - 1; - - do { - JsonNode response = activities.withQuery( errorQuery ).get(); - JsonNode cursorNode = response.get( "cursor" ); - - cursor = cursorNode != null ? cursorNode.asText() : null; - - JsonNode entities = response.get( "entities" ); - - int returnSize = entities.size(); - - for ( int i = 0; i < returnSize; i++, index-- ) { - assertEquals( activites.get( index ), entities.get( i ) ); - } - - activities = activities.withCursor( cursor ); - } - while ( cursor != null && cursor.length() > 0 ); - - assertEquals( "Paged to last result", -1, index ); - } -} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3993f081/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/activities/PagingEntitiesTest.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/activities/PagingEntitiesTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/activities/PagingEntitiesTest.java deleted file mode 100644 index ab9f0f0..0000000 --- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/activities/PagingEntitiesTest.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * 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.applications.collection.activities; - - -import java.util.HashMap; -import java.util.Map; - -import com.fasterxml.jackson.databind.JsonNode; -import java.io.IOException; -import org.junit.Rule; -import org.junit.Test; -import org.apache.usergrid.rest.AbstractRestIT; -import org.apache.usergrid.rest.TestContextSetup; -import org.apache.usergrid.rest.test.resource.CustomCollection; - -import org.apache.commons.lang.ArrayUtils; - -import static org.junit.Assert.assertEquals; -import static org.apache.usergrid.utils.MapUtils.hashMap; - - -/** - * // TODO: Document this - * - * @author ApigeeCorporation - * @since 4.0 - */ -public class PagingEntitiesTest extends AbstractRestIT { - - @Rule - public TestContextSetup context = new TestContextSetup( this ); - - - @Test //USERGRID-266 - public void pageThroughConnectedEntities() throws IOException { - - CustomCollection activities = context.collection( "activities" ); - - long created = 0; - int maxSize = 100; - long[] verifyCreated = new long[maxSize]; - Map actor = hashMap( "displayName", "Erin" ); - Map props = new HashMap(); - - - props.put( "actor", actor ); - props.put( "verb", "go" ); - - for ( int i = 0; i < maxSize; i++ ) { - - props.put( "ordinal", i ); - JsonNode activity = activities.create( props ); - verifyCreated[i] = activity.findValue( "created" ).longValue(); - if ( i == 0 ) { - created = activity.findValue( "created" ).longValue(); - } - } - ArrayUtils.reverse( verifyCreated ); - - refreshIndex(context.getOrgName(), context.getAppName()); - - String query = "select * where created >= " + created; - - - JsonNode node = activities.query( query, "limit", "2" ); //activities.query(query,""); - int index = 0; - while ( node.get( "entities" ).get( "created" ) != null ) { - assertEquals( 2, node.get( "entities" ).size() ); - - if ( node.get( "cursor" ) != null ) { - node = activities.query( query, "cursor", node.get( "cursor" ).toString() ); - } - - else { - break; - } - } - } - - - @Test //USERGRID-1253 - public void pagingQueryReturnCorrectResults() throws Exception { - - CustomCollection activities = context.collection( "activities" ); - - long created = 0; - int maxSize = 23; - long[] verifyCreated = new long[maxSize]; - Map actor = hashMap( "displayName", "Erin" ); - Map props = new HashMap(); - - props.put( "actor", actor ); - props.put( "content", "bragh" ); - - for ( int i = 0; i < maxSize; i++ ) { - - if ( i > 17 && i < 23 ) { - props.put( "verb", "stop" ); - } - else { - props.put( "verb", "go" ); - } - props.put( "ordinal", i ); - JsonNode activity = activities.create( props ); - verifyCreated[i] = activity.findValue( "created" ).longValue(); - if ( i == 18 ) { - created = activity.findValue( "created" ).longValue(); - } - } - - refreshIndex(context.getOrgName(), context.getAppName()); - - String query = "select * where created >= " + created + " or verb = 'stop'"; - - JsonNode node = activities.withQuery( query ).get(); - - for ( int index = 0; index < 5; index++ ) { - assertEquals( verifyCreated[maxSize - 1 - index], - node.get( "entities" ).get( index ).get( "created" ).longValue() ); - } - - int totalEntitiesContained = activities.countEntities( query ); - - assertEquals( 5, totalEntitiesContained ); - } -} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3993f081/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/devices/DevicesResourceIT.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/devices/DevicesResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/devices/DevicesResourceIT.java new file mode 100644 index 0000000..4010a05 --- /dev/null +++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/devices/DevicesResourceIT.java @@ -0,0 +1,87 @@ +/* + * 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.applications.collection.devices; + + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import com.fasterxml.jackson.databind.JsonNode; +import org.junit.Test; +import org.apache.usergrid.cassandra.Concurrent; +import org.apache.usergrid.rest.AbstractRestIT; + +import com.sun.jersey.api.client.UniformInterfaceException; +import java.io.IOException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; +import org.junit.Ignore; + + +@Concurrent() +public class DevicesResourceIT extends AbstractRestIT { + + @Test + @Ignore("cannot be supported with Core Persistence which requires time based UUIDs") + public void putWithUUIDShouldCreateAfterDelete() throws IOException { + + Map<String, String> payload = new HashMap<String, String>(); + UUID uuid = UUID.randomUUID(); + payload.put( "name", "foo" ); + + String path = "devices/" + uuid; + + refreshIndex("test-organization", "test-app"); + + JsonNode response = mapper.readTree( appPath( path ).put( String.class, payload )); + + // create + JsonNode entity = getEntity( response, 0 ); + assertNotNull( entity ); + String newUuid = entity.get( "uuid" ).textValue(); + assertEquals( uuid.toString(), newUuid ); + + // delete + response = mapper.readTree( appPath( path ).delete( String.class )); + assertNotNull( getEntity( response, 0 ) ); + + refreshIndex("test-organization", "test-app"); + + // check deleted + try { + response = mapper.readTree( appPath( path ).get( String.class )); + fail( "should get 404 error" ); + } + catch ( UniformInterfaceException e ) { + assertEquals( 404, e.getResponse().getStatus() ); + } + + // create again + response = mapper.readTree( appPath( path ).put( String.class, payload )); + entity = getEntity( response, 0 ); + assertNotNull( entity ); + + refreshIndex("test-organization", "test-app"); + + // check existence + response = mapper.readTree( appPath( path ).get( String.class )); + assertNotNull( getEntity( response, 0 ) ); + } +} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3993f081/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/groups/GeoPagingTest.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/groups/GeoPagingTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/groups/GeoPagingTest.java deleted file mode 100644 index db99c9f..0000000 --- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/groups/GeoPagingTest.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * 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.applications.collection.groups; - - -import java.util.HashMap; -import java.util.Map; - -import com.fasterxml.jackson.databind.JsonNode; -import java.io.IOException; -import org.junit.Rule; -import org.junit.Test; -import org.apache.usergrid.rest.AbstractRestIT; -import org.apache.usergrid.rest.TestContextSetup; -import org.apache.usergrid.rest.test.resource.CustomCollection; - -import static org.junit.Assert.assertEquals; -import static org.apache.usergrid.utils.MapUtils.hashMap; - - -/** - * // TODO: Document this - * - * @author ApigeeCorporation - * @since 4.0 - */ -public class GeoPagingTest extends AbstractRestIT { - - @Rule - public TestContextSetup context = new TestContextSetup( this ); - - - @Test //("Test uses up to many resources to run reliably") // USERGRID-1403 - public void groupQueriesWithGeoPaging() throws IOException { - - CustomCollection groups = context.application().collection( "test1groups" ); - - int maxRangeLimit = 2000; - long[] index = new long[maxRangeLimit]; - Map actor = hashMap( "displayName", "Erin" ); - - Map props = new HashMap(); - - props.put( "actor", actor ); - Map location = hashMap( "latitude", 37 ); - location.put( "longitude", -75 ); - props.put( "location", location ); - props.put( "verb", "go" ); - props.put( "content", "bragh" ); - - for ( int i = 0; i < 5; i++ ) { - String newPath = String.format( "/kero" + i ); - props.put( "path", newPath ); - props.put( "ordinal", i ); - JsonNode activity = groups.create( props ); - index[i] = activity.findValue( "created" ).longValue(); - } - - refreshIndex(context.getOrgName(), context.getAppName()); - - String query = "select * where location within 20000 of 37,-75 " - + " and created > " + index[2] - + " and created < " + index[4] + ""; - - JsonNode node = groups.withQuery( query ).get(); - assertEquals( 1, node.get( "entities" ).size() ); - - assertEquals( index[3], node.get( "entities" ).get( 0 ).get( "created" ).longValue() ); - } - - - @Test // USERGRID-1401 - public void groupQueriesWithConsistentResults() throws IOException { - - CustomCollection groups = context.application().collection( "test2groups" ); - - int maxRangeLimit = 20; - JsonNode[] saved = new JsonNode[maxRangeLimit]; - - Map<String, String> actor = hashMap( "displayName", "Erin" ); - Map<String, Object> props = new HashMap<String, Object>(); - - props.put( "actor", actor ); - Map<String, Integer> location = hashMap( "latitude", 37 ); - location.put( "longitude", -75 ); - props.put( "location", location ); - props.put( "verb", "go" ); - props.put( "content", "bragh" ); - - for ( int i = 0; i < 20; i++ ) { - String newPath = String.format( "/kero" + i ); - props.put( "path", newPath ); - props.put( "ordinal", i ); - JsonNode activity = groups.create( props ).get( "entities" ).get( 0 ); - saved[i] = activity; - } - - refreshIndex(context.getOrgName(), context.getAppName()); - - JsonNode node = null; - for ( int consistent = 0; consistent < 20; consistent++ ) { - - String query = String.format( - "select * where location within 100 of 37, -75 and ordinal >= %d and ordinal < %d", - saved[7].get( "ordinal" ).asLong(), saved[10].get( "ordinal" ).asLong() ); - - node = groups.withQuery( query ).get(); //groups.query(query); - - JsonNode entities = node.get( "entities" ); - - assertEquals( 3, entities.size() ); - - for ( int i = 0; i < 3; i++ ) { - // shouldn't start at 10 since you're excluding it above in the query, it should return 9,8,7 - assertEquals( saved[7 + i], entities.get( i ) ); - } - } - } -}
