use of org.drools.workbench.models.datamodel.rule.ExpressionVariable in project drools-wb by kiegroup.
the class GuidedRuleEditorValidatorTest method testComparingFieldToExpression.
@Test
public void testComparingFieldToExpression() throws Exception {
FactPattern f1 = new FactPattern();
f1.setBoundName("f1");
FactPattern f2 = new FactPattern();
SingleFieldConstraint constraint = new SingleFieldConstraint();
constraint.setOperator("==");
constraint.getExpressionValue().appendPart(new ExpressionVariable("field", "java.lang.Number", "Number"));
f2.addConstraint(constraint);
model.lhs = new IPattern[] { f1, f2 };
assertTrue(validator.isValid());
}
use of org.drools.workbench.models.datamodel.rule.ExpressionVariable in project drools-wb by kiegroup.
the class GuidedRuleEditorValidatorTest method testValidFromCompositeFactPattern.
@Test
public void testValidFromCompositeFactPattern() throws Exception {
FactPattern factPattern = new FactPattern("SomeList");
factPattern.setBoundName("list");
FromCompositeFactPattern fromCompositeFactPattern = new FromCompositeFactPattern();
fromCompositeFactPattern.setFactPattern(new FactPattern("Person"));
ExpressionFormLine expression = new ExpressionFormLine();
expression.appendPart(new ExpressionVariable("list", "SomeList", "SomeList"));
fromCompositeFactPattern.setExpression(expression);
model.lhs = new IPattern[] { fromCompositeFactPattern };
assertTrue(validator.isValid());
}
use of org.drools.workbench.models.datamodel.rule.ExpressionVariable in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testDSLWithFrom.
/*
* https://issues.jboss.org/browse/DROOLS-1903
*/
@Test
public void testDSLWithFrom() {
final RuleModel m = new RuleModel();
m.name = "testDSLWithFrom";
m.lhs = new IPattern[2];
m.rhs = new IAction[0];
final FromCollectCompositeFactPattern from = new FromCollectCompositeFactPattern();
final FromCompositeFactPattern rightPattern = new FromCompositeFactPattern();
final FactPattern person = new FactPattern("Person");
person.setBoundName("$person");
m.lhs[0] = person;
rightPattern.setFactPattern(new FactPattern("Person"));
rightPattern.setExpression(new ExpressionFormLine(new ExpressionVariable(person.getBoundName(), person.getFactType())));
from.setRightPattern(rightPattern);
from.setFactPattern(new FactPattern("java.util.List"));
m.lhs[1] = from;
final RuleModel modelSpy = spy(m);
doReturn(true).when(modelSpy).hasDSLSentences();
final String drl = ruleModelPersistence.marshal(modelSpy);
final RuleModel tempModel = spy(ruleModelPersistence.unmarshalUsingDSL(drl, null, dmo, ""));
doReturn(true).when(tempModel).hasDSLSentences();
final String newDrl = ruleModelPersistence.marshal(tempModel);
final RuleModel newModel = ruleModelPersistence.unmarshalUsingDSL(newDrl, null, dmo, "");
assertTrue(newModel.lhs[0] instanceof FactPattern);
assertTrue(newModel.lhs[1] instanceof FromCollectCompositeFactPattern);
assertDSLEscaping(newDrl);
}
use of org.drools.workbench.models.datamodel.rule.ExpressionVariable in project drools by kiegroup.
the class RuleModelDRLPersistenceUnmarshallingTest method testExpressionEditorLeftToOperator.
@Test
public void testExpressionEditorLeftToOperator() throws Exception {
String drl = "" + "rule \"r1\"\n" + "dialect \"mvel\"\n" + "when\n" + " a: Applicant()\n" + " Applicant( age == a.age )\n" + "then\n" + "end";
addModelField("Applicant", "this", "Applicant", DataType.TYPE_THIS);
addModelField("Applicant", "age", "java.lang.Integer", "Integer");
RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
FactPattern pattern1 = (FactPattern) m.lhs[0];
assertEquals("a", pattern1.getBoundName());
FactPattern pattern2 = (FactPattern) m.lhs[1];
assertEquals(1, pattern2.getConstraintList().getNumberOfConstraints());
assertTrue(pattern2.getConstraintList().getConstraint(0) instanceof SingleFieldConstraint);
SingleFieldConstraint constraint = (SingleFieldConstraint) pattern2.getConstraintList().getConstraint(0);
assertEquals("age", constraint.getFieldName());
assertEquals("==", constraint.getOperator());
assertEquals(BaseSingleFieldConstraint.TYPE_EXPR_BUILDER_VALUE, constraint.getConstraintValueType());
assertEquals("", constraint.getValue());
assertEquals(2, constraint.getExpressionValue().getParts().size());
assertTrue(constraint.getExpressionValue().getParts().get(0) instanceof ExpressionVariable);
ExpressionVariable expressionVariable = (ExpressionVariable) constraint.getExpressionValue().getParts().get(0);
assertEquals("a", expressionVariable.getName());
assertEquals("Applicant", expressionVariable.getClassType());
assertEquals("this", expressionVariable.getGenericType());
assertEquals(constraint.getExpressionValue().getParts().get(1), expressionVariable.getNext());
assertTrue(constraint.getExpressionValue().getParts().get(1) instanceof ExpressionField);
ExpressionField expressionField = (ExpressionField) constraint.getExpressionValue().getParts().get(1);
assertEquals("age", expressionField.getName());
assertEquals("java.lang.Integer", expressionField.getClassType());
assertEquals("Integer", expressionField.getGenericType());
}
use of org.drools.workbench.models.datamodel.rule.ExpressionVariable in project drools by kiegroup.
the class CopyExpressionVisitor method visit.
public void visit(ExpressionVariable part) {
add(new ExpressionVariable(part.getName(), part.getFactType()));
moveNext(part);
}
Aggregations