use of org.drools.workbench.models.datamodel.rule.SingleFieldConstraint in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testNestedCompositeConstraints6AllValues.
@Test
public void testNestedCompositeConstraints6AllValues() {
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_TEMPLATE);
cfc1sfc2.setValue("$f2");
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_TEMPLATE);
cfc2sfc2.setValue("$f4");
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_TEMPLATE);
cfc3sfc2.setValue("$f6");
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", "v2", "v3", "v4", "v5", "v6" });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.SingleFieldConstraint in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method checkLHSConstraintSeparatorWithTemplateKeyAndLiteral.
@Test
public void checkLHSConstraintSeparatorWithTemplateKeyAndLiteral() {
FactPattern fp = new FactPattern("Smurf");
fp.setBoundName("p1");
SingleFieldConstraint sfc1 = new SingleFieldConstraint();
sfc1.setOperator("==");
sfc1.setFactType("Smurf");
sfc1.setFieldName("field1");
sfc1.setFieldType(DataType.TYPE_STRING);
sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
sfc1.setValue("$f1");
SingleFieldConstraint sfc2 = new SingleFieldConstraint();
sfc2.setOperator("==");
sfc2.setFactType("Smurf");
sfc2.setFieldName("field1");
sfc2.setFieldType(DataType.TYPE_STRING);
sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
sfc2.setValue("$f2");
SingleFieldConstraint sfc3 = new SingleFieldConstraint();
sfc3.setOperator("==");
sfc3.setFactType("Smurf");
sfc3.setFieldName("field1");
sfc3.setFieldType(DataType.TYPE_STRING);
sfc3.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
sfc3.setValue("value");
fp.addConstraint(sfc1);
fp.addConstraint(sfc2);
fp.addConstraint(sfc3);
// Test 1
TemplateModel m1 = new TemplateModel();
m1.addLhsItem(fp);
m1.name = "r1";
m1.addRow(new String[] { null, null });
final String expected1 = "rule \"r1_0\"\n" + " dialect \"mvel\"\n" + " when\n" + " p1 : Smurf( field1 == \"value\" )\n" + " then\n" + "end";
checkMarshall(expected1, m1);
// Test 2
TemplateModel m2 = new TemplateModel();
m2.addLhsItem(fp);
m2.name = "r2";
m2.addRow(new String[] { "t1", "t2" });
final String expected2 = "rule \"r2_0\"\n" + " dialect \"mvel\"\n" + " when\n" + " p1 : Smurf( field1 == \"t1\", field1 == \"t2\", field1 == \"value\" )\n" + " then\n" + "end";
checkMarshall(expected2, m2);
// Test 3
TemplateModel m3 = new TemplateModel();
m3.addLhsItem(fp);
m3.name = "r3";
m3.addRow(new String[] { "t1", null });
final String expected3 = "rule \"r3_0\"\n" + " dialect \"mvel\"\n" + " when\n" + " p1 : Smurf( field1 == \"t1\", field1 == \"value\" )\n" + " then\n" + "end";
checkMarshall(expected3, m3);
// Test 4
TemplateModel m4 = new TemplateModel();
m4.addLhsItem(fp);
m4.name = "r4";
m4.addRow(new String[] { null, "t2" });
final String expected4 = "rule \"r4_0\"\n" + " dialect \"mvel\"\n" + " when\n" + " p1 : Smurf( field1 == \"t2\", field1 == \"value\" )\n" + " then\n" + "end";
checkMarshall(expected4, m4);
}
use of org.drools.workbench.models.datamodel.rule.SingleFieldConstraint in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testNestedCompositeConstraints4AllValues.
@Test
public void testNestedCompositeConstraints4AllValues() {
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( field1 == \"foo\" || field2== \"bar\", field3 == \"goo\" || field4 == \"boo\" )\n" + "then\n" + "end\n";
m.addRow(new String[] { "foo", "bar", "goo", "boo" });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.SingleFieldConstraint in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testSimpleSingleTemplateValueSingleLiteralValue.
@Test
public void testSimpleSingleTemplateValueSingleLiteralValue() {
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("bar");
con2.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
p.addConstraint(con2);
m.addLhsItem(p);
m.addRow(new String[] { "foo" });
String expected = "rule \"t1_0\"" + "dialect \"mvel\"\n" + "when \n" + "Person( field1 == \"foo\", field2 == \"bar\" )" + "then \n" + "end";
checkMarshall(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.SingleFieldConstraint in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testConnectiveConstraintFirstValue.
@Test
public void testConnectiveConstraintFirstValue() {
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\" )\n" + "then\n" + "end\n";
m.addRow(new String[] { "foo", null });
checkMarshall(expected, m);
}
Aggregations