use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testNestedCompositeConstraints6VariablesAndLiterals.
@Test
public void testNestedCompositeConstraints6VariablesAndLiterals() {
TemplateModel m = new TemplateModel();
m.name = "t1";
FactPattern p = new FactPattern("Person");
m.addLhsItem(p);
final CompositeFieldConstraint cfc1 = new CompositeFieldConstraint();
cfc1.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
p.addConstraint(cfc1);
final SingleFieldConstraint cfc1sfc1 = new SingleFieldConstraint();
cfc1sfc1.setFieldName("field1");
cfc1sfc1.setFieldType(DataType.TYPE_STRING);
cfc1sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
cfc1sfc1.setValue("$f1");
cfc1sfc1.setOperator("==");
cfc1.addConstraint(cfc1sfc1);
final SingleFieldConstraint cfc1sfc2 = new SingleFieldConstraint();
cfc1sfc2.setFieldName("field2");
cfc1sfc2.setFieldType(DataType.TYPE_STRING);
cfc1sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
cfc1sfc2.setValue("v2");
cfc1sfc2.setOperator("==");
cfc1.addConstraint(cfc1sfc2);
final CompositeFieldConstraint cfc2 = new CompositeFieldConstraint();
cfc2.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
p.addConstraint(cfc2);
final SingleFieldConstraint cfc2sfc1 = new SingleFieldConstraint();
cfc2sfc1.setFieldName("field3");
cfc2sfc1.setFieldType(DataType.TYPE_STRING);
cfc2sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
cfc2sfc1.setValue("$f3");
cfc2sfc1.setOperator("==");
cfc2.addConstraint(cfc2sfc1);
final SingleFieldConstraint cfc2sfc2 = new SingleFieldConstraint();
cfc2sfc2.setFieldName("field4");
cfc2sfc2.setFieldType(DataType.TYPE_STRING);
cfc2sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
cfc2sfc2.setValue("v4");
cfc2sfc2.setOperator("==");
cfc2.addConstraint(cfc2sfc2);
final CompositeFieldConstraint cfc3 = new CompositeFieldConstraint();
cfc3.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
p.addConstraint(cfc3);
final SingleFieldConstraint cfc3sfc1 = new SingleFieldConstraint();
cfc3sfc1.setFieldName("field5");
cfc3sfc1.setFieldType(DataType.TYPE_STRING);
cfc3sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
cfc3sfc1.setValue("$f5");
cfc3sfc1.setOperator("==");
cfc3.addConstraint(cfc3sfc1);
final SingleFieldConstraint cfc3sfc2 = new SingleFieldConstraint();
cfc3sfc2.setFieldName("field6");
cfc3sfc2.setFieldType(DataType.TYPE_STRING);
cfc3sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
cfc3sfc2.setValue("v6");
cfc3sfc2.setOperator("==");
cfc3.addConstraint(cfc3sfc2);
String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( field1 == \"v1\" || field2 == \"v2\", field3 == \"v3\" || field4 == \"v4\", field5 == \"v5\" || field6 == \"v6\" )\n" + "then\n" + "end\n";
m.addRow(new String[] { "v1", "v3", "v5" });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testUpdateModifyMultipleFieldsWithMultipleSkipped4.
@Test
public void testUpdateModifyMultipleFieldsWithMultipleSkipped4() {
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_TEMPLATE);
afv0.setField("field1");
afv0.setValue("$f1");
auf1.addFieldValue(afv0);
ActionFieldValue afv1 = new ActionFieldValue();
afv1.setNature(FieldNatureType.TYPE_TEMPLATE);
afv1.setField("field2");
afv1.setValue("$f2");
auf1.addFieldValue(afv1);
ActionFieldValue afv2 = new ActionFieldValue();
afv2.setNature(FieldNatureType.TYPE_TEMPLATE);
afv2.setField("field3");
afv2.setValue("$f3");
auf1.addFieldValue(afv2);
m.addRhsItem(auf1);
String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + " $p : Person()\n" + "then\n" + " modify( $p ) {\n" + " setField1(\"v1\"),\n" + " setField3(\"v3\")\n" + " }\n" + "end";
m.addRow(new String[] { "v1", null, "v3" });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testFreeFormLineSecondValue.
@Test
public void testFreeFormLineSecondValue() {
TemplateModel m = new TemplateModel();
m.name = "r1";
FreeFormLine ffl = new FreeFormLine();
ffl.setText("Person( field1 == \"@{f1}\", field2 == \"@{f2}\" )");
m.addLhsItem(ffl);
String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "then\n" + "end";
m.addRow(new String[] { null, "bar" });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testSimpleFirstValue.
@Test
public void testSimpleFirstValue() {
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", null });
String expected = "rule \"t1_0\"" + "dialect \"mvel\"\n" + "when \n" + "Person( field1 == \"foo\" )" + "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 testActionFreeFormLineBothValues.
@Test
public void testActionFreeFormLineBothValues() {
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" + "System.println( \"foo\" + \"bar\" );" + "end";
m.addRow(new String[] { "foo", "bar" });
checkMarshall(expected, m);
}
Aggregations