22
22
import org .elasticsearch .ElasticsearchParseException ;
23
23
import org .elasticsearch .ingest .Processor ;
24
24
import org .elasticsearch .ingest .TestProcessor ;
25
+ import org .elasticsearch .script .ScriptService ;
25
26
import org .elasticsearch .test .ESTestCase ;
26
27
import org .hamcrest .Matchers ;
27
28
30
31
import java .util .Map ;
31
32
32
33
import static org .hamcrest .Matchers .equalTo ;
34
+ import static org .mockito .Mockito .mock ;
33
35
34
36
public class ForEachProcessorFactoryTests extends ESTestCase {
35
37
38
+ private final ScriptService scriptService = mock (ScriptService .class );
39
+
36
40
public void testCreate () throws Exception {
37
41
Processor processor = new TestProcessor (ingestDocument -> { });
38
42
Map <String , Processor .Factory > registry = new HashMap <>();
39
43
registry .put ("_name" , (r , t , c ) -> processor );
40
- ForEachProcessor .Factory forEachFactory = new ForEachProcessor .Factory ();
44
+ ForEachProcessor .Factory forEachFactory = new ForEachProcessor .Factory (scriptService );
41
45
42
46
Map <String , Object > config = new HashMap <>();
43
47
config .put ("field" , "_field" );
@@ -53,7 +57,7 @@ public void testSetIgnoreMissing() throws Exception {
53
57
Processor processor = new TestProcessor (ingestDocument -> { });
54
58
Map <String , Processor .Factory > registry = new HashMap <>();
55
59
registry .put ("_name" , (r , t , c ) -> processor );
56
- ForEachProcessor .Factory forEachFactory = new ForEachProcessor .Factory ();
60
+ ForEachProcessor .Factory forEachFactory = new ForEachProcessor .Factory (scriptService );
57
61
58
62
Map <String , Object > config = new HashMap <>();
59
63
config .put ("field" , "_field" );
@@ -71,7 +75,7 @@ public void testCreateWithTooManyProcessorTypes() throws Exception {
71
75
Map <String , Processor .Factory > registry = new HashMap <>();
72
76
registry .put ("_first" , (r , t , c ) -> processor );
73
77
registry .put ("_second" , (r , t , c ) -> processor );
74
- ForEachProcessor .Factory forEachFactory = new ForEachProcessor .Factory ();
78
+ ForEachProcessor .Factory forEachFactory = new ForEachProcessor .Factory (scriptService );
75
79
76
80
Map <String , Object > config = new HashMap <>();
77
81
config .put ("field" , "_field" );
@@ -84,7 +88,7 @@ public void testCreateWithTooManyProcessorTypes() throws Exception {
84
88
}
85
89
86
90
public void testCreateWithNonExistingProcessorType () throws Exception {
87
- ForEachProcessor .Factory forEachFactory = new ForEachProcessor .Factory ();
91
+ ForEachProcessor .Factory forEachFactory = new ForEachProcessor .Factory (scriptService );
88
92
Map <String , Object > config = new HashMap <>();
89
93
config .put ("field" , "_field" );
90
94
config .put ("processor" , Collections .singletonMap ("_name" , Collections .emptyMap ()));
@@ -97,15 +101,15 @@ public void testCreateWithMissingField() throws Exception {
97
101
Processor processor = new TestProcessor (ingestDocument -> { });
98
102
Map <String , Processor .Factory > registry = new HashMap <>();
99
103
registry .put ("_name" , (r , t , c ) -> processor );
100
- ForEachProcessor .Factory forEachFactory = new ForEachProcessor .Factory ();
104
+ ForEachProcessor .Factory forEachFactory = new ForEachProcessor .Factory (scriptService );
101
105
Map <String , Object > config = new HashMap <>();
102
106
config .put ("processor" , Collections .singletonList (Collections .singletonMap ("_name" , Collections .emptyMap ())));
103
107
Exception exception = expectThrows (Exception .class , () -> forEachFactory .create (registry , null , config ));
104
108
assertThat (exception .getMessage (), equalTo ("[field] required property is missing" ));
105
109
}
106
110
107
111
public void testCreateWithMissingProcessor () {
108
- ForEachProcessor .Factory forEachFactory = new ForEachProcessor .Factory ();
112
+ ForEachProcessor .Factory forEachFactory = new ForEachProcessor .Factory (scriptService );
109
113
Map <String , Object > config = new HashMap <>();
110
114
config .put ("field" , "_field" );
111
115
Exception exception = expectThrows (Exception .class , () -> forEachFactory .create (Collections .emptyMap (), null , config ));
0 commit comments