use of org.drools.workbench.models.datamodel.rule.ActionFieldValue in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testUpdateModifyMultipleFieldsWithMultipleSkipped2.
@Test
public void testUpdateModifyMultipleFieldsWithMultipleSkipped2() {
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" + " setField2(\"v2\"),\n" + " setField3(\"v3\")\n" + " }\n" + "end";
m.addRow(new String[] { null, "v2", "v3" });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.ActionFieldValue in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testRHSDelimitedNonEmptyStringValues.
@Test
public void testRHSDelimitedNonEmptyStringValues() {
FactPattern fp = new FactPattern("Smurf");
fp.setBoundName("p1");
ActionUpdateField auf1 = new ActionUpdateField("p1");
auf1.addFieldValue(new ActionFieldValue("name", "$name", DataType.TYPE_STRING));
auf1.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
ActionUpdateField auf2 = new ActionUpdateField("p1");
auf2.addFieldValue(new ActionFieldValue("age", "$age", DataType.TYPE_NUMERIC_INTEGER));
auf2.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
// Test 1
TemplateModel m1 = new TemplateModel();
m1.addLhsItem(fp);
m1.addRhsItem(auf1);
m1.addRhsItem(auf2);
m1.name = "r1";
m1.addRow(new String[] { null, null });
final String expected1 = "rule \"r1_0\"\n" + " dialect \"mvel\"\n" + " when\n" + " p1 : Smurf()\n" + " then\n" + "end";
checkMarshall(expected1, m1);
// Test 2
TemplateModel m2 = new TemplateModel();
m2.addLhsItem(fp);
m2.addRhsItem(auf1);
m2.addRhsItem(auf2);
m2.name = "r2";
m2.addRow(new String[] { "\" \"", "35" });
final String expected2 = "rule \"r2_0\"\n" + " dialect \"mvel\"\n" + " when\n" + " p1 : Smurf()\n" + " then\n" + " modify( p1 ) {\n" + " setName( \" \" ),\n" + " setAge( 35 )\n" + " }\n" + "end";
checkMarshall(expected2, m2);
// Test 3
TemplateModel m3 = new TemplateModel();
m3.addLhsItem(fp);
m3.addRhsItem(auf1);
m3.addRhsItem(auf2);
m3.name = "r3";
m3.addRow(new String[] { "\"\"", null });
final String expected3 = "rule \"r3_0\"\n" + " dialect \"mvel\"\n" + " when\n" + " p1 : Smurf()\n" + " then\n" + " modify( p1 ) {\n" + " setName( \"\" )\n" + " }\n" + "end";
checkMarshall(expected3, m3);
// Test 4
TemplateModel m4 = new TemplateModel();
m4.addLhsItem(fp);
m4.addRhsItem(auf1);
m4.addRhsItem(auf2);
m4.name = "r4";
m4.addRow(new String[] { "\"\"", "35" });
final String expected4 = "rule \"r4_0\"\n" + " dialect \"mvel\"\n" + " when\n" + " p1 : Smurf()\n" + " then\n" + " modify( p1 ) {\n" + " setName( \"\" ),\n" + " setAge( 35 )\n" + " }\n" + "end";
checkMarshall(expected4, m4);
}
use of org.drools.workbench.models.datamodel.rule.ActionFieldValue in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testActionModifyTwoFieldsFirstTemplateSecondLiteral1.
@Test
public void testActionModifyTwoFieldsFirstTemplateSecondLiteral1() {
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_LITERAL);
afv1.setField("field2");
afv1.setValue("bar");
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[] { "foo" });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.ActionFieldValue in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testActionInsertFactFirstValue.
@Test
public void testActionInsertFactFirstValue() {
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" + "f0.setField1(\"foo\");\n" + "insert(f0);\n" + "end";
m.addRow(new String[] { "foo", null });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.ActionFieldValue in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testActionModifyTwoFieldsFirstTemplateSecondTemplate1.
@Test
public void testActionModifyTwoFieldsFirstTemplateSecondTemplate1() {
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);
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[] { "foo", "bar" });
checkMarshall(expected, m);
}
Aggregations