Skip to content

Commit eb516d7

Browse files
authored
Remove Expression specific alias tests (elastic#64065)
There is no longer a reason to have specific unit tests for looking up field aliases in Expression, especially as the field type lookup function is mocked. Such tests can be removed. Also, there was a leftover usage of a mocked MapperService to feed a LeafDocLookup which is also removed.
1 parent 60e5199 commit eb516d7

File tree

4 files changed

+6
-38
lines changed

4 files changed

+6
-38
lines changed

modules/lang-expression/src/test/java/org/elasticsearch/script/expression/ExpressionFieldScriptTests.java

+1-10
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ public void setUp() throws Exception {
6060
when(fieldData.load(anyObject())).thenReturn(atomicFieldData);
6161

6262
service = new ExpressionScriptEngine();
63-
lookup = new SearchLookup(field -> field.equals("field") || field.equals("alias") ? fieldType : null,
64-
(ignored, lookup) -> fieldData, null);
63+
lookup = new SearchLookup(field -> field.equals("field") ? fieldType : null, (ignored, lookup) -> fieldData, null);
6564
}
6665

6766
private FieldScript.LeafFactory compile(String expression) {
@@ -90,12 +89,4 @@ public void testFieldAccess() throws IOException {
9089
Object result = script.execute();
9190
assertThat(result, equalTo(2.718));
9291
}
93-
94-
public void testFieldAccessWithFieldAlias() throws IOException {
95-
FieldScript script = compile("doc['alias'].value").newInstance(null);
96-
script.setDocument(1);
97-
98-
Object result = script.execute();
99-
assertThat(result, equalTo(2.718));
100-
}
10192
}

modules/lang-expression/src/test/java/org/elasticsearch/script/expression/ExpressionNumberSortScriptTests.java

+1-10
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ public void setUp() throws Exception {
5959
when(fieldData.load(anyObject())).thenReturn(atomicFieldData);
6060

6161
service = new ExpressionScriptEngine();
62-
lookup = new SearchLookup(field -> field.equals("field") || field.equals("alias") ? fieldType : null,
63-
(ignored, lookup) -> fieldData, null);
62+
lookup = new SearchLookup(field -> field.equals("field") ? fieldType : null, (ignored, lookup) -> fieldData, null);
6463
}
6564

6665
private NumberSortScript.LeafFactory compile(String expression) {
@@ -90,12 +89,4 @@ public void testFieldAccess() throws IOException {
9089
double result = script.execute();
9190
assertEquals(2.718, result, 0.0);
9291
}
93-
94-
public void testFieldAccessWithFieldAlias() throws IOException {
95-
NumberSortScript script = compile("doc['alias'].value").newInstance(null);
96-
script.setDocument(1);
97-
98-
double result = script.execute();
99-
assertEquals(2.718, result, 0.0);
100-
}
10192
}

modules/lang-expression/src/test/java/org/elasticsearch/script/expression/ExpressionTermsSetQueryTests.java

+1-10
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ public void setUp() throws Exception {
5959
when(fieldData.load(anyObject())).thenReturn(atomicFieldData);
6060

6161
service = new ExpressionScriptEngine();
62-
lookup = new SearchLookup(field -> field.equals("field") || field.equals("alias") ? fieldType : null,
63-
(ignored, lookup) -> fieldData, null);
62+
lookup = new SearchLookup(field -> field.equals("field") ? fieldType : null, (ignored, lookup) -> fieldData, null);
6463
}
6564

6665
private TermsSetQueryScript.LeafFactory compile(String expression) {
@@ -90,12 +89,4 @@ public void testFieldAccess() throws IOException {
9089
double result = script.execute().doubleValue();
9190
assertEquals(2.718, result, 0.0);
9291
}
93-
94-
public void testFieldAccessWithFieldAlias() throws IOException {
95-
TermsSetQueryScript script = compile("doc['alias'].value").newInstance(null);
96-
script.setDocument(1);
97-
98-
double result = script.execute().doubleValue();
99-
assertEquals(2.718, result, 0.0);
100-
}
10192
}

server/src/test/java/org/elasticsearch/search/lookup/LeafDocLookupTests.java

+3-8
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.elasticsearch.index.fielddata.LeafFieldData;
2323
import org.elasticsearch.index.fielddata.ScriptDocValues;
2424
import org.elasticsearch.index.mapper.MappedFieldType;
25-
import org.elasticsearch.index.mapper.MapperService;
2625
import org.elasticsearch.test.ESTestCase;
2726
import org.junit.Before;
2827

@@ -45,17 +44,13 @@ public void setUp() throws Exception {
4544
when(fieldType.name()).thenReturn("field");
4645
when(fieldType.valueForDisplay(anyObject())).then(returnsFirstArg());
4746

48-
MapperService mapperService = mock(MapperService.class);
49-
when(mapperService.fieldType("_type")).thenReturn(fieldType);
50-
when(mapperService.fieldType("field")).thenReturn(fieldType);
51-
when(mapperService.fieldType("alias")).thenReturn(fieldType);
52-
5347
docValues = mock(ScriptDocValues.class);
5448
IndexFieldData<?> fieldData = createFieldData(docValues);
5549

56-
docLookup = new LeafDocLookup(mapperService::fieldType,
50+
docLookup = new LeafDocLookup(
51+
field -> field.equals("field") || field.equals("alias") || field.equals("_type") ? fieldType : null,
5752
ignored -> fieldData,
58-
new String[] { "type" },
53+
new String[]{"type"},
5954
null);
6055
}
6156

0 commit comments

Comments
 (0)