Search in sources :

Example 16 with ConversionResult

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

the class GuidedDecisionTableGeneratorListenerTest method conditionsTest.

private void conditionsTest(final String xlsFileName, final List<Object[]> expectedRows) {
    final ConversionResult result = new ConversionResult();
    final List<DataListener> listeners = new ArrayList<DataListener>();
    addModelField("org.test.Driver", "this", "org.test.Driver", DataType.TYPE_THIS);
    addModelField("org.test.Driver", "age", Integer.class.getName(), DataType.TYPE_NUMERIC_INTEGER);
    addModelField("org.test.Driver", "firstName", String.class.getName(), DataType.TYPE_STRING);
    addModelField("org.test.Driver", "surname", String.class.getName(), DataType.TYPE_STRING);
    addModelField("org.test.Vehicle", "this", "org.test.Vehicle", DataType.TYPE_THIS);
    addModelField("org.test.Vehicle", "make", String.class.getName(), DataType.TYPE_STRING);
    addModelField("org.test.Vehicle", "model", String.class.getName(), DataType.TYPE_STRING);
    final GuidedDecisionTableGeneratorListener listener = new GuidedDecisionTableGeneratorListener(result, dmo);
    listeners.add(listener);
    // Convert
    final ExcelParser parser = new ExcelParser(listeners);
    final InputStream is = this.getClass().getResourceAsStream(xlsFileName);
    try {
        parser.parseFile(is);
    } finally {
        try {
            is.close();
        } catch (IOException ioe) {
            fail(ioe.getMessage());
        }
    }
    // Check conversion results
    assertEquals(0, result.getMessages().size());
    // Check basics
    List<GuidedDecisionTable52> dtables = listener.getGuidedDecisionTables();
    assertNotNull(dtables);
    assertEquals(1, dtables.size());
    GuidedDecisionTable52 dtable = dtables.get(0);
    assertEquals("ConditionsTest", dtable.getTableName());
    assertEquals(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY, dtable.getTableFormat());
    // Check expanded columns
    List<BaseColumn> columns = dtable.getExpandedColumns();
    assertNotNull(columns);
    assertEquals(7, 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 BRLConditionVariableColumn);
    assertTrue(columns.get(4) instanceof BRLConditionVariableColumn);
    assertTrue(columns.get(5) instanceof BRLConditionVariableColumn);
    assertTrue(columns.get(6) instanceof BRLConditionVariableColumn);
    // Check individual condition columns
    assertEquals(2, dtable.getConditions().size());
    assertTrue(dtable.getConditions().get(0) instanceof BRLConditionColumn);
    assertTrue(dtable.getConditions().get(1) instanceof BRLConditionColumn);
    // Column 1
    BRLConditionColumn conditionCol0 = ((BRLConditionColumn) dtable.getConditions().get(0));
    assertEquals("Converted from ['Age of driver', 'First name', 'Surname']", conditionCol0.getHeader());
    assertEquals(3, 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("Driver", conditionCol0fp.getFactType());
    assertEquals(3, conditionCol0fp.getNumberOfConstraints());
    assertTrue(conditionCol0fp.getConstraint(0) instanceof SingleFieldConstraint);
    final SingleFieldConstraint conditionCol0fpsfc0 = (SingleFieldConstraint) conditionCol0fp.getConstraint(0);
    assertEquals("age", conditionCol0fpsfc0.getFieldName());
    assertEquals(">", conditionCol0fpsfc0.getOperator());
    assertEquals("param1", conditionCol0fpsfc0.getValue());
    assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol0fpsfc0.getConstraintValueType());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, conditionCol0fpsfc0.getFieldType());
    assertTrue(conditionCol0fp.getConstraint(1) instanceof SingleFieldConstraint);
    final SingleFieldConstraint conditionCol0fpsfc1 = (SingleFieldConstraint) conditionCol0fp.getConstraint(1);
    assertEquals("firstName", conditionCol0fpsfc1.getFieldName());
    assertEquals("==", conditionCol0fpsfc1.getOperator());
    assertEquals("param2", conditionCol0fpsfc1.getValue());
    assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol0fpsfc1.getConstraintValueType());
    assertEquals(DataType.TYPE_STRING, conditionCol0fpsfc1.getFieldType());
    assertTrue(conditionCol0fp.getConstraint(2) instanceof SingleFieldConstraint);
    final SingleFieldConstraint conditionCol0fpsfc2 = (SingleFieldConstraint) conditionCol0fp.getConstraint(2);
    assertEquals("surname", conditionCol0fpsfc2.getFieldName());
    assertEquals("==", conditionCol0fpsfc2.getOperator());
    assertEquals("param3", conditionCol0fpsfc2.getValue());
    assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol0fpsfc2.getConstraintValueType());
    assertEquals(DataType.TYPE_STRING, conditionCol0fpsfc2.getFieldType());
    // Column 1 - Variable 1
    BRLConditionVariableColumn conditionCol0param0 = conditionCol0.getChildColumns().get(0);
    assertEquals("param1", conditionCol0param0.getVarName());
    assertEquals("Age of driver", conditionCol0param0.getHeader());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, conditionCol0param0.getFieldType());
    assertEquals("Driver", conditionCol0param0.getFactType());
    assertEquals("age", conditionCol0param0.getFactField());
    // Column 1 - Variable 2
    BRLConditionVariableColumn conditionCol0param1 = conditionCol0.getChildColumns().get(1);
    assertEquals("param2", conditionCol0param1.getVarName());
    assertEquals("First name", conditionCol0param1.getHeader());
    assertEquals(DataType.TYPE_STRING, conditionCol0param1.getFieldType());
    assertEquals("Driver", conditionCol0param1.getFactType());
    assertEquals("firstName", conditionCol0param1.getFactField());
    // Column 1 - Variable 3
    BRLConditionVariableColumn conditionCol0param2 = conditionCol0.getChildColumns().get(2);
    assertEquals("param3", conditionCol0param2.getVarName());
    assertEquals("Surname", conditionCol0param2.getHeader());
    assertEquals(DataType.TYPE_STRING, conditionCol0param2.getFieldType());
    assertEquals("Driver", conditionCol0param2.getFactType());
    assertEquals("surname", conditionCol0param2.getFactField());
    // Column 2
    BRLConditionColumn conditionCol1 = ((BRLConditionColumn) dtable.getConditions().get(1));
    assertEquals("Converted from ['something', 'something']", conditionCol1.getHeader());
    assertEquals(2, conditionCol1.getChildColumns().size());
    List<IPattern> conditionCol1definition = conditionCol1.getDefinition();
    assertEquals(1, conditionCol1definition.size());
    assertTrue(conditionCol1definition.get(0) instanceof FactPattern);
    FactPattern conditionCol1fp = (FactPattern) conditionCol1definition.get(0);
    assertEquals("Vehicle", conditionCol1fp.getFactType());
    assertEquals(2, conditionCol1fp.getNumberOfConstraints());
    assertTrue(conditionCol1fp.getConstraint(0) instanceof SingleFieldConstraint);
    final SingleFieldConstraint conditionCol1fpsfc0 = (SingleFieldConstraint) conditionCol1fp.getConstraint(0);
    assertEquals("make", conditionCol1fpsfc0.getFieldName());
    assertEquals("==", conditionCol1fpsfc0.getOperator());
    assertEquals("param4", conditionCol1fpsfc0.getValue());
    assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol1fpsfc0.getConstraintValueType());
    assertEquals(DataType.TYPE_STRING, conditionCol1fpsfc0.getFieldType());
    assertTrue(conditionCol1fp.getConstraint(1) instanceof SingleFieldConstraint);
    final SingleFieldConstraint conditionCol1fpsfc1 = (SingleFieldConstraint) conditionCol1fp.getConstraint(1);
    assertEquals("model", conditionCol1fpsfc1.getFieldName());
    assertEquals("==", conditionCol1fpsfc1.getOperator());
    assertEquals("param5", conditionCol1fpsfc1.getValue());
    assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol1fpsfc1.getConstraintValueType());
    assertEquals(DataType.TYPE_STRING, conditionCol1fpsfc1.getFieldType());
    // Column 2 - Variable 1
    BRLConditionVariableColumn conditionCol1param0 = conditionCol1.getChildColumns().get(0);
    assertEquals("param4", conditionCol1param0.getVarName());
    assertEquals("something", conditionCol1param0.getHeader());
    assertEquals(DataType.TYPE_STRING, conditionCol1param0.getFieldType());
    assertEquals("Vehicle", conditionCol1param0.getFactType());
    assertEquals("make", conditionCol1param0.getFactField());
    // Column 2 - Variable 2
    BRLConditionVariableColumn conditionCol1param1 = conditionCol1.getChildColumns().get(1);
    assertEquals("param5", conditionCol1param1.getVarName());
    assertEquals("something", conditionCol1param1.getHeader());
    assertEquals(DataType.TYPE_STRING, conditionCol1param1.getFieldType());
    assertEquals("Vehicle", conditionCol1param1.getFactType());
    assertEquals("model", conditionCol1param1.getFactField());
    // Check data
    assertEquals(2, dtable.getData().size());
    assertNotNull(expectedRows);
    assertTrue(expectedRows.size() == 2);
    for (int i = 0; i < 2; i++) {
        assertTrue(isRowEquivalent(expectedRows.get(i), dtable.getData().get(i)));
    }
}
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) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) IOException(java.io.IOException) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BigInteger(java.math.BigInteger) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) ConversionResult(org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) ExcelParser(org.drools.decisiontable.parser.xls.ExcelParser) DataListener(org.drools.template.parser.DataListener) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)

