1414import org .junit .jupiter .params .ParameterizedTest ;
1515import org .junit .jupiter .params .provider .Arguments ;
1616import org .junit .jupiter .params .provider .MethodSource ;
17+ import org .mockito .Mock ;
18+ import org .opensearch .dataprepper .expression .ExpressionEvaluator ;
1719import org .opensearch .dataprepper .model .configuration .PluginSetting ;
1820import org .opensearch .dataprepper .model .event .Event ;
1921import org .opensearch .dataprepper .model .record .Record ;
@@ -40,6 +42,9 @@ public class GrokProcessorIT {
4042 private final String PLUGIN_NAME = "grok" ;
4143 private String messageInput ;
4244
45+ @ Mock
46+ private ExpressionEvaluator <Boolean > expressionEvaluator ;
47+
4348 @ BeforeEach
4449 public void setup () {
4550
@@ -53,7 +58,8 @@ public void setup() {
5358 GrokProcessorConfig .DEFAULT_PATTERNS_FILES_GLOB ,
5459 Collections .emptyMap (),
5560 GrokProcessorConfig .DEFAULT_TIMEOUT_MILLIS ,
56- GrokProcessorConfig .DEFAULT_TARGET_KEY );
61+ GrokProcessorConfig .DEFAULT_TARGET_KEY ,
62+ null );
5763
5864 pluginSetting .setPipelineName ("grokPipeline" );
5965
@@ -77,7 +83,8 @@ private PluginSetting completePluginSettingForGrokProcessor(final boolean breakO
7783 final String patternsFilesGlob ,
7884 final Map <String , String > patternDefinitions ,
7985 final int timeoutMillis ,
80- final String targetKey ) {
86+ final String targetKey ,
87+ final String grokWhen ) {
8188 final Map <String , Object > settings = new HashMap <>();
8289 settings .put (GrokProcessorConfig .BREAK_ON_MATCH , breakOnMatch );
8390 settings .put (GrokProcessorConfig .NAMED_CAPTURES_ONLY , namedCapturesOnly );
@@ -89,6 +96,7 @@ private PluginSetting completePluginSettingForGrokProcessor(final boolean breakO
8996 settings .put (GrokProcessorConfig .PATTERNS_FILES_GLOB , patternsFilesGlob );
9097 settings .put (GrokProcessorConfig .TIMEOUT_MILLIS , timeoutMillis );
9198 settings .put (GrokProcessorConfig .TARGET_KEY , targetKey );
99+ settings .put (GrokProcessorConfig .GROK_WHEN , grokWhen );
92100
93101 return new PluginSetting (PLUGIN_NAME , settings );
94102 }
@@ -101,7 +109,7 @@ public void testMatchNoCapturesWithExistingAndNonExistingKey() throws JsonProces
101109 matchConfig .put ("bad_key" , Collections .singletonList (nonMatchingPattern ));
102110
103111 pluginSetting .getSettings ().put (GrokProcessorConfig .MATCH , matchConfig );
104- grokProcessor = new GrokProcessor (pluginSetting );
112+ grokProcessor = new GrokProcessor (pluginSetting , expressionEvaluator );
105113
106114 final Map <String , Object > testData = new HashMap ();
107115 testData .put ("message" , messageInput );
@@ -121,7 +129,7 @@ public void testSingleMatchSinglePatternWithDefaults() throws JsonProcessingExce
121129 matchConfig .put ("message" , Collections .singletonList ("%{COMMONAPACHELOG}" ));
122130
123131 pluginSetting .getSettings ().put (GrokProcessorConfig .MATCH , matchConfig );
124- grokProcessor = new GrokProcessor (pluginSetting );
132+ grokProcessor = new GrokProcessor (pluginSetting , expressionEvaluator );
125133
126134 final Map <String , Object > testData = new HashMap ();
127135 testData .put ("message" , messageInput );
@@ -159,7 +167,7 @@ public void testSingleMatchMultiplePatternWithBreakOnMatchFalse() throws JsonPro
159167
160168 pluginSetting .getSettings ().put (GrokProcessorConfig .MATCH , matchConfig );
161169 pluginSetting .getSettings ().put (GrokProcessorConfig .BREAK_ON_MATCH , false );
162- grokProcessor = new GrokProcessor (pluginSetting );
170+ grokProcessor = new GrokProcessor (pluginSetting , expressionEvaluator );
163171
164172 final Map <String , Object > testData = new HashMap ();
165173 testData .put ("message" , messageInput );
@@ -194,7 +202,7 @@ public void testSingleMatchTypeConversionWithDefaults() throws JsonProcessingExc
194202 matchConfig .put ("message" , Collections .singletonList ("\" (?:%{WORD:verb} %{NOTSPACE:request}(?: HTTP/%{NUMBER:httpversion})?|%{DATA:rawrequest})\" %{NUMBER:response:int} (?:%{NUMBER:bytes:float}|-)" ));
195203
196204 pluginSetting .getSettings ().put (GrokProcessorConfig .MATCH , matchConfig );
197- grokProcessor = new GrokProcessor (pluginSetting );
205+ grokProcessor = new GrokProcessor (pluginSetting , expressionEvaluator );
198206
199207 final Map <String , Object > testData = new HashMap ();
200208 testData .put ("message" , messageInput );
@@ -226,7 +234,7 @@ public void testMultipleMatchWithBreakOnMatchFalse() throws JsonProcessingExcept
226234
227235 pluginSetting .getSettings ().put (GrokProcessorConfig .MATCH , matchConfig );
228236 pluginSetting .getSettings ().put (GrokProcessorConfig .BREAK_ON_MATCH , false );
229- grokProcessor = new GrokProcessor (pluginSetting );
237+ grokProcessor = new GrokProcessor (pluginSetting , expressionEvaluator );
230238
231239 final Map <String , Object > testData = new HashMap ();
232240 testData .put ("message" , messageInput );
@@ -264,7 +272,7 @@ public void testMatchWithKeepEmptyCapturesTrue() throws JsonProcessingException
264272
265273 pluginSetting .getSettings ().put (GrokProcessorConfig .MATCH , matchConfig );
266274 pluginSetting .getSettings ().put (GrokProcessorConfig .KEEP_EMPTY_CAPTURES , true );
267- grokProcessor = new GrokProcessor (pluginSetting );
275+ grokProcessor = new GrokProcessor (pluginSetting , expressionEvaluator );
268276
269277 final Map <String , Object > testData = new HashMap ();
270278 testData .put ("message" , messageInput );
@@ -300,7 +308,7 @@ public void testMatchWithNamedCapturesOnlyFalse() throws JsonProcessingException
300308
301309 pluginSetting .getSettings ().put (GrokProcessorConfig .MATCH , matchConfig );
302310 pluginSetting .getSettings ().put (GrokProcessorConfig .NAMED_CAPTURES_ONLY , false );
303- grokProcessor = new GrokProcessor (pluginSetting );
311+ grokProcessor = new GrokProcessor (pluginSetting , expressionEvaluator );
304312
305313 final Map <String , Object > testData = new HashMap ();
306314 testData .put ("message" , "This is my greedy data before matching 192.0.2.1 123456" );
@@ -332,7 +340,7 @@ public void testPatternDefinitions() throws JsonProcessingException {
332340
333341 pluginSetting .getSettings ().put (GrokProcessorConfig .MATCH , matchConfig );
334342 pluginSetting .getSettings ().put (GrokProcessorConfig .PATTERN_DEFINITIONS , patternDefinitions );
335- grokProcessor = new GrokProcessor (pluginSetting );
343+ grokProcessor = new GrokProcessor (pluginSetting , expressionEvaluator );
336344
337345 final Map <String , Object > testData = new HashMap ();
338346 testData .put ("message" , "This is my greedy data before matching with my phone number 123-456-789" );
@@ -375,7 +383,7 @@ public void testPatternsDirWithDefaultPatternsFilesGlob() throws JsonProcessingE
375383
376384 pluginSetting .getSettings ().put (GrokProcessorConfig .MATCH , matchConfig );
377385 pluginSetting .getSettings ().put (GrokProcessorConfig .PATTERNS_DIRECTORIES , patternsDirectories );
378- grokProcessor = new GrokProcessor (pluginSetting );
386+ grokProcessor = new GrokProcessor (pluginSetting , expressionEvaluator );
379387
380388 final Record <Event > resultRecord = buildRecordWithEvent (resultData );
381389
@@ -408,7 +416,7 @@ public void testPatternsDirWithCustomPatternsFilesGlob() throws JsonProcessingEx
408416 pluginSetting .getSettings ().put (GrokProcessorConfig .MATCH , matchConfig );
409417 pluginSetting .getSettings ().put (GrokProcessorConfig .PATTERNS_DIRECTORIES , patternsDirectories );
410418 pluginSetting .getSettings ().put (GrokProcessorConfig .PATTERNS_FILES_GLOB , "*1.txt" );
411- grokProcessor = new GrokProcessor (pluginSetting );
419+ grokProcessor = new GrokProcessor (pluginSetting , expressionEvaluator );
412420
413421 final Record <Event > resultRecord = buildRecordWithEvent (resultData );
414422
@@ -423,7 +431,7 @@ public void testPatternsDirWithCustomPatternsFilesGlob() throws JsonProcessingEx
423431
424432 pluginSetting .getSettings ().put (GrokProcessorConfig .MATCH , matchConfigWithPatterns2Pattern );
425433
426- Throwable throwable = assertThrows (IllegalArgumentException .class , () -> new GrokProcessor (( pluginSetting ) ));
434+ Throwable throwable = assertThrows (IllegalArgumentException .class , () -> new GrokProcessor (pluginSetting , expressionEvaluator ));
427435 assertThat ("No definition for key 'CUSTOMBIRTHDAYPATTERN' found, aborting" , equalTo (throwable .getMessage ()));
428436 }
429437
@@ -433,7 +441,7 @@ public void testMatchWithNamedCapturesSyntax() throws JsonProcessingException {
433441 matchConfig .put ("message" , Collections .singletonList ("%{GREEDYDATA:greedy_data} (?<mynumber>\\ d\\ d\\ d-\\ d\\ d\\ d-\\ d\\ d\\ d)" ));
434442
435443 pluginSetting .getSettings ().put (GrokProcessorConfig .MATCH , matchConfig );
436- grokProcessor = new GrokProcessor (pluginSetting );
444+ grokProcessor = new GrokProcessor (pluginSetting , expressionEvaluator );
437445
438446 final Map <String , Object > testData = new HashMap ();
439447 testData .put ("message" , "This is my greedy data before matching with my phone number 123-456-789" );
@@ -457,14 +465,14 @@ public void testMatchWithNamedCapturesSyntax() throws JsonProcessingException {
457465 @ Test
458466 public void testCompileNonRegisteredPatternThrowsIllegalArgumentException () {
459467
460- grokProcessor = new GrokProcessor (pluginSetting );
468+ grokProcessor = new GrokProcessor (pluginSetting , expressionEvaluator );
461469
462470 final Map <String , List <String >> matchConfig = new HashMap <>();
463471 matchConfig .put ("message" , Collections .singletonList ("%{NONEXISTENTPATTERN}" ));
464472
465473 pluginSetting .getSettings ().put (GrokProcessorConfig .MATCH , matchConfig );
466474
467- assertThrows (IllegalArgumentException .class , () -> new GrokProcessor (pluginSetting ));
475+ assertThrows (IllegalArgumentException .class , () -> new GrokProcessor (pluginSetting , expressionEvaluator ));
468476 }
469477
470478 @ ParameterizedTest
@@ -474,7 +482,7 @@ void testDataPrepperBuiltInGrokPatterns(final String matchPattern, final String
474482 matchConfig .put ("message" , Collections .singletonList (matchPattern ));
475483
476484 pluginSetting .getSettings ().put (GrokProcessorConfig .MATCH , matchConfig );
477- grokProcessor = new GrokProcessor (pluginSetting );
485+ grokProcessor = new GrokProcessor (pluginSetting , expressionEvaluator );
478486
479487 final Map <String , Object > testData = new HashMap ();
480488 testData .put ("message" , logInput );
0 commit comments