Search in sources :

Example 96 with Pattern52

use of org.drools.workbench.models.guided.dtable.shared.model.Pattern52 in project drools-wb by kiegroup.

the class ConditionColumnSynchronizerTest method checkConditionCannotBeDeletedWhenFieldBindingIsUsedInAction.

@Test
public void checkConditionCannotBeDeletedWhenFieldBindingIsUsedInAction() throws VetoException {
    final Pattern52 pattern = boundApplicantPattern("$a");
    final ConditionCol52 condition = ageEqualsCondition();
    condition.setBinding("$age");
    final BRLActionColumn action = actionCallMethod("$age");
    modelSynchronizer.appendColumn(pattern, condition);
    modelSynchronizer.appendColumn(action);
    try {
        modelSynchronizer.deleteColumn(condition);
        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(condition, model.getExpandedColumns().get(2));
    assertEquals(action.getChildColumns().get(0), model.getExpandedColumns().get(3));
}
Also used : VetoException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoException) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) VetoDeletePatternInUseException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoDeletePatternInUseException) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Example 97 with Pattern52

use of org.drools.workbench.models.guided.dtable.shared.model.Pattern52 in project drools-wb by kiegroup.

the class ConditionColumnSynchronizerTest method testMoveColumnTo_OutOfBounds_OutOfConditions.

@Test
public void testMoveColumnTo_OutOfBounds_OutOfConditions() throws VetoException {
    final Pattern52 pattern = boundApplicantPattern("$a");
    final ConditionCol52 column1 = ageEqualsCondition();
    final ConditionCol52 column2 = nameEqualsCondition();
    modelSynchronizer.appendColumn(pattern, column1);
    modelSynchronizer.appendColumn(pattern, column2);
    modelSynchronizer.appendRow();
    uiModel.setCellValue(0, 2, new BaseGridCellValue<Integer>(45));
    uiModel.setCellValue(0, 3, new BaseGridCellValue<String>("Smurf"));
    assertEquals(1, model.getPatterns().size());
    final List<ConditionCol52> conditionColumns1_1 = model.getPatterns().get(0).getChildColumns();
    assertEquals(column1, conditionColumns1_1.get(0));
    assertEquals(column2, conditionColumns1_1.get(1));
    assertEquals(45, model.getData().get(0).get(2).getNumericValue());
    assertEquals("Smurf", model.getData().get(0).get(3).getStringValue());
    assertEquals(4, uiModel.getColumns().size());
    final GridColumn<?> uiModelColumn1_1 = uiModel.getColumns().get(2);
    final GridColumn<?> uiModelColumn2_1 = uiModel.getColumns().get(3);
    assertEquals("$a : Applicant", uiModelColumn1_1.getHeaderMetaData().get(0).getTitle());
    assertEquals("$a : Applicant", uiModelColumn2_1.getHeaderMetaData().get(0).getTitle());
    assertTrue(uiModelColumn1_1 instanceof IntegerUiColumn);
    assertTrue(uiModelColumn2_1 instanceof StringUiColumn);
    assertEquals(2, uiModelColumn1_1.getIndex());
    assertEquals(3, uiModelColumn2_1.getIndex());
    assertEquals(45, uiModel.getRow(0).getCells().get(uiModelColumn1_1.getIndex()).getValue().getValue());
    assertEquals("Smurf", uiModel.getRow(0).getCells().get(uiModelColumn2_1.getIndex()).getValue().getValue());
    uiModel.moveColumnTo(0, uiModelColumn1_1);
    assertEquals(1, model.getPatterns().size());
    final List<ConditionCol52> conditionColumns1_2 = model.getPatterns().get(0).getChildColumns();
    assertEquals(column1, conditionColumns1_2.get(0));
    assertEquals(column2, conditionColumns1_2.get(1));
    assertEquals(45, model.getData().get(0).get(2).getNumericValue());
    assertEquals("Smurf", model.getData().get(0).get(3).getStringValue());
    assertEquals(4, uiModel.getColumns().size());
    final GridColumn<?> uiModelColumn1_2 = uiModel.getColumns().get(2);
    final GridColumn<?> uiModelColumn2_2 = uiModel.getColumns().get(3);
    assertEquals("$a : Applicant", uiModelColumn1_2.getHeaderMetaData().get(0).getTitle());
    assertEquals("$a : Applicant", uiModelColumn2_2.getHeaderMetaData().get(0).getTitle());
    assertTrue(uiModelColumn1_2 instanceof IntegerUiColumn);
    assertTrue(uiModelColumn2_2 instanceof StringUiColumn);
    assertEquals(2, uiModelColumn1_2.getIndex());
    assertEquals(3, uiModelColumn2_2.getIndex());
    assertEquals(45, uiModel.getRow(0).getCells().get(uiModelColumn1_2.getIndex()).getValue().getValue());
    assertEquals("Smurf", uiModel.getRow(0).getCells().get(uiModelColumn2_2.getIndex()).getValue().getValue());
}
Also used : ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) StringUiColumn(org.drools.workbench.screens.guided.dtable.client.widget.table.columns.StringUiColumn) IntegerUiColumn(org.drools.workbench.screens.guided.dtable.client.widget.table.columns.IntegerUiColumn) Test(org.junit.Test)

