use of org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact in project drools by kiegroup.
the class RuleModelDRLPersistenceUnmarshallingTest method testNestedFieldConstraintsAsExpression.
@Test
public void testNestedFieldConstraintsAsExpression() {
String drl = "rule \"rule1\"\n" + "when\n" + "Person( contact.telephone > 12345 )\n" + "then\n" + "end";
addModelField("org.test.Person", "contact", "org.test.Contact", "Contact");
addModelField("org.test.Contact", "telephone", "java.lang.Integer", DataType.TYPE_NUMERIC_INTEGER);
RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
assertNotNull(m);
assertEquals("rule1", m.name);
assertEquals(1, m.lhs.length);
IPattern p = m.lhs[0];
assertTrue(p instanceof FactPattern);
FactPattern fp = (FactPattern) p;
assertEquals("Person", fp.getFactType());
assertEquals(1, fp.getConstraintList().getConstraints().length);
assertTrue(((FactPattern) m.lhs[0]).getFieldConstraints()[0] instanceof SingleFieldConstraintEBLeftSide);
SingleFieldConstraintEBLeftSide ebLeftSide = (SingleFieldConstraintEBLeftSide) ((FactPattern) m.lhs[0]).getFieldConstraints()[0];
assertEquals("telephone", ebLeftSide.getFieldName());
assertEquals("java.lang.Integer", ebLeftSide.getFieldType());
assertEquals(">", ebLeftSide.getOperator());
assertEquals("12345", ebLeftSide.getValue());
assertEquals(3, ebLeftSide.getExpressionLeftSide().getParts().size());
assertTrue(ebLeftSide.getExpressionLeftSide().getParts().get(0) instanceof ExpressionUnboundFact);
ExpressionUnboundFact expressionUnboundFact = ((ExpressionUnboundFact) ebLeftSide.getExpressionLeftSide().getParts().get(0));
assertEquals("Person", expressionUnboundFact.getName());
assertEquals("Person", expressionUnboundFact.getClassType());
assertEquals("Person", expressionUnboundFact.getGenericType());
assertEquals(((FactPattern) m.lhs[0]).getFactType(), expressionUnboundFact.getFactType());
assertEquals(null, expressionUnboundFact.getPrevious());
assertEquals(ebLeftSide.getExpressionLeftSide().getParts().get(1), expressionUnboundFact.getNext());
assertTrue(ebLeftSide.getExpressionLeftSide().getParts().get(1) instanceof ExpressionField);
ExpressionField expressionField1 = (ExpressionField) ebLeftSide.getExpressionLeftSide().getParts().get(1);
assertEquals("contact", expressionField1.getName());
assertEquals("org.test.Contact", expressionField1.getClassType());
assertEquals("Contact", expressionField1.getGenericType());
assertEquals(ebLeftSide.getExpressionLeftSide().getParts().get(0), expressionField1.getPrevious());
assertEquals(ebLeftSide.getExpressionLeftSide().getParts().get(2), expressionField1.getNext());
assertTrue(ebLeftSide.getExpressionLeftSide().getParts().get(2) instanceof ExpressionField);
ExpressionField expressionField2 = (ExpressionField) ebLeftSide.getExpressionLeftSide().getParts().get(2);
assertEquals("telephone", expressionField2.getName());
assertEquals("java.lang.Integer", expressionField2.getClassType());
assertEquals(DataType.TYPE_NUMERIC_INTEGER, expressionField2.getGenericType());
assertEquals(ebLeftSide.getExpressionLeftSide().getParts().get(1), expressionField2.getPrevious());
assertNull(expressionField2.getNext());
}
use of org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact in project drools by kiegroup.
the class RuleModelDRLPersistenceUnmarshallingTest method testNestedFieldExpressionsWithAFunction.
@Test
public void testNestedFieldExpressionsWithAFunction() {
String drl = "rule rule1\n" + "when\n" + "Person( address.postalCode == myFunction() )\n" + "then\n" + "end";
addModelField("org.test.Person", "address", "org.test.Address", "Address");
addModelField("org.test.Address", "postalCode", "java.lang.Integer", "Integer");
RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
assertNotNull(m);
assertEquals(1, m.lhs.length);
assertTrue(m.lhs[0] instanceof FactPattern);
assertTrue(((FactPattern) m.lhs[0]).getFieldConstraints()[0] instanceof SingleFieldConstraintEBLeftSide);
SingleFieldConstraintEBLeftSide ebLeftSide = (SingleFieldConstraintEBLeftSide) ((FactPattern) m.lhs[0]).getFieldConstraints()[0];
assertEquals("postalCode", ebLeftSide.getFieldName());
assertEquals("java.lang.Integer", ebLeftSide.getFieldType());
assertEquals("==", ebLeftSide.getOperator());
assertEquals("myFunction()", ebLeftSide.getValue());
assertEquals(3, ebLeftSide.getExpressionLeftSide().getParts().size());
assertTrue(ebLeftSide.getExpressionLeftSide().getParts().get(0) instanceof ExpressionUnboundFact);
ExpressionUnboundFact expressionUnboundFact = ((ExpressionUnboundFact) ebLeftSide.getExpressionLeftSide().getParts().get(0));
assertEquals("Person", expressionUnboundFact.getName());
assertEquals("Person", expressionUnboundFact.getClassType());
assertEquals("Person", expressionUnboundFact.getGenericType());
assertEquals(((FactPattern) m.lhs[0]).getFactType(), expressionUnboundFact.getFactType());
assertNull(expressionUnboundFact.getPrevious());
assertEquals(ebLeftSide.getExpressionLeftSide().getParts().get(1), expressionUnboundFact.getNext());
assertTrue(ebLeftSide.getExpressionLeftSide().getParts().get(1) instanceof ExpressionField);
ExpressionField expressionField1 = (ExpressionField) ebLeftSide.getExpressionLeftSide().getParts().get(1);
assertEquals("address", expressionField1.getName());
assertEquals("org.test.Address", expressionField1.getClassType());
assertEquals("Address", expressionField1.getGenericType());
assertEquals(ebLeftSide.getExpressionLeftSide().getParts().get(0), expressionField1.getPrevious());
assertEquals(ebLeftSide.getExpressionLeftSide().getParts().get(2), expressionField1.getNext());
assertTrue(ebLeftSide.getExpressionLeftSide().getParts().get(2) instanceof ExpressionField);
ExpressionField expressionField2 = (ExpressionField) ebLeftSide.getExpressionLeftSide().getParts().get(2);
assertEquals("postalCode", expressionField2.getName());
assertEquals("java.lang.Integer", expressionField2.getClassType());
assertEquals("Integer", expressionField2.getGenericType());
assertEquals(ebLeftSide.getExpressionLeftSide().getParts().get(1), expressionField2.getPrevious());
assertNull(expressionField2.getNext());
}
Aggregations