Example 17 with ConversionResult

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

the class GuidedDecisionTableGeneratorListenerTest method testMissingTemplateKeyValues_StringFields.

@Test
public // https://issues.jboss.org/browse/GUVNOR-2030
void testMissingTemplateKeyValues_StringFields() {
    final ConversionResult result = new ConversionResult();
    final List<DataListener> listeners = new ArrayList<DataListener>();
    final GuidedDecisionTableGeneratorListener listener = new GuidedDecisionTableGeneratorListener(result, dmo);
    listeners.add(listener);
    // Convert
    final ExcelParser parser = new ExcelParser(listeners);
    final InputStream is = this.getClass().getResourceAsStream("GUVNOR-2030.xls");
    try {
        parser.parseFile(is);
    } finally {
        try {
            is.close();
        } catch (IOException ioe) {
            fail(ioe.getMessage());
        }
    }
    // 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("asd", dtable.getTableName());
    assertEquals(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY, dtable.getTableFormat());
    // Check expanded columns
    List<BaseColumn> columns = dtable.getExpandedColumns();
    assertNotNull(columns);
    assertEquals(6, 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 BRLConditionVariableColumn);
    assertTrue(columns.get(4) instanceof BRLConditionVariableColumn);
    assertTrue(columns.get(5) instanceof BRLActionVariableColumn);
    // Check individual condition columns
    assertEquals(1, dtable.getConditions().size());
    assertTrue(dtable.getConditions().get(0) instanceof BRLConditionColumn);
    // Column 1
    BRLConditionColumn conditionCol0 = ((BRLConditionColumn) dtable.getConditions().get(0));
    assertEquals("Converted from ['Rule disabler', 'CovenanteeId', 'blah']", conditionCol0.getHeader());
    assertEquals(3, 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("Transaction", conditionCol0fp.getFactType());
    assertEquals(3, conditionCol0fp.getNumberOfConstraints());
    assertTrue(conditionCol0fp.getConstraint(0) instanceof SingleFieldConstraint);
    final SingleFieldConstraint conditionCol0fpsfc0 = (SingleFieldConstraint) conditionCol0fp.getConstraint(0);
    assertEquals("isDisabled(\"asd\")", conditionCol0fpsfc0.getFieldName());
    assertEquals("==", conditionCol0fpsfc0.getOperator());
    assertEquals("param1", conditionCol0fpsfc0.getValue());
    assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol0fpsfc0.getConstraintValueType());
    assertEquals("java.lang.String", conditionCol0fpsfc0.getFieldType());
    assertTrue(conditionCol0fp.getConstraint(1) instanceof SingleFieldConstraint);
    final SingleFieldConstraint conditionCol0fpsfc1 = (SingleFieldConstraint) conditionCol0fp.getConstraint(1);
    assertEquals("getClientCovenanteeId()", conditionCol0fpsfc1.getFieldName());
    assertEquals("==", conditionCol0fpsfc1.getOperator());
    assertEquals("param2", conditionCol0fpsfc1.getValue());
    assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol0fpsfc1.getConstraintValueType());
    assertEquals("java.lang.String", conditionCol0fpsfc1.getFieldType());
    assertTrue(conditionCol0fp.getConstraint(2) instanceof SingleFieldConstraint);
    final SingleFieldConstraint conditionCol0fpsfc2 = (SingleFieldConstraint) conditionCol0fp.getConstraint(2);
    assertEquals("isBlacklisted(\"asd\")", conditionCol0fpsfc2.getFieldName());
    assertEquals("==", conditionCol0fpsfc2.getOperator());
    assertEquals("param3", conditionCol0fpsfc2.getValue());
    assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol0fpsfc2.getConstraintValueType());
    assertEquals("java.lang.String", conditionCol0fpsfc2.getFieldType());
    // Column 1 - Variable 1
    BRLConditionVariableColumn conditionCol0param0 = conditionCol0.getChildColumns().get(0);
    assertEquals("param1", conditionCol0param0.getVarName());
    assertEquals("Rule disabler", conditionCol0param0.getHeader());
    assertEquals(DataType.TYPE_STRING, conditionCol0param0.getFieldType());
    assertEquals("java.lang.String", conditionCol0param0.getFactType());
    assertEquals("isDisabled(\"asd\")", conditionCol0param0.getFactField());
    // Column 1 - Variable 2
    BRLConditionVariableColumn conditionCol0param1 = conditionCol0.getChildColumns().get(1);
    assertEquals("param2", conditionCol0param1.getVarName());
    assertEquals("CovenanteeId", conditionCol0param1.getHeader());
    assertEquals(DataType.TYPE_STRING, conditionCol0param1.getFieldType());
    assertEquals("java.lang.String", conditionCol0param1.getFactType());
    assertEquals("getClientCovenanteeId()", conditionCol0param1.getFactField());
    // Column 1 - Variable 3
    BRLConditionVariableColumn conditionCol0param2 = conditionCol0.getChildColumns().get(2);
    assertEquals("param3", conditionCol0param2.getVarName());
    assertEquals("blah", conditionCol0param2.getHeader());
    assertEquals(DataType.TYPE_STRING, conditionCol0param2.getFieldType());
    assertEquals("java.lang.String", conditionCol0param2.getFactType());
    assertEquals("isBlacklisted(\"asd\")", conditionCol0param2.getFactField());
    // Check individual action columns
    assertEquals(1, dtable.getActionCols().size());
    assertTrue(dtable.getActionCols().get(0) instanceof BRLActionColumn);
    // Column 2
    BRLActionColumn actionCol0 = ((BRLActionColumn) dtable.getActionCols().get(0));
    assertEquals("Converted from ['Risk level']", actionCol0.getHeader());
    assertEquals(1, actionCol0.getChildColumns().size());
    List<IAction> actionCol0definition = actionCol0.getDefinition();
    assertEquals(1, actionCol0definition.size());
    assertTrue(actionCol0definition.get(0) instanceof FreeFormLine);
    FreeFormLine actionCol0ffl = (FreeFormLine) actionCol0definition.get(0);
    assertEquals("riskIndex.setRisk(\"asd\", @{param4});", actionCol0ffl.getText());
    // Check data
    assertEquals(1, dtable.getData().size());
    assertTrue(isRowEquivalent(new Object[] { 1, "asd", "false", "", "true", "0" }, dtable.getData().get(0)));
}
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) ArrayList(java.util.ArrayList) 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) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) ExcelParser(org.drools.decisiontable.parser.xls.ExcelParser) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) IAction(org.drools.workbench.models.datamodel.rule.IAction) InputStream(java.io.InputStream) IOException(java.io.IOException) ConversionResult(org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) DataListener(org.drools.template.parser.DataListener) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Example 18 with ConversionResult

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

