use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testActionUpdateFactBothValues.
@Test
public void testActionUpdateFactBothValues() {
TemplateModel m = new TemplateModel();
m.name = "r1";
FactPattern fp = new FactPattern("Person");
fp.setBoundName("$p");
m.addLhsItem(fp);
ActionSetField asf = new ActionSetField("$p");
ActionFieldValue afv0 = new ActionFieldValue();
afv0.setNature(FieldNatureType.TYPE_TEMPLATE);
afv0.setField("field1");
afv0.setValue("$f1");
asf.addFieldValue(afv0);
ActionFieldValue afv1 = new ActionFieldValue();
afv1.setNature(FieldNatureType.TYPE_TEMPLATE);
afv1.setField("field2");
afv1.setValue("$f2");
asf.addFieldValue(afv1);
m.addRhsItem(asf);
String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "$p : Person()\n" + "then\n" + "$p.setField1(\"foo\");\n" + "$p.setField2(\"bar\");\n" + "end";
m.addRow(new String[] { "foo", "bar" });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testActionInsertFactSecondValue.
@Test
public void testActionInsertFactSecondValue() {
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.setField2(\"bar\");\n" + "insert(f0);\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 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.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testCompositeConstraintWithConnectiveConstraintFirstValue.
@Test
public void testCompositeConstraintWithConnectiveConstraintFirstValue() {
TemplateModel m = new TemplateModel();
m.name = "t1";
FactPattern p1 = new FactPattern("Person");
m.addLhsItem(p1);
CompositeFieldConstraint comp = new CompositeFieldConstraint();
comp.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
p1.addConstraint(comp);
final SingleFieldConstraint X = new SingleFieldConstraint();
X.setFieldName("field1");
X.setFieldType(DataType.TYPE_STRING);
X.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
X.setValue("$f1");
X.setOperator("==");
comp.addConstraint(X);
ConnectiveConstraint connective = new ConnectiveConstraint();
connective.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
connective.setFieldType(DataType.TYPE_STRING);
connective.setOperator("|| ==");
connective.setValue("goo");
X.setConnectives(new ConnectiveConstraint[1]);
X.getConnectives()[0] = connective;
final SingleFieldConstraint Y = new SingleFieldConstraint();
Y.setFieldName("field2");
Y.setFieldType(DataType.TYPE_STRING);
Y.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
Y.setValue("$f2");
Y.setOperator("==");
comp.addConstraint(Y);
String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( field1 == \"foo\" || == \"goo\" )\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 testActionUpdateFactZeroValues.
@Test
public void testActionUpdateFactZeroValues() {
TemplateModel m = new TemplateModel();
m.name = "r1";
FactPattern fp = new FactPattern("Person");
fp.setBoundName("$p");
m.addLhsItem(fp);
ActionSetField asf = new ActionSetField("$p");
ActionFieldValue afv0 = new ActionFieldValue();
afv0.setNature(FieldNatureType.TYPE_TEMPLATE);
afv0.setField("field1");
afv0.setValue("$f1");
asf.addFieldValue(afv0);
ActionFieldValue afv1 = new ActionFieldValue();
afv1.setNature(FieldNatureType.TYPE_TEMPLATE);
afv1.setField("field2");
afv1.setValue("$f2");
asf.addFieldValue(afv1);
m.addRhsItem(asf);
String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "$p : Person()\n" + "then\n" + "end";
m.addRow(new String[] { null, null });
checkMarshall(expected, m);
}
Aggregations