Search in sources :

Example 26 with ExpressionField

use of org.drools.workbench.models.datamodel.rule.ExpressionField 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());
}
Also used : SingleFieldConstraintEBLeftSide(org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) ExpressionField(org.drools.workbench.models.datamodel.rule.ExpressionField) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) ExpressionUnboundFact(org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact) Test(org.junit.Test)

Aggregations

ExpressionField (org.drools.workbench.models.datamodel.rule.ExpressionField)26 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)24 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)24 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)24 Test (org.junit.Test)24 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)23 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)23 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)23 ExpressionUnboundFact (org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact)21 SingleFieldConstraintEBLeftSide (org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide)21 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)11 ExpressionMethod (org.drools.workbench.models.datamodel.rule.ExpressionMethod)5 ExpressionVariable (org.drools.workbench.models.datamodel.rule.ExpressionVariable)5 ExpressionFormLine (org.drools.workbench.models.datamodel.rule.ExpressionFormLine)4 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ExpressionText (org.drools.workbench.models.datamodel.rule.ExpressionText)2 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)2 MethodInfo (org.kie.soup.project.datamodel.oracle.MethodInfo)2