Example 98 with Pattern52

use of org.drools.workbench.models.guided.dtable.shared.model.Pattern52 in project drools-wb by kiegroup.

the class ConditionColumnSynchronizerTest method testUpdate3.

@Test
public void testUpdate3() throws VetoException {
    // Multiple Patterns, multiple Conditions
    final Pattern52 pattern1 = spy(boundApplicantPattern("$a"));
    final ConditionCol52 condition1 = spy(ageEqualsCondition());
    modelSynchronizer.appendColumn(pattern1, condition1);
    final ConditionCol52 condition2 = nameEqualsCondition();
    modelSynchronizer.appendColumn(pattern1, condition2);
    final Pattern52 editedPattern = boundAddressPattern("$d");
    final ConditionCol52 editedCondition = new ConditionCol52();
    editedCondition.setWidth(condition1.getWidth());
    editedCondition.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    editedCondition.setHeader("col1");
    editedCondition.setFactField("country");
    editedCondition.setOperator("==");
    List<BaseColumnFieldDiff> diffs = modelSynchronizer.updateColumn(pattern1, condition1, editedPattern, editedCondition);
    assertEquals(3, diffs.size());
    verify(pattern1).diff(editedPattern);
    verify(condition1).diff(editedCondition);
    assertEquals(4, model.getExpandedColumns().size());
    assertEquals(2, model.getConditions().size());
    assertEquals(1, model.getConditionPattern("$a").getChildColumns().size());
    assertEquals(1, model.getConditionPattern("$d").getChildColumns().size());
    assertEquals(4, uiModel.getColumns().size());
    assertTrue(uiModel.getColumns().get(2) instanceof StringUiColumn);
    assertTrue(uiModel.getColumns().get(3) instanceof StringUiColumn);
    assertEquals(editedPattern.getBoundName() + " : " + editedPattern.getFactType(), uiModel.getColumns().get(3).getHeaderMetaData().get(0).getTitle());
    assertEquals(editedCondition.getHeader(), uiModel.getColumns().get(3).getHeaderMetaData().get(1).getTitle());
}
Also used : ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) StringUiColumn(org.drools.workbench.screens.guided.dtable.client.widget.table.columns.StringUiColumn) BaseColumnFieldDiff(org.drools.workbench.models.guided.dtable.shared.model.BaseColumnFieldDiff) Test(org.junit.Test)

Example 99 with Pattern52

use of org.drools.workbench.models.guided.dtable.shared.model.Pattern52 in project drools-wb by kiegroup.

the class ConditionColumnSynchronizerTest method testMoveColumnsTo_MoveLeft.

