Search in sources :

Example 11 with ExpressionMethod

use of org.drools.workbench.models.datamodel.rule.ExpressionMethod in project drools by kiegroup.

the class CopyExpressionVisitorTest method testExpressionFormLineCopy.

@Test
public void testExpressionFormLineCopy() {
    ExpressionFormLine efl = new ExpressionFormLine();
    efl.appendPart(new ExpressionCollection("collection", "CT", "GT", "PT"));
    efl.appendPart(new ExpressionCollectionIndex("collectionIndex", "CT", "GT"));
    efl.appendPart(new ExpressionField("field", "CT", "FT", "PT"));
    efl.appendPart(new ExpressionFieldVariable("fieldVariable", "Type"));
    efl.appendPart(new ExpressionGlobalVariable("globalVariable", "CT", "GT", "PT"));
    efl.appendPart(new ExpressionMethod("method", "CT", "GT"));
    efl.appendPart(new ExpressionMethodParameter("methodParam", "CT", "GT"));
    efl.appendPart(new ExpressionText("text"));
    efl.appendPart(new ExpressionUnboundFact("FactType"));
    efl.appendPart(new ExpressionVariable("binding", "FactType"));
    // verify that the new instance created with copy constructor is equal to original
    assertEquals(efl, new ExpressionFormLine(efl));
}
Also used : ExpressionFormLine(org.drools.workbench.models.datamodel.rule.ExpressionFormLine) ExpressionFieldVariable(org.drools.workbench.models.datamodel.rule.ExpressionFieldVariable) ExpressionMethod(org.drools.workbench.models.datamodel.rule.ExpressionMethod) ExpressionCollectionIndex(org.drools.workbench.models.datamodel.rule.ExpressionCollectionIndex) ExpressionMethodParameter(org.drools.workbench.models.datamodel.rule.ExpressionMethodParameter) ExpressionCollection(org.drools.workbench.models.datamodel.rule.ExpressionCollection) ExpressionText(org.drools.workbench.models.datamodel.rule.ExpressionText) ExpressionVariable(org.drools.workbench.models.datamodel.rule.ExpressionVariable) ExpressionField(org.drools.workbench.models.datamodel.rule.ExpressionField) ExpressionUnboundFact(org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact) ExpressionGlobalVariable(org.drools.workbench.models.datamodel.rule.ExpressionGlobalVariable) Test(org.junit.Test)

Example 12 with ExpressionMethod

use of org.drools.workbench.models.datamodel.rule.ExpressionMethod in project drools by kiegroup.

the class RuleModelDRLPersistenceUnmarshallingTest method testLHSNestedMethodCalls.

@Test
public void testLHSNestedMethodCalls() throws Exception {
    String drl = "package org.mortgages;\n" + "rule \"test\"\n" + " dialect \"mvel\"\n" + " when\n" + "  Parent( methodToGetChild1().methodToGetChild2().field1 > 5 )\n" + " then\n" + "end";
    addMethodInformation("Parent", "methodToGetChild1", Collections.emptyList(), "Child1", null, "Child1");
    addMethodInformation("Child1", "methodToGetChild2", Collections.emptyList(), "Child2", null, "Child2");
    addModelField("Child2", "field1", "int", DataType.TYPE_NUMERIC_INTEGER);
    final RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
    assertNotNull(m);
    assertEquals(1, m.lhs.length);
    assertTrue(m.lhs[0] instanceof FactPattern);
    final FactPattern fp = (FactPattern) m.lhs[0];
    assertEquals("Parent", fp.getFactType());
    assertEquals(1, fp.getNumberOfConstraints());
    assertTrue(fp.getConstraint(0) instanceof SingleFieldConstraintEBLeftSide);
    final SingleFieldConstraintEBLeftSide exp = (SingleFieldConstraintEBLeftSide) fp.getConstraint(0);
    assertEquals("int", exp.getFieldType());
    assertEquals(">", exp.getOperator());
    assertEquals("5", exp.getValue());
    assertEquals(4, exp.getExpressionLeftSide().getParts().size());
    assertTrue(exp.getExpressionLeftSide().getParts().get(0) instanceof ExpressionUnboundFact);
    final ExpressionUnboundFact expPart0 = (ExpressionUnboundFact) exp.getExpressionLeftSide().getParts().get(0);
    assertEquals("Parent", expPart0.getFactType());
    assertTrue(exp.getExpressionLeftSide().getParts().get(1) instanceof ExpressionMethod);
    final ExpressionMethod expPart1 = (ExpressionMethod) exp.getExpressionLeftSide().getParts().get(1);
    assertEquals("methodToGetChild1", expPart1.getName());
    assertTrue(exp.getExpressionLeftSide().getParts().get(2) instanceof ExpressionMethod);
    final ExpressionMethod expPart2 = (ExpressionMethod) exp.getExpressionLeftSide().getParts().get(2);
    assertEquals("methodToGetChild2", expPart2.getName());
    assertTrue(exp.getExpressionLeftSide().getParts().get(3) instanceof ExpressionField);
    final ExpressionField expPart3 = (ExpressionField) exp.getExpressionLeftSide().getParts().get(3);
    assertEquals("field1", expPart3.getName());
}
Also used : SingleFieldConstraintEBLeftSide(org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide) ExpressionMethod(org.drools.workbench.models.datamodel.rule.ExpressionMethod) 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

ExpressionMethod (org.drools.workbench.models.datamodel.rule.ExpressionMethod)12 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)9 ExpressionUnboundFact (org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact)9 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)9 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)9 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)9 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)9 Test (org.junit.Test)9 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)8 SingleFieldConstraintEBLeftSide (org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide)7 ExpressionField (org.drools.workbench.models.datamodel.rule.ExpressionField)5 ExpressionFormLine (org.drools.workbench.models.datamodel.rule.ExpressionFormLine)5 ExpressionText (org.drools.workbench.models.datamodel.rule.ExpressionText)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)3 ExpressionVariable (org.drools.workbench.models.datamodel.rule.ExpressionVariable)3 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)3 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)3