use of org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn in project drools-wb by kiegroup.
the class BRLConditionColumnSynchronizerTest method testUpdate2.
@Test
public void testUpdate2() throws VetoException {
// Single Column, multiple variables
final BRLConditionColumn column = spy(new BRLConditionColumn());
final BRLConditionVariableColumn columnV0 = new BRLConditionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Applicant", "age");
final BRLConditionVariableColumn columnV1 = new BRLConditionVariableColumn("$name", DataType.TYPE_STRING, "Applicant", "name");
column.getChildColumns().add(columnV0);
column.getChildColumns().add(columnV1);
column.setHeader("col1");
columnV0.setHeader("col1v0");
columnV1.setHeader("col1v1");
modelSynchronizer.appendColumn(column);
assertEquals(4, model.getExpandedColumns().size());
assertEquals(1, model.getConditions().size());
assertEquals(4, uiModel.getColumns().size());
assertTrue(uiModel.getColumns().get(2) instanceof IntegerUiColumn);
assertTrue(uiModel.getColumns().get(3) instanceof StringUiColumn);
final BRLConditionColumn edited = new BRLConditionColumn();
final BRLConditionVariableColumn editedColumnV0 = new BRLConditionVariableColumn("$name", DataType.TYPE_STRING, "Applicant", "name");
edited.getChildColumns().add(editedColumnV0);
edited.setHideColumn(true);
edited.setHeader("updated");
editedColumnV0.setHeader("updated");
List<BaseColumnFieldDiff> diffs = modelSynchronizer.updateColumn(column, edited);
assertEquals(6, // header, hide, field name, field type, binding, removed column
diffs.size());
verify(column).diff(edited);
assertEquals(3, model.getExpandedColumns().size());
assertEquals(1, model.getConditions().size());
assertEquals(3, uiModel.getColumns().size());
assertTrue(uiModel.getColumns().get(2) instanceof StringUiColumn);
assertEquals("updated", uiModel.getColumns().get(2).getHeaderMetaData().get(0).getTitle());
assertEquals(false, uiModel.getColumns().get(2).isVisible());
assertEquals("$name", uiModel.getColumns().get(2).getHeaderMetaData().get(1).getTitle());
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn 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.BRLConditionVariableColumn in project drools-wb by kiegroup.
the class BRLConditionColumnSynchronizerTest method testAppend1.
@Test
public void testAppend1() throws VetoException {
// Single Column, single variable
final BRLConditionColumn column = new BRLConditionColumn();
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);
assertEquals(3, model.getExpandedColumns().size());
assertEquals(1, model.getConditions().size());
assertEquals(3, uiModel.getColumns().size());
assertTrue(uiModel.getColumns().get(2) instanceof IntegerUiColumn);
assertEquals(2, uiModel.getColumns().get(2).getHeaderMetaData().size());
assertEquals("$age", uiModel.getColumns().get(2).getHeaderMetaData().get(1).getTitle());
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn in project drools-wb by kiegroup.
the class BRLConditionColumnSynchronizerTest method testUpdate1.
@Test
public void testUpdate1() throws VetoException {
// Single Column, single variable
final BRLConditionColumn column = spy(new BRLConditionColumn());
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);
assertEquals(3, model.getExpandedColumns().size());
assertEquals(1, model.getConditions().size());
assertEquals(3, uiModel.getColumns().size());
assertTrue(uiModel.getColumns().get(2) instanceof IntegerUiColumn);
assertEquals(2, uiModel.getColumns().get(2).getHeaderMetaData().size());
assertEquals("$age", uiModel.getColumns().get(2).getHeaderMetaData().get(1).getTitle());
final BRLConditionColumn edited = new BRLConditionColumn();
final BRLConditionVariableColumn editedColumnV0 = new BRLConditionVariableColumn("$name", DataType.TYPE_STRING, "Applicant", "name");
edited.getChildColumns().add(editedColumnV0);
edited.setHideColumn(true);
edited.setHeader("updated");
editedColumnV0.setHeader("updated");
List<BaseColumnFieldDiff> diffs = modelSynchronizer.updateColumn(column, edited);
assertEquals(5, // header, hide, field name, field type, binding
diffs.size());
verify(column).diff(edited);
assertEquals(3, model.getExpandedColumns().size());
assertEquals(1, model.getConditions().size());
assertEquals(3, uiModel.getColumns().size());
assertTrue(uiModel.getColumns().get(2) instanceof StringUiColumn);
assertEquals("updated", uiModel.getColumns().get(2).getHeaderMetaData().get(0).getTitle());
assertEquals(false, uiModel.getColumns().get(2).isVisible());
assertEquals(2, uiModel.getColumns().get(2).getHeaderMetaData().size());
assertEquals("$name", uiModel.getColumns().get(2).getHeaderMetaData().get(1).getTitle());
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn 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);
}
Aggregations