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 2014/03/05 17:20:46 UTC

[1/5] Re-organize test packages.

Repository: incubator-usergrid
Updated Branches:
  refs/heads/two-dot-o bae131fdc -> de98a4a1e


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5eaf05ac/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/test/CassandraService.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/test/CassandraService.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/test/CassandraService.java
deleted file mode 100644
index d374da5..0000000
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/test/CassandraService.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.test;
-
-/**
- *
- * @author ApigeeCorporation
- */
-class CassandraService {
-    
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5eaf05ac/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/test/CoreApplication.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/test/CoreApplication.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/test/CoreApplication.java
deleted file mode 100644
index 00e375c..0000000
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/test/CoreApplication.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.test;
-
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.UUID;
-
-import org.junit.rules.TestRule;
-import org.junit.runner.Description;
-import org.junit.runners.model.Statement;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.usergrid.persistence.model.entity.Entity;
-import org.apache.usergrid.persistence.model.entity.Id;
-import org.apache.usergrid.persistence.query.Query;
-import org.apache.usergrid.persistence.query.Results;
-
-
-public class CoreApplication implements Application, TestRule {
-
-    private final static Logger LOG = LoggerFactory.getLogger( CoreApplication.class );
-    protected UUID id;
-    protected String appName;
-    protected String orgName;
-    protected CoreITSetup setup;
-    protected EntityManagerFacade em;
-    protected Map<String, Object> properties = new LinkedHashMap<String, Object>();
-
-
-    public CoreApplication( CoreITSetup setup ) {
-        this.setup = setup;
-    }
-
-    public void setEntityManager( EntityManagerFacade em ) {
-        this.em = em;
-    }
-
-    @Override
-    public void putAll( Map<String, Object> properties ) {
-        this.properties.putAll( properties );
-    }
-
-
-    @Override
-    public Object get( String key ) {
-        return properties.get( key );
-    }
-
-
-    @Override
-    public Map<String, Object> getProperties() {
-        return properties;
-    }
-
-
-    @Override
-    public UUID getId() {
-        return id;
-    }
-
-
-    @Override
-    public String getOrgName() {
-        return orgName;
-    }
-
-
-    @Override
-    public String getAppName() {
-        return appName;
-    }
-
-
-    @Override
-    public Entity create( String type ) throws Exception {
-        Entity entity = em.create( type, properties );
-        clear();
-        return entity;
-    }
-
-
-    @Override
-    public Object put( String property, Object value ) {
-        return properties.put( property, value );
-    }
-
-
-    @Override
-    public void clear() {
-        properties.clear();
-    }
-
-    @Override
-    public Entity get( Id id ) throws Exception {
-        return em.get( id );
-    }
-
-    @Override
-    public Statement apply( final Statement base, final Description description ) {
-        return new Statement() {
-            @Override
-            public void evaluate() throws Throwable {
-                before( description );
-
-                try {
-                    base.evaluate();
-                }
-                finally {
-                    after( description );
-                }
-            }
-        };
-    }
-
-
-    protected void after( Description description ) {
-        LOG.info( "Test {}: finish with application", description.getDisplayName() );
-    }
-
-
-    protected void before( Description description ) throws Exception {
-    }
-
-
-    public EntityManagerFacade getEm() {
-        return em;
-    }
-
-    public void addToCollection( Entity user, String collection, Entity item ) throws Exception {
-        em.addToCollection( user, collection, item );
-    }
-
-    public Results searchCollection( Entity user, String collection, Query query ) throws Exception {
-        return em.searchCollection( user, collection, query );
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5eaf05ac/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/test/CoreITSetup.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/test/CoreITSetup.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/test/CoreITSetup.java
deleted file mode 100644
index ebbc940..0000000
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/test/CoreITSetup.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.test;
-
-
-import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
-import org.junit.rules.TestRule;
-
-
-public interface CoreITSetup extends TestRule {
-
-    EntityCollectionManagerFactory getEmf();
-
-    void dump( String name, Object obj );
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5eaf05ac/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/test/CoreITSetupImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/test/CoreITSetupImpl.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/test/CoreITSetupImpl.java
deleted file mode 100644
index a545c3d..0000000
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/test/CoreITSetupImpl.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-package org.apache.usergrid.test;
-
-
-import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
-import org.apache.usergrid.persistence.utils.JsonUtils;
-
-import org.junit.runner.Description;
-import org.junit.runners.model.Statement;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-public class CoreITSetupImpl implements CoreITSetup {
-    private static final Logger LOG = LoggerFactory.getLogger( CoreITSetupImpl.class );
-
-    protected EntityCollectionManagerFactory emf;
-    protected CassandraService cassandraService;
-    protected boolean enabled = false;
-
-
-//    public CoreITSetupImpl( CassandraResource cassandraResource ) {
-//        this.cassandraResource = cassandraResource;
-//    }
-
-
-    @Override
-    public Statement apply( Statement base, Description description ) {
-        return statement( base, description );
-    }
-
-
-    private Statement statement( final Statement base, final Description description ) {
-        return new Statement() {
-            @Override
-            public void evaluate() throws Throwable {
-                before( description );
-
-                try {
-                    base.evaluate();
-                }
-                finally {
-                    after( description );
-                }
-            }
-        };
-    }
-
-
-    /**
-     * Sets up the resources for the test here.
-     *
-     * @throws Throwable if setup fails (which will disable {@code after}
-     */
-    protected void before( Description description ) throws Throwable {
-        LOG.info( "Setting up for {}", description.getDisplayName() );
-        initialize();
-    }
-
-
-    private void initialize() {
-    }
-
-
-    /** Override to tear down your specific external resource. */
-    protected void after( Description description ) {
-        LOG.info( "Tearing down for {}", description.getDisplayName() );
-    }
-
-
-    @Override
-    public void dump( String name, Object obj ) {
-        if ( obj != null && LOG.isInfoEnabled() ) {
-            LOG.info( name + ":\n" + JsonUtils.mapToFormattedJsonString( obj ) );
-        }
-    }
-
-    public EntityCollectionManagerFactory getEmf() {
-        return emf;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5eaf05ac/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/test/EntityBuilder.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/test/EntityBuilder.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/test/EntityBuilder.java
deleted file mode 100644
index d7c4380..0000000
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/test/EntityBuilder.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-
-package org.apache.usergrid.test;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import org.apache.usergrid.persistence.model.entity.Entity;
-import org.apache.usergrid.persistence.model.field.BooleanField;
-import org.apache.usergrid.persistence.model.field.DoubleField;
-import org.apache.usergrid.persistence.model.field.EntityObjectField;
-import org.apache.usergrid.persistence.model.field.Field;
-import org.apache.usergrid.persistence.model.field.FloatField;
-import org.apache.usergrid.persistence.model.field.IntegerField;
-import org.apache.usergrid.persistence.model.field.ListField;
-import org.apache.usergrid.persistence.model.field.LocationField;
-import org.apache.usergrid.persistence.model.field.LongField;
-import org.apache.usergrid.persistence.model.field.StringField;
-import org.apache.usergrid.persistence.model.field.value.Location;
-
-
-public class EntityBuilder {
-
-    public static Entity fromMap( String scope, Map<String, Object> item ) {
-        return fromMap( scope, null, item );
-    }
-
-    public static Entity fromMap( String scope, Entity entity, Map<String, Object> map ) {
-
-        if ( entity == null ) {
-            entity = new Entity();
-        }
-
-        for ( String fieldName : map.keySet() ) {
-
-            Object value = map.get( fieldName );
-
-            if ( value instanceof String ) {
-                entity.setField( new StringField( fieldName, (String)value ));
-
-            } else if ( value instanceof Boolean ) {
-                entity.setField( new BooleanField( fieldName, (Boolean)value ));
-                        
-            } else if ( value instanceof Integer ) {
-                entity.setField( new IntegerField( fieldName, (Integer)value ));
-
-            } else if ( value instanceof Double ) {
-                entity.setField( new DoubleField( fieldName, (Double)value ));
-
-		    } else if ( value instanceof Float ) {
-                entity.setField( new FloatField( fieldName, (Float)value ));
-				
-            } else if ( value instanceof Long ) {
-                entity.setField( new LongField( fieldName, (Long)value ));
-
-            } else if ( value instanceof List) {
-                entity.setField( listToListField( scope, fieldName, (List)value ));
-
-            } else if ( value instanceof Map ) {
-
-				Field field = null;
-
-				// is the map really a location element?
-				Map<String, Object> m = (Map<String, Object>)value;
-				if ( m.size() == 2) {
-					Double lat = null;
-					Double lon = null;
-					try {
-						if ( m.get("latitude") != null && m.get("longitude") != null ) {
-							lat = Double.parseDouble( m.get("latitude").toString() );
-							lon = Double.parseDouble( m.get("longitude").toString() );
-
-						} else if ( m.get("lat") != null && m.get("lon") != null ) { 
-							lat = Double.parseDouble( m.get("lat").toString() );
-							lon = Double.parseDouble( m.get("lon").toString() );
-						}
-					} catch ( NumberFormatException ignored ) {}
-
-					if ( lat != null && lon != null ) {
-						field = new LocationField( fieldName, new Location( lat, lon ));
-					}
-				}
-
-				if ( field == null ) { 
-
-					// not a location element, process it as map
-					entity.setField( new EntityObjectField( fieldName, 
-						fromMap( scope, (Map<String, Object>)value ))); // recursion
-
-				} else {
-					entity.setField( field );
-				}
-	
-			} else {
-                throw new RuntimeException("Unknown type " + value.getClass().getName());
-            }
-        }
-
-        return entity;
-    }
-
-    
-    private static ListField listToListField( String scope, String fieldName, List list ) {
-
-        if (list.isEmpty()) {
-            return new ListField( fieldName );
-        }
-
-        Object sample = list.get(0);
-
-        if ( sample instanceof Map ) {
-            return new ListField<Entity>( fieldName, processListForField( scope, list ));
-
-        } else if ( sample instanceof List ) {
-            return new ListField<List>( fieldName, processListForField( scope, list ));
-            
-        } else if ( sample instanceof String ) {
-            return new ListField<String>( fieldName, (List<String>)list );
-                    
-        } else if ( sample instanceof Boolean ) {
-            return new ListField<Boolean>( fieldName, (List<Boolean>)list );
-                    
-        } else if ( sample instanceof Integer ) {
-            return new ListField<Integer>( fieldName, (List<Integer>)list );
-
-        } else if ( sample instanceof Double ) {
-            return new ListField<Double>( fieldName, (List<Double>)list );
-
-        } else if ( sample instanceof Long ) {
-            return new ListField<Long>( fieldName, (List<Long>)list );
-
-        } else {
-            throw new RuntimeException("Unknown type " + sample.getClass().getName());
-        }
-    }
-
-    
-    private static List processListForField( String scope, List list ) {
-        if ( list.isEmpty() ) {
-            return list;
-        }
-        Object sample = list.get(0);
-
-        if ( sample instanceof Map ) {
-            List<Entity> newList = new ArrayList<Entity>();
-            for ( Map<String, Object> map : (List<Map<String, Object>>)list ) {
-                newList.add( fromMap( scope, map ) );
-            }
-            return newList;
-
-        } else if ( sample instanceof List ) {
-            return processListForField( scope, list ); // recursion
-            
-        } else { 
-            return list;
-        } 
-    }
-
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5eaf05ac/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/test/EntityManagerFacade.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/test/EntityManagerFacade.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/test/EntityManagerFacade.java
deleted file mode 100644
index b2a5657..0000000
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/test/EntityManagerFacade.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.test;
-
-import java.util.HashMap;
-import java.util.Map;
-import org.apache.usergrid.persistence.collection.CollectionScope;
-import org.apache.usergrid.persistence.collection.EntityCollectionManager;
-import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
-import org.apache.usergrid.persistence.collection.impl.CollectionScopeImpl;
-import org.apache.usergrid.persistence.index.EntityCollectionIndex;
-import org.apache.usergrid.persistence.index.EntityCollectionIndexFactory;
-import org.apache.usergrid.persistence.model.entity.Entity;
-import org.apache.usergrid.persistence.model.entity.Id;
-import org.apache.usergrid.persistence.model.entity.SimpleId;
-import org.apache.usergrid.persistence.model.field.LocationField;
-import org.apache.usergrid.persistence.model.field.value.Location;
-import org.apache.usergrid.persistence.model.util.UUIDGenerator;
-import org.apache.usergrid.persistence.query.EntityRef;
-import org.apache.usergrid.persistence.query.Query;
-import org.apache.usergrid.persistence.query.Results;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-/** 
- * Implements just enough of the old EntityManager interface to get old tests imported from the
- * Usergrid 1.0 Core module working against the new Core Persistence index & query system.
- */
-public class EntityManagerFacade {
-    private static final Logger logger = LoggerFactory.getLogger( EntityManagerFacade.class );
-
-    private final Id orgId;
-    private final Id appId;
-    private final EntityCollectionManagerFactory ecmf;
-    private final EntityCollectionIndexFactory ecif;
-    private final Map<String, String> typesByCollectionNames = new HashMap<String, String>();
-    
-    public EntityManagerFacade( 
-        Id orgId, 
-        Id appId, 
-        EntityCollectionManagerFactory ecmf, 
-        EntityCollectionIndexFactory ecif ) {
-
-        this.appId = appId;
-        this.orgId = orgId;
-        this.ecmf = ecmf;
-        this.ecif = ecif;
-    }
-
-    public Entity create( String type, Map<String, Object> properties ) {
-
-        CollectionScope scope = new CollectionScopeImpl( appId, orgId, type );
-        EntityCollectionManager ecm = ecmf.createCollectionManager( scope );
-        EntityCollectionIndex eci = ecif.createCollectionIndex( scope );
-
-        final String collectionName;
-        if ( type.endsWith("y") ) {
-            collectionName = type.substring( 0, type.length() - 1) + "ies";
-        } else {
-            collectionName = type + "s";
-        }
-        typesByCollectionNames.put( collectionName, type );
-        
-        Entity entity = new Entity(new SimpleId(UUIDGenerator.newTimeUUID(), scope.getName()));
-        entity = EntityBuilder.fromMap( scope.getName(), entity, properties );
-        entity = ecm.write( entity ).toBlockingObservable().last();
-
-        eci.index( entity );
-        return entity;
-    }
-
-    public Results searchCollection( Entity user, String collectionName, Query query ) {
-
-        String type = typesByCollectionNames.get( collectionName );
-		if ( type == null ) {
-			throw new RuntimeException( 
-					"No type found for collection name: " + collectionName);
-		}
-        CollectionScope scope = new CollectionScopeImpl( appId, orgId, type );
-
-        EntityCollectionIndex eci = ecif.createCollectionIndex( scope );
-        Results results = eci.execute( query );
-        return results;
-    }
-
-    public Entity get( Id id ) {
-        CollectionScope scope = new CollectionScopeImpl( appId, orgId, id.getType() );
-        EntityCollectionManager ecm = ecmf.createCollectionManager( scope );
-        return ecm.load( id ).toBlockingObservable().last();
-    }
-
-    public void addToCollection( Entity user, String collectionName, Entity entity ) {
-        // basically a no-op except that can now map Entity type to collection name
-        typesByCollectionNames.put( collectionName, entity.getId().getType() );
-    }
-
-    public Entity getApplicationRef() {
-        return new Entity();
-    }
-
-    public void update( Entity entity ) {
-
-        String type = entity.getId().getType();
-
-        CollectionScope scope = new CollectionScopeImpl( appId, orgId, type );
-        EntityCollectionManager ecm = ecmf.createCollectionManager( scope );
-        EntityCollectionIndex eci = ecif.createCollectionIndex( scope );
-
-        final String collectionName;
-        if ( type.endsWith("y") ) {
-            collectionName = type.substring( 0, type.length() - 1) + "ies";
-        } else {
-            collectionName = type + "s";
-        }
-        typesByCollectionNames.put( collectionName, type );
-        
-        entity = ecm.write( entity ).toBlockingObservable().last();
-
-        eci.index( entity );
-    }
-
-	
-	public void delete( Entity entity ) {
-
-        String type = entity.getId().getType();
-
-        CollectionScope scope = new CollectionScopeImpl( appId, orgId, type );
-        EntityCollectionManager ecm = ecmf.createCollectionManager( scope );
-        EntityCollectionIndex eci = ecif.createCollectionIndex( scope );
-
-		eci.deindex( entity );
-		ecm.delete( entity.getId() );
-	}
-
-	public void setProperty( EntityRef entityRef, String fieldName, double lat, double lon ) {
-
-        String type = entityRef.getId().getType();
-
-        CollectionScope scope = new CollectionScopeImpl( appId, orgId, type );
-        EntityCollectionManager ecm = ecmf.createCollectionManager( scope );
-        EntityCollectionIndex eci = ecif.createCollectionIndex( scope );
-
-		Entity entity = ecm.load( entityRef.getId() ).toBlockingObservable().last();
-		entity.setField( new LocationField( fieldName, new Location( lat, lon )));
-
-        entity = ecm.write(entity).toBlockingObservable().last();
-        eci.index(entity);
-	}
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5eaf05ac/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/test/Point.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/test/Point.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/test/Point.java
deleted file mode 100644
index 4de6ad5..0000000
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/test/Point.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
-Copyright 2010 Alexandre Gellibert
-
-Licensed 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.test;
-
-
-import org.apache.commons.lang.Validate;
-
-
-/** @author Alexandre Gellibert */
-public class Point {
-
-    private double lat;
-    private double lon;
-
-
-    public Point() {
-
-    }
-
-
-    public Point( double lat, double lon ) {
-        Validate.isTrue( !( lat > 90.0 || lat < -90.0 ), "Latitude must be in [-90, 90]  but was ", lat );
-        Validate.isTrue( !( lon > 180.0 || lon < -180.0 ), "Longitude must be in [-180, 180] but was ", lon );
-        this.lat = lat;
-        this.lon = lon;
-    }
-
-
-    public double getLat() {
-        return lat;
-    }
-
-
-    public void setLat( double lat ) {
-        this.lat = lat;
-    }
-
-
-    public double getLon() {
-        return lon;
-    }
-
-
-    public void setLon( double lon ) {
-        this.lon = lon;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5eaf05ac/stack/corepersistence/queryindex/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/resources/log4j.properties b/stack/corepersistence/queryindex/src/test/resources/log4j.properties
index 06b55ef..e7a0884 100644
--- a/stack/corepersistence/queryindex/src/test/resources/log4j.properties
+++ b/stack/corepersistence/queryindex/src/test/resources/log4j.properties
@@ -1,4 +1,4 @@
-log4j.rootLogger=INFO,stdout
+log4j.rootLogger=ERROR,stdout
 
 log4j.appender.stdout=org.apache.log4j.ConsoleAppender
 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
@@ -11,6 +11,5 @@ log4j.logger.org.safehaus.chop.api.store.amazon=DEBUG
 log4j.logger.org.apache.http=ERROR
 log4j.logger.com.amazonaws.request=ERROR
 
-log4j.logger.org.apache.usergrid=INFO
-log4j.logger.org.apache.usergrid.persistence.index=DEBUG
-log4j.logger.org.apache.usergrid.persistence.query=DEBUG
+log4j.logger.org.apache.usergrid.persistence.query=INFO
+log4j.logger.org.apache.usergrid.persistence.index=INFO


[5/5] git commit: Simple stress tests.

Posted by sn...@apache.org.
Simple stress 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/de98a4a1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/de98a4a1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/de98a4a1

Branch: refs/heads/two-dot-o
Commit: de98a4a1e58081240064d56c5d0aa3dc56cf505b
Parents: 5eaf05a
Author: Dave Johnson <dm...@apigee.com>
Authored: Wed Mar 5 10:23:51 2014 -0500
Committer: Dave Johnson <dm...@apigee.com>
Committed: Wed Mar 5 10:23:51 2014 -0500

----------------------------------------------------------------------
 .../collection/EntityCollectionManagerST.java   | 89 ++++++++++++++++++++
 .../index/impl/EntityCollectionIndexST.java     | 78 +++++++++++++++++
 2 files changed, 167 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/de98a4a1/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerST.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerST.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerST.java
new file mode 100644
index 0000000..e989942
--- /dev/null
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerST.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.collection;
+
+import com.google.inject.Inject;
+import org.apache.commons.lang3.time.StopWatch;
+import org.apache.usergrid.persistence.collection.cassandra.CassandraRule;
+import org.apache.usergrid.persistence.collection.guice.MigrationManagerRule;
+import org.apache.usergrid.persistence.collection.guice.TestCollectionModule;
+import org.apache.usergrid.persistence.collection.impl.CollectionScopeImpl;
+import org.apache.usergrid.persistence.model.entity.Entity;
+import org.apache.usergrid.persistence.model.entity.SimpleId;
+import org.jukito.JukitoRunner;
+import org.jukito.UseModules;
+import static org.junit.Assert.assertNotNull;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import rx.Observable;
+
+
+@RunWith(JukitoRunner.class)
+@UseModules(TestCollectionModule.class)
+public class EntityCollectionManagerST {
+    private static final Logger log = LoggerFactory.getLogger( EntityCollectionManagerST.class );
+
+    @Inject
+    private EntityCollectionManagerFactory factory;
+
+    @ClassRule
+    public static CassandraRule rule = new CassandraRule();
+
+    @Inject
+    @Rule
+    public MigrationManagerRule migrationManagerRule;
+
+    @Test
+    public void writeThousands() {
+
+        CollectionScope context = new CollectionScopeImpl(
+                new SimpleId("organization"), new SimpleId("test"), "test");
+
+        EntityCollectionManager manager = factory.createCollectionManager(context);
+
+        int limit = 10000;
+
+        StopWatch timer = new StopWatch();
+        timer.start();
+
+        for (int i = 0; i < limit; i++) {
+
+            Entity newEntity = new Entity(new SimpleId("test"));
+            Observable<Entity> observable = manager.write(newEntity);
+            Entity returned = observable.toBlockingObservable().lastOrDefault(null);
+            assertNotNull("Returned has a id", returned.getId());
+            assertNotNull("Returned has a version", returned.getVersion());
+
+            Entity fetched = manager.load( returned.getId() ).toBlockingObservable().last();
+            assertNotNull("Returned has a id", fetched.getId());
+            assertNotNull("Returned has a version", fetched.getVersion());
+
+            if ( i % 1000 == 0 ) {
+                log.info("   Wrote: " + i);
+            }
+        }
+
+        timer.stop();
+        log.info( "Total time to write {} entries {}ms, average {}ms/entry", 
+            limit, timer.getTime(), timer.getTime() / limit );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/de98a4a1/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexST.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexST.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexST.java
new file mode 100644
index 0000000..c2e693c
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexST.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.index.impl;
+
+import com.google.inject.Inject;
+import java.io.IOException;
+import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.commons.lang3.time.StopWatch;
+import org.apache.usergrid.persistence.collection.CollectionScope;
+import org.apache.usergrid.persistence.collection.impl.CollectionScopeImpl;
+import org.apache.usergrid.persistence.collection.util.EntityUtils;
+import org.apache.usergrid.persistence.index.EntityCollectionIndex;
+import org.apache.usergrid.persistence.index.EntityCollectionIndexFactory;
+import org.apache.usergrid.persistence.index.guice.TestIndexModule;
+import org.apache.usergrid.persistence.model.entity.Entity;
+import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.model.entity.SimpleId;
+import org.apache.usergrid.persistence.model.field.StringField;
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
+import org.jukito.JukitoRunner;
+import org.jukito.UseModules;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+@RunWith(JukitoRunner.class)
+@UseModules(TestIndexModule.class)
+public class EntityCollectionIndexST {
+    private static final Logger log = LoggerFactory.getLogger( EntityCollectionIndexST.class );
+        
+    @Inject
+    public EntityCollectionIndexFactory collectionIndexFactory;    
+
+    @Test
+    public void indexThousands() throws IOException {
+
+        Id appId = new SimpleId("application");
+        Id orgId = new SimpleId("organization");
+        CollectionScope scope = new CollectionScopeImpl( appId, orgId, "contacts" );
+        EntityCollectionIndex index = collectionIndexFactory.createCollectionIndex( scope );
+
+        int limit = 10000;
+        StopWatch timer = new StopWatch();
+        timer.start();
+        for ( int i = 0; i < limit; i++ ) { 
+
+            Entity entity = new Entity(new SimpleId(UUIDGenerator.newTimeUUID(), scope.getName()));
+            EntityUtils.setVersion( entity, UUIDGenerator.newTimeUUID() );
+            entity.setField( new StringField( "name", RandomStringUtils.randomAlphabetic(20)) );
+
+            index.index( entity );
+
+            if ( i % 1000 == 0 ) {
+                log.info("   Indexed: " + i);
+            }
+        }
+        timer.stop();
+        log.info( "Total time to index {} entries {}ms, average {}ms/entry", 
+            limit, timer.getTime(), timer.getTime() / limit );
+    }
+}


[3/5] Re-organize test packages.

Posted by sn...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5eaf05ac/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/IndexIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/IndexIT.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/IndexIT.java
deleted file mode 100644
index 1bf2fcd..0000000
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/IndexIT.java
+++ /dev/null
@@ -1,484 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence;
-
-import com.google.inject.Inject;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
-import org.apache.usergrid.persistence.collection.cassandra.CassandraRule;
-import org.apache.usergrid.persistence.collection.guice.MigrationManagerRule;
-import org.apache.usergrid.persistence.index.EntityCollectionIndexFactory;
-import org.apache.usergrid.persistence.index.guice.IndexTestModule;
-import org.apache.usergrid.persistence.model.entity.Entity;
-import org.apache.usergrid.persistence.model.entity.Id;
-import org.apache.usergrid.persistence.model.entity.SimpleId;
-import org.apache.usergrid.persistence.query.Query;
-import org.apache.usergrid.persistence.query.Results;
-import org.apache.usergrid.persistence.utils.JsonUtils;
-import org.apache.usergrid.test.CoreApplication;
-import org.apache.usergrid.test.CoreITSetup;
-import org.apache.usergrid.test.CoreITSetupImpl;
-import org.apache.usergrid.test.EntityManagerFacade;
-import org.jukito.JukitoRunner;
-import org.jukito.UseModules;
-import static org.junit.Assert.assertEquals;
-import org.junit.ClassRule;
-import org.junit.Ignore;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-@RunWith(JukitoRunner.class)
-@UseModules({ IndexTestModule.class })
-public class IndexIT {
-    
-    private static final Logger LOG = LoggerFactory.getLogger( IndexIT.class );
-
-    @ClassRule
-    public static CassandraRule cass = new CassandraRule();
-
-    @Inject
-    @Rule
-    public MigrationManagerRule migrationManagerRule;
-    
-    @ClassRule
-    public static CoreITSetup setup = new CoreITSetupImpl();
-
-    @Rule
-    public CoreApplication app = new CoreApplication( setup );
-
-    @Inject
-    public EntityCollectionManagerFactory collectionManagerFactory;
-    
-    @Inject
-    public EntityCollectionIndexFactory collectionIndexFactory;
-
-    public static final String[] alphabet = {
-            "Alpha", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot", "Golf", "Hotel", "India", "Juliet", "Kilo", "Lima",
-            "Mike", "November", "Oscar", "Papa", "Quebec", "Romeo", "Sierra", "Tango", "Uniform", "Victor", "Whiskey",
-            "X-ray", "Yankee", "Zulu"
-    };
-
-    @Ignore // TODO: enable when Cursor support implemented
-    @Test
-    public void testCollectionOrdering() throws Exception {
-        LOG.info( "testCollectionOrdering" );
-
-        Id appId = new SimpleId("application");
-        Id orgId = new SimpleId("organization");
-        EntityManagerFacade em = new EntityManagerFacade( orgId, appId, 
-            collectionManagerFactory, collectionIndexFactory );
-
-        for ( int i = alphabet.length - 1; i >= 0; i-- ) {
-            String name = alphabet[i];
-            Map<String, Object> properties = new LinkedHashMap<String, Object>();
-            properties.put( "name", name );
-
-            em.create( "items", properties );
-        }
-
-        int i = 0;
-        
-        Query query = Query.fromQL( "order by name" );
-        Results r = em.searchCollection( em.getApplicationRef(), "items", query );
-        for ( Entity entity : r.getEntities() ) {
-            assertEquals( alphabet[i], entity.getField( "name" ).getValue() );
-            i++;
-        }
-
-        query = Query.fromQL( "order by name" ).withCursor( r.getCursor() );
-        r = em.searchCollection( em.getApplicationRef(), "items", query );
-        for ( Entity entity : r.getEntities() ) {
-            assertEquals( alphabet[i], entity.getField( "name" ).getValue() );
-            i++;
-        }
-
-        query = Query.fromQL( "order by name" ).withCursor( r.getCursor() );
-        r = em.searchCollection( em.getApplicationRef(), "items", query );
-        for ( Entity entity : r.getEntities() ) {
-            assertEquals( alphabet[i], entity.getField( "name" ).getValue() );
-            i++;
-        }
-
-        assertEquals( alphabet.length, i );
-
-        i = alphabet.length;
-
-        query = Query.fromQL( "order by name desc" );
-        r = em.searchCollection( em.getApplicationRef(), "items", query );
-        for ( Entity entity : r.getEntities() ) {
-            i--;
-            assertEquals( alphabet[i], entity.getField( "name" ).getValue() );
-        }
-
-        query = Query.fromQL( "order by name desc" ).withCursor( r.getCursor() );
-        r = em.searchCollection( em.getApplicationRef(), "items", query );
-        // LOG.info(JsonUtils.mapToFormattedJsonString(r.getEntities()));
-        for ( Entity entity : r.getEntities() ) {
-            i--;
-            assertEquals( alphabet[i], entity.getField( "name" ).getValue() );
-        }
-
-        query = Query.fromQL( "order by name desc" ).withCursor( r.getCursor() );
-        r = em.searchCollection( em.getApplicationRef(), "items", query );
-        for ( Entity entity : r.getEntities() ) {
-            i--;
-            assertEquals( alphabet[i], entity.getField( "name" ).getValue() );
-        }
-
-        assertEquals( 0, i );
-    }
-
-
-    @Test
-    public void testCollectionFilters() throws Exception {
-        LOG.info( "testCollectionFilters" );
-
-        Id appId = new SimpleId("application");
-        Id orgId = new SimpleId("organization");
-        EntityManagerFacade em = new EntityManagerFacade( orgId, appId, 
-            collectionManagerFactory, collectionIndexFactory );
-
-        for ( int i = alphabet.length - 1; i >= 0; i-- ) {
-            String name = alphabet[i];
-            Map<String, Object> properties = new LinkedHashMap<String, Object>();
-            properties.put( "name", name );
-            em.create( "item", properties );
-        }
-
-        Query query = Query.fromQL( "name < 'Delta' order by name" );
-        Results r = em.searchCollection( em.getApplicationRef(), "items", query );
-        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
-        int i = 0;
-        for ( Entity entity : r.getEntities() ) {
-            assertEquals( alphabet[i], entity.getField( "name" ).getValue() );
-            i++;
-        }
-        assertEquals( 3, i );
-
-        query = Query.fromQL( "name <= 'delta' order by name" );
-        r = em.searchCollection( em.getApplicationRef(), "items", query );
-        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
-        i = 0;
-        for ( Entity entity : r.getEntities() ) {
-            assertEquals( alphabet[i], entity.getField( "name" ).getValue() );
-            i++;
-        }
-        assertEquals( 4, i );
-
-        query = Query.fromQL( "name <= 'foxtrot' and name > 'bravo' order by name" );
-        r = em.searchCollection( em.getApplicationRef(), "items", query );
-        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
-        i = 2;
-        for ( Entity entity : r.getEntities() ) {
-            assertEquals( alphabet[i], entity.getField( "name" ).getValue() );
-            i++;
-        }
-        assertEquals( 6, i );
-
-        query = Query.fromQL( "name < 'foxtrot' and name > 'bravo' order by name" );
-        r = em.searchCollection( em.getApplicationRef(), "items", query );
-        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
-        i = 2;
-        for ( Entity entity : r.getEntities() ) {
-            assertEquals( alphabet[i], entity.getField( "name" ).getValue() );
-            i++;
-        }
-        assertEquals( 5, i );
-
-        query = Query.fromQL( "name < 'foxtrot' and name >= 'bravo' order by name" );
-        r = em.searchCollection( em.getApplicationRef(), "items", query );
-        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
-        i = 1;
-        for ( Entity entity : r.getEntities() ) {
-            assertEquals( alphabet[i], entity.getField( "name" ).getValue() );
-            i++;
-        }
-        assertEquals( 5, i );
-
-        query = Query.fromQL( "name <= 'foxtrot' and name >= 'bravo' order by name" );
-        r = em.searchCollection( em.getApplicationRef(), "items", query );
-        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
-        i = 1;
-        for ( Entity entity : r.getEntities() ) {
-            assertEquals( alphabet[i], entity.getField( "name" ).getValue() );
-            i++;
-        }
-        assertEquals( 6, i );
-
-        query = Query.fromQL( "name <= 'foxtrot' and name >= 'bravo' order by name desc" );
-        r = em.searchCollection( em.getApplicationRef(), "items", query );
-        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
-        i = 6;
-        for ( Entity entity : r.getEntities() ) {
-            i--;
-            assertEquals( alphabet[i], entity.getField( "name" ).getValue() );
-        }
-        assertEquals( 1, i );
-
-        query = Query.fromQL( "name < 'foxtrot' and name > 'bravo' order by name desc" );
-        r = em.searchCollection( em.getApplicationRef(), "items", query );
-        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
-        i = 5;
-        for ( Entity entity : r.getEntities() ) {
-            i--;
-            assertEquals( alphabet[i], entity.getField( "name" ).getValue() );
-        }
-        assertEquals( 2, i );
-
-        query = Query.fromQL( "name < 'foxtrot' and name >= 'bravo' order by name desc" );
-        r = em.searchCollection( em.getApplicationRef(), "items", query );
-        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
-        i = 5;
-        for ( Entity entity : r.getEntities() ) {
-            i--;
-            assertEquals( alphabet[i], entity.getField( "name" ).getValue() );
-        }
-        assertEquals( 1, i );
-
-        query = Query.fromQL( "name = 'foxtrot'" );
-        r = em.searchCollection( em.getApplicationRef(), "items", query );
-        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
-        assertEquals( 1, r.size() );
-
-        long created = r.getEntity().getVersion().timestamp();
-        Id entityId = r.getEntity().getId();
-
-        query = Query.fromQL( "created = " + created );
-        r = em.searchCollection( em.getApplicationRef(), "items", query );
-        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
-        assertEquals( 1, r.size() );
-        assertEquals( entityId, r.getEntity().getId() );
-    }
-
-
-    @Test
-    public void testSecondarySorts() throws Exception {
-        LOG.info( "testSecondarySorts" );
-
-        Id appId = new SimpleId("application");
-        Id orgId = new SimpleId("organization");
-        EntityManagerFacade em = new EntityManagerFacade( orgId, appId, 
-            collectionManagerFactory, collectionIndexFactory );
-
-        for ( int i = alphabet.length - 1; i >= 0; i-- ) {
-            String name = alphabet[i];
-            Map<String, Object> properties = new LinkedHashMap<String, Object>();
-            properties.put( "name", name );
-            properties.put( "group", i / 3 );
-            properties.put( "reverse_name", alphabet[alphabet.length - 1 - i] );
-
-            em.create( "item", properties );
-        }
-
-        Query query = Query.fromQL( "group = 1 order by name desc" );
-        Results r = em.searchCollection( em.getApplicationRef(), "items", query );
-        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
-        int i = 6;
-        for ( Entity entity : r.getEntities() ) {
-            i--;
-            assertEquals( 1, entity.getField( "group" ).getValue() );
-            assertEquals( alphabet[i], entity.getField( "name" ).getValue() );
-        }
-        assertEquals( 3, i );
-    }
-
-
-//    @Test
-//    public void testPropertyUpdateWithConnection() throws Exception {
-//
-//        Id appId = new SimpleId("application");
-//        Id orgId = new SimpleId("organization");
-//        CollectionScope scope = new CollectionScopeImpl( appId, orgId, "items" );
-//        EntityManagerFacade em = new EntityManagerFacade( factory, null);
-//
-//
-//        Map<String, Object> entity1 = new LinkedHashMap<String, Object>();
-//        entity1.put( "name", "name_1" );
-//        entity1.put( "status", "pickled" );
-//
-//
-//        Map<String, Object> entity2 = new LinkedHashMap<String, Object>();
-//        entity2.put( "name", "name_2" );
-//        entity2.put( "status", "foo" );
-//
-//
-//        Entity entity1Ref = em.create( "names", entity1 );
-//        Entity entity2Ref = em.create( "names", entity2 );
-//
-//
-//        em.createConnection( entity2Ref, "connecting", entity1Ref );
-//
-//        //should return valid values
-//        Query query = Query.fromQL( "select * where status = 'pickled'" );
-//
-//        Results r = em.searchCollection( em.getApplicationRef(), "names", query );
-//        assertEquals( 1, r.size() );
-//        assertEquals( entity1Ref.getUuid(), r.getEntity().getUuid() );
-//
-//
-//        r = em.searchCollection( em.getApplicationRef(), "names", query );
-//        assertEquals( 1, r.size() );
-//        assertEquals( entity1Ref.getUuid(), r.getEntity().getUuid() );
-//
-//        //now update the first entity, this causes the failure after connections
-//        entity1Ref.setProperty( "status", "herring" );
-//
-//        em.update( entity1Ref );
-//
-//        //query and check the status has been updated, shouldn't return results
-//        query = Query.fromQL( "select * where status = 'pickled'" );
-//
-//        r = em.searchCollection( em.getApplicationRef(), "names", query );
-//        assertEquals( 0, r.size() );
-//
-//        //search connections
-//        r = em.searchCollection( em.getApplicationRef(), "names", query );
-//        assertEquals( 0, r.size() );
-//
-//
-//        //should return results
-//        query = Query.fromQL( "select * where status = 'herring'" );
-//
-//        r = em.searchCollection( em.getApplicationRef(), "names", query );
-//        assertEquals( 1, r.size() );
-//
-//        assertEquals( entity1Ref.getUuid(), r.getEntity().getUuid() );
-//
-//
-//        //search connections
-//        r = em.searchCollection( em.getApplicationRef(), "names", query );
-//        assertEquals( 1, r.size() );
-//        assertEquals( entity1Ref.getUuid(), r.getEntity().getUuid() );
-//    }
-//
-//
-//    /** Same as above, but verifies the data in our entity_index_entry CF after the operations have completed */
-//
-//    @Test
-//    public void testPropertyUpdateWithConnectionEntityIndexEntryAudit() throws Exception {
-//
-//        Id appId = new SimpleId("application");
-//        Id orgId = new SimpleId("organization");
-//        CollectionScope scope = new CollectionScopeImpl( appId, orgId, "items" );
-//        EntityManagerFacade em = new EntityManagerFacade( factory, null);
-//
-//
-//        Map<String, Object> entity1 = new LinkedHashMap<String, Object>();
-//        entity1.put( "name", "name_1" );
-//        entity1.put( "status", "pickled" );
-//
-//
-//        Map<String, Object> entity2 = new LinkedHashMap<String, Object>();
-//        entity2.put( "name", "name_2" );
-//        entity2.put( "status", "foo" );
-//
-//
-//        Entity entity1Ref = em.create( "names", entity1 );
-//        Entity entity2Ref = em.create( "names", entity2 );
-//
-//
-//        em.createConnection( entity2Ref, "connecting", entity1Ref );
-//
-//        //should return valid values
-//        Query query = Query.fromQL( "select * where status = 'pickled'" );
-//
-//        Results r = em.searchCollection( em.getApplicationRef(), "names", query );
-//        assertEquals( 1, r.size() );
-//        assertEquals( entity1Ref.getUuid(), r.getEntity().getUuid() );
-//
-//
-//        r = em.searchCollection( em.getApplicationRef(), "names", query );
-//        assertEquals( 1, r.size() );
-//        assertEquals( entity1Ref.getUuid(), r.getEntity().getUuid() );
-//
-//        //now update the first entity, this causes the failure after connections
-//        entity1Ref.setProperty( "status", "herring" );
-//
-//        em.update( entity1Ref );
-//
-//        //query and check the status has been updated, shouldn't return results
-//        query = Query.fromQL( "select * where status = 'pickled'" );
-//
-//        r = em.searchCollection( em.getApplicationRef(), "names", query );
-//        assertEquals( 0, r.size() );
-//
-//        //search connections
-//        r = em.searchCollection( em.getApplicationRef(), "names", query );
-//        assertEquals( 0, r.size() );
-//
-//
-//        //should return results
-//        query = Query.fromQL( "select * where status = 'herring'" );
-//
-//        r = em.searchCollection( em.getApplicationRef(), "names", query );
-//        assertEquals( 1, r.size() );
-//
-//        assertEquals( entity1Ref.getUuid(), r.getEntity().getUuid() );
-//
-//
-//        //search connections
-//        r = em.searchCollection( em.getApplicationRef(), "names", query );
-//        assertEquals( 1, r.size() );
-//        assertEquals( entity1Ref.getUuid(), r.getEntity().getUuid() );
-//
-//
-//        RelationManagerImpl impl = ( RelationManagerImpl ) em.getRelationManager( entity2Ref );
-//
-//        //now read the index and see what properties are there
-//
-//
-//        CassandraService cass = CoreITSuite.cassandraResource.getBean( CassandraService.class );
-//
-//        ByteBufferSerializer buf = ByteBufferSerializer.get();
-//
-//        Keyspace ko = cass.getApplicationKeyspace( applicationId );
-//        Mutator<ByteBuffer> m = createMutator( ko, buf );
-//
-//
-//        IndexUpdate update =
-//                impl.batchStartIndexUpdate( m, entity1Ref, "status", "ignore", UUIDUtils.newTimeUUID(), false, false,
-//                        true, false );
-//
-//        int count = 0;
-//
-//        IndexEntry lastMatch = null;
-//
-//        for ( IndexEntry entry : update.getPrevEntries() ) {
-//            if ( "status".equals( entry.getPath() ) ) {
-//                count++;
-//                lastMatch = entry;
-//            }
-//        }
-//
-//
-//        assertEquals( 1, count );
-//
-//        if ( lastMatch != null ) {
-//            assertEquals( "herring", lastMatch.getValue() );
-//        }
-//        else {
-//            fail( "The last match was null but should have been herring!" );
-//        }
-//    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5eaf05ac/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/guice/IndexTestModule.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/guice/IndexTestModule.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/guice/IndexTestModule.java
deleted file mode 100644
index fa60155..0000000
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/guice/IndexTestModule.java
+++ /dev/null
@@ -1,30 +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.persistence.index.guice;
-
-import org.apache.usergrid.persistence.collection.guice.TestModule;
-
-
-public class IndexTestModule extends TestModule {
-
-    @Override
-    protected void configure() {
-        install( new IndexModule() );
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5eaf05ac/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/guice/TestIndexModule.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/guice/TestIndexModule.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/guice/TestIndexModule.java
new file mode 100644
index 0000000..3c2390b
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/guice/TestIndexModule.java
@@ -0,0 +1,30 @@
+/*
+ * 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.persistence.index.guice;
+
+import org.apache.usergrid.persistence.collection.guice.TestModule;
+
+
+public class TestIndexModule extends TestModule {
+
+    @Override
+    protected void configure() {
+        install( new IndexModule() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5eaf05ac/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CollectionIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CollectionIT.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CollectionIT.java
new file mode 100644
index 0000000..0444daf
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CollectionIT.java
@@ -0,0 +1,1638 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.index.impl;
+
+
+import com.google.inject.Inject;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
+import org.apache.usergrid.persistence.collection.cassandra.CassandraRule;
+import org.apache.usergrid.persistence.collection.guice.MigrationManagerRule;
+import org.apache.usergrid.persistence.index.EntityCollectionIndexFactory;
+import org.apache.usergrid.persistence.index.guice.TestIndexModule;
+import org.apache.usergrid.persistence.index.legacy.CoreApplication;
+import org.apache.usergrid.persistence.index.legacy.CoreITSetup;
+import org.apache.usergrid.persistence.index.legacy.CoreITSetupImpl;
+import org.apache.usergrid.persistence.index.legacy.EntityManagerFacade;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.usergrid.persistence.model.entity.Entity;
+import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.model.entity.SimpleId;
+import org.apache.usergrid.persistence.model.field.StringField;
+import org.apache.usergrid.persistence.query.Query;
+import org.apache.usergrid.persistence.query.Results;
+import org.apache.usergrid.persistence.utils.JsonUtils;
+import static org.apache.usergrid.persistence.utils.MapUtils.hashMap;
+import org.apache.usergrid.persistence.utils.UUIDUtils;
+import org.jukito.JukitoRunner;
+import org.jukito.UseModules;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.runner.RunWith;
+
+
+@RunWith(JukitoRunner.class)
+@UseModules({ TestIndexModule.class })
+public class CollectionIT {
+    private static final Logger LOG = LoggerFactory.getLogger( CollectionIT.class );
+
+    @ClassRule
+    public static CassandraRule cass = new CassandraRule();
+
+    @Inject
+    @Rule
+    public MigrationManagerRule migrationManagerRule;
+    
+    @ClassRule
+    public static CoreITSetup setup = new CoreITSetupImpl();
+
+    @Rule
+    public CoreApplication app = new CoreApplication( setup );
+
+    @Inject
+    public EntityCollectionManagerFactory collectionManagerFactory;
+    
+    @Inject
+    public EntityCollectionIndexFactory collectionIndexFactory;
+
+    private EntityManagerFacade em;
+
+    @Before
+    public void setup() {
+
+        Id appId = new SimpleId("application");
+        Id orgId = new SimpleId("organization");
+
+        em = new EntityManagerFacade( orgId, appId, 
+            collectionManagerFactory, collectionIndexFactory );
+
+        app.setEntityManager( em );                
+    }
+
+    @Test
+    public void testCollection() throws Exception {
+        app.put( "username", "edanuff" );
+        app.put( "email", "ed@anuff.com" );
+
+        Entity user = app.create( "user" );
+        assertNotNull( user );
+
+        app.put( "actor", new LinkedHashMap<String, Object>() {
+            {
+                put( "displayName", "Ed Anuff" );
+                put( "objectType", "person" );
+            }
+        } );
+        app.put( "verb", "tweet" );
+        app.put( "content", "I ate a sammich" );
+        app.put( "ordinal", 3 );
+
+        Entity activity = app.create( "activity" );
+        assertNotNull( activity );
+
+        LOG.info( "" + activity.getClass() );
+        LOG.info( JsonUtils.mapToFormattedJsonString( activity ) );
+
+        activity = app.get( activity.getId() );
+
+        LOG.info( "Activity class = {}", activity.getClass() );
+        LOG.info( JsonUtils.mapToFormattedJsonString( activity ) );
+
+        app.addToCollection( user, "activities", activity );
+
+        // test queries on the collection
+
+        app.put( "actor", new LinkedHashMap<String, Object>() {
+            {
+                put( "displayName", "Ed Anuff" );
+                put( "objectType", "person" );
+            }
+        } );
+        app.put( "verb", "tweet2" );
+        app.put( "content", "I ate a pickle" );
+        app.put( "ordinal", 2 );
+        Entity activity2 = app.create( "activity" );
+        activity2 = app.get( activity2.getId() );
+        app.addToCollection( user, "activities", activity2 );
+
+        app.put( "actor", new LinkedHashMap<String, Object>() {
+            {
+                put( "displayName", "Ed Anuff" );
+                put( "objectType", "person" );
+            }
+        } );
+        app.put( "verb", "tweet2" );
+        app.put( "content", "I ate an apple" );
+        app.put( "ordinal", 1 );
+        Entity activity3 = app.create( "activity" );
+        activity3 = app.get( activity3.getId() );
+        app.addToCollection( user, "activities", activity3 );
+
+        // empty query
+        Query query = new Query();
+        Results r = app.searchCollection( user, "activities", query );
+        assertEquals( 3, r.size() ); // success
+
+        // query verb
+        query = new Query().addEqualityFilter( "verb", "tweet2" );
+        r = app.searchCollection( user, "activities", query );
+        assertEquals( 2, r.size() );
+
+        // query verb, sort created
+        query = new Query().addEqualityFilter( "verb", "tweet2" );
+        query.addSort( "created" );
+        r = app.searchCollection( user, "activities", query );
+        assertEquals( 2, r.size() );
+        List<Entity> entities = r.getEntities();
+        assertEquals( entities.get( 0 ).getId(), activity2.getId() );
+        assertEquals( entities.get( 1 ).getId(), activity3.getId() );
+
+        // query verb, sort ordinal
+        query = new Query().addEqualityFilter( "verb", "tweet2" );
+        query.addSort( "ordinal" );
+        r = app.searchCollection( user, "activities", query );
+        assertEquals( 2, r.size() );
+        entities = r.getEntities();
+        assertEquals( entities.get( 0 ).getId(), activity3.getId() );
+        assertEquals( entities.get( 1 ).getId(), activity2.getId() );
+
+        // empty query, sort content
+        query = new Query();
+        query.addSort( "content" );
+        r = app.searchCollection( user, "activities", query );
+        assertEquals( 3, r.size() );
+        entities = r.getEntities();
+        LOG.info( JsonUtils.mapToFormattedJsonString( entities ) );
+        assertEquals( entities.get( 0 ).getId(), activity2.getId() );
+        assertEquals( entities.get( 1 ).getId(), activity.getId() );
+        assertEquals( entities.get( 2 ).getId(), activity3.getId() );
+
+        // empty query, sort verb
+        query = new Query();
+        query.addSort( "verb" );
+        r = app.searchCollection( user, "activities", query );
+        assertEquals( 3, r.size() );
+
+        // empty query, sort ordinal
+        query = new Query();
+        query.addSort( "ordinal" );
+        r = app.searchCollection( user, "activities", query );
+        assertEquals( 3, r.size() );
+        entities = r.getEntities();
+        assertEquals( entities.get( 0 ).getId(), activity3.getId() );
+        assertEquals( entities.get( 1 ).getId(), activity2.getId() );
+        assertEquals( entities.get( 2 ).getId(), activity.getId() );
+
+        // query ordinal
+        query = new Query().addEqualityFilter( "ordinal", 2 );
+        r = app.searchCollection( user, "activities", query );
+        assertEquals( 1, r.size() );
+
+        // query ordinal and sort ordinal
+        query = new Query().addEqualityFilter( "ordinal", 2 );
+        query.addSort( "ordinal" );
+        r = app.searchCollection( user, "activities", query );
+        assertEquals( 1, r.size() );
+    }
+
+
+    @Test
+    public void userFirstNameSearch() throws Exception {
+
+        String firstName = "firstName" + UUIDUtils.newTimeUUID();
+
+        Map<String, Object> properties = new LinkedHashMap<String, Object>();
+        properties.put( "username", "edanuff" );
+        properties.put( "email", "ed@anuff.com" );
+        properties.put( "firstname", firstName );
+
+        Entity user = em.create( "user", properties );
+        assertNotNull( user );
+
+        // EntityRef
+        Query query = new Query();
+        query.addEqualityFilter( "firstname", firstName );
+
+        Results r = em.searchCollection( em.getApplicationRef(), "users", query );
+
+        assertTrue( r.size() > 0 );
+
+        Entity returned = r.getEntities().get( 0 );
+
+        assertEquals( user.getId(), returned.getId() );
+
+        // update the username
+        String newFirstName = "firstName" + UUIDUtils.newTimeUUID();
+
+        user.setField( new StringField("firstname", newFirstName) );
+
+        em.update( user );
+
+        // search with the old username, should be no results
+        query = new Query();
+        query.addEqualityFilter( "firstname", firstName );
+
+        r = em.searchCollection( em.getApplicationRef(), "users", query );
+
+        assertEquals( 0, r.size() );
+
+        // search with the new username, should be results.
+
+        query = new Query();
+        query.addEqualityFilter( "firstname", newFirstName );
+
+        r = em.searchCollection( em.getApplicationRef(), "users", query );
+
+        assertTrue( r.size() > 0 );
+
+        returned = r.getEntities().get( 0 );
+
+        assertEquals( user.getId(), returned.getId() );
+    }
+
+
+    @Test
+    public void userMiddleNameSearch() throws Exception {
+
+        String middleName = "middleName" + UUIDUtils.newTimeUUID();
+
+        Map<String, Object> properties = new LinkedHashMap<String, Object>();
+        properties.put( "username", "edanuff" );
+        properties.put( "email", "ed@anuff.com" );
+        properties.put( "middlename", middleName );
+
+        Entity user = em.create( "user", properties );
+        assertNotNull( user );
+
+        // EntityRef
+        Query query = new Query();
+        query.addEqualityFilter( "middlename", middleName );
+
+        Results r = em.searchCollection( em.getApplicationRef(), "users", query );
+
+        assertTrue( r.size() > 0 );
+
+        Entity returned = r.getEntities().get( 0 );
+
+        assertEquals( user.getId(), returned.getId() );
+    }
+
+
+    @Test
+    public void userLastNameSearch() throws Exception {
+
+        String lastName = "lastName" + UUIDUtils.newTimeUUID();
+
+        Map<String, Object> properties = new LinkedHashMap<String, Object>();
+        properties.put( "username", "edanuff" );
+        properties.put( "email", "ed@anuff.com" );
+        properties.put( "lastname", lastName );
+
+        Entity user = em.create( "user", properties );
+        assertNotNull( user );
+
+        // EntityRef
+        Query query = new Query();
+        query.addEqualityFilter( "lastname", lastName );
+
+        Results r = em.searchCollection( em.getApplicationRef(), "users", query );
+
+        assertTrue( r.size() > 0 );
+
+        Entity returned = r.getEntities().get( 0 );
+
+        assertEquals( user.getId(), returned.getId() );
+    }
+
+
+//    @Test
+//    public void testGroups() throws Exception {
+//        UUID applicationId = setup.createApplication( "testOrganization", "testGroups" );
+//        assertNotNull( applicationId );
+//
+//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
+//        assertNotNull( em );
+//
+//        Map<String, Object> properties = new LinkedHashMap<String, Object>();
+//        properties.put( "username", "edanuff" );
+//        properties.put( "email", "ed@anuff.com" );
+//
+//        Entity user1 = em.create( "user", properties );
+//        assertNotNull( user1 );
+//
+//        properties = new LinkedHashMap<String, Object>();
+//        properties.put( "username", "djacobs" );
+//        properties.put( "email", "djacobs@gmail.com" );
+//
+//        Entity user2 = em.create( "user", properties );
+//        assertNotNull( user2 );
+//
+//        properties = new LinkedHashMap<String, Object>();
+//        properties.put( "path", "group1" );
+//        Entity group = em.create( "group", properties );
+//        assertNotNull( group );
+//
+//        em.addToCollection( group, "users", user1 );
+//        em.addToCollection( group, "users", user2 );
+//
+//        properties = new LinkedHashMap<String, Object>();
+//        properties.put( "nickname", "ed" );
+//        em.updateProperties( new SimpleCollectionRef( group, "users", user1 ), properties );
+//
+//        Results r = em.searchCollection( group, "users", new Query().addEqualityFilter( "member.nickname", "ed" )
+//                                                                    .withResultsLevel(
+//                                                                            Results.Level.LINKED_PROPERTIES ) );
+//        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
+//        assertEquals( 1, r.size() );
+//
+//        em.removeFromCollection( user1, "groups", group );
+//    }
+
+
+    @Test
+    public void groupNameSearch() throws Exception {
+
+        String groupName = "groupName" + UUIDUtils.newTimeUUID();
+
+        Map<String, Object> properties = new LinkedHashMap<String, Object>();
+        properties.put( "title", "testTitle" );
+        properties.put( "path", "testPath" );
+        properties.put( "name", groupName );
+
+        Entity group = em.create( "group", properties );
+        assertNotNull( group );
+
+        // EntityRef
+        Query query = new Query();
+        query.addEqualityFilter( "name", groupName );
+
+        Results r = em.searchCollection( em.getApplicationRef(), "groups", query );
+
+        assertTrue( r.size() > 0 );
+
+        Entity returned = r.getEntities().get( 0 );
+
+        assertEquals( group.getId(), returned.getId() );
+    }
+
+
+    @Test
+    public void groupTitleSearch() throws Exception {
+
+
+        String titleName = "groupName" + UUIDUtils.newTimeUUID();
+
+        Map<String, Object> properties = new LinkedHashMap<String, Object>();
+        properties.put( "title", titleName );
+        properties.put( "path", "testPath" );
+        properties.put( "name", "testName" );
+
+        Entity group = em.create( "group", properties );
+        assertNotNull( group );
+
+        // EntityRef
+        Query query = new Query();
+        query.addEqualityFilter( "title", titleName );
+
+        Results r = em.searchCollection( em.getApplicationRef(), "groups", query );
+
+        assertTrue( r.size() > 0 );
+
+        Entity returned = r.getEntities().get( 0 );
+
+        assertEquals( group.getId(), returned.getId() );
+    }
+
+
+    @Test
+    public void testSubkeys() throws Exception {
+
+        Map<String, Object> properties = new LinkedHashMap<String, Object>();
+        properties.put( "username", "edanuff" );
+        properties.put( "email", "ed@anuff.com" );
+
+        Entity user = em.create( "user", properties );
+        assertNotNull( user );
+
+        properties = new LinkedHashMap<String, Object>();
+        properties.put( "actor", hashMap( "displayName", "Ed Anuff" ).map( "objectType", "person" ) );
+        properties.put( "verb", "tweet" );
+        properties.put( "content", "I ate a sammich" );
+
+        em.addToCollection( user, "activities", em.create( "activity", properties ) );
+
+        properties = new LinkedHashMap<String, Object>();
+        properties.put( "actor", hashMap( "displayName", "Ed Anuff" ).map( "objectType", "person" ) );
+        properties.put( "verb", "post" );
+        properties.put( "content", "I wrote a blog post" );
+
+        em.addToCollection( user, "activities", em.create( "activity", properties ) );
+
+        properties = new LinkedHashMap<String, Object>();
+        properties.put( "actor", hashMap( "displayName", "Ed Anuff" ).map( "objectType", "person" ) );
+        properties.put( "verb", "tweet" );
+        properties.put( "content", "I ate another sammich" );
+
+        em.addToCollection( user, "activities", em.create( "activity", properties ) );
+
+        properties = new LinkedHashMap<String, Object>();
+        properties.put( "actor", hashMap( "displayName", "Ed Anuff" ).map( "objectType", "person" ) );
+        properties.put( "verb", "post" );
+        properties.put( "content", "I wrote another blog post" );
+
+        em.addToCollection( user, "activities", em.create( "activity", properties ) );
+
+        Results r = em.searchCollection( user, "activities", Query.searchForProperty( "verb", "post" ) );
+        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
+        assertEquals( 2, r.size() );
+    }
+
+
+//    @Test
+//    public void emptyQuery() throws Exception {
+//
+//        String firstName = "firstName" + UUIDUtils.newTimeUUID();
+//
+//        Map<String, Object> properties = new LinkedHashMap<String, Object>();
+//        properties.put( "username", "edanuff" );
+//        properties.put( "email", "ed@anuff.com" );
+//        properties.put( "firstname", firstName );
+//
+//        Entity user = em.create( "user", properties );
+//        assertNotNull( user );
+//
+//        properties = new LinkedHashMap<String, Object>();
+//        properties.put( "username", "djacobs" );
+//        properties.put( "email", "djacobs@gmail.com" );
+//
+//        Entity user2 = em.create( "user", properties );
+//        assertNotNull( user2 );
+//
+//        // EntityRef
+//        Query query = new Query();
+//
+//        Results r = em.searchCollection( em.getApplicationRef(), "users", query );
+//
+//        assertEquals( 2, r.size() );
+//
+//        Entity returned = r.getEntities().get( 0 );
+//
+//        assertEquals( user.getId(), returned.getId() );
+//
+//        returned = r.getEntities().get( 1 );
+//
+//        assertEquals( user2.getId(), returned.getId() );
+//    }
+
+
+//    @Test
+//    public void emptyQueryReverse() throws Exception {
+//
+//        String firstName = "firstName" + UUIDUtils.newTimeUUID();
+//
+//        Map<String, Object> properties = new LinkedHashMap<String, Object>();
+//        properties.put( "username", "edanuff" );
+//        properties.put( "email", "ed@anuff.com" );
+//        properties.put( "firstname", firstName );
+//
+//        Entity user = em.create( "user", properties );
+//        assertNotNull( user );
+//
+//        properties = new LinkedHashMap<String, Object>();
+//        properties.put( "username", "djacobs" );
+//        properties.put( "email", "djacobs@gmail.com" );
+//
+//        Entity user2 = em.create( "user", properties );
+//        assertNotNull( user2 );
+//
+//        // EntityRef
+//        Query query = new Query();
+//        query.setReversed( true );
+//
+//        Results r = em.searchCollection( em.getApplicationRef(), "users", query );
+//
+//        assertEquals( 2, r.size() );
+//
+//        Entity returned = r.getEntities().get( 0 );
+//
+//        assertEquals( user2.getId(), returned.getId() );
+//
+//        returned = r.getEntities().get( 1 );
+//
+//        assertEquals( user.getId(), returned.getId() );
+//    }
+
+
+//    @Test
+//    public void orQuery() throws Exception {
+//        UUID applicationId = setup.createApplication( "testOrganization", "orQuery" );
+//        assertNotNull( applicationId );
+//
+//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
+//        assertNotNull( em );
+//
+//        Map<String, Object> properties = new LinkedHashMap<String, Object>();
+//        properties.put( "keywords", "blah,test,game" );
+//        properties.put( "title", "Solitaire" );
+//
+//        Entity game1 = em.create( "orquerygame", properties );
+//        assertNotNull( game1 );
+//
+//        properties = new LinkedHashMap<String, Object>();
+//        properties.put( "keywords", "random,test" );
+//        properties.put( "title", "Hearts" );
+//
+//        Entity game2 = em.create( "orquerygame", properties );
+//        assertNotNull( game2 );
+//
+//        // EntityRef
+//        Query query = Query.fromQL( "select * where keywords contains 'Random' OR keywords contains 'Game'" );
+//
+//        Results r = em.searchCollection( em.getApplicationRef(), "orquerygames", query );
+//
+//        assertEquals( 2, r.size() );
+//
+//        Entity returned = r.getEntities().get( 0 );
+//
+//        assertEquals( game1.getUuid(), returned.getUuid() );
+//
+//        returned = r.getEntities().get( 1 );
+//
+//        assertEquals( game2.getUuid(), returned.getUuid() );
+//
+//        query = Query.fromQL( "select * where( keywords contains 'Random' OR keywords contains 'Game')" );
+//
+//        r = em.searchCollection( em.getApplicationRef(), "orquerygames", query );
+//
+//        assertEquals( 2, r.size() );
+//
+//        returned = r.getEntities().get( 0 );
+//
+//        assertEquals( game1.getUuid(), returned.getUuid() );
+//
+//        returned = r.getEntities().get( 1 );
+//
+//        assertEquals( game2.getUuid(), returned.getUuid() );
+//
+//        // field order shouldn't matter USERGRID-375
+//        query = Query.fromQL( "select * where keywords contains 'blah' OR title contains 'blah'" );
+//
+//        r = em.searchCollection( em.getApplicationRef(), "orquerygames", query );
+//
+//        assertEquals( 1, r.size() );
+//
+//        returned = r.getEntities().get( 0 );
+//
+//        assertEquals( game1.getUuid(), returned.getUuid() );
+//
+//        query = Query.fromQL( "select * where  title contains 'blah' OR keywords contains 'blah'" );
+//
+//        r = em.searchCollection( em.getApplicationRef(), "orquerygames", query );
+//
+//        assertEquals( 1, r.size() );
+//
+//        returned = r.getEntities().get( 0 );
+//
+//        assertEquals( game1.getUuid(), returned.getUuid() );
+//    }
+//
+//
+//    @Test
+//    public void andQuery() throws Exception {
+//        UUID applicationId = setup.createApplication( "testOrganization", "andQuery" );
+//        assertNotNull( applicationId );
+//
+//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
+//        assertNotNull( em );
+//
+//        Map<String, Object> properties = new LinkedHashMap<String, Object>();
+//        properties.put( "keywords", "blah,test,game" );
+//        properties.put( "title", "Solitaire" );
+//
+//        Entity game1 = em.create( "game", properties );
+//        assertNotNull( game1 );
+//
+//        properties = new LinkedHashMap<String, Object>();
+//        properties.put( "keywords", "random,test" );
+//        properties.put( "title", "Hearts" );
+//
+//        Entity game2 = em.create( "game", properties );
+//        assertNotNull( game2 );
+//
+//        // overlap
+//        Query query = Query.fromQL( "select * where keywords contains 'test' AND keywords contains 'random'" );
+//        Results r = em.searchCollection( em.getApplicationRef(), "games", query );
+//        assertEquals( 1, r.size() );
+//
+//        // disjoint
+//        query = Query.fromQL( "select * where keywords contains 'random' AND keywords contains 'blah'" );
+//        r = em.searchCollection( em.getApplicationRef(), "games", query );
+//        assertEquals( 0, r.size() );
+//
+//        // same each side
+//        query = Query.fromQL( "select * where keywords contains 'test' AND keywords contains 'test'" );
+//        r = em.searchCollection( em.getApplicationRef(), "games", query );
+//        assertEquals( 2, r.size() );
+//
+//        Entity returned = r.getEntities().get( 0 );
+//        assertEquals( game1.getUuid(), returned.getUuid() );
+//
+//        returned = r.getEntities().get( 1 );
+//        assertEquals( game2.getUuid(), returned.getUuid() );
+//
+//        // one side, left
+//        query = Query.fromQL( "select * where keywords contains 'test' AND keywords contains 'foobar'" );
+//        r = em.searchCollection( em.getApplicationRef(), "games", query );
+//        assertEquals( 0, r.size() );
+//
+//        // one side, right
+//        query = Query.fromQL( "select * where keywords contains 'foobar' AND keywords contains 'test'" );
+//        r = em.searchCollection( em.getApplicationRef(), "games", query );
+//        assertEquals( 0, r.size() );
+//    }
+//
+//
+//    @Test
+//    public void notQuery() throws Exception {
+//        UUID applicationId = setup.createApplication( "testOrganization", "notQuery" );
+//        assertNotNull( applicationId );
+//
+//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
+//        assertNotNull( em );
+//
+//        Map<String, Object> properties = new LinkedHashMap<String, Object>();
+//        properties.put( "keywords", "blah,test,game" );
+//        properties.put( "title", "Solitaire" );
+//
+//        Entity game1 = em.create( "game", properties );
+//        assertNotNull( game1 );
+//
+//        properties = new LinkedHashMap<String, Object>();
+//        properties.put( "keywords", "random,test" );
+//        properties.put( "title", "Hearts" );
+//
+//        Entity game2 = em.create( "game", properties );
+//        assertNotNull( game2 );
+//
+//        // simple not
+//        Query query = Query.fromQL( "select * where NOT keywords contains 'game'" );
+//        Results r = em.searchCollection( em.getApplicationRef(), "games", query );
+//        assertEquals( 1, r.size() );
+//
+//        // full negation in simple
+//        query = Query.fromQL( "select * where NOT keywords contains 'test'" );
+//        r = em.searchCollection( em.getApplicationRef(), "games", query );
+//        assertEquals( 0, r.size() );
+//
+//        // simple subtraction
+//        query = Query.fromQL( "select * where keywords contains 'test' AND NOT keywords contains 'random'" );
+//        r = em.searchCollection( em.getApplicationRef(), "games", query );
+//        assertEquals( 1, r.size() );
+//
+//        // disjoint or
+//        query = Query.fromQL( "select * where keywords contains 'random' OR NOT keywords contains 'blah'" );
+//        r = em.searchCollection( em.getApplicationRef(), "games", query );
+//        assertEquals( 1, r.size() );
+//
+//        // disjoint and
+//        query = Query.fromQL( "select * where keywords contains 'random' AND NOT keywords contains 'blah'" );
+//        r = em.searchCollection( em.getApplicationRef(), "games", query );
+//        assertEquals( 1, r.size() );
+//
+//        // self canceling or
+//        query = Query.fromQL( "select * where keywords contains 'test' AND NOT keywords contains 'test'" );
+//        r = em.searchCollection( em.getApplicationRef(), "games", query );
+//        assertEquals( 0, r.size() );
+//
+//        // select all
+//        query = Query.fromQL( "select * where keywords contains 'test' OR NOT keywords contains 'test'" );
+//        r = em.searchCollection( em.getApplicationRef(), "games", query );
+//        assertEquals( 2, r.size() );
+//
+//        // null right and
+//        query = Query.fromQL( "select * where keywords contains 'test' AND NOT keywords contains 'foobar'" );
+//        r = em.searchCollection( em.getApplicationRef(), "games", query );
+//        assertEquals( 2, r.size() );
+//
+//        // null left and
+//        query = Query.fromQL( "select * where keywords contains 'foobar' AND NOT keywords contains 'test'" );
+//        r = em.searchCollection( em.getApplicationRef(), "games", query );
+//        assertEquals( 0, r.size() );
+//    }
+//
+//
+//    @Test
+//    public void testKeywordsOrQuery() throws Exception {
+//        LOG.info( "testKeywordsOrQuery" );
+//
+//        UUID applicationId = setup.createApplication( "testOrganization", "testKeywordsOrQuery" );
+//        assertNotNull( applicationId );
+//
+//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
+//        assertNotNull( em );
+//
+//        Map<String, Object> properties = new LinkedHashMap<String, Object>();
+//        properties.put( "title", "Galactians 2" );
+//        properties.put( "keywords", "Hot, Space Invaders, Classic" );
+//        em.create( "game", properties );
+//
+//        properties = new LinkedHashMap<String, Object>();
+//        properties.put( "title", "Bunnies Extreme" );
+//        properties.put( "keywords", "Hot, New" );
+//        em.create( "game", properties );
+//
+//        properties = new LinkedHashMap<String, Object>();
+//        properties.put( "title", "Hot Shots" );
+//        properties.put( "keywords", "Action, New" );
+//        em.create( "game", properties );
+//
+//        Query query = Query.fromQL( "select * where keywords contains 'hot' or title contains 'hot'" );
+//        Results r = em.searchCollection( em.getApplicationRef(), "games", query );
+//        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
+//        assertEquals( 3, r.size() );
+//    }
+//
+//
+//    @Test
+//    public void testKeywordsAndQuery() throws Exception {
+//        LOG.info( "testKeywordsOrQuery" );
+//
+//        UUID applicationId = setup.createApplication( "testOrganization", "testKeywordsAndQuery" );
+//        assertNotNull( applicationId );
+//
+//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
+//        assertNotNull( em );
+//
+//        Map<String, Object> properties = new LinkedHashMap<String, Object>();
+//        properties.put( "title", "Galactians 2" );
+//        properties.put( "keywords", "Hot, Space Invaders, Classic" );
+//        Entity firstGame = em.create( "game", properties );
+//
+//        properties = new LinkedHashMap<String, Object>();
+//        properties.put( "title", "Bunnies Extreme" );
+//        properties.put( "keywords", "Hot, New" );
+//        Entity secondGame = em.create( "game", properties );
+//
+//        properties = new LinkedHashMap<String, Object>();
+//        properties.put( "title", "Hot Shots Extreme" );
+//        properties.put( "keywords", "Action, New" );
+//        Entity thirdGame = em.create( "game", properties );
+//
+//        Query query = Query.fromQL( "select * where keywords contains 'new' and title contains 'extreme'" );
+//        Results r = em.searchCollection( em.getApplicationRef(), "games", query );
+//        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
+//        assertEquals( 2, r.size() );
+//
+//        assertEquals( secondGame.getUuid(), r.getEntities().get( 0 ).getUuid() );
+//        assertEquals( thirdGame.getUuid(), r.getEntities().get( 1 ).getUuid() );
+//    }
+//
+//
+//    @Test
+//    public void pagingAfterDelete() throws Exception {
+//
+//        UUID applicationId = setup.createApplication( "testOrganization", "pagingAfterDelete" );
+//        assertNotNull( applicationId );
+//
+//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
+//        assertNotNull( em );
+//
+//        int size = 20;
+//        List<UUID> entityIds = new ArrayList<UUID>();
+//
+//        for ( int i = 0; i < size; i++ ) {
+//            Map<String, Object> properties = new LinkedHashMap<String, Object>();
+//            properties.put( "name", "object" + i );
+//            Entity created = em.create( "objects", properties );
+//
+//            entityIds.add( created.getUuid() );
+//        }
+//
+//        Query query = new Query();
+//        query.setLimit( 50 );
+//
+//        Results r = em.searchCollection( em.getApplicationRef(), "objects", query );
+//
+//        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
+//
+//        assertEquals( size, r.size() );
+//
+//        // check they're all the same before deletion
+//        for ( int i = 0; i < size; i++ ) {
+//            assertEquals( entityIds.get( i ), r.getEntities().get( i ).getUuid() );
+//        }
+//
+//        // now delete 5 items that will span the 10 pages
+//        for ( int i = 5; i < 10; i++ ) {
+//            Entity entity = r.getEntities().get( i );
+//            em.delete( entity );
+//            entityIds.remove( entity.getUuid() );
+//        }
+//
+//        // now query with paging
+//        query = new Query();
+//
+//        r = em.searchCollection( em.getApplicationRef(), "objects", query );
+//
+//        assertEquals( 10, r.size() );
+//
+//        for ( int i = 0; i < 10; i++ ) {
+//            assertEquals( entityIds.get( i ), r.getEntities().get( i ).getUuid() );
+//        }
+//
+//        // try the next page, set our cursor, it should be the last 5 entities
+//        query = new Query();
+//        query.setCursor( r.getCursor() );
+//
+//        r = em.searchCollection( em.getApplicationRef(), "objects", query );
+//
+//        assertEquals( 5, r.size() );
+//        for ( int i = 10; i < 15; i++ ) {
+//            assertEquals( entityIds.get( i ), r.getEntities().get( i - 10 ).getUuid() );
+//        }
+//    }
+//
+//
+//    @Test
+//    public void pagingLessThanWithCriteria() throws Exception {
+//
+//        UUID applicationId = setup.createApplication( "testOrganization", "pagingLessThanWithCriteria" );
+//        assertNotNull( applicationId );
+//
+//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
+//        assertNotNull( em );
+//
+//        int size = 40;
+//        List<UUID> entityIds = new ArrayList<UUID>();
+//
+//        for ( int i = 0; i < size; i++ ) {
+//            Map<String, Object> properties = new LinkedHashMap<String, Object>();
+//            properties.put( "index", i );
+//            Entity created = em.create( "page", properties );
+//
+//            entityIds.add( created.getUuid() );
+//        }
+//
+//        int pageSize = 10;
+//
+//        Query query = new Query();
+//        query.setLimit( pageSize );
+//        query.addFilter( "index < " + size * 2 );
+//
+//        Results r = null;
+//
+//        // check they're all the same before deletion
+//        for ( int i = 0; i < size / pageSize; i++ ) {
+//
+//            r = em.searchCollection( em.getApplicationRef(), "pages", query );
+//
+//            LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
+//
+//            assertEquals( pageSize, r.size() );
+//
+//            for ( int j = 0; j < pageSize; j++ ) {
+//                assertEquals( entityIds.get( i * pageSize + j ), r.getEntities().get( j ).getUuid() );
+//            }
+//
+//            query.setCursor( r.getCursor() );
+//        }
+//
+//        //check our last search
+//        r = em.searchCollection( em.getApplicationRef(), "pages", query );
+//
+//        assertEquals( 0, r.size() );
+//
+//        assertNull( r.getCursor() );
+//    }
+//
+//
+//    @Test
+//    public void pagingGreaterThanWithCriteria() throws Exception {
+//
+//        UUID applicationId = setup.createApplication( "testOrganization", "pagingGreaterThanWithCriteria" );
+//        assertNotNull( applicationId );
+//
+//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
+//        assertNotNull( em );
+//
+//        int size = 40;
+//        List<UUID> entityIds = new ArrayList<UUID>();
+//
+//        for ( int i = 0; i < size; i++ ) {
+//            Map<String, Object> properties = new LinkedHashMap<String, Object>();
+//            properties.put( "index", i );
+//            Entity created = em.create( "page", properties );
+//
+//            entityIds.add( created.getUuid() );
+//        }
+//
+//        int pageSize = 10;
+//
+//        Query query = new Query();
+//        query.setLimit( pageSize );
+//        query.addFilter( "index >= " + size / 2 );
+//
+//        Results r = null;
+//
+//        // check they're all the same before deletion
+//        for ( int i = 2; i < size / pageSize; i++ ) {
+//
+//            r = em.searchCollection( em.getApplicationRef(), "pages", query );
+//
+//            LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
+//
+//            assertEquals( pageSize, r.size() );
+//
+//            for ( int j = 0; j < pageSize; j++ ) {
+//                assertEquals( entityIds.get( i * pageSize + j ), r.getEntities().get( j ).getUuid() );
+//            }
+//
+//            query.setCursor( r.getCursor() );
+//        }
+//
+//        r = em.searchCollection( em.getApplicationRef(), "pages", query );
+//
+//        assertEquals( 0, r.size() );
+//
+//        assertNull( r.getCursor() );
+//    }
+//
+//
+//    @Test
+//    public void pagingWithBoundsCriteria() throws Exception {
+//
+//        UUID applicationId = setup.createApplication( "testOrganization", "pagingWithBoundsCriteria" );
+//        assertNotNull( applicationId );
+//
+//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
+//        assertNotNull( em );
+//
+//        int size = 40;
+//        List<UUID> entityIds = new ArrayList<UUID>();
+//
+//        for ( int i = 0; i < size; i++ ) {
+//            Map<String, Object> properties = new LinkedHashMap<String, Object>();
+//            properties.put( "index", i );
+//            Entity created = em.create( "page", properties );
+//
+//            entityIds.add( created.getUuid() );
+//        }
+//
+//        int pageSize = 10;
+//
+//        Query query = new Query();
+//        query.setLimit( pageSize );
+//        query.addFilter( "index >= 10" );
+//        query.addFilter( "index <= 29" );
+//
+//        Results r = null;
+//
+//        // check they're all the same before deletion
+//        for ( int i = 1; i < 3; i++ ) {
+//
+//            r = em.searchCollection( em.getApplicationRef(), "pages", query );
+//
+//            LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
+//
+//            assertEquals( pageSize, r.size() );
+//
+//            for ( int j = 0; j < pageSize; j++ ) {
+//                assertEquals( entityIds.get( i * pageSize + j ), r.getEntities().get( j ).getUuid() );
+//            }
+//
+//            query.setCursor( r.getCursor() );
+//        }
+//
+//        r = em.searchCollection( em.getApplicationRef(), "pages", query );
+//
+//        assertEquals( 0, r.size() );
+//
+//        assertNull( r.getCursor() );
+//    }
+//
+//
+//    @Test
+//    public void testPagingWithGetNextResults() throws Exception {
+//
+//        UUID applicationId = setup.createApplication( "testOrganization", "pagingWithBoundsCriteria2" );
+//        assertNotNull( applicationId );
+//
+//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
+//        assertNotNull( em );
+//
+//        int size = 40;
+//        List<UUID> entityIds = new ArrayList<UUID>();
+//
+//        for ( int i = 0; i < size; i++ ) {
+//            Map<String, Object> properties = new LinkedHashMap<String, Object>();
+//            properties.put( "index", i );
+//            Entity created = em.create( "page", properties );
+//
+//            entityIds.add( created.getUuid() );
+//        }
+//
+//        int pageSize = 10;
+//
+//        Query query = new Query();
+//        query.setLimit( pageSize );
+//        query.addFilter( "index >= 10" );
+//        query.addFilter( "index <= 29" );
+//
+//        Results r = em.searchCollection( em.getApplicationRef(), "pages", query );
+//
+//        // check they're all the same before deletion
+//        for ( int i = 1; i < 3; i++ ) {
+//
+//            LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
+//
+//            assertEquals( pageSize, r.size() );
+//
+//            for ( int j = 0; j < pageSize; j++ ) {
+//                assertEquals( entityIds.get( i * pageSize + j ), r.getEntities().get( j ).getUuid() );
+//            }
+//
+//            r = r.getNextPageResults();
+//        }
+//
+//        assertEquals( 0, r.size() );
+//        assertNull( r.getCursor() );
+//    }
+//
+//
+//    @Test
+//    public void subpropertyQuerying() throws Exception {
+//        Map<String, Object> root = new HashMap<String, Object>();
+//
+//        Map<String, Object> subEntity = new HashMap<String, Object>();
+//
+//        root.put( "rootprop1", "simpleprop" );
+//
+//        subEntity.put( "intprop", 10 );
+//        subEntity.put( "substring", "I'm a tokenized string that should be indexed" );
+//
+//        root.put( "subentity", subEntity );
+//
+//        UUID applicationId = setup.createApplication( "testOrganization", "subpropertyQuerying" );
+//        assertNotNull( applicationId );
+//
+//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
+//        assertNotNull( em );
+//
+//        Entity saved = em.create( "test", root );
+//
+//        Query query = new Query();
+//        query.addEqualityFilter( "rootprop1", "simpleprop" );
+//
+//        Results results = em.searchCollection( em.getApplicationRef(), "tests", query );
+//
+//        Entity entity = results.getEntitiesMap().get( saved.getUuid() );
+//
+//        assertNotNull( entity );
+//
+//        // query on the nested int value
+//        query = new Query();
+//        query.addEqualityFilter( "subentity.intprop", 10 );
+//
+//        results = em.searchCollection( em.getApplicationRef(), "tests", query );
+//
+//        entity = results.getEntitiesMap().get( saved.getUuid() );
+//
+//        assertNotNull( entity );
+//
+//        // query on the nexted tokenized value
+//        query = new Query();
+//        query.addContainsFilter( "subentity.substring", "tokenized" );
+//        query.addContainsFilter( "subentity.substring", "indexed" );
+//
+//        results = em.searchCollection( em.getApplicationRef(), "tests", query );
+//
+//        entity = results.getEntitiesMap().get( saved.getUuid() );
+//
+//        assertNotNull( entity );
+//    }
+//
+//
+//    @Test
+//    public void arrayQuerying() throws Exception {
+//
+//        Map<String, Object> root = new HashMap<String, Object>();
+//
+//        root.put( "intprop", 10 );
+//        root.put( "array", new String[] { "val1", "val2", "val3 with spaces" } );
+//
+//        Map<String, Object> jsonData = ( Map<String, Object> ) JsonUtils.parse( JsonUtils.mapToJsonString( root ) );
+//
+//        UUID applicationId = setup.createApplication( "testOrganization", "arrayQuerying" );
+//        assertNotNull( applicationId );
+//
+//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
+//        assertNotNull( em );
+//
+//        Entity saved = em.create( "test", jsonData );
+//
+//        Query query = new Query();
+//        query.addEqualityFilter( "intprop", 10 );
+//
+//        Results results = em.searchCollection( em.getApplicationRef(), "tests", query );
+//
+//        Entity entity = results.getEntitiesMap().get( saved.getUuid() );
+//
+//        assertNotNull( entity );
+//
+//        // query on the nested int value
+//        query = new Query();
+//        query.addEqualityFilter( "array", "val1" );
+//
+//        results = em.searchCollection( em.getApplicationRef(), "tests", query );
+//
+//        entity = results.getEntitiesMap().get( saved.getUuid() );
+//
+//        assertNotNull( entity );
+//
+//        // query on the nexted tokenized value
+//        query = new Query();
+//        query.addEqualityFilter( "array", "val2" );
+//
+//        results = em.searchCollection( em.getApplicationRef(), "tests", query );
+//
+//        entity = results.getEntitiesMap().get( saved.getUuid() );
+//
+//        assertNotNull( entity );
+//
+//        query = new Query();
+//        query.addEqualityFilter( "array", "val3" );
+//
+//        results = em.searchCollection( em.getApplicationRef(), "tests", query );
+//
+//        entity = results.getEntitiesMap().get( saved.getUuid() );
+//
+//        assertNull( entity );
+//
+//        query = new Query();
+//        query.addContainsFilter( "array", "spaces" );
+//        results = em.searchCollection( em.getApplicationRef(), "tests", query );
+//
+//        entity = results.getEntitiesMap().get( saved.getUuid() );
+//
+//        assertNotNull( entity );
+//    }
+//
+//
+//    @Test
+//    public void stringWithSpaces() throws Exception {
+//        Map<String, Object> props = new HashMap<String, Object>();
+//
+//        props.put( "myString", "My simple string" );
+//
+//        UUID applicationId = setup.createApplication( "testOrganization", "stringWithSpaces" );
+//        assertNotNull( applicationId );
+//
+//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
+//        assertNotNull( em );
+//
+//        Entity saved = em.create( "test", props );
+//
+//        Query query = new Query();
+//        query.addEqualityFilter( "myString", "My simple string" );
+//
+//        Results results = em.searchCollection( em.getApplicationRef(), "tests", query );
+//
+//        Entity entity = results.getEntitiesMap().get( saved.getUuid() );
+//
+//        assertNotNull( entity );
+//    }
+//
+//
+//    @Test
+//    public void testSelectTerms() throws Exception {
+//
+//        UUID applicationId = setup.createApplication( "testOrganization", "testSelectTerms" );
+//
+//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
+//
+//        Map<String, Object> properties = new LinkedHashMap<String, Object>();
+//        properties.put( "username", "edanuff" );
+//        properties.put( "email", "ed@anuff.com" );
+//
+//        em.create( "user", properties );
+//
+//        String s = "select username, email where username = 'edanuff'";
+//        Query query = Query.fromQL( s );
+//
+//        Results r = em.searchCollection( em.getApplicationRef(), "users", query );
+//        assertTrue( r.size() == 1 );
+//
+//        // selection results should be a list of lists
+//        List<Object> sr = query.getSelectionResults( r );
+//        assertTrue( sr.size() == 1 );
+//
+//        List firstResult = ( List ) sr.get( 0 );
+//        assertTrue( "edanuff".equals( firstResult.get( 0 ) ) );
+//        assertTrue( "ed@anuff.com".equals( firstResult.get( 1 ) ) );
+//    }
+//
+//
+//    @Test
+//    public void testRedefineTerms() throws Exception {
+//
+//        UUID applicationId = setup.createApplication( "testOrganization", "testRedefineTerms" );
+//
+//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
+//
+//        Map<String, Object> properties = new LinkedHashMap<String, Object>();
+//        properties.put( "username", "edanuff" );
+//        properties.put( "email", "ed@anuff.com" );
+//
+//        em.create( "user", properties );
+//
+//        String s = "select {name: username, email: email} where username = 'edanuff'";
+//        Query query = Query.fromQL( s );
+//
+//        Results r = em.searchCollection( em.getApplicationRef(), "users", query );
+//        assertTrue( r.size() == 1 );
+//
+//        // selection results should be a list of lists
+//        List<Object> sr = query.getSelectionResults( r );
+//        assertTrue( sr.size() == 1 );
+//
+//        Map firstResult = ( Map ) sr.get( 0 );
+//        assertTrue( "edanuff".equals( firstResult.get( "name" ) ) );
+//        assertTrue( "ed@anuff.com".equals( firstResult.get( "email" ) ) );
+//    }
+//
+//
+//    @Test
+//    public void testSelectEmailViaConnection() throws Exception {
+//
+//        UUID applicationId = setup.createApplication( "testOrganization", "testSelectEmail" );
+//
+//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
+//
+//        Map<String, Object> properties = new LinkedHashMap<String, Object>();
+//        properties.put( "username", "ed@anuff.com" );
+//        properties.put( "email", "ed@anuff.com" );
+//
+//        em.create( "user", properties );
+//
+//        String s = "select * where username = 'ed@anuff.com'";
+//        Query query = Query.fromQL( s );
+//
+//        Results r = em.searchCollection( em.getApplicationRef(), "users", query );
+//        assertTrue( r.size() == 1 );
+//
+//        // selection results should be a list of lists
+//        Entity entity = r.getEntity();
+//
+//        assertTrue( "ed@anuff.com".equals( entity.getProperty( "username" ) ) );
+//        assertTrue( "ed@anuff.com".equals( entity.getProperty( "email" ) ) );
+//
+//        // now create a role and connect it
+//        properties = new LinkedHashMap<String, Object>();
+//        properties.put( "name", "test" );
+//
+//        Entity foo = em.create( "foo", properties );
+//
+//        em.createConnection( foo, "testconnection", entity );
+//
+//        // now query via the testConnection, this should work
+//
+//        query = Query.fromQL( s );
+//        query.setConnectionType( "testconnection" );
+//        query.setEntityType( "user" );
+//
+//        r = em.searchConnectedEntities( foo, query );
+//
+//        assertEquals( "connection must match", 1, r.size() );
+//
+//        // selection results should be a list of lists
+//        entity = r.getEntity();
+//        assertTrue( "ed@anuff.com".equals( entity.getProperty( "username" ) ) );
+//        assertTrue( "ed@anuff.com".equals( entity.getProperty( "email" ) ) );
+//    }
+//
+//
+//    @Test
+//    public void testNotQueryAnd() throws Exception {
+//
+//        UUID applicationId = setup.createApplication( "testOrganization", "testNotQueryAnd" );
+//
+//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
+//
+//        Map<String, Object> location = new LinkedHashMap<String, Object>();
+//        location.put( "Place", "24 Westminster Avenue, Venice, CA 90291, USA" );
+//        location.put( "Longitude", -118.47425979999998 );
+//        location.put( "Latitude", 33.9887663 );
+//
+//        Map<String, Object> recipient = new LinkedHashMap<String, Object>();
+//        recipient.put( "TimeRequested", 1359077878l );
+//        recipient.put( "Username", "fb_536692245" );
+//        recipient.put( "Location", location );
+//
+//        Map<String, Object> properties = new LinkedHashMap<String, Object>();
+//        properties.put( "Flag", "requested" );
+//        properties.put( "Recipient", recipient );
+//
+//        em.create( "loveobject", properties );
+//
+//        location = new LinkedHashMap<String, Object>();
+//        location.put( "Place", "Via Pietro Maroncelli, 48, 62012 Santa Maria Apparente Province of Macerata, Italy" );
+//        location.put( "Longitude", 13.693080199999999 );
+//        location.put( "Latitude", 43.2985019 );
+//
+//        recipient = new LinkedHashMap<String, Object>();
+//        recipient.put( "TimeRequested", 1359077878l );
+//        recipient.put( "Username", "fb_100000787138041" );
+//        recipient.put( "Location", location );
+//
+//        properties = new LinkedHashMap<String, Object>();
+//        properties.put( "Flag", "requested" );
+//        properties.put( "Recipient", recipient );
+//
+//        em.create( "loveobject", properties );
+//
+//        // String s = "select * where Flag = 'requested'";
+//        // String s =
+//        // "select * where Flag = 'requested' and NOT Recipient.Username = 'fb_536692245' order by created asc";
+//        String s = "select * where Flag = 'requested' and NOT Recipient.Username = 'fb_536692245' order by created asc";
+//        Query query = Query.fromQL( s );
+//
+//        Results r = em.searchCollection( em.getApplicationRef(), "loveobjects", query );
+//        assertTrue( r.size() == 1 );
+//
+//        String username = ( String ) ( ( Map ) r.getEntities().get( 0 ).getProperty( "Recipient" ) ).get( "Username" );
+//        // selection results should be a list of lists
+//        List<Object> sr = query.getSelectionResults( r );
+//        assertTrue( sr.size() == 1 );
+//
+//        assertEquals( "fb_100000787138041", username );
+//    }
+//
+//
+//    @Test
+//    public void runtimeTypeCorrect() throws Exception {
+//
+//        UUID applicationId = setup.createApplication( "testOrganization", "runtimeTypeCorrect" );
+//        assertNotNull( applicationId );
+//
+//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
+//        assertNotNull( em );
+//
+//        int size = 20;
+//        List<User> createdEntities = new ArrayList<User>();
+//
+//        for ( int i = 0; i < size; i++ ) {
+//            User user = new User();
+//            user.setEmail( String.format( "test%d@usergrid.com", i ) );
+//            user.setUsername( String.format( "test%d", i ) );
+//            user.setName( String.format( "test%d", i ) );
+//
+//            User created = em.create( user );
+//
+//            createdEntities.add( created );
+//        }
+//
+//        Results r = em.getCollection( em.getApplicationRef(), "users", null, 50, Level.ALL_PROPERTIES, false );
+//
+//        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
+//
+//        assertEquals( size, r.size() );
+//
+//        // check they're all the same before deletion
+//        for ( int i = 0; i < size; i++ ) {
+//            assertEquals( createdEntities.get( i ).getUuid(), r.getEntities().get( i ).getUuid() );
+//            assertTrue( r.getEntities().get( i ) instanceof User );
+//        }
+//    }
+//
+//
+//    @Test
+//    public void badOrderByBadGrammarAsc() throws Exception {
+//
+//        UUID applicationId = setup.createApplication( "testOrganization", "badOrderByBadGrammarAsc" );
+//        assertNotNull( applicationId );
+//
+//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
+//        assertNotNull( em );
+//
+//        String s = "select * where name = 'bob' order by asc";
+//
+//        String error = null;
+//        String entityType = null;
+//        String propertyName = null;
+//
+//        try {
+//            em.searchCollection( em.getApplicationRef(), "users", Query.fromQL( s ) );
+//            fail( "I should throw an exception" );
+//        }
+//        catch ( NoIndexException nie ) {
+//            error = nie.getMessage();
+//            entityType = nie.getEntityType();
+//            propertyName = nie.getPropertyName();
+//        }
+//
+//        assertEquals( "Entity 'user' with property named '' is not indexed.  You cannot use the this field in queries.",
+//                error );
+//        assertEquals( "user", entityType );
+//        assertEquals( "", propertyName );
+//    }
+//
+//
+//    @Test
+//    public void badOrderByBadGrammarDesc() throws Exception {
+//        UUID applicationId = setup.createApplication( "testOrganization", "badOrderByBadGrammarDesc" );
+//        assertNotNull( applicationId );
+//
+//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
+//        assertNotNull( em );
+//
+//        String s = "select * where name = 'bob' order by desc";
+//
+//        String error = null;
+//        String entityType = null;
+//        String propertyName = null;
+//
+//
+//        try {
+//            em.searchCollection( em.getApplicationRef(), "users", Query.fromQL( s ) );
+//            fail( "I should throw an exception" );
+//        }
+//        catch ( NoIndexException nie ) {
+//            error = nie.getMessage();
+//            entityType = nie.getEntityType();
+//            propertyName = nie.getPropertyName();
+//        }
+//
+//        assertEquals( "Entity 'user' with property named '' is not indexed.  You cannot use the this field in queries.",
+//                error );
+//        assertEquals( "user", entityType );
+//        assertEquals( "", propertyName );
+//    }
+//
+//
+//    @Test
+//    public void uuidIdentifierTest() throws Exception {
+//        UUID applicationId = setup.createApplication( "testOrganization", "uuidIdentifierTest" );
+//        assertNotNull( applicationId );
+//
+//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
+//        assertNotNull( em );
+//
+//        Map<String, Object> properties = new LinkedHashMap<String, Object>();
+//        properties.put( "keywords", "blah,test,game" );
+//        properties.put( "title", "Solitaire" );
+//
+//        Entity game1 = em.create( "game", properties );
+//        assertNotNull( game1 );
+//
+//        //we create 2 entities, otherwise this test will pass when it shouldn't
+//        Entity game2 = em.create( "game", properties );
+//        assertNotNull( game2 );
+//
+//
+//        // overlap
+//        Query query = new Query();
+//        query.addIdentifier( Identifier.fromUUID( game1.getUuid() ) );
+//        Results r = em.searchCollection( em.getApplicationRef(), "games", query );
+//        assertEquals( "We should only get 1 result", 1, r.size() );
+//        assertNull( "No cursor should be present", r.getCursor() );
+//
+//        assertEquals( "Saved entity returned", game1, r.getEntity() );
+//    }
+//
+//
+//    @Test
+//    public void nameIdentifierTest() throws Exception {
+//        UUID applicationId = setup.createApplication( "testOrganization", "nameIdentifierTest" );
+//        assertNotNull( applicationId );
+//
+//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
+//        assertNotNull( em );
+//
+//        Map<String, Object> properties = new LinkedHashMap<String, Object>();
+//        properties.put( "keywords", "blah,test,game" );
+//        properties.put( "title", "Solitaire" );
+//        properties.put( "name", "test" );
+//
+//        Entity game1 = em.create( "games", properties );
+//        assertNotNull( game1 );
+//
+//        //we create 2 entities, otherwise this test will pass when it shouldn't
+//        properties.put( "name", "test2" );
+//        Entity game2 = em.create( "game", properties );
+//        assertNotNull( game2 );
+//
+//        // overlap
+//        Query query = new Query();
+//        query.addIdentifier( Identifier.fromName( "test" ) );
+//        Results r = em.searchCollection( em.getApplicationRef(), "games", query );
+//        assertEquals( "We should only get 1 result", 1, r.size() );
+//        assertNull( "No cursor should be present", r.getCursor() );
+//
+//        assertEquals( "Saved entity returned", game1, r.getEntity() );
+//    }
+//
+//
+//    @Test
+//    public void emailIdentifierTest() throws Exception {
+//        UUID applicationId = setup.createApplication( "testOrganization", "emailIdentifierTest" );
+//        assertNotNull( applicationId );
+//
+//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
+//        assertNotNull( em );
+//
+//        User user = new User();
+//        user.setUsername( "foobar" );
+//        user.setEmail( "foobar@usergrid.org" );
+//
+//        Entity createUser = em.create( user );
+//        assertNotNull( createUser );
+//
+//        //we create 2 entities, otherwise this test will pass when it shouldn't
+//        User user2 = new User();
+//        user2.setUsername( "foobar2" );
+//        user2.setEmail( "foobar2@usergrid.org" );
+//        Entity createUser2 = em.create( user2 );
+//        assertNotNull( createUser2 );
+//
+//        // overlap
+//        Query query = new Query();
+//        query.addIdentifier( Identifier.fromEmail( "foobar@usergrid.org" ) );
+//        Results r = em.searchCollection( em.getApplicationRef(), "users", query );
+//        assertEquals( "We should only get 1 result", 1, r.size() );
+//        assertNull( "No cursor should be present", r.getCursor() );
+//
+//        assertEquals( "Saved entity returned", createUser, r.getEntity() );
+//    }
+//
+//
+//    @Test(expected = DuplicateUniquePropertyExistsException.class)
+//    public void duplicateIdentifierTest() throws Exception {
+//        UUID applicationId = setup.createApplication( "testOrganization", "duplicateIdentifierTest" );
+//        assertNotNull( applicationId );
+//
+//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
+//        assertNotNull( em );
+//
+//        User user = new User();
+//        user.setUsername( "foobar" );
+//        user.setEmail( "foobar@usergrid.org" );
+//
+//        Entity createUser = em.create( user );
+//        assertNotNull( createUser );
+//
+//        //we create 2 entities, otherwise this test will pass when it shouldn't
+//        User user2 = new User();
+//        user2.setUsername( "foobar" );
+//        user2.setEmail( "foobar@usergrid.org" );
+//        em.create( user2 );
+//    }
+//
+//
+//    @Test(expected = DuplicateUniquePropertyExistsException.class)
+//    public void duplicateNameTest() throws Exception {
+//        UUID applicationId = setup.createApplication( "testOrganization", "duplicateNameTest" );
+//        assertNotNull( applicationId );
+//
+//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
+//        assertNotNull( em );
+//
+//        DynamicEntity restaurant = new DynamicEntity();
+//        restaurant.setName( "4peaks" );
+//
+//        Entity createdRestaurant = em.create( "restaurant", restaurant.getProperties() );
+//        assertNotNull( createdRestaurant );
+//
+//
+//        //we create 2 entities, otherwise this test will pass when it shouldn't
+//        DynamicEntity restaurant2 = new DynamicEntity();
+//        restaurant2.setName( "4peaks" );
+//
+//        em.create( "restaurant", restaurant2.getProperties() );
+//    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5eaf05ac/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/ElasticSearchTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/ElasticSearchTest.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/ElasticSearchTest.java
index dfb6b91..f5d294a 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/ElasticSearchTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/ElasticSearchTest.java
@@ -27,7 +27,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import org.apache.commons.lang3.RandomStringUtils;
-import org.apache.usergrid.persistence.utils.ElasticSearchRule;
+import org.apache.usergrid.persistence.index.utils.ElasticSearchRule;
 import org.elasticsearch.ElasticsearchException;
 import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
 import org.elasticsearch.action.get.GetResponse;
@@ -52,7 +52,7 @@ import org.slf4j.LoggerFactory;
  * Elastic search experiments in the form of a test.
  */
 public class ElasticSearchTest {
-    private static final Logger logger = LoggerFactory.getLogger( ElasticSearchTest.class );
+    private static final Logger log = LoggerFactory.getLogger( ElasticSearchTest.class );
 
     @Rule
     public ElasticSearchRule elasticSearchRule = new ElasticSearchRule();
@@ -211,7 +211,7 @@ public class ElasticSearchTest {
 
                 }
             } catch ( Exception e ) {
-                logger.error( "Error processing {} : {}", key, value, e );
+                log.error( "Error processing {} : {}", key, value, e );
                 throw new RuntimeException(e);
             }
         }
@@ -258,11 +258,11 @@ public class ElasticSearchTest {
     }
 
     void log( GetResponse getResponse ) {
-        logger.info( "-------------------------------------------------------------------------" );
-        logger.info( "id:      " + getResponse.getId() );
-        logger.info( "type:    " + getResponse.getType() );
-        logger.info( "version: " + getResponse.getVersion() );
-        logger.info( "index:   " + getResponse.getIndex() );
-        logger.info( "source:  " + getResponse.getSourceAsString() );
+        log.info( "-------------------------------------------------------------------------" );
+        log.info( "id:      " + getResponse.getId() );
+        log.info( "type:    " + getResponse.getType() );
+        log.info( "version: " + getResponse.getVersion() );
+        log.info( "index:   " + getResponse.getIndex() );
+        log.info( "source:  " + getResponse.getSourceAsString() );
     }
 }


[2/5] Re-organize test packages.

Posted by sn...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5eaf05ac/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexTest.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexTest.java
index 8db4204..90010fb 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexTest.java
@@ -35,14 +35,14 @@ import org.apache.usergrid.persistence.collection.impl.CollectionScopeImpl;
 import org.apache.usergrid.persistence.collection.util.EntityUtils;
 import org.apache.usergrid.persistence.index.EntityCollectionIndex;
 import org.apache.usergrid.persistence.index.EntityCollectionIndexFactory;
-import org.apache.usergrid.persistence.index.guice.IndexTestModule;
+import org.apache.usergrid.persistence.index.guice.TestIndexModule;
 import org.apache.usergrid.persistence.model.entity.Entity;
 import org.apache.usergrid.persistence.model.entity.Id;
 import org.apache.usergrid.persistence.model.entity.SimpleId;
 import org.apache.usergrid.persistence.model.util.UUIDGenerator;
 import org.apache.usergrid.persistence.query.Query;
 import org.apache.usergrid.persistence.query.Results;
-import org.apache.usergrid.test.EntityBuilder;
+import org.apache.usergrid.persistence.index.legacy.EntityBuilder;
 import org.jukito.JukitoRunner;
 import org.jukito.UseModules;
 import static org.junit.Assert.assertEquals;
@@ -58,10 +58,10 @@ import org.slf4j.LoggerFactory;
 
 
 @RunWith(JukitoRunner.class)
-@UseModules({ IndexTestModule.class })
+@UseModules({ TestIndexModule.class })
 public class EntityCollectionIndexTest {
 
-    private static final Logger logger = LoggerFactory.getLogger( EntityCollectionIndexTest.class );
+    private static final Logger log = LoggerFactory.getLogger( EntityCollectionIndexTest.class );
     
     @ClassRule
     public static CassandraRule cass = new CassandraRule();
@@ -102,14 +102,14 @@ public class EntityCollectionIndexTest {
             entity = EntityBuilder.fromMap( scope.getName(), entity, item );
             EntityUtils.setVersion( entity, UUIDGenerator.newTimeUUID() );
 
-           entity = entityManager.write( entity ).toBlockingObservable().last();
+            entity = entityManager.write( entity ).toBlockingObservable().last();
 
             entityIndex.index( entity );
 
             count++;
         }
         timer.stop();
-        logger.info( "Total time to index {} entries {}ms, average {}ms/entry", 
+        log.info( "Total time to index {} entries {}ms, average {}ms/entry", 
             count, timer.getTime(), timer.getTime() / count );
 
         testQueries( entityIndex );
@@ -130,7 +130,7 @@ public class EntityCollectionIndexTest {
         } else {
             assertEquals( num, results.getEntities().size() );
         }
-        logger.debug( "Query time {}ms", timer.getTime() );
+        log.debug( "Query time {}ms", timer.getTime() );
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5eaf05ac/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/GeoIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/GeoIT.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/GeoIT.java
new file mode 100644
index 0000000..af1e18c
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/GeoIT.java
@@ -0,0 +1,550 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.impl;
+
+import com.google.inject.Inject;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
+import org.apache.usergrid.persistence.collection.cassandra.CassandraRule;
+import org.apache.usergrid.persistence.collection.guice.MigrationManagerRule;
+import org.apache.usergrid.persistence.index.EntityCollectionIndexFactory;
+import org.apache.usergrid.persistence.index.guice.TestIndexModule;
+import org.apache.usergrid.persistence.index.legacy.CoreApplication;
+import org.apache.usergrid.persistence.index.legacy.CoreITSetup;
+import org.apache.usergrid.persistence.index.legacy.CoreITSetupImpl;
+import org.apache.usergrid.persistence.index.legacy.EntityManagerFacade;
+import org.apache.usergrid.persistence.index.legacy.Point;
+import org.apache.usergrid.persistence.model.entity.Entity;
+import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.model.entity.SimpleId;
+import org.apache.usergrid.persistence.query.EntityRef;
+import org.apache.usergrid.persistence.query.Query;
+import org.apache.usergrid.persistence.query.Results;
+import org.apache.usergrid.persistence.query.SimpleEntityRef;
+import org.apache.usergrid.persistence.utils.MapUtils;
+import org.jukito.JukitoRunner;
+import org.jukito.UseModules;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+@RunWith(JukitoRunner.class)
+@UseModules({ TestIndexModule.class })
+public class GeoIT {
+    private static final Logger LOG = LoggerFactory.getLogger( GeoIT.class );
+
+    @ClassRule
+    public static CassandraRule cass = new CassandraRule();
+
+    @Inject
+    @Rule
+    public MigrationManagerRule migrationManagerRule;
+    
+    @ClassRule
+    public static CoreITSetup setup = new CoreITSetupImpl();
+
+    @Rule
+    public CoreApplication app = new CoreApplication( setup );
+
+    @Inject
+    public EntityCollectionManagerFactory collectionManagerFactory;
+    
+    @Inject
+    public EntityCollectionIndexFactory collectionIndexFactory;
+
+    public GeoIT() {
+        super();
+    }
+
+
+    @Test
+    public void testGeo() throws Exception {
+        LOG.info( "GeoIT.testGeo" );
+
+        Id appId = new SimpleId("testGeo");
+        Id orgId = new SimpleId("testOrganization");
+        EntityManagerFacade em = new EntityManagerFacade( orgId, appId, 
+            collectionManagerFactory, collectionIndexFactory );
+        assertNotNull( em );
+
+		// Two intersections two blocks apart
+        final Point folsomAnd7th =    new Point( 37.774277, -122.404744 );
+        final Point folsomAndBryant = new Point( 37.776753, -122.407846 );
+
+		// and about 50 kilometers away...
+		// 260 Sheridan Ave, Palo Alto, CA
+	 	final Point paloalto = new Point( 37.426373, -122.14108 ); 
+
+        Map<String, Object> properties = new LinkedHashMap<String, Object>() {{
+            put( "username", "edanuff" );
+            put( "email", "ed@anuff.com" );
+            put( "location", new HashMap<String, Object>() {{
+                put("latitude", folsomAndBryant.getLat() );
+                put("longitude", folsomAndBryant.getLon() );
+            }});
+        }};
+	
+        Entity user = em.create( "user", properties );
+        assertNotNull( user );
+		LOG.info( user.toString() );
+
+		// Folsom and 7th more than 100 meters from Folson and Bryant
+		Query q = Query.fromQL("location within 100 of " 
+			+ folsomAnd7th.getLat() + "," + folsomAnd7th.getLon() + " limit 100");
+		Results results = em.searchCollection(null, "users", q);
+        assertEquals( 0, results.size() );
+
+		// but within 400 meters
+		q = Query.fromQL("location within 400 of " 
+			+ folsomAnd7th.getLat() + "," + folsomAnd7th.getLon() + " limit 100");
+		results = em.searchCollection(null, "users", q);
+        assertEquals( 1, results.size() );
+
+		// move user to Palo Alto, 50km away 
+        updatePos( em, new SimpleEntityRef( user.getId(), user.getVersion() ), 
+			paloalto.getLat(), paloalto.getLon() );
+
+		// user no longer within 200m of that San Francico intersection  
+		q = Query.fromQL("location within 200 of " + folsomAndBryant.getLat() 
+				+ "," + folsomAndBryant.getLon() + " limit 100");
+		results = em.searchCollection(null, "users", q);
+        assertEquals( 0, results.size() );
+
+		// move user to the other SF intersection
+        updatePos( em, user, folsomAnd7th.getLat(), folsomAnd7th.getLon() );
+
+		// now they are close to Folsom and Bryant
+		q = Query.fromQL("location within 1000 of " 
+				+ folsomAndBryant.getLat() + "," + folsomAndBryant.getLon() + " limit 100");
+		results = em.searchCollection(null, "users", q);
+        assertEquals( 1, results.size() );
+
+        // check at globally large distance
+		q = Query.fromQL("location within " + Integer.MAX_VALUE + " of " 
+				+ folsomAndBryant.getLat() + "," + folsomAndBryant.getLon() + " limit 100");
+		results = em.searchCollection(null, "users", q);
+        assertEquals( 1, results.size() );
+
+        // create a new entity so we have 2
+        LinkedHashMap<String, Object> properties2 = new LinkedHashMap<String, Object>() {{
+        	put( "username", "sganyo" );
+        	put( "email", "sganyo@anuff.com" );
+			put( "location", new HashMap<String, Object>() {{
+				put( "latitude", 31.1 ); // 31.1, 121.2 is shanghai
+				put( "longitude", 121.2 ); 
+			}});
+		}};
+        Entity user2 = em.create( "user", properties2 );
+        assertNotNull( user2 );
+        
+		q = Query.fromQL("location within 10000 of " 
+				+ folsomAndBryant.getLat() + "," + folsomAndBryant.getLon() + " limit 100");
+		results = em.searchCollection(null, "users", q);
+
+        assertEquals( 1, results.size() );
+
+        // check at globally large distance
+		q = Query.fromQL("location within " + Integer.MAX_VALUE + " of " 
+				+ folsomAndBryant.getLat() + "," + folsomAndBryant.getLon() + " limit 100");
+		results = em.searchCollection(null, "users", q);
+		
+        assertEquals( 2, results.size() );
+
+        // check at globally large distance (center point close to other entity)
+        Point shanghai = new Point( 31.14, 121.27 );
+
+		q = Query.fromQL("location within " + Integer.MAX_VALUE + " of " 
+				+ shanghai.getLat() + "," + shanghai.getLon() + " limit 100");
+		results = em.searchCollection(null, "users", q);
+
+        assertEquals( 2, results.size() );
+
+        Results emSearchResults = em.searchCollection( em.getApplicationRef(), "users",
+            Query.fromQL( "location within 1000 of 37.776753, -122.407846" ) );
+
+        assertEquals( 1, emSearchResults.size() );
+
+        updatePos( em, user, folsomAndBryant.getLat(), folsomAndBryant.getLon());
+
+        Point paloaltoCaltran = new Point( 37.428526, -122.140916 );
+
+		q = Query.fromQL("location within 1000 of " 
+				+ paloaltoCaltran.getLat() + "," + paloaltoCaltran.getLon() + " limit 100");
+		results = em.searchCollection(null, "users", q);
+
+        assertEquals( 0, results.size() );
+
+        emSearchResults = em.searchCollection( em.getApplicationRef(), "users",
+                Query.fromQL( "location within 1000 of 37.428526, -122.140916" ) );
+        assertEquals( 0, emSearchResults.size() );
+
+        properties = new LinkedHashMap<String, Object>();
+        properties.put( "name", "Brickhouse" );
+        properties.put( "address", "426 Brannan Street" );
+        properties.put( "location", getLocation( 37.779632, -122.395131 ) );
+
+        Entity restaurant = em.create( "restaurant", properties );
+        assertNotNull( restaurant );
+
+		// TODO: update with new Core Persistence graph API
+
+//        em.createConnection( user, "likes", restaurant );
+//
+//        emSearchResults =
+//                em.searchConnectedEntities( user, Query.fromQL( "location within 2000 of 37.776753, -122.407846" ) );
+//        assertEquals( 1, emSearchResults.size() );
+//
+//        emSearchResults =
+//                em.searchConnectedEntities( user, Query.fromQL( "location within 1000 of 37.776753, -122.407846" ) );
+//        assertEquals( 0, emSearchResults.size() );
+    }
+
+
+    @Test
+    public void testPointPaging() throws Exception {
+
+        Id appId = new SimpleId("testGeo");
+        Id orgId = new SimpleId("testOrganization");
+        EntityManagerFacade em = new EntityManagerFacade( orgId, appId, 
+            collectionManagerFactory, collectionIndexFactory );
+        assertNotNull( em );
+
+        // save objects in a diagonal line from -90 -180 to 90 180
+
+        int numEntities = 50;
+
+        float minLattitude = -90;
+        float maxLattitude = 90;
+        float minLongitude = -180;
+        float maxLongitude = 180;
+
+        float lattitudeDelta = ( maxLattitude - minLattitude ) / numEntities;
+
+        float longitudeDelta = ( maxLongitude - minLongitude ) / numEntities;
+
+        for ( int i = 0; i < numEntities; i++ ) {
+            float lattitude = minLattitude + lattitudeDelta * i;
+            float longitude = minLongitude + longitudeDelta * i;
+
+            Map<String, Float> location = MapUtils.hashMap( 
+                    "latitude", lattitude ).map( "longitude", longitude );
+
+            Map<String, Object> data = new HashMap<String, Object>( 2 );
+            data.put( "name", String.valueOf( i ) );
+            data.put( "location", location );
+
+            em.create( "store", data );
+        }
+
+        // earth's circumference is 40075km; up it to 50000km, to be safe
+        Query query = new Query();
+        query.addFilter( "location within 50000000 of -90, -180" );
+        query.setLimit( 100 );
+
+        int count = 0;
+        Results results;
+
+        do {
+            results = em.searchCollection( em.getApplicationRef(), "stores", query );
+
+            for ( Entity entity : results.getEntities() ) {
+                count++;
+            }
+
+            // set for the next "page"
+            query.setCursor( results.getCursor() );
+        }
+        while ( results.getCursor() != null );
+
+        // check we got back all 500 entities
+        assertEquals( numEntities, count );
+    }
+
+
+//    @Test
+//    public void testSamePointPaging() throws Exception {
+//
+//        Id appId = new SimpleId("testGeo");
+//        Id orgId = new SimpleId("testOrganization");
+//        EntityManagerFacade em = new EntityManagerFacade( orgId, appId, 
+//            collectionManagerFactory, collectionIndexFactory );
+//        assertNotNull( em );
+//
+//        // save objects in a diagonal line from -90 -180 to 90 180
+//
+//        int numEntities = 10;
+//
+//        for ( int i = 0; i < numEntities; i++ ) {
+//            Map<String, Object> data = new HashMap<String, Object>( 2 );
+//            data.put( "name", String.valueOf( i ) );
+//            setPos( data, 0, 0 );
+//
+//            em.create( "store", data );
+//        }
+//
+//        Query query = new Query();
+//        // earth's circumference is 40,075 kilometers. Up it to 50,000kilometers
+//        // just to be save
+//        query.addFilter( "location within 50000000 of 0, 0" );
+//        query.setLimit( 10 );
+//
+//        int count = 0;
+//        Results results;
+//
+//        do {
+//            results = em.searchCollection( em.getApplicationRef(), "stores", query );
+//
+//            for ( Entity entity : results.getEntities() ) {
+//                count++;
+//            }
+//
+//            // set for the next "page"
+//            query.setCursor( results.getCursor() );
+//        }
+//        while ( results.getCursor() != null );
+//
+//        // check we got back all 500 entities
+//        assertEquals( numEntities, count );
+//    }
+
+
+    @Test
+    public void testDistanceByLimit() throws Exception {
+
+        Id appId = new SimpleId("testGeo");
+        Id orgId = new SimpleId("testOrganization");
+        EntityManagerFacade em = new EntityManagerFacade( orgId, appId, 
+            collectionManagerFactory, collectionIndexFactory );
+        assertNotNull( em );
+
+        // save objects in a diagonal line from -90 -180 to 90 180
+        int numEntities = 10;
+
+        float minLattitude = -90;
+        float maxLattitude = 90;
+        float minLongitude = -180;
+        float maxLongitude = 180;
+
+        float lattitudeDelta = ( maxLattitude - minLattitude ) / numEntities;
+        float longitudeDelta = ( maxLongitude - minLongitude ) / numEntities;
+
+        for ( int i = 0; i < numEntities; i++ ) {
+            final float latitude = minLattitude + lattitudeDelta * i;
+            final float longitude = minLongitude + longitudeDelta * i;
+
+            Map<String, Object> location = new HashMap<String, Object>() {{
+                put("latitude", latitude);
+                put("longitude", longitude);
+            }}; 
+
+            Map<String, Object> data = new HashMap<String, Object>( 2 );
+            data.put( "name", String.valueOf( i ) );
+            data.put( "location", location );
+
+            em.create( "store", data );
+        }
+
+        // earth's circumference is 40075km; up it to 50,000km, just to be safe.
+        Query query = new Query();
+        query.addFilter( "location within " + (50000 * 1000) + " of -90, -180" );
+        query.setLimit( 100 );
+
+        int count = 0;
+        do {
+            Results results = em.searchCollection( em.getApplicationRef(), "stores", query );
+            for ( Entity entity : results.getEntities() ) {
+                count++;
+            }
+        }
+        while ( query.getCursor() != null );
+
+        // check we got back all entities
+        assertEquals( numEntities, count );
+    }
+
+
+//    @Test
+//    public void testGeoWithIntersection() throws Exception {
+//
+//        Id appId = new SimpleId("testGeo");
+//        Id orgId = new SimpleId("testOrganization");
+//        EntityManagerFacade em = new EntityManagerFacade( orgId, appId, 
+//            collectionManagerFactory, collectionIndexFactory );
+//        assertNotNull( em );
+//
+//        int size = 10;
+//        int min = 50;
+//        int max = 90;
+//
+//        List<Entity> created = new ArrayList<Entity>( size );
+//
+//        for ( int i = 0; i < size; i++ ) {
+//
+//            // save all entities in the same location
+//            Map<String, Object> data = new HashMap<String, Object>( 2 );
+//            data.put( "name", String.valueOf( i ) );
+//            data.put( "index", i );
+//            setPos( data, 0, 0 );
+//
+//            Entity e = em.create( "store", data );
+//
+//            created.add( e );
+//        }
+//
+//        int startDelta = size - min;
+//
+//        //    String queryString = String.format("select * where location within 100 of 0,
+//        // 0 and index >= %d and index < %d order by index",min, max);
+//
+//        String queryString = String.format( 
+//                "select * where index >= %d and index < %d order by index", min, max );
+//
+//        Query query = Query.fromQL( queryString );
+//
+//        Results r;
+//        int count = 0;
+//
+//        do {
+//
+//            r = em.searchCollection( em.getApplicationRef(), "stores", query );
+//
+//            for ( Entity e : r.getEntities() ) {
+//                assertEquals( created.get( startDelta + count ), e );
+//                count++;
+//            }
+//
+//            query.setCursor( r.getCursor() );
+//        }
+//        while ( r.hasCursor() );
+//
+//        assertEquals( startDelta - ( size - max ), count );
+//    }
+//
+//
+//    @Test
+//    public void testDenseSearch() throws Exception {
+//
+//        Id appId = new SimpleId("testGeo");
+//        Id orgId = new SimpleId("testOrganization");
+//        EntityManagerFacade em = new EntityManagerFacade( orgId, appId, 
+//            collectionManagerFactory, collectionIndexFactory );
+//        assertNotNull( em );
+//
+//        // save objects in a diagonal line from -90 -180 to 90 180
+//
+//        int numEntities = 500;
+//
+//        float minLattitude = 48.32455f;
+//        float maxLattitude = 48.46481f;
+//        float minLongitude = 9.89561f;
+//        float maxLongitude = 10.0471f;
+//
+//        float lattitudeDelta = ( maxLattitude - minLattitude ) / numEntities;
+//
+//        float longitudeDelta = ( maxLongitude - minLongitude ) / numEntities;
+//
+//        for ( int i = 0; i < numEntities; i++ ) {
+//            float lattitude = minLattitude + lattitudeDelta * i;
+//            float longitude = minLongitude + longitudeDelta * i;
+//
+//            Map<String, Float> location = MapUtils.hashMap( "latitude", lattitude ).map( "longitude", longitude );
+//
+//            Map<String, Object> data = new HashMap<String, Object>( 2 );
+//            data.put( "name", String.valueOf( i ) );
+//            data.put( "location", location );
+//
+//            em.create( "store", data );
+//        }
+//
+//        //do a direct geo iterator test.  We need to make sure that we short circuit on the correct tile.
+//
+//        float lattitude = 48.38626f;
+//        float longtitude = 9.94175f;
+//        int distance = 1000;
+//        int limit = 8;
+//
+//
+//        QuerySlice slice = new QuerySlice( "location", 0 );
+//
+//        GeoIterator itr = new GeoIterator(
+//                new CollectionGeoSearch( em, setup.getIbl(), setup.getCassSvc(), em.getApplicationRef(), "stores" ),
+//                limit, slice, "location", new Point( lattitude, longtitude ), distance );
+//
+//
+//        // check we got back all 500 entities
+//        assertFalse( itr.hasNext() );
+//
+//        List<String> cells = itr.getLastCellsSearched();
+//
+//        assertEquals( 1, cells.size() );
+//
+//        assertEquals( 4, cells.get( 0 ).length() );
+//
+//
+//        long startTime = System.currentTimeMillis();
+//
+//        //now test at the EM level, there should be 0 results.
+//        Query query = new Query();
+//
+//        query.addFilter( "location within 1000 of 48.38626, 9.94175" );
+//        query.setLimit( 8 );
+//
+//
+//        Results results = em.searchCollection( em.getApplicationRef(), "stores", query );
+//
+//        assertEquals( 0, results.size() );
+//
+//        long endTime = System.currentTimeMillis();
+//
+//        LOG.info( "Runtime took {} milliseconds to search", endTime - startTime );
+//    }
+
+
+    public Map<String, Object> getLocation( double latitude, double longitude ) throws Exception {
+        Map<String, Object> latlong = new LinkedHashMap<String, Object>();
+        latlong.put( "latitude", latitude );
+        latlong.put( "longitude", longitude );
+        return latlong;
+    }
+
+
+    public void updatePos( EntityManagerFacade em, EntityRef ref, double lat, double lon) throws Exception {
+        em.setProperty( ref, "location", lat, lon );
+	}
+
+    public void updatePos( EntityManagerFacade em, Entity e, double lat, double lon) throws Exception {
+        em.setProperty( new SimpleEntityRef( e.getId(), e.getVersion()), "location", lat, lon );
+    }
+
+
+    public void setPos( Map<String, Object> data, double latitude, double longitude ) {
+        Map<String, Object> latlong = new LinkedHashMap<String, Object>();
+        latlong.put( "latitude", latitude );
+        latlong.put( "longitude", longitude );
+        data.put( "location", latlong );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5eaf05ac/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/IndexIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/IndexIT.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/IndexIT.java
new file mode 100644
index 0000000..cea12bb
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/IndexIT.java
@@ -0,0 +1,484 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.impl;
+
+import com.google.inject.Inject;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
+import org.apache.usergrid.persistence.collection.cassandra.CassandraRule;
+import org.apache.usergrid.persistence.collection.guice.MigrationManagerRule;
+import org.apache.usergrid.persistence.index.EntityCollectionIndexFactory;
+import org.apache.usergrid.persistence.index.guice.TestIndexModule;
+import org.apache.usergrid.persistence.index.legacy.CoreApplication;
+import org.apache.usergrid.persistence.index.legacy.CoreITSetup;
+import org.apache.usergrid.persistence.index.legacy.CoreITSetupImpl;
+import org.apache.usergrid.persistence.index.legacy.EntityManagerFacade;
+import org.apache.usergrid.persistence.model.entity.Entity;
+import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.model.entity.SimpleId;
+import org.apache.usergrid.persistence.query.Query;
+import org.apache.usergrid.persistence.query.Results;
+import org.apache.usergrid.persistence.utils.JsonUtils;
+import org.jukito.JukitoRunner;
+import org.jukito.UseModules;
+import static org.junit.Assert.assertEquals;
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+@RunWith(JukitoRunner.class)
+@UseModules({ TestIndexModule.class })
+public class IndexIT {
+    
+    private static final Logger LOG = LoggerFactory.getLogger( IndexIT.class );
+
+    @ClassRule
+    public static CassandraRule cass = new CassandraRule();
+
+    @Inject
+    @Rule
+    public MigrationManagerRule migrationManagerRule;
+    
+    @ClassRule
+    public static CoreITSetup setup = new CoreITSetupImpl();
+
+    @Rule
+    public CoreApplication app = new CoreApplication( setup );
+
+    @Inject
+    public EntityCollectionManagerFactory collectionManagerFactory;
+    
+    @Inject
+    public EntityCollectionIndexFactory collectionIndexFactory;
+
+    public static final String[] alphabet = {
+            "Alpha", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot", "Golf", "Hotel", "India", "Juliet", "Kilo", "Lima",
+            "Mike", "November", "Oscar", "Papa", "Quebec", "Romeo", "Sierra", "Tango", "Uniform", "Victor", "Whiskey",
+            "X-ray", "Yankee", "Zulu"
+    };
+
+    @Ignore // TODO: enable when Cursor support implemented
+    @Test
+    public void testCollectionOrdering() throws Exception {
+        LOG.info( "testCollectionOrdering" );
+
+        Id appId = new SimpleId("application");
+        Id orgId = new SimpleId("organization");
+        EntityManagerFacade em = new EntityManagerFacade( orgId, appId, 
+            collectionManagerFactory, collectionIndexFactory );
+
+        for ( int i = alphabet.length - 1; i >= 0; i-- ) {
+            String name = alphabet[i];
+            Map<String, Object> properties = new LinkedHashMap<String, Object>();
+            properties.put( "name", name );
+
+            em.create( "items", properties );
+        }
+
+        int i = 0;
+        
+        Query query = Query.fromQL( "order by name" );
+        Results r = em.searchCollection( em.getApplicationRef(), "items", query );
+        for ( Entity entity : r.getEntities() ) {
+            assertEquals( alphabet[i], entity.getField( "name" ).getValue() );
+            i++;
+        }
+
+        query = Query.fromQL( "order by name" ).withCursor( r.getCursor() );
+        r = em.searchCollection( em.getApplicationRef(), "items", query );
+        for ( Entity entity : r.getEntities() ) {
+            assertEquals( alphabet[i], entity.getField( "name" ).getValue() );
+            i++;
+        }
+
+        query = Query.fromQL( "order by name" ).withCursor( r.getCursor() );
+        r = em.searchCollection( em.getApplicationRef(), "items", query );
+        for ( Entity entity : r.getEntities() ) {
+            assertEquals( alphabet[i], entity.getField( "name" ).getValue() );
+            i++;
+        }
+
+        assertEquals( alphabet.length, i );
+
+        i = alphabet.length;
+
+        query = Query.fromQL( "order by name desc" );
+        r = em.searchCollection( em.getApplicationRef(), "items", query );
+        for ( Entity entity : r.getEntities() ) {
+            i--;
+            assertEquals( alphabet[i], entity.getField( "name" ).getValue() );
+        }
+
+        query = Query.fromQL( "order by name desc" ).withCursor( r.getCursor() );
+        r = em.searchCollection( em.getApplicationRef(), "items", query );
+        // LOG.info(JsonUtils.mapToFormattedJsonString(r.getEntities()));
+        for ( Entity entity : r.getEntities() ) {
+            i--;
+            assertEquals( alphabet[i], entity.getField( "name" ).getValue() );
+        }
+
+        query = Query.fromQL( "order by name desc" ).withCursor( r.getCursor() );
+        r = em.searchCollection( em.getApplicationRef(), "items", query );
+        for ( Entity entity : r.getEntities() ) {
+            i--;
+            assertEquals( alphabet[i], entity.getField( "name" ).getValue() );
+        }
+
+        assertEquals( 0, i );
+    }
+
+
+    @Test
+    public void testCollectionFilters() throws Exception {
+        LOG.info( "testCollectionFilters" );
+
+        Id appId = new SimpleId("application");
+        Id orgId = new SimpleId("organization");
+        EntityManagerFacade em = new EntityManagerFacade( orgId, appId, 
+            collectionManagerFactory, collectionIndexFactory );
+
+        for ( int i = alphabet.length - 1; i >= 0; i-- ) {
+            String name = alphabet[i];
+            Map<String, Object> properties = new LinkedHashMap<String, Object>();
+            properties.put( "name", name );
+            em.create( "item", properties );
+        }
+
+        Query query = Query.fromQL( "name < 'Delta' order by name" );
+        Results r = em.searchCollection( em.getApplicationRef(), "items", query );
+        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
+        int i = 0;
+        for ( Entity entity : r.getEntities() ) {
+            assertEquals( alphabet[i], entity.getField( "name" ).getValue() );
+            i++;
+        }
+        assertEquals( 3, i );
+
+        query = Query.fromQL( "name <= 'delta' order by name" );
+        r = em.searchCollection( em.getApplicationRef(), "items", query );
+        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
+        i = 0;
+        for ( Entity entity : r.getEntities() ) {
+            assertEquals( alphabet[i], entity.getField( "name" ).getValue() );
+            i++;
+        }
+        assertEquals( 4, i );
+
+        query = Query.fromQL( "name <= 'foxtrot' and name > 'bravo' order by name" );
+        r = em.searchCollection( em.getApplicationRef(), "items", query );
+        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
+        i = 2;
+        for ( Entity entity : r.getEntities() ) {
+            assertEquals( alphabet[i], entity.getField( "name" ).getValue() );
+            i++;
+        }
+        assertEquals( 6, i );
+
+        query = Query.fromQL( "name < 'foxtrot' and name > 'bravo' order by name" );
+        r = em.searchCollection( em.getApplicationRef(), "items", query );
+        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
+        i = 2;
+        for ( Entity entity : r.getEntities() ) {
+            assertEquals( alphabet[i], entity.getField( "name" ).getValue() );
+            i++;
+        }
+        assertEquals( 5, i );
+
+        query = Query.fromQL( "name < 'foxtrot' and name >= 'bravo' order by name" );
+        r = em.searchCollection( em.getApplicationRef(), "items", query );
+        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
+        i = 1;
+        for ( Entity entity : r.getEntities() ) {
+            assertEquals( alphabet[i], entity.getField( "name" ).getValue() );
+            i++;
+        }
+        assertEquals( 5, i );
+
+        query = Query.fromQL( "name <= 'foxtrot' and name >= 'bravo' order by name" );
+        r = em.searchCollection( em.getApplicationRef(), "items", query );
+        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
+        i = 1;
+        for ( Entity entity : r.getEntities() ) {
+            assertEquals( alphabet[i], entity.getField( "name" ).getValue() );
+            i++;
+        }
+        assertEquals( 6, i );
+
+        query = Query.fromQL( "name <= 'foxtrot' and name >= 'bravo' order by name desc" );
+        r = em.searchCollection( em.getApplicationRef(), "items", query );
+        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
+        i = 6;
+        for ( Entity entity : r.getEntities() ) {
+            i--;
+            assertEquals( alphabet[i], entity.getField( "name" ).getValue() );
+        }
+        assertEquals( 1, i );
+
+        query = Query.fromQL( "name < 'foxtrot' and name > 'bravo' order by name desc" );
+        r = em.searchCollection( em.getApplicationRef(), "items", query );
+        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
+        i = 5;
+        for ( Entity entity : r.getEntities() ) {
+            i--;
+            assertEquals( alphabet[i], entity.getField( "name" ).getValue() );
+        }
+        assertEquals( 2, i );
+
+        query = Query.fromQL( "name < 'foxtrot' and name >= 'bravo' order by name desc" );
+        r = em.searchCollection( em.getApplicationRef(), "items", query );
+        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
+        i = 5;
+        for ( Entity entity : r.getEntities() ) {
+            i--;
+            assertEquals( alphabet[i], entity.getField( "name" ).getValue() );
+        }
+        assertEquals( 1, i );
+
+        query = Query.fromQL( "name = 'foxtrot'" );
+        r = em.searchCollection( em.getApplicationRef(), "items", query );
+        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
+        assertEquals( 1, r.size() );
+
+        long created = r.getEntity().getVersion().timestamp();
+        Id entityId = r.getEntity().getId();
+
+        query = Query.fromQL( "created = " + created );
+        r = em.searchCollection( em.getApplicationRef(), "items", query );
+        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
+        assertEquals( 1, r.size() );
+        assertEquals( entityId, r.getEntity().getId() );
+    }
+
+
+    @Test
+    public void testSecondarySorts() throws Exception {
+        LOG.info( "testSecondarySorts" );
+
+        Id appId = new SimpleId("application");
+        Id orgId = new SimpleId("organization");
+        EntityManagerFacade em = new EntityManagerFacade( orgId, appId, 
+            collectionManagerFactory, collectionIndexFactory );
+
+        for ( int i = alphabet.length - 1; i >= 0; i-- ) {
+            String name = alphabet[i];
+            Map<String, Object> properties = new LinkedHashMap<String, Object>();
+            properties.put( "name", name );
+            properties.put( "group", i / 3 );
+            properties.put( "reverse_name", alphabet[alphabet.length - 1 - i] );
+
+            em.create( "item", properties );
+        }
+
+        Query query = Query.fromQL( "group = 1 order by name desc" );
+        Results r = em.searchCollection( em.getApplicationRef(), "items", query );
+        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
+        int i = 6;
+        for ( Entity entity : r.getEntities() ) {
+            i--;
+            assertEquals( 1, entity.getField( "group" ).getValue() );
+            assertEquals( alphabet[i], entity.getField( "name" ).getValue() );
+        }
+        assertEquals( 3, i );
+    }
+
+
+//    @Test
+//    public void testPropertyUpdateWithConnection() throws Exception {
+//
+//        Id appId = new SimpleId("application");
+//        Id orgId = new SimpleId("organization");
+//        CollectionScope scope = new CollectionScopeImpl( appId, orgId, "items" );
+//        EntityManagerFacade em = new EntityManagerFacade( factory, null);
+//
+//
+//        Map<String, Object> entity1 = new LinkedHashMap<String, Object>();
+//        entity1.put( "name", "name_1" );
+//        entity1.put( "status", "pickled" );
+//
+//
+//        Map<String, Object> entity2 = new LinkedHashMap<String, Object>();
+//        entity2.put( "name", "name_2" );
+//        entity2.put( "status", "foo" );
+//
+//
+//        Entity entity1Ref = em.create( "names", entity1 );
+//        Entity entity2Ref = em.create( "names", entity2 );
+//
+//
+//        em.createConnection( entity2Ref, "connecting", entity1Ref );
+//
+//        //should return valid values
+//        Query query = Query.fromQL( "select * where status = 'pickled'" );
+//
+//        Results r = em.searchCollection( em.getApplicationRef(), "names", query );
+//        assertEquals( 1, r.size() );
+//        assertEquals( entity1Ref.getUuid(), r.getEntity().getUuid() );
+//
+//
+//        r = em.searchCollection( em.getApplicationRef(), "names", query );
+//        assertEquals( 1, r.size() );
+//        assertEquals( entity1Ref.getUuid(), r.getEntity().getUuid() );
+//
+//        //now update the first entity, this causes the failure after connections
+//        entity1Ref.setProperty( "status", "herring" );
+//
+//        em.update( entity1Ref );
+//
+//        //query and check the status has been updated, shouldn't return results
+//        query = Query.fromQL( "select * where status = 'pickled'" );
+//
+//        r = em.searchCollection( em.getApplicationRef(), "names", query );
+//        assertEquals( 0, r.size() );
+//
+//        //search connections
+//        r = em.searchCollection( em.getApplicationRef(), "names", query );
+//        assertEquals( 0, r.size() );
+//
+//
+//        //should return results
+//        query = Query.fromQL( "select * where status = 'herring'" );
+//
+//        r = em.searchCollection( em.getApplicationRef(), "names", query );
+//        assertEquals( 1, r.size() );
+//
+//        assertEquals( entity1Ref.getUuid(), r.getEntity().getUuid() );
+//
+//
+//        //search connections
+//        r = em.searchCollection( em.getApplicationRef(), "names", query );
+//        assertEquals( 1, r.size() );
+//        assertEquals( entity1Ref.getUuid(), r.getEntity().getUuid() );
+//    }
+//
+//
+//    /** Same as above, but verifies the data in our entity_index_entry CF after the operations have completed */
+//
+//    @Test
+//    public void testPropertyUpdateWithConnectionEntityIndexEntryAudit() throws Exception {
+//
+//        Id appId = new SimpleId("application");
+//        Id orgId = new SimpleId("organization");
+//        CollectionScope scope = new CollectionScopeImpl( appId, orgId, "items" );
+//        EntityManagerFacade em = new EntityManagerFacade( factory, null);
+//
+//
+//        Map<String, Object> entity1 = new LinkedHashMap<String, Object>();
+//        entity1.put( "name", "name_1" );
+//        entity1.put( "status", "pickled" );
+//
+//
+//        Map<String, Object> entity2 = new LinkedHashMap<String, Object>();
+//        entity2.put( "name", "name_2" );
+//        entity2.put( "status", "foo" );
+//
+//
+//        Entity entity1Ref = em.create( "names", entity1 );
+//        Entity entity2Ref = em.create( "names", entity2 );
+//
+//
+//        em.createConnection( entity2Ref, "connecting", entity1Ref );
+//
+//        //should return valid values
+//        Query query = Query.fromQL( "select * where status = 'pickled'" );
+//
+//        Results r = em.searchCollection( em.getApplicationRef(), "names", query );
+//        assertEquals( 1, r.size() );
+//        assertEquals( entity1Ref.getUuid(), r.getEntity().getUuid() );
+//
+//
+//        r = em.searchCollection( em.getApplicationRef(), "names", query );
+//        assertEquals( 1, r.size() );
+//        assertEquals( entity1Ref.getUuid(), r.getEntity().getUuid() );
+//
+//        //now update the first entity, this causes the failure after connections
+//        entity1Ref.setProperty( "status", "herring" );
+//
+//        em.update( entity1Ref );
+//
+//        //query and check the status has been updated, shouldn't return results
+//        query = Query.fromQL( "select * where status = 'pickled'" );
+//
+//        r = em.searchCollection( em.getApplicationRef(), "names", query );
+//        assertEquals( 0, r.size() );
+//
+//        //search connections
+//        r = em.searchCollection( em.getApplicationRef(), "names", query );
+//        assertEquals( 0, r.size() );
+//
+//
+//        //should return results
+//        query = Query.fromQL( "select * where status = 'herring'" );
+//
+//        r = em.searchCollection( em.getApplicationRef(), "names", query );
+//        assertEquals( 1, r.size() );
+//
+//        assertEquals( entity1Ref.getUuid(), r.getEntity().getUuid() );
+//
+//
+//        //search connections
+//        r = em.searchCollection( em.getApplicationRef(), "names", query );
+//        assertEquals( 1, r.size() );
+//        assertEquals( entity1Ref.getUuid(), r.getEntity().getUuid() );
+//
+//
+//        RelationManagerImpl impl = ( RelationManagerImpl ) em.getRelationManager( entity2Ref );
+//
+//        //now read the index and see what properties are there
+//
+//
+//        CassandraService cass = CoreITSuite.cassandraResource.getBean( CassandraService.class );
+//
+//        ByteBufferSerializer buf = ByteBufferSerializer.get();
+//
+//        Keyspace ko = cass.getApplicationKeyspace( applicationId );
+//        Mutator<ByteBuffer> m = createMutator( ko, buf );
+//
+//
+//        IndexUpdate update =
+//                impl.batchStartIndexUpdate( m, entity1Ref, "status", "ignore", UUIDUtils.newTimeUUID(), false, false,
+//                        true, false );
+//
+//        int count = 0;
+//
+//        IndexEntry lastMatch = null;
+//
+//        for ( IndexEntry entry : update.getPrevEntries() ) {
+//            if ( "status".equals( entry.getPath() ) ) {
+//                count++;
+//                lastMatch = entry;
+//            }
+//        }
+//
+//
+//        assertEquals( 1, count );
+//
+//        if ( lastMatch != null ) {
+//            assertEquals( "herring", lastMatch.getValue() );
+//        }
+//        else {
+//            fail( "The last match was null but should have been herring!" );
+//        }
+//    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5eaf05ac/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/Application.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/Application.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/Application.java
new file mode 100644
index 0000000..a7d461f
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/Application.java
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.index.legacy;
+
+
+import java.util.Map;
+import java.util.UUID;
+import org.apache.usergrid.persistence.model.entity.Entity;
+import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.query.Query;
+import org.apache.usergrid.persistence.query.Results;
+
+import org.junit.rules.TestRule;
+
+
+
+/**
+ * A Usergrid Application object used to simplify Test code by making it much more readable and removing unnecessary
+ * clutter due to boilerplate code. Use concrete instances of Application from various modules like {@link
+ * CoreApplication} with the Rule and ClassRule annotations to create unique Applications in Usergrid for use in
+ * testing.
+ */
+public interface Application extends TestRule {
+    /**
+     * Gets the Application's UUID.
+     *
+     * @return the UUID of the application
+     */
+    UUID getId();
+
+    /** Clears the properties associated with this Application. */
+    void clear();
+
+    /**
+     * Gets a property value managed by this Application.
+     *
+     * @param key the key associated with the property
+     *
+     * @return the value of the property
+     */
+    Object get( String key );
+
+    /**
+     * Puts a property value into the Application.
+     *
+     * @param property the key of the property
+     * @param value the value of the property
+     *
+     * @return the last value held by the property
+     */
+    Object put( String property, Object value );
+
+    /**
+     * Gets the Map of properties associated with this Application.
+     *
+     * @return the Map of properties associated with this Application
+     */
+    Map<String, Object> getProperties();
+
+    /**
+     * Gets the name of the organization this Application is associated with.
+     *
+     * @return the name of this Application's organization
+     */
+    @SuppressWarnings("UnusedDeclaration")
+    String getOrgName();
+
+    /**
+     * Gets the name of this Application.
+     *
+     * @return the name of this Application
+     */
+    @SuppressWarnings("UnusedDeclaration")
+    String getAppName();
+
+    /**
+     * Gets an entity associated with this Application based on it's type.
+     *
+     * @param type the type of the entity
+     *
+     * @return the entity
+     *
+     * @throws Exception if something goes wrong accessing the entity
+     */
+    Entity create( String type ) throws Exception;
+
+    /**
+     * Gets an entity associated with this Application by unique id.
+     *
+     * @param id the unique identifier for the entity associated with this Application
+     *
+     * @return the entity associated with this Application
+     *
+     * @throws Exception if anything goes wrong accessing the entity
+     */
+    Entity get( Id id ) throws Exception;
+
+    
+    /**
+     * Adds an item to a collection associated with this Application.
+     *
+     * @param user the user adding the item
+     * @param collection the collection the item is added to
+     * @param item the entity being added to the collection
+     *
+     * @throws Exception if anything goes wrong adding the item to the specified collection
+     */
+    void addToCollection( Entity user, String collection, Entity item ) throws Exception;
+
+    /**
+     * Searches a collection for items satisfying a Query.
+     *
+     * @param user the user performing the query
+     * @param collection the collection being queried
+     * @param query the query to apply for selecting items in the collection
+     *
+     * @return the set of items resulting from the query
+     *
+     * @throws Exception if anything goes wrong querying the specified collection
+     */
+    Results searchCollection( Entity user, String collection, Query query ) throws Exception;
+
+
+    /**
+     * Puts all of the properties into this Application's properties.
+     *
+     * @param properties the Map of property key value pairs
+     */
+    void putAll( Map<String, Object> properties );
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5eaf05ac/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/CoreApplication.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/CoreApplication.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/CoreApplication.java
new file mode 100644
index 0000000..ab099da
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/CoreApplication.java
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.legacy;
+
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.usergrid.persistence.model.entity.Entity;
+import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.query.Query;
+import org.apache.usergrid.persistence.query.Results;
+
+
+public class CoreApplication implements Application, TestRule {
+
+    private final static Logger LOG = LoggerFactory.getLogger( CoreApplication.class );
+    protected UUID id;
+    protected String appName;
+    protected String orgName;
+    protected CoreITSetup setup;
+    protected EntityManagerFacade em;
+    protected Map<String, Object> properties = new LinkedHashMap<String, Object>();
+
+
+    public CoreApplication( CoreITSetup setup ) {
+        this.setup = setup;
+    }
+
+    public void setEntityManager( EntityManagerFacade em ) {
+        this.em = em;
+    }
+
+    @Override
+    public void putAll( Map<String, Object> properties ) {
+        this.properties.putAll( properties );
+    }
+
+
+    @Override
+    public Object get( String key ) {
+        return properties.get( key );
+    }
+
+
+    @Override
+    public Map<String, Object> getProperties() {
+        return properties;
+    }
+
+
+    @Override
+    public UUID getId() {
+        return id;
+    }
+
+
+    @Override
+    public String getOrgName() {
+        return orgName;
+    }
+
+
+    @Override
+    public String getAppName() {
+        return appName;
+    }
+
+
+    @Override
+    public Entity create( String type ) throws Exception {
+        Entity entity = em.create( type, properties );
+        clear();
+        return entity;
+    }
+
+
+    @Override
+    public Object put( String property, Object value ) {
+        return properties.put( property, value );
+    }
+
+
+    @Override
+    public void clear() {
+        properties.clear();
+    }
+
+    @Override
+    public Entity get( Id id ) throws Exception {
+        return em.get( id );
+    }
+
+    @Override
+    public Statement apply( final Statement base, final Description description ) {
+        return new Statement() {
+            @Override
+            public void evaluate() throws Throwable {
+                before( description );
+
+                try {
+                    base.evaluate();
+                }
+                finally {
+                    after( description );
+                }
+            }
+        };
+    }
+
+
+    protected void after( Description description ) {
+        LOG.info( "Test {}: finish with application", description.getDisplayName() );
+    }
+
+
+    protected void before( Description description ) throws Exception {
+    }
+
+
+    public EntityManagerFacade getEm() {
+        return em;
+    }
+
+    public void addToCollection( Entity user, String collection, Entity item ) throws Exception {
+        em.addToCollection( user, collection, item );
+    }
+
+    public Results searchCollection( Entity user, String collection, Query query ) throws Exception {
+        return em.searchCollection( user, collection, query );
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5eaf05ac/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/CoreITSetup.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/CoreITSetup.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/CoreITSetup.java
new file mode 100644
index 0000000..a621bbf
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/CoreITSetup.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.legacy;
+
+
+import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
+import org.junit.rules.TestRule;
+
+
+public interface CoreITSetup extends TestRule {
+
+    EntityCollectionManagerFactory getEmf();
+
+    void dump( String name, Object obj );
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5eaf05ac/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/CoreITSetupImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/CoreITSetupImpl.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/CoreITSetupImpl.java
new file mode 100644
index 0000000..41c3dbd
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/CoreITSetupImpl.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.index.legacy;
+
+
+import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
+import org.apache.usergrid.persistence.utils.JsonUtils;
+
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class CoreITSetupImpl implements CoreITSetup {
+    private static final Logger LOG = LoggerFactory.getLogger( CoreITSetupImpl.class );
+
+    protected EntityCollectionManagerFactory emf;
+    protected boolean enabled = false;
+
+
+//    public CoreITSetupImpl( CassandraResource cassandraResource ) {
+//        this.cassandraResource = cassandraResource;
+//    }
+
+
+    @Override
+    public Statement apply( Statement base, Description description ) {
+        return statement( base, description );
+    }
+
+
+    private Statement statement( final Statement base, final Description description ) {
+        return new Statement() {
+            @Override
+            public void evaluate() throws Throwable {
+                before( description );
+
+                try {
+                    base.evaluate();
+                }
+                finally {
+                    after( description );
+                }
+            }
+        };
+    }
+
+
+    /**
+     * Sets up the resources for the test here.
+     *
+     * @throws Throwable if setup fails (which will disable {@code after}
+     */
+    protected void before( Description description ) throws Throwable {
+        LOG.info( "Setting up for {}", description.getDisplayName() );
+        initialize();
+    }
+
+
+    private void initialize() {
+    }
+
+
+    /** Override to tear down your specific external resource. */
+    protected void after( Description description ) {
+        LOG.info( "Tearing down for {}", description.getDisplayName() );
+    }
+
+
+    @Override
+    public void dump( String name, Object obj ) {
+        if ( obj != null && LOG.isInfoEnabled() ) {
+            LOG.info( name + ":\n" + JsonUtils.mapToFormattedJsonString( obj ) );
+        }
+    }
+
+    public EntityCollectionManagerFactory getEmf() {
+        return emf;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5eaf05ac/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/EntityBuilder.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/EntityBuilder.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/EntityBuilder.java
new file mode 100644
index 0000000..fefb8fb
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/EntityBuilder.java
@@ -0,0 +1,177 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+
+package org.apache.usergrid.persistence.index.legacy;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import org.apache.usergrid.persistence.model.entity.Entity;
+import org.apache.usergrid.persistence.model.field.BooleanField;
+import org.apache.usergrid.persistence.model.field.DoubleField;
+import org.apache.usergrid.persistence.model.field.EntityObjectField;
+import org.apache.usergrid.persistence.model.field.Field;
+import org.apache.usergrid.persistence.model.field.FloatField;
+import org.apache.usergrid.persistence.model.field.IntegerField;
+import org.apache.usergrid.persistence.model.field.ListField;
+import org.apache.usergrid.persistence.model.field.LocationField;
+import org.apache.usergrid.persistence.model.field.LongField;
+import org.apache.usergrid.persistence.model.field.StringField;
+import org.apache.usergrid.persistence.model.field.value.Location;
+
+
+public class EntityBuilder {
+
+    public static Entity fromMap( String scope, Map<String, Object> item ) {
+        return fromMap( scope, null, item );
+    }
+
+    public static Entity fromMap( String scope, Entity entity, Map<String, Object> map ) {
+
+        if ( entity == null ) {
+            entity = new Entity();
+        }
+
+        for ( String fieldName : map.keySet() ) {
+
+            Object value = map.get( fieldName );
+
+            if ( value instanceof String ) {
+                entity.setField( new StringField( fieldName, (String)value ));
+
+            } else if ( value instanceof Boolean ) {
+                entity.setField( new BooleanField( fieldName, (Boolean)value ));
+                        
+            } else if ( value instanceof Integer ) {
+                entity.setField( new IntegerField( fieldName, (Integer)value ));
+
+            } else if ( value instanceof Double ) {
+                entity.setField( new DoubleField( fieldName, (Double)value ));
+
+		    } else if ( value instanceof Float ) {
+                entity.setField( new FloatField( fieldName, (Float)value ));
+				
+            } else if ( value instanceof Long ) {
+                entity.setField( new LongField( fieldName, (Long)value ));
+
+            } else if ( value instanceof List) {
+                entity.setField( listToListField( scope, fieldName, (List)value ));
+
+            } else if ( value instanceof Map ) {
+
+				Field field = null;
+
+				// is the map really a location element?
+				Map<String, Object> m = (Map<String, Object>)value;
+				if ( m.size() == 2) {
+					Double lat = null;
+					Double lon = null;
+					try {
+						if ( m.get("latitude") != null && m.get("longitude") != null ) {
+							lat = Double.parseDouble( m.get("latitude").toString() );
+							lon = Double.parseDouble( m.get("longitude").toString() );
+
+						} else if ( m.get("lat") != null && m.get("lon") != null ) { 
+							lat = Double.parseDouble( m.get("lat").toString() );
+							lon = Double.parseDouble( m.get("lon").toString() );
+						}
+					} catch ( NumberFormatException ignored ) {}
+
+					if ( lat != null && lon != null ) {
+						field = new LocationField( fieldName, new Location( lat, lon ));
+					}
+				}
+
+				if ( field == null ) { 
+
+					// not a location element, process it as map
+					entity.setField( new EntityObjectField( fieldName, 
+						fromMap( scope, (Map<String, Object>)value ))); // recursion
+
+				} else {
+					entity.setField( field );
+				}
+	
+			} else {
+                throw new RuntimeException("Unknown type " + value.getClass().getName());
+            }
+        }
+
+        return entity;
+    }
+
+    
+    private static ListField listToListField( String scope, String fieldName, List list ) {
+
+        if (list.isEmpty()) {
+            return new ListField( fieldName );
+        }
+
+        Object sample = list.get(0);
+
+        if ( sample instanceof Map ) {
+            return new ListField<Entity>( fieldName, processListForField( scope, list ));
+
+        } else if ( sample instanceof List ) {
+            return new ListField<List>( fieldName, processListForField( scope, list ));
+            
+        } else if ( sample instanceof String ) {
+            return new ListField<String>( fieldName, (List<String>)list );
+                    
+        } else if ( sample instanceof Boolean ) {
+            return new ListField<Boolean>( fieldName, (List<Boolean>)list );
+                    
+        } else if ( sample instanceof Integer ) {
+            return new ListField<Integer>( fieldName, (List<Integer>)list );
+
+        } else if ( sample instanceof Double ) {
+            return new ListField<Double>( fieldName, (List<Double>)list );
+
+        } else if ( sample instanceof Long ) {
+            return new ListField<Long>( fieldName, (List<Long>)list );
+
+        } else {
+            throw new RuntimeException("Unknown type " + sample.getClass().getName());
+        }
+    }
+
+    
+    private static List processListForField( String scope, List list ) {
+        if ( list.isEmpty() ) {
+            return list;
+        }
+        Object sample = list.get(0);
+
+        if ( sample instanceof Map ) {
+            List<Entity> newList = new ArrayList<Entity>();
+            for ( Map<String, Object> map : (List<Map<String, Object>>)list ) {
+                newList.add( fromMap( scope, map ) );
+            }
+            return newList;
+
+        } else if ( sample instanceof List ) {
+            return processListForField( scope, list ); // recursion
+            
+        } else { 
+            return list;
+        } 
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5eaf05ac/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/EntityManagerFacade.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/EntityManagerFacade.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/EntityManagerFacade.java
new file mode 100644
index 0000000..089446b
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/EntityManagerFacade.java
@@ -0,0 +1,167 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.legacy;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.usergrid.persistence.collection.CollectionScope;
+import org.apache.usergrid.persistence.collection.EntityCollectionManager;
+import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
+import org.apache.usergrid.persistence.collection.impl.CollectionScopeImpl;
+import org.apache.usergrid.persistence.index.EntityCollectionIndex;
+import org.apache.usergrid.persistence.index.EntityCollectionIndexFactory;
+import org.apache.usergrid.persistence.model.entity.Entity;
+import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.model.entity.SimpleId;
+import org.apache.usergrid.persistence.model.field.LocationField;
+import org.apache.usergrid.persistence.model.field.value.Location;
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
+import org.apache.usergrid.persistence.query.EntityRef;
+import org.apache.usergrid.persistence.query.Query;
+import org.apache.usergrid.persistence.query.Results;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/** 
+ * Implements just enough of the old EntityManager interface to get old tests imported from the
+ * Usergrid 1.0 Core module working against the new Core Persistence index & query system.
+ */
+public class EntityManagerFacade {
+    private static final Logger logger = LoggerFactory.getLogger( EntityManagerFacade.class );
+
+    private final Id orgId;
+    private final Id appId;
+    private final EntityCollectionManagerFactory ecmf;
+    private final EntityCollectionIndexFactory ecif;
+    private final Map<String, String> typesByCollectionNames = new HashMap<String, String>();
+    
+    public EntityManagerFacade( 
+        Id orgId, 
+        Id appId, 
+        EntityCollectionManagerFactory ecmf, 
+        EntityCollectionIndexFactory ecif ) {
+
+        this.appId = appId;
+        this.orgId = orgId;
+        this.ecmf = ecmf;
+        this.ecif = ecif;
+    }
+
+    public Entity create( String type, Map<String, Object> properties ) {
+
+        CollectionScope scope = new CollectionScopeImpl( appId, orgId, type );
+        EntityCollectionManager ecm = ecmf.createCollectionManager( scope );
+        EntityCollectionIndex eci = ecif.createCollectionIndex( scope );
+
+        final String collectionName;
+        if ( type.endsWith("y") ) {
+            collectionName = type.substring( 0, type.length() - 1) + "ies";
+        } else {
+            collectionName = type + "s";
+        }
+        typesByCollectionNames.put( collectionName, type );
+        
+        Entity entity = new Entity(new SimpleId(UUIDGenerator.newTimeUUID(), scope.getName()));
+        entity = EntityBuilder.fromMap( scope.getName(), entity, properties );
+        entity = ecm.write( entity ).toBlockingObservable().last();
+
+        eci.index( entity );
+        return entity;
+    }
+
+    public Results searchCollection( Entity user, String collectionName, Query query ) {
+
+        String type = typesByCollectionNames.get( collectionName );
+		if ( type == null ) {
+			throw new RuntimeException( 
+					"No type found for collection name: " + collectionName);
+		}
+        CollectionScope scope = new CollectionScopeImpl( appId, orgId, type );
+
+        EntityCollectionIndex eci = ecif.createCollectionIndex( scope );
+        Results results = eci.execute( query );
+        return results;
+    }
+
+    public Entity get( Id id ) {
+        CollectionScope scope = new CollectionScopeImpl( appId, orgId, id.getType() );
+        EntityCollectionManager ecm = ecmf.createCollectionManager( scope );
+        return ecm.load( id ).toBlockingObservable().last();
+    }
+
+    public void addToCollection( Entity user, String collectionName, Entity entity ) {
+        // basically a no-op except that can now map Entity type to collection name
+        typesByCollectionNames.put( collectionName, entity.getId().getType() );
+    }
+
+    public Entity getApplicationRef() {
+        return new Entity();
+    }
+
+    public void update( Entity entity ) {
+
+        String type = entity.getId().getType();
+
+        CollectionScope scope = new CollectionScopeImpl( appId, orgId, type );
+        EntityCollectionManager ecm = ecmf.createCollectionManager( scope );
+        EntityCollectionIndex eci = ecif.createCollectionIndex( scope );
+
+        final String collectionName;
+        if ( type.endsWith("y") ) {
+            collectionName = type.substring( 0, type.length() - 1) + "ies";
+        } else {
+            collectionName = type + "s";
+        }
+        typesByCollectionNames.put( collectionName, type );
+        
+        entity = ecm.write( entity ).toBlockingObservable().last();
+
+        eci.index( entity );
+    }
+
+	
+	public void delete( Entity entity ) {
+
+        String type = entity.getId().getType();
+
+        CollectionScope scope = new CollectionScopeImpl( appId, orgId, type );
+        EntityCollectionManager ecm = ecmf.createCollectionManager( scope );
+        EntityCollectionIndex eci = ecif.createCollectionIndex( scope );
+
+		eci.deindex( entity );
+		ecm.delete( entity.getId() );
+	}
+
+	public void setProperty( EntityRef entityRef, String fieldName, double lat, double lon ) {
+
+        String type = entityRef.getId().getType();
+
+        CollectionScope scope = new CollectionScopeImpl( appId, orgId, type );
+        EntityCollectionManager ecm = ecmf.createCollectionManager( scope );
+        EntityCollectionIndex eci = ecif.createCollectionIndex( scope );
+
+		Entity entity = ecm.load( entityRef.getId() ).toBlockingObservable().last();
+		entity.setField( new LocationField( fieldName, new Location( lat, lon )));
+
+        entity = ecm.write(entity).toBlockingObservable().last();
+        eci.index(entity);
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5eaf05ac/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/Point.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/Point.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/Point.java
new file mode 100644
index 0000000..ed31b8d
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/Point.java
@@ -0,0 +1,58 @@
+/*
+Copyright 2010 Alexandre Gellibert
+
+Licensed 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.persistence.index.legacy;
+
+
+import org.apache.commons.lang.Validate;
+
+
+/** @author Alexandre Gellibert */
+public class Point {
+
+    private double lat;
+    private double lon;
+
+
+    public Point() {
+
+    }
+
+
+    public Point( double lat, double lon ) {
+        Validate.isTrue( !( lat > 90.0 || lat < -90.0 ), "Latitude must be in [-90, 90]  but was ", lat );
+        Validate.isTrue( !( lon > 180.0 || lon < -180.0 ), "Longitude must be in [-180, 180] but was ", lon );
+        this.lat = lat;
+        this.lon = lon;
+    }
+
+
+    public double getLat() {
+        return lat;
+    }
+
+
+    public void setLat( double lat ) {
+        this.lat = lat;
+    }
+
+
+    public double getLon() {
+        return lon;
+    }
+
+
+    public void setLon( double lon ) {
+        this.lon = lon;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5eaf05ac/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/utils/ElasticSearchRule.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/utils/ElasticSearchRule.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/utils/ElasticSearchRule.java
new file mode 100644
index 0000000..d3eccff
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/utils/ElasticSearchRule.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.utils;
+
+import org.apache.usergrid.persistence.collection.util.AvailablePortFinder;
+import org.elasticsearch.client.Client;
+import org.elasticsearch.common.settings.ImmutableSettings;
+import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.node.Node;
+import org.elasticsearch.node.NodeBuilder;
+import org.junit.rules.ExternalResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class ElasticSearchRule extends ExternalResource {
+    private static final Logger log = LoggerFactory.getLogger( ElasticSearchRule.class ); 
+
+    private Client client; 
+
+    @Override
+    protected void after() {
+        client.close();
+    }
+
+    @Override
+    protected void before() throws Throwable {
+
+        // use unique port and directory names so multiple instances of ES can run concurrently.
+        int port = AvailablePortFinder.getNextAvailable(2000);
+        Settings settings = ImmutableSettings.settingsBuilder()
+            .put("node.http.enabled", true)
+            .put("transport.tcp.port", port )
+            .put("path.logs","target/elasticsearch/logs_" + port )
+            .put("path.data","target/elasticsearch/data_" + port )
+            .put("gateway.type", "none" )
+            .put("index.store.type", "memory" )
+            .put("index.number_of_shards", 1 )
+            .put("index.number_of_replicas", 1).build();
+
+        Node node = NodeBuilder.nodeBuilder().local(true).settings(settings).node();
+        client = node.client();
+    }
+
+    public Client getClient() {
+        return client;
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5eaf05ac/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/utils/ElasticSearchRule.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/utils/ElasticSearchRule.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/utils/ElasticSearchRule.java
deleted file mode 100644
index 0068fad..0000000
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/utils/ElasticSearchRule.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.utils;
-
-import org.apache.usergrid.persistence.collection.util.AvailablePortFinder;
-import org.elasticsearch.client.Client;
-import org.elasticsearch.common.settings.ImmutableSettings;
-import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.node.Node;
-import org.elasticsearch.node.NodeBuilder;
-import org.junit.rules.ExternalResource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-public class ElasticSearchRule extends ExternalResource {
-    private static final Logger log = LoggerFactory.getLogger( ElasticSearchRule.class ); 
-
-    private Client client; 
-
-    @Override
-    protected void after() {
-        client.close();
-    }
-
-    @Override
-    protected void before() throws Throwable {
-
-        // use unique port and directory names so multiple instances of ES can run concurrently.
-        int port = AvailablePortFinder.getNextAvailable(2000);
-        Settings settings = ImmutableSettings.settingsBuilder()
-            .put("node.http.enabled", true)
-            .put("transport.tcp.port", port )
-            .put("path.logs","target/elasticsearch/logs_" + port )
-            .put("path.data","target/elasticsearch/data_" + port )
-            .put("gateway.type", "none" )
-            .put("index.store.type", "memory" )
-            .put("index.number_of_shards", 1 )
-            .put("index.number_of_replicas", 1).build();
-
-        Node node = NodeBuilder.nodeBuilder().local(true).settings(settings).node();
-        client = node.client();
-    }
-
-    public Client getClient() {
-        return client;
-    }
-    
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5eaf05ac/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/test/Application.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/test/Application.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/test/Application.java
deleted file mode 100644
index 4314989..0000000
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/test/Application.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-package org.apache.usergrid.test;
-
-
-import java.util.Map;
-import java.util.UUID;
-import org.apache.usergrid.persistence.model.entity.Entity;
-import org.apache.usergrid.persistence.model.entity.Id;
-import org.apache.usergrid.persistence.query.Query;
-import org.apache.usergrid.persistence.query.Results;
-
-import org.junit.rules.TestRule;
-
-
-
-/**
- * A Usergrid Application object used to simplify Test code by making it much more readable and removing unnecessary
- * clutter due to boilerplate code. Use concrete instances of Application from various modules like {@link
- * CoreApplication} with the Rule and ClassRule annotations to create unique Applications in Usergrid for use in
- * testing.
- */
-public interface Application extends TestRule {
-    /**
-     * Gets the Application's UUID.
-     *
-     * @return the UUID of the application
-     */
-    UUID getId();
-
-    /** Clears the properties associated with this Application. */
-    void clear();
-
-    /**
-     * Gets a property value managed by this Application.
-     *
-     * @param key the key associated with the property
-     *
-     * @return the value of the property
-     */
-    Object get( String key );
-
-    /**
-     * Puts a property value into the Application.
-     *
-     * @param property the key of the property
-     * @param value the value of the property
-     *
-     * @return the last value held by the property
-     */
-    Object put( String property, Object value );
-
-    /**
-     * Gets the Map of properties associated with this Application.
-     *
-     * @return the Map of properties associated with this Application
-     */
-    Map<String, Object> getProperties();
-
-    /**
-     * Gets the name of the organization this Application is associated with.
-     *
-     * @return the name of this Application's organization
-     */
-    @SuppressWarnings("UnusedDeclaration")
-    String getOrgName();
-
-    /**
-     * Gets the name of this Application.
-     *
-     * @return the name of this Application
-     */
-    @SuppressWarnings("UnusedDeclaration")
-    String getAppName();
-
-    /**
-     * Gets an entity associated with this Application based on it's type.
-     *
-     * @param type the type of the entity
-     *
-     * @return the entity
-     *
-     * @throws Exception if something goes wrong accessing the entity
-     */
-    Entity create( String type ) throws Exception;
-
-    /**
-     * Gets an entity associated with this Application by unique id.
-     *
-     * @param id the unique identifier for the entity associated with this Application
-     *
-     * @return the entity associated with this Application
-     *
-     * @throws Exception if anything goes wrong accessing the entity
-     */
-    Entity get( Id id ) throws Exception;
-
-    
-    /**
-     * Adds an item to a collection associated with this Application.
-     *
-     * @param user the user adding the item
-     * @param collection the collection the item is added to
-     * @param item the entity being added to the collection
-     *
-     * @throws Exception if anything goes wrong adding the item to the specified collection
-     */
-    void addToCollection( Entity user, String collection, Entity item ) throws Exception;
-
-    /**
-     * Searches a collection for items satisfying a Query.
-     *
-     * @param user the user performing the query
-     * @param collection the collection being queried
-     * @param query the query to apply for selecting items in the collection
-     *
-     * @return the set of items resulting from the query
-     *
-     * @throws Exception if anything goes wrong querying the specified collection
-     */
-    Results searchCollection( Entity user, String collection, Query query ) throws Exception;
-
-
-    /**
-     * Puts all of the properties into this Application's properties.
-     *
-     * @param properties the Map of property key value pairs
-     */
-    void putAll( Map<String, Object> properties );
-}


[4/5] git commit: Re-organize test packages.

Posted by sn...@apache.org.
Re-organize test packages.


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

Branch: refs/heads/two-dot-o
Commit: 5eaf05aced2bf4df634ece7a00de530422ec9336
Parents: bae131f
Author: Dave Johnson <dm...@apigee.com>
Authored: Wed Mar 5 10:22:54 2014 -0500
Committer: Dave Johnson <dm...@apigee.com>
Committed: Wed Mar 5 10:22:54 2014 -0500

----------------------------------------------------------------------
 .../index/impl/EsEntityCollectionIndex.java     |   13 +-
 .../usergrid/persistence/query/Results.java     |    7 +-
 .../usergrid/persistence/CollectionIT.java      | 1638 ------------------
 .../org/apache/usergrid/persistence/GeoIT.java  |  554 ------
 .../apache/usergrid/persistence/IndexIT.java    |  484 ------
 .../index/guice/IndexTestModule.java            |   30 -
 .../index/guice/TestIndexModule.java            |   30 +
 .../persistence/index/impl/CollectionIT.java    | 1638 ++++++++++++++++++
 .../index/impl/ElasticSearchTest.java           |   18 +-
 .../index/impl/EntityCollectionIndexTest.java   |   14 +-
 .../usergrid/persistence/index/impl/GeoIT.java  |  550 ++++++
 .../persistence/index/impl/IndexIT.java         |  484 ++++++
 .../persistence/index/legacy/Application.java   |  145 ++
 .../index/legacy/CoreApplication.java           |  156 ++
 .../persistence/index/legacy/CoreITSetup.java   |   31 +
 .../index/legacy/CoreITSetupImpl.java           |   96 +
 .../persistence/index/legacy/EntityBuilder.java |  177 ++
 .../index/legacy/EntityManagerFacade.java       |  167 ++
 .../persistence/index/legacy/Point.java         |   58 +
 .../index/utils/ElasticSearchRule.java          |   65 +
 .../persistence/utils/ElasticSearchRule.java    |   65 -
 .../org/apache/usergrid/test/Application.java   |  145 --
 .../apache/usergrid/test/CassandraService.java  |   27 -
 .../apache/usergrid/test/CoreApplication.java   |  156 --
 .../org/apache/usergrid/test/CoreITSetup.java   |   31 -
 .../apache/usergrid/test/CoreITSetupImpl.java   |   97 --
 .../org/apache/usergrid/test/EntityBuilder.java |  177 --
 .../usergrid/test/EntityManagerFacade.java      |  167 --
 .../java/org/apache/usergrid/test/Point.java    |   58 -
 .../src/test/resources/log4j.properties         |    7 +-
 30 files changed, 3634 insertions(+), 3651 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5eaf05ac/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityCollectionIndex.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityCollectionIndex.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityCollectionIndex.java
index d33b525..f7b56c4 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityCollectionIndex.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityCollectionIndex.java
@@ -120,6 +120,17 @@ public class EsEntityCollectionIndex implements EntityCollectionIndex {
 
     public void index( Entity entity ) {
 
+        // TODO: real exception types here
+        if ( entity.getId() == null ) {
+            throw new RuntimeException("Cannot index entity with id null");
+        }
+        if ( entity.getId().getUuid() == null || entity.getId().getType() == null ) {
+            throw new RuntimeException("Cannot index entity with incomplete id");
+        }
+        if ( entity.getVersion() == null ) {
+            throw new RuntimeException("Cannot index entity with version null");
+        }
+
         Map<String, Object> entityAsMap = EsEntityCollectionIndex.entityToMap( entity );
         entityAsMap.put("created", entity.getVersion().timestamp() );
 
@@ -208,7 +219,6 @@ public class EsEntityCollectionIndex implements EntityCollectionIndex {
             String version = idparts[2];
 
             Id entityId = new SimpleId( UUID.fromString(id), type);
-            UUID entityVersion = UUID.fromString(version);
 
             Entity entity = manager.load( entityId ).toBlockingObservable().last();
             if ( entity == null ) {
@@ -216,6 +226,7 @@ public class EsEntityCollectionIndex implements EntityCollectionIndex {
                 throw new RuntimeException("Entity id [" + entityId + "] not found"); 
             }
 
+            UUID entityVersion = UUID.fromString(version);
             if ( entityVersion.compareTo( entity.getVersion()) == -1 ) {
                 logger.debug("   Stale hit " + hit.getId() ); 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5eaf05ac/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/Results.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/Results.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/Results.java
index ad4ee54..8d28eed 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/Results.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/Results.java
@@ -204,8 +204,13 @@ public class Results implements Iterable<Entity> {
     }
 
 
+    public boolean hasCursor() {
+        return cursor != null;
+    }
+
+
     public String getCursor() {
-        return null;
+        return cursor;
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5eaf05ac/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/CollectionIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/CollectionIT.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/CollectionIT.java
deleted file mode 100644
index 7e15646..0000000
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/CollectionIT.java
+++ /dev/null
@@ -1,1638 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-package org.apache.usergrid.persistence;
-
-
-import com.google.inject.Inject;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
-import org.apache.usergrid.persistence.collection.cassandra.CassandraRule;
-import org.apache.usergrid.persistence.collection.guice.MigrationManagerRule;
-import org.apache.usergrid.persistence.index.EntityCollectionIndexFactory;
-import org.apache.usergrid.persistence.index.guice.IndexTestModule;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.usergrid.persistence.model.entity.Entity;
-import org.apache.usergrid.persistence.model.entity.Id;
-import org.apache.usergrid.persistence.model.entity.SimpleId;
-import org.apache.usergrid.persistence.model.field.StringField;
-import org.apache.usergrid.persistence.query.Query;
-import org.apache.usergrid.persistence.query.Results;
-import org.apache.usergrid.persistence.utils.JsonUtils;
-import static org.apache.usergrid.persistence.utils.MapUtils.hashMap;
-import org.apache.usergrid.persistence.utils.UUIDUtils;
-import org.apache.usergrid.test.CoreApplication;
-import org.apache.usergrid.test.CoreITSetup;
-import org.apache.usergrid.test.CoreITSetupImpl;
-import org.apache.usergrid.test.EntityManagerFacade;
-import org.jukito.JukitoRunner;
-import org.jukito.UseModules;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.runner.RunWith;
-
-
-@RunWith(JukitoRunner.class)
-@UseModules({ IndexTestModule.class })
-public class CollectionIT {
-    private static final Logger LOG = LoggerFactory.getLogger( CollectionIT.class );
-
-    @ClassRule
-    public static CassandraRule cass = new CassandraRule();
-
-    @Inject
-    @Rule
-    public MigrationManagerRule migrationManagerRule;
-    
-    @ClassRule
-    public static CoreITSetup setup = new CoreITSetupImpl();
-
-    @Rule
-    public CoreApplication app = new CoreApplication( setup );
-
-    @Inject
-    public EntityCollectionManagerFactory collectionManagerFactory;
-    
-    @Inject
-    public EntityCollectionIndexFactory collectionIndexFactory;
-
-    private EntityManagerFacade em;
-
-    @Before
-    public void setup() {
-
-        Id appId = new SimpleId("application");
-        Id orgId = new SimpleId("organization");
-
-        em = new EntityManagerFacade( orgId, appId, 
-            collectionManagerFactory, collectionIndexFactory );
-
-        app.setEntityManager( em );                
-    }
-
-    @Test
-    public void testCollection() throws Exception {
-        app.put( "username", "edanuff" );
-        app.put( "email", "ed@anuff.com" );
-
-        Entity user = app.create( "user" );
-        assertNotNull( user );
-
-        app.put( "actor", new LinkedHashMap<String, Object>() {
-            {
-                put( "displayName", "Ed Anuff" );
-                put( "objectType", "person" );
-            }
-        } );
-        app.put( "verb", "tweet" );
-        app.put( "content", "I ate a sammich" );
-        app.put( "ordinal", 3 );
-
-        Entity activity = app.create( "activity" );
-        assertNotNull( activity );
-
-        LOG.info( "" + activity.getClass() );
-        LOG.info( JsonUtils.mapToFormattedJsonString( activity ) );
-
-        activity = app.get( activity.getId() );
-
-        LOG.info( "Activity class = {}", activity.getClass() );
-        LOG.info( JsonUtils.mapToFormattedJsonString( activity ) );
-
-        app.addToCollection( user, "activities", activity );
-
-        // test queries on the collection
-
-        app.put( "actor", new LinkedHashMap<String, Object>() {
-            {
-                put( "displayName", "Ed Anuff" );
-                put( "objectType", "person" );
-            }
-        } );
-        app.put( "verb", "tweet2" );
-        app.put( "content", "I ate a pickle" );
-        app.put( "ordinal", 2 );
-        Entity activity2 = app.create( "activity" );
-        activity2 = app.get( activity2.getId() );
-        app.addToCollection( user, "activities", activity2 );
-
-        app.put( "actor", new LinkedHashMap<String, Object>() {
-            {
-                put( "displayName", "Ed Anuff" );
-                put( "objectType", "person" );
-            }
-        } );
-        app.put( "verb", "tweet2" );
-        app.put( "content", "I ate an apple" );
-        app.put( "ordinal", 1 );
-        Entity activity3 = app.create( "activity" );
-        activity3 = app.get( activity3.getId() );
-        app.addToCollection( user, "activities", activity3 );
-
-        // empty query
-        Query query = new Query();
-        Results r = app.searchCollection( user, "activities", query );
-        assertEquals( 3, r.size() ); // success
-
-        // query verb
-        query = new Query().addEqualityFilter( "verb", "tweet2" );
-        r = app.searchCollection( user, "activities", query );
-        assertEquals( 2, r.size() );
-
-        // query verb, sort created
-        query = new Query().addEqualityFilter( "verb", "tweet2" );
-        query.addSort( "created" );
-        r = app.searchCollection( user, "activities", query );
-        assertEquals( 2, r.size() );
-        List<Entity> entities = r.getEntities();
-        assertEquals( entities.get( 0 ).getId(), activity2.getId() );
-        assertEquals( entities.get( 1 ).getId(), activity3.getId() );
-
-        // query verb, sort ordinal
-        query = new Query().addEqualityFilter( "verb", "tweet2" );
-        query.addSort( "ordinal" );
-        r = app.searchCollection( user, "activities", query );
-        assertEquals( 2, r.size() );
-        entities = r.getEntities();
-        assertEquals( entities.get( 0 ).getId(), activity3.getId() );
-        assertEquals( entities.get( 1 ).getId(), activity2.getId() );
-
-        // empty query, sort content
-        query = new Query();
-        query.addSort( "content" );
-        r = app.searchCollection( user, "activities", query );
-        assertEquals( 3, r.size() );
-        entities = r.getEntities();
-        LOG.info( JsonUtils.mapToFormattedJsonString( entities ) );
-        assertEquals( entities.get( 0 ).getId(), activity2.getId() );
-        assertEquals( entities.get( 1 ).getId(), activity.getId() );
-        assertEquals( entities.get( 2 ).getId(), activity3.getId() );
-
-        // empty query, sort verb
-        query = new Query();
-        query.addSort( "verb" );
-        r = app.searchCollection( user, "activities", query );
-        assertEquals( 3, r.size() );
-
-        // empty query, sort ordinal
-        query = new Query();
-        query.addSort( "ordinal" );
-        r = app.searchCollection( user, "activities", query );
-        assertEquals( 3, r.size() );
-        entities = r.getEntities();
-        assertEquals( entities.get( 0 ).getId(), activity3.getId() );
-        assertEquals( entities.get( 1 ).getId(), activity2.getId() );
-        assertEquals( entities.get( 2 ).getId(), activity.getId() );
-
-        // query ordinal
-        query = new Query().addEqualityFilter( "ordinal", 2 );
-        r = app.searchCollection( user, "activities", query );
-        assertEquals( 1, r.size() );
-
-        // query ordinal and sort ordinal
-        query = new Query().addEqualityFilter( "ordinal", 2 );
-        query.addSort( "ordinal" );
-        r = app.searchCollection( user, "activities", query );
-        assertEquals( 1, r.size() );
-    }
-
-
-    @Test
-    public void userFirstNameSearch() throws Exception {
-
-        String firstName = "firstName" + UUIDUtils.newTimeUUID();
-
-        Map<String, Object> properties = new LinkedHashMap<String, Object>();
-        properties.put( "username", "edanuff" );
-        properties.put( "email", "ed@anuff.com" );
-        properties.put( "firstname", firstName );
-
-        Entity user = em.create( "user", properties );
-        assertNotNull( user );
-
-        // EntityRef
-        Query query = new Query();
-        query.addEqualityFilter( "firstname", firstName );
-
-        Results r = em.searchCollection( em.getApplicationRef(), "users", query );
-
-        assertTrue( r.size() > 0 );
-
-        Entity returned = r.getEntities().get( 0 );
-
-        assertEquals( user.getId(), returned.getId() );
-
-        // update the username
-        String newFirstName = "firstName" + UUIDUtils.newTimeUUID();
-
-        user.setField( new StringField("firstname", newFirstName) );
-
-        em.update( user );
-
-        // search with the old username, should be no results
-        query = new Query();
-        query.addEqualityFilter( "firstname", firstName );
-
-        r = em.searchCollection( em.getApplicationRef(), "users", query );
-
-        assertEquals( 0, r.size() );
-
-        // search with the new username, should be results.
-
-        query = new Query();
-        query.addEqualityFilter( "firstname", newFirstName );
-
-        r = em.searchCollection( em.getApplicationRef(), "users", query );
-
-        assertTrue( r.size() > 0 );
-
-        returned = r.getEntities().get( 0 );
-
-        assertEquals( user.getId(), returned.getId() );
-    }
-
-
-    @Test
-    public void userMiddleNameSearch() throws Exception {
-
-        String middleName = "middleName" + UUIDUtils.newTimeUUID();
-
-        Map<String, Object> properties = new LinkedHashMap<String, Object>();
-        properties.put( "username", "edanuff" );
-        properties.put( "email", "ed@anuff.com" );
-        properties.put( "middlename", middleName );
-
-        Entity user = em.create( "user", properties );
-        assertNotNull( user );
-
-        // EntityRef
-        Query query = new Query();
-        query.addEqualityFilter( "middlename", middleName );
-
-        Results r = em.searchCollection( em.getApplicationRef(), "users", query );
-
-        assertTrue( r.size() > 0 );
-
-        Entity returned = r.getEntities().get( 0 );
-
-        assertEquals( user.getId(), returned.getId() );
-    }
-
-
-    @Test
-    public void userLastNameSearch() throws Exception {
-
-        String lastName = "lastName" + UUIDUtils.newTimeUUID();
-
-        Map<String, Object> properties = new LinkedHashMap<String, Object>();
-        properties.put( "username", "edanuff" );
-        properties.put( "email", "ed@anuff.com" );
-        properties.put( "lastname", lastName );
-
-        Entity user = em.create( "user", properties );
-        assertNotNull( user );
-
-        // EntityRef
-        Query query = new Query();
-        query.addEqualityFilter( "lastname", lastName );
-
-        Results r = em.searchCollection( em.getApplicationRef(), "users", query );
-
-        assertTrue( r.size() > 0 );
-
-        Entity returned = r.getEntities().get( 0 );
-
-        assertEquals( user.getId(), returned.getId() );
-    }
-
-
-//    @Test
-//    public void testGroups() throws Exception {
-//        UUID applicationId = setup.createApplication( "testOrganization", "testGroups" );
-//        assertNotNull( applicationId );
-//
-//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
-//        assertNotNull( em );
-//
-//        Map<String, Object> properties = new LinkedHashMap<String, Object>();
-//        properties.put( "username", "edanuff" );
-//        properties.put( "email", "ed@anuff.com" );
-//
-//        Entity user1 = em.create( "user", properties );
-//        assertNotNull( user1 );
-//
-//        properties = new LinkedHashMap<String, Object>();
-//        properties.put( "username", "djacobs" );
-//        properties.put( "email", "djacobs@gmail.com" );
-//
-//        Entity user2 = em.create( "user", properties );
-//        assertNotNull( user2 );
-//
-//        properties = new LinkedHashMap<String, Object>();
-//        properties.put( "path", "group1" );
-//        Entity group = em.create( "group", properties );
-//        assertNotNull( group );
-//
-//        em.addToCollection( group, "users", user1 );
-//        em.addToCollection( group, "users", user2 );
-//
-//        properties = new LinkedHashMap<String, Object>();
-//        properties.put( "nickname", "ed" );
-//        em.updateProperties( new SimpleCollectionRef( group, "users", user1 ), properties );
-//
-//        Results r = em.searchCollection( group, "users", new Query().addEqualityFilter( "member.nickname", "ed" )
-//                                                                    .withResultsLevel(
-//                                                                            Results.Level.LINKED_PROPERTIES ) );
-//        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
-//        assertEquals( 1, r.size() );
-//
-//        em.removeFromCollection( user1, "groups", group );
-//    }
-
-
-    @Test
-    public void groupNameSearch() throws Exception {
-
-        String groupName = "groupName" + UUIDUtils.newTimeUUID();
-
-        Map<String, Object> properties = new LinkedHashMap<String, Object>();
-        properties.put( "title", "testTitle" );
-        properties.put( "path", "testPath" );
-        properties.put( "name", groupName );
-
-        Entity group = em.create( "group", properties );
-        assertNotNull( group );
-
-        // EntityRef
-        Query query = new Query();
-        query.addEqualityFilter( "name", groupName );
-
-        Results r = em.searchCollection( em.getApplicationRef(), "groups", query );
-
-        assertTrue( r.size() > 0 );
-
-        Entity returned = r.getEntities().get( 0 );
-
-        assertEquals( group.getId(), returned.getId() );
-    }
-
-
-    @Test
-    public void groupTitleSearch() throws Exception {
-
-
-        String titleName = "groupName" + UUIDUtils.newTimeUUID();
-
-        Map<String, Object> properties = new LinkedHashMap<String, Object>();
-        properties.put( "title", titleName );
-        properties.put( "path", "testPath" );
-        properties.put( "name", "testName" );
-
-        Entity group = em.create( "group", properties );
-        assertNotNull( group );
-
-        // EntityRef
-        Query query = new Query();
-        query.addEqualityFilter( "title", titleName );
-
-        Results r = em.searchCollection( em.getApplicationRef(), "groups", query );
-
-        assertTrue( r.size() > 0 );
-
-        Entity returned = r.getEntities().get( 0 );
-
-        assertEquals( group.getId(), returned.getId() );
-    }
-
-
-    @Test
-    public void testSubkeys() throws Exception {
-
-        Map<String, Object> properties = new LinkedHashMap<String, Object>();
-        properties.put( "username", "edanuff" );
-        properties.put( "email", "ed@anuff.com" );
-
-        Entity user = em.create( "user", properties );
-        assertNotNull( user );
-
-        properties = new LinkedHashMap<String, Object>();
-        properties.put( "actor", hashMap( "displayName", "Ed Anuff" ).map( "objectType", "person" ) );
-        properties.put( "verb", "tweet" );
-        properties.put( "content", "I ate a sammich" );
-
-        em.addToCollection( user, "activities", em.create( "activity", properties ) );
-
-        properties = new LinkedHashMap<String, Object>();
-        properties.put( "actor", hashMap( "displayName", "Ed Anuff" ).map( "objectType", "person" ) );
-        properties.put( "verb", "post" );
-        properties.put( "content", "I wrote a blog post" );
-
-        em.addToCollection( user, "activities", em.create( "activity", properties ) );
-
-        properties = new LinkedHashMap<String, Object>();
-        properties.put( "actor", hashMap( "displayName", "Ed Anuff" ).map( "objectType", "person" ) );
-        properties.put( "verb", "tweet" );
-        properties.put( "content", "I ate another sammich" );
-
-        em.addToCollection( user, "activities", em.create( "activity", properties ) );
-
-        properties = new LinkedHashMap<String, Object>();
-        properties.put( "actor", hashMap( "displayName", "Ed Anuff" ).map( "objectType", "person" ) );
-        properties.put( "verb", "post" );
-        properties.put( "content", "I wrote another blog post" );
-
-        em.addToCollection( user, "activities", em.create( "activity", properties ) );
-
-        Results r = em.searchCollection( user, "activities", Query.searchForProperty( "verb", "post" ) );
-        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
-        assertEquals( 2, r.size() );
-    }
-
-
-//    @Test
-//    public void emptyQuery() throws Exception {
-//
-//        String firstName = "firstName" + UUIDUtils.newTimeUUID();
-//
-//        Map<String, Object> properties = new LinkedHashMap<String, Object>();
-//        properties.put( "username", "edanuff" );
-//        properties.put( "email", "ed@anuff.com" );
-//        properties.put( "firstname", firstName );
-//
-//        Entity user = em.create( "user", properties );
-//        assertNotNull( user );
-//
-//        properties = new LinkedHashMap<String, Object>();
-//        properties.put( "username", "djacobs" );
-//        properties.put( "email", "djacobs@gmail.com" );
-//
-//        Entity user2 = em.create( "user", properties );
-//        assertNotNull( user2 );
-//
-//        // EntityRef
-//        Query query = new Query();
-//
-//        Results r = em.searchCollection( em.getApplicationRef(), "users", query );
-//
-//        assertEquals( 2, r.size() );
-//
-//        Entity returned = r.getEntities().get( 0 );
-//
-//        assertEquals( user.getId(), returned.getId() );
-//
-//        returned = r.getEntities().get( 1 );
-//
-//        assertEquals( user2.getId(), returned.getId() );
-//    }
-
-
-//    @Test
-//    public void emptyQueryReverse() throws Exception {
-//
-//        String firstName = "firstName" + UUIDUtils.newTimeUUID();
-//
-//        Map<String, Object> properties = new LinkedHashMap<String, Object>();
-//        properties.put( "username", "edanuff" );
-//        properties.put( "email", "ed@anuff.com" );
-//        properties.put( "firstname", firstName );
-//
-//        Entity user = em.create( "user", properties );
-//        assertNotNull( user );
-//
-//        properties = new LinkedHashMap<String, Object>();
-//        properties.put( "username", "djacobs" );
-//        properties.put( "email", "djacobs@gmail.com" );
-//
-//        Entity user2 = em.create( "user", properties );
-//        assertNotNull( user2 );
-//
-//        // EntityRef
-//        Query query = new Query();
-//        query.setReversed( true );
-//
-//        Results r = em.searchCollection( em.getApplicationRef(), "users", query );
-//
-//        assertEquals( 2, r.size() );
-//
-//        Entity returned = r.getEntities().get( 0 );
-//
-//        assertEquals( user2.getId(), returned.getId() );
-//
-//        returned = r.getEntities().get( 1 );
-//
-//        assertEquals( user.getId(), returned.getId() );
-//    }
-
-
-//    @Test
-//    public void orQuery() throws Exception {
-//        UUID applicationId = setup.createApplication( "testOrganization", "orQuery" );
-//        assertNotNull( applicationId );
-//
-//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
-//        assertNotNull( em );
-//
-//        Map<String, Object> properties = new LinkedHashMap<String, Object>();
-//        properties.put( "keywords", "blah,test,game" );
-//        properties.put( "title", "Solitaire" );
-//
-//        Entity game1 = em.create( "orquerygame", properties );
-//        assertNotNull( game1 );
-//
-//        properties = new LinkedHashMap<String, Object>();
-//        properties.put( "keywords", "random,test" );
-//        properties.put( "title", "Hearts" );
-//
-//        Entity game2 = em.create( "orquerygame", properties );
-//        assertNotNull( game2 );
-//
-//        // EntityRef
-//        Query query = Query.fromQL( "select * where keywords contains 'Random' OR keywords contains 'Game'" );
-//
-//        Results r = em.searchCollection( em.getApplicationRef(), "orquerygames", query );
-//
-//        assertEquals( 2, r.size() );
-//
-//        Entity returned = r.getEntities().get( 0 );
-//
-//        assertEquals( game1.getUuid(), returned.getUuid() );
-//
-//        returned = r.getEntities().get( 1 );
-//
-//        assertEquals( game2.getUuid(), returned.getUuid() );
-//
-//        query = Query.fromQL( "select * where( keywords contains 'Random' OR keywords contains 'Game')" );
-//
-//        r = em.searchCollection( em.getApplicationRef(), "orquerygames", query );
-//
-//        assertEquals( 2, r.size() );
-//
-//        returned = r.getEntities().get( 0 );
-//
-//        assertEquals( game1.getUuid(), returned.getUuid() );
-//
-//        returned = r.getEntities().get( 1 );
-//
-//        assertEquals( game2.getUuid(), returned.getUuid() );
-//
-//        // field order shouldn't matter USERGRID-375
-//        query = Query.fromQL( "select * where keywords contains 'blah' OR title contains 'blah'" );
-//
-//        r = em.searchCollection( em.getApplicationRef(), "orquerygames", query );
-//
-//        assertEquals( 1, r.size() );
-//
-//        returned = r.getEntities().get( 0 );
-//
-//        assertEquals( game1.getUuid(), returned.getUuid() );
-//
-//        query = Query.fromQL( "select * where  title contains 'blah' OR keywords contains 'blah'" );
-//
-//        r = em.searchCollection( em.getApplicationRef(), "orquerygames", query );
-//
-//        assertEquals( 1, r.size() );
-//
-//        returned = r.getEntities().get( 0 );
-//
-//        assertEquals( game1.getUuid(), returned.getUuid() );
-//    }
-//
-//
-//    @Test
-//    public void andQuery() throws Exception {
-//        UUID applicationId = setup.createApplication( "testOrganization", "andQuery" );
-//        assertNotNull( applicationId );
-//
-//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
-//        assertNotNull( em );
-//
-//        Map<String, Object> properties = new LinkedHashMap<String, Object>();
-//        properties.put( "keywords", "blah,test,game" );
-//        properties.put( "title", "Solitaire" );
-//
-//        Entity game1 = em.create( "game", properties );
-//        assertNotNull( game1 );
-//
-//        properties = new LinkedHashMap<String, Object>();
-//        properties.put( "keywords", "random,test" );
-//        properties.put( "title", "Hearts" );
-//
-//        Entity game2 = em.create( "game", properties );
-//        assertNotNull( game2 );
-//
-//        // overlap
-//        Query query = Query.fromQL( "select * where keywords contains 'test' AND keywords contains 'random'" );
-//        Results r = em.searchCollection( em.getApplicationRef(), "games", query );
-//        assertEquals( 1, r.size() );
-//
-//        // disjoint
-//        query = Query.fromQL( "select * where keywords contains 'random' AND keywords contains 'blah'" );
-//        r = em.searchCollection( em.getApplicationRef(), "games", query );
-//        assertEquals( 0, r.size() );
-//
-//        // same each side
-//        query = Query.fromQL( "select * where keywords contains 'test' AND keywords contains 'test'" );
-//        r = em.searchCollection( em.getApplicationRef(), "games", query );
-//        assertEquals( 2, r.size() );
-//
-//        Entity returned = r.getEntities().get( 0 );
-//        assertEquals( game1.getUuid(), returned.getUuid() );
-//
-//        returned = r.getEntities().get( 1 );
-//        assertEquals( game2.getUuid(), returned.getUuid() );
-//
-//        // one side, left
-//        query = Query.fromQL( "select * where keywords contains 'test' AND keywords contains 'foobar'" );
-//        r = em.searchCollection( em.getApplicationRef(), "games", query );
-//        assertEquals( 0, r.size() );
-//
-//        // one side, right
-//        query = Query.fromQL( "select * where keywords contains 'foobar' AND keywords contains 'test'" );
-//        r = em.searchCollection( em.getApplicationRef(), "games", query );
-//        assertEquals( 0, r.size() );
-//    }
-//
-//
-//    @Test
-//    public void notQuery() throws Exception {
-//        UUID applicationId = setup.createApplication( "testOrganization", "notQuery" );
-//        assertNotNull( applicationId );
-//
-//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
-//        assertNotNull( em );
-//
-//        Map<String, Object> properties = new LinkedHashMap<String, Object>();
-//        properties.put( "keywords", "blah,test,game" );
-//        properties.put( "title", "Solitaire" );
-//
-//        Entity game1 = em.create( "game", properties );
-//        assertNotNull( game1 );
-//
-//        properties = new LinkedHashMap<String, Object>();
-//        properties.put( "keywords", "random,test" );
-//        properties.put( "title", "Hearts" );
-//
-//        Entity game2 = em.create( "game", properties );
-//        assertNotNull( game2 );
-//
-//        // simple not
-//        Query query = Query.fromQL( "select * where NOT keywords contains 'game'" );
-//        Results r = em.searchCollection( em.getApplicationRef(), "games", query );
-//        assertEquals( 1, r.size() );
-//
-//        // full negation in simple
-//        query = Query.fromQL( "select * where NOT keywords contains 'test'" );
-//        r = em.searchCollection( em.getApplicationRef(), "games", query );
-//        assertEquals( 0, r.size() );
-//
-//        // simple subtraction
-//        query = Query.fromQL( "select * where keywords contains 'test' AND NOT keywords contains 'random'" );
-//        r = em.searchCollection( em.getApplicationRef(), "games", query );
-//        assertEquals( 1, r.size() );
-//
-//        // disjoint or
-//        query = Query.fromQL( "select * where keywords contains 'random' OR NOT keywords contains 'blah'" );
-//        r = em.searchCollection( em.getApplicationRef(), "games", query );
-//        assertEquals( 1, r.size() );
-//
-//        // disjoint and
-//        query = Query.fromQL( "select * where keywords contains 'random' AND NOT keywords contains 'blah'" );
-//        r = em.searchCollection( em.getApplicationRef(), "games", query );
-//        assertEquals( 1, r.size() );
-//
-//        // self canceling or
-//        query = Query.fromQL( "select * where keywords contains 'test' AND NOT keywords contains 'test'" );
-//        r = em.searchCollection( em.getApplicationRef(), "games", query );
-//        assertEquals( 0, r.size() );
-//
-//        // select all
-//        query = Query.fromQL( "select * where keywords contains 'test' OR NOT keywords contains 'test'" );
-//        r = em.searchCollection( em.getApplicationRef(), "games", query );
-//        assertEquals( 2, r.size() );
-//
-//        // null right and
-//        query = Query.fromQL( "select * where keywords contains 'test' AND NOT keywords contains 'foobar'" );
-//        r = em.searchCollection( em.getApplicationRef(), "games", query );
-//        assertEquals( 2, r.size() );
-//
-//        // null left and
-//        query = Query.fromQL( "select * where keywords contains 'foobar' AND NOT keywords contains 'test'" );
-//        r = em.searchCollection( em.getApplicationRef(), "games", query );
-//        assertEquals( 0, r.size() );
-//    }
-//
-//
-//    @Test
-//    public void testKeywordsOrQuery() throws Exception {
-//        LOG.info( "testKeywordsOrQuery" );
-//
-//        UUID applicationId = setup.createApplication( "testOrganization", "testKeywordsOrQuery" );
-//        assertNotNull( applicationId );
-//
-//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
-//        assertNotNull( em );
-//
-//        Map<String, Object> properties = new LinkedHashMap<String, Object>();
-//        properties.put( "title", "Galactians 2" );
-//        properties.put( "keywords", "Hot, Space Invaders, Classic" );
-//        em.create( "game", properties );
-//
-//        properties = new LinkedHashMap<String, Object>();
-//        properties.put( "title", "Bunnies Extreme" );
-//        properties.put( "keywords", "Hot, New" );
-//        em.create( "game", properties );
-//
-//        properties = new LinkedHashMap<String, Object>();
-//        properties.put( "title", "Hot Shots" );
-//        properties.put( "keywords", "Action, New" );
-//        em.create( "game", properties );
-//
-//        Query query = Query.fromQL( "select * where keywords contains 'hot' or title contains 'hot'" );
-//        Results r = em.searchCollection( em.getApplicationRef(), "games", query );
-//        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
-//        assertEquals( 3, r.size() );
-//    }
-//
-//
-//    @Test
-//    public void testKeywordsAndQuery() throws Exception {
-//        LOG.info( "testKeywordsOrQuery" );
-//
-//        UUID applicationId = setup.createApplication( "testOrganization", "testKeywordsAndQuery" );
-//        assertNotNull( applicationId );
-//
-//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
-//        assertNotNull( em );
-//
-//        Map<String, Object> properties = new LinkedHashMap<String, Object>();
-//        properties.put( "title", "Galactians 2" );
-//        properties.put( "keywords", "Hot, Space Invaders, Classic" );
-//        Entity firstGame = em.create( "game", properties );
-//
-//        properties = new LinkedHashMap<String, Object>();
-//        properties.put( "title", "Bunnies Extreme" );
-//        properties.put( "keywords", "Hot, New" );
-//        Entity secondGame = em.create( "game", properties );
-//
-//        properties = new LinkedHashMap<String, Object>();
-//        properties.put( "title", "Hot Shots Extreme" );
-//        properties.put( "keywords", "Action, New" );
-//        Entity thirdGame = em.create( "game", properties );
-//
-//        Query query = Query.fromQL( "select * where keywords contains 'new' and title contains 'extreme'" );
-//        Results r = em.searchCollection( em.getApplicationRef(), "games", query );
-//        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
-//        assertEquals( 2, r.size() );
-//
-//        assertEquals( secondGame.getUuid(), r.getEntities().get( 0 ).getUuid() );
-//        assertEquals( thirdGame.getUuid(), r.getEntities().get( 1 ).getUuid() );
-//    }
-//
-//
-//    @Test
-//    public void pagingAfterDelete() throws Exception {
-//
-//        UUID applicationId = setup.createApplication( "testOrganization", "pagingAfterDelete" );
-//        assertNotNull( applicationId );
-//
-//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
-//        assertNotNull( em );
-//
-//        int size = 20;
-//        List<UUID> entityIds = new ArrayList<UUID>();
-//
-//        for ( int i = 0; i < size; i++ ) {
-//            Map<String, Object> properties = new LinkedHashMap<String, Object>();
-//            properties.put( "name", "object" + i );
-//            Entity created = em.create( "objects", properties );
-//
-//            entityIds.add( created.getUuid() );
-//        }
-//
-//        Query query = new Query();
-//        query.setLimit( 50 );
-//
-//        Results r = em.searchCollection( em.getApplicationRef(), "objects", query );
-//
-//        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
-//
-//        assertEquals( size, r.size() );
-//
-//        // check they're all the same before deletion
-//        for ( int i = 0; i < size; i++ ) {
-//            assertEquals( entityIds.get( i ), r.getEntities().get( i ).getUuid() );
-//        }
-//
-//        // now delete 5 items that will span the 10 pages
-//        for ( int i = 5; i < 10; i++ ) {
-//            Entity entity = r.getEntities().get( i );
-//            em.delete( entity );
-//            entityIds.remove( entity.getUuid() );
-//        }
-//
-//        // now query with paging
-//        query = new Query();
-//
-//        r = em.searchCollection( em.getApplicationRef(), "objects", query );
-//
-//        assertEquals( 10, r.size() );
-//
-//        for ( int i = 0; i < 10; i++ ) {
-//            assertEquals( entityIds.get( i ), r.getEntities().get( i ).getUuid() );
-//        }
-//
-//        // try the next page, set our cursor, it should be the last 5 entities
-//        query = new Query();
-//        query.setCursor( r.getCursor() );
-//
-//        r = em.searchCollection( em.getApplicationRef(), "objects", query );
-//
-//        assertEquals( 5, r.size() );
-//        for ( int i = 10; i < 15; i++ ) {
-//            assertEquals( entityIds.get( i ), r.getEntities().get( i - 10 ).getUuid() );
-//        }
-//    }
-//
-//
-//    @Test
-//    public void pagingLessThanWithCriteria() throws Exception {
-//
-//        UUID applicationId = setup.createApplication( "testOrganization", "pagingLessThanWithCriteria" );
-//        assertNotNull( applicationId );
-//
-//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
-//        assertNotNull( em );
-//
-//        int size = 40;
-//        List<UUID> entityIds = new ArrayList<UUID>();
-//
-//        for ( int i = 0; i < size; i++ ) {
-//            Map<String, Object> properties = new LinkedHashMap<String, Object>();
-//            properties.put( "index", i );
-//            Entity created = em.create( "page", properties );
-//
-//            entityIds.add( created.getUuid() );
-//        }
-//
-//        int pageSize = 10;
-//
-//        Query query = new Query();
-//        query.setLimit( pageSize );
-//        query.addFilter( "index < " + size * 2 );
-//
-//        Results r = null;
-//
-//        // check they're all the same before deletion
-//        for ( int i = 0; i < size / pageSize; i++ ) {
-//
-//            r = em.searchCollection( em.getApplicationRef(), "pages", query );
-//
-//            LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
-//
-//            assertEquals( pageSize, r.size() );
-//
-//            for ( int j = 0; j < pageSize; j++ ) {
-//                assertEquals( entityIds.get( i * pageSize + j ), r.getEntities().get( j ).getUuid() );
-//            }
-//
-//            query.setCursor( r.getCursor() );
-//        }
-//
-//        //check our last search
-//        r = em.searchCollection( em.getApplicationRef(), "pages", query );
-//
-//        assertEquals( 0, r.size() );
-//
-//        assertNull( r.getCursor() );
-//    }
-//
-//
-//    @Test
-//    public void pagingGreaterThanWithCriteria() throws Exception {
-//
-//        UUID applicationId = setup.createApplication( "testOrganization", "pagingGreaterThanWithCriteria" );
-//        assertNotNull( applicationId );
-//
-//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
-//        assertNotNull( em );
-//
-//        int size = 40;
-//        List<UUID> entityIds = new ArrayList<UUID>();
-//
-//        for ( int i = 0; i < size; i++ ) {
-//            Map<String, Object> properties = new LinkedHashMap<String, Object>();
-//            properties.put( "index", i );
-//            Entity created = em.create( "page", properties );
-//
-//            entityIds.add( created.getUuid() );
-//        }
-//
-//        int pageSize = 10;
-//
-//        Query query = new Query();
-//        query.setLimit( pageSize );
-//        query.addFilter( "index >= " + size / 2 );
-//
-//        Results r = null;
-//
-//        // check they're all the same before deletion
-//        for ( int i = 2; i < size / pageSize; i++ ) {
-//
-//            r = em.searchCollection( em.getApplicationRef(), "pages", query );
-//
-//            LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
-//
-//            assertEquals( pageSize, r.size() );
-//
-//            for ( int j = 0; j < pageSize; j++ ) {
-//                assertEquals( entityIds.get( i * pageSize + j ), r.getEntities().get( j ).getUuid() );
-//            }
-//
-//            query.setCursor( r.getCursor() );
-//        }
-//
-//        r = em.searchCollection( em.getApplicationRef(), "pages", query );
-//
-//        assertEquals( 0, r.size() );
-//
-//        assertNull( r.getCursor() );
-//    }
-//
-//
-//    @Test
-//    public void pagingWithBoundsCriteria() throws Exception {
-//
-//        UUID applicationId = setup.createApplication( "testOrganization", "pagingWithBoundsCriteria" );
-//        assertNotNull( applicationId );
-//
-//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
-//        assertNotNull( em );
-//
-//        int size = 40;
-//        List<UUID> entityIds = new ArrayList<UUID>();
-//
-//        for ( int i = 0; i < size; i++ ) {
-//            Map<String, Object> properties = new LinkedHashMap<String, Object>();
-//            properties.put( "index", i );
-//            Entity created = em.create( "page", properties );
-//
-//            entityIds.add( created.getUuid() );
-//        }
-//
-//        int pageSize = 10;
-//
-//        Query query = new Query();
-//        query.setLimit( pageSize );
-//        query.addFilter( "index >= 10" );
-//        query.addFilter( "index <= 29" );
-//
-//        Results r = null;
-//
-//        // check they're all the same before deletion
-//        for ( int i = 1; i < 3; i++ ) {
-//
-//            r = em.searchCollection( em.getApplicationRef(), "pages", query );
-//
-//            LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
-//
-//            assertEquals( pageSize, r.size() );
-//
-//            for ( int j = 0; j < pageSize; j++ ) {
-//                assertEquals( entityIds.get( i * pageSize + j ), r.getEntities().get( j ).getUuid() );
-//            }
-//
-//            query.setCursor( r.getCursor() );
-//        }
-//
-//        r = em.searchCollection( em.getApplicationRef(), "pages", query );
-//
-//        assertEquals( 0, r.size() );
-//
-//        assertNull( r.getCursor() );
-//    }
-//
-//
-//    @Test
-//    public void testPagingWithGetNextResults() throws Exception {
-//
-//        UUID applicationId = setup.createApplication( "testOrganization", "pagingWithBoundsCriteria2" );
-//        assertNotNull( applicationId );
-//
-//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
-//        assertNotNull( em );
-//
-//        int size = 40;
-//        List<UUID> entityIds = new ArrayList<UUID>();
-//
-//        for ( int i = 0; i < size; i++ ) {
-//            Map<String, Object> properties = new LinkedHashMap<String, Object>();
-//            properties.put( "index", i );
-//            Entity created = em.create( "page", properties );
-//
-//            entityIds.add( created.getUuid() );
-//        }
-//
-//        int pageSize = 10;
-//
-//        Query query = new Query();
-//        query.setLimit( pageSize );
-//        query.addFilter( "index >= 10" );
-//        query.addFilter( "index <= 29" );
-//
-//        Results r = em.searchCollection( em.getApplicationRef(), "pages", query );
-//
-//        // check they're all the same before deletion
-//        for ( int i = 1; i < 3; i++ ) {
-//
-//            LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
-//
-//            assertEquals( pageSize, r.size() );
-//
-//            for ( int j = 0; j < pageSize; j++ ) {
-//                assertEquals( entityIds.get( i * pageSize + j ), r.getEntities().get( j ).getUuid() );
-//            }
-//
-//            r = r.getNextPageResults();
-//        }
-//
-//        assertEquals( 0, r.size() );
-//        assertNull( r.getCursor() );
-//    }
-//
-//
-//    @Test
-//    public void subpropertyQuerying() throws Exception {
-//        Map<String, Object> root = new HashMap<String, Object>();
-//
-//        Map<String, Object> subEntity = new HashMap<String, Object>();
-//
-//        root.put( "rootprop1", "simpleprop" );
-//
-//        subEntity.put( "intprop", 10 );
-//        subEntity.put( "substring", "I'm a tokenized string that should be indexed" );
-//
-//        root.put( "subentity", subEntity );
-//
-//        UUID applicationId = setup.createApplication( "testOrganization", "subpropertyQuerying" );
-//        assertNotNull( applicationId );
-//
-//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
-//        assertNotNull( em );
-//
-//        Entity saved = em.create( "test", root );
-//
-//        Query query = new Query();
-//        query.addEqualityFilter( "rootprop1", "simpleprop" );
-//
-//        Results results = em.searchCollection( em.getApplicationRef(), "tests", query );
-//
-//        Entity entity = results.getEntitiesMap().get( saved.getUuid() );
-//
-//        assertNotNull( entity );
-//
-//        // query on the nested int value
-//        query = new Query();
-//        query.addEqualityFilter( "subentity.intprop", 10 );
-//
-//        results = em.searchCollection( em.getApplicationRef(), "tests", query );
-//
-//        entity = results.getEntitiesMap().get( saved.getUuid() );
-//
-//        assertNotNull( entity );
-//
-//        // query on the nexted tokenized value
-//        query = new Query();
-//        query.addContainsFilter( "subentity.substring", "tokenized" );
-//        query.addContainsFilter( "subentity.substring", "indexed" );
-//
-//        results = em.searchCollection( em.getApplicationRef(), "tests", query );
-//
-//        entity = results.getEntitiesMap().get( saved.getUuid() );
-//
-//        assertNotNull( entity );
-//    }
-//
-//
-//    @Test
-//    public void arrayQuerying() throws Exception {
-//
-//        Map<String, Object> root = new HashMap<String, Object>();
-//
-//        root.put( "intprop", 10 );
-//        root.put( "array", new String[] { "val1", "val2", "val3 with spaces" } );
-//
-//        Map<String, Object> jsonData = ( Map<String, Object> ) JsonUtils.parse( JsonUtils.mapToJsonString( root ) );
-//
-//        UUID applicationId = setup.createApplication( "testOrganization", "arrayQuerying" );
-//        assertNotNull( applicationId );
-//
-//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
-//        assertNotNull( em );
-//
-//        Entity saved = em.create( "test", jsonData );
-//
-//        Query query = new Query();
-//        query.addEqualityFilter( "intprop", 10 );
-//
-//        Results results = em.searchCollection( em.getApplicationRef(), "tests", query );
-//
-//        Entity entity = results.getEntitiesMap().get( saved.getUuid() );
-//
-//        assertNotNull( entity );
-//
-//        // query on the nested int value
-//        query = new Query();
-//        query.addEqualityFilter( "array", "val1" );
-//
-//        results = em.searchCollection( em.getApplicationRef(), "tests", query );
-//
-//        entity = results.getEntitiesMap().get( saved.getUuid() );
-//
-//        assertNotNull( entity );
-//
-//        // query on the nexted tokenized value
-//        query = new Query();
-//        query.addEqualityFilter( "array", "val2" );
-//
-//        results = em.searchCollection( em.getApplicationRef(), "tests", query );
-//
-//        entity = results.getEntitiesMap().get( saved.getUuid() );
-//
-//        assertNotNull( entity );
-//
-//        query = new Query();
-//        query.addEqualityFilter( "array", "val3" );
-//
-//        results = em.searchCollection( em.getApplicationRef(), "tests", query );
-//
-//        entity = results.getEntitiesMap().get( saved.getUuid() );
-//
-//        assertNull( entity );
-//
-//        query = new Query();
-//        query.addContainsFilter( "array", "spaces" );
-//        results = em.searchCollection( em.getApplicationRef(), "tests", query );
-//
-//        entity = results.getEntitiesMap().get( saved.getUuid() );
-//
-//        assertNotNull( entity );
-//    }
-//
-//
-//    @Test
-//    public void stringWithSpaces() throws Exception {
-//        Map<String, Object> props = new HashMap<String, Object>();
-//
-//        props.put( "myString", "My simple string" );
-//
-//        UUID applicationId = setup.createApplication( "testOrganization", "stringWithSpaces" );
-//        assertNotNull( applicationId );
-//
-//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
-//        assertNotNull( em );
-//
-//        Entity saved = em.create( "test", props );
-//
-//        Query query = new Query();
-//        query.addEqualityFilter( "myString", "My simple string" );
-//
-//        Results results = em.searchCollection( em.getApplicationRef(), "tests", query );
-//
-//        Entity entity = results.getEntitiesMap().get( saved.getUuid() );
-//
-//        assertNotNull( entity );
-//    }
-//
-//
-//    @Test
-//    public void testSelectTerms() throws Exception {
-//
-//        UUID applicationId = setup.createApplication( "testOrganization", "testSelectTerms" );
-//
-//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
-//
-//        Map<String, Object> properties = new LinkedHashMap<String, Object>();
-//        properties.put( "username", "edanuff" );
-//        properties.put( "email", "ed@anuff.com" );
-//
-//        em.create( "user", properties );
-//
-//        String s = "select username, email where username = 'edanuff'";
-//        Query query = Query.fromQL( s );
-//
-//        Results r = em.searchCollection( em.getApplicationRef(), "users", query );
-//        assertTrue( r.size() == 1 );
-//
-//        // selection results should be a list of lists
-//        List<Object> sr = query.getSelectionResults( r );
-//        assertTrue( sr.size() == 1 );
-//
-//        List firstResult = ( List ) sr.get( 0 );
-//        assertTrue( "edanuff".equals( firstResult.get( 0 ) ) );
-//        assertTrue( "ed@anuff.com".equals( firstResult.get( 1 ) ) );
-//    }
-//
-//
-//    @Test
-//    public void testRedefineTerms() throws Exception {
-//
-//        UUID applicationId = setup.createApplication( "testOrganization", "testRedefineTerms" );
-//
-//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
-//
-//        Map<String, Object> properties = new LinkedHashMap<String, Object>();
-//        properties.put( "username", "edanuff" );
-//        properties.put( "email", "ed@anuff.com" );
-//
-//        em.create( "user", properties );
-//
-//        String s = "select {name: username, email: email} where username = 'edanuff'";
-//        Query query = Query.fromQL( s );
-//
-//        Results r = em.searchCollection( em.getApplicationRef(), "users", query );
-//        assertTrue( r.size() == 1 );
-//
-//        // selection results should be a list of lists
-//        List<Object> sr = query.getSelectionResults( r );
-//        assertTrue( sr.size() == 1 );
-//
-//        Map firstResult = ( Map ) sr.get( 0 );
-//        assertTrue( "edanuff".equals( firstResult.get( "name" ) ) );
-//        assertTrue( "ed@anuff.com".equals( firstResult.get( "email" ) ) );
-//    }
-//
-//
-//    @Test
-//    public void testSelectEmailViaConnection() throws Exception {
-//
-//        UUID applicationId = setup.createApplication( "testOrganization", "testSelectEmail" );
-//
-//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
-//
-//        Map<String, Object> properties = new LinkedHashMap<String, Object>();
-//        properties.put( "username", "ed@anuff.com" );
-//        properties.put( "email", "ed@anuff.com" );
-//
-//        em.create( "user", properties );
-//
-//        String s = "select * where username = 'ed@anuff.com'";
-//        Query query = Query.fromQL( s );
-//
-//        Results r = em.searchCollection( em.getApplicationRef(), "users", query );
-//        assertTrue( r.size() == 1 );
-//
-//        // selection results should be a list of lists
-//        Entity entity = r.getEntity();
-//
-//        assertTrue( "ed@anuff.com".equals( entity.getProperty( "username" ) ) );
-//        assertTrue( "ed@anuff.com".equals( entity.getProperty( "email" ) ) );
-//
-//        // now create a role and connect it
-//        properties = new LinkedHashMap<String, Object>();
-//        properties.put( "name", "test" );
-//
-//        Entity foo = em.create( "foo", properties );
-//
-//        em.createConnection( foo, "testconnection", entity );
-//
-//        // now query via the testConnection, this should work
-//
-//        query = Query.fromQL( s );
-//        query.setConnectionType( "testconnection" );
-//        query.setEntityType( "user" );
-//
-//        r = em.searchConnectedEntities( foo, query );
-//
-//        assertEquals( "connection must match", 1, r.size() );
-//
-//        // selection results should be a list of lists
-//        entity = r.getEntity();
-//        assertTrue( "ed@anuff.com".equals( entity.getProperty( "username" ) ) );
-//        assertTrue( "ed@anuff.com".equals( entity.getProperty( "email" ) ) );
-//    }
-//
-//
-//    @Test
-//    public void testNotQueryAnd() throws Exception {
-//
-//        UUID applicationId = setup.createApplication( "testOrganization", "testNotQueryAnd" );
-//
-//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
-//
-//        Map<String, Object> location = new LinkedHashMap<String, Object>();
-//        location.put( "Place", "24 Westminster Avenue, Venice, CA 90291, USA" );
-//        location.put( "Longitude", -118.47425979999998 );
-//        location.put( "Latitude", 33.9887663 );
-//
-//        Map<String, Object> recipient = new LinkedHashMap<String, Object>();
-//        recipient.put( "TimeRequested", 1359077878l );
-//        recipient.put( "Username", "fb_536692245" );
-//        recipient.put( "Location", location );
-//
-//        Map<String, Object> properties = new LinkedHashMap<String, Object>();
-//        properties.put( "Flag", "requested" );
-//        properties.put( "Recipient", recipient );
-//
-//        em.create( "loveobject", properties );
-//
-//        location = new LinkedHashMap<String, Object>();
-//        location.put( "Place", "Via Pietro Maroncelli, 48, 62012 Santa Maria Apparente Province of Macerata, Italy" );
-//        location.put( "Longitude", 13.693080199999999 );
-//        location.put( "Latitude", 43.2985019 );
-//
-//        recipient = new LinkedHashMap<String, Object>();
-//        recipient.put( "TimeRequested", 1359077878l );
-//        recipient.put( "Username", "fb_100000787138041" );
-//        recipient.put( "Location", location );
-//
-//        properties = new LinkedHashMap<String, Object>();
-//        properties.put( "Flag", "requested" );
-//        properties.put( "Recipient", recipient );
-//
-//        em.create( "loveobject", properties );
-//
-//        // String s = "select * where Flag = 'requested'";
-//        // String s =
-//        // "select * where Flag = 'requested' and NOT Recipient.Username = 'fb_536692245' order by created asc";
-//        String s = "select * where Flag = 'requested' and NOT Recipient.Username = 'fb_536692245' order by created asc";
-//        Query query = Query.fromQL( s );
-//
-//        Results r = em.searchCollection( em.getApplicationRef(), "loveobjects", query );
-//        assertTrue( r.size() == 1 );
-//
-//        String username = ( String ) ( ( Map ) r.getEntities().get( 0 ).getProperty( "Recipient" ) ).get( "Username" );
-//        // selection results should be a list of lists
-//        List<Object> sr = query.getSelectionResults( r );
-//        assertTrue( sr.size() == 1 );
-//
-//        assertEquals( "fb_100000787138041", username );
-//    }
-//
-//
-//    @Test
-//    public void runtimeTypeCorrect() throws Exception {
-//
-//        UUID applicationId = setup.createApplication( "testOrganization", "runtimeTypeCorrect" );
-//        assertNotNull( applicationId );
-//
-//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
-//        assertNotNull( em );
-//
-//        int size = 20;
-//        List<User> createdEntities = new ArrayList<User>();
-//
-//        for ( int i = 0; i < size; i++ ) {
-//            User user = new User();
-//            user.setEmail( String.format( "test%d@usergrid.com", i ) );
-//            user.setUsername( String.format( "test%d", i ) );
-//            user.setName( String.format( "test%d", i ) );
-//
-//            User created = em.create( user );
-//
-//            createdEntities.add( created );
-//        }
-//
-//        Results r = em.getCollection( em.getApplicationRef(), "users", null, 50, Level.ALL_PROPERTIES, false );
-//
-//        LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
-//
-//        assertEquals( size, r.size() );
-//
-//        // check they're all the same before deletion
-//        for ( int i = 0; i < size; i++ ) {
-//            assertEquals( createdEntities.get( i ).getUuid(), r.getEntities().get( i ).getUuid() );
-//            assertTrue( r.getEntities().get( i ) instanceof User );
-//        }
-//    }
-//
-//
-//    @Test
-//    public void badOrderByBadGrammarAsc() throws Exception {
-//
-//        UUID applicationId = setup.createApplication( "testOrganization", "badOrderByBadGrammarAsc" );
-//        assertNotNull( applicationId );
-//
-//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
-//        assertNotNull( em );
-//
-//        String s = "select * where name = 'bob' order by asc";
-//
-//        String error = null;
-//        String entityType = null;
-//        String propertyName = null;
-//
-//        try {
-//            em.searchCollection( em.getApplicationRef(), "users", Query.fromQL( s ) );
-//            fail( "I should throw an exception" );
-//        }
-//        catch ( NoIndexException nie ) {
-//            error = nie.getMessage();
-//            entityType = nie.getEntityType();
-//            propertyName = nie.getPropertyName();
-//        }
-//
-//        assertEquals( "Entity 'user' with property named '' is not indexed.  You cannot use the this field in queries.",
-//                error );
-//        assertEquals( "user", entityType );
-//        assertEquals( "", propertyName );
-//    }
-//
-//
-//    @Test
-//    public void badOrderByBadGrammarDesc() throws Exception {
-//        UUID applicationId = setup.createApplication( "testOrganization", "badOrderByBadGrammarDesc" );
-//        assertNotNull( applicationId );
-//
-//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
-//        assertNotNull( em );
-//
-//        String s = "select * where name = 'bob' order by desc";
-//
-//        String error = null;
-//        String entityType = null;
-//        String propertyName = null;
-//
-//
-//        try {
-//            em.searchCollection( em.getApplicationRef(), "users", Query.fromQL( s ) );
-//            fail( "I should throw an exception" );
-//        }
-//        catch ( NoIndexException nie ) {
-//            error = nie.getMessage();
-//            entityType = nie.getEntityType();
-//            propertyName = nie.getPropertyName();
-//        }
-//
-//        assertEquals( "Entity 'user' with property named '' is not indexed.  You cannot use the this field in queries.",
-//                error );
-//        assertEquals( "user", entityType );
-//        assertEquals( "", propertyName );
-//    }
-//
-//
-//    @Test
-//    public void uuidIdentifierTest() throws Exception {
-//        UUID applicationId = setup.createApplication( "testOrganization", "uuidIdentifierTest" );
-//        assertNotNull( applicationId );
-//
-//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
-//        assertNotNull( em );
-//
-//        Map<String, Object> properties = new LinkedHashMap<String, Object>();
-//        properties.put( "keywords", "blah,test,game" );
-//        properties.put( "title", "Solitaire" );
-//
-//        Entity game1 = em.create( "game", properties );
-//        assertNotNull( game1 );
-//
-//        //we create 2 entities, otherwise this test will pass when it shouldn't
-//        Entity game2 = em.create( "game", properties );
-//        assertNotNull( game2 );
-//
-//
-//        // overlap
-//        Query query = new Query();
-//        query.addIdentifier( Identifier.fromUUID( game1.getUuid() ) );
-//        Results r = em.searchCollection( em.getApplicationRef(), "games", query );
-//        assertEquals( "We should only get 1 result", 1, r.size() );
-//        assertNull( "No cursor should be present", r.getCursor() );
-//
-//        assertEquals( "Saved entity returned", game1, r.getEntity() );
-//    }
-//
-//
-//    @Test
-//    public void nameIdentifierTest() throws Exception {
-//        UUID applicationId = setup.createApplication( "testOrganization", "nameIdentifierTest" );
-//        assertNotNull( applicationId );
-//
-//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
-//        assertNotNull( em );
-//
-//        Map<String, Object> properties = new LinkedHashMap<String, Object>();
-//        properties.put( "keywords", "blah,test,game" );
-//        properties.put( "title", "Solitaire" );
-//        properties.put( "name", "test" );
-//
-//        Entity game1 = em.create( "games", properties );
-//        assertNotNull( game1 );
-//
-//        //we create 2 entities, otherwise this test will pass when it shouldn't
-//        properties.put( "name", "test2" );
-//        Entity game2 = em.create( "game", properties );
-//        assertNotNull( game2 );
-//
-//        // overlap
-//        Query query = new Query();
-//        query.addIdentifier( Identifier.fromName( "test" ) );
-//        Results r = em.searchCollection( em.getApplicationRef(), "games", query );
-//        assertEquals( "We should only get 1 result", 1, r.size() );
-//        assertNull( "No cursor should be present", r.getCursor() );
-//
-//        assertEquals( "Saved entity returned", game1, r.getEntity() );
-//    }
-//
-//
-//    @Test
-//    public void emailIdentifierTest() throws Exception {
-//        UUID applicationId = setup.createApplication( "testOrganization", "emailIdentifierTest" );
-//        assertNotNull( applicationId );
-//
-//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
-//        assertNotNull( em );
-//
-//        User user = new User();
-//        user.setUsername( "foobar" );
-//        user.setEmail( "foobar@usergrid.org" );
-//
-//        Entity createUser = em.create( user );
-//        assertNotNull( createUser );
-//
-//        //we create 2 entities, otherwise this test will pass when it shouldn't
-//        User user2 = new User();
-//        user2.setUsername( "foobar2" );
-//        user2.setEmail( "foobar2@usergrid.org" );
-//        Entity createUser2 = em.create( user2 );
-//        assertNotNull( createUser2 );
-//
-//        // overlap
-//        Query query = new Query();
-//        query.addIdentifier( Identifier.fromEmail( "foobar@usergrid.org" ) );
-//        Results r = em.searchCollection( em.getApplicationRef(), "users", query );
-//        assertEquals( "We should only get 1 result", 1, r.size() );
-//        assertNull( "No cursor should be present", r.getCursor() );
-//
-//        assertEquals( "Saved entity returned", createUser, r.getEntity() );
-//    }
-//
-//
-//    @Test(expected = DuplicateUniquePropertyExistsException.class)
-//    public void duplicateIdentifierTest() throws Exception {
-//        UUID applicationId = setup.createApplication( "testOrganization", "duplicateIdentifierTest" );
-//        assertNotNull( applicationId );
-//
-//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
-//        assertNotNull( em );
-//
-//        User user = new User();
-//        user.setUsername( "foobar" );
-//        user.setEmail( "foobar@usergrid.org" );
-//
-//        Entity createUser = em.create( user );
-//        assertNotNull( createUser );
-//
-//        //we create 2 entities, otherwise this test will pass when it shouldn't
-//        User user2 = new User();
-//        user2.setUsername( "foobar" );
-//        user2.setEmail( "foobar@usergrid.org" );
-//        em.create( user2 );
-//    }
-//
-//
-//    @Test(expected = DuplicateUniquePropertyExistsException.class)
-//    public void duplicateNameTest() throws Exception {
-//        UUID applicationId = setup.createApplication( "testOrganization", "duplicateNameTest" );
-//        assertNotNull( applicationId );
-//
-//        EntityManager em = setup.getEmf().getEntityManager( applicationId );
-//        assertNotNull( em );
-//
-//        DynamicEntity restaurant = new DynamicEntity();
-//        restaurant.setName( "4peaks" );
-//
-//        Entity createdRestaurant = em.create( "restaurant", restaurant.getProperties() );
-//        assertNotNull( createdRestaurant );
-//
-//
-//        //we create 2 entities, otherwise this test will pass when it shouldn't
-//        DynamicEntity restaurant2 = new DynamicEntity();
-//        restaurant2.setName( "4peaks" );
-//
-//        em.create( "restaurant", restaurant2.getProperties() );
-//    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5eaf05ac/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/GeoIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/GeoIT.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/GeoIT.java
deleted file mode 100644
index f7db4a4..0000000
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/GeoIT.java
+++ /dev/null
@@ -1,554 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence;
-
-import com.google.inject.Inject;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
-import org.apache.usergrid.persistence.collection.cassandra.CassandraRule;
-import org.apache.usergrid.persistence.collection.guice.MigrationManagerRule;
-import org.apache.usergrid.test.Point;
-import org.apache.usergrid.persistence.index.EntityCollectionIndexFactory;
-import org.apache.usergrid.persistence.index.guice.IndexTestModule;
-import org.apache.usergrid.persistence.model.entity.Entity;
-import org.apache.usergrid.persistence.model.entity.Id;
-import org.apache.usergrid.persistence.model.entity.SimpleId;
-import org.apache.usergrid.persistence.query.EntityRef;
-import org.apache.usergrid.persistence.query.Query;
-import org.apache.usergrid.persistence.query.Results;
-import org.apache.usergrid.persistence.query.SimpleEntityRef;
-import org.apache.usergrid.persistence.utils.MapUtils;
-import org.apache.usergrid.test.CoreApplication;
-import org.apache.usergrid.test.CoreITSetup;
-import org.apache.usergrid.test.CoreITSetupImpl;
-import org.apache.usergrid.test.EntityManagerFacade;
-import org.jukito.JukitoRunner;
-import org.jukito.UseModules;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-@RunWith(JukitoRunner.class)
-@UseModules({ IndexTestModule.class })
-public class GeoIT {
-    private static final Logger LOG = LoggerFactory.getLogger( GeoIT.class );
-
-    @ClassRule
-    public static CassandraRule cass = new CassandraRule();
-
-    @Inject
-    @Rule
-    public MigrationManagerRule migrationManagerRule;
-    
-    @ClassRule
-    public static CoreITSetup setup = new CoreITSetupImpl();
-
-    @Rule
-    public CoreApplication app = new CoreApplication( setup );
-
-    @Inject
-    public EntityCollectionManagerFactory collectionManagerFactory;
-    
-    @Inject
-    public EntityCollectionIndexFactory collectionIndexFactory;
-
-    public GeoIT() {
-        super();
-    }
-
-
-    @Test
-    public void testGeo() throws Exception {
-        LOG.info( "GeoIT.testGeo" );
-
-        Id appId = new SimpleId("testGeo");
-        Id orgId = new SimpleId("testOrganization");
-        EntityManagerFacade em = new EntityManagerFacade( orgId, appId, 
-            collectionManagerFactory, collectionIndexFactory );
-        assertNotNull( em );
-
-		// Two intersections two blocks apart
-        final Point folsomAnd7th =    new Point( 37.774277, -122.404744 );
-        final Point folsomAndBryant = new Point( 37.776753, -122.407846 );
-
-		// and about 50 kilometers away...
-		// 260 Sheridan Ave, Palo Alto, CA
-	 	final Point paloalto = new Point( 37.426373, -122.14108 ); 
-
-        Map<String, Object> properties = new LinkedHashMap<String, Object>() {{
-            put( "username", "edanuff" );
-            put( "email", "ed@anuff.com" );
-            put( "location", new HashMap<String, Object>() {{
-                put("latitude", folsomAndBryant.getLat() );
-                put("longitude", folsomAndBryant.getLon() );
-            }});
-        }};
-	
-        Entity user = em.create( "user", properties );
-        assertNotNull( user );
-		LOG.info( user.toString() );
-
-		// Folsom and 7th more than 100 meters from Folson and Bryant
-		Query q = Query.fromQL("location within 100 of " 
-			+ folsomAnd7th.getLat() + "," + folsomAnd7th.getLon() + " limit 100");
-		Results results = em.searchCollection(null, "users", q);
-        assertEquals( 0, results.size() );
-
-		// but within 400 meters
-		q = Query.fromQL("location within 400 of " 
-			+ folsomAnd7th.getLat() + "," + folsomAnd7th.getLon() + " limit 100");
-		results = em.searchCollection(null, "users", q);
-        assertEquals( 1, results.size() );
-
-		// move user to Palo Alto, 50km away 
-        updatePos( em, new SimpleEntityRef( user.getId(), user.getVersion() ), 
-			paloalto.getLat(), paloalto.getLon() );
-
-		// user no longer within 200m of that San Francico intersection  
-		q = Query.fromQL("location within 200 of " + folsomAndBryant.getLat() 
-				+ "," + folsomAndBryant.getLon() + " limit 100");
-		results = em.searchCollection(null, "users", q);
-        assertEquals( 0, results.size() );
-
-		// move user to the other SF intersection
-        updatePos( em, user, folsomAnd7th.getLat(), folsomAnd7th.getLon() );
-
-		// now they are close to Folsom and Bryant
-		q = Query.fromQL("location within 1000 of " 
-				+ folsomAndBryant.getLat() + "," + folsomAndBryant.getLon() + " limit 100");
-		results = em.searchCollection(null, "users", q);
-        assertEquals( 1, results.size() );
-
-        // check at globally large distance
-		q = Query.fromQL("location within " + Integer.MAX_VALUE + " of " 
-				+ folsomAndBryant.getLat() + "," + folsomAndBryant.getLon() + " limit 100");
-		results = em.searchCollection(null, "users", q);
-        assertEquals( 1, results.size() );
-
-        // create a new entity so we have 2
-        LinkedHashMap<String, Object> properties2 = new LinkedHashMap<String, Object>() {{
-        	put( "username", "sganyo" );
-        	put( "email", "sganyo@anuff.com" );
-			put( "location", new HashMap<String, Object>() {{
-				put( "latitude", 31.1 ); // 31.1, 121.2 is shanghai
-				put( "longitude", 121.2 ); 
-			}});
-		}};
-        Entity user2 = em.create( "user", properties2 );
-        assertNotNull( user2 );
-        
-		q = Query.fromQL("location within 10000 of " 
-				+ folsomAndBryant.getLat() + "," + folsomAndBryant.getLon() + " limit 100");
-		results = em.searchCollection(null, "users", q);
-
-        assertEquals( 1, results.size() );
-
-        // check at globally large distance
-		q = Query.fromQL("location within " + Integer.MAX_VALUE + " of " 
-				+ folsomAndBryant.getLat() + "," + folsomAndBryant.getLon() + " limit 100");
-		results = em.searchCollection(null, "users", q);
-		
-        assertEquals( 2, results.size() );
-
-        // check at globally large distance (center point close to other entity)
-        Point shanghai = new Point( 31.14, 121.27 );
-
-		q = Query.fromQL("location within " + Integer.MAX_VALUE + " of " 
-				+ shanghai.getLat() + "," + shanghai.getLon() + " limit 100");
-		results = em.searchCollection(null, "users", q);
-
-        assertEquals( 2, results.size() );
-
-        Results emSearchResults = em.searchCollection( em.getApplicationRef(), "users",
-            Query.fromQL( "location within 1000 of 37.776753, -122.407846" ) );
-
-        assertEquals( 1, emSearchResults.size() );
-
-        updatePos( em, user, folsomAndBryant.getLat(), folsomAndBryant.getLon());
-
-        Point paloaltoCaltran = new Point( 37.428526, -122.140916 );
-
-		q = Query.fromQL("location within 1000 of " 
-				+ paloaltoCaltran.getLat() + "," + paloaltoCaltran.getLon() + " limit 100");
-		results = em.searchCollection(null, "users", q);
-
-        assertEquals( 0, results.size() );
-
-        emSearchResults = em.searchCollection( em.getApplicationRef(), "users",
-                Query.fromQL( "location within 1000 of 37.428526, -122.140916" ) );
-        assertEquals( 0, emSearchResults.size() );
-
-        properties = new LinkedHashMap<String, Object>();
-        properties.put( "name", "Brickhouse" );
-        properties.put( "address", "426 Brannan Street" );
-        properties.put( "location", getLocation( 37.779632, -122.395131 ) );
-
-        Entity restaurant = em.create( "restaurant", properties );
-        assertNotNull( restaurant );
-
-		// TODO: update with new Core Persistence graph API
-
-//        em.createConnection( user, "likes", restaurant );
-//
-//        emSearchResults =
-//                em.searchConnectedEntities( user, Query.fromQL( "location within 2000 of 37.776753, -122.407846" ) );
-//        assertEquals( 1, emSearchResults.size() );
-//
-//        emSearchResults =
-//                em.searchConnectedEntities( user, Query.fromQL( "location within 1000 of 37.776753, -122.407846" ) );
-//        assertEquals( 0, emSearchResults.size() );
-    }
-
-
-    @Test
-    public void testPointPaging() throws Exception {
-
-        Id appId = new SimpleId("testGeo");
-        Id orgId = new SimpleId("testOrganization");
-        EntityManagerFacade em = new EntityManagerFacade( orgId, appId, 
-            collectionManagerFactory, collectionIndexFactory );
-        assertNotNull( em );
-
-        // save objects in a diagonal line from -90 -180 to 90 180
-
-        int numEntities = 50;
-
-        float minLattitude = -90;
-        float maxLattitude = 90;
-        float minLongitude = -180;
-        float maxLongitude = 180;
-
-        float lattitudeDelta = ( maxLattitude - minLattitude ) / numEntities;
-
-        float longitudeDelta = ( maxLongitude - minLongitude ) / numEntities;
-
-        for ( int i = 0; i < numEntities; i++ ) {
-            float lattitude = minLattitude + lattitudeDelta * i;
-            float longitude = minLongitude + longitudeDelta * i;
-
-            Map<String, Float> location = MapUtils.hashMap( 
-                    "latitude", lattitude ).map( "longitude", longitude );
-
-            Map<String, Object> data = new HashMap<String, Object>( 2 );
-            data.put( "name", String.valueOf( i ) );
-            data.put( "location", location );
-
-            em.create( "store", data );
-        }
-
-        // earth's circumference is 40075km; up it to 50000km, to be safe
-        Query query = new Query();
-        query.addFilter( "location within 50000000 of -90, -180" );
-        query.setLimit( 100 );
-
-        int count = 0;
-        Results results;
-
-        do {
-            results = em.searchCollection( em.getApplicationRef(), "stores", query );
-
-            for ( Entity entity : results.getEntities() ) {
-                count++;
-            }
-
-            // set for the next "page"
-            query.setCursor( results.getCursor() );
-        }
-        while ( results.getCursor() != null );
-
-        // check we got back all 500 entities
-        assertEquals( numEntities, count );
-    }
-
-
-//    @Test
-//    public void testSamePointPaging() throws Exception {
-//
-//        Id appId = new SimpleId("testGeo");
-//        Id orgId = new SimpleId("testOrganization");
-//        EntityManagerFacade em = new EntityManagerFacade( orgId, appId, 
-//            collectionManagerFactory, collectionIndexFactory );
-//        assertNotNull( em );
-//
-//        // save objects in a diagonal line from -90 -180 to 90 180
-//
-//        int numEntities = 500;
-//
-//        for ( int i = 0; i < numEntities; i++ ) {
-//            Map<String, Object> data = new HashMap<String, Object>( 2 );
-//            data.put( "name", String.valueOf( i ) );
-//            setPos( data, 0, 0 );
-//
-//            em.create( "store", data );
-//        }
-//
-//        Query query = new Query();
-//        // earth's circumference is 40,075 kilometers. Up it to 50,000kilometers
-//        // just to be save
-//        query.addFilter( "location within 50000000 of 0, 0" );
-//        query.setLimit( 100 );
-//
-//        int count = 0;
-//        Results results;
-//
-//        do {
-//            results = em.searchCollection( em.getApplicationRef(), "stores", query );
-//
-//            for ( Entity entity : results.getEntities() ) {
-//                count++;
-//            }
-//
-//            // set for the next "page"
-//            query.setCursor( results.getCursor() );
-//        }
-//        while ( results.getCursor() != null );
-//
-//        // check we got back all 500 entities
-//        assertEquals( numEntities, count );
-//    }
-
-
-//    @Test
-//    public void testDistanceByLimit() throws Exception {
-//
-//        Id appId = new SimpleId("testGeo");
-//        Id orgId = new SimpleId("testOrganization");
-//        EntityManagerFacade em = new EntityManagerFacade( orgId, appId, 
-//            collectionManagerFactory, collectionIndexFactory );
-//        assertNotNull( em );
-//
-//        // save objects in a diagonal line from -90 -180 to 90 180
-//
-//        int numEntities = 100;
-//
-//        float minLattitude = -90;
-//        float maxLattitude = 90;
-//        float minLongitude = -180;
-//        float maxLongitude = 180;
-//
-//        float lattitudeDelta = ( maxLattitude - minLattitude ) / numEntities;
-//
-//        float longitudeDelta = ( maxLongitude - minLongitude ) / numEntities;
-//
-//        for ( int i = 0; i < numEntities; i++ ) {
-//            float lattitude = minLattitude + lattitudeDelta * i;
-//            float longitude = minLongitude + longitudeDelta * i;
-//
-//            Map<String, Float> location = 
-//                    MapUtils.hashMap( "latitude", lattitude )
-//                            .map( "longitude", longitude );
-//
-//            Map<String, Object> data = new HashMap<String, Object>( 2 );
-//            data.put( "name", String.valueOf( i ) );
-//            data.put( "location", location );
-//
-//            em.create( "store", data );
-//        }
-//
-//        Query query = new Query();
-//        // earth's circumference is 40,075 kilometers. Up it to 50,000kilometers
-//        // just to be save
-//        query.addFilter( "location within 0 of -90, -180" );
-//        query.setLimit( 100 );
-//
-//        int count = 0;
-//
-//        do {
-//            Results results = em.searchCollection( em.getApplicationRef(), "stores", query );
-//
-//            for ( Entity entity : results.getEntities() ) {
-//                count++;
-//            }
-//        }
-//        while ( query.getCursor() != null );
-//
-//        // check we got back all 500 entities
-//        assertEquals( numEntities, count );
-//    }
-
-
-//    @Test
-//    public void testGeoWithIntersection() throws Exception {
-//
-//        Id appId = new SimpleId("testGeo");
-//        Id orgId = new SimpleId("testOrganization");
-//        EntityManagerFacade em = new EntityManagerFacade( orgId, appId, 
-//            collectionManagerFactory, collectionIndexFactory );
-//        assertNotNull( em );
-//
-//        int size = 100;
-//        int min = 50;
-//        int max = 90;
-//
-//        List<Entity> created = new ArrayList<Entity>( size );
-//
-//        for ( int i = 0; i < size; i++ ) {
-//
-//            // save all entities in the same location
-//            Map<String, Object> data = new HashMap<String, Object>( 2 );
-//            data.put( "name", String.valueOf( i ) );
-//            data.put( "index", i );
-//            setPos( data, 0, 0 );
-//
-//            Entity e = em.create( "store", data );
-//
-//            created.add( e );
-//        }
-//
-//        int startDelta = size - min;
-//
-//        //    String queryString = String.format("select * where location within 100 of 0,
-//        // 0 and index >= %d and index < %d order by index",min, max);
-//
-//        String queryString = String.format( 
-//                "select * where index >= %d and index < %d order by index", min, max );
-//
-//        Query query = Query.fromQL( queryString );
-//
-//        Results r;
-//        int count = 0;
-//
-//        do {
-//
-//            r = em.searchCollection( em.getApplicationRef(), "stores", query );
-//
-//            for ( Entity e : r.getEntities() ) {
-//                assertEquals( created.get( startDelta + count ), e );
-//                count++;
-//            }
-//
-//            query.setCursor( r.getCursor() );
-//        }
-//        while ( r.hasCursor() );
-//
-//        assertEquals( startDelta - ( size - max ), count );
-//    }
-
-
-//    @Test
-//    public void testDenseSearch() throws Exception {
-//
-//        Id appId = new SimpleId("testGeo");
-//        Id orgId = new SimpleId("testOrganization");
-//        EntityManagerFacade em = new EntityManagerFacade( orgId, appId, 
-//            collectionManagerFactory, collectionIndexFactory );
-//        assertNotNull( em );
-//
-//        // save objects in a diagonal line from -90 -180 to 90 180
-//
-//        int numEntities = 500;
-//
-//        float minLattitude = 48.32455f;
-//        float maxLattitude = 48.46481f;
-//        float minLongitude = 9.89561f;
-//        float maxLongitude = 10.0471f;
-//
-//        float lattitudeDelta = ( maxLattitude - minLattitude ) / numEntities;
-//
-//        float longitudeDelta = ( maxLongitude - minLongitude ) / numEntities;
-//
-//        for ( int i = 0; i < numEntities; i++ ) {
-//            float lattitude = minLattitude + lattitudeDelta * i;
-//            float longitude = minLongitude + longitudeDelta * i;
-//
-//            Map<String, Float> location = MapUtils.hashMap( "latitude", lattitude ).map( "longitude", longitude );
-//
-//            Map<String, Object> data = new HashMap<String, Object>( 2 );
-//            data.put( "name", String.valueOf( i ) );
-//            data.put( "location", location );
-//
-//            em.create( "store", data );
-//        }
-//
-//        //do a direct geo iterator test.  We need to make sure that we short circuit on the correct tile.
-//
-//        float lattitude = 48.38626f;
-//        float longtitude = 9.94175f;
-//        int distance = 1000;
-//        int limit = 8;
-//
-//
-//        QuerySlice slice = new QuerySlice( "location", 0 );
-//
-//        GeoIterator itr = new GeoIterator(
-//                new CollectionGeoSearch( em, setup.getIbl(), setup.getCassSvc(), em.getApplicationRef(), "stores" ),
-//                limit, slice, "location", new Point( lattitude, longtitude ), distance );
-//
-//
-//        // check we got back all 500 entities
-//        assertFalse( itr.hasNext() );
-//
-//        List<String> cells = itr.getLastCellsSearched();
-//
-//        assertEquals( 1, cells.size() );
-//
-//        assertEquals( 4, cells.get( 0 ).length() );
-//
-//
-//        long startTime = System.currentTimeMillis();
-//
-//        //now test at the EM level, there should be 0 results.
-//        Query query = new Query();
-//
-//        query.addFilter( "location within 1000 of 48.38626, 9.94175" );
-//        query.setLimit( 8 );
-//
-//
-//        Results results = em.searchCollection( em.getApplicationRef(), "stores", query );
-//
-//        assertEquals( 0, results.size() );
-//
-//        long endTime = System.currentTimeMillis();
-//
-//        LOG.info( "Runtime took {} milliseconds to search", endTime - startTime );
-//    }
-
-
-    public Map<String, Object> getLocation( double latitude, double longitude ) throws Exception {
-        Map<String, Object> latlong = new LinkedHashMap<String, Object>();
-        latlong.put( "latitude", latitude );
-        latlong.put( "longitude", longitude );
-        return latlong;
-    }
-
-
-    public void updatePos( EntityManagerFacade em, EntityRef ref, double lat, double lon) throws Exception {
-        em.setProperty( ref, "location", lat, lon );
-	}
-
-    public void updatePos( EntityManagerFacade em, Entity e, double lat, double lon) throws Exception {
-        em.setProperty( new SimpleEntityRef( e.getId(), e.getVersion()), "location", lat, lon );
-    }
-
-
-    public void setPos( Map<String, Object> data, double latitude, double longitude ) {
-        Map<String, Object> latlong = new LinkedHashMap<String, Object>();
-        latlong.put( "latitude", latitude );
-        latlong.put( "longitude", longitude );
-        data.put( "location", latlong );
-    }
-}