use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testNestedCompositeConstraints6LiteralsAndVariablesWithValues.
@Test
public void testNestedCompositeConstraints6LiteralsAndVariablesWithValues() {
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_LITERAL);
cfc1sfc1.setValue("v1");
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_LITERAL);
cfc2sfc1.setValue("v3");
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_LITERAL);
cfc3sfc1.setValue("v5");
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[] { "v2", "v4", "v6" });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testNestedCompositeConstraints5SecondValue.
@Test
public void testNestedCompositeConstraints5SecondValue() {
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 comp1sfc1 = new SingleFieldConstraint();
comp1sfc1.setFieldName("field1");
comp1sfc1.setFieldType(DataType.TYPE_STRING);
comp1sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
comp1sfc1.setValue("$f1");
comp1sfc1.setOperator("==");
comp.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("==");
comp.addConstraint(comp1sfc2);
final SingleFieldConstraint comp1sfc3 = new SingleFieldConstraint();
comp1sfc3.setFieldName("field3");
comp1sfc3.setFieldType(DataType.TYPE_STRING);
comp1sfc3.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
comp1sfc3.setValue("$f3");
comp1sfc3.setOperator("==");
comp.addConstraint(comp1sfc3);
String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( field2 == \"bar\" )\n" + "then\n" + "end\n";
m.addRow(new String[] { null, "bar", null });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelXMLPersistenceTest method testRoundTrip.
@Test
public void testRoundTrip() {
final TemplateModel m = getComplexModel();
final String xml = RuleTemplateModelXMLPersistenceImpl.getInstance().marshal(m);
final TemplateModel m2 = RuleTemplateModelXMLPersistenceImpl.getInstance().unmarshal(xml);
assertNotNull(m2);
assertEquals(m.name, m2.name);
assertEquals(m.lhs.length, m2.lhs.length);
assertEquals(m.rhs.length, m2.rhs.length);
assertEquals(1, m.attributes.length);
final RuleAttribute at = m.attributes[0];
assertEquals("no-loop", at.getAttributeName());
assertEquals("true", at.getValue());
final String newXML = RuleTemplateModelXMLPersistenceImpl.getInstance().marshal(m2);
assertEquals(xml, newXML);
}
use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelXMLPersistenceTest method testGenerateEmptyXML.
@Test
public void testGenerateEmptyXML() {
final RuleTemplateModelPersistence p = RuleTemplateModelXMLPersistenceImpl.getInstance();
final String xml = p.marshal(new TemplateModel());
assertNotNull(xml);
assertFalse(xml.equals(""));
assertTrue(xml.startsWith("<rule>"));
assertTrue(xml.endsWith("</rule>"));
}
use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelXMLPersistenceTest method getComplexModel.
private TemplateModel getComplexModel() {
final TemplateModel m = new TemplateModel();
m.addAttribute(new RuleAttribute("no-loop", "true"));
final FactPattern pat = new FactPattern("Person");
pat.setBoundName("p1");
final SingleFieldConstraint con = new SingleFieldConstraint();
con.setFactType("Person");
con.setFieldBinding("f1");
con.setFieldName("age");
con.setOperator("<");
con.setValue("42");
pat.addConstraint(con);
m.addLhsItem(pat);
final CompositeFactPattern comp = new CompositeFactPattern("not");
comp.addFactPattern(new FactPattern("Cancel"));
m.addLhsItem(comp);
final ActionUpdateField set = new ActionUpdateField();
set.setVariable("p1");
set.addFieldValue(new ActionFieldValue("status", "rejected", DataType.TYPE_STRING));
m.addRhsItem(set);
final ActionRetractFact ret = new ActionRetractFact("p1");
m.addRhsItem(ret);
final DSLSentence sen = new DSLSentence();
sen.setDefinition("Send an email to {administrator}");
m.addRhsItem(sen);
return m;
}
Aggregations