use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testNestedCompositeConstraints3FirstValue.
@Test
public void testNestedCompositeConstraints3FirstValue() {
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);
final SingleFieldConstraint sfc2 = new SingleFieldConstraint();
sfc2.setFieldName("field2");
sfc2.setFieldType(DataType.TYPE_STRING);
sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
sfc2.setValue("$f2");
sfc2.setOperator("==");
comp.addConstraint(sfc2);
CompositeFieldConstraint comp2 = new CompositeFieldConstraint();
comp2.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_AND);
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);
comp.addConstraint(comp2);
String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( field1 == \"foo\" )\n" + "then\n" + "end\n";
m.addRow(new String[] { "foo", null, null });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testActionModifyTwoFieldsFirstLiteralSecondTemplate1.
@Test
public void testActionModifyTwoFieldsFirstLiteralSecondTemplate1() {
TemplateModel m = new TemplateModel();
m.name = "r1";
FactPattern fp = new FactPattern("Person");
fp.setBoundName("$p");
m.addLhsItem(fp);
ActionUpdateField auf1 = new ActionUpdateField("$p");
ActionFieldValue afv0 = new ActionFieldValue();
afv0.setNature(FieldNatureType.TYPE_LITERAL);
afv0.setField("field1");
afv0.setValue("foo");
auf1.addFieldValue(afv0);
ActionFieldValue afv1 = new ActionFieldValue();
afv1.setNature(FieldNatureType.TYPE_TEMPLATE);
afv1.setField("field2");
afv1.setValue("$f2");
auf1.addFieldValue(afv1);
m.addRhsItem(auf1);
String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + " $p : Person()\n" + "then\n" + " modify( $p ) {\n" + " setField1(\"foo\"),\n" + " setField2(\"bar\")\n" + " }\n" + "end";
m.addRow(new String[] { "bar" });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testCompositeFactPatternFirstValue.
@Test
public void testCompositeFactPatternFirstValue() {
TemplateModel m = new TemplateModel();
m.name = "t1";
CompositeFactPattern cp = new CompositeFactPattern(CompositeFactPattern.COMPOSITE_TYPE_OR);
FactPattern p1 = new FactPattern("Person");
SingleFieldConstraint sfc1 = new SingleFieldConstraint();
sfc1.setFieldName("field1");
sfc1.setFieldType(DataType.TYPE_STRING);
sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
sfc1.setValue("$f1");
sfc1.setOperator("==");
p1.addConstraint(sfc1);
FactPattern p2 = new FactPattern("Person");
SingleFieldConstraint sfc2 = new SingleFieldConstraint();
sfc2.setFieldName("field2");
sfc2.setFieldType(DataType.TYPE_STRING);
sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
sfc2.setValue("$f2");
sfc2.setOperator("==");
p2.addConstraint(sfc2);
cp.addFactPattern(p1);
cp.addFactPattern(p2);
m.addLhsItem(cp);
String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "(\n" + "Person( field1 == \"foo\" )\n" + "or\n" + "Person( )\n" + ")\n" + "then\n" + "end\n";
m.addRow(new String[] { "foo", null });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testGeneratorFactoryReuse.
@Test
public void testGeneratorFactoryReuse() {
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("==");
con.setValue("$f1");
con.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
p.addConstraint(con);
SingleFieldConstraint con2 = new SingleFieldConstraint();
con.setFieldType(DataType.TYPE_STRING);
con2.setFieldName("field2");
con2.setOperator("==");
con2.setValue("$f2");
con2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
p.addConstraint(con2);
m.addLhsItem(p);
m.addRow(new String[] { "foo", "bar" });
String expected = "rule \"t1_0\"" + "dialect \"mvel\"\n" + "when \n" + "Person( field1 == \"foo\", field2 == \"bar\" )" + "then \n" + "end";
checkMarshall(expected, m);
checkMarshall(expected, m);
}
use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testActionFreeFormLineFirstValue.
@Test
public void testActionFreeFormLineFirstValue() {
TemplateModel m = new TemplateModel();
m.name = "r1";
FreeFormLine ffl = new FreeFormLine();
ffl.setText("System.println( \"@{f1}\" + \"@{f2}\" );");
m.addRhsItem(ffl);
String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "then\n" + "end";
m.addRow(new String[] { "foo", null });
checkMarshall(expected, m);
}
Aggregations