use of org.apache.metron.stellar.common.StellarProcessor in project metron by apache.
the class StellarProcessorUtils method validate.
public static void validate(String rule, Context context) {
StellarProcessor processor = new StellarProcessor();
Assert.assertTrue(rule + " not valid.", processor.validate(rule, context));
}
use of org.apache.metron.stellar.common.StellarProcessor in project metron by apache.
the class StellarProcessorUtils method run.
/**
* This utility class is intended for use while unit testing Stellar operators.
* It is included in the "main" code so third-party operators will not need
* a test dependency on Stellar's test-jar.
*
* This class ensures the basic contract of a stellar expression is adhered to:
* 1. Validate works on the expression
* 2. The output can be serialized and deserialized properly
*
* @param rule
* @param variables
* @param context
* @return ret
*/
public static Object run(String rule, Map<String, Object> variables, Context context) {
StellarProcessor processor = new StellarProcessor();
Assert.assertTrue(rule + " not valid.", processor.validate(rule, context));
Object ret = processor.parse(rule, new DefaultVariableResolver(x -> variables.get(x), x -> variables.containsKey(x)), StellarFunctions.FUNCTION_RESOLVER(), context);
byte[] raw = SerDeUtils.toBytes(ret);
Object actual = SerDeUtils.fromBytes(raw, Object.class);
Assert.assertEquals(ret, actual);
return ret;
}
Aggregations