use of org.apache.metron.stellar.dsl.DefaultVariableResolver in project metron by apache.
the class RegExFunctionsTest method testRegExGroupVal.
@Test
public void testRegExGroupVal() throws Exception {
final Map<String, String> variableMap = new HashMap<String, String>() {
{
put("numbers", "12345");
put("numberPattern", "\\d(\\d)(\\d).*");
put("numberPatternNoCaptures", "\\d\\d\\d.*");
put("letters", "abcde");
put("empty", "");
}
};
Assert.assertTrue(runPredicate("REGEXP_GROUP_VAL(numbers,numberPattern,2) == '3'", new DefaultVariableResolver(v -> variableMap.get(v), v -> variableMap.containsKey(v))));
Assert.assertTrue(runPredicate("REGEXP_GROUP_VAL(letters,numberPattern,2) == null", new DefaultVariableResolver(v -> variableMap.get(v), v -> variableMap.containsKey(v))));
Assert.assertTrue(runPredicate("REGEXP_GROUP_VAL(empty,numberPattern,2) == null", new DefaultVariableResolver(v -> variableMap.get(v), v -> variableMap.containsKey(v))));
Assert.assertTrue(runPredicate("REGEXP_GROUP_VAL(numbers,numberPatternNoCaptures,2) == null", new DefaultVariableResolver(v -> variableMap.get(v), v -> variableMap.containsKey(v))));
boolean thrown = false;
try {
runPredicate("REGEXP_GROUP_VAL(2) == null", new DefaultVariableResolver(v -> variableMap.get(v), v -> variableMap.containsKey(v)));
} catch (ParseException | IllegalStateException ise) {
thrown = true;
}
if (!thrown) {
Assert.assertTrue("Did not fail on wrong number of parameters", false);
}
}
Aggregations