Search in sources :

Example 6 with VetoDeletePatternInUseException

use of org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoDeletePatternInUseException in project drools-wb by kiegroup.

the class BRLConditionColumnSynchronizerTest method checkBRLFragmentConditionCannotBeDeletedWhenFieldBindingIsUsedInAction.

@Test
public void checkBRLFragmentConditionCannotBeDeletedWhenFieldBindingIsUsedInAction() 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 {
        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.getChildColumns().get(0), model.getExpandedColumns().get(3));
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) VetoException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoException) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) ActionCallMethod(org.drools.workbench.models.datamodel.rule.ActionCallMethod) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn) 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 7 with VetoDeletePatternInUseException

use of org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoDeletePatternInUseException in project drools-wb by kiegroup.

the class ConditionColumnSynchronizerTest method checkConditionCannotBeDeletedWithSingleChildColumnWithAction.

@Test
public void checkConditionCannotBeDeletedWithSingleChildColumnWithAction() throws VetoException {
    final Pattern52 pattern = boundApplicantPattern("$a");
    final ConditionCol52 condition = ageEqualsCondition();
    final ActionCol52 action = actionUpdatePattern("$a");
    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, 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) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) 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)

Aggregations

VetoDeletePatternInUseException (org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoDeletePatternInUseException)7 VetoException (org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoException)5 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)4 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)4 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)4 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)4 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)4 Test (org.junit.Test)4 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)2 ActionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionCol52)2 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)2 BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 Command (com.google.gwt.user.client.Command)1 FlowPanel (com.google.gwt.user.client.ui.FlowPanel)1 HorizontalPanel (com.google.gwt.user.client.ui.HorizontalPanel)1 Label (com.google.gwt.user.client.ui.Label)1 VerticalPanel (com.google.gwt.user.client.ui.VerticalPanel)1 Widget (com.google.gwt.user.client.ui.Widget)1 ArrayList (java.util.ArrayList)1