use of org.drools.workbench.models.datamodel.rule.SingleFieldConstraint in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testCompositeFactPatternSecondValue.
@Test
public void testCompositeFactPatternSecondValue() {
TemplateModel m = new TemplateModel();
m.name = "t1";
CompositeFactPattern cp = new CompositeFactPattern(CompositeFactPattern.COMPOSITE_TYPE_OR);
FactPattern p1 = new FactPattern("Person");
SingleFieldConstraint sfc1 = new SingleFieldConstraint();
sfc1.setFieldName("field1");
sfc1.setFieldType(DataType.TYPE_STRING);
sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
sfc1.setValue("$f1");
sfc1.setOperator("==");
p1.addConstraint(sfc1);
FactPattern p2 = new FactPattern("Person");
SingleFieldConstraint sfc2 = new SingleFieldConstraint();
sfc2.setFieldName("field2");
sfc2.setFieldType(DataType.TYPE_STRING);
sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
sfc2.setValue("$f2");
sfc2.setOperator("==");
p2.addConstraint(sfc2);
cp.addFactPattern(p1);
cp.addFactPattern(p2);
m.addLhsItem(cp);
String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "(\n" + "Person( )\n" + "or\n" + "Person( field2 == \"bar\" )\n" + ")\n" + "then\n" + "end\n";
m.addRow(new String[] { null, "bar" });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.SingleFieldConstraint in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testConnectiveConstraintSecondValue.
@Test
public void testConnectiveConstraintSecondValue() {
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 == \"bar\" )\n" + "then\n" + "end\n";
m.addRow(new String[] { null, "bar" });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.SingleFieldConstraint in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testSimpleFromCollectMultipleSubPatternValues.
@Test
public void testSimpleFromCollectMultipleSubPatternValues() {
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( field1 == \"foo\", field2 == \"bar\" ) ) \n" + "then\n" + "end";
m.addRow(new String[] { "1", "foo", "bar" });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.SingleFieldConstraint in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testNestedCompositeConstraintsAllValues.
@Test
public void testNestedCompositeConstraintsAllValues() {
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);
CompositeFieldConstraint comp2 = new CompositeFieldConstraint();
comp2.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_AND);
final SingleFieldConstraint comp2sfc1 = new SingleFieldConstraint();
comp2sfc1.setFieldType(DataType.TYPE_STRING);
comp2sfc1.setFieldName("field2");
comp2sfc1.setOperator("==");
comp2sfc1.setValue("$f2");
comp2sfc1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_TEMPLATE);
comp2.addConstraint(comp2sfc1);
final SingleFieldConstraint comp2sfc2 = new SingleFieldConstraint();
comp2sfc2.setFieldType(DataType.TYPE_STRING);
comp2sfc2.setFieldName("field3");
comp2sfc2.setOperator("==");
comp2sfc2.setValue("$f3");
comp2sfc2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_TEMPLATE);
comp2.addConstraint(comp2sfc2);
comp.addConstraint(comp2);
String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( field1 == \"foo\" || ( field2 == \"bar\" && field3 == \"goo\" ) )\n" + "then\n" + "end\n";
m.addRow(new String[] { "foo", "bar", "goo" });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.SingleFieldConstraint in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testInWithSimpleSingleLiteralValue.
@Test
public void testInWithSimpleSingleLiteralValue() {
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("in");
con.setValue("$f1");
con.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
p.addConstraint(con);
m.addLhsItem(p);
m.addRow(new String[] { "ak1,mk1" });
m.addRow(new String[] { "(ak2,mk2)" });
m.addRow(new String[] { "( ak3, mk3 )" });
m.addRow(new String[] { "( \"ak4\", \"mk4\" )" });
m.addRow(new String[] { "( \"ak5 \", \" mk5\" )" });
String expected = "rule \"t1_4\"" + "dialect \"mvel\"\n" + "when \n" + " Person( field1 in (\"ak5 \",\" mk5\") )" + "then \n" + "end" + "rule \"t1_3\"" + "dialect \"mvel\"\n" + "when \n" + " Person( field1 in (\"ak4\",\"mk4\") )" + "then \n" + "end" + "rule \"t1_2\"" + "dialect \"mvel\"\n" + "when \n" + " Person( field1 in (\"ak3\",\"mk3\") )" + "then \n" + "end" + "rule \"t1_1\"" + "dialect \"mvel\"\n" + "when \n" + " Person( field1 in (\"ak2\",\"mk2\") )" + "then \n" + "end" + "rule \"t1_0\"" + "dialect \"mvel\"\n" + "when \n" + " Person( field1 in (\"ak1\",\"mk1\") )" + "then \n" + "end";
checkMarshall(expected, m);
}
Aggregations