Skip to content

Commit 6ffa705

Browse files
authored
[9.0] Fix a RemoveProcessor test that never ran (elastic#126464) (elastic#126481)
* Conserve precious characters * Whitespace * Make this test actually run
1 parent 48c2008 commit 6ffa705

File tree

1 file changed

+29
-69
lines changed

1 file changed

+29
-69
lines changed

modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/RemoveProcessorTests.java

Lines changed: 29 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
import org.elasticsearch.script.TemplateScript;
1717
import org.elasticsearch.test.ESTestCase;
1818

19-
import java.util.ArrayList;
19+
import java.util.Arrays;
2020
import java.util.HashMap;
2121
import java.util.List;
2222
import java.util.Map;
2323

24+
import static org.elasticsearch.ingest.common.RemoveProcessor.shouldKeep;
2425
import static org.hamcrest.Matchers.containsString;
2526
import static org.hamcrest.Matchers.equalTo;
2627

@@ -76,27 +77,23 @@ public void testKeepFields() throws Exception {
7677
source.put("age", 55);
7778
source.put("address", address);
7879

79-
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), source);
80+
IngestDocument document = RandomDocumentPicks.randomIngestDocument(random(), source);
8081

81-
List<TemplateScript.Factory> fieldsToKeep = List.of(
82-
new TestTemplateService.MockTemplateScript.Factory("name"),
83-
new TestTemplateService.MockTemplateScript.Factory("address.street")
84-
);
82+
Processor processor = new RemoveProcessor(null, null, List.of(), templates("name", "address.street"), false);
83+
processor.execute(document);
8584

86-
Processor processor = new RemoveProcessor(randomAlphaOfLength(10), null, new ArrayList<>(), fieldsToKeep, false);
87-
processor.execute(ingestDocument);
88-
assertTrue(ingestDocument.hasField("name"));
89-
assertTrue(ingestDocument.hasField("address"));
90-
assertTrue(ingestDocument.hasField("address.street"));
91-
assertFalse(ingestDocument.hasField("age"));
92-
assertFalse(ingestDocument.hasField("address.number"));
93-
assertTrue(ingestDocument.hasField("_index"));
94-
assertTrue(ingestDocument.hasField("_version"));
95-
assertTrue(ingestDocument.hasField("_id"));
96-
assertTrue(ingestDocument.hasField("_version_type"));
85+
assertTrue(document.hasField("name"));
86+
assertTrue(document.hasField("address"));
87+
assertTrue(document.hasField("address.street"));
88+
assertFalse(document.hasField("age"));
89+
assertFalse(document.hasField("address.number"));
90+
assertTrue(document.hasField("_index"));
91+
assertTrue(document.hasField("_version"));
92+
assertTrue(document.hasField("_id"));
93+
assertTrue(document.hasField("_version_type"));
9794
}
9895

99-
public void testShouldKeep(String a, String b) {
96+
public void testShouldKeep() {
10097
Map<String, Object> address = new HashMap<>();
10198
address.put("street", "Ipiranga Street");
10299
address.put("number", 123);
@@ -105,57 +102,20 @@ public void testShouldKeep(String a, String b) {
105102
source.put("name", "eric clapton");
106103
source.put("address", address);
107104

108-
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), source);
109-
110-
assertTrue(RemoveProcessor.shouldKeep("name", List.of(new TestTemplateService.MockTemplateScript.Factory("name")), ingestDocument));
111-
112-
assertTrue(RemoveProcessor.shouldKeep("age", List.of(new TestTemplateService.MockTemplateScript.Factory("age")), ingestDocument));
113-
114-
assertFalse(RemoveProcessor.shouldKeep("name", List.of(new TestTemplateService.MockTemplateScript.Factory("age")), ingestDocument));
115-
116-
assertTrue(
117-
RemoveProcessor.shouldKeep(
118-
"address",
119-
List.of(new TestTemplateService.MockTemplateScript.Factory("address.street")),
120-
ingestDocument
121-
)
122-
);
123-
124-
assertTrue(
125-
RemoveProcessor.shouldKeep(
126-
"address",
127-
List.of(new TestTemplateService.MockTemplateScript.Factory("address.number")),
128-
ingestDocument
129-
)
130-
);
131-
132-
assertTrue(
133-
RemoveProcessor.shouldKeep(
134-
"address.street",
135-
List.of(new TestTemplateService.MockTemplateScript.Factory("address")),
136-
ingestDocument
137-
)
138-
);
139-
140-
assertTrue(
141-
RemoveProcessor.shouldKeep(
142-
"address.number",
143-
List.of(new TestTemplateService.MockTemplateScript.Factory("address")),
144-
ingestDocument
145-
)
146-
);
147-
148-
assertTrue(
149-
RemoveProcessor.shouldKeep("address", List.of(new TestTemplateService.MockTemplateScript.Factory("address")), ingestDocument)
150-
);
151-
152-
assertFalse(
153-
RemoveProcessor.shouldKeep(
154-
"address.street",
155-
List.of(new TestTemplateService.MockTemplateScript.Factory("address.number")),
156-
ingestDocument
157-
)
158-
);
105+
IngestDocument document = RandomDocumentPicks.randomIngestDocument(random(), source);
106+
107+
assertTrue(shouldKeep("name", templates("name"), document));
108+
assertTrue(shouldKeep("age", templates("age"), document));
109+
assertFalse(shouldKeep("name", templates("age"), document));
110+
assertTrue(shouldKeep("address", templates("address.street"), document));
111+
assertTrue(shouldKeep("address", templates("address.number"), document));
112+
assertTrue(shouldKeep("address.street", templates("address"), document));
113+
assertTrue(shouldKeep("address.number", templates("address"), document));
114+
assertTrue(shouldKeep("address", templates("address"), document));
115+
assertFalse(shouldKeep("address.street", templates("address.number"), document));
159116
}
160117

118+
private static List<TemplateScript.Factory> templates(String... fields) {
119+
return Arrays.stream(fields).map(f -> (TemplateScript.Factory) new TestTemplateService.MockTemplateScript.Factory(f)).toList();
120+
}
161121
}

0 commit comments

Comments
 (0)