use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.
the class StreamLookupTest method mockLookupRowSet.
private RowSet mockLookupRowSet(boolean binary) {
final int storageType = binary ? ValueMetaInterface.STORAGE_TYPE_BINARY_STRING : ValueMetaInterface.STORAGE_TYPE_NORMAL;
Object[][] data = { { "Value1", "1" }, { "Value2", "2" } };
if (binary) {
convertDataToBinary(data);
}
RowSet lookupRowSet = smh.getMockInputRowSet(data);
doReturn("Lookup").when(lookupRowSet).getOriginStepName();
doReturn("StreamLookup").when(lookupRowSet).getDestinationStepName();
RowMeta lookupRowMeta = new RowMeta();
ValueMetaString valueMeta = new ValueMetaString("Value");
valueMeta.setStorageType(storageType);
valueMeta.setStorageMetadata(new ValueMetaString());
lookupRowMeta.addValueMeta(valueMeta);
ValueMetaString idMeta = new ValueMetaString("Id");
idMeta.setStorageType(storageType);
idMeta.setStorageMetadata(new ValueMetaString());
lookupRowMeta.addValueMeta(idMeta);
doReturn(lookupRowMeta).when(lookupRowSet).getRowMeta();
return lookupRowSet;
}
use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.
the class SwitchCaseTest method testProcessRow.
/**
* PDI 6900. Test that process row works correctly. Simulate step workload when input and output row sets already
* created and mapped to specified case values.
*
* @throws KettleException
*/
@Test
public void testProcessRow() throws KettleException {
SwitchCaseCustom krasavez = new SwitchCaseCustom(mockHelper);
krasavez.first = false;
// create two output row sets
RowSet rowSetOne = new QueueRowSet();
RowSet rowSetTwo = new QueueRowSet();
// this row set should contain only '3'.
krasavez.data.outputMap.put(3, rowSetOne);
krasavez.data.outputMap.put(3, rowSetTwo);
// this row set contains nulls only
RowSet rowSetNullOne = new QueueRowSet();
RowSet rowSetNullTwo = new QueueRowSet();
krasavez.data.nullRowSetSet.add(rowSetNullOne);
krasavez.data.nullRowSetSet.add(rowSetNullTwo);
// this row set contains all expect null or '3'
RowSet def = new QueueRowSet();
krasavez.data.defaultRowSetSet.add(def);
// generate some data (see method implementation)
// expected: 5 times null,
// expected 1*2 = 2 times 3
// expected 5*2 + 5 = 15 rows generated
// expected 15 - 5 - 2 = 8 rows go to default.
// expected one empty string at the end
// System.out.println( krasavez.getInputDataOverview() );
// 1, 1, null, 2, 2, null, 3, 3, null, 4, 4, null, 5, 5, null,""
krasavez.generateData(1, 5, 2);
// call method under test
krasavez.processRow();
assertEquals("First row set collects 2 rows", 2, rowSetOne.size());
assertEquals("Second row set collects 2 rows", 2, rowSetTwo.size());
assertEquals("First null row set collects 5 rows", 6, rowSetNullOne.size());
assertEquals("Second null row set collects 5 rows", 6, rowSetNullTwo.size());
assertEquals("Default row set collects the rest of rows", 8, def.size());
// now - check the data is correct in every row set:
assertEquals("First row set contains only 3: ", true, isRowSetContainsValue(rowSetOne, new Object[] { 3 }, new Object[] {}));
assertEquals("Second row set contains only 3: ", true, isRowSetContainsValue(rowSetTwo, new Object[] { 3 }, new Object[] {}));
assertEquals("First null row set contains only null: ", true, isRowSetContainsValue(rowSetNullOne, new Object[] { null }, new Object[] {}));
assertEquals("Second null row set contains only null: ", true, isRowSetContainsValue(rowSetNullTwo, new Object[] { null }, new Object[] {}));
assertEquals("Default row set do not contains null or 3, but other", true, isRowSetContainsValue(def, new Object[] { 1, 2, 4, 5 }, new Object[] { 3, null }));
}
use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.
the class SwitchCaseTest method testCreateOutputValueMapping.
/**
* PDI-6900 Check that SwichCase step can correctly set up input values to output rowsets.
*
* @throws KettleException
* @throws URISyntaxException
* @throws ParserConfigurationException
* @throws SAXException
* @throws IOException
*/
@Test
public void testCreateOutputValueMapping() throws KettleException, URISyntaxException, ParserConfigurationException, SAXException, IOException {
SwitchCaseCustom krasavez = new SwitchCaseCustom(mockHelper);
// load step info value-case mapping from xml.
List<DatabaseMeta> emptyList = new ArrayList<DatabaseMeta>();
krasavez.meta.loadXML(loadStepXmlMetadata("SwitchCaseTest.xml"), emptyList, mock(IMetaStore.class));
KeyToRowSetMap expectedNN = new KeyToRowSetMap();
Set<RowSet> nulls = new HashSet<RowSet>();
// create real steps for all targets
List<SwitchCaseTarget> list = krasavez.meta.getCaseTargets();
for (SwitchCaseTarget item : list) {
StepMetaInterface smInt = new DummyTransMeta();
StepMeta stepMeta = new StepMeta(item.caseTargetStepname, smInt);
item.caseTargetStep = stepMeta;
// create and put row set for this
RowSet rw = new QueueRowSet();
krasavez.map.put(item.caseTargetStepname, rw);
// null values goes to null rowset
if (item.caseValue != null) {
expectedNN.put(item.caseValue, rw);
} else {
nulls.add(rw);
}
}
// create default step
StepMetaInterface smInt = new DummyTransMeta();
StepMeta stepMeta = new StepMeta(krasavez.meta.getDefaultTargetStepname(), smInt);
krasavez.meta.setDefaultTargetStep(stepMeta);
RowSet rw = new QueueRowSet();
krasavez.map.put(krasavez.meta.getDefaultTargetStepname(), rw);
krasavez.createOutputValueMapping();
// inspect step output data:
Set<RowSet> ones = krasavez.data.outputMap.get("1");
assertEquals("Output map for 1 values contains 2 row sets", 2, ones.size());
Set<RowSet> twos = krasavez.data.outputMap.get("2");
assertEquals("Output map for 2 values contains 1 row sets", 1, twos.size());
assertEquals("Null row set contains 2 items: ", 2, krasavez.data.nullRowSetSet.size());
assertEquals("We have at least one default rowset", 1, krasavez.data.defaultRowSetSet.size());
// check that rowsets data is correct:
Set<RowSet> rowsets = expectedNN.get("1");
for (RowSet rowset : rowsets) {
assertTrue("Output map for 1 values contains expected row set", ones.contains(rowset));
}
rowsets = expectedNN.get("2");
for (RowSet rowset : rowsets) {
assertTrue("Output map for 2 values contains expected row set", twos.contains(rowset));
}
for (RowSet rowset : krasavez.data.nullRowSetSet) {
assertTrue("Output map for null values contains expected row set", nulls.contains(rowset));
}
// we have already check that there is only one item.
for (RowSet rowset : krasavez.data.defaultRowSetSet) {
assertTrue("Output map for default case contains expected row set", rowset.equals(rw));
}
}
use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.
the class StepMockHelper method getMockInputRowSet.
public RowSet getMockInputRowSet(final List<Object[]> rows) {
final AtomicInteger index = new AtomicInteger(0);
RowSet rowSet = mock(RowSet.class, Mockito.RETURNS_MOCKS);
Answer<Object[]> answer = new Answer<Object[]>() {
@Override
public Object[] answer(InvocationOnMock invocation) throws Throwable {
int i = index.getAndIncrement();
return i < rows.size() ? rows.get(i) : null;
}
};
when(rowSet.getRowWait(anyLong(), any(TimeUnit.class))).thenAnswer(answer);
when(rowSet.getRow()).thenAnswer(answer);
when(rowSet.isDone()).thenAnswer(new Answer<Boolean>() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
return index.get() >= rows.size();
}
});
return rowSet;
}
use of org.pentaho.di.core.RowSet 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]);
}
}
Aggregations