use of org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testSimpleFromCollectMultipleSubPatternValuesFirstValue.
@Test
public void testSimpleFromCollectMultipleSubPatternValuesFirstValue() {
TemplateModel m = new TemplateModel();
m.name = "r1";
FactPattern fp = new FactPattern("Person");
SingleFieldConstraint sfc = new SingleFieldConstraint("field1");
sfc.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
sfc.setFieldType(DataType.TYPE_STRING);
sfc.setOperator("==");
sfc.setValue("$f1");
fp.addConstraint(sfc);
SingleFieldConstraint sfc1 = new SingleFieldConstraint("field2");
sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
sfc1.setFieldType(DataType.TYPE_STRING);
sfc1.setOperator("==");
sfc1.setValue("$f2");
fp.addConstraint(sfc1);
FactPattern fp2 = new FactPattern("java.util.List");
SingleFieldConstraint sfc2 = new SingleFieldConstraint("size");
sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
sfc2.setFieldType(DataType.TYPE_NUMERIC_INTEGER);
sfc2.setOperator(">");
sfc2.setValue("$f3");
fp2.addConstraint(sfc2);
FromCollectCompositeFactPattern fac = new FromCollectCompositeFactPattern();
fac.setRightPattern(fp);
fac.setFactPattern(fp2);
m.addLhsItem(fac);
String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "java.util.List( size > 1 ) from collect ( Person( field1 == \"foo\" ) ) \n" + "then\n" + "end";
m.addRow(new String[] { "1", "foo", null });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testSimpleFromCollectMultipleSubPatternValuesSecondValue.
@Test
public void testSimpleFromCollectMultipleSubPatternValuesSecondValue() {
TemplateModel m = new TemplateModel();
m.name = "r1";
FactPattern fp = new FactPattern("Person");
SingleFieldConstraint sfc = new SingleFieldConstraint("field1");
sfc.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
sfc.setFieldType(DataType.TYPE_STRING);
sfc.setOperator("==");
sfc.setValue("$f1");
fp.addConstraint(sfc);
SingleFieldConstraint sfc1 = new SingleFieldConstraint("field2");
sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
sfc1.setFieldType(DataType.TYPE_STRING);
sfc1.setOperator("==");
sfc1.setValue("$f2");
fp.addConstraint(sfc1);
FactPattern fp2 = new FactPattern("java.util.List");
SingleFieldConstraint sfc2 = new SingleFieldConstraint("size");
sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
sfc2.setFieldType(DataType.TYPE_NUMERIC_INTEGER);
sfc2.setOperator(">");
sfc2.setValue("$f3");
fp2.addConstraint(sfc2);
FromCollectCompositeFactPattern fac = new FromCollectCompositeFactPattern();
fac.setRightPattern(fp);
fac.setFactPattern(fp2);
m.addLhsItem(fac);
String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "java.util.List( size > 1 ) from collect ( Person( field2 == \"bar\" ) ) \n" + "then\n" + "end";
m.addRow(new String[] { "1", null, "bar" });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testFromCollectFreeFormLineFirstValue.
@Test
public void testFromCollectFreeFormLineFirstValue() {
TemplateModel m = new TemplateModel();
m.name = "r1";
FreeFormLine ffl = new FreeFormLine();
ffl.setText("Person( field1 == \"@{f1}\", field2 == \"@{f2}\" )");
FactPattern fp = new FactPattern("java.util.List");
FromCollectCompositeFactPattern fac = new FromCollectCompositeFactPattern();
fac.setRightPattern(ffl);
fac.setFactPattern(fp);
m.addLhsItem(fac);
String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "then\n" + "end";
m.addRow(new String[] { "foo", null });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testSimpleFromCollect.
@Test
public void testSimpleFromCollect() {
TemplateModel m = new TemplateModel();
m.name = "r1";
FactPattern fp = new FactPattern("Person");
SingleFieldConstraint sfc = new SingleFieldConstraint("field1");
sfc.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
sfc.setFieldType(DataType.TYPE_STRING);
sfc.setOperator("==");
sfc.setValue("$f1");
fp.addConstraint(sfc);
FromCollectCompositeFactPattern fac = new FromCollectCompositeFactPattern();
fac.setRightPattern(fp);
fac.setFactPattern(new FactPattern("java.util.List"));
m.addLhsItem(fac);
String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "java.util.List( ) from collect ( Person( field1 == \"foo\" ) ) \n" + "then\n" + "end";
m.addRow(new String[] { "foo" });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testFromCollectWithEmbeddedFromEntryPoint.
@Test
public void testFromCollectWithEmbeddedFromEntryPoint() {
RuleModel m = new RuleModel();
m.name = "r1";
SingleFieldConstraint sfc = new SingleFieldConstraint("bar");
sfc.setFactType(DataType.TYPE_NUMERIC_INTEGER);
sfc.setFieldBinding("$a");
sfc.setOperator("==");
sfc.setValue("777");
FactPattern fp = new FactPattern("Foo");
fp.addConstraint(sfc);
FromEntryPointFactPattern fep = new FromEntryPointFactPattern();
fep.setEntryPointName("ep");
fep.setFactPattern(fp);
FromCollectCompositeFactPattern fac = new FromCollectCompositeFactPattern();
fac.setRightPattern(fep);
fac.setFactPattern(new FactPattern("java.util.List"));
m.addLhsItem(fac);
String expected = "rule \"r1\"\n" + "dialect \"mvel\"\n" + "when\n" + "java.util.List( ) from collect ( Foo( $a : bar == 777 ) from entry-point \"ep\" ) \n" + "then\n" + "end";
checkMarshalling(expected, m);
}
Aggregations