@Test
public void testMoveColumnsTo_MoveLeft() throws VetoException {
    final Pattern52 pattern1 = boundApplicantPattern("$a");
    final ConditionCol52 column1p1 = ageEqualsCondition();
    final ConditionCol52 column2p1 = nameEqualsCondition();
    modelSynchronizer.appendColumn(pattern1, column1p1);
    modelSynchronizer.appendColumn(pattern1, column2p1);
    final Pattern52 pattern2 = boundAddressPattern("$d");
    final ConditionCol52 column1p2 = new ConditionCol52();
    column1p2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    column1p2.setFactField("state");
    column1p2.setOperator("==");
    column1p2.setHeader("state");
    final ConditionCol52 column2p2 = new ConditionCol52();
    column2p2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    column2p2.setFactField("country");
    column2p2.setOperator("==");
    column2p2.setHeader("country");
    modelSynchronizer.appendColumn(pattern2, column1p2);
    modelSynchronizer.appendColumn(pattern2, column2p2);
    modelSynchronizer.appendRow();
    uiModel.setCellValue(0, 2, new BaseGridCellValue<Integer>(45));
    uiModel.setCellValue(0, 3, new BaseGridCellValue<String>("Smurf"));
    uiModel.setCellValue(0, 4, new BaseGridCellValue<String>("NY"));
    uiModel.setCellValue(0, 5, new BaseGridCellValue<String>("America"));
    assertEquals(2, model.getPatterns().size());
    final List<ConditionCol52> conditionColumns1_1p1 = model.getPatterns().get(0).getChildColumns();
    assertEquals(column1p1, conditionColumns1_1p1.get(0));
    assertEquals(column2p1, conditionColumns1_1p1.get(1));
    assertEquals(45, model.getData().get(0).get(2).getNumericValue());
    assertEquals("Smurf", model.getData().get(0).get(3).getStringValue());
    final List<ConditionCol52> conditionColumns1_1p2 = model.getPatterns().get(1).getChildColumns();
    assertEquals(column1p2, conditionColumns1_1p2.get(0));
    assertEquals(column2p2, conditionColumns1_1p2.get(1));
    assertEquals("NY", model.getData().get(0).get(4).getStringValue());
    assertEquals("America", model.getData().get(0).get(5).getStringValue());
    assertEquals(6, uiModel.getColumns().size());
    final GridColumn<?> uiModelColumn1_1 = uiModel.getColumns().get(2);
    final GridColumn<?> uiModelColumn2_1 = uiModel.getColumns().get(3);
    final GridColumn<?> uiModelColumn3_1 = uiModel.getColumns().get(4);
    final GridColumn<?> uiModelColumn4_1 = uiModel.getColumns().get(5);
    assertEquals("$a : Applicant", uiModelColumn1_1.getHeaderMetaData().get(0).getTitle());
    assertEquals("$a : Applicant", uiModelColumn2_1.getHeaderMetaData().get(0).getTitle());
    assertEquals("$d : Address", uiModelColumn3_1.getHeaderMetaData().get(0).getTitle());
    assertEquals("$d : Address", uiModelColumn4_1.getHeaderMetaData().get(0).getTitle());
    assertTrue(uiModelColumn1_1 instanceof IntegerUiColumn);
    assertTrue(uiModelColumn2_1 instanceof StringUiColumn);
    assertTrue(uiModelColumn3_1 instanceof StringUiColumn);
    assertTrue(uiModelColumn4_1 instanceof StringUiColumn);
    assertEquals(2, uiModelColumn1_1.getIndex());
    assertEquals(3, uiModelColumn2_1.getIndex());
    assertEquals(4, uiModelColumn3_1.getIndex());
    assertEquals(5, uiModelColumn4_1.getIndex());
    assertEquals(45, uiModel.getRow(0).getCells().get(uiModelColumn1_1.getIndex()).getValue().getValue());
    assertEquals("Smurf", uiModel.getRow(0).getCells().get(uiModelColumn2_1.getIndex()).getValue().getValue());
    assertEquals("NY", uiModel.getRow(0).getCells().get(uiModelColumn3_1.getIndex()).getValue().getValue());
    assertEquals("America", uiModel.getRow(0).getCells().get(uiModelColumn4_1.getIndex()).getValue().getValue());
    uiModel.moveColumnsTo(2, new ArrayList<GridColumn<?>>() {

        {
            add(uiModelColumn3_1);
            add(uiModelColumn4_1);
        }
    });
    assertEquals(2, model.getPatterns().size());
    final List<ConditionCol52> conditionColumns1_2p2 = model.getPatterns().get(0).getChildColumns();
    assertEquals(column1p2, conditionColumns1_2p2.get(0));
    assertEquals(column2p2, conditionColumns1_2p2.get(1));
    assertEquals("NY", model.getData().get(0).get(2).getStringValue());
    assertEquals("America", model.getData().get(0).get(3).getStringValue());
    final List<ConditionCol52> conditionColumns1_2p1 = model.getPatterns().get(1).getChildColumns();
    assertEquals(column1p1, conditionColumns1_2p1.get(0));
    assertEquals(column2p1, conditionColumns1_2p1.get(1));
    assertEquals(45, model.getData().get(0).get(4).getNumericValue());
    assertEquals("Smurf", model.getData().get(0).get(5).getStringValue());
    assertEquals(6, uiModel.getColumns().size());
    final GridColumn<?> uiModelColumn1_2 = uiModel.getColumns().get(2);
    final GridColumn<?> uiModelColumn2_2 = uiModel.getColumns().get(3);
    final GridColumn<?> uiModelColumn3_2 = uiModel.getColumns().get(4);
    final GridColumn<?> uiModelColumn4_2 = uiModel.getColumns().get(5);
    assertEquals("$d : Address", uiModelColumn1_2.getHeaderMetaData().get(0).getTitle());
    assertEquals("$d : Address", uiModelColumn2_2.getHeaderMetaData().get(0).getTitle());
    assertEquals("$a : Applicant", uiModelColumn3_2.getHeaderMetaData().get(0).getTitle());
    assertEquals("$a : Applicant", uiModelColumn4_2.getHeaderMetaData().get(0).getTitle());
    assertTrue(uiModelColumn1_2 instanceof StringUiColumn);
    assertTrue(uiModelColumn2_2 instanceof StringUiColumn);
    assertTrue(uiModelColumn3_2 instanceof IntegerUiColumn);
    assertTrue(uiModelColumn4_2 instanceof StringUiColumn);
    assertEquals(4, uiModelColumn1_2.getIndex());
    assertEquals(5, uiModelColumn2_2.getIndex());
    assertEquals(2, uiModelColumn3_2.getIndex());
    assertEquals(3, uiModelColumn4_2.getIndex());
    assertEquals("NY", uiModel.getRow(0).getCells().get(uiModelColumn1_2.getIndex()).getValue().getValue());
    assertEquals("America", uiModel.getRow(0).getCells().get(uiModelColumn2_2.getIndex()).getValue().getValue());
    assertEquals(45, uiModel.getRow(0).getCells().get(uiModelColumn3_2.getIndex()).getValue().getValue());
    assertEquals("Smurf", uiModel.getRow(0).getCells().get(uiModelColumn4_2.getIndex()).getValue().getValue());
}
Also used : ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) StringUiColumn(org.drools.workbench.screens.guided.dtable.client.widget.table.columns.StringUiColumn) IntegerUiColumn(org.drools.workbench.screens.guided.dtable.client.widget.table.columns.IntegerUiColumn) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) Test(org.junit.Test)

