Search in sources :

Example 61 with BRLActionColumn

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

the class BRLActionColumnPluginTest method testSetupEditingColWhenColumnIsNew.

@Test
public void testSetupEditingColWhenColumnIsNew() throws Exception {
    final BRLActionColumn column = mock(BRLActionColumn.class);
    doReturn(true).when(plugin).isNewColumn();
    doReturn(column).when(plugin).newBRLActionColumn();
    plugin.setupEditingCol();
    verify(column, never()).setHeader(any());
    verify(column, never()).setDefinition(any());
    verify(column, never()).setChildColumns(any());
    verify(column, never()).setHideColumn(anyBoolean());
    assertEquals(column, plugin.editingCol());
}
Also used : BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) Test(org.junit.Test)

Example 62 with BRLActionColumn

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

the class BRLActionColumnPluginTest method testGenerateColumnWhenColumnIsNotNew.

@Test
public void testGenerateColumnWhenColumnIsNotNew() throws Exception {
    final BRLActionColumn originalCol = mock(BRLActionColumn.class);
    final GuidedDecisionTable52 model = mock(GuidedDecisionTable52.class);
    when(model.getActionCols()).thenReturn(new ArrayList<>());
    when(presenter.getModel()).thenReturn(model);
    when(editingCol.getHeader()).thenReturn("header");
    when(plugin.originalCol()).thenReturn(originalCol);
    when(plugin.isNewColumn()).thenReturn(false);
    final Boolean success = plugin.generateColumn();
    assertTrue(success);
    verify(plugin).getDefinedVariables(any());
    verify(editingCol).setDefinition(any());
    verify(presenter).updateColumn(originalCol, editingCol);
    verify(translationService, never()).format(any());
}
Also used : BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) Mockito.anyBoolean(org.mockito.Mockito.anyBoolean) Test(org.junit.Test)

Example 63 with BRLActionColumn

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

the class ConditionColumnSynchronizerTest method checkConditionCannotBeUpdatedWhenFieldBindingIsUsedInAction.

@Test
public void checkConditionCannotBeUpdatedWhenFieldBindingIsUsedInAction() 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 {
        final Pattern52 editedPattern = boundApplicantPattern("$a");
        final ConditionCol52 editedCondition = ageEqualsCondition();
        editedCondition.setBinding("$age2");
        modelSynchronizer.updateColumn(pattern, condition, editedPattern, editedCondition);
        fail("Update 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(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) VetoUpdatePatternInUseException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoUpdatePatternInUseException) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Example 64 with BRLActionColumn

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

the class ExtendedGuidedDecisionTableBuilder method withActionBRLFragment.

public AbstractDecisionTableBuilder withActionBRLFragment() {
    final BRLActionColumn brlActionColumn = createBRLActionColumn();
    ArrayList<BRLActionVariableColumn> childColumns = new ArrayList<>();
    childColumns.add(new BRLActionVariableColumn());
    brlActionColumn.setChildColumns(childColumns);
    table.getActionCols().add(brlActionColumn);
    return this;
}
Also used : BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) ArrayList(java.util.ArrayList) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)

Example 65 with BRLActionColumn

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

the class GuidedDecisionTableGeneratorListenerTest method checkConversionWithBigMaths.

