Search in sources :

Example 6 with QueueRowSet

use of org.pentaho.di.core.QueueRowSet in project pentaho-kettle by pentaho.

the class NullIfTest method test.

@Test
public void test() throws KettleException {
    KettleEnvironment.init();
    NullIf step = new NullIf(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans);
    step.init(smh.initStepMetaInterface, smh.stepDataInterface);
    step.setInputRowMeta(getInputRowMeta());
    step.addRowSetToInputRowSets(mockInputRowSet());
    step.addRowSetToOutputRowSets(new QueueRowSet());
    boolean hasMoreRows;
    do {
        hasMoreRows = step.processRow(mockProcessRowMeta(), smh.processRowsStepDataInterface);
    } while (hasMoreRows);
    RowSet outputRowSet = step.getOutputRowSets().get(0);
    Object[] actualRow = outputRowSet.getRow();
    Object[] expectedRow = new Object[] { "value1", null, "value3" };
    Assert.assertEquals("Output row is of an unexpected length", expectedRow.length, outputRowSet.getRowMeta().size());
    for (int i = 0; i < expectedRow.length; i++) {
        Assert.assertEquals("Unexpected output value at index " + i, expectedRow[i], actualRow[i]);
    }
}
Also used : QueueRowSet(org.pentaho.di.core.QueueRowSet) RowSet(org.pentaho.di.core.RowSet) QueueRowSet(org.pentaho.di.core.QueueRowSet) Test(org.junit.Test)

Example 7 with QueueRowSet

use of org.pentaho.di.core.QueueRowSet in project pentaho-kettle by pentaho.

the class NullIfTest method testDateWithFormat.

@Test
public void testDateWithFormat() throws KettleException {
    KettleEnvironment.init();
    NullIf step = new NullIf(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans);
    step.init(smh.initStepMetaInterface, smh.stepDataInterface);
    step.setInputRowMeta(getInputRowMeta2());
    Date d1 = null;
    Date d2 = null;
    Date d3 = null;
    Date d4 = null;
    try {
        DateFormat formatter = new SimpleDateFormat("yyyyMMdd");
        d1 = formatter.parse("20150606");
        d3 = formatter.parse("20150607");
        formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS");
        d2 = formatter.parse("2015/06/06 00:00:00.000");
        d4 = formatter.parse("2015/07/06 00:00:00.000");
    } catch (ParseException e) {
        e.printStackTrace();
    }
    step.addRowSetToInputRowSets(smh.getMockInputRowSet(new Object[][] { { d1, d2, d3, d4 } }));
    step.addRowSetToOutputRowSets(new QueueRowSet());
    boolean hasMoreRows;
    do {
        hasMoreRows = step.processRow(mockProcessRowMeta2(), smh.processRowsStepDataInterface);
    } while (hasMoreRows);
    RowSet outputRowSet = step.getOutputRowSets().get(0);
    Object[] actualRow = outputRowSet.getRow();
    Object[] expectedRow = new Object[] { null, null, d3, d4 };
    Assert.assertEquals("Output row is of an unexpected length", expectedRow.length, outputRowSet.getRowMeta().size());
    for (int i = 0; i < expectedRow.length; i++) {
        Assert.assertEquals("Unexpected output value at index " + i, expectedRow[i], actualRow[i]);
    }
}
Also used : QueueRowSet(org.pentaho.di.core.QueueRowSet) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) RowSet(org.pentaho.di.core.RowSet) QueueRowSet(org.pentaho.di.core.QueueRowSet) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) Test(org.junit.Test)

Example 8 with QueueRowSet

use of org.pentaho.di.core.QueueRowSet in project pentaho-kettle by pentaho.

the class IfNullTest method testString_emptyIsNotNull.

