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/01/30 02:21:13 UTC
[33/50] [abbrv] git commit: Refactoring and Improving query-validator
module
Refactoring and Improving query-validator module
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/ebfe96e8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/ebfe96e8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/ebfe96e8
Branch: refs/heads/USERGRID-2771-graph-edges
Commit: ebfe96e8403d62ecb4a3c27e019ae4a65576e24c
Parents: 447ede6
Author: Sungju Jin <su...@softwaregeeks.org>
Authored: Thu Jan 16 23:04:12 2014 +0900
Committer: Sungju Jin <su...@softwaregeeks.org>
Committed: Thu Jan 16 23:04:12 2014 +0900
----------------------------------------------------------------------
stack/query-validator/pom.xml | 235 +++--
.../query/validator/ApiServerRunner.java | 49 +-
.../validator/DefaultQueryResultsMatcher.java | 32 +
.../usergrid/query/validator/QueryEntity.java | 31 +-
.../usergrid/query/validator/QueryRequest.java | 31 +-
.../usergrid/query/validator/QueryResponse.java | 22 +-
.../query/validator/QueryResultsMatcher.java | 29 +
.../usergrid/query/validator/QueryRunner.java | 23 +-
.../validator/QueryValidationConfiguration.java | 22 +-
.../query/validator/QueryValidator.java | 33 +-
.../usergrid/query/validator/SqliteRunner.java | 60 +-
.../usergrid-query-validator-context.xml | 16 +-
.../query/validator/AbstractQueryIT.java | 133 +++
.../usergrid/query/validator/QueryITSuite.java | 39 +
.../query/validator/QueryValidationTest.java | 339 -------
.../query/validator/QueryValidatorRunner.java | 209 -----
.../query/validator/users/UserQueryIT.java | 877 +++++++++++++++++++
.../src/test/resources/log4j.properties | 2 +-
.../src/test/resources/project.properties | 1 +
.../src/test/resources/user.json | 15 +-
.../resources/usergrid-custom-test.properties | 13 +-
.../test/resources/usergrid-test-context.xml | 24 +-
22 files changed, 1476 insertions(+), 759 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ebfe96e8/stack/query-validator/pom.xml
----------------------------------------------------------------------
diff --git a/stack/query-validator/pom.xml b/stack/query-validator/pom.xml
index eb0f42e..30bb3dd 100644
--- a/stack/query-validator/pom.xml
+++ b/stack/query-validator/pom.xml
@@ -5,23 +5,19 @@
<parent>
<groupId>org.usergrid</groupId>
<artifactId>usergrid</artifactId>
- <version>0.0.16-SNAPSHOT</version>
+ <version>0.0.28-SNAPSHOT</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <!-- This seems to be a safe figure -->
+ <core.it.heapmax>1024m</core.it.heapmax>
+ <core.it.heapmin>1024m</core.it.heapmin>
</properties>
<artifactId>usergrid-query-validator</artifactId>
<name>Usergrid Query Validator</name>
- <description>Query validator tools for Usergrid system.</description>
+ <description>Query validator tools for Usergrid.</description>
<packaging>jar</packaging>
- <reporting>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-report-plugin</artifactId>
- </plugin>
- </plugins>
- </reporting>
+
<build>
<resources>
<resource>
@@ -37,9 +33,7 @@
<directory>src/test/resources</directory>
<filtering>true</filtering>
<includes>
- <include>**/*.xml</include>
- <include>**/*.properties</include>
- <include>**/*.json</include>
+ <include>**/*</include>
</includes>
</testResource>
</testResources>
@@ -48,7 +42,17 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
- <testFailureIgnore>false</testFailureIgnore>
+ <argLine>-Xmx${core.it.heapmax} -Xms${core.it.heapmin} -Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8
+ </argLine>
+
+ <includes>
+ <include>**/*Suite.java</include>
+ </includes>
+ <excludes>
+ <!-- Need to exclude Suite tests to prevent double execution -->
+ <exclude>**/UserQueryIT.java</exclude>
+ </excludes>
+
</configuration>
</plugin>
@@ -77,7 +81,6 @@
<goal>test-jar</goal>
</goals>
<configuration>
- <classifier>tests</classifier>
<includes>
<include>**/org/usergrid/**</include>
</includes>
@@ -92,142 +95,202 @@
<groupId>org.usergrid</groupId>
<artifactId>usergrid-config</artifactId>
<version>${project.version}</version>
- <scope>test</scope>
- <classifier>tests</classifier>
</dependency>
+
<dependency>
<groupId>org.usergrid</groupId>
- <artifactId>usergrid-count-batcher</artifactId>
+ <artifactId>usergrid-core</artifactId>
<version>${project.version}</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>commons-logging</artifactId>
+ <groupId>commons-logging</groupId>
+ </exclusion>
+ </exclusions>
</dependency>
+
<dependency>
<groupId>org.usergrid</groupId>
- <artifactId>usergrid-count-common</artifactId>
+ <artifactId>usergrid-rest</artifactId>
<version>${project.version}</version>
+ <classifier>classes</classifier>
+ <exclusions>
+ <exclusion>
+ <artifactId>servlet-api</artifactId>
+ <groupId>javax.servlet</groupId>
+ </exclusion>
+ </exclusions>
</dependency>
+
<dependency>
<groupId>org.usergrid</groupId>
- <artifactId>usergrid-test-utils</artifactId>
+ <artifactId>usergrid-rest</artifactId>
<version>${project.version}</version>
- <scope>test</scope>
+ <classifier>compiled-jsp</classifier>
</dependency>
+
<dependency>
<groupId>org.usergrid</groupId>
- <artifactId>usergrid-core</artifactId>
+ <artifactId>usergrid-rest</artifactId>
<version>${project.version}</version>
- <exclusions>
- <exclusion>
- <artifactId>commons-logging</artifactId>
- <groupId>commons-logging</groupId>
- </exclusion>
- </exclusions>
+ <classifier>tests</classifier>
+ <scope>test</scope>
</dependency>
+
+ <!-- Apache Dependencies -->
+
<dependency>
- <groupId>org.usergrid</groupId>
- <artifactId>usergrid-scheduler</artifactId>
- <version>${project.version}</version>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ </dependency>
+
+ <!-- SUN, Javax Package, and Other Com Dependencies -->
+
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>jstl</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-webmvc</artifactId>
</dependency>
+
+ <!--<dependency>-->
+ <!--<!– TODO - should not scope be 'test' ? –>-->
+ <!--<groupId>org.slf4j</groupId>-->
+ <!--<artifactId>jcl-over-slf4j</artifactId>-->
+ <!--</dependency>-->
+
+ <!--<dependency>-->
+ <!--<!– TODO - should not scope be 'test' ? –>-->
+ <!--<groupId>org.slf4j</groupId>-->
+ <!--<artifactId>jul-to-slf4j</artifactId>-->
+ <!--</dependency>-->
+
+ <!-- Testing and Logging Dependencies -->
+
<dependency>
<groupId>org.usergrid</groupId>
- <artifactId>usergrid-core</artifactId>
+ <artifactId>usergrid-config</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<classifier>tests</classifier>
</dependency>
+
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
+ <groupId>org.usergrid</groupId>
+ <artifactId>usergrid-test-utils</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
</dependency>
+
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
+ <groupId>org.usergrid</groupId>
+ <artifactId>usergrid-core</artifactId>
+ <version>${project.version}</version>
<scope>test</scope>
+ <classifier>tests</classifier>
</dependency>
+
<dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
+
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>jcl-over-slf4j</artifactId>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
+
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>jul-to-slf4j</artifactId>
+ <groupId>org.jvnet.mock-javamail</groupId>
+ <artifactId>mock-javamail</artifactId>
<scope>test</scope>
</dependency>
+
<dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-core</artifactId>
- <exclusions>
- <exclusion>
- <artifactId>commons-logging</artifactId>
- <groupId>commons-logging</groupId>
- </exclusion>
- </exclusions>
+ <groupId>org.hectorclient</groupId>
+ <artifactId>hector-test</artifactId>
+ <scope>test</scope>
</dependency>
+
<dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-expression</artifactId>
+ <groupId>org.apache.tomcat.embed</groupId>
+ <artifactId>tomcat-embed-core</artifactId>
+ <scope>test</scope>
</dependency>
+
<dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-beans</artifactId>
+ <groupId>org.apache.tomcat.embed</groupId>
+ <artifactId>tomcat-embed-logging-juli</artifactId>
+ <scope>test</scope>
</dependency>
+
<dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-aop</artifactId>
+ <groupId>org.apache.tomcat.embed</groupId>
+ <artifactId>tomcat-embed-jasper</artifactId>
+ <scope>test</scope>
</dependency>
+
<dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-context</artifactId>
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>tomcat-jasper-el</artifactId>
+ <scope>test</scope>
</dependency>
+
<dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-context-support</artifactId>
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>tomcat-jsp-api</artifactId>
+ <scope>test</scope>
</dependency>
+
<dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-web</artifactId>
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>juli</artifactId>
+ <scope>test</scope>
</dependency>
+
+ <!-- use the external test client. Just depend on the maven jetty plugin to launch jetty -->
<dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-test</artifactId>
+ <groupId>com.sun.jersey.jersey-test-framework</groupId>
+ <artifactId>jersey-test-framework-external</artifactId>
<scope>test</scope>
</dependency>
+
<dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-jdbc</artifactId>
- <version>${org.springframework.version}</version>
+ <groupId>com.sun.jersey.jersey-test-framework</groupId>
+ <artifactId>jersey-test-framework-core</artifactId>
+ <scope>test</scope>
</dependency>
+
+
+
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
+ <groupId>org.usergrid</groupId>
+ <artifactId>usergrid-java-client</artifactId>
</dependency>
+
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.7.2</version>
</dependency>
- <dependency>
- <groupId>org.usergrid</groupId>
- <artifactId>usergrid-java-client</artifactId>
- <version>0.0.3</version>
- <scope>compile</scope>
- </dependency>
+
<dependency>
- <groupId>org.usergrid</groupId>
- <artifactId>usergrid-standalone</artifactId>
- <version>${project.version}</version>
- <exclusions>
- <exclusion>
- <artifactId>commons-logging</artifactId>
- <groupId>commons-logging</groupId>
- </exclusion>
- </exclusions>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-jdbc</artifactId>
+ <version>${org.springframework.version}</version>
</dependency>
+
</dependencies>
-</project>
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ebfe96e8/stack/query-validator/src/main/java/org/usergrid/query/validator/ApiServerRunner.java
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/main/java/org/usergrid/query/validator/ApiServerRunner.java b/stack/query-validator/src/main/java/org/usergrid/query/validator/ApiServerRunner.java
index b7c5739..7a7015e 100644
--- a/stack/query-validator/src/main/java/org/usergrid/query/validator/ApiServerRunner.java
+++ b/stack/query-validator/src/main/java/org/usergrid/query/validator/ApiServerRunner.java
@@ -1,33 +1,34 @@
-/*******************************************************************************
- * Copyright 2013 baas.io
- *
- * 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
+/**
+ * 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
+ * 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;
import org.apache.commons.lang.StringUtils;
import org.codehaus.jackson.JsonNode;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
+import org.usergrid.java.client.Client;
import org.usergrid.java.client.response.ApiResponse;
import org.usergrid.persistence.Entity;
+import org.usergrid.persistence.Schema;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
-import org.usergrid.java.client.Client;
-import org.usergrid.persistence.Schema;
-
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -35,7 +36,7 @@ import java.util.logging.Logger;
import static org.usergrid.java.client.utils.ObjectUtils.isEmpty;
/**
- * @author Sung-ju Jin(realbeast)
+ * @author Sungju Jin
*/
@Component
public class ApiServerRunner implements QueryRunner {
@@ -78,17 +79,17 @@ public class ApiServerRunner implements QueryRunner {
}
public boolean insertDatas() {
- List<org.usergrid.java.client.entities.Entity> clientEntities = getEntitiesForClient(getEntities());
- for(org.usergrid.java.client.entities.Entity entity : clientEntities) {
- ApiResponse response = client.createEntity(entity);
- if( response == null || !StringUtils.isEmpty(response.getError()) ) {
- logger.log(Level.SEVERE, response.getErrorDescription());
- //throw new RuntimeException(response.getErrorDescription());
- } else {
- logger.log(Level.INFO, response.toString());
- }
- }
- return true;
+ List<org.usergrid.java.client.entities.Entity> clientEntities = getEntitiesForClient(getEntities());
+ for(org.usergrid.java.client.entities.Entity entity : clientEntities) {
+ ApiResponse response = client.createEntity(entity);
+ if( response == null || !StringUtils.isEmpty(response.getError()) ) {
+ logger.log(Level.SEVERE, response.getErrorDescription());
+ //throw new RuntimeException(response.getErrorDescription());
+ } else {
+ logger.log(Level.INFO, response.toString());
+ }
+ }
+ return true;
}
private List<org.usergrid.java.client.entities.Entity> getEntitiesForClient(List<Entity> entities) {
@@ -209,4 +210,4 @@ public class ApiServerRunner implements QueryRunner {
public void setPassword(String password) {
this.password = password;
}
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ebfe96e8/stack/query-validator/src/main/java/org/usergrid/query/validator/DefaultQueryResultsMatcher.java
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/main/java/org/usergrid/query/validator/DefaultQueryResultsMatcher.java b/stack/query-validator/src/main/java/org/usergrid/query/validator/DefaultQueryResultsMatcher.java
new file mode 100644
index 0000000..614b9fc
--- /dev/null
+++ b/stack/query-validator/src/main/java/org/usergrid/query/validator/DefaultQueryResultsMatcher.java
@@ -0,0 +1,32 @@
+/**
+ * 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;
+
+import org.usergrid.persistence.Entity;
+
+import java.util.List;
+
+/**
+ * @author Sungju Jin
+ */
+public class DefaultQueryResultsMatcher implements QueryResultsMatcher {
+ @Override
+ public boolean equals(List<Entity> expectedEntities, List<Entity> actuallyEntities) {
+ return expectedEntities.equals(actuallyEntities);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ebfe96e8/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryEntity.java
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryEntity.java b/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryEntity.java
index c4ccd3e..c43afe7 100644
--- a/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryEntity.java
+++ b/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryEntity.java
@@ -1,9 +1,29 @@
+/**
+ * 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;
import org.usergrid.persistence.DynamicEntity;
import java.util.Map;
+/**
+ * @author Sungju Jin
+ */
public class QueryEntity extends DynamicEntity {
@Override
@@ -26,9 +46,18 @@ public class QueryEntity extends DynamicEntity {
Object value = properties.get(key);
Object otherValue = otherProperties.get(key);
+
+ if(value.getClass() == Boolean.class) {
+ value = (Boolean)value ? 1 : 0;
+ }
+
+ if(otherValue.getClass() == Boolean.class) {
+ otherValue = (Boolean)otherValue ? 1 : 0;
+ }
+
if( otherValue == null || !value.equals(otherValue) )
return false;
}
return true;
}
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ebfe96e8/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryRequest.java
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryRequest.java b/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryRequest.java
index 0515085..59032ba 100644
--- a/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryRequest.java
+++ b/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryRequest.java
@@ -1,27 +1,28 @@
-/*******************************************************************************
- * Copyright 2013 baas.io
- *
- * 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
+/**
+ * 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
+ * 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;
/**
- * @author Sung-ju Jin(realbeast)
+ * @author Sungju Jin
*/
public class QueryRequest {
private String dbQuery;
private ApiQuery apiQuery;
- private boolean ignoreOrdering;
public QueryRequest() {
this.apiQuery = new ApiQuery();
@@ -63,12 +64,4 @@ public class QueryRequest {
this.limit = limit;
}
}
-
- public boolean isIgnoreOrdering() {
- return ignoreOrdering;
- }
-
- public void setIgnoreOrdering(boolean ignoreOrdering) {
- this.ignoreOrdering = ignoreOrdering;
- }
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ebfe96e8/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryResponse.java
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryResponse.java b/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryResponse.java
index 6a7dbce..6a05c13 100644
--- a/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryResponse.java
+++ b/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryResponse.java
@@ -1,18 +1,20 @@
-/*******************************************************************************
- * Copyright 2013 baas.io
- *
- * 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
+/**
+ * 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
+ * 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;
import org.apache.commons.lang.StringUtils;
@@ -21,7 +23,7 @@ import org.usergrid.persistence.Entity;
import java.util.List;
/**
- * @author Sung-ju Jin(realbeast)
+ * @author Sungju Jin
*/
public class QueryResponse {
@@ -100,4 +102,4 @@ public class QueryResponse {
builder.append("\n");
return builder.toString();
}
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ebfe96e8/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryResultsMatcher.java
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryResultsMatcher.java b/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryResultsMatcher.java
new file mode 100644
index 0000000..e720ec5
--- /dev/null
+++ b/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryResultsMatcher.java
@@ -0,0 +1,29 @@
+/**
+ * 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;
+
+import org.usergrid.persistence.Entity;
+
+import java.util.List;
+
+/**
+ * @author Sungju Jin
+ */
+public interface QueryResultsMatcher {
+ boolean equals(List<Entity> expectedEntities, List<Entity> actuallyEntities);
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ebfe96e8/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryRunner.java
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryRunner.java b/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryRunner.java
index caabb96..fbc6220 100644
--- a/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryRunner.java
+++ b/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryRunner.java
@@ -1,25 +1,28 @@
-/*******************************************************************************
- * Copyright 2013 baas.io
- *
- * 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
+/**
+ * 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
+ * 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;
-import java.util.List;
import org.usergrid.persistence.Entity;
+import java.util.List;
+
/**
- * @author Sung-ju Jin(realbeast)
+ * @author Sungju Jin
*/
public interface QueryRunner {
public boolean setup();
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ebfe96e8/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryValidationConfiguration.java
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryValidationConfiguration.java b/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryValidationConfiguration.java
index 147a75a..35f3994 100644
--- a/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryValidationConfiguration.java
+++ b/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryValidationConfiguration.java
@@ -1,3 +1,20 @@
+/**
+ * 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;
import org.usergrid.persistence.Entity;
@@ -5,6 +22,9 @@ import org.usergrid.utils.InflectionUtils;
import java.util.List;
+/**
+ * @author Sungju Jin
+ */
public class QueryValidationConfiguration {
String org;
@@ -71,4 +91,4 @@ public class QueryValidationConfiguration {
public void setPassword(String password) {
this.password = password;
}
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ebfe96e8/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryValidator.java
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryValidator.java b/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryValidator.java
index d5eb67a..0e7f89a 100644
--- a/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryValidator.java
+++ b/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryValidator.java
@@ -1,18 +1,20 @@
-/*******************************************************************************
- * Copyright 2013 baas.io
- *
- * 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
+/**
+ * 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
+ * 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;
import org.springframework.beans.factory.annotation.Autowired;
@@ -22,7 +24,7 @@ import org.usergrid.persistence.Entity;
import java.util.List;
/**
- * @author Sung-ju Jin(realbeast)
+ * @author Sungju Jin
*/
@Component
public class QueryValidator {
@@ -45,14 +47,13 @@ public class QueryValidator {
}
public QueryResponse execute(QueryRequest request) {
+ return execute(request, new DefaultQueryResultsMatcher());
+ }
+
+ public QueryResponse execute(QueryRequest request, QueryResultsMatcher matcher) {
List<Entity> sqlEntities = sql.execute(request.getDbQuery());
List<Entity> apiEntities = api.execute(request.getApiQuery().getQuery(), request.getApiQuery().getLimit());
- boolean equals = false;
- if( request.isIgnoreOrdering() ) {
- equals = sqlEntities.size() == apiEntities.size();
- } else {
- equals = sqlEntities.equals(apiEntities);
- }
+ boolean equals = matcher.equals(sqlEntities, apiEntities);
QueryResponse response = new QueryResponse();
response.setResult(equals);
@@ -74,4 +75,4 @@ public class QueryValidator {
api.setEmail(configuration.getEmail());
api.setPassword(configuration.getPassword());
}
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ebfe96e8/stack/query-validator/src/main/java/org/usergrid/query/validator/SqliteRunner.java
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/main/java/org/usergrid/query/validator/SqliteRunner.java b/stack/query-validator/src/main/java/org/usergrid/query/validator/SqliteRunner.java
index b85e19c..dd728c8 100644
--- a/stack/query-validator/src/main/java/org/usergrid/query/validator/SqliteRunner.java
+++ b/stack/query-validator/src/main/java/org/usergrid/query/validator/SqliteRunner.java
@@ -1,18 +1,20 @@
-/*******************************************************************************
- * Copyright 2013 baas.io
- *
- * 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
+/**
+ * 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
+ * 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;
import org.apache.commons.lang.StringUtils;
@@ -31,7 +33,7 @@ import java.util.Map;
import java.util.logging.Logger;
/**
- * @author Sung-ju Jin(realbeast)
+ * @author Sungju Jin
*/
@Component
public class SqliteRunner implements QueryRunner {
@@ -65,8 +67,28 @@ public class SqliteRunner implements QueryRunner {
feilds.append(key);
feilds.append(",");
- Object value = entity.getProperty(key);
- Class type = value.getClass();
+ Class type = null;
+ try
+ {
+ type = entity.getProperty(key).getClass();
+ } catch (NullPointerException ne) {
+ type = entity.getDynamicProperties().get(key).getClass();
+ }
+
+ Object value = null;
+ if(StringUtils.equals("name",key)) {
+ value = entity.getName();
+ } else {
+ value = entity.getProperty(key);
+ }
+ if( type == Boolean.class ) {
+ if((Boolean)value) {
+ value = 1;
+ } else {
+ value = 0;
+ }
+ }
+
String sqlType = getSqlDatatype(type);
if( StringUtils.equals("TEXT", sqlType) ) {
values.append("'");
@@ -104,7 +126,14 @@ public class SqliteRunner implements QueryRunner {
builder.append(key);
builder.append(" ");
- Class type = entity.getProperty(key).getClass();
+ Class type = null;
+ try
+ {
+ type = entity.getProperty(key).getClass();
+ } catch (NullPointerException ne) {
+ type = entity.getDynamicProperties().get(key).getClass();
+ }
+
String sqlType = getSqlDatatype(type);
builder.append(sqlType);
builder.append(",");
@@ -140,10 +169,13 @@ public class SqliteRunner implements QueryRunner {
// based on sqlite (http://www.sqlite.org/datatype3.html)
private String getSqlDatatype(Class clz) {
+ if ( clz == null )
+ return "TEXT";
+
if( clz == Integer.class || clz == Long.class || clz == Boolean.class ) {
return "INTEGER";
} else if( clz == Double.class ) {
- return "REAL";
+ return "REAL";
} else if( clz == Byte.class ) {
return "BLOB";
}
@@ -157,4 +189,4 @@ public class SqliteRunner implements QueryRunner {
public void setEntities(List<Entity> entities) {
this.entities = entities;
}
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ebfe96e8/stack/query-validator/src/main/resources/usergrid-query-validator-context.xml
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/main/resources/usergrid-query-validator-context.xml b/stack/query-validator/src/main/resources/usergrid-query-validator-context.xml
index b2bf935..89679d7 100644
--- a/stack/query-validator/src/main/resources/usergrid-query-validator-context.xml
+++ b/stack/query-validator/src/main/resources/usergrid-query-validator-context.xml
@@ -1,16 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
- <context:annotation-config />
+ <context:annotation-config />
<context:component-scan base-package="org.usergrid.query.validator" />
- <import resource="classpath:/usergrid-core-context.xml" />
-
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.sqlite.JDBC" />
@@ -20,4 +18,4 @@
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource" />
</bean>
-</beans>
+</beans>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ebfe96e8/stack/query-validator/src/test/java/org/usergrid/query/validator/AbstractQueryIT.java
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/test/java/org/usergrid/query/validator/AbstractQueryIT.java b/stack/query-validator/src/test/java/org/usergrid/query/validator/AbstractQueryIT.java
new file mode 100644
index 0000000..b48e094
--- /dev/null
+++ b/stack/query-validator/src/test/java/org/usergrid/query/validator/AbstractQueryIT.java
@@ -0,0 +1,133 @@
+/**
+ * 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;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.StringUtils;
+import org.junit.BeforeClass;
+import org.usergrid.management.ApplicationInfo;
+import org.usergrid.management.ManagementService;
+import org.usergrid.management.OrganizationInfo;
+import org.usergrid.management.UserInfo;
+import org.usergrid.persistence.Entity;
+import org.usergrid.utils.JsonUtils;
+
+import java.io.IOException;
+import java.net.URL;
+import java.nio.charset.Charset;
+import java.util.*;
+
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * @author Sungju Jin
+ */
+public class AbstractQueryIT {
+
+ protected static QueryValidator validator;
+ private static Properties properties;
+ private static String fullEndpoint;
+ private static String orgName;
+ private static String appName;
+ private static String email;
+ private static String password;
+ private static int port;
+
+ @BeforeClass
+ public static void tearsup() throws Exception {
+ validator = QueryITSuite.cassandraResource.getBean(QueryValidator.class);
+ properties = QueryITSuite.cassandraResource.getBean("properties",Properties.class);
+ if( isDisableLocalServer()) {
+ return;
+ }
+ setProperties();
+ createOrganizationWithApplication();
+ }
+
+ private static void createOrganizationWithApplication() throws Exception {
+ String uuid = UUID.randomUUID().toString().replaceAll("-", "");
+ orgName = orgName + uuid;
+ appName = appName + uuid;
+ email = orgName + "@usergrid.com";
+ ManagementService managementService = QueryITSuite.serverResource.getMgmtSvc();
+ UserInfo user = managementService.createAdminUser(orgName, "Query Test", email, password, false, false);
+ OrganizationInfo org = managementService.createOrganization(orgName, user, false );
+ assertNotNull( org );
+ ApplicationInfo app = managementService.createApplication( org.getUuid(), appName);
+ assertNotNull( app );
+ }
+
+ private static void setProperties() {
+ port = QueryITSuite.serverResource.getTomcatPort();
+ fullEndpoint = (String)properties.get("usergrid.query.validator.api.endpoint") + ":" + port;
+ orgName = (String)properties.get("usergrid.query.validator.api.organization");
+ appName = (String)properties.get("usergrid.query.validator.api.app");
+ email = (String)properties.get("usergrid.query.validator.api.authorize.email");
+ password = (String)properties.get("usergrid.query.validator.api.authorize.password");
+ }
+
+ protected static void createInitializationDatas(String collection) {
+ List<Entity> entities = loadEntitiesFromResource(collection);
+ QueryValidationConfiguration configuration = new QueryValidationConfiguration();
+ configuration.setEndpointUri(fullEndpoint);
+ configuration.setOrg(orgName);
+ configuration.setEmail(email);
+ configuration.setPassword(password);
+ configuration.setApp(appName);
+ configuration.setCollection(collection);
+ configuration.setEntities(entities);
+ validator.setConfiguration(configuration);
+ validator.setup();
+ }
+
+ private static List<Entity> loadEntitiesFromResource(String collection) {
+ String json = null;
+ try {
+ URL url = Thread.currentThread().getContextClassLoader().getResource(collection + ".json");
+ json = FileUtils.readFileToString(FileUtils.toFile(url), Charset.forName("UTF-8"));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ List<Entity> entities = new ArrayList<Entity>();
+ List<Map<String, Object>> datas = (List<Map<String, Object>>) JsonUtils.parse(json);
+ int index = 0;
+ for(Map<String, Object> data : datas) {
+ long created = System.currentTimeMillis() + (index*1000);
+
+ QueryEntity entity = new QueryEntity();
+ entity.setType(collection);
+ for ( Map.Entry<String, Object> property : data.entrySet() ) {
+ if(StringUtils.equals("name", property.getKey()))
+ entity.setName((String)property.getValue());
+ else
+ entity.setProperty( property.getKey(), property.getValue() );
+ }
+ entity.setProperties(data);
+ entity.setCreated(created);
+ entity.setModified(created);
+ entities.add(entity);
+ index++;
+ }
+ return entities;
+ }
+
+ private static boolean isDisableLocalServer() {
+ return !StringUtils.equalsIgnoreCase("true", (String) properties.get("usergrid.query.validator.api.enablelocal"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ebfe96e8/stack/query-validator/src/test/java/org/usergrid/query/validator/QueryITSuite.java
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/test/java/org/usergrid/query/validator/QueryITSuite.java b/stack/query-validator/src/test/java/org/usergrid/query/validator/QueryITSuite.java
new file mode 100644
index 0000000..327776f
--- /dev/null
+++ b/stack/query-validator/src/test/java/org/usergrid/query/validator/QueryITSuite.java
@@ -0,0 +1,39 @@
+/**
+ * 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;
+
+import org.junit.ClassRule;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.usergrid.cassandra.CassandraResource;
+import org.usergrid.query.validator.users.UserQueryIT;
+import org.usergrid.rest.ITSetup;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses(
+ {
+ UserQueryIT.class
+ })
+public class QueryITSuite {
+ @ClassRule
+ public static CassandraResource cassandraResource = CassandraResource.newWithAvailablePorts();
+
+ //TODO Detecting current path
+ @ClassRule
+ public static ITSetup serverResource = new ITSetup( cassandraResource, "../rest/src/main/webapp" );
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ebfe96e8/stack/query-validator/src/test/java/org/usergrid/query/validator/QueryValidationTest.java
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/test/java/org/usergrid/query/validator/QueryValidationTest.java b/stack/query-validator/src/test/java/org/usergrid/query/validator/QueryValidationTest.java
deleted file mode 100644
index 5fbacb3..0000000
--- a/stack/query-validator/src/test/java/org/usergrid/query/validator/QueryValidationTest.java
+++ /dev/null
@@ -1,339 +0,0 @@
-/*******************************************************************************
- * Copyright 2013 baas.io
- *
- * 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.usergrid.query.validator;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.Assert;
-
-/**
- * @author Sung-ju Jin(realbeast)
- */
-@RunWith(QueryValidatorRunner.class)
-public class QueryValidationTest {
-
- private QueryValidator validator;
-
- @Before
- public void setup() {
- validator = QueryValidatorRunner.getValidator();
- }
-
- @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);
- 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);
- 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);
- 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_limitL100() {
- String sqlite = "SELECT * FROM users WHERE sex = 'male' and age >= 35 ORDER BY age desc LIMIT 100";
- String api = "select * where sex = 'male' and age >= 35 order by age 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 qlSexEqualAndAgeGreaterthanequal_sortNameDesc_limitL100() {
- String sqlite = "SELECT * FROM users WHERE sex = 'male' and age >= 35 ORDER BY name desc LIMIT 100";
- String api = "select * where sex = 'male' and age >= 35 order by name 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 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);
- 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_limitL100() {
- String sqlite = "SELECT * FROM users WHERE sex = 'male' and age >= 35 or sex = 'female' ORDER BY name desc LIMIT 100";
- String api = "select * where sex = 'male' and age >= 35 or sex = 'female' order by name 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 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());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ebfe96e8/stack/query-validator/src/test/java/org/usergrid/query/validator/QueryValidatorRunner.java
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/test/java/org/usergrid/query/validator/QueryValidatorRunner.java b/stack/query-validator/src/test/java/org/usergrid/query/validator/QueryValidatorRunner.java
deleted file mode 100644
index 6f9d443..0000000
--- a/stack/query-validator/src/test/java/org/usergrid/query/validator/QueryValidatorRunner.java
+++ /dev/null
@@ -1,209 +0,0 @@
-/*******************************************************************************
- * Copyright 2013 baas.io
- *
- * 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.usergrid.query.validator;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang.StringUtils;
-import org.junit.runner.notification.RunNotifier;
-import org.junit.runners.model.InitializationError;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.usergrid.cassandra.CassandraRunner;
-import org.usergrid.cassandra.DataControl;
-import org.usergrid.management.ManagementService;
-import org.usergrid.persistence.Entity;
-import org.usergrid.standalone.Server;
-import org.usergrid.utils.JsonUtils;
-
-import java.io.IOException;
-import java.net.URL;
-import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-/**
- * @author Sung-ju Jin(realbeast)
- */
-public class QueryValidatorRunner extends CassandraRunner {
-
- private static Logger logger = LoggerFactory.getLogger(QueryValidatorRunner.class);
- private boolean enableLocalServer;
- private static StandaloneServer standaloneServer;
- private Properties properties;
- private static QueryValidator validator;
- private static boolean initialize = false;
-
- public QueryValidatorRunner(Class<?> klass) throws InitializationError {
- super(klass);
- }
-
- @Override
- protected DataControl preTest(RunNotifier notifier) {
- DataControl control = super.preTest(notifier);
- try {
- setup();
- } catch (InitializationError initializationError) {
- initializationError.printStackTrace();
- }
- return control;
- }
-
- public static QueryValidator getValidator() {
- return validator;
- }
-
- public synchronized void setup() throws InitializationError {
- if(initialize)
- return;
-
- try {
- logger.info("Loading initialize...");
- Thread.sleep(20*1000);
- } catch (InterruptedException e) {}
-
- validator = CassandraRunner.getBean(QueryValidator.class);
- properties = CassandraRunner.getBean("properties",Properties.class);
-
- if( validator == null || properties == null) {
- throw new InitializationError("Application context not loaded.");
- }
-
- String enableString = (String)properties.get("usergrid.query.validator.api.enablelocal");
- enableLocalServer = StringUtils.endsWithIgnoreCase("true", enableString);
- if( enableLocalServer ) {
- startStandaloneServer();
- try {
- logger.info("Loading standalone server...");
- Thread.sleep(20*1000);
- } catch (InterruptedException e) {}
- }
- initialize = true;
-
- String endpoint = (String)properties.get("usergrid.query.validator.api.endpoint");
- String organization = (String)properties.get("usergrid.query.validator.api.organization");
- String app = (String)properties.get("usergrid.query.validator.api.app");
- String email = (String)properties.get("usergrid.query.validator.api.authorize.email");
- String password = (String)properties.get("usergrid.query.validator.api.authorize.password");
-
- String collection = "user";
- List<Entity> entities = loadEntities(collection);
- QueryValidationConfiguration configuration = new QueryValidationConfiguration();
- configuration.setEndpointUri(endpoint);
- configuration.setOrg(organization);
- configuration.setEmail(email);
- configuration.setPassword(password);
- configuration.setApp(app);
- configuration.setCollection(collection);
- configuration.setEntities(entities);
- validator.setConfiguration(configuration);
- validator.setup();
-
- }
-
- private List<Entity> loadEntities(String collection) {
- String json = null;
- try {
- URL url = Thread.currentThread().getContextClassLoader().getResource(collection + ".json");
- json = FileUtils.readFileToString(FileUtils.toFile(url), Charset.forName("UTF-8"));
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- List<Entity> entities = new ArrayList<Entity>();
- List<Map<String, Object>> datas = (List<Map<String, Object>>) JsonUtils.parse(json);
- for(Map<String, Object> data : datas) {
- Entity entity = new QueryEntity();
- entity.setType(collection);
- entity.setProperties(data);
- entity.setCreated(System.currentTimeMillis());
- entity.setModified(entity.getCreated());
- entities.add(entity);
- }
- return entities;
- }
-
- private void startStandaloneServer() {
- standaloneServer = new StandaloneServer();
- try {
- Thread thread = new Thread(standaloneServer);
- thread.start();
- } catch (Exception ex) {
- logger.error("Could not schedule standalone server runner", ex);
- }
- Runtime.getRuntime().addShutdownHook(new Thread() {
- @Override
- public void run() {
- try {
- logger.error("In shutdownHook");
- stopServer();
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- });
- boolean loaded = false;
- while (!loaded) {
- if( standaloneServer.server.isRunning() ) {
- if( standaloneServer.server.getManagementService() != null ) {
- loaded = true;
- continue;
- }
- }
- try {
- logger.info("Loding application context...");
- Thread.sleep(2*1000);
- } catch (InterruptedException e) {
- continue;
- }
- }
-
- if(loaded) {
- ManagementService managementService = standaloneServer.server.getManagementService();
- try {
- managementService.setup();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- logger.info("Finish start standalone server.");
- }
-
- static class StandaloneServer implements Runnable {
- public static Server server;
-
- public StandaloneServer() {
- server = new Server();
- }
-
- @Override
- public void run() {
- server.setInitializeDatabaseOnStart(true);
- server.setDaemon(false);
- server.startServer();
- }
-
- public void stop() {
- server.stopServer();
- }
- }
-
- private void stopServer() {
- standaloneServer.stop();
- }
-}