private void checkConversionWithBigMaths(final ConversionResult result, final GuidedDecisionTableGeneratorListener listener, final Supplier<String> expectedDataType, final Supplier<Object> expectedDataValueRow0, final Supplier<Object> expectedDataValueRow1) {
    // Check conversion results
    assertEquals(0, result.getMessages().size());
    // Check basics
    final List<GuidedDecisionTable52> dtables = listener.getGuidedDecisionTables();
    assertNotNull(dtables);
    assertEquals(1, dtables.size());
    GuidedDecisionTable52 dtable = dtables.get(0);
    assertEquals("HelloWorld1", dtable.getTableName());
    assertEquals(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY, dtable.getTableFormat());
    // Check expanded columns
    List<BaseColumn> columns = dtable.getExpandedColumns();
    assertNotNull(columns);
    assertEquals(8, columns.size());
    assertTrue(columns.get(0) instanceof RowNumberCol52);
    assertTrue(columns.get(1) instanceof DescriptionCol52);
    assertTrue(columns.get(2) instanceof BRLConditionVariableColumn);
    assertTrue(columns.get(3) instanceof BRLActionVariableColumn);
    assertTrue(columns.get(4) instanceof BRLActionVariableColumn);
    assertTrue(columns.get(5) instanceof BRLActionVariableColumn);
    assertTrue(columns.get(6) instanceof BRLActionVariableColumn);
    assertTrue(columns.get(7) instanceof BRLActionVariableColumn);
    // Check individual condition columns
    assertEquals(1, dtable.getConditions().size());
    assertTrue(dtable.getConditions().get(0) instanceof BRLConditionColumn);
    BRLConditionColumn conditionCol0 = ((BRLConditionColumn) dtable.getConditions().get(0));
    assertEquals("Converted from ['Status']", conditionCol0.getHeader());
    assertEquals(1, conditionCol0.getChildColumns().size());
    List<IPattern> conditionCol0definition = conditionCol0.getDefinition();
    assertEquals(1, conditionCol0definition.size());
    assertTrue(conditionCol0definition.get(0) instanceof FactPattern);
    FactPattern conditionCol0fp = (FactPattern) conditionCol0definition.get(0);
    assertEquals("Message", conditionCol0fp.getFactType());
    assertEquals(1, conditionCol0fp.getNumberOfConstraints());
    // Field Constraint 1
    assertTrue(conditionCol0fp.getConstraint(0) instanceof SingleFieldConstraint);
    final SingleFieldConstraint conditionCol0fpsfc0 = (SingleFieldConstraint) conditionCol0fp.getConstraint(0);
    assertEquals("status", conditionCol0fpsfc0.getFieldName());
    assertEquals("==", conditionCol0fpsfc0.getOperator());
    assertEquals("param1", conditionCol0fpsfc0.getValue());
    assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol0fpsfc0.getConstraintValueType());
    assertEquals(DataType.TYPE_STRING, conditionCol0fpsfc0.getFieldType());
    // Field Constraint 1 - Variable 1
    BRLConditionVariableColumn conditionCol0param0 = conditionCol0.getChildColumns().get(0);
    assertEquals("param1", conditionCol0param0.getVarName());
    assertEquals("Status", conditionCol0param0.getHeader());
    assertEquals(DataType.TYPE_STRING, conditionCol0param0.getFieldType());
    assertEquals("Message", conditionCol0param0.getFactType());
    assertEquals("status", conditionCol0param0.getFactField());
    // Check individual action columns
    assertEquals(3, dtable.getActionCols().size());
    // Action 1
    assertTrue(dtable.getActionCols().get(0) instanceof BRLActionColumn);
    BRLActionColumn actionCol0 = ((BRLActionColumn) dtable.getActionCols().get(0));
    assertEquals("Converted from ['Print out message?']", actionCol0.getHeader());
    assertEquals(1, actionCol0.getChildColumns().size());
    List<IAction> actionCol0definition = actionCol0.getDefinition();
    assertEquals(1, actionCol0definition.size());
    assertTrue(actionCol0definition.get(0) instanceof FreeFormLine);
    FreeFormLine actionCol0ffl0 = (FreeFormLine) actionCol0definition.get(0);
    assertEquals("System.out.println(m.getMessage());", actionCol0ffl0.getText());
    // Action 2
    BRLActionColumn actionCol1 = ((BRLActionColumn) dtable.getActionCols().get(1));
    assertEquals("Converted from ['Set message', 'Set status', 'Set rate']", actionCol1.getHeader());
    assertEquals(3, actionCol1.getChildColumns().size());
    List<IAction> actionCol1definition = actionCol1.getDefinition();
    assertEquals(1, actionCol1definition.size());
    assertTrue(actionCol1definition.get(0) instanceof ActionSetField);
    ActionSetField actionCol1asf0 = (ActionSetField) actionCol1definition.get(0);
    assertEquals("m", actionCol1asf0.getVariable());
    ActionFieldValue[] actionCol1asf0afvs = actionCol1asf0.getFieldValues();
    assertEquals(3, actionCol1asf0afvs.length);
    ActionFieldValue actionCol1asf0afv0 = actionCol1asf0afvs[0];
    assertEquals("message", actionCol1asf0afv0.getField());
    assertEquals("param2", actionCol1asf0afv0.getValue());
    assertEquals(FieldNatureType.TYPE_TEMPLATE, actionCol1asf0afv0.getNature());
    assertEquals(DataType.TYPE_STRING, actionCol1asf0afv0.getType());
    ActionFieldValue actionCol1asf0afv1 = actionCol1asf0afvs[1];
    assertEquals("status", actionCol1asf0afv1.getField());
    assertEquals("param3", actionCol1asf0afv1.getValue());
    assertEquals(FieldNatureType.TYPE_TEMPLATE, actionCol1asf0afv1.getNature());
    assertEquals(DataType.TYPE_STRING, actionCol1asf0afv1.getType());
    // Action 1 - Variable 1
    BRLActionVariableColumn actionCol0param0 = actionCol0.getChildColumns().get(0);
    assertEquals("", actionCol0param0.getVarName());
    assertEquals("Print out message?", actionCol0param0.getHeader());
    assertEquals(DataType.TYPE_BOOLEAN, actionCol0param0.getFieldType());
    assertNull(actionCol0param0.getFactType());
    assertNull(actionCol0param0.getFactField());
    assertTrue(dtable.getActionCols().get(0) instanceof BRLActionColumn);
    // Action 2 - Variable 1
    BRLActionVariableColumn actionCol1param0 = actionCol1.getChildColumns().get(0);
    assertEquals("param2", actionCol1param0.getVarName());
    assertEquals("Set message", actionCol1param0.getHeader());
    assertEquals(DataType.TYPE_STRING, actionCol1param0.getFieldType());
    assertEquals("Message", actionCol1param0.getFactType());
    assertEquals("message", actionCol1param0.getFactField());
    // Action 2 - Variable 2
    BRLActionVariableColumn actionCol1param1 = actionCol1.getChildColumns().get(1);
    assertEquals("param3", actionCol1param1.getVarName());
    assertEquals("Set status", actionCol1param1.getHeader());
    assertEquals(DataType.TYPE_STRING, actionCol1param1.getFieldType());
    assertEquals("Message", actionCol1param1.getFactType());
    assertEquals("status", actionCol1param1.getFactField());
    // Action 2 - Variable 3
    BRLActionVariableColumn actionCol1param2 = actionCol1.getChildColumns().get(2);
    assertEquals("param4", actionCol1param2.getVarName());
    assertEquals("Set rate", actionCol1param2.getHeader());
    assertEquals(expectedDataType.get(), actionCol1param2.getFieldType());
    assertEquals("Message", actionCol1param2.getFactType());
    assertEquals("rate", actionCol1param2.getFactField());
    // Check data
    assertEquals(2, dtable.getData().size());
    assertTrue(isRowEquivalent(new Object[] { 1, "Hello World", "Message.HELLO", false, "Goodbye cruel world", "Message.GOODBYE", expectedDataValueRow0.get(), "m" }, dtable.getData().get(0)));
    assertTrue(isRowEquivalent(new Object[] { 2, "Goodbye", "Message.GOODBYE", false, "", "", expectedDataValueRow1.get(), "m" }, dtable.getData().get(1)));
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) IPattern(org.drools.workbench.models.datamodel.rule.IPattern) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) IAction(org.drools.workbench.models.datamodel.rule.IAction) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)

Aggregations

BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)71 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)51 Test (org.junit.Test)51 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)31 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)24 ArrayList (java.util.ArrayList)21 IAction (org.drools.workbench.models.datamodel.rule.IAction)21 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)19 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)19 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)18 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)17 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)16 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)16 ActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52)15 BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)15 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)13 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)13 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)13 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)11 IOException (java.io.IOException)9