@Test
public void testString_emptyIsNotNull() throws KettleException {
    // FieldAccessor.ensureEmptyStringIsNotNull( true );
    Whitebox.setInternalState(ValueMetaBase.class, "EMPTY_STRING_AND_NULL_ARE_DIFFERENT", true);
    IfNull step = new IfNull(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans);
    step.init(smh.initStepMetaInterface, smh.stepDataInterface);
    final RowMeta inputRowMeta = buildInputRowMeta(// 
    new ValueMetaString("some-field"), // 
    new ValueMetaString("null-field"), // 
    new ValueMetaString("empty-field"), // 
    new ValueMetaString("space-field"), // 
    new ValueMetaString("another-field"));
    step.setInputRowMeta(inputRowMeta);
    final Object[] inputRow = new Object[] { "value1", null, "", "    ", "value5" };
    final Object[] expectedRow = new Object[] { "value1", "replace-value", "", "    ", "value5" };
    step.addRowSetToInputRowSets(buildInputRowSet(inputRow));
    step.addRowSetToOutputRowSets(new QueueRowSet());
    boolean hasMoreRows;
    do {
        hasMoreRows = step.processRow(mockProcessRowMeta(), smh.processRowsStepDataInterface);
    } while (hasMoreRows);
    RowSet outputRowSet = step.getOutputRowSets().get(0);
    assertRowSetMatches("", expectedRow, outputRowSet);
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) QueueRowSet(org.pentaho.di.core.QueueRowSet) RowSet(org.pentaho.di.core.RowSet) QueueRowSet(org.pentaho.di.core.QueueRowSet) Test(org.junit.Test)

Example 9 with QueueRowSet

use of org.pentaho.di.core.QueueRowSet in project pentaho-kettle by pentaho.

the class IfNullTest method testString_emptyIsNull.

@Test
public void testString_emptyIsNull() throws KettleException {
    Whitebox.setInternalState(ValueMetaBase.class, "EMPTY_STRING_AND_NULL_ARE_DIFFERENT", false);
    IfNull step = new IfNull(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans);
    step.init(smh.initStepMetaInterface, smh.stepDataInterface);
    final RowMeta inputRowMeta = buildInputRowMeta(// 
    new ValueMetaString("some-field"), // 
    new ValueMetaString("null-field"), // 
    new ValueMetaString("empty-field"), // 
    new ValueMetaString("space-field"), // 
    new ValueMetaString("another-field"));
    step.setInputRowMeta(inputRowMeta);
    final Object[] inputRow = new Object[] { "value1", null, "", "    ", "value5" };
    final Object[] expectedRow = new Object[] { "value1", "replace-value", "replace-value", "    ", "value5" };
    step.addRowSetToInputRowSets(buildInputRowSet(inputRow));
    step.addRowSetToOutputRowSets(new QueueRowSet());
    boolean hasMoreRows;
    do {
        hasMoreRows = step.processRow(mockProcessRowMeta(), smh.processRowsStepDataInterface);
    } while (hasMoreRows);
    RowSet outputRowSet = step.getOutputRowSets().get(0);
    assertRowSetMatches("", expectedRow, outputRowSet);
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) QueueRowSet(org.pentaho.di.core.QueueRowSet) RowSet(org.pentaho.di.core.RowSet) QueueRowSet(org.pentaho.di.core.QueueRowSet) Test(org.junit.Test)

Example 10 with QueueRowSet

use of org.pentaho.di.core.QueueRowSet in project pentaho-kettle by pentaho.

the class TransExecutorUnitTest method collectsExecutionResults.

