From 2e687384290cf09207e9f12275b5775d684d5ddf Mon Sep 17 00:00:00 2001 From: javanna Date: Thu, 10 Sep 2015 16:04:55 +0200 Subject: [PATCH] adapt to upstream changes --- .../index/query/AndQueryBuilderTests.java | 124 ------------------ .../index/query/FQueryFilterBuilderTests.java | 91 ------------- .../query/FilteredQueryBuilderTests.java | 108 --------------- .../index/query/LimitQueryBuilderTests.java | 43 ------ .../index/query/OrQueryBuilderTests.java | 120 ----------------- 5 files changed, 486 deletions(-) delete mode 100644 core/src/test/java/org/elasticsearch/index/query/AndQueryBuilderTests.java delete mode 100644 core/src/test/java/org/elasticsearch/index/query/FQueryFilterBuilderTests.java delete mode 100644 core/src/test/java/org/elasticsearch/index/query/FilteredQueryBuilderTests.java delete mode 100644 core/src/test/java/org/elasticsearch/index/query/LimitQueryBuilderTests.java delete mode 100644 core/src/test/java/org/elasticsearch/index/query/OrQueryBuilderTests.java diff --git a/core/src/test/java/org/elasticsearch/index/query/AndQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/AndQueryBuilderTests.java deleted file mode 100644 index ae55678cd66..00000000000 --- a/core/src/test/java/org/elasticsearch/index/query/AndQueryBuilderTests.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch 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.elasticsearch.index.query; - -import org.apache.lucene.search.BooleanClause; -import org.apache.lucene.search.BooleanQuery; -import org.apache.lucene.search.Query; -import org.junit.Test; - -import java.io.IOException; -import java.util.*; - -import static org.hamcrest.CoreMatchers.*; - -@SuppressWarnings("deprecation") -public class AndQueryBuilderTests extends AbstractQueryTestCase { - - /** - * @return a AndQueryBuilder with random limit between 0 and 20 - */ - @Override - protected AndQueryBuilder doCreateTestQueryBuilder() { - AndQueryBuilder query = new AndQueryBuilder(); - int subQueries = randomIntBetween(1, 5); - for (int i = 0; i < subQueries; i++ ) { - query.add(RandomQueryBuilder.createQuery(random())); - } - return query; - } - - @Override - protected void doAssertLuceneQuery(AndQueryBuilder queryBuilder, Query query, QueryShardContext context) throws IOException { - if (queryBuilder.innerQueries().isEmpty()) { - assertThat(query, nullValue()); - } else { - List clauses = new ArrayList<>(); - for (QueryBuilder innerFilter : queryBuilder.innerQueries()) { - Query clause = innerFilter.toQuery(context); - if (clause != null) { - clauses.add(clause); - } - } - if (clauses.isEmpty()) { - assertThat(query, nullValue()); - } else { - assertThat(query, instanceOf(BooleanQuery.class)); - BooleanQuery booleanQuery = (BooleanQuery) query; - assertThat(booleanQuery.clauses().size(), equalTo(clauses.size())); - Iterator queryIterator = clauses.iterator(); - for (BooleanClause booleanClause : booleanQuery) { - assertThat(booleanClause.getOccur(), equalTo(BooleanClause.Occur.MUST)); - assertThat(booleanClause.getQuery(), equalTo(queryIterator.next())); - } - } - } - } - - /** - * test corner case where no inner queries exist - */ - @Test - public void testNoInnerQueries() throws QueryShardException, IOException { - AndQueryBuilder andQuery = new AndQueryBuilder(); - assertNull(andQuery.toQuery(createShardContext())); - } - - @Test(expected=QueryParsingException.class) - public void testMissingFiltersSection() throws IOException { - parseQuery("{ \"and\" : {}"); - } - - @Test - public void testValidate() { - AndQueryBuilder andQuery = new AndQueryBuilder(); - int iters = randomIntBetween(0, 5); - int totalExpectedErrors = 0; - for (int i = 0; i < iters; i++) { - if (randomBoolean()) { - if (randomBoolean()) { - andQuery.add(RandomQueryBuilder.createInvalidQuery(random())); - } else { - andQuery.add(null); - } - totalExpectedErrors++; - } else { - andQuery.add(RandomQueryBuilder.createQuery(random())); - } - } - assertValidate(andQuery, totalExpectedErrors); - } - - @Override - protected Map getAlternateVersions() { - Map alternateVersions = new HashMap<>(); - QueryBuilder innerQuery = createTestQueryBuilder().innerQueries().get(0); - AndQueryBuilder expectedQuery = new AndQueryBuilder(innerQuery); - String contentString = "{ \"and\" : [ " + innerQuery + "] }"; - alternateVersions.put(contentString, expectedQuery); - return alternateVersions; - } - - @Test(expected=QueryParsingException.class) - public void testParsingExceptionNonFiltersElementArray() throws IOException { - String queryString = "{ \"and\" : { \"whatever_filters\" : [ { \"match_all\" : {} } ] } }"; - parseQuery(queryString); - } -} diff --git a/core/src/test/java/org/elasticsearch/index/query/FQueryFilterBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/FQueryFilterBuilderTests.java deleted file mode 100644 index 19e0db5127b..00000000000 --- a/core/src/test/java/org/elasticsearch/index/query/FQueryFilterBuilderTests.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch 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.elasticsearch.index.query; - -import org.apache.lucene.search.ConstantScoreQuery; -import org.apache.lucene.search.Query; -import org.junit.Test; - -import java.io.IOException; - -import static org.hamcrest.CoreMatchers.*; - -@SuppressWarnings("deprecation") -public class FQueryFilterBuilderTests extends AbstractQueryTestCase { - - /** - * @return a FQueryFilterBuilder with random inner query - */ - @Override - protected FQueryFilterBuilder doCreateTestQueryBuilder() { - QueryBuilder innerQuery = RandomQueryBuilder.createQuery(random()); - return new FQueryFilterBuilder(innerQuery); - } - - @Override - protected void doAssertLuceneQuery(FQueryFilterBuilder queryBuilder, Query query, QueryShardContext context) throws IOException { - Query innerQuery = queryBuilder.innerQuery().toQuery(context); - if (innerQuery == null) { - assertThat(query, nullValue()); - } else { - assertThat(query, instanceOf(ConstantScoreQuery.class)); - ConstantScoreQuery constantScoreQuery = (ConstantScoreQuery) query; - assertThat(constantScoreQuery.getQuery(), equalTo(innerQuery)); - } - } - - /** - * test corner case where no inner query exist - */ - @Test - public void testNoInnerQuery() throws QueryParsingException, IOException { - FQueryFilterBuilder queryFilterQuery = new FQueryFilterBuilder(EmptyQueryBuilder.PROTOTYPE); - assertNull(queryFilterQuery.toQuery(createShardContext())); - } - - /** - * test wrapping an inner filter that returns null also returns null to pass on upwards - */ - @Test - public void testInnerQueryReturnsNull() throws IOException { - // create inner filter - String queryString = "{ \"constant_score\" : { \"filter\" : {} } }"; - QueryBuilder innerQuery = parseQuery(queryString); - // check that when wrapping this filter, toQuery() returns null - FQueryFilterBuilder queryFilterQuery = new FQueryFilterBuilder(innerQuery); - assertNull(queryFilterQuery.toQuery(createShardContext())); - } - - @Test - public void testValidate() { - QueryBuilder innerQuery = null; - int totalExpectedErrors = 0; - if (randomBoolean()) { - if (randomBoolean()) { - innerQuery = RandomQueryBuilder.createInvalidQuery(random()); - } - totalExpectedErrors++; - } else { - innerQuery = RandomQueryBuilder.createQuery(random()); - } - FQueryFilterBuilder fQueryFilter = new FQueryFilterBuilder(innerQuery); - assertValidate(fQueryFilter, totalExpectedErrors); - } -} diff --git a/core/src/test/java/org/elasticsearch/index/query/FilteredQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/FilteredQueryBuilderTests.java deleted file mode 100644 index 5a6a528b2df..00000000000 --- a/core/src/test/java/org/elasticsearch/index/query/FilteredQueryBuilderTests.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch 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.elasticsearch.index.query; - -import org.apache.lucene.search.BooleanClause; -import org.apache.lucene.search.BooleanQuery; -import org.apache.lucene.search.Query; -import org.junit.Test; - -import java.io.IOException; - -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.nullValue; - -@SuppressWarnings("deprecation") -public class FilteredQueryBuilderTests extends AbstractQueryTestCase { - - @Override - protected FilteredQueryBuilder doCreateTestQueryBuilder() { - QueryBuilder queryBuilder = RandomQueryBuilder.createQuery(random()); - QueryBuilder filterBuilder = RandomQueryBuilder.createQuery(random()); - return new FilteredQueryBuilder(queryBuilder, filterBuilder); - } - - @Override - protected void doAssertLuceneQuery(FilteredQueryBuilder queryBuilder, Query query, QueryShardContext context) throws IOException { - Query innerQuery = queryBuilder.innerQuery().toQuery(context); - if (innerQuery == null) { - assertThat(query, nullValue()); - } else { - assertThat(query, instanceOf(BooleanQuery.class)); - BooleanQuery booleanQuery = (BooleanQuery) query; - Query innerFilter = queryBuilder.innerFilter().toQuery(context); - if (innerFilter == null) { - assertThat(booleanQuery.clauses().size(), equalTo(1)); - assertThat(booleanQuery.clauses().get(0).getOccur(), equalTo(BooleanClause.Occur.MUST)); - assertThat(booleanQuery.clauses().get(0).getQuery(), equalTo(innerQuery)); - } else { - assertThat(booleanQuery.clauses().get(0).getOccur(), equalTo(BooleanClause.Occur.MUST)); - assertThat(booleanQuery.clauses().get(0).getQuery(), equalTo(innerQuery)); - assertThat(booleanQuery.clauses().get(1).getOccur(), equalTo(BooleanClause.Occur.FILTER)); - assertThat(booleanQuery.clauses().get(1).getQuery(), equalTo(innerFilter)); - } - } - } - - @Test - public void testValidation() { - QueryBuilder valid = RandomQueryBuilder.createQuery(random()); - QueryBuilder invalid = RandomQueryBuilder.createInvalidQuery(random()); - - // invalid cases - FilteredQueryBuilder qb = new FilteredQueryBuilder(invalid); - QueryValidationException result = qb.validate(); - assertNotNull(result); - assertEquals(1, result.validationErrors().size()); - - qb = new FilteredQueryBuilder(valid, invalid); - result = qb.validate(); - assertNotNull(result); - assertEquals(1, result.validationErrors().size()); - - qb = new FilteredQueryBuilder(invalid, valid); - result = qb.validate(); - assertNotNull(result); - assertEquals(1, result.validationErrors().size()); - - qb = new FilteredQueryBuilder(invalid, invalid); - result = qb.validate(); - assertNotNull(result); - assertEquals(2, result.validationErrors().size()); - - // valid cases - qb = new FilteredQueryBuilder(valid); - assertNull(qb.validate()); - - qb = new FilteredQueryBuilder(null); - assertNull(qb.validate()); - - qb = new FilteredQueryBuilder(null, valid); - assertNull(qb.validate()); - - qb = new FilteredQueryBuilder(valid, null); - assertNull(qb.validate()); - - qb = new FilteredQueryBuilder(valid, valid); - assertNull(qb.validate()); - } - -} diff --git a/core/src/test/java/org/elasticsearch/index/query/LimitQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/LimitQueryBuilderTests.java deleted file mode 100644 index 8567505aded..00000000000 --- a/core/src/test/java/org/elasticsearch/index/query/LimitQueryBuilderTests.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch 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.elasticsearch.index.query; - -import org.apache.lucene.search.MatchAllDocsQuery; -import org.apache.lucene.search.Query; - -import java.io.IOException; - -import static org.hamcrest.CoreMatchers.instanceOf; - -public class LimitQueryBuilderTests extends AbstractQueryTestCase { - - /** - * @return a LimitQueryBuilder with random limit between 0 and 20 - */ - @Override - protected LimitQueryBuilder doCreateTestQueryBuilder() { - return new LimitQueryBuilder(randomIntBetween(0, 20)); - } - - @Override - protected void doAssertLuceneQuery(LimitQueryBuilder queryBuilder, Query query, QueryShardContext context) throws IOException { - assertThat(query, instanceOf(MatchAllDocsQuery.class)); - } -} diff --git a/core/src/test/java/org/elasticsearch/index/query/OrQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/OrQueryBuilderTests.java deleted file mode 100644 index 1c4c38e2c64..00000000000 --- a/core/src/test/java/org/elasticsearch/index/query/OrQueryBuilderTests.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch 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.elasticsearch.index.query; - -import org.apache.lucene.search.BooleanClause; -import org.apache.lucene.search.BooleanQuery; -import org.apache.lucene.search.Query; -import org.junit.Test; - -import java.io.IOException; -import java.util.*; - -import static org.hamcrest.CoreMatchers.*; - -@SuppressWarnings("deprecation") -public class OrQueryBuilderTests extends AbstractQueryTestCase { - - /** - * @return an OrQueryBuilder with random limit between 0 and 20 - */ - @Override - protected OrQueryBuilder doCreateTestQueryBuilder() { - OrQueryBuilder query = new OrQueryBuilder(); - int subQueries = randomIntBetween(1, 5); - for (int i = 0; i < subQueries; i++ ) { - query.add(RandomQueryBuilder.createQuery(random())); - } - return query; - } - - @Override - protected void doAssertLuceneQuery(OrQueryBuilder queryBuilder, Query query, QueryShardContext context) throws IOException { - if (queryBuilder.innerQueries().isEmpty()) { - assertThat(query, nullValue()); - } else { - List innerQueries = new ArrayList<>(); - for (QueryBuilder subQuery : queryBuilder.innerQueries()) { - Query innerQuery = subQuery.toQuery(context); - // ignore queries that are null - if (innerQuery != null) { - innerQueries.add(innerQuery); - } - } - if (innerQueries.isEmpty()) { - assertThat(query, nullValue()); - } else { - assertThat(query, instanceOf(BooleanQuery.class)); - BooleanQuery booleanQuery = (BooleanQuery) query; - assertThat(booleanQuery.clauses().size(), equalTo(innerQueries.size())); - Iterator queryIterator = innerQueries.iterator(); - for (BooleanClause booleanClause : booleanQuery) { - assertThat(booleanClause.getOccur(), equalTo(BooleanClause.Occur.SHOULD)); - assertThat(booleanClause.getQuery(), equalTo(queryIterator.next())); - } - } - } - } - - /** - * test corner case where no inner queries exist - */ - @Test - public void testNoInnerQueries() throws QueryShardException, IOException { - OrQueryBuilder orQuery = new OrQueryBuilder(); - assertNull(orQuery.toQuery(createShardContext())); - } - - @Override - protected Map getAlternateVersions() { - Map alternateVersions = new HashMap<>(); - QueryBuilder innerQuery = createTestQueryBuilder().innerQueries().get(0); - OrQueryBuilder expectedQuery = new OrQueryBuilder(innerQuery); - String contentString = "{ \"or\" : [ " + innerQuery + "] }"; - alternateVersions.put(contentString, expectedQuery); - return alternateVersions; - } - - @Test(expected=QueryParsingException.class) - public void testMissingFiltersSection() throws IOException { - String queryString = "{ \"or\" : {}"; - parseQuery(queryString); - } - - @Test - public void testValidate() { - OrQueryBuilder orQuery = new OrQueryBuilder(); - int iters = randomIntBetween(0, 5); - int totalExpectedErrors = 0; - for (int i = 0; i < iters; i++) { - if (randomBoolean()) { - if (randomBoolean()) { - orQuery.add(RandomQueryBuilder.createInvalidQuery(random())); - } else { - orQuery.add(null); - } - totalExpectedErrors++; - } else { - orQuery.add(RandomQueryBuilder.createQuery(random())); - } - } - assertValidate(orQuery, totalExpectedErrors); - } -}