use of org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52 in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method testLimitedEntryLHSNotInOperator.
@Test
public void testLimitedEntryLHSNotInOperator() {
GuidedDecisionTable52 dt = new GuidedDecisionTable52();
dt.setTableFormat(GuidedDecisionTable52.TableFormat.LIMITED_ENTRY);
dt.setTableName("limited-entry");
Pattern52 p1 = new Pattern52();
p1.setBoundName("p1");
p1.setFactType("Smurf");
dt.getConditions().add(p1);
LimitedEntryConditionCol52 cc1 = new LimitedEntryConditionCol52();
cc1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
cc1.setFieldType(DataType.TYPE_STRING);
cc1.setFactField("name");
cc1.setOperator("not in");
cc1.setValue(new DTCellValue52("Pupa, Brains"));
p1.getChildColumns().add(cc1);
LimitedEntryConditionCol52 cc2 = new LimitedEntryConditionCol52();
cc2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
cc2.setFieldType(DataType.TYPE_NUMERIC_INTEGER);
cc2.setFactField("age");
cc2.setOperator("not in");
cc2.setValue(new DTCellValue52("55, 66"));
p1.getChildColumns().add(cc2);
dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { 1l, "desc", true, true }, new Object[] { 2l, "desc", false, false } }));
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.GuidedDecisionTable52 in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method testRHSWithBRLColumn_ParseToDRL_FreeFormLine.
@Test
public // This test checks a Decision Table involving BRL columns is correctly converted into DRL
void testRHSWithBRLColumn_ParseToDRL_FreeFormLine() {
GuidedDecisionTable52 dtable = new GuidedDecisionTable52();
// Row 0 should become an IAction in the resulting RuleModel as it contains values for all Template fields in the BRL Column
// Row 1 should *NOT* become an IAction in the resulting RuleModel as it does *NOT* contain values for all Template fields in the BRL Column
// Row 2 should *NOT* become an IAction in the resulting RuleModel as it does *NOT* contain values for all Template fields in the BRL Column
// Row 3 should *NOT* become an IAction in the resulting RuleModel as it does *NOT* contain values for all Template fields in the BRL Column
String[][] data = new String[][] { new String[] { "1", "desc", "Pupa", "50" }, new String[] { "2", "desc", "", "50" }, new String[] { "3", "desc", "Pupa", "" }, new String[] { "4", "desc", "", "" } };
// Simple (mandatory) columns
dtable.setRowNumberCol(new RowNumberCol52());
dtable.setDescriptionCol(new DescriptionCol52());
// BRL Action
BRLActionColumn brl1 = new BRLActionColumn();
// BRL Action definition
List<IAction> brl1Definition = new ArrayList<IAction>();
FreeFormLine brl1DefinitionFreeFormLine = new FreeFormLine();
brl1DefinitionFreeFormLine.setText("System.out.println( \"name == @{name}, age == @{age}\" );");
brl1Definition.add(brl1DefinitionFreeFormLine);
brl1.setDefinition(brl1Definition);
// Setup BRL column bindings
BRLActionVariableColumn brl1Variable1 = new BRLActionVariableColumn("name", DataType.TYPE_STRING);
BRLActionVariableColumn brl1Variable2 = new BRLActionVariableColumn("age", DataType.TYPE_NUMERIC_INTEGER);
brl1.getChildColumns().add(brl1Variable1);
brl1.getChildColumns().add(brl1Variable2);
dtable.getActionCols().add(brl1);
dtable.setData(DataUtilities.makeDataLists(data));
// Now to test conversion
int ruleStartIndex;
int pattern1StartIndex;
GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
String drl = p.marshal(dtable);
// Row 0
ruleStartIndex = drl.indexOf("//from row number: 1");
assertFalse(ruleStartIndex == -1);
pattern1StartIndex = drl.indexOf("System.out.println( \"name == Pupa, age == 50\" );", ruleStartIndex);
assertFalse(pattern1StartIndex == -1);
// Row 1
ruleStartIndex = drl.indexOf("//from row number: 2");
assertFalse(ruleStartIndex == -1);
pattern1StartIndex = drl.indexOf("System.out.println(", ruleStartIndex);
assertTrue(pattern1StartIndex == -1);
// Row 2
ruleStartIndex = drl.indexOf("//from row number: 3");
assertFalse(ruleStartIndex == -1);
pattern1StartIndex = drl.indexOf("System.out.println(", ruleStartIndex);
assertTrue(pattern1StartIndex == -1);
// Row 3
ruleStartIndex = drl.indexOf("//from row number: 4");
assertFalse(ruleStartIndex == -1);
pattern1StartIndex = drl.indexOf("System.out.println(", ruleStartIndex);
assertTrue(pattern1StartIndex == -1);
}
use of org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52 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.GuidedDecisionTable52 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.GuidedDecisionTable52 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);
}
Aggregations