Shorten nested test query builder generation.

This commit is contained in:
Isabel Drost-Fromm 2016-04-28 15:31:56 +02:00
parent 3490daa7ea
commit a03b131319
4 changed files with 19 additions and 26 deletions

View File

@ -67,7 +67,7 @@ public class FieldSortBuilderTests extends AbstractSortTestCase<FieldSortBuilder
}
if (randomBoolean()) {
builder.setNestedFilter(RandomSortDataGenerator.nestedFilter(builder.getNestedFilter()));
builder.setNestedFilter(NestedQueryBuilderGenerator.nestedFilter(builder.getNestedFilter()));
}
if (randomBoolean()) {
@ -90,7 +90,7 @@ public class FieldSortBuilderTests extends AbstractSortTestCase<FieldSortBuilder
() -> ESTestCase.randomAsciiOfLengthBetween(1, 10)));
break;
case 1:
mutated.setNestedFilter(RandomSortDataGenerator.nestedFilter(mutated.getNestedFilter()));
mutated.setNestedFilter(NestedQueryBuilderGenerator.nestedFilter(mutated.getNestedFilter()));
break;
case 2:
mutated.sortMode(ESTestCase.randomValueOtherThan(mutated.sortMode(), () -> randomFrom(SortMode.values())));

View File

@ -89,7 +89,7 @@ public class GeoDistanceSortBuilderTests extends AbstractSortTestCase<GeoDistanc
result.sortMode(mode(result.sortMode()));
}
if (randomBoolean()) {
result.setNestedFilter(RandomSortDataGenerator.nestedFilter(result.getNestedFilter()));
result.setNestedFilter(NestedQueryBuilderGenerator.nestedFilter(result.getNestedFilter()));
}
if (randomBoolean()) {
result.setNestedPath(
@ -177,7 +177,7 @@ public class GeoDistanceSortBuilderTests extends AbstractSortTestCase<GeoDistanc
result.sortMode(mode(original.sortMode()));
break;
case 6:
result.setNestedFilter(RandomSortDataGenerator.nestedFilter(original.getNestedFilter()));
result.setNestedFilter(NestedQueryBuilderGenerator.nestedFilter(original.getNestedFilter()));
break;
case 7:
result.setNestedPath(ESTestCase.randomValueOtherThan(

View File

@ -25,30 +25,23 @@ import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.TermQueryBuilder;
import org.elasticsearch.test.ESTestCase;
public class RandomSortDataGenerator {
private RandomSortDataGenerator() {
import java.util.Arrays;
import java.util.List;
public class NestedQueryBuilderGenerator {
private NestedQueryBuilderGenerator() {
// this is a helper class only, doesn't need a constructor
}
public static QueryBuilder nestedFilter(QueryBuilder original) {
private static List<QueryBuilder<?>> builders = Arrays.asList(
new MatchAllQueryBuilder(),
new IdsQueryBuilder(),
new TermQueryBuilder(ESTestCase.randomAsciiOfLengthBetween(1, 10), ESTestCase.randomDouble()));
public static QueryBuilder<?> nestedFilter(QueryBuilder<?> original) {
@SuppressWarnings("rawtypes")
QueryBuilder nested = null;
while (nested == null || nested.equals(original)) {
switch (ESTestCase.randomInt(2)) {
case 0:
nested = new MatchAllQueryBuilder();
break;
case 1:
nested = new IdsQueryBuilder();
break;
default:
case 2:
nested = new TermQueryBuilder(ESTestCase.randomAsciiOfLengthBetween(1, 10), ESTestCase.randomDouble());
break;
}
nested.boost((float) ESTestCase.randomDoubleBetween(0, 10, false));
}
QueryBuilder nested = ESTestCase.randomValueOtherThan(original, () -> ESTestCase.randomFrom(builders));
nested.boost((float) ESTestCase.randomDoubleBetween(0, 10, false));
return nested;
}
}

View File

@ -63,7 +63,7 @@ public class ScriptSortBuilderTests extends AbstractSortTestCase<ScriptSortBuild
}
}
if (randomBoolean()) {
builder.setNestedFilter(RandomSortDataGenerator.nestedFilter(builder.getNestedFilter()));
builder.setNestedFilter(NestedQueryBuilderGenerator.nestedFilter(builder.getNestedFilter()));
}
if (randomBoolean()) {
builder.setNestedPath(ESTestCase.randomValueOtherThan(
@ -115,7 +115,7 @@ public class ScriptSortBuilderTests extends AbstractSortTestCase<ScriptSortBuild
}
break;
case 2:
result.setNestedFilter(RandomSortDataGenerator.nestedFilter(original.getNestedFilter()));
result.setNestedFilter(NestedQueryBuilderGenerator.nestedFilter(original.getNestedFilter()));
break;
case 3:
result.setNestedPath(original.getNestedPath() + "_some_suffix");