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]);
}
}
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]);
}
}
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);
}
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);
}
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());
}
Aggregations