Repository: usergrid Updated Branches: refs/heads/USERGRID-872 41a6cea24 -> 41caeaa10
USERGRID-1099 - Porting new test from 1.x into latest 2.x code. Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/f7a82ba8 Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/f7a82ba8 Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/f7a82ba8 Branch: refs/heads/USERGRID-872 Commit: f7a82ba81cf49f5bdd536370f966dd0480f1edf4 Parents: c6945e3 Author: Michael Russo <[email protected]> Authored: Thu Dec 17 14:15:42 2015 -0800 Committer: Michael Russo <[email protected]> Committed: Thu Dec 17 14:15:42 2015 -0800 ---------------------------------------------------------------------- .../persistence/query/ParenthesisProblemIT.java | 81 ++++++++++++++++++++ 1 file changed, 81 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/usergrid/blob/f7a82ba8/stack/core/src/test/java/org/apache/usergrid/persistence/query/ParenthesisProblemIT.java ---------------------------------------------------------------------- diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/query/ParenthesisProblemIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/query/ParenthesisProblemIT.java new file mode 100644 index 0000000..60c1622 --- /dev/null +++ b/stack/core/src/test/java/org/apache/usergrid/persistence/query/ParenthesisProblemIT.java @@ -0,0 +1,81 @@ +/* + * 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.query; + +import org.apache.usergrid.AbstractCoreIT; +import org.apache.usergrid.persistence.EntityManager; +import org.apache.usergrid.persistence.Query; +import org.apache.usergrid.persistence.Results; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashMap; + +import static org.junit.Assert.assertEquals; + + +// Created for https://issues.apache.org/jira/browse/USERGRID-1099 +public class ParenthesisProblemIT extends AbstractCoreIT { + private static final Logger logger = LoggerFactory.getLogger( ParenthesisProblemIT.class ); + + @Test + public void parenthesisProblem1() throws Exception { + // C = c and ( A > a or B = false ) + parenthesisProblem(1, "color = 'tabby' and (age > 7 or large = true)"); + } + + @Test + public void parenthesisProblem2() throws Exception { + // same as #1 except for order of things listed in 'and' operation + // ( A > a or B = false ) and C = c + parenthesisProblem(1, "select * where (age > 7 or large = true) and color = 'tabby'"); + } + + private void parenthesisProblem( int expect, String query ) throws Exception { + + EntityManager em =app.getEntityManager(); + + em.create( "cat", new HashMap<String, Object>() {{ + put("name","enzo"); + put("color","orange"); + put("large", true); + put("age",6); + }}); + + em.create( "cat", new HashMap<String, Object> () {{ + put("name","marquee"); + put("color","grey"); + put("large",false); + put("age",8); + }}); + + em.create( "cat", new HashMap<String, Object> () {{ + put("name","bertha"); + put("color","tabby"); + put("large",true); + put("age",1); + }}); + + app.refreshIndex(); + + final Results entities = em.searchCollection( em.getApplicationRef(), "cats", Query.fromQL(query)); + + assertEquals(expect, entities.size()); + } +}
