Search in sources :

Example 11 with ResultSetCompareAction

use of org.pentaho.actionsequence.dom.actions.ResultSetCompareAction in project pentaho-platform by pentaho.

the class ResultSetCompareComponentTest method validation_fails_without_compareColumnNumber.

@Test
public void validation_fails_without_compareColumnNumber() {
    ResultSetCompareComponent rscc = createResultSetCompareComponent();
    IPentahoResultSet rs = Mockito.mock(IPentahoResultSet.class);
    ResultSetCompareAction resultSetCompareAction = createResultSetCompareAction(rs, rs, null, false, true);
    rscc.setActionDefinition(resultSetCompareAction);
    int actualValidateResult = rscc.validate();
    assertEquals(IRuntimeContext.RUNTIME_CONTEXT_VALIDATE_FAIL, actualValidateResult);
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) ResultSetCompareAction(org.pentaho.actionsequence.dom.actions.ResultSetCompareAction) Test(org.junit.Test)

Example 12 with ResultSetCompareAction

use of org.pentaho.actionsequence.dom.actions.ResultSetCompareAction in project pentaho-platform by pentaho.

the class ResultSetCompareComponent method compareEquals.

private boolean compareEquals(final IPentahoResultSet rs1, final IPentahoResultSet rs2, final int compareCol, boolean outputMismatches, final boolean stopOnError) {
    int sourceRowCount = rs1.getRowCount();
    int sourceColCount = rs1.getColumnCount();
    int compRowCount = rs2.getRowCount();
    int compColCount = rs2.getColumnCount();
    StringBuffer outputBuf = new StringBuffer();
    if (!outputMismatches) {
        if (sourceRowCount != compRowCount) {
            // $NON-NLS-1$
            error(Messages.getInstance().getErrorString("ResultSetCompareComponent.ERROR_0006_RESULTSETS_ROWCOUNT_WRONG"));
            return false;
        }
        if (sourceColCount != compColCount) {
            error(Messages.getInstance().getErrorString(// $NON-NLS-1$
            "ResultSetCompareComponent.ERROR_0007_RESULTSETS_COLUMNCOUNT_WRONG"));
            return false;
        }
    }
    if (compareCol > sourceColCount) {
        // $NON-NLS-1$
        error(Messages.getInstance().getErrorString("ResultSetCompareComponent.ERROR_0008_COLUMN_NOT_FOUND") + compareCol);
        return false;
    }
    if (compareCol > compColCount) {
        // $NON-NLS-1$
        error(Messages.getInstance().getErrorString("ResultSetCompareComponent.ERROR_0009_COMPARISON_COLUMN_NOT_FOUND") + compareCol);
        return false;
    }
    boolean anyMismatches = false;
    boolean foundIt;
    Object srcValue = null, compValue = null;
    ResultSetCompareAction compareAction = (ResultSetCompareAction) getActionDefinition();
    IActionOutput output = compareAction.getOutputCompareResult();
    for (int sourceRows = 0; sourceRows < sourceRowCount; sourceRows++) {
        foundIt = false;
        srcValue = rs1.getValueAt(sourceRows, compareCol);
        // n+1 traversal. This accommodates non-ordered input
        for (int compRows = 0; compRows < compRowCount; compRows++) {
            compValue = rs2.getValueAt(compRows, compareCol);
            if (compValue.equals(srcValue)) {
                foundIt = true;
                break;
            }
        }
        if (!foundIt) {
            if (outputBuf.length() > 0) {
                // $NON-NLS-1$
                outputBuf.append(",").append(srcValue.toString().trim());
            } else {
                outputBuf.append(srcValue.toString().trim());
            }
            if (output != null) {
                output.setValue(outputBuf.toString());
            }
            if (outputMismatches) {
                error(Messages.getInstance().getErrorString("ResultSetCompareComponent.ERROR_0010_MISMATCH_OUTPUT", // $NON-NLS-1$
                srcValue.toString()));
                anyMismatches = true;
            } else {
                if (stopOnError) {
                    return false;
                }
            }
        }
    }
    if (!anyMismatches) {
        if (output != null) {
            output.setValue(ResultSetCompareComponent.COMPARE_RESULT_OK);
        }
    }
    return stopOnError ? !anyMismatches : true;
}
Also used : ResultSetCompareAction(org.pentaho.actionsequence.dom.actions.ResultSetCompareAction) IActionOutput(org.pentaho.actionsequence.dom.IActionOutput)

Aggregations

ResultSetCompareAction (org.pentaho.actionsequence.dom.actions.ResultSetCompareAction)12 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)8 Test (org.junit.Test)7 IActionInput (org.pentaho.actionsequence.dom.IActionInput)1 IActionOutput (org.pentaho.actionsequence.dom.IActionOutput)1