[TEST] adapt FilteredQueryBuilderTests to upstream changes

This commit is contained in:
javanna 2015-09-03 21:18:24 +02:00 committed by Luca Cavanna
parent 8bd7cdbdad
commit ea83007c7e
1 changed files with 6 additions and 11 deletions

View File

@ -21,9 +21,7 @@ package org.elasticsearch.index.query;
import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.ConstantScoreQuery;
import org.apache.lucene.search.Query; import org.apache.lucene.search.Query;
import org.elasticsearch.common.lucene.search.Queries;
import org.junit.Test; import org.junit.Test;
import java.io.IOException; import java.io.IOException;
@ -48,17 +46,14 @@ public class FilteredQueryBuilderTests extends BaseQueryTestCase<FilteredQueryBu
if (innerQuery == null) { if (innerQuery == null) {
assertThat(query, nullValue()); assertThat(query, nullValue());
} else { } else {
assertThat(query, instanceOf(BooleanQuery.class));
BooleanQuery booleanQuery = (BooleanQuery) query;
Query innerFilter = queryBuilder.innerFilter().toQuery(context); Query innerFilter = queryBuilder.innerFilter().toQuery(context);
if (innerFilter == null || Queries.isConstantMatchAllQuery(innerFilter)) { if (innerFilter == null) {
innerQuery.setBoost(queryBuilder.boost()); assertThat(booleanQuery.clauses().size(), equalTo(1));
assertThat(query, equalTo(innerQuery)); assertThat(booleanQuery.clauses().get(0).getOccur(), equalTo(BooleanClause.Occur.MUST));
} else if (Queries.isConstantMatchAllQuery(innerQuery)) { assertThat(booleanQuery.clauses().get(0).getQuery(), equalTo(innerQuery));
assertThat(query, instanceOf(ConstantScoreQuery.class));
assertThat(((ConstantScoreQuery)query).getQuery(), equalTo(innerFilter));
} else { } else {
assertThat(query, instanceOf(BooleanQuery.class));
BooleanQuery booleanQuery = (BooleanQuery) query;
assertThat(booleanQuery.clauses().size(), equalTo(2));
assertThat(booleanQuery.clauses().get(0).getOccur(), equalTo(BooleanClause.Occur.MUST)); assertThat(booleanQuery.clauses().get(0).getOccur(), equalTo(BooleanClause.Occur.MUST));
assertThat(booleanQuery.clauses().get(0).getQuery(), equalTo(innerQuery)); assertThat(booleanQuery.clauses().get(0).getQuery(), equalTo(innerQuery));
assertThat(booleanQuery.clauses().get(1).getOccur(), equalTo(BooleanClause.Occur.FILTER)); assertThat(booleanQuery.clauses().get(1).getOccur(), equalTo(BooleanClause.Occur.FILTER));