@Test
public void collectsExecutionResults() throws Exception {
    prepareOneRowForExecutor();
    StepMeta parentStepMeta = mock(StepMeta.class);
    when(parentStepMeta.getName()).thenReturn("parentStepMeta");
    meta.setParentStepMeta(parentStepMeta);
    internalResult.setResult(true);
    meta.setExecutionResultField("executionResultField");
    internalResult.setNrErrors(1);
    meta.setExecutionNrErrorsField("executionNrErrorsField");
    internalResult.setNrLinesRead(2);
    meta.setExecutionLinesReadField("executionLinesReadField");
    internalResult.setNrLinesWritten(3);
    meta.setExecutionLinesWrittenField("executionLinesWrittenField");
    internalResult.setNrLinesInput(4);
    meta.setExecutionLinesInputField("executionLinesInputField");
    internalResult.setNrLinesOutput(5);
    meta.setExecutionLinesOutputField("executionLinesOutputField");
    internalResult.setNrLinesRejected(6);
    meta.setExecutionLinesRejectedField("executionLinesRejectedField");
    internalResult.setNrLinesUpdated(7);
    meta.setExecutionLinesUpdatedField("executionLinesUpdatedField");
    internalResult.setNrLinesDeleted(8);
    meta.setExecutionLinesDeletedField("executionLinesDeletedField");
    internalResult.setNrFilesRetrieved(9);
    meta.setExecutionFilesRetrievedField("executionFilesRetrievedField");
    internalResult.setExitStatus(10);
    meta.setExecutionExitStatusField("executionExitStatusField");
    RowSet rowSet = new QueueRowSet();
    // any value except null
    StepMeta stepMeta = mockStepAndMapItToRowSet("stepMetaMock", rowSet);
    meta.setExecutionResultTargetStepMeta(stepMeta);
    executor.init(meta, data);
    executor.setInputRowMeta(new RowMeta());
    assertTrue("Passing one line at first time", executor.processRow(meta, data));
    assertFalse("Executing the internal trans during the second round", executor.processRow(meta, data));
    Object[] resultsRow = rowSet.getRowImmediate();
    assertNotNull(resultsRow);
    assertNull("Only one row is expected", rowSet.getRowImmediate());
    assertEquals(internalResult.getResult(), resultsRow[0]);
    assertEquals(internalResult.getNrErrors(), resultsRow[1]);
    assertEquals(internalResult.getNrLinesRead(), resultsRow[2]);
    assertEquals(internalResult.getNrLinesWritten(), resultsRow[3]);
    assertEquals(internalResult.getNrLinesInput(), resultsRow[4]);
    assertEquals(internalResult.getNrLinesOutput(), resultsRow[5]);
    assertEquals(internalResult.getNrLinesRejected(), resultsRow[6]);
    assertEquals(internalResult.getNrLinesUpdated(), resultsRow[7]);
    assertEquals(internalResult.getNrLinesDeleted(), resultsRow[8]);
    assertEquals(internalResult.getNrFilesRetrieved(), resultsRow[9]);
    assertEquals(internalResult.getExitStatus(), ((Number) resultsRow[10]).intValue());
}
Also used : QueueRowSet(org.pentaho.di.core.QueueRowSet) RowMeta(org.pentaho.di.core.row.RowMeta) RowSet(org.pentaho.di.core.RowSet) QueueRowSet(org.pentaho.di.core.QueueRowSet) StepMeta(org.pentaho.di.trans.step.StepMeta) Test(org.junit.Test)

Aggregations

QueueRowSet (org.pentaho.di.core.QueueRowSet)20 RowSet (org.pentaho.di.core.RowSet)18 Test (org.junit.Test)13 RowMeta (org.pentaho.di.core.row.RowMeta)5 StepMeta (org.pentaho.di.trans.step.StepMeta)5 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)4 File (java.io.File)3 SingleRowRowSet (org.pentaho.di.core.SingleRowRowSet)3 KettleException (org.pentaho.di.core.exception.KettleException)3 SimpleDateFormat (java.text.SimpleDateFormat)2 BlockingBatchingRowSet (org.pentaho.di.core.BlockingBatchingRowSet)2 BlockingRowSet (org.pentaho.di.core.BlockingRowSet)2 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)2 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)2 StepDataInterface (org.pentaho.di.trans.step.StepDataInterface)2 StepInterface (org.pentaho.di.trans.step.StepInterface)2 StepMetaInterface (org.pentaho.di.trans.step.StepMetaInterface)2 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1