use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testSimpleFromCollectMultipleSubPatternValues.
@Test
public void testSimpleFromCollectMultipleSubPatternValues() {
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\", field2 == \"bar\" ) ) \n" + "then\n" + "end";
m.addRow(new String[] { "1", "foo", "bar" });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testNestedCompositeConstraintsAllValues.
@Test
public void testNestedCompositeConstraintsAllValues() {
TemplateModel m = new TemplateModel();
m.name = "t1";
FactPattern p = new FactPattern("Person");
CompositeFieldConstraint comp = new CompositeFieldConstraint();
comp.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
p.addConstraint(comp);
m.addLhsItem(p);
final SingleFieldConstraint sfc1 = new SingleFieldConstraint();
sfc1.setFieldName("field1");
sfc1.setFieldType(DataType.TYPE_STRING);
sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
sfc1.setValue("$f1");
sfc1.setOperator("==");
comp.addConstraint(sfc1);
CompositeFieldConstraint comp2 = new CompositeFieldConstraint();
comp2.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_AND);
final SingleFieldConstraint comp2sfc1 = new SingleFieldConstraint();
comp2sfc1.setFieldType(DataType.TYPE_STRING);
comp2sfc1.setFieldName("field2");
comp2sfc1.setOperator("==");
comp2sfc1.setValue("$f2");
comp2sfc1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_TEMPLATE);
comp2.addConstraint(comp2sfc1);
final SingleFieldConstraint comp2sfc2 = new SingleFieldConstraint();
comp2sfc2.setFieldType(DataType.TYPE_STRING);
comp2sfc2.setFieldName("field3");
comp2sfc2.setOperator("==");
comp2sfc2.setValue("$f3");
comp2sfc2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_TEMPLATE);
comp2.addConstraint(comp2sfc2);
comp.addConstraint(comp2);
String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( field1 == \"foo\" || ( field2 == \"bar\" && field3 == \"goo\" ) )\n" + "then\n" + "end\n";
m.addRow(new String[] { "foo", "bar", "goo" });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testActionInsertFactZeroValues.
@Test
public void testActionInsertFactZeroValues() {
TemplateModel m = new TemplateModel();
m.name = "r1";
FactPattern fp = new FactPattern("Person");
fp.setBoundName("$p");
m.addLhsItem(fp);
ActionInsertFact aif = new ActionInsertFact("Present");
aif.setBoundName("f0");
ActionFieldValue afv0 = new ActionFieldValue();
afv0.setNature(FieldNatureType.TYPE_TEMPLATE);
afv0.setField("field1");
afv0.setValue("$f1");
aif.addFieldValue(afv0);
ActionFieldValue afv1 = new ActionFieldValue();
afv1.setNature(FieldNatureType.TYPE_TEMPLATE);
afv1.setField("field2");
afv1.setValue("$f2");
aif.addFieldValue(afv1);
m.addRhsItem(aif);
String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "$p : Person()\n" + "then\n" + "Present f0 = new Present();\n" + "insert(f0);\n" + "end";
m.addRow(new String[] { null, null });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testInWithSimpleSingleLiteralValue.
@Test
public void testInWithSimpleSingleLiteralValue() {
TemplateModel m = new TemplateModel();
m.name = "t1";
FactPattern p = new FactPattern("Person");
SingleFieldConstraint con = new SingleFieldConstraint();
con.setFieldType(DataType.TYPE_STRING);
con.setFieldName("field1");
con.setOperator("in");
con.setValue("$f1");
con.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
p.addConstraint(con);
m.addLhsItem(p);
m.addRow(new String[] { "ak1,mk1" });
m.addRow(new String[] { "(ak2,mk2)" });
m.addRow(new String[] { "( ak3, mk3 )" });
m.addRow(new String[] { "( \"ak4\", \"mk4\" )" });
m.addRow(new String[] { "( \"ak5 \", \" mk5\" )" });
String expected = "rule \"t1_4\"" + "dialect \"mvel\"\n" + "when \n" + " Person( field1 in (\"ak5 \",\" mk5\") )" + "then \n" + "end" + "rule \"t1_3\"" + "dialect \"mvel\"\n" + "when \n" + " Person( field1 in (\"ak4\",\"mk4\") )" + "then \n" + "end" + "rule \"t1_2\"" + "dialect \"mvel\"\n" + "when \n" + " Person( field1 in (\"ak3\",\"mk3\") )" + "then \n" + "end" + "rule \"t1_1\"" + "dialect \"mvel\"\n" + "when \n" + " Person( field1 in (\"ak2\",\"mk2\") )" + "then \n" + "end" + "rule \"t1_0\"" + "dialect \"mvel\"\n" + "when \n" + " Person( field1 in (\"ak1\",\"mk1\") )" + "then \n" + "end";
checkMarshall(expected, m);
}
use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testNestedCompositeConstraints4ThirdValue.
@Test
public void testNestedCompositeConstraints4ThirdValue() {
TemplateModel m = new TemplateModel();
m.name = "t1";
FactPattern p = new FactPattern("Person");
m.addLhsItem(p);
CompositeFieldConstraint comp1 = new CompositeFieldConstraint();
comp1.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
final SingleFieldConstraint comp1sfc1 = new SingleFieldConstraint();
comp1sfc1.setFieldName("field1");
comp1sfc1.setFieldType(DataType.TYPE_STRING);
comp1sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
comp1sfc1.setValue("$f1");
comp1sfc1.setOperator("==");
comp1.addConstraint(comp1sfc1);
final SingleFieldConstraint comp1sfc2 = new SingleFieldConstraint();
comp1sfc2.setFieldName("field2");
comp1sfc2.setFieldType(DataType.TYPE_STRING);
comp1sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
comp1sfc2.setValue("$f2");
comp1sfc2.setOperator("==");
comp1.addConstraint(comp1sfc2);
p.addConstraint(comp1);
CompositeFieldConstraint comp2 = new CompositeFieldConstraint();
comp2.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
final SingleFieldConstraint comp2sfc1 = new SingleFieldConstraint();
comp2sfc1.setFieldType(DataType.TYPE_STRING);
comp2sfc1.setFieldName("field3");
comp2sfc1.setOperator("==");
comp2sfc1.setValue("$f3");
comp2sfc1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_TEMPLATE);
comp2.addConstraint(comp2sfc1);
final SingleFieldConstraint comp2sfc2 = new SingleFieldConstraint();
comp2sfc2.setFieldName("field4");
comp2sfc2.setFieldType(DataType.TYPE_STRING);
comp2sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
comp2sfc2.setValue("$f4");
comp2sfc2.setOperator("==");
comp2.addConstraint(comp2sfc2);
p.addConstraint(comp2);
String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( field3 == \"goo\" )\n" + "then\n" + "end\n";
m.addRow(new String[] { null, null, "goo", null });
checkMarshall(expected, m);
}
Aggregations