use of org.apache.hop.core.QueueRowSet in project hop by apache.
the class NullIfTest method testDateWithFormat.
@Test
public void testDateWithFormat() throws HopException {
HopEnvironment.init();
NullIf transform = new NullIf(smh.transformMeta, mockProcessRowMeta2(), smh.iTransformData, 0, smh.pipelineMeta, smh.pipeline);
transform.init();
transform.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();
}
transform.addRowSetToInputRowSets(smh.getMockInputRowSet(new Object[][] { { d1, d2, d3, d4 } }));
transform.addRowSetToOutputRowSets(new QueueRowSet());
boolean hasMoreRows;
do {
hasMoreRows = transform.processRow();
} while (hasMoreRows);
IRowSet outputRowSet = transform.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.apache.hop.core.QueueRowSet in project hop by apache.
the class StreamLookupTest method doTest.
private void doTest(boolean memoryPreservationActive, boolean binaryLookupStream, boolean binaryDataStream) throws HopException {
StreamLookup transform = new StreamLookup(smh.transformMeta, smh.iTransformMeta, smh.iTransformData, 0, smh.pipelineMeta, smh.pipeline);
transform.init();
transform.addRowSetToInputRowSets(mockLookupRowSet(binaryLookupStream));
transform.addRowSetToInputRowSets(mockDataRowSet(binaryDataStream));
transform.addRowSetToOutputRowSets(new QueueRowSet());
StreamLookupMeta meta = mockProcessRowMeta(memoryPreservationActive);
StreamLookupData data = new StreamLookupData();
data.readLookupValues = true;
IRowSet outputRowSet = transform.getOutputRowSets().get(0);
// Process rows and collect output
int rowNumber = 0;
String[] expectedOutput = { "Name", "", "Value" };
while (transform.processRow()) {
Object[] rowData = outputRowSet.getRow();
if (rowData != null) {
IRowMeta rowMeta = outputRowSet.getRowMeta();
assertEquals("Output row is of wrong size", 3, rowMeta.size());
rowNumber++;
// Verify output
for (int valueIndex = 0; valueIndex < rowMeta.size(); valueIndex++) {
String expectedValue = expectedOutput[valueIndex] + rowNumber;
Object actualValue = rowMeta.getValueMeta(valueIndex).convertToNormalStorageType(rowData[valueIndex]);
assertEquals("Unexpected value at row " + rowNumber + " position " + valueIndex, expectedValue, actualValue);
}
}
}
assertEquals("Incorrect output row number", 2, rowNumber);
}
use of org.apache.hop.core.QueueRowSet in project hop by apache.
the class CsvInputMultiCharDelimiterTest method doTest.
private void doTest(String content) throws Exception {
IRowSet output = new QueueRowSet();
File tmp = createTestFile(ENCODING, content);
try {
CsvInputMeta meta = createMeta(tmp, createInputFileFields("f1", "f2", "f3"));
CsvInputData data = new CsvInputData();
csvInput = new CsvInput(transformMockHelper.transformMeta, meta, data, 0, transformMockHelper.pipelineMeta, transformMockHelper.pipeline);
csvInput.init();
csvInput.addRowSetToOutputRowSets(output);
try {
csvInput.processRow();
} finally {
csvInput.dispose();
}
} finally {
tmp.delete();
}
Object[] row = output.getRowImmediate();
assertNotNull(row);
assertEquals("value1", row[0]);
assertEquals("value2", row[1]);
assertEquals("value3", row[2]);
assertNull(output.getRowImmediate());
}
use of org.apache.hop.core.QueueRowSet in project hop by apache.
the class IfNullTest method testStringEmptyIsNull.
@Test
public void testStringEmptyIsNull() throws HopException {
System.setProperty(Const.HOP_EMPTY_STRING_DIFFERS_FROM_NULL, "N");
IfNull transform = new IfNull(smh.transformMeta, mockProcessRowMeta(), smh.iTransformData, 0, smh.pipelineMeta, smh.pipeline);
transform.init();
final RowMeta inputRowMeta = buildInputRowMeta(//
new ValueMetaString("some-field"), //
new ValueMetaString("null-field"), //
new ValueMetaString("empty-field"), //
new ValueMetaString("space-field"), //
new ValueMetaString("another-field"));
transform.setInputRowMeta(inputRowMeta);
final Object[] inputRow = new Object[] { "value1", null, "", " ", "value5" };
final Object[] expectedRow = new Object[] { "value1", "replace-value", "replace-value", " ", "value5" };
transform.addRowSetToInputRowSets(buildInputRowSet(inputRow));
transform.addRowSetToOutputRowSets(new QueueRowSet());
boolean hasMoreRows;
do {
hasMoreRows = transform.processRow();
} while (hasMoreRows);
IRowSet outputRowSet = transform.getOutputRowSets().get(0);
assertRowSetMatches("", expectedRow, outputRowSet);
}
use of org.apache.hop.core.QueueRowSet in project hop by apache.
the class IfNullTest method testStringEmptyIsNotNull.
@Test
public void testStringEmptyIsNotNull() throws HopException {
System.setProperty(Const.HOP_EMPTY_STRING_DIFFERS_FROM_NULL, "Y");
IfNull transform = new IfNull(smh.transformMeta, mockProcessRowMeta(), smh.iTransformData, 0, smh.pipelineMeta, smh.pipeline);
transform.init();
final RowMeta inputRowMeta = buildInputRowMeta(//
new ValueMetaString("some-field"), //
new ValueMetaString("null-field"), //
new ValueMetaString("empty-field"), //
new ValueMetaString("space-field"), //
new ValueMetaString("another-field"));
transform.setInputRowMeta(inputRowMeta);
final Object[] inputRow = new Object[] { "value1", null, "", " ", "value5" };
final Object[] expectedRow = new Object[] { "value1", "replace-value", "", " ", "value5" };
transform.addRowSetToInputRowSets(buildInputRowSet(inputRow));
transform.addRowSetToOutputRowSets(new QueueRowSet());
boolean hasMoreRows;
do {
hasMoreRows = transform.processRow();
} while (hasMoreRows);
IRowSet outputRowSet = transform.getOutputRowSets().get(0);
assertRowSetMatches("", expectedRow, outputRowSet);
}
Aggregations