Search in sources :

Example 1 with ExpressionCollection

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

the class RuleModelDRLPersistenceUnmarshallingTest method testListSize.

@Test
public void testListSize() throws Exception {
    String drl = "" + "package org.mortgages;\n" + "import java.lang.Number;\n" + "rule \"Test\"\n" + "  dialect \"mvel\"\n" + "  when\n" + "    Person( addresses.size() == 0 )\n" + "  then\n" + "end\n";
    addModelField("Person", "addresses", "java.util.List", DataType.TYPE_COLLECTION);
    addMethodInformation("java.util.List", "size", Collections.emptyList(), "int", null, DataType.TYPE_NUMERIC_INTEGER);
    HashMap<String, String> map = new HashMap<>();
    map.put("Person#addresses", "Address");
    when(dmo.getModuleFieldParametersType()).thenReturn(map);
    final RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
    assertEquals(1, m.lhs.length);
    FactPattern pattern = (FactPattern) m.lhs[0];
    assertEquals(1, pattern.getConstraintList().getConstraints().length);
    SingleFieldConstraintEBLeftSide constraint = (SingleFieldConstraintEBLeftSide) pattern.getConstraint(0);
    assertEquals("size", constraint.getFieldName());
    assertEquals("int", constraint.getFieldType());
    assertEquals("0", constraint.getValue());
    assertEquals("==", constraint.getOperator());
    assertEquals(1, constraint.getConstraintValueType());
    assertTrue(constraint.getExpressionLeftSide().getParts().get(0) instanceof ExpressionUnboundFact);
    assertTrue(constraint.getExpressionLeftSide().getParts().get(1) instanceof ExpressionCollection);
    assertTrue(constraint.getExpressionLeftSide().getParts().get(2) instanceof ExpressionMethod);
    assertEqualsIgnoreWhitespace(drl, RuleModelDRLPersistenceImpl.getInstance().marshal(m));
}
Also used : SingleFieldConstraintEBLeftSide(org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide) ExpressionMethod(org.drools.workbench.models.datamodel.rule.ExpressionMethod) HashMap(java.util.HashMap) ExpressionCollection(org.drools.workbench.models.datamodel.rule.ExpressionCollection) 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) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) ExpressionUnboundFact(org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact) Test(org.junit.Test)

Example 2 with ExpressionCollection

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

the class CopyExpressionVisitor method visit.

public void visit(ExpressionCollection part) {
    add(new ExpressionCollection(part.getName(), part.getClassType(), part.getGenericType(), part.getParametricType()));
    moveNext(part);
}
Also used : ExpressionCollection(org.drools.workbench.models.datamodel.rule.ExpressionCollection)

Example 3 with ExpressionCollection

use of org.drools.workbench.models.datamodel.rule.ExpressionCollection 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)

Aggregations

ExpressionCollection (org.drools.workbench.models.datamodel.rule.ExpressionCollection)3 ExpressionMethod (org.drools.workbench.models.datamodel.rule.ExpressionMethod)2 ExpressionUnboundFact (org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)1 ExpressionCollectionIndex (org.drools.workbench.models.datamodel.rule.ExpressionCollectionIndex)1 ExpressionField (org.drools.workbench.models.datamodel.rule.ExpressionField)1 ExpressionFieldVariable (org.drools.workbench.models.datamodel.rule.ExpressionFieldVariable)1 ExpressionFormLine (org.drools.workbench.models.datamodel.rule.ExpressionFormLine)1 ExpressionGlobalVariable (org.drools.workbench.models.datamodel.rule.ExpressionGlobalVariable)1 ExpressionMethodParameter (org.drools.workbench.models.datamodel.rule.ExpressionMethodParameter)1 ExpressionText (org.drools.workbench.models.datamodel.rule.ExpressionText)1 ExpressionVariable (org.drools.workbench.models.datamodel.rule.ExpressionVariable)1 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)1 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)1 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)1 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)1 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)1 SingleFieldConstraintEBLeftSide (org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide)1