use of org.drools.mvel.evaluators.AfterEvaluatorDefinition in project drools by kiegroup.
the class KnowledgeBuilderConfigurationTest method testEvaluatorConfiguration.
@Test
public void testEvaluatorConfiguration() {
// in this use case, the application already has the instance of the evaluator definition
EvaluatorDefinition afterDef = new AfterEvaluatorDefinition();
assertNotNull(afterDef);
// creating the option and storing in a local var just to make test easier
EvaluatorOption option = EvaluatorOption.get("after", afterDef);
// wiring the evaluator definition using the type safe method
config.setOption(option);
// checking the type safe getOption() method
assertEquals(option, config.getOption(EvaluatorOption.class, "after"));
// checking string conversion
assertEquals("after", config.getOption(EvaluatorOption.class, "after").getName());
assertEquals(afterDef, config.getOption(EvaluatorOption.class, "after").getEvaluatorDefinition());
// checking the string based getProperty() method
assertEquals(AfterEvaluatorDefinition.class.getName(), config.getProperty(EvaluatorOption.PROPERTY_NAME + "after"));
// wiring the evaluator definition using the string based setProperty() method
config.setProperty(EvaluatorOption.PROPERTY_NAME + "before", BeforeEvaluatorDefinition.class.getName());
BeforeEvaluatorDefinition beforeDef = new BeforeEvaluatorDefinition();
// checking the type safe getOption() method
assertEquals(EvaluatorOption.get("before", beforeDef), config.getOption(EvaluatorOption.class, "before"));
// checking string conversion
assertEquals("before", config.getOption(EvaluatorOption.class, "before").getName());
assertEquals(beforeDef.getClass().getName(), config.getOption(EvaluatorOption.class, "before").getEvaluatorDefinition().getClass().getName());
// checking the string based getProperty() method
assertEquals(beforeDef.getClass().getName(), config.getProperty(EvaluatorOption.PROPERTY_NAME + "before"));
}
use of org.drools.mvel.evaluators.AfterEvaluatorDefinition in project drools by kiegroup.
the class BuildUtilsTest method testCalculateTemporalDistance.
/**
* Test method for {@link org.drools.core.reteoo.builder.BuildUtils#calculateTemporalDistance(org.drools.core.rule.GroupElement)}.
*/
@Test
public void testCalculateTemporalDistance() {
// input is here just for "documentation" purposes
Interval[][] input = new Interval[][] { { new Interval(0, 0), new Interval(-2, 2), new Interval(-3, 4), new Interval(MIN, MAX), new Interval(MIN, MAX) }, { new Interval(-2, 2), new Interval(0, 0), new Interval(MIN, MAX), new Interval(1, 2), new Interval(MIN, MAX) }, { new Interval(-4, 3), new Interval(MIN, MAX), new Interval(0, 0), new Interval(2, 3), new Interval(MIN, MAX) }, { new Interval(MIN, MAX), new Interval(-2, -1), new Interval(-3, -2), new Interval(0, 0), new Interval(1, 10) }, { new Interval(MIN, MAX), new Interval(MIN, MAX), new Interval(MIN, MAX), new Interval(-10, -1), new Interval(0, 0) } };
Interval[][] expected = new Interval[][] { { new Interval(0, 0), new Interval(-2, 2), new Interval(-3, 2), new Interval(-1, 4), new Interval(0, 14) }, { new Interval(-2, 2), new Interval(0, 0), new Interval(-2, 0), new Interval(1, 2), new Interval(2, 12) }, { new Interval(-2, 3), new Interval(0, 2), new Interval(0, 0), new Interval(2, 3), new Interval(3, 13) }, { new Interval(-4, 1), new Interval(-2, -1), new Interval(-3, -2), new Interval(0, 0), new Interval(1, 10) }, { new Interval(-14, 0), new Interval(-12, -2), new Interval(-13, -3), new Interval(-10, -1), new Interval(0, 0) } };
AfterEvaluatorDefinition evals = new AfterEvaluatorDefinition();
ClassObjectType ot = new ClassObjectType(StockTick.class, true);
Pattern a = new Pattern(0, ot, "$a");
Pattern b = new Pattern(1, ot, "$b");
b.addConstraint(new EvaluatorConstraint(new Declaration[] { a.getDeclaration() }, evals.getEvaluator(ValueType.OBJECT_TYPE, AfterEvaluatorDefinition.AFTER, "-2,2"), new SelfReferenceClassFieldReader(StockTick.class)));
Pattern c = new Pattern(2, ot, "$c");
c.addConstraint(new EvaluatorConstraint(new Declaration[] { a.getDeclaration() }, evals.getEvaluator(ValueType.OBJECT_TYPE, AfterEvaluatorDefinition.AFTER, "-3,4"), new SelfReferenceClassFieldReader(StockTick.class)));
Pattern d = new Pattern(3, ot, "$d");
d.addConstraint(new EvaluatorConstraint(new Declaration[] { b.getDeclaration() }, evals.getEvaluator(ValueType.OBJECT_TYPE, AfterEvaluatorDefinition.AFTER, "1,2"), new SelfReferenceClassFieldReader(StockTick.class)));
d.addConstraint(new EvaluatorConstraint(new Declaration[] { c.getDeclaration() }, evals.getEvaluator(ValueType.OBJECT_TYPE, AfterEvaluatorDefinition.AFTER, "2,3"), new SelfReferenceClassFieldReader(StockTick.class)));
Pattern e = new Pattern(4, ot, "$e");
e.addConstraint(new EvaluatorConstraint(new Declaration[] { d.getDeclaration() }, evals.getEvaluator(ValueType.OBJECT_TYPE, AfterEvaluatorDefinition.AFTER, "1,10"), new SelfReferenceClassFieldReader(StockTick.class)));
GroupElement not = new GroupElement(Type.NOT);
not.addChild(e);
GroupElement and = new GroupElement(Type.AND);
and.addChild(a);
and.addChild(b);
and.addChild(c);
and.addChild(d);
and.addChild(not);
TemporalDependencyMatrix matrix = utils.calculateTemporalDistance(and);
// printMatrix( matrix.getMatrix() );
assertEqualsMatrix(expected, matrix.getMatrix());
assertEquals(15, matrix.getExpirationOffset(a));
assertEquals(11, matrix.getExpirationOffset(d));
assertEquals(1, matrix.getExpirationOffset(e));
}
Aggregations