use of org.drools.workbench.models.guided.dtable.shared.model.CompositeColumn 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.CompositeColumn 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);
}
use of org.drools.workbench.models.guided.dtable.shared.model.CompositeColumn in project drools-wb by kiegroup.
the class ColumnsPagePresenterTest method testRefreshConditionsWidgetWhenConditionColumnsIsNotEmpty.
@Test
public void testRefreshConditionsWidgetWhenConditionColumnsIsNotEmpty() {
final ColumnManagementView columnManagementView = mock(ColumnManagementView.class);
final GuidedDecisionTableAccordionItem item = mock(GuidedDecisionTableAccordionItem.class);
final Label blankSlate = mock(Label.class);
final List<CompositeColumn<? extends BaseColumn>> conditions1 = new ArrayList<CompositeColumn<? extends BaseColumn>>() {
{
add(compositeColumn1);
}
};
final Map<String, List<BaseColumn>> conditions2 = new HashMap<String, List<BaseColumn>>() {
{
put("title", new ArrayList<>());
}
};
doReturn(verticalPanel).when(presenter).getConditionsWidget();
doReturn(columnManagementView).when(presenter).getConditionsPanel();
doReturn(blankSlate).when(presenter).blankSlate();
doReturn(item).when(accordion).getItem(CONDITION);
doReturn(conditions2).when(presenter).groupByTitle(conditions1);
presenter.refreshConditionsWidget(conditions1);
verify(item, never()).setOpen(false);
verify(verticalPanel, never()).add(blankSlate);
verify(verticalPanel).add(columnManagementView);
verify(columnManagementView).renderColumns(conditions2);
}
use of org.drools.workbench.models.guided.dtable.shared.model.CompositeColumn in project drools-wb by kiegroup.
the class ColumnsPagePresenterTest method testRefreshConditionsWidgetWhenConditionColumnsIsEmpty.
@Test
public void testRefreshConditionsWidgetWhenConditionColumnsIsEmpty() {
final List<CompositeColumn<? extends BaseColumn>> conditions = new ArrayList<>();
final ColumnManagementView columnManagementView = mock(ColumnManagementView.class);
final GuidedDecisionTableAccordionItem item = mock(GuidedDecisionTableAccordionItem.class);
final Label blankSlate = mock(Label.class);
doReturn(verticalPanel).when(presenter).getConditionsWidget();
doReturn(columnManagementView).when(presenter).getConditionsPanel();
doReturn(blankSlate).when(presenter).blankSlate();
doReturn(item).when(accordion).getItem(CONDITION);
presenter.refreshConditionsWidget(conditions);
verify(item).setOpen(false);
verify(verticalPanel).add(blankSlate);
verify(verticalPanel, never()).add(columnManagementView);
verify(columnManagementView, never()).renderColumns(any());
}
use of org.drools.workbench.models.guided.dtable.shared.model.CompositeColumn in project drools-wb by kiegroup.
the class ValidatorTest method fakeCompositeColumn.
private List<CompositeColumn<? extends BaseColumn>> fakeCompositeColumn(final ConditionCol52... columns) {
final List<CompositeColumn<? extends BaseColumn>> compositeColumns = new ArrayList<>();
compositeColumns.add(fakeCompositeColumn(new ArrayList<ConditionCol52>() {
{
for (ConditionCol52 column : columns) {
add(column);
}
}
}));
return compositeColumns;
}
Aggregations