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/02/13 21:21:56 UTC
[38/50] [abbrv] git commit: Missed a couple of package-rename spots
in query-validator,
there still one compilation problem in QueryValidatorRunner.
Missed a couple of package-rename spots in query-validator, there still one compilation problem in QueryValidatorRunner.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/482c5cef
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/482c5cef
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/482c5cef
Branch: refs/heads/optimistic-tx-semantics
Commit: 482c5ceffc9492af2828444d712492607a3baa32
Parents: ad8d78f
Author: Dave Johnson <dm...@apigee.com>
Authored: Thu Feb 13 08:33:43 2014 -0500
Committer: Dave Johnson <dm...@apigee.com>
Committed: Thu Feb 13 08:33:43 2014 -0500
----------------------------------------------------------------------
stack/query-validator/pom.xml | 33 +-
.../query/validator/ApiServerRunner.java | 212 ++++++++++++
.../usergrid/query/validator/QueryEntity.java | 34 ++
.../usergrid/query/validator/QueryRequest.java | 74 ++++
.../usergrid/query/validator/QueryResponse.java | 103 ++++++
.../usergrid/query/validator/QueryRunner.java | 28 ++
.../validator/QueryValidationConfiguration.java | 74 ++++
.../query/validator/QueryValidator.java | 77 +++++
.../usergrid/query/validator/SqliteRunner.java | 160 +++++++++
.../query/validator/ApiServerRunner.java | 212 ------------
.../usergrid/query/validator/QueryEntity.java | 34 --
.../usergrid/query/validator/QueryRequest.java | 74 ----
.../usergrid/query/validator/QueryResponse.java | 103 ------
.../usergrid/query/validator/QueryRunner.java | 28 --
.../validator/QueryValidationConfiguration.java | 74 ----
.../query/validator/QueryValidator.java | 77 -----
.../usergrid/query/validator/SqliteRunner.java | 160 ---------
.../query/validator/CassandraRunner.java | 199 +++++++++++
.../query/validator/QueryValidationTest.java | 339 +++++++++++++++++++
.../query/validator/QueryValidatorRunner.java | 207 +++++++++++
.../query/validator/QueryValidationTest.java | 339 -------------------
.../query/validator/QueryValidatorRunner.java | 209 ------------
stack/rest/pom.xml | 4 +-
23 files changed, 1513 insertions(+), 1341 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/482c5cef/stack/query-validator/pom.xml
----------------------------------------------------------------------
diff --git a/stack/query-validator/pom.xml b/stack/query-validator/pom.xml
index 4f523a6..33c61f9 100644
--- a/stack/query-validator/pom.xml
+++ b/stack/query-validator/pom.xml
@@ -5,7 +5,7 @@
<parent>
<groupId>org.apache.usergrid</groupId>
<artifactId>usergrid</artifactId>
- <version>0.0.16-SNAPSHOT</version>
+ <version>0.0.29-SNAPSHOT</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -97,16 +97,6 @@
</dependency>
<dependency>
<groupId>org.apache.usergrid</groupId>
- <artifactId>usergrid-count-batcher</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.usergrid</groupId>
- <artifactId>usergrid-count-common</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.usergrid</groupId>
<artifactId>usergrid-test-utils</artifactId>
<version>${project.version}</version>
<scope>test</scope>
@@ -124,11 +114,6 @@
</dependency>
<dependency>
<groupId>org.apache.usergrid</groupId>
- <artifactId>usergrid-scheduler</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.usergrid</groupId>
<artifactId>usergrid-core</artifactId>
<version>${project.version}</version>
<scope>test</scope>
@@ -212,22 +197,12 @@
<artifactId>sqlite-jdbc</artifactId>
<version>3.7.2</version>
</dependency>
- <dependency>
- <groupId>org.apache.usergrid</groupId>
+ <dependency>
+ <groupId>org.usergrid</groupId>
<artifactId>usergrid-java-client</artifactId>
<version>0.0.3</version>
<scope>compile</scope>
</dependency>
- <dependency>
- <groupId>org.apache.usergrid</groupId>
- <artifactId>usergrid-standalone</artifactId>
- <version>${project.version}</version>
- <exclusions>
- <exclusion>
- <artifactId>commons-logging</artifactId>
- <groupId>commons-logging</groupId>
- </exclusion>
- </exclusions>
- </dependency>
</dependencies>
+
</project>
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/482c5cef/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/ApiServerRunner.java
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/ApiServerRunner.java b/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/ApiServerRunner.java
new file mode 100644
index 0000000..c5f28e6
--- /dev/null
+++ b/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/ApiServerRunner.java
@@ -0,0 +1,212 @@
+/*******************************************************************************
+ * 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.apache.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.apache.usergrid.persistence.Entity;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import org.apache.usergrid.persistence.Schema;
+
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.usergrid.java.client.Client;
+import org.usergrid.java.client.response.ApiResponse;
+
+import static org.usergrid.java.client.utils.ObjectUtils.isEmpty;
+
+/**
+ * @author Sung-ju Jin(realbeast)
+ */
+@Component
+public class ApiServerRunner implements QueryRunner {
+
+ private Logger logger = Logger.getLogger(SqliteRunner.class.getName());
+ private Client client;
+
+ private String org;
+ private String app;
+ private String baseUri;
+ private String email;
+ private String password;
+ private String collection;
+ private List<Entity> entities;
+
+ @Override
+ public boolean setup() {
+ client = new Client(getOrg(), getApp()).withApiUrl(getBaseUri());
+ String accessToken = authorize(email, password);
+ if(!StringUtils.isEmpty(accessToken))
+ client.setAccessToken(accessToken);
+ return insertDatas();
+ }
+
+ public String authorize(String email, String password) {
+ String accessToken = null;
+ Map<String, Object> formData = new HashMap<String, Object>();
+ formData.put("grant_type", "password");
+ formData.put("username", email);
+ formData.put("password", password);
+ ApiResponse response = client.apiRequest(HttpMethod.POST, null, formData,
+ "management", "token");
+ if (!isEmpty(response.getAccessToken())) {
+ accessToken = response.getAccessToken();
+ logger.info("Access token: " + accessToken);
+ } else {
+ logger.info("Response: " + response);
+ }
+ return accessToken;
+ }
+
+ 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;
+ }
+
+ private List<org.usergrid.java.client.entities.Entity> getEntitiesForClient(List<Entity> entities) {
+ List<org.usergrid.java.client.entities.Entity> clientEntities = new ArrayList<org.usergrid.java.client.entities.Entity>();
+ for(Entity entity : entities) {
+ org.usergrid.java.client.entities.Entity clientEntity = new org.usergrid.java.client.entities.Entity();
+ clientEntity.setType(entity.getType());
+ Map<String, Object> properties = Schema.getDefaultSchema().getEntityProperties(entity);
+ for(String key : properties.keySet()) {
+ Object value = entity.getProperty(key);
+ if( value instanceof String )
+ clientEntity.setProperty(key,(String)value );
+ else if( value instanceof Long )
+ clientEntity.setProperty(key,(Long)value );
+ else if( value instanceof Integer )
+ clientEntity.setProperty(key,(Integer)value );
+ else if( value instanceof Float )
+ clientEntity.setProperty(key,(Float)value );
+ else if( value instanceof Boolean )
+ clientEntity.setProperty(key,(Boolean)value );
+ }
+ clientEntities.add(clientEntity);
+ }
+ return clientEntities;
+ }
+
+ @Override
+ public List<Entity> execute(String query) {
+ return execute(query, 10);
+ }
+
+ @Override
+ public List<Entity> execute(String query, int limit) {
+ Map<String, Object> params = new HashMap<String, Object>();
+ params.put("ql", query);
+ params.put("limit", limit);
+ ApiResponse response = client.apiRequest(HttpMethod.GET, params, null, getOrg(), getApp(), getCollection());
+ List<Entity> entities = new ArrayList<Entity>();
+ if( response.getEntities() == null )
+ return entities;
+
+ for(org.usergrid.java.client.entities.Entity clientEntitity : response.getEntities()) {
+ Entity entity = new QueryEntity();
+ entity.setUuid(clientEntitity.getUuid());
+ entity.setType(clientEntitity.getType());
+ Map<String, JsonNode> values = clientEntitity.getProperties();
+ for( String key : values.keySet() ) {
+ JsonNode node = values.get(key);
+ if( node.isBoolean() ) {
+ entity.setProperty(key, node.asBoolean());
+ } else if( node.isInt() ) {
+ entity.setProperty(key, node.asInt());
+ } else if( node.isLong() ) {
+ entity.setProperty(key, node.asLong());
+ } else if( node.isDouble() ) {
+ entity.setProperty(key, node.asDouble());
+ } else {
+ entity.setProperty(key, node.asText());
+ }
+ }
+ entities.add(entity);
+ }
+ return entities;
+ }
+
+ public String getOrg() {
+ return org;
+ }
+
+ public void setOrg(String org) {
+ this.org = org;
+ }
+
+ public String getApp() {
+ return app;
+ }
+
+ public void setApp(String app) {
+ this.app = app;
+ }
+
+ public String getBaseUri() {
+ return baseUri;
+ }
+
+ public void setBaseUri(String baseUri) {
+ this.baseUri = baseUri;
+ }
+
+ public String getCollection() {
+ return collection;
+ }
+
+ public void setCollection(String collection) {
+ this.collection = collection;
+ }
+
+ public List<Entity> getEntities() {
+ return entities;
+ }
+
+ public void setEntities(List<Entity> entities) {
+ this.entities = entities;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/482c5cef/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/QueryEntity.java
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/QueryEntity.java b/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/QueryEntity.java
new file mode 100644
index 0000000..77893bd
--- /dev/null
+++ b/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/QueryEntity.java
@@ -0,0 +1,34 @@
+package org.apache.usergrid.query.validator;
+
+import org.apache.usergrid.persistence.DynamicEntity;
+
+import java.util.Map;
+
+public class QueryEntity extends DynamicEntity {
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ if(!(obj instanceof QueryEntity))
+ return false;
+
+ QueryEntity other = (QueryEntity)obj;
+ Map<String, Object> properties = this.getProperties();
+ Map<String, Object> otherProperties = other.getProperties();
+ for(String key : properties.keySet()) {
+ if( "created".equals(key) || "modified".equals(key) )
+ continue;
+
+ Object value = properties.get(key);
+ Object otherValue = otherProperties.get(key);
+ if( otherValue == null || !value.equals(otherValue) )
+ return false;
+ }
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/482c5cef/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/QueryRequest.java
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/QueryRequest.java b/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/QueryRequest.java
new file mode 100644
index 0000000..d2989c7
--- /dev/null
+++ b/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/QueryRequest.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * 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.apache.usergrid.query.validator;
+
+/**
+ * @author Sung-ju Jin(realbeast)
+ */
+public class QueryRequest {
+ private String dbQuery;
+ private ApiQuery apiQuery;
+ private boolean ignoreOrdering;
+
+ public QueryRequest() {
+ this.apiQuery = new ApiQuery();
+ }
+
+ public String getDbQuery() {
+ return dbQuery;
+ }
+
+ public void setDbQuery(String dbQuery) {
+ this.dbQuery = dbQuery;
+ }
+
+ public ApiQuery getApiQuery() {
+ return apiQuery;
+ }
+
+ static public class ApiQuery {
+ private String query;
+ private int limit;
+
+ public ApiQuery() {
+ limit = 10;
+ }
+
+ public String getQuery() {
+ return query;
+ }
+
+ public void setQuery(String query) {
+ this.query = query;
+ }
+
+ public int getLimit() {
+ return limit;
+ }
+
+ public void setLimit(int limit) {
+ this.limit = limit;
+ }
+ }
+
+ public boolean isIgnoreOrdering() {
+ return ignoreOrdering;
+ }
+
+ public void setIgnoreOrdering(boolean ignoreOrdering) {
+ this.ignoreOrdering = ignoreOrdering;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/482c5cef/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/QueryResponse.java
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/QueryResponse.java b/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/QueryResponse.java
new file mode 100644
index 0000000..aa152d5
--- /dev/null
+++ b/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/QueryResponse.java
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * 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.apache.usergrid.query.validator;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.usergrid.persistence.Entity;
+
+import java.util.List;
+
+/**
+ * @author Sung-ju Jin(realbeast)
+ */
+public class QueryResponse {
+
+ boolean result;
+ List<Entity> expacted;
+ List<Entity> actually;
+ String description;
+ QueryRequest request;
+
+ public boolean result() {
+ return result;
+ }
+
+ public void setResult(boolean result) {
+ this.result = result;
+ }
+
+ public List<Entity> getExpacted() {
+ return expacted;
+ }
+
+ public void setExpacted(List<Entity> expacted) {
+ this.expacted = expacted;
+ }
+
+ public List<Entity> getActually() {
+ return actually;
+ }
+
+ public void setActually(List<Entity> actually) {
+ this.actually = actually;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public QueryRequest getRequest() {
+ return request;
+ }
+
+ public void setRequest(QueryRequest request) {
+ this.request = request;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("\n");
+ builder.append(StringUtils.rightPad("", 20, "-"));
+ builder.append("\n");
+ builder.append(StringUtils.rightPad("* Expected", 20, " "));
+ builder.append("\n");
+ builder.append("list size : " + expacted.size());
+ builder.append("\n");
+ for(Entity entity : expacted) {
+ builder.append(entity.toString());
+ builder.append("\n");
+ }
+
+ builder.append("\n");
+ builder.append(StringUtils.rightPad("* Actually", 20, " "));
+ builder.append("\n");
+ builder.append("list size : " + actually.size());
+ builder.append("\n");
+ for(Entity entity : actually) {
+ builder.append(entity.toString());
+ builder.append("\n");
+ }
+
+ builder.append(StringUtils.rightPad("", 20, "-"));
+ builder.append("\n");
+ return builder.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/482c5cef/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/QueryRunner.java
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/QueryRunner.java b/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/QueryRunner.java
new file mode 100644
index 0000000..06341d6
--- /dev/null
+++ b/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/QueryRunner.java
@@ -0,0 +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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.usergrid.query.validator;
+
+import java.util.List;
+import org.apache.usergrid.persistence.Entity;
+
+/**
+ * @author Sung-ju Jin(realbeast)
+ */
+public interface QueryRunner {
+ public boolean setup();
+ public List<Entity> execute(String query);
+ public List<Entity> execute(String query, int limit);
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/482c5cef/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/QueryValidationConfiguration.java
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/QueryValidationConfiguration.java b/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/QueryValidationConfiguration.java
new file mode 100644
index 0000000..8b14737
--- /dev/null
+++ b/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/QueryValidationConfiguration.java
@@ -0,0 +1,74 @@
+package org.apache.usergrid.query.validator;
+
+import org.apache.usergrid.persistence.Entity;
+import org.apache.usergrid.utils.InflectionUtils;
+
+import java.util.List;
+
+public class QueryValidationConfiguration {
+
+ String org;
+ String app;
+ String endpointUri;
+ String email;
+ String password;
+ String collection;
+ List<Entity> entities;
+
+ public String getCollection() {
+ return collection;
+ }
+
+ public void setCollection(String collection) {
+ String pluralizeName = InflectionUtils.pluralize(collection);
+ this.collection = pluralizeName;
+ }
+
+ public String getOrg() {
+ return org;
+ }
+
+ public void setOrg(String org) {
+ this.org = org;
+ }
+
+ public String getApp() {
+ return app;
+ }
+
+ public void setApp(String app) {
+ this.app = app;
+ }
+
+ public String getEndpointUri() {
+ return endpointUri;
+ }
+
+ public void setEndpointUri(String endpointUri) {
+ this.endpointUri = endpointUri;
+ }
+
+ public List<Entity> getEntities() {
+ return entities;
+ }
+
+ public void setEntities(List<Entity> entities) {
+ this.entities = entities;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/482c5cef/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/QueryValidator.java
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/QueryValidator.java b/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/QueryValidator.java
new file mode 100644
index 0000000..180a8e5
--- /dev/null
+++ b/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/QueryValidator.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * 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.apache.usergrid.query.validator;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.apache.usergrid.persistence.Entity;
+
+import java.util.List;
+
+/**
+ * @author Sung-ju Jin(realbeast)
+ */
+@Component
+public class QueryValidator {
+
+ QueryValidationConfiguration configuration;
+ @Autowired
+ ApiServerRunner api;
+ @Autowired
+ SqliteRunner sql;
+
+ public QueryValidator() {
+ }
+
+ public QueryValidator(QueryValidationConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+ public boolean setup() {
+ return api.setup() && sql.setup();
+ }
+
+ public QueryResponse execute(QueryRequest request) {
+ 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);
+ }
+
+ QueryResponse response = new QueryResponse();
+ response.setResult(equals);
+ response.setExpacted(sqlEntities);
+ response.setActually(apiEntities);
+ return response;
+ }
+
+ public void setConfiguration(QueryValidationConfiguration configuration) {
+ this.configuration = configuration;
+ sql.setCollection(configuration.getCollection());
+ sql.setEntities(configuration.getEntities());
+
+ api.setOrg(configuration.getOrg());
+ api.setApp(configuration.getApp());
+ api.setBaseUri(configuration.getEndpointUri());
+ api.setCollection(configuration.getCollection());
+ api.setEntities(configuration.getEntities());
+ api.setEmail(configuration.getEmail());
+ api.setPassword(configuration.getPassword());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/482c5cef/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/SqliteRunner.java
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/SqliteRunner.java b/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/SqliteRunner.java
new file mode 100644
index 0000000..a1932a0
--- /dev/null
+++ b/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/SqliteRunner.java
@@ -0,0 +1,160 @@
+/*******************************************************************************
+ * 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.apache.usergrid.query.validator;
+
+import org.apache.commons.lang.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.stereotype.Component;
+import org.apache.usergrid.persistence.Entity;
+import org.apache.usergrid.persistence.Schema;
+
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Logger;
+
+/**
+ * @author Sung-ju Jin(realbeast)
+ */
+@Component
+public class SqliteRunner implements QueryRunner {
+
+ private Logger logger = Logger.getLogger(SqliteRunner.class.getName());
+
+ @Autowired
+ private JdbcTemplate jdbcTemplate;
+ private String collection;
+ private List<Entity> entities;
+
+ @Override
+ public boolean setup() {
+ createTable();
+ insertDatas();
+
+ return true;
+ }
+
+ private void insertDatas() {
+ for( Entity entity : entities ) {
+ insertData(entity);
+ }
+ }
+
+ private void insertData(Entity entity) {
+ StringBuilder feilds = new StringBuilder();
+ StringBuilder values = new StringBuilder();
+ Map<String, Object> properties = Schema.getDefaultSchema().getEntityProperties(entity);
+ for(String key : properties.keySet()) {
+ feilds.append(key);
+ feilds.append(",");
+
+ Object value = entity.getProperty(key);
+ Class type = value.getClass();
+ String sqlType = getSqlDatatype(type);
+ if( StringUtils.equals("TEXT", sqlType) ) {
+ values.append("'");
+ values.append(value);
+ values.append("'");
+ } else {
+ values.append(value);
+ }
+ values.append(",");
+ }
+ feilds.deleteCharAt(feilds.length()-1);
+ values.deleteCharAt(values.length()-1);
+
+ StringBuilder builder = new StringBuilder();
+ builder.append("INSERT INTO ");
+ builder.append(collection);
+ builder.append("(");
+ builder.append(feilds);
+ builder.append(")");
+ builder.append(" VALUES(");
+ builder.append(values);
+ builder.append(")");
+ logger.info(builder.toString());
+ jdbcTemplate.execute(builder.toString());
+ }
+
+ private void createTable() {
+ Entity entity = entities.get(0);
+ StringBuilder builder = new StringBuilder();
+ builder.append("CREATE TABLE ");
+ builder.append(collection);
+ builder.append("(");
+ Map<String, Object> properties = Schema.getDefaultSchema().getEntityProperties(entity);
+ for(String key : properties.keySet()) {
+ builder.append(key);
+ builder.append(" ");
+
+ Class type = entity.getProperty(key).getClass();
+ String sqlType = getSqlDatatype(type);
+ builder.append(sqlType);
+ builder.append(",");
+ }
+ builder.deleteCharAt(builder.length()-1);
+ builder.append(")");
+
+ jdbcTemplate.execute("DROP TABLE IF EXISTS " + collection);
+ logger.info(builder.toString());
+ jdbcTemplate.execute(builder.toString());
+ }
+
+ @Override
+ public List<Entity> execute(String query) {
+ List<Entity> entities = jdbcTemplate.query(query, new RowMapper<Entity>() {
+ @Override
+ public Entity mapRow(ResultSet rs, int i) throws SQLException {
+ ResultSetMetaData rsmd = rs.getMetaData();
+ Entity entity = new QueryEntity();
+ for( int j = 1 ; j <= rsmd.getColumnCount() ; j++) {
+ entity.setProperty(rsmd.getColumnName(j), rs.getObject(j));
+ }
+ return entity;
+ }
+ });
+ return entities;
+ }
+
+ @Override
+ public List<Entity> execute(String query, int limit) {
+ return execute(query);
+ }
+
+ // based on sqlite (http://www.sqlite.org/datatype3.html)
+ private String getSqlDatatype(Class clz) {
+ if( clz == Integer.class || clz == Long.class || clz == Boolean.class ) {
+ return "INTEGER";
+ } else if( clz == Double.class ) {
+ return "REAL";
+ } else if( clz == Byte.class ) {
+ return "BLOB";
+ }
+ return "TEXT";
+ }
+
+ public void setCollection(String collection) {
+ this.collection = collection;
+ }
+
+ public void setEntities(List<Entity> entities) {
+ this.entities = entities;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/482c5cef/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
deleted file mode 100644
index c53d08b..0000000
--- a/stack/query-validator/src/main/java/org/usergrid/query/validator/ApiServerRunner.java
+++ /dev/null
@@ -1,212 +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.apache.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.apache.usergrid.java.client.response.ApiResponse;
-import org.apache.usergrid.persistence.Entity;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import org.apache.usergrid.java.client.Client;
-import org.apache.usergrid.persistence.Schema;
-
-import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import static org.apache.usergrid.java.client.utils.ObjectUtils.isEmpty;
-
-/**
- * @author Sung-ju Jin(realbeast)
- */
-@Component
-public class ApiServerRunner implements QueryRunner {
-
- private Logger logger = Logger.getLogger(SqliteRunner.class.getName());
- private Client client;
-
- private String org;
- private String app;
- private String baseUri;
- private String email;
- private String password;
- private String collection;
- private List<Entity> entities;
-
- @Override
- public boolean setup() {
- client = new Client(getOrg(), getApp()).withApiUrl(getBaseUri());
- String accessToken = authorize(email, password);
- if(!StringUtils.isEmpty(accessToken))
- client.setAccessToken(accessToken);
- return insertDatas();
- }
-
- public String authorize(String email, String password) {
- String accessToken = null;
- Map<String, Object> formData = new HashMap<String, Object>();
- formData.put("grant_type", "password");
- formData.put("username", email);
- formData.put("password", password);
- ApiResponse response = client.apiRequest(HttpMethod.POST, null, formData,
- "management", "token");
- if (!isEmpty(response.getAccessToken())) {
- accessToken = response.getAccessToken();
- logger.info("Access token: " + accessToken);
- } else {
- logger.info("Response: " + response);
- }
- return accessToken;
- }
-
- public boolean insertDatas() {
- List<org.apache.usergrid.java.client.entities.Entity> clientEntities = getEntitiesForClient(getEntities());
- for(org.apache.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.apache.usergrid.java.client.entities.Entity> getEntitiesForClient(List<Entity> entities) {
- List<org.apache.usergrid.java.client.entities.Entity> clientEntities = new ArrayList<org.apache.usergrid.java.client.entities.Entity>();
- for(Entity entity : entities) {
- org.apache.usergrid.java.client.entities.Entity clientEntity = new org.apache.usergrid.java.client.entities.Entity();
- clientEntity.setType(entity.getType());
- Map<String, Object> properties = Schema.getDefaultSchema().getEntityProperties(entity);
- for(String key : properties.keySet()) {
- Object value = entity.getProperty(key);
- if( value instanceof String )
- clientEntity.setProperty(key,(String)value );
- else if( value instanceof Long )
- clientEntity.setProperty(key,(Long)value );
- else if( value instanceof Integer )
- clientEntity.setProperty(key,(Integer)value );
- else if( value instanceof Float )
- clientEntity.setProperty(key,(Float)value );
- else if( value instanceof Boolean )
- clientEntity.setProperty(key,(Boolean)value );
- }
- clientEntities.add(clientEntity);
- }
- return clientEntities;
- }
-
- @Override
- public List<Entity> execute(String query) {
- return execute(query, 10);
- }
-
- @Override
- public List<Entity> execute(String query, int limit) {
- Map<String, Object> params = new HashMap<String, Object>();
- params.put("ql", query);
- params.put("limit", limit);
- ApiResponse response = client.apiRequest(HttpMethod.GET, params, null, getOrg(), getApp(), getCollection());
- List<Entity> entities = new ArrayList<Entity>();
- if( response.getEntities() == null )
- return entities;
-
- for(org.apache.usergrid.java.client.entities.Entity clientEntitity : response.getEntities()) {
- Entity entity = new QueryEntity();
- entity.setUuid(clientEntitity.getUuid());
- entity.setType(clientEntitity.getType());
- Map<String, JsonNode> values = clientEntitity.getProperties();
- for( String key : values.keySet() ) {
- JsonNode node = values.get(key);
- if( node.isBoolean() ) {
- entity.setProperty(key, node.asBoolean());
- } else if( node.isInt() ) {
- entity.setProperty(key, node.asInt());
- } else if( node.isLong() ) {
- entity.setProperty(key, node.asLong());
- } else if( node.isDouble() ) {
- entity.setProperty(key, node.asDouble());
- } else {
- entity.setProperty(key, node.asText());
- }
- }
- entities.add(entity);
- }
- return entities;
- }
-
- public String getOrg() {
- return org;
- }
-
- public void setOrg(String org) {
- this.org = org;
- }
-
- public String getApp() {
- return app;
- }
-
- public void setApp(String app) {
- this.app = app;
- }
-
- public String getBaseUri() {
- return baseUri;
- }
-
- public void setBaseUri(String baseUri) {
- this.baseUri = baseUri;
- }
-
- public String getCollection() {
- return collection;
- }
-
- public void setCollection(String collection) {
- this.collection = collection;
- }
-
- public List<Entity> getEntities() {
- return entities;
- }
-
- public void setEntities(List<Entity> entities) {
- this.entities = entities;
- }
-
- public String getEmail() {
- return email;
- }
-
- public void setEmail(String email) {
- this.email = email;
- }
-
- public String getPassword() {
- return password;
- }
-
- public void setPassword(String password) {
- this.password = password;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/482c5cef/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
deleted file mode 100644
index 77893bd..0000000
--- a/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryEntity.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package org.apache.usergrid.query.validator;
-
-import org.apache.usergrid.persistence.DynamicEntity;
-
-import java.util.Map;
-
-public class QueryEntity extends DynamicEntity {
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- if(!(obj instanceof QueryEntity))
- return false;
-
- QueryEntity other = (QueryEntity)obj;
- Map<String, Object> properties = this.getProperties();
- Map<String, Object> otherProperties = other.getProperties();
- for(String key : properties.keySet()) {
- if( "created".equals(key) || "modified".equals(key) )
- continue;
-
- Object value = properties.get(key);
- Object otherValue = otherProperties.get(key);
- if( otherValue == null || !value.equals(otherValue) )
- return false;
- }
- return true;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/482c5cef/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
deleted file mode 100644
index d2989c7..0000000
--- a/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryRequest.java
+++ /dev/null
@@ -1,74 +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.apache.usergrid.query.validator;
-
-/**
- * @author Sung-ju Jin(realbeast)
- */
-public class QueryRequest {
- private String dbQuery;
- private ApiQuery apiQuery;
- private boolean ignoreOrdering;
-
- public QueryRequest() {
- this.apiQuery = new ApiQuery();
- }
-
- public String getDbQuery() {
- return dbQuery;
- }
-
- public void setDbQuery(String dbQuery) {
- this.dbQuery = dbQuery;
- }
-
- public ApiQuery getApiQuery() {
- return apiQuery;
- }
-
- static public class ApiQuery {
- private String query;
- private int limit;
-
- public ApiQuery() {
- limit = 10;
- }
-
- public String getQuery() {
- return query;
- }
-
- public void setQuery(String query) {
- this.query = query;
- }
-
- public int getLimit() {
- return limit;
- }
-
- public void setLimit(int limit) {
- this.limit = limit;
- }
- }
-
- public boolean isIgnoreOrdering() {
- return ignoreOrdering;
- }
-
- public void setIgnoreOrdering(boolean ignoreOrdering) {
- this.ignoreOrdering = ignoreOrdering;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/482c5cef/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
deleted file mode 100644
index aa152d5..0000000
--- a/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryResponse.java
+++ /dev/null
@@ -1,103 +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.apache.usergrid.query.validator;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.usergrid.persistence.Entity;
-
-import java.util.List;
-
-/**
- * @author Sung-ju Jin(realbeast)
- */
-public class QueryResponse {
-
- boolean result;
- List<Entity> expacted;
- List<Entity> actually;
- String description;
- QueryRequest request;
-
- public boolean result() {
- return result;
- }
-
- public void setResult(boolean result) {
- this.result = result;
- }
-
- public List<Entity> getExpacted() {
- return expacted;
- }
-
- public void setExpacted(List<Entity> expacted) {
- this.expacted = expacted;
- }
-
- public List<Entity> getActually() {
- return actually;
- }
-
- public void setActually(List<Entity> actually) {
- this.actually = actually;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public QueryRequest getRequest() {
- return request;
- }
-
- public void setRequest(QueryRequest request) {
- this.request = request;
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("\n");
- builder.append(StringUtils.rightPad("", 20, "-"));
- builder.append("\n");
- builder.append(StringUtils.rightPad("* Expected", 20, " "));
- builder.append("\n");
- builder.append("list size : " + expacted.size());
- builder.append("\n");
- for(Entity entity : expacted) {
- builder.append(entity.toString());
- builder.append("\n");
- }
-
- builder.append("\n");
- builder.append(StringUtils.rightPad("* Actually", 20, " "));
- builder.append("\n");
- builder.append("list size : " + actually.size());
- builder.append("\n");
- for(Entity entity : actually) {
- builder.append(entity.toString());
- builder.append("\n");
- }
-
- builder.append(StringUtils.rightPad("", 20, "-"));
- builder.append("\n");
- return builder.toString();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/482c5cef/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
deleted file mode 100644
index 06341d6..0000000
--- a/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryRunner.java
+++ /dev/null
@@ -1,28 +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.apache.usergrid.query.validator;
-
-import java.util.List;
-import org.apache.usergrid.persistence.Entity;
-
-/**
- * @author Sung-ju Jin(realbeast)
- */
-public interface QueryRunner {
- public boolean setup();
- public List<Entity> execute(String query);
- public List<Entity> execute(String query, int limit);
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/482c5cef/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
deleted file mode 100644
index 8b14737..0000000
--- a/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryValidationConfiguration.java
+++ /dev/null
@@ -1,74 +0,0 @@
-package org.apache.usergrid.query.validator;
-
-import org.apache.usergrid.persistence.Entity;
-import org.apache.usergrid.utils.InflectionUtils;
-
-import java.util.List;
-
-public class QueryValidationConfiguration {
-
- String org;
- String app;
- String endpointUri;
- String email;
- String password;
- String collection;
- List<Entity> entities;
-
- public String getCollection() {
- return collection;
- }
-
- public void setCollection(String collection) {
- String pluralizeName = InflectionUtils.pluralize(collection);
- this.collection = pluralizeName;
- }
-
- public String getOrg() {
- return org;
- }
-
- public void setOrg(String org) {
- this.org = org;
- }
-
- public String getApp() {
- return app;
- }
-
- public void setApp(String app) {
- this.app = app;
- }
-
- public String getEndpointUri() {
- return endpointUri;
- }
-
- public void setEndpointUri(String endpointUri) {
- this.endpointUri = endpointUri;
- }
-
- public List<Entity> getEntities() {
- return entities;
- }
-
- public void setEntities(List<Entity> entities) {
- this.entities = entities;
- }
-
- public String getEmail() {
- return email;
- }
-
- public void setEmail(String email) {
- this.email = email;
- }
-
- public String getPassword() {
- return password;
- }
-
- public void setPassword(String password) {
- this.password = password;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/482c5cef/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
deleted file mode 100644
index 180a8e5..0000000
--- a/stack/query-validator/src/main/java/org/usergrid/query/validator/QueryValidator.java
+++ /dev/null
@@ -1,77 +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.apache.usergrid.query.validator;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-import org.apache.usergrid.persistence.Entity;
-
-import java.util.List;
-
-/**
- * @author Sung-ju Jin(realbeast)
- */
-@Component
-public class QueryValidator {
-
- QueryValidationConfiguration configuration;
- @Autowired
- ApiServerRunner api;
- @Autowired
- SqliteRunner sql;
-
- public QueryValidator() {
- }
-
- public QueryValidator(QueryValidationConfiguration configuration) {
- this.configuration = configuration;
- }
-
- public boolean setup() {
- return api.setup() && sql.setup();
- }
-
- public QueryResponse execute(QueryRequest request) {
- 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);
- }
-
- QueryResponse response = new QueryResponse();
- response.setResult(equals);
- response.setExpacted(sqlEntities);
- response.setActually(apiEntities);
- return response;
- }
-
- public void setConfiguration(QueryValidationConfiguration configuration) {
- this.configuration = configuration;
- sql.setCollection(configuration.getCollection());
- sql.setEntities(configuration.getEntities());
-
- api.setOrg(configuration.getOrg());
- api.setApp(configuration.getApp());
- api.setBaseUri(configuration.getEndpointUri());
- api.setCollection(configuration.getCollection());
- api.setEntities(configuration.getEntities());
- api.setEmail(configuration.getEmail());
- api.setPassword(configuration.getPassword());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/482c5cef/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
deleted file mode 100644
index a1932a0..0000000
--- a/stack/query-validator/src/main/java/org/usergrid/query/validator/SqliteRunner.java
+++ /dev/null
@@ -1,160 +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.apache.usergrid.query.validator;
-
-import org.apache.commons.lang.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.jdbc.core.RowMapper;
-import org.springframework.stereotype.Component;
-import org.apache.usergrid.persistence.Entity;
-import org.apache.usergrid.persistence.Schema;
-
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.SQLException;
-import java.util.List;
-import java.util.Map;
-import java.util.logging.Logger;
-
-/**
- * @author Sung-ju Jin(realbeast)
- */
-@Component
-public class SqliteRunner implements QueryRunner {
-
- private Logger logger = Logger.getLogger(SqliteRunner.class.getName());
-
- @Autowired
- private JdbcTemplate jdbcTemplate;
- private String collection;
- private List<Entity> entities;
-
- @Override
- public boolean setup() {
- createTable();
- insertDatas();
-
- return true;
- }
-
- private void insertDatas() {
- for( Entity entity : entities ) {
- insertData(entity);
- }
- }
-
- private void insertData(Entity entity) {
- StringBuilder feilds = new StringBuilder();
- StringBuilder values = new StringBuilder();
- Map<String, Object> properties = Schema.getDefaultSchema().getEntityProperties(entity);
- for(String key : properties.keySet()) {
- feilds.append(key);
- feilds.append(",");
-
- Object value = entity.getProperty(key);
- Class type = value.getClass();
- String sqlType = getSqlDatatype(type);
- if( StringUtils.equals("TEXT", sqlType) ) {
- values.append("'");
- values.append(value);
- values.append("'");
- } else {
- values.append(value);
- }
- values.append(",");
- }
- feilds.deleteCharAt(feilds.length()-1);
- values.deleteCharAt(values.length()-1);
-
- StringBuilder builder = new StringBuilder();
- builder.append("INSERT INTO ");
- builder.append(collection);
- builder.append("(");
- builder.append(feilds);
- builder.append(")");
- builder.append(" VALUES(");
- builder.append(values);
- builder.append(")");
- logger.info(builder.toString());
- jdbcTemplate.execute(builder.toString());
- }
-
- private void createTable() {
- Entity entity = entities.get(0);
- StringBuilder builder = new StringBuilder();
- builder.append("CREATE TABLE ");
- builder.append(collection);
- builder.append("(");
- Map<String, Object> properties = Schema.getDefaultSchema().getEntityProperties(entity);
- for(String key : properties.keySet()) {
- builder.append(key);
- builder.append(" ");
-
- Class type = entity.getProperty(key).getClass();
- String sqlType = getSqlDatatype(type);
- builder.append(sqlType);
- builder.append(",");
- }
- builder.deleteCharAt(builder.length()-1);
- builder.append(")");
-
- jdbcTemplate.execute("DROP TABLE IF EXISTS " + collection);
- logger.info(builder.toString());
- jdbcTemplate.execute(builder.toString());
- }
-
- @Override
- public List<Entity> execute(String query) {
- List<Entity> entities = jdbcTemplate.query(query, new RowMapper<Entity>() {
- @Override
- public Entity mapRow(ResultSet rs, int i) throws SQLException {
- ResultSetMetaData rsmd = rs.getMetaData();
- Entity entity = new QueryEntity();
- for( int j = 1 ; j <= rsmd.getColumnCount() ; j++) {
- entity.setProperty(rsmd.getColumnName(j), rs.getObject(j));
- }
- return entity;
- }
- });
- return entities;
- }
-
- @Override
- public List<Entity> execute(String query, int limit) {
- return execute(query);
- }
-
- // based on sqlite (http://www.sqlite.org/datatype3.html)
- private String getSqlDatatype(Class clz) {
- if( clz == Integer.class || clz == Long.class || clz == Boolean.class ) {
- return "INTEGER";
- } else if( clz == Double.class ) {
- return "REAL";
- } else if( clz == Byte.class ) {
- return "BLOB";
- }
- return "TEXT";
- }
-
- public void setCollection(String collection) {
- this.collection = collection;
- }
-
- public void setEntities(List<Entity> entities) {
- this.entities = entities;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/482c5cef/stack/query-validator/src/test/java/org/apache/usergrid/query/validator/CassandraRunner.java
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/test/java/org/apache/usergrid/query/validator/CassandraRunner.java b/stack/query-validator/src/test/java/org/apache/usergrid/query/validator/CassandraRunner.java
new file mode 100644
index 0000000..802f842
--- /dev/null
+++ b/stack/query-validator/src/test/java/org/apache/usergrid/query/validator/CassandraRunner.java
@@ -0,0 +1,199 @@
+/*
+ * Copyright 2014 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.usergrid.query.validator;
+
+import org.apache.commons.io.FileUtils;
+import org.junit.runner.notification.RunNotifier;
+import org.junit.runners.BlockJUnit4ClassRunner;
+import org.junit.runners.model.InitializationError;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import java.io.File;
+import java.lang.annotation.Annotation;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import org.apache.cassandra.service.CassandraDaemon;
+import org.apache.usergrid.cassandra.DataControl;
+import org.apache.usergrid.cassandra.SchemaManager;
+
+public class CassandraRunner extends BlockJUnit4ClassRunner {
+
+ private static final String TMP = "tmp";
+ private static Logger logger = LoggerFactory.getLogger(CassandraRunner.class);
+ private static ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
+ private static ContextHolder contextHolder;
+ private SchemaManager schemaManager;
+
+ // TODO maybe put a 'holder' object in the executor and provide access to application context thusly?
+ // TODO assume a static 'usergrid-test-context.xml' primer/starter file
+
+ public CassandraRunner(Class<?> klass) throws InitializationError {
+ super(klass);
+ logger.info("CassandraRunner started with class {}", klass.getName());
+ }
+
+
+ public static <T> T getBean(String name, Class<T> requiredType) {
+ return contextHolder.applicationContext.getBean(name, requiredType);
+ }
+
+ public static <T> T getBean(Class<T> requiredType) {
+ return contextHolder.applicationContext.getBean(requiredType);
+ }
+
+ /**
+ * Class-level run. The order of events are as follows:
+ * - load spring (if not loaded)
+ * - init cassandra (if not started)
+ * - look for DataControl annotation on class and delegate
+ * @param notifier
+ */
+ @Override
+ public void run(RunNotifier notifier) {
+ DataControl control = preTest(notifier);
+ super.run(notifier);
+ postTest(notifier, control);
+
+ }
+
+ protected DataControl preTest(RunNotifier notifier){
+ maybeInit();
+
+ // check for SchemaManager annotation
+ DataControl control = null;
+ for(Annotation ann : getTestClass().getAnnotations() ) {
+ logger.info("examining annotation " + ann);
+ if ( ann instanceof DataControl ) {
+ logger.info("founda dataCOntrol annotation");
+ control = (DataControl)ann;
+ }
+ }
+ loadDataControl(control);
+ maybeCreateSchema();
+
+ return control;
+ }
+
+ protected void postTest(RunNotifier notifier, DataControl control){
+ if ( control == null || !control.skipTruncate() ) {
+ schemaManager.destroy();
+ }
+ logger.info("shutting down context");
+ contextHolder.applicationContext.stop();
+
+ }
+
+
+ private void loadDataControl(DataControl dataControl) {
+ if ( !contextHolder.applicationContext.isActive() ) {
+ logger.info("restarting context...");
+ contextHolder.applicationContext.refresh();
+ }
+
+ if ( dataControl != null ) {
+ // TODO check for classpath and go static?
+ logger.info("dataControl found - looking upma SchemaManager impl");
+ schemaManager = getBean(dataControl.schemaManager(), SchemaManager.class);
+ } else {
+ logger.info("dataControl not found - using default SchemaManager impl");
+ schemaManager = getBean(SchemaManager.class);
+ }
+
+
+ }
+
+ private boolean maybeCreateSchema() {
+ if ( schemaManager.exists() ) {
+ logger.info("Schema existed");
+ return false;
+ }
+ schemaManager.create();
+ schemaManager.populateBaseData();
+
+ return true;
+ }
+
+
+
+ private static void maybeInit() {
+ if ( contextHolder != null ) {
+ return;
+ }
+ logger.info("Initing CassandraRunner...");
+
+ // TODO these should all be passed in as config options ... via spring?
+ // TODO make sure these match up with configs
+ // TODO one cassandra config in this project!
+ // TODO log4j.properties required to be present
+
+ System.setProperty("cassandra-foreground", "true");
+ System.setProperty("log4j.defaultInitOverride","true");
+ System.setProperty("log4j.configuration", "log4j.properties");
+ //System.setProperty("cassandra.load_ring_state", "false");so
+ //System.setProperty("cassandra.join_ring","false");
+ System.setProperty("cassandra.ring_delay_ms","100");
+
+ FileUtils.deleteQuietly(new File(TMP));
+
+ contextHolder = new ContextHolder();
+ try {
+ executor.schedule(contextHolder, 3, TimeUnit.SECONDS).get();
+ } catch (Exception ex) {
+ logger.error("Could not schedule cassandra runner",ex);
+ }
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+ @Override
+ public void run() {
+ try {
+ logger.error("In shutdownHook");
+ stopCassandra();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ });
+ }
+
+ private static void stopCassandra() throws Exception {
+ if (contextHolder != null && contextHolder.cassandraDaemon != null) {
+ contextHolder.cassandraDaemon.deactivate();
+ }
+ executor.shutdown();
+ executor.shutdownNow();
+ }
+
+ static class ContextHolder implements Runnable {
+ ConfigurableApplicationContext applicationContext;
+ CassandraDaemon cassandraDaemon;
+
+ @Override
+ public void run() {
+ cassandraDaemon = new CassandraDaemon();
+ cassandraDaemon.activate();
+ String[] locations = {"usergrid-test-context.xml"};
+ applicationContext = new ClassPathXmlApplicationContext(locations);
+
+
+
+ //acbf.autowire(getTestClass().getJavaClass(),AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, true);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/482c5cef/stack/query-validator/src/test/java/org/apache/usergrid/query/validator/QueryValidationTest.java
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/test/java/org/apache/usergrid/query/validator/QueryValidationTest.java b/stack/query-validator/src/test/java/org/apache/usergrid/query/validator/QueryValidationTest.java
new file mode 100644
index 0000000..5054e45
--- /dev/null
+++ b/stack/query-validator/src/test/java/org/apache/usergrid/query/validator/QueryValidationTest.java
@@ -0,0 +1,339 @@
+/*******************************************************************************
+ * 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.apache.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());
+ }
+}