use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testSimpleFromCollectMultipleSubPatternValuesSecondValue.
@Test
public void testSimpleFromCollectMultipleSubPatternValuesSecondValue() {
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( field2 == \"bar\" ) ) \n" + "then\n" + "end";
m.addRow(new String[] { "1", null, "bar" });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.guided.template.shared.TemplateModel 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);
}
use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testActionInsertFactBothValues.
@Test
public void testActionInsertFactBothValues() {
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" + "f0.setField2(\"bar\");\n" + "insert(f0);\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 testNestedCompositeConstraints6VariablesNoValuesAndLiterals.
@Test
public void testNestedCompositeConstraints6VariablesNoValuesAndLiterals() {
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( field2 == \"v2\", field4 == \"v4\", field6 == \"v6\" )\n" + "then\n" + "end\n";
m.addRow(new String[] { null, null, null });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testSimpleSingleValue.
@Test
public void testSimpleSingleValue() {
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);
m.addLhsItem(p);
m.addRow(new String[] { "foo" });
String expected = "rule \"t1_0\"" + "dialect \"mvel\"\n" + "when \n" + "Person( field1 == \"foo\" )" + "then \n" + "end";
checkMarshall(expected, m);
}
Aggregations