Example 100 with Pattern52

use of org.drools.workbench.models.guided.dtable.shared.model.Pattern52 in project drools-wb by kiegroup.

the class ConditionColumnSynchronizerTest method testUpdate6.

@Test
public void testUpdate6() throws VetoException {
    // Single Pattern, single Condition
    final Pattern52 pattern = spy(boundApplicantPattern("$a"));
    final ConditionCol52 condition = spy(ageEqualsCondition());
    modelSynchronizer.appendColumn(pattern, condition);
    final Pattern52 editedPattern = boundApplicantPattern("$a");
    final ConditionCol52 editedCondition = ageEqualsCondition();
    editedCondition.setWidth(condition.getWidth());
    editedCondition.setOperator("!=");
    List<BaseColumnFieldDiff> diffs = modelSynchronizer.updateColumn(pattern, condition, editedPattern, editedCondition);
    assertEquals(1, diffs.size());
    verify(pattern).diff(editedPattern);
    verify(condition).diff(editedCondition);
    assertEquals(3, model.getExpandedColumns().size());
    assertEquals(1, model.getConditions().size());
    assertEquals(1, model.getConditionPattern("$a").getChildColumns().size());
    assertEquals(3, uiModel.getColumns().size());
    assertTrue(uiModel.getColumns().get(2) instanceof IntegerUiColumn);
    assertEquals(editedPattern.getBoundName() + " : " + editedPattern.getFactType(), uiModel.getColumns().get(2).getHeaderMetaData().get(0).getTitle());
    assertEquals(editedCondition.getHeader(), uiModel.getColumns().get(2).getHeaderMetaData().get(1).getTitle());
}
Also used : ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) BaseColumnFieldDiff(org.drools.workbench.models.guided.dtable.shared.model.BaseColumnFieldDiff) IntegerUiColumn(org.drools.workbench.screens.guided.dtable.client.widget.table.columns.IntegerUiColumn) Test(org.junit.Test)

Aggregations

Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)243 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)184 Test (org.junit.Test)180 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)92 LimitedEntryConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52)66 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)45 ActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52)39 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)34 ArrayList (java.util.ArrayList)31 ActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52)31 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)28 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)27 Path (org.uberfire.backend.vfs.Path)27 RawMVELEvaluator (org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator)26 PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)26 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)26 StringUiColumn (org.drools.workbench.screens.guided.dtable.client.widget.table.columns.StringUiColumn)25 IntegerUiColumn (org.drools.workbench.screens.guided.dtable.client.widget.table.columns.IntegerUiColumn)24 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)24 ModuleDataModelOracle (org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle)24