use of org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52 in project drools-wb by kiegroup.
the class BRLConditionColumnSynchronizerTest method checkBRLFragmentConditionCannotBeDeletedWithAction.
@Test
public void checkBRLFragmentConditionCannotBeDeletedWithAction() throws VetoException {
final BRLConditionColumn column = new BRLConditionColumn();
column.setDefinition(Collections.singletonList(new FactPattern("Applicant") {
{
setBoundName("$a");
}
}));
final BRLConditionVariableColumn columnV0 = new BRLConditionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Applicant", "age");
column.getChildColumns().add(columnV0);
column.setHeader("col1");
columnV0.setHeader("col1v0");
modelSynchronizer.appendColumn(column);
final ActionSetFieldCol52 action = new ActionSetFieldCol52() {
{
setBoundName("$a");
setFactField("age");
setHeader("action1");
}
};
modelSynchronizer.appendColumn(action);
try {
modelSynchronizer.deleteColumn(column);
fail("Deletion of the column should have been vetoed.");
} catch (VetoDeletePatternInUseException veto) {
// This is expected
} catch (VetoException veto) {
fail("VetoDeletePatternInUseException was expected.");
}
assertEquals(4, model.getExpandedColumns().size());
assertTrue(model.getExpandedColumns().get(0) instanceof RowNumberCol52);
assertTrue(model.getExpandedColumns().get(1) instanceof DescriptionCol52);
assertEquals(columnV0, model.getExpandedColumns().get(2));
assertEquals(action, model.getExpandedColumns().get(3));
}
use of org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52 in project drools-wb by kiegroup.
the class BRLConditionColumnSynchronizerTest method checkBRLFragmentConditionCannotBeUpdatedWhenFieldBindingIsUsedInAction.
@Test
public void checkBRLFragmentConditionCannotBeUpdatedWhenFieldBindingIsUsedInAction() throws VetoException {
final BRLConditionColumn column = new BRLConditionColumn();
column.setDefinition(Collections.singletonList(new FactPattern("Applicant") {
{
setBoundName("$a");
addConstraint(new SingleFieldConstraint("age") {
{
setBoundName("$age");
}
});
}
}));
final BRLConditionVariableColumn columnV0 = new BRLConditionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Applicant", "age");
column.getChildColumns().add(columnV0);
column.setHeader("col1");
columnV0.setHeader("col1v0");
modelSynchronizer.appendColumn(column);
final BRLActionColumn action = new BRLActionColumn();
action.setDefinition(Collections.singletonList(new ActionCallMethod() {
{
setVariable("$age");
setMethodName("toString()");
}
}));
final BRLActionVariableColumn columnV1 = new BRLActionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Applicant", "age");
action.getChildColumns().add(columnV1);
action.setHeader("col2");
columnV1.setHeader("col2v0");
modelSynchronizer.appendColumn(action);
try {
final BRLConditionColumn editedColumn = new BRLConditionColumn();
editedColumn.setDefinition(Collections.singletonList(new FactPattern("Applicant") {
{
setBoundName("$a");
addConstraint(new SingleFieldConstraint("age") {
{
setBoundName("$age2");
}
});
}
}));
final BRLConditionVariableColumn editedColumnV0 = new BRLConditionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Applicant", "age");
editedColumn.getChildColumns().add(editedColumnV0);
editedColumn.setHeader("col1");
editedColumnV0.setHeader("col1v0");
modelSynchronizer.updateColumn(column, editedColumn);
fail("Deletion of the column should have been vetoed.");
} catch (VetoUpdatePatternInUseException veto) {
// This is expected
} catch (VetoException veto) {
fail("VetoUpdatePatternInUseException was expected.");
}
assertEquals(4, model.getExpandedColumns().size());
assertTrue(model.getExpandedColumns().get(0) instanceof RowNumberCol52);
assertTrue(model.getExpandedColumns().get(1) instanceof DescriptionCol52);
assertEquals(columnV0, model.getExpandedColumns().get(2));
assertEquals(action.getChildColumns().get(0), model.getExpandedColumns().get(3));
}
use of org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52 in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method testLHSOtherwisePatternBoolean.
@Test
public void testLHSOtherwisePatternBoolean() {
GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
String[][] row = new String[2][];
String[][] data = new String[2][];
row[0] = new String[] { "1", "desc1", "true", "false" };
List<DTCellValue52> rowDTModel0 = DataUtilities.makeDataRowList(row[0]);
data[0] = row[0];
row[1] = new String[] { "3", "desc3", null, null };
List<DTCellValue52> rowDTModel1 = DataUtilities.makeDataRowList(row[1]);
rowDTModel1.get(2).setOtherwise(true);
rowDTModel1.get(3).setOtherwise(true);
data[1] = row[1];
final List<List<DTCellValue52>> allDTData = new ArrayList<List<DTCellValue52>>() {
{
add(rowDTModel0);
add(rowDTModel1);
}
};
List<BaseColumn> allColumns = new ArrayList<BaseColumn>();
List<CompositeColumn<? extends BaseColumn>> allPatterns = new ArrayList<CompositeColumn<? extends BaseColumn>>();
allColumns.add(new RowNumberCol52());
allColumns.add(new DescriptionCol52());
Pattern52 p1 = new Pattern52();
p1.setBoundName("p1");
p1.setFactType("Person");
allPatterns.add(p1);
ConditionCol52 col = new ConditionCol52();
col.setFactField("alive");
col.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
col.setFieldType(DataType.TYPE_BOOLEAN);
col.setOperator("==");
p1.getChildColumns().add(col);
allColumns.add(col);
Pattern52 p2 = new Pattern52();
p2.setBoundName("p2");
p2.setFactType("Person");
allPatterns.add(p2);
ConditionCol52 col2 = new ConditionCol52();
col2.setFactField("alive");
col2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
col2.setFieldType(DataType.TYPE_BOOLEAN);
col2.setOperator("!=");
p2.getChildColumns().add(col2);
allColumns.add(col2);
RuleModel rm = new RuleModel();
TemplateDataProvider rowDataProvider0 = new GuidedDTTemplateDataProvider(allColumns, rowDTModel0);
p.doConditions(allColumns, allPatterns, rowDataProvider0, rowDTModel0, allDTData, rm);
String drl0 = RuleModelDRLPersistenceImpl.getInstance().marshal(rm);
assertEquals(2, rm.lhs.length);
assertEquals("Person", ((FactPattern) rm.lhs[0]).getFactType());
assertEquals("p1", ((FactPattern) rm.lhs[0]).getBoundName());
assertEquals("Person", ((FactPattern) rm.lhs[1]).getFactType());
assertEquals("p2", ((FactPattern) rm.lhs[1]).getBoundName());
assertTrue(drl0.indexOf("p1 : Person( alive == true )") > 0);
assertTrue(drl0.indexOf("p2 : Person( alive != false )") > 0);
TemplateDataProvider rowDataProvider1 = new GuidedDTTemplateDataProvider(allColumns, rowDTModel1);
p.doConditions(allColumns, allPatterns, rowDataProvider1, rowDTModel1, allDTData, rm);
String drl1 = RuleModelDRLPersistenceImpl.getInstance().marshal(rm);
assertEquals(2, rm.lhs.length);
assertEquals("Person", ((FactPattern) rm.lhs[0]).getFactType());
assertEquals("p1", ((FactPattern) rm.lhs[0]).getBoundName());
assertEquals("Person", ((FactPattern) rm.lhs[1]).getFactType());
assertEquals("p2", ((FactPattern) rm.lhs[1]).getBoundName());
assertTrue(drl1.indexOf("p1 : Person( alive not in ( true )") > 0);
assertTrue(drl1.indexOf("p2 : Person( alive in ( false )") > 0);
}
use of org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52 in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method testLHSWithBRLColumn_ParseToDRL_FreeFormLine.
@Test
public // This test checks a Decision Table involving BRL columns is correctly converted into DRL
void testLHSWithBRLColumn_ParseToDRL_FreeFormLine() {
GuidedDecisionTable52 dtable = new GuidedDecisionTable52();
// Row 0 should become an IPattern in the resulting RuleModel as it contains values for all Template fields in the BRL Column
// Row 1 should *NOT* become an IPattern in the resulting RuleModel as it does *NOT* contain values for all Template fields in the BRL Column
// Row 2 should *NOT* become an IPattern in the resulting RuleModel as it does *NOT* contain values for all Template fields in the BRL Column
// Row 3 should *NOT* become an IPattern 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 Column
BRLConditionColumn brl1 = new BRLConditionColumn();
// BRL Column definition
List<IPattern> brl1Definition = new ArrayList<IPattern>();
FreeFormLine brl1DefinitionFreeFormLine = new FreeFormLine();
brl1DefinitionFreeFormLine.setText("Smurf( name == \"@{name}\", age == @{age} )");
brl1Definition.add(brl1DefinitionFreeFormLine);
brl1.setDefinition(brl1Definition);
// Setup BRL column bindings
BRLConditionVariableColumn brl1Variable1 = new BRLConditionVariableColumn("name", DataType.TYPE_STRING);
BRLConditionVariableColumn brl1Variable2 = new BRLConditionVariableColumn("age", DataType.TYPE_NUMERIC_INTEGER);
brl1.getChildColumns().add(brl1Variable1);
brl1.getChildColumns().add(brl1Variable2);
dtable.getConditions().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("Smurf( name == \"Pupa\", age == 50 )", ruleStartIndex);
assertFalse(pattern1StartIndex == -1);
// Row 1
ruleStartIndex = drl.indexOf("//from row number: 2");
assertFalse(ruleStartIndex == -1);
pattern1StartIndex = drl.indexOf("Smurf(", ruleStartIndex);
assertTrue(pattern1StartIndex == -1);
// Row 2
ruleStartIndex = drl.indexOf("//from row number: 3");
assertFalse(ruleStartIndex == -1);
pattern1StartIndex = drl.indexOf("Smurf(", ruleStartIndex);
assertTrue(pattern1StartIndex == -1);
// Row 3
ruleStartIndex = drl.indexOf("//from row number: 4");
assertFalse(ruleStartIndex == -1);
pattern1StartIndex = drl.indexOf("Smurf(", ruleStartIndex);
assertTrue(pattern1StartIndex == -1);
}
use of org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52 in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method testLHSOtherwisePatternDate.
@Test
public void testLHSOtherwisePatternDate() {
GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
String[][] row = new String[3][];
String[][] data = new String[3][];
row[0] = new String[] { "1", "desc1", "01-Jan-1980", "20-Jun-1985" };
List<DTCellValue52> rowDTModel0 = DataUtilities.makeDataRowList(row[0]);
data[0] = row[0];
row[1] = new String[] { "2", "desc2", "01-Feb-1981", "21-Jun-1986" };
List<DTCellValue52> rowDTModel1 = DataUtilities.makeDataRowList(row[1]);
data[1] = row[1];
row[2] = new String[] { "3", "desc3", null, null };
List<DTCellValue52> rowDTModel2 = DataUtilities.makeDataRowList(row[2]);
rowDTModel2.get(2).setOtherwise(true);
rowDTModel2.get(3).setOtherwise(true);
data[2] = row[2];
final List<List<DTCellValue52>> allDTData = new ArrayList<List<DTCellValue52>>() {
{
add(rowDTModel0);
add(rowDTModel1);
add(rowDTModel2);
}
};
List<BaseColumn> allColumns = new ArrayList<BaseColumn>();
List<CompositeColumn<? extends BaseColumn>> allPatterns = new ArrayList<CompositeColumn<? extends BaseColumn>>();
allColumns.add(new RowNumberCol52());
allColumns.add(new DescriptionCol52());
Pattern52 p1 = new Pattern52();
p1.setBoundName("p1");
p1.setFactType("Person");
allPatterns.add(p1);
ConditionCol52 col = new ConditionCol52();
col.setFactField("dateOfBirth");
col.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
col.setFieldType(DataType.TYPE_DATE);
col.setOperator("==");
p1.getChildColumns().add(col);
allColumns.add(col);
Pattern52 p2 = new Pattern52();
p2.setBoundName("p2");
p2.setFactType("Person");
allPatterns.add(p2);
ConditionCol52 col2 = new ConditionCol52();
col2.setFactField("dateOfBirth");
col2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
col2.setFieldType(DataType.TYPE_DATE);
col2.setOperator("!=");
p2.getChildColumns().add(col2);
allColumns.add(col2);
RuleModel rm = new RuleModel();
TemplateDataProvider rowDataProvider0 = new GuidedDTTemplateDataProvider(allColumns, rowDTModel0);
p.doConditions(allColumns, allPatterns, rowDataProvider0, rowDTModel0, allDTData, rm);
String drl0 = RuleModelDRLPersistenceImpl.getInstance().marshal(rm);
assertEquals(2, rm.lhs.length);
assertEquals("Person", ((FactPattern) rm.lhs[0]).getFactType());
assertEquals("p1", ((FactPattern) rm.lhs[0]).getBoundName());
assertEquals("Person", ((FactPattern) rm.lhs[1]).getFactType());
assertEquals("p2", ((FactPattern) rm.lhs[1]).getBoundName());
assertTrue(drl0.indexOf("p1 : Person( dateOfBirth == \"01-Jan-1980\" )") > 0);
assertTrue(drl0.indexOf("p2 : Person( dateOfBirth != \"20-Jun-1985\" )") > 0);
TemplateDataProvider rowDataProvider1 = new GuidedDTTemplateDataProvider(allColumns, rowDTModel1);
p.doConditions(allColumns, allPatterns, rowDataProvider1, rowDTModel1, allDTData, rm);
String drl1 = RuleModelDRLPersistenceImpl.getInstance().marshal(rm);
assertEquals(2, rm.lhs.length);
assertEquals("Person", ((FactPattern) rm.lhs[0]).getFactType());
assertEquals("p1", ((FactPattern) rm.lhs[0]).getBoundName());
assertEquals("Person", ((FactPattern) rm.lhs[1]).getFactType());
assertEquals("p2", ((FactPattern) rm.lhs[1]).getBoundName());
assertTrue(drl1.indexOf("p1 : Person( dateOfBirth == \"01-Feb-1981\" )") > 0);
assertTrue(drl1.indexOf("p2 : Person( dateOfBirth != \"21-Jun-1986\" )") > 0);
TemplateDataProvider rowDataProvider2 = new GuidedDTTemplateDataProvider(allColumns, rowDTModel2);
p.doConditions(allColumns, allPatterns, rowDataProvider2, rowDTModel2, allDTData, rm);
String drl2 = RuleModelDRLPersistenceImpl.getInstance().marshal(rm);
assertEquals(2, rm.lhs.length);
assertEquals("Person", ((FactPattern) rm.lhs[0]).getFactType());
assertEquals("p1", ((FactPattern) rm.lhs[0]).getBoundName());
assertEquals("Person", ((FactPattern) rm.lhs[1]).getFactType());
assertEquals("p2", ((FactPattern) rm.lhs[1]).getBoundName());
assertTrue(drl2.indexOf("p1 : Person( dateOfBirth not in ( \"01-Jan-1980\", \"01-Feb-1981\" )") > 0);
assertTrue(drl2.indexOf("p2 : Person( dateOfBirth in ( \"20-Jun-1985\", \"21-Jun-1986\" )") > 0);
}
Aggregations