use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testNestedCompositeConstraints3ThirdValue.
@Test
public void testNestedCompositeConstraints3ThirdValue() {
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( ( field3 == \"goo\" ) )\n" + "then\n" + "end\n";
m.addRow(new String[] { null, null, "goo" });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testEmptyFreeForm.
@Test
public void testEmptyFreeForm() {
// https://bugzilla.redhat.com/show_bug.cgi?id=1058247
TemplateModel m = new TemplateModel();
m.name = "Empty FreeFormLine";
FreeFormLine fl = new FreeFormLine();
m.addLhsItem(fl);
FactPattern fp = new FactPattern("Person");
fp.setBoundName("$p");
SingleFieldConstraint sfc1 = new SingleFieldConstraint();
sfc1.setFieldName("field1");
sfc1.setFieldType(DataType.TYPE_STRING);
sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
sfc1.setValue("$f1");
sfc1.setOperator("==");
fp.addConstraint(sfc1);
m.addLhsItem(fp);
FreeFormLine fr = new FreeFormLine();
m.addRhsItem(fr);
ActionSetField asf = new ActionSetField("$p");
ActionFieldValue afv0 = new ActionFieldValue();
afv0.setNature(FieldNatureType.TYPE_TEMPLATE);
afv0.setType(DataType.TYPE_STRING);
afv0.setField("field1");
afv0.setValue("$asf1");
asf.addFieldValue(afv0);
m.addRhsItem(asf);
String expected = "rule \"Empty FreeFormLine_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "$p : Person( field1 == \"foo\" )\n" + "then\n" + "$p.setField1(\"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 testSimpleSecondValue.
@Test
public void testSimpleSecondValue() {
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[] { null, "bar" });
String expected = "rule \"t1_0\"" + "dialect \"mvel\"\n" + "when \n" + "Person( field2 == \"bar\" )" + "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 testConnectiveConstraintBothValues.
@Test
public void testConnectiveConstraintBothValues() {
TemplateModel m = new TemplateModel();
m.name = "t1";
FactPattern p1 = new FactPattern("Person");
m.addLhsItem(p1);
final SingleFieldConstraint X = new SingleFieldConstraint();
X.setFieldName("field1");
X.setFieldType(DataType.TYPE_STRING);
X.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
X.setValue("$f1");
X.setOperator("==");
p1.addConstraint(X);
ConnectiveConstraint connective = new ConnectiveConstraint();
connective.setConstraintValueType(BaseSingleFieldConstraint.TYPE_TEMPLATE);
connective.setFieldType(DataType.TYPE_STRING);
connective.setOperator("|| ==");
connective.setValue("$f2");
X.setConnectives(new ConnectiveConstraint[1]);
X.getConnectives()[0] = connective;
String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( field1 == \"foo\" || == \"bar\" )\n" + "then\n" + "end\n";
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 testNestedCompositeConstraints4FourthValue.
@Test
public void testNestedCompositeConstraints4FourthValue() {
TemplateModel m = new TemplateModel();
m.name = "t1";
FactPattern p = new FactPattern("Person");
m.addLhsItem(p);
CompositeFieldConstraint comp1 = new CompositeFieldConstraint();
comp1.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
final SingleFieldConstraint comp1sfc1 = new SingleFieldConstraint();
comp1sfc1.setFieldName("field1");
comp1sfc1.setFieldType(DataType.TYPE_STRING);
comp1sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
comp1sfc1.setValue("$f1");
comp1sfc1.setOperator("==");
comp1.addConstraint(comp1sfc1);
final SingleFieldConstraint comp1sfc2 = new SingleFieldConstraint();
comp1sfc2.setFieldName("field2");
comp1sfc2.setFieldType(DataType.TYPE_STRING);
comp1sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
comp1sfc2.setValue("$f2");
comp1sfc2.setOperator("==");
comp1.addConstraint(comp1sfc2);
p.addConstraint(comp1);
CompositeFieldConstraint comp2 = new CompositeFieldConstraint();
comp2.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
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);
final SingleFieldConstraint comp2sfc2 = new SingleFieldConstraint();
comp2sfc2.setFieldName("field4");
comp2sfc2.setFieldType(DataType.TYPE_STRING);
comp2sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
comp2sfc2.setValue("$f4");
comp2sfc2.setOperator("==");
comp2.addConstraint(comp2sfc2);
p.addConstraint(comp2);
String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( field4 == \"boo\" )\n" + "then\n" + "end\n";
m.addRow(new String[] { null, null, null, "boo" });
checkMarshall(expected, m);
}
Aggregations