Skip to content

Commit 46540d5

Browse files
committed
Add object mapping to base test setup to extend test coverage
1 parent 2d64dd1 commit 46540d5

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/test/java/org/elasticsearch/index/query/BaseQueryTestCase.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,14 @@
7777
@Ignore
7878
public abstract class BaseQueryTestCase<QB extends QueryBuilder<QB>> extends ElasticsearchTestCase {
7979

80+
protected static final String OBJECT_FIELD_NAME = "object";
8081
protected static final String DATE_FIELD_NAME = "age";
8182
protected static final String INT_FIELD_NAME = "price";
8283
protected static final String STRING_FIELD_NAME = "text";
8384
protected static final String DOUBLE_FIELD_NAME = "double";
8485
protected static final String BOOLEAN_FIELD_NAME = "boolean";
8586
protected static final String[] mappedFieldNames = new String[]{DATE_FIELD_NAME, INT_FIELD_NAME,
86-
STRING_FIELD_NAME, DOUBLE_FIELD_NAME, BOOLEAN_FIELD_NAME};
87+
STRING_FIELD_NAME, DOUBLE_FIELD_NAME, BOOLEAN_FIELD_NAME, OBJECT_FIELD_NAME};
8788

8889
private static Injector injector;
8990
private static IndexQueryParserService queryParserService;
@@ -140,7 +141,10 @@ protected void configure() {
140141
INT_FIELD_NAME, "type=integer",
141142
DOUBLE_FIELD_NAME, "type=double",
142143
BOOLEAN_FIELD_NAME, "type=boolean",
143-
STRING_FIELD_NAME, "type=string").string()), false);
144+
STRING_FIELD_NAME, "type=string",
145+
OBJECT_FIELD_NAME, "type=object",
146+
OBJECT_FIELD_NAME+"."+DATE_FIELD_NAME, "type=date",
147+
OBJECT_FIELD_NAME+"."+INT_FIELD_NAME, "type=integer").string()), false);
144148
currentTypes[i] = type;
145149
}
146150

src/test/java/org/elasticsearch/index/query/ExistsQueryBuilderTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ protected ExistsQueryBuilder createEmptyQueryBuilder() {
4444
@Override
4545
protected Query createExpectedQuery(ExistsQueryBuilder queryBuilder, QueryParseContext context) throws IOException {
4646
final FieldNamesFieldMapper fieldNamesMapper = (FieldNamesFieldMapper)context.mapperService().fullName(FieldNamesFieldMapper.NAME);
47-
Collection<String> fields = context.simpleMatchToIndexNames(queryBuilder.name());
47+
String fieldNameInTest = queryBuilder.name();
48+
if (getCurrentTypes().length > 0 && fieldNameInTest.equals(BaseQueryTestCase.OBJECT_FIELD_NAME)) {
49+
// objects have two inner fields, add wildcard to match behaviour of extending field name pattern in test
50+
fieldNameInTest = fieldNameInTest +".*";
51+
}
52+
Collection<String> fields = context.simpleMatchToIndexNames(fieldNameInTest);
4853

4954
if (fields.isEmpty()) {
5055
return Queries.newMatchNoDocsQuery();

0 commit comments

Comments
 (0)