use of org.drools.workbench.models.guided.dtable.shared.model.Pattern52 in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method testLHSNotInOperator.
@Test
public void testLHSNotInOperator() {
GuidedDecisionTable52 dt = new GuidedDecisionTable52();
dt.setTableFormat(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY);
dt.setTableName("extended-entry");
Pattern52 p1 = new Pattern52();
p1.setBoundName("p1");
p1.setFactType("Smurf");
dt.getConditions().add(p1);
ConditionCol52 cc1 = new ConditionCol52();
cc1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
cc1.setFieldType(DataType.TYPE_STRING);
cc1.setFactField("name");
cc1.setOperator("not in");
p1.getChildColumns().add(cc1);
ConditionCol52 cc2 = new ConditionCol52();
cc2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
cc2.setFieldType(DataType.TYPE_NUMERIC_INTEGER);
cc2.setFactField("age");
cc2.setOperator("not in");
p1.getChildColumns().add(cc2);
dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { 1l, "desc", "Pupa, Brains", "55, 66" }, new Object[] { 2l, "desc", "", "" } }));
GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
String drl = p.marshal(dt);
int index = -1;
index = drl.indexOf("Smurf( name not in ( \"Pupa\", \"Brains\" ) , age not in ( 55, 66 ) )");
assertTrue(index > -1);
index = drl.indexOf("Smurf( )", index + 1);
assertFalse(index > -1);
}
use of org.drools.workbench.models.guided.dtable.shared.model.Pattern52 in project drools by kiegroup.
the class BRLRuleModelTest method testRuleModelWithRHSBoundFactsUsageWithBRLActionColumn.
@Test
public void testRuleModelWithRHSBoundFactsUsageWithBRLActionColumn() {
final GuidedDecisionTable52 dt = new GuidedDecisionTable52();
// Setup Decision Table columns
final Pattern52 p1 = new Pattern52();
p1.setFactType("Driver");
p1.setBoundName("$d");
dt.getConditions().add(p1);
final BRLActionColumn brl = new BRLActionColumn();
brl.setDefinition(Collections.singletonList(new ActionSetField() {
{
setVariable("$d");
}
}));
dt.getActionCols().add(brl);
final BRLRuleModel model = new BRLRuleModel(dt);
// Checks
assertTrue(model.isBoundFactUsed("$d"));
assertFalse(model.isBoundFactUsed("$cheese"));
}
use of org.drools.workbench.models.guided.dtable.shared.model.Pattern52 in project drools by kiegroup.
the class BRLRuleModelTest method testUpdateModifyMultipleFieldsWithMultipleSkipped2.
@Test
public void testUpdateModifyMultipleFieldsWithMultipleSkipped2() {
GuidedDecisionTable52 dt = new GuidedDecisionTable52();
Pattern52 p1 = new Pattern52();
p1.setBoundName("x");
p1.setFactType("Context");
ConditionCol52 c = new ConditionCol52();
c.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
p1.getChildColumns().add(c);
dt.getConditions().add(p1);
BRLActionColumn brlAction1 = new BRLActionColumn();
ActionUpdateField auf1 = new ActionUpdateField("x");
auf1.addFieldValue(new ActionFieldValue("f1", "$f1", DataType.TYPE_STRING));
auf1.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
brlAction1.getDefinition().add(auf1);
brlAction1.getChildColumns().add(new BRLActionVariableColumn("$f1", DataType.TYPE_STRING, "Context", "f1"));
ActionUpdateField auf2 = new ActionUpdateField("x");
auf2.addFieldValue(new ActionFieldValue("f2", "$f2", DataType.TYPE_STRING));
auf2.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
brlAction1.getDefinition().add(auf2);
brlAction1.getChildColumns().add(new BRLActionVariableColumn("$f2", DataType.TYPE_STRING, "Context", "f2"));
ActionUpdateField auf3 = new ActionUpdateField("x");
auf3.addFieldValue(new ActionFieldValue("f3", "$f3", DataType.TYPE_STRING));
auf3.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
brlAction1.getDefinition().add(auf3);
brlAction1.getChildColumns().add(new BRLActionVariableColumn("$f3", DataType.TYPE_STRING, "Context", "f3"));
dt.getActionCols().add(brlAction1);
dt.setData(DataUtilities.makeDataLists(new String[][] { new String[] { "1", "desc", "x", null, "v2", "v3" } }));
String drl = GuidedDTDRLPersistence.getInstance().marshal(dt);
final String expected = "//from row number: 1\n" + "//desc\n" + "rule \"Row 1 null\"\n" + "dialect \"mvel\"\n" + "when\n" + " x : Context( )\n" + "then\n" + " modify( x ) {\n" + " setF2( \"v2\" ),\n" + " setF3( \"v3\" )\n" + "}\n" + "end\n";
assertEqualsIgnoreWhitespace(expected, drl);
}
use of org.drools.workbench.models.guided.dtable.shared.model.Pattern52 in project drools by kiegroup.
the class BRLRuleModelTest method testUpdateModifyMultipleFields.
@Test
public void testUpdateModifyMultipleFields() {
GuidedDecisionTable52 dt = new GuidedDecisionTable52();
Pattern52 p1 = new Pattern52();
p1.setBoundName("x");
p1.setFactType("Context");
ConditionCol52 c = new ConditionCol52();
c.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
p1.getChildColumns().add(c);
dt.getConditions().add(p1);
BRLActionColumn brlAction1 = new BRLActionColumn();
ActionUpdateField auf1 = new ActionUpdateField("x");
auf1.addFieldValue(new ActionFieldValue("age", "$age", DataType.TYPE_NUMERIC_INTEGER));
auf1.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
brlAction1.getDefinition().add(auf1);
brlAction1.getChildColumns().add(new BRLActionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Context", "age"));
dt.getActionCols().add(brlAction1);
BRLActionColumn brlAction2 = new BRLActionColumn();
ActionUpdateField auf2 = new ActionUpdateField("x");
auf2.addFieldValue(new ActionFieldValue("name", "$name", DataType.TYPE_STRING));
auf2.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
brlAction2.getDefinition().add(auf2);
brlAction2.getChildColumns().add(new BRLActionVariableColumn("$name", DataType.TYPE_STRING, "Context", "name"));
dt.getActionCols().add(brlAction2);
dt.setData(DataUtilities.makeDataLists(new String[][] { new String[] { "1", "desc", "x", "55", "Fred" } }));
String drl = GuidedDTDRLPersistence.getInstance().marshal(dt);
final String expected1 = "//from row number: 1\n" + "//desc\n" + "rule \"Row 1 null\"\n" + "dialect \"mvel\"\n" + "when\n" + " x : Context( )\n" + "then\n" + " modify( x ) {\n" + " setAge( 55 ), \n" + " setName( \"Fred\" )\n" + "}\n" + "end\n";
assertEqualsIgnoreWhitespace(expected1, drl);
dt.setData(DataUtilities.makeDataLists(new String[][] { new String[] { "1", "desc", "x", "", "Fred" } }));
drl = GuidedDTDRLPersistence.getInstance().marshal(dt);
final String expected2 = "//from row number: 1\n" + "//desc\n" + "rule \"Row 1 null\"\n" + "dialect \"mvel\"\n" + "when\n" + " x : Context( )\n" + "then\n" + " modify( x ) {\n" + " setName( \"Fred\" )\n" + "}\n" + "end\n";
assertEqualsIgnoreWhitespace(expected2, drl);
dt.setData(DataUtilities.makeDataLists(new String[][] { new String[] { "1", "desc", "x", "55", "" } }));
drl = GuidedDTDRLPersistence.getInstance().marshal(dt);
final String expected3 = "//from row number: 1\n" + "//desc\n" + "rule \"Row 1 null\"\n" + "dialect \"mvel\"\n" + "when\n" + " x : Context( )\n" + "then\n" + " modify( x ) {\n" + " setAge( 55 ) \n" + "}\n" + "end\n";
assertEqualsIgnoreWhitespace(expected3, drl);
}
use of org.drools.workbench.models.guided.dtable.shared.model.Pattern52 in project drools by kiegroup.
the class BRLRuleModelTest method testRuleModelWithRHSBoundFactsUsageWithActionInsertFact.
@Test
public void testRuleModelWithRHSBoundFactsUsageWithActionInsertFact() {
final GuidedDecisionTable52 dt = new GuidedDecisionTable52();
// Setup Decision Table columns
final Pattern52 p1 = new Pattern52();
p1.setFactType("Driver");
p1.setBoundName("$d");
dt.getConditions().add(p1);
final ActionInsertFactCol52 ins = new ActionInsertFactCol52();
ins.setBoundName("$ins");
ins.setFactField("rating");
ins.setFactType("Person");
ins.setType(DataType.TYPE_STRING);
dt.getActionCols().add(ins);
final BRLRuleModel model = new BRLRuleModel(dt);
// Checks
assertTrue(model.isBoundFactUsed("$ins"));
assertFalse(model.isBoundFactUsed("$cheese"));
}
Aggregations