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));
}
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);
}
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));
}
Aggregations