the class GuidedDecisionTableGeneratorListenerTest method testActions.

@Test
public void testActions() {
    final ConversionResult result = new ConversionResult();
    final List<DataListener> listeners = new ArrayList<DataListener>();
    final GuidedDecisionTableGeneratorListener listener = new GuidedDecisionTableGeneratorListener(result, dmo);
    listeners.add(listener);
    // Convert
    final ExcelParser parser = new ExcelParser(listeners);
    final InputStream is = this.getClass().getResourceAsStream("Actions.xls");
    try {
        parser.parseFile(is);
    } finally {
        try {
            is.close();
        } catch (IOException ioe) {
            fail(ioe.getMessage());
        }
    }
    // Check conversion results
    assertEquals(0, result.getMessages().size());
    // Check basics
    List<GuidedDecisionTable52> dtables = listener.getGuidedDecisionTables();
    assertNotNull(dtables);
    assertEquals(1, dtables.size());
    GuidedDecisionTable52 dtable = dtables.get(0);
    assertEquals("ActionsTest", dtable.getTableName());
    assertEquals(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY, dtable.getTableFormat());
    // Check expanded columns
    List<BaseColumn> columns = dtable.getExpandedColumns();
    assertNotNull(columns);
    assertEquals(7, columns.size());
    assertTrue(columns.get(0) instanceof RowNumberCol52);
    assertTrue(columns.get(1) instanceof DescriptionCol52);
    assertTrue(columns.get(2) instanceof BRLActionVariableColumn);
    assertTrue(columns.get(3) instanceof BRLActionVariableColumn);
    assertTrue(columns.get(4) instanceof BRLActionVariableColumn);
    assertTrue(columns.get(5) instanceof BRLActionVariableColumn);
    assertTrue(columns.get(6) instanceof BRLActionVariableColumn);
    // Check individual action columns
    assertEquals(4, dtable.getActionCols().size());
    assertTrue(dtable.getActionCols().get(0) instanceof BRLActionColumn);
    assertTrue(dtable.getActionCols().get(1) instanceof BRLActionColumn);
    assertTrue(dtable.getActionCols().get(2) instanceof BRLActionColumn);
    assertTrue(dtable.getActionCols().get(3) instanceof BRLActionColumn);
    // Column 1
    BRLActionColumn actionCol0 = ((BRLActionColumn) dtable.getActionCols().get(0));
    assertEquals("Converted from ['Multi-parameters', 'Multi-parameters']", actionCol0.getHeader());
    assertEquals(2, actionCol0.getChildColumns().size());
    List<IAction> actionCol0definition = actionCol0.getDefinition();
    assertEquals(1, actionCol0definition.size());
    assertTrue(actionCol0definition.get(0) instanceof FreeFormLine);
    FreeFormLine actionCol0ffl = (FreeFormLine) actionCol0definition.get(0);
    assertEquals("policy.setBasePrice(@{param1}, @{param2});", actionCol0ffl.getText());
    // Column 1 - Variable 1
    BRLActionVariableColumn actionCol0param0 = actionCol0.getChildColumns().get(0);
    assertEquals("param1", actionCol0param0.getVarName());
    assertEquals("Multi-parameters", actionCol0param0.getHeader());
    assertEquals(DataType.TYPE_OBJECT, actionCol0param0.getFieldType());
    assertNull(actionCol0param0.getFactType());
    assertNull(actionCol0param0.getFactField());
    // Column 1 - Variable 2
    BRLActionVariableColumn actionCol0param1 = actionCol0.getChildColumns().get(1);
    assertEquals("param2", actionCol0param1.getVarName());
    assertEquals("Multi-parameters", actionCol0param1.getHeader());
    assertEquals(DataType.TYPE_OBJECT, actionCol0param1.getFieldType());
    assertNull(actionCol0param1.getFactType());
    assertNull(actionCol0param1.getFactField());
    // Column 2
    BRLActionColumn actionCol1 = ((BRLActionColumn) dtable.getActionCols().get(1));
    assertEquals("Converted from ['Single-parameter']", actionCol1.getHeader());
    assertEquals(1, actionCol1.getChildColumns().size());
    List<IAction> actionCol1definition = actionCol1.getDefinition();
    assertEquals(1, actionCol1definition.size());
    assertTrue(actionCol1definition.get(0) instanceof FreeFormLine);
    FreeFormLine actionCol1ffl = (FreeFormLine) actionCol1definition.get(0);
    assertEquals("policy.setSmurf(@{param3});", actionCol1ffl.getText());
    // Column 2 - Variable 1
    BRLActionVariableColumn actionCol1param0 = actionCol1.getChildColumns().get(0);
    assertEquals("param3", actionCol1param0.getVarName());
    assertEquals("Single-parameter", actionCol1param0.getHeader());
    assertEquals(DataType.TYPE_OBJECT, actionCol1param0.getFieldType());
    assertNull(actionCol1param0.getFactType());
    assertNull(actionCol1param0.getFactField());
    // Column 3
    BRLActionColumn actionCol2 = ((BRLActionColumn) dtable.getActionCols().get(2));
    assertEquals("Converted from ['Log-single-parameter']", actionCol2.getHeader());
    assertEquals(1, actionCol2.getChildColumns().size());
    List<IAction> actionCol2definition = actionCol2.getDefinition();
    assertEquals(1, actionCol2definition.size());
    assertTrue(actionCol2definition.get(0) instanceof FreeFormLine);
    FreeFormLine actionCol2ffl = (FreeFormLine) actionCol2definition.get(0);
    assertEquals("System.out.println(\"@{param4}\");", actionCol2ffl.getText());
    // Column 3 - Variable 1
    BRLActionVariableColumn actionCol2param0 = actionCol2.getChildColumns().get(0);
    assertEquals("param4", actionCol2param0.getVarName());
    assertEquals("Log-single-parameter", actionCol2param0.getHeader());
    assertEquals(DataType.TYPE_OBJECT, actionCol2param0.getFieldType());
    assertNull(actionCol2param0.getFactType());
    assertNull(actionCol2param0.getFactField());
    // Column 4
    BRLActionColumn actionCol3 = ((BRLActionColumn) dtable.getActionCols().get(3));
    assertEquals("Converted from ['Zero-parameters']", actionCol3.getHeader());
    assertEquals(1, actionCol3.getChildColumns().size());
    List<IAction> actionCol3definition = actionCol3.getDefinition();
    assertEquals(1, actionCol3definition.size());
    assertTrue(actionCol3definition.get(0) instanceof FreeFormLine);
    FreeFormLine actionCol3ffl = (FreeFormLine) actionCol3definition.get(0);
    assertEquals("System.out.println(\"Woot\");", actionCol3ffl.getText());
    // Column 3 - Variable 1
    BRLActionVariableColumn actionCol3param0 = actionCol3.getChildColumns().get(0);
    assertEquals("", actionCol3param0.getVarName());
    assertEquals("Zero-parameters", actionCol3param0.getHeader());
    assertEquals(DataType.TYPE_BOOLEAN, actionCol3param0.getFieldType());
    assertNull(actionCol3param0.getFactType());
    assertNull(actionCol3param0.getFactField());
    // Check data
    assertEquals(2, dtable.getData().size());
    assertTrue(isRowEquivalent(new Object[] { 1, "Row 1", "10", "20", "30", "hello", true }, dtable.getData().get(0)));
    assertTrue(isRowEquivalent(new Object[] { 2, "Row 2", "50", "60", "70", "goodbye", false }, dtable.getData().get(1)));
}
Also used : GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) IAction(org.drools.workbench.models.datamodel.rule.IAction) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ConversionResult(org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) ExcelParser(org.drools.decisiontable.parser.xls.ExcelParser) DataListener(org.drools.template.parser.DataListener) 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) Test(org.junit.Test)

Example 19 with ConversionResult

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

the class GuidedDecisionTableGeneratorListenerTest method testDurationWarnings.

@Test
public void testDurationWarnings() {
    final ConversionResult result = new ConversionResult();
    final List<DataListener> listeners = new ArrayList<DataListener>();
    final GuidedDecisionTableGeneratorListener listener = new GuidedDecisionTableGeneratorListener(result, dmo);
    listeners.add(listener);
    // Convert
    final ExcelParser parser = new ExcelParser(listeners);
    final InputStream is = this.getClass().getResourceAsStream("DurationWarnings.xls");
    try {
        parser.parseFile(is);
    } finally {
        try {
            is.close();
        } catch (IOException ioe) {
            fail(ioe.getMessage());
        }
    }
    // Check conversion results
    assertEquals(2, result.getMessages().size());
    assertEquals(ConversionMessageType.WARNING, result.getMessages().get(0).getMessageType());
    assertFalse(result.getMessages().get(0).getMessage().indexOf("Duration is not an long literal, in cell C7") == -1);
    assertEquals(ConversionMessageType.WARNING, result.getMessages().get(1).getMessageType());
    assertFalse(result.getMessages().get(1).getMessage().indexOf("Duration is not an long literal, in cell C8") == -1);
    // Check basics
    List<GuidedDecisionTable52> dtables = listener.getGuidedDecisionTables();
    assertNotNull(dtables);
    assertEquals(1, dtables.size());
    GuidedDecisionTable52 dtable = dtables.get(0);
    assertEquals("DurationWarningsTest", dtable.getTableName());
    assertEquals(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY, dtable.getTableFormat());
    // Check expanded columns
    List<BaseColumn> columns = dtable.getExpandedColumns();
    assertNotNull(columns);
    assertEquals(3, columns.size());
    assertTrue(columns.get(0) instanceof RowNumberCol52);
    assertTrue(columns.get(1) instanceof DescriptionCol52);
    assertTrue(columns.get(2) instanceof AttributeCol52);
    // Check attribute column
    AttributeCol52 attrCol2 = ((AttributeCol52) columns.get(2));
    assertEquals(GuidedDecisionTable52.DURATION_ATTR, attrCol2.getAttribute());
    assertFalse(attrCol2.isUseRowNumber());
    assertFalse(attrCol2.isReverseOrder());
    // Check data
    assertEquals(2, dtable.getData().size());
    assertTrue(isRowEquivalent(new Object[] { 1, "Rule 1", 0 }, dtable.getData().get(0)));
    assertTrue(isRowEquivalent(new Object[] { 2, "Rule 2", 0 }, dtable.getData().get(1)));
}
Also used : GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) AttributeCol52(org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52) ConversionResult(org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) ExcelParser(org.drools.decisiontable.parser.xls.ExcelParser) DataListener(org.drools.template.parser.DataListener) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Example 20 with ConversionResult

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

the class GuidedDecisionTableGeneratorListenerTest method testRowDescriptions.

@Test
public void testRowDescriptions() {
    final ConversionResult result = new ConversionResult();
    final List<DataListener> listeners = new ArrayList<DataListener>();
    final GuidedDecisionTableGeneratorListener listener = new GuidedDecisionTableGeneratorListener(result, dmo);
    listeners.add(listener);
    // Convert
    final ExcelParser parser = new ExcelParser(listeners);
    final InputStream is = this.getClass().getResourceAsStream("MultipleRuleTables.xls");
    try {
        parser.parseFile(is);
    } finally {
        try {
            is.close();
        } catch (IOException ioe) {
            fail(ioe.getMessage());
        }
    }
    // Check conversion results
    assertEquals(0, result.getMessages().size());
    // Check basics
    final List<GuidedDecisionTable52> dtables = listener.getGuidedDecisionTables();
    assertNotNull(dtables);
    assertEquals(2, dtables.size());
    GuidedDecisionTable52 dtable = dtables.get(0);
    assertEquals(2, dtable.getData().size());
    assertEquals("Created from row 7", dtable.getData().get(0).get(1).getStringValue());
    assertEquals("Row 2", dtable.getData().get(1).get(1).getStringValue());
    dtable = dtables.get(1);
    assertEquals(2, dtable.getData().size());
    assertEquals("Row 1", dtable.getData().get(0).get(1).getStringValue());
    assertEquals("Created from row 16", dtable.getData().get(1).get(1).getStringValue());
}
Also used : ConversionResult(org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ExcelParser(org.drools.decisiontable.parser.xls.ExcelParser) DataListener(org.drools.template.parser.DataListener) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

ConversionResult (org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult)30 Test (org.junit.Test)27 InputStream (java.io.InputStream)26 IOException (java.io.IOException)23 ArrayList (java.util.ArrayList)23 ExcelParser (org.drools.decisiontable.parser.xls.ExcelParser)23 DataListener (org.drools.template.parser.DataListener)23 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)21 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)17 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)17 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)17 BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)11 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)10 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)10 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)10 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)9 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)9 IAction (org.drools.workbench.models.datamodel.rule.IAction)9 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)9 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)9