usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [32/50] [abbrv] Refactoring and Improving query-validator module
Date Thu, 30 Jan 2014 01:21:12 GMT
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ebfe96e8/stack/query-validator/src/test/java/org/usergrid/query/validator/users/UserQueryIT.java
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/test/java/org/usergrid/query/validator/users/UserQueryIT.java
b/stack/query-validator/src/test/java/org/usergrid/query/validator/users/UserQueryIT.java
new file mode 100644
index 0000000..fc6fafa
--- /dev/null
+++ b/stack/query-validator/src/test/java/org/usergrid/query/validator/users/UserQueryIT.java
@@ -0,0 +1,877 @@
+/**
+ * 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.usergrid.query.validator.users;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.usergrid.persistence.Entity;
+import org.usergrid.query.validator.AbstractQueryIT;
+import org.usergrid.query.validator.QueryRequest;
+import org.usergrid.query.validator.QueryResponse;
+import org.usergrid.query.validator.QueryResultsMatcher;
+import org.usergrid.utils.StringUtils;
+
+import java.util.List;
+
+/**
+ * @author Sungju Jin
+ */
+public class UserQueryIT extends AbstractQueryIT {
+
+    @BeforeClass
+    public static void setDatas() {
+        createInitializationDatas("user");
+    }
+
+    @Test
+    public void sexEqualAndNameEqual() {
+        String sqlite = "SELECT * FROM users WHERE sex = 'male' and name = 'judekim' LIMIT
10";
+        String api = "SELECT * WHERE sex = 'male' AND name = 'judekim'";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request);
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void nameEqualAndSexEqual() {
+        String sqlite = "SELECT * FROM users WHERE name = 'judekim' and sex = 'male' LIMIT
10";
+        String api = "select * where name = 'judekim' and sex = 'male'";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request);
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void nameEqualAndSexEqual_limitL20() {
+        String sqlite = "SELECT * FROM users WHERE name = 'judekim' and sex = 'male' LIMIT
20";
+        String api = "select * where name = 'judekim' and sex = 'male'";
+        int limit = 20;
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        request.getApiQuery().setLimit(limit);
+        QueryResponse response = validator.execute(request);
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void sexEqualAndNameEqualExtra1() {
+        String sqlite = "SELECT * FROM users WHERE sex = 'female' and name = 'curioe' LIMIT
10";
+        String api = "select * where sex = 'female' and name = 'curioe'";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request);
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void sexEqualOrNameEqual() {
+        String sqlite = "SELECT * FROM users WHERE sex = 'female' or name = 'curioe' LIMIT
10";
+        String api = "select * where sex = 'female' or name = 'curioe'";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request);
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void nameBeginswithAndSexEqualAndAgeGreaterthanequalOrSexEqual_sortNameDesc()
{
+        String sqlite = "SELECT * FROM users WHERE name LIKE 'a%' and sex = 'male' and age
>= 35 or sex = 'female' ORDER BY name desc LIMIT 10";
+        String api = "select * where name = 'a*' and sex = 'male' and age >= 35 or sex
= 'female' order by name desc";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request);
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void nameBeginswithAndSexEqualAndAgeGreaterthanequalOrSexEqual_sortAddressAscNameDesc()
{
+        String sqlite = "SELECT * FROM users WHERE name LIKE 'a%' and sex = 'male' and age
>= 35 or sex = 'female' ORDER BY address asc, name desc LIMIT 4";
+        String api = "select * where name = 'a*' and sex = 'male' and age >= 35 or sex
= 'female' order by address asc, name desc";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        request.getApiQuery().setLimit(4);
+        QueryResponse response = validator.execute(request);
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void nameBeginswithAndSexEqualAndAgeGreaterthanequalOrSexEqual_sortAddressAscNameDesc_limitL4()
{
+        String sqlite = "SELECT * FROM users WHERE name LIKE 'a%' and sex = 'male' and age
>= 35 or sex = 'female' ORDER BY address asc, name desc LIMIT 4";
+        String api = "select * where name = 'a*' and sex = 'male' and age >= 35 or sex
= 'female' order by address asc, name desc";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        request.getApiQuery().setLimit(4);
+        QueryResponse response = validator.execute(request);
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void sexEqual_sortAgeDescExtra1() {
+        String sqlite = "SELECT * FROM users WHERE sex = 'male' ORDER BY age desc LIMIT 10";
+        String api = "select * where sex = 'male' order by age desc";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request, new QueryResultsMatcher() {
+            @Override
+            public boolean equals(List<Entity> expectedEntities, List<Entity>
actuallyEntities) {
+                boolean equals = expectedEntities.size() == expectedEntities.size();
+                if( !equals )
+                    return false;
+
+                for(Entity entity : actuallyEntities) {
+                    String sex = (String)entity.getProperty("sex");
+
+                    if((StringUtils.equals("male",sex)) == false) {
+                        return false;
+                    }
+                }
+                return equals;
+            }
+        });
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void sexEqual_sortAgeDescExtra2() {
+        String sqlite = " SELECT * FROM users WHERE sex = 'female' ORDER BY age desc LIMIT
10";
+        String api = "select * where sex = 'female' order by age desc";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request);
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void sexEqualAndAgeGreaterthanequal() {
+        String sqlite = " SELECT * FROM users WHERE sex = 'male' and age >= 35 LIMIT 10";
+        String api = "select * where sex = 'male' and age >= 35";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request);
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void sexEqualAndAgeGreaterthanequal_sortAgeDesc() {
+        String sqlite = "SELECT * FROM users WHERE sex = 'male' and age >= 35 ORDER BY
age desc LIMIT 10";
+        String api = "select * where sex = 'male' and age >= 35 order by age desc";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request);
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void sexEqualAndAgeGreaterthanequal_sortNameDesc() {
+        String sqlite = "SELECT * FROM users WHERE sex = 'male' and age >= 35 ORDER BY
name desc LIMIT 10";
+        String api = "select * where sex = 'male' and age >= 35 order by name desc";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request);
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void sexEqualAndAgeGreaterthanequal_sortAgeDesc_limitL20() {
+        String sqlite = "SELECT * FROM users WHERE sex = 'male' and age >= 35 ORDER BY
age desc LIMIT 20";
+        String api = "select * where sex = 'male' and age >= 35 order by age desc";
+        int limit = 20;
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        request.getApiQuery().setLimit(limit);
+        QueryResponse response = validator.execute(request);
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void qlSexEqualAndAgeGreaterthanequal_sortNameDesc_limitL20() {
+        String sqlite = "SELECT * FROM users WHERE sex = 'male' and age >= 35 ORDER BY
name desc LIMIT 20";
+        String api = "select * where sex = 'male' and age >= 35 order by name desc";
+        int limit = 20;
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        request.getApiQuery().setLimit(limit);
+        QueryResponse response = validator.execute(request);
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void sexEqualAndAgeGreaterthanequalOrSexEqual() {
+        String sqlite = "SELECT * FROM users WHERE sex = 'male' and age >= 35 or sex =
'female' LIMIT 10";
+        String api = "select * where sex = 'male' and age >= 35 or sex = 'female'";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request, new QueryResultsMatcher() {
+            @Override
+            public boolean equals(List<Entity> expectedEntities, List<Entity>
actuallyEntities) {
+                boolean equals = expectedEntities.size() == expectedEntities.size();
+                if( !equals )
+                    return false;
+
+                for(Entity entity : actuallyEntities) {
+                    int age = (Integer)entity.getProperty("age");
+                    String sex = (String)entity.getProperty("sex");
+
+                    if(((StringUtils.equals("male",sex) && age >= 35) || StringUtils.equals("female",sex))
== false) {
+                        return false;
+                    }
+                }
+                return equals;
+            }
+        });
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void sexEqualAndAgeGreaterthanequalOrSexEqual_sortAgeDesc() {
+        String sqlite = "SELECT * FROM users WHERE sex = 'male' and age >= 35 or sex =
'female' ORDER BY age desc LIMIT 10";
+        String api = "select * where sex = 'male' and age >= 35 or sex = 'female' order
by age desc";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request);
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void limitL12() {
+        String sqlite = "SELECT * FROM users LIMIT 12";
+        String api = null;
+        int limit = 12;
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        request.getApiQuery().setLimit(limit);
+        QueryResponse response = validator.execute(request);
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void sexEqualAndAgeGreaterthanequalOrSexEqual_sortNameDesc() {
+        String sqlite = "SELECT * FROM users WHERE sex = 'male' and age >= 35 or sex =
'female' ORDER BY name desc LIMIT 10";
+        String api = "select * where sex = 'male' and age >= 35 or sex = 'female' order
by name desc";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request);
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void sexEqualAndAgeGreaterthanequalOrSexEqual_sortNameDesc_limitL20() {
+        String sqlite = "SELECT * FROM users WHERE sex = 'male' and age >= 35 or sex =
'female' ORDER BY name desc LIMIT 20";
+        String api = "select * where sex = 'male' and age >= 35 or sex = 'female' order
by name desc";
+        int limit = 20;
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        request.getApiQuery().setLimit(limit);
+        QueryResponse response = validator.execute(request);
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void limitL11() {
+        String sqlite = "SELECT * FROM users LIMIT 11";
+        String api = null;
+        int limit = 11;
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        request.getApiQuery().setLimit(limit);
+        QueryResponse response = validator.execute(request);
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void nameBeginswithAndSexEqualAndAgeGreaterthanequalOrSexEqual() {
+        String sqlite = "SELECT * FROM users WHERE name LIKE 'a%' and sex = 'male' and age
>= 20 or sex = 'female' LIMIT 10";
+        String api = "select * where name = 'a*' and sex = 'male' and age >= 20 or sex
= 'female'";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request);
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void nameBeginswithAndSexEqualAndAgeGreaterthanequalOrSexEqual_limitL20() {
+        String sqlite = "SELECT * FROM users WHERE name LIKE 'a%' and sex = 'male' and age
>= 20 or sex = 'female' LIMIT 20";
+        String api = "select * where name = 'a*' and sex = 'male' and age >= 20 or sex
= 'female'";
+        int limit = 20;
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        request.getApiQuery().setLimit(limit);
+        QueryResponse response = validator.execute(request);
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void sexEqualAndAgeGreaterthanequal_sortAddressDesc_limitL100() {
+        String sqlite = "SELECT * FROM users WHERE sex = 'male' and age >= 35 ORDER BY
address desc LIMIT 100";
+        String api = "select * where sex = 'male' and age >= 35 order by address desc";
+        int limit = 100;
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        request.getApiQuery().setLimit(limit);
+        QueryResponse response = validator.execute(request);
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void qlNameEqual() {
+        String sqlite = "SELECT * FROM users WHERE name = 'judekim' LIMIT 10";
+        String api = "select * where name = 'judekim'";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request);
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void qlAgeEqual() {
+        String sqlite = "SELECT * FROM users WHERE age = 16 LIMIT 10";
+        String api = "select * where age = 16";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request);
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void qlNameEqualAndAgeEqual() {
+        String sqlite = "SELECT * FROM users WHERE name = 'askagirl' and age = 16 LIMIT 10";
+        String api = "select * where name = 'askagirl' and age = 16";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request, new QueryResultsMatcher() {
+            @Override
+            public boolean equals(List<Entity> expectedEntities, List<Entity>
actuallyEntities) {
+                boolean equals = expectedEntities.size() == expectedEntities.size();
+                if( !equals )
+                    return false;
+
+                for(Entity entity : actuallyEntities) {
+                    String name = entity.getName();
+                    int age = (Integer)entity.getProperty("age");
+                    if ((StringUtils.equals("askagirl", name) && age == 16) == false)
{
+                        return false;
+                    }
+                }
+                return equals;
+            }
+        });
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void qlAgeLessthan() {
+        String sqlite = "SELECT * FROM users WHERE age < 16 LIMIT 10";
+        String api = "select * where age < 16";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request, new QueryResultsMatcher() {
+            @Override
+            public boolean equals(List<Entity> expectedEntities, List<Entity>
actuallyEntities) {
+                boolean equals = expectedEntities.size() == expectedEntities.size();
+                if( !equals )
+                    return false;
+
+                for(Entity entity : actuallyEntities) {
+                    int age = (Integer)entity.getProperty("age");
+                    if((age < 16) == false) {
+                        return false;
+                    }
+                }
+                return equals;
+            }
+        });
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void qlAgeLessthanequal() {
+        String sqlite = "SELECT * FROM users WHERE age <= 16 LIMIT 20";
+        String api = "select * where age <= 16";
+        int limit = 20;
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        request.getApiQuery().setLimit(limit);
+        QueryResponse response = validator.execute(request, new QueryResultsMatcher() {
+            @Override
+            public boolean equals(List<Entity> expectedEntities, List<Entity>
actuallyEntities) {
+                boolean equals = expectedEntities.size() == expectedEntities.size();
+                if( !equals )
+                    return false;
+
+                for(Entity entity : actuallyEntities) {
+                    int age = (Integer)entity.getProperty("age");
+                    if((age <= 16) == false) {
+                        return false;
+                    }
+                }
+                return equals;
+            }
+        });
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void qlAgeGreaterthan() {
+        String sqlite = "SELECT * FROM users WHERE age > 16 LIMIT 10";
+        String api = "select * where age > 16";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request, new QueryResultsMatcher() {
+            @Override
+            public boolean equals(List<Entity> expectedEntities, List<Entity>
actuallyEntities) {
+                boolean equals = expectedEntities.size() == expectedEntities.size();
+                if( !equals )
+                    return false;
+
+                for(Entity entity : actuallyEntities) {
+                    int age = (Integer)entity.getProperty("age");
+                    if((age > 16) == false) {
+                        return false;
+                    }
+                }
+                return equals;
+            }
+        });
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void qlAgeGreaterthanequal() {
+        String sqlite = "SELECT * FROM users WHERE age >= 16 LIMIT 10";
+        String api = "select * where age >= 16";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request, new QueryResultsMatcher() {
+            @Override
+            public boolean equals(List<Entity> expectedEntities, List<Entity>
actuallyEntities) {
+                boolean equals = expectedEntities.size() == expectedEntities.size();
+                if( !equals )
+                    return false;
+
+                for(Entity entity : actuallyEntities) {
+                    int age = (Integer)entity.getProperty("age");
+                    if((age >= 16) == false) {
+                        return false;
+                    }
+                }
+                return equals;
+            }
+        });
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void qlAgeGreaterthanequalAndAgeLessthan() {
+        String sqlite = "SELECT * FROM users WHERE age >= 32 and age < 40 LIMIT 10";
+        String api = "select * where age >= 32 and age < 40";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request, new QueryResultsMatcher() {
+            @Override
+            public boolean equals(List<Entity> expectedEntities, List<Entity>
actuallyEntities) {
+                boolean equals = expectedEntities.size() == expectedEntities.size();
+                if( !equals )
+                    return false;
+
+                for(Entity entity : actuallyEntities) {
+                    int age = (Integer)entity.getProperty("age");
+                    if((age >= 32 && age < 40) == false) {
+                        return false;
+                    }
+                }
+                return equals;
+            }
+        });
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void qlAgeGreaterthanequalAndAgeLessthanAndSexEqual() {
+        String sqlite = "SELECT * FROM users WHERE age >= 32 and age < 40 and sex =
'female' LIMIT 10";
+        String api = "select * where age >= 32 and age < 40 and sex = 'female'";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request, new QueryResultsMatcher() {
+            @Override
+            public boolean equals(List<Entity> expectedEntities, List<Entity>
actuallyEntities) {
+                boolean equals = expectedEntities.size() == expectedEntities.size();
+                if( !equals )
+                    return false;
+
+                for(Entity entity : actuallyEntities) {
+                    int age = (Integer)entity.getProperty("age");
+                    String sex = (String)entity.getProperty("sex");
+
+                    if((age >= 32 && age < 40 && StringUtils.equals("female",sex))
== false) {
+                        return false;
+                    }
+                }
+                return equals;
+            }
+        });
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void qlAddressFulltext() {
+        String sqlite = "SELECT * FROM users WHERE address LIKE '%서울시%' LIMIT 10";
+        String api = "select * where address contains '서울시'";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request, new QueryResultsMatcher() {
+            @Override
+            public boolean equals(List<Entity> expectedEntities, List<Entity>
actuallyEntities) {
+                boolean equals = expectedEntities.size() == expectedEntities.size();
+                if( !equals )
+                    return false;
+
+                for(Entity entity : actuallyEntities) {
+                    String address = (String)entity.getProperty("address");
+
+                    if((StringUtils.contains(address,"서울시")) == false) {
+                        return false;
+                    }
+                }
+                return equals;
+            }
+        });
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void qlAddressFulltextstartswith() {
+        String sqlite = " SELECT * FROM users WHERE address LIKE 'A%' LIMIT 10";
+        String api = "select * where address contains 'A*'";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request, new QueryResultsMatcher() {
+            @Override
+            public boolean equals(List<Entity> expectedEntities, List<Entity>
actuallyEntities) {
+                boolean equals = expectedEntities.size() == expectedEntities.size();
+                if( !equals )
+                    return false;
+
+                for(Entity entity : actuallyEntities) {
+                    String address = (String)entity.getProperty("address");
+
+                    if((StringUtils.startsWith(address,"A")) == false) {
+                        return false;
+                    }
+                }
+                return equals;
+            }
+        });
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void qlAddressBeginswith() {
+        String sqlite = "SELECT * FROM users WHERE address LIKE 'B%' LIMIT 10";
+        String api = "select * where address = 'B*'";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request, new QueryResultsMatcher() {
+            @Override
+            public boolean equals(List<Entity> expectedEntities, List<Entity>
actuallyEntities) {
+                boolean equals = expectedEntities.size() == expectedEntities.size();
+                if( !equals )
+                    return false;
+
+                for(Entity entity : actuallyEntities) {
+                    String address = (String)entity.getProperty("address");
+
+                    if((StringUtils.startsWith(address,"B")) == false) {
+                        return false;
+                    }
+                }
+                return equals;
+            }
+        });
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void qlAddressBeginswithAndSexFulltextstartswith() {
+        String sqlite = "SELECT * FROM users WHERE address LIKE 'C%' and sex LIKE 'ma%' LIMIT
10";
+        String api = "select * where address = 'C*' and sex contains 'ma*'";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request, new QueryResultsMatcher() {
+            @Override
+            public boolean equals(List<Entity> expectedEntities, List<Entity>
actuallyEntities) {
+                boolean equals = expectedEntities.size() == expectedEntities.size();
+                if( !equals )
+                    return false;
+
+                for(Entity entity : actuallyEntities) {
+                    String address = (String)entity.getProperty("address");
+
+                    if((StringUtils.startsWith(address,"C")) == false) {
+                        return false;
+                    }
+                }
+                return equals;
+            }
+        });
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void qlAddressBeginswithAndSexFulltext() {
+        String sqlite = "SELECT * FROM users WHERE (address LIKE 'D%' and sex LIKE '%male%')
LIMIT 10";
+        String api = "select * where address = 'D*' and sex contains 'male'";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request, new QueryResultsMatcher() {
+            @Override
+            public boolean equals(List<Entity> expectedEntities, List<Entity>
actuallyEntities) {
+                boolean equals = expectedEntities.size() == expectedEntities.size();
+                if( !equals )
+                    return false;
+
+                for(Entity entity : actuallyEntities) {
+                    String address = (String)entity.getProperty("address");
+
+                    if((StringUtils.startsWith(address,"D")) == false) {
+                        return false;
+                    }
+                }
+                return equals;
+            }
+        });
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void qlSexEqualOrAgeGreaterthanequalAndAgeLessthan_limitL20() {
+        String sqlite = "SELECT * FROM users WHERE sex = 'female' or age >= 12 and age
< 20 LIMIT 20";
+        String api = "select * where sex = 'female' or age >= 12 and age < 20";
+        int limit = 20;
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        request.getApiQuery().setLimit(limit);
+        QueryResponse response = validator.execute(request, new QueryResultsMatcher() {
+            @Override
+            public boolean equals(List<Entity> expectedEntities, List<Entity>
actuallyEntities) {
+                boolean equals = expectedEntities.size() == expectedEntities.size();
+                if( !equals )
+                    return false;
+
+                for(Entity entity : actuallyEntities) {
+                    int age = (Integer)entity.getProperty("age");
+                    String sex = (String)entity.getProperty("sex");
+
+                    if(((StringUtils.equals("female",sex) || age >= 12) && age
< 20) == false) {
+                        return false;
+                    }
+                }
+                return equals;
+            }
+        });
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void sortNameAsc() {
+        String sqlite = "SELECT * FROM users ORDER BY name asc LIMIT 10";
+        String api = "select * order by name asc";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request);
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void sortNameDesc() {
+        String sqlite = "SELECT * FROM users ORDER BY name desc LIMIT 10";
+        String api = "select * order by name desc";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request);
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void sortNameAscAgeDesc() {
+        String sqlite = "SELECT * FROM users ORDER BY name asc, age desc LIMIT 10";
+        String api = "select * order by name asc, age desc";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request);
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void sortNameAscAddressAsc() {
+        String sqlite = "SELECT * FROM users ORDER BY name asc, address asc LIMIT 10";
+        String api = "select * order by name asc, address asc";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request);
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void sortCreatedAsc() {
+        String sqlite = "SELECT * FROM users ORDER BY created asc LIMIT 10";
+        String api = "select * order by created asc";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request);
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void sortCreatedDesc() {
+        String sqlite = "SELECT * FROM users ORDER BY created desc LIMIT 10";
+        String api = "select * order by created desc";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request);
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void sortModifiedAsc() {
+        String sqlite = "SELECT * FROM users ORDER BY modified asc LIMIT 10";
+        String api = "select * order by modified asc";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request);
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void sortCreatedDescNameAsc() {
+        String sqlite = "SELECT * FROM users ORDER BY created desc, name asc LIMIT 10";
+        String api = "select * order by created desc, name asc";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request);
+        Assert.assertTrue(response.toString(), response.result());
+    }
+
+    @Test
+    public void sortNameAscCreatedDesc() {
+        String sqlite = "SELECT * FROM users ORDER BY name asc, created desc LIMIT 10";
+        String api = "select * order by name asc, created desc";
+
+        QueryRequest request = new QueryRequest();
+        request.setDbQuery(sqlite);
+        request.getApiQuery().setQuery(api);
+        QueryResponse response = validator.execute(request);
+        Assert.assertTrue(response.toString(), response.result());
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ebfe96e8/stack/query-validator/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/test/resources/log4j.properties b/stack/query-validator/src/test/resources/log4j.properties
index ddd90fb..d60fa61 100644
--- a/stack/query-validator/src/test/resources/log4j.properties
+++ b/stack/query-validator/src/test/resources/log4j.properties
@@ -39,4 +39,4 @@ log4j.logger.org.usergrid.rest.security.AllowAjaxFilter=WARN, stdout
 log4j.logger.me.prettyprint.hector.api.beans.AbstractComposite=ERROR, stdout
 
 log4j.logger.org.usergrid.query.validator.ApiServerRunner=INFO
-log4j.logger.org.usergrid.query.validator.QueryValidatorRunner=INFO
+log4j.logger.org.usergrid.query.validator.QueryValidatorRunner=INFO
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ebfe96e8/stack/query-validator/src/test/resources/project.properties
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/test/resources/project.properties b/stack/query-validator/src/test/resources/project.properties
new file mode 100644
index 0000000..c0bf364
--- /dev/null
+++ b/stack/query-validator/src/test/resources/project.properties
@@ -0,0 +1 @@
+target.directory=${project.build.directory}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ebfe96e8/stack/query-validator/src/test/resources/user.json
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/test/resources/user.json b/stack/query-validator/src/test/resources/user.json
index b1dbc80..19beef1 100644
--- a/stack/query-validator/src/test/resources/user.json
+++ b/stack/query-validator/src/test/resources/user.json
@@ -10,14 +10,14 @@
         "name":"zoozooz",
         "username":"zoozooz",
         "address":"서울시 관악구 봉천동",
-        "age":16,
+        "age":76,
         "sex":"male"
     },
     {
         "name":"r2fresh",
         "username":"r2fresh",
         "address":"경기도 고양시 일산",
-        "age":16,
+        "age":36,
         "sex":"male"
     },
     {
@@ -38,14 +38,14 @@
         "name":"izakaya",
         "username":"izakaya",
         "address":"인천광역시 어디어디",
-        "age":16,
+        "age":28,
         "sex":"male"
     },
     {
         "name":"aksagirl",
         "username":"aksagirl",
         "address":"부산광역시 어딘가",
-        "age":16,
+        "age":26,
         "sex":"male"
     },
     {
@@ -70,13 +70,6 @@
         "sex":"male"
     },
     {
-        "name":"akaia75",
-        "username":"akaia75",
-        "address":"서울시 구로구",
-        "age":13,
-        "sex":"male"
-    },
-    {
         "name":"curioe",
         "username":"curioe",
         "address":"서울시 어디인가",

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ebfe96e8/stack/query-validator/src/test/resources/usergrid-custom-test.properties
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/test/resources/usergrid-custom-test.properties b/stack/query-validator/src/test/resources/usergrid-custom-test.properties
index 39050d9..6ba10b0 100644
--- a/stack/query-validator/src/test/resources/usergrid-custom-test.properties
+++ b/stack/query-validator/src/test/resources/usergrid-custom-test.properties
@@ -1,6 +1,13 @@
 usergrid.query.validator.api.enablelocal=true
-usergrid.query.validator.api.endpoint=http://localhost:8080
+usergrid.query.validator.api.endpoint=http://localhost
+usergrid.query.validator.api.endpoint.port=8080
 usergrid.query.validator.api.organization=test-organization
 usergrid.query.validator.api.app=test-app
-usergrid.query.validator.api.authorize.email=test@usergrid.com
-usergrid.query.validator.api.authorize.password=test
\ No newline at end of file
+usergrid.query.validator.api.authorize.email=test22
+usergrid.query.validator.api.authorize.password=test
+
+# SysAdmin login
+usergrid.sysadmin.login.name=superuser
+usergrid.sysadmin.login.email=superuser@usergrid.com
+usergrid.sysadmin.login.password=superpassword
+usergrid.sysadmin.login.allowed=true
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ebfe96e8/stack/query-validator/src/test/resources/usergrid-test-context.xml
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/test/resources/usergrid-test-context.xml b/stack/query-validator/src/test/resources/usergrid-test-context.xml
index 0cccb05..bec5638 100644
--- a/stack/query-validator/src/test/resources/usergrid-test-context.xml
+++ b/stack/query-validator/src/test/resources/usergrid-test-context.xml
@@ -1,8 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <beans xmlns="http://www.springframework.org/schema/beans"
-	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	xsi:schemaLocation="
-	http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
+       xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
+       xsi:schemaLocation="
+	http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
+	http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
+	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
 
     <bean id="properties"
           class="org.springframework.beans.factory.config.PropertiesFactoryBean">
@@ -12,12 +15,20 @@
             <list>
                 <value>classpath:/usergrid-default.properties</value>
                 <value>classpath:/usergrid-test.properties</value>
-                <value>${usergrid-custom-spring-test-properties}</value>
+                <value>classpath:/usergrid-custom-test.properties</value>
             </list>
         </property>
     </bean>
 
-	<import resource="classpath:/usergrid-query-validator-context.xml" />
+    <import resource="usergrid-rest-context.xml"/>
+
+    <bean id="traceTagManager" class="org.usergrid.persistence.cassandra.util.TraceTagManager">
+        <property name="reportUnattached" value="false"/>
+        <property name="traceEnabled" value="false"/>
+    </bean>
+
+
+    <bean id="binaryStore" class="org.usergrid.services.assets.data.LocalFileBinaryStore"/>
 
     <bean id="setup" class="org.usergrid.persistence.cassandra.Setup">
         <constructor-arg ref="entityManagerFactory"/>
@@ -30,5 +41,6 @@
         <constructor-arg ref="cassandraCluster"/>
     </bean>
 
+    <import resource="usergrid-query-validator-context.xml"/>
 
-</beans>
+</beans>
\ No newline at end of file


Mime
View raw message