use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.
the class TextFileOutputTest method doOutput.
private List<Throwable> doOutput(TextFileField[] textFileField, List<Object[]> rows, String pathToFile, String endedLine, Boolean isHeaderEnabled, Boolean isDoNotOpenNewFileInit, Boolean append) throws KettleException {
TextFileOutputData textFileOutputData = new TextFileOutputData();
TextFileOutput textFileOutput = new TextFileOutputTestHandler(stepMockHelper.stepMeta, textFileOutputData, 0, stepMockHelper.transMeta, stepMockHelper.trans);
// init step meta and process step meta should be the same in this case
Mockito.when(stepMockHelper.processRowsStepMetaInterface.isDoNotOpenNewFileInit()).thenReturn(isDoNotOpenNewFileInit);
Mockito.when(stepMockHelper.processRowsStepMetaInterface.isFileAppended()).thenReturn(append);
Mockito.when(stepMockHelper.processRowsStepMetaInterface.isHeaderEnabled()).thenReturn(isHeaderEnabled);
Mockito.when(stepMockHelper.processRowsStepMetaInterface.getFileName()).thenReturn(pathToFile);
Mockito.when(stepMockHelper.processRowsStepMetaInterface.buildFilename(Mockito.anyString(), Mockito.anyString(), ((VariableSpace) Mockito.anyObject()), Mockito.anyInt(), Mockito.anyString(), Mockito.anyInt(), Mockito.anyBoolean(), (TextFileOutputMeta) Mockito.anyObject())).thenReturn(pathToFile);
Mockito.when(stepMockHelper.processRowsStepMetaInterface.getOutputFields()).thenReturn(textFileField);
textFileOutput.init(stepMockHelper.processRowsStepMetaInterface, textFileOutputData);
// Process rows
RowSet rowSet = stepMockHelper.getMockInputRowSet(rows);
RowMetaInterface inputRowMeta = Mockito.mock(RowMetaInterface.class);
textFileOutput.setInputRowMeta(inputRowMeta);
Mockito.when(rowSet.getRowWait(Mockito.anyInt(), (TimeUnit) Mockito.anyObject())).thenReturn(rows.isEmpty() ? null : rows.iterator().next());
Mockito.when(rowSet.getRowMeta()).thenReturn(inputRowMeta);
Mockito.when(inputRowMeta.clone()).thenReturn(inputRowMeta);
for (int i = 0; i < textFileField.length; i++) {
String name = textFileField[i].getName();
ValueMetaString valueMetaString = new ValueMetaString(name);
Mockito.when(inputRowMeta.getValueMeta(i)).thenReturn(valueMetaString);
Mockito.when(inputRowMeta.indexOfValue(name)).thenReturn(i);
}
textFileOutput.addRowSetToInputRowSets(rowSet);
textFileOutput.addRowSetToOutputRowSets(rowSet);
Mockito.when(stepMockHelper.processRowsStepMetaInterface.getEndedLine()).thenReturn(endedLine);
Mockito.when(stepMockHelper.processRowsStepMetaInterface.isFastDump()).thenReturn(true);
for (int i = 0; i < rows.size(); i++) {
((TextFileOutputTestHandler) textFileOutput).setRow(rows.get(i));
textFileOutput.processRow(stepMockHelper.processRowsStepMetaInterface, textFileOutputData);
}
((TextFileOutputTestHandler) textFileOutput).setRow(null);
textFileOutput.processRow(stepMockHelper.processRowsStepMetaInterface, textFileOutputData);
textFileOutput.dispose(stepMockHelper.processRowsStepMetaInterface, textFileOutputData);
return ((TextFileOutputTestHandler) textFileOutput).errors;
}
use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.
the class ValidatorTest method readSourceValuesFromInfoStepsTest.
@Test
public void readSourceValuesFromInfoStepsTest() throws Exception {
String name = "Valid list";
String field = "sourcing field 1";
String values = "A";
mockHelper.stepMeta.setName(name);
ValidatorMeta meta = new ValidatorMeta();
List<Validation> validations = new ArrayList<>();
Validation validation1 = new Validation("validation1");
validation1.setSourcingValues(true);
validation1.setSourcingField(field);
validations.add(validation1);
Validation validation2 = new Validation("validation2");
validation2.setSourcingValues(true);
validation2.setSourcingField("sourcing field 2");
validations.add(validation2);
meta.setValidations(validations);
StepMeta stepMeta = new StepMeta();
stepMeta.setName(name);
RowSet rowSet = Mockito.mock(RowSet.class);
Mockito.when(rowSet.getOriginStepName()).thenReturn(name);
Mockito.when(rowSet.getDestinationStepName()).thenReturn("Validator");
Mockito.when(rowSet.getOriginStepCopy()).thenReturn(0);
Mockito.when(rowSet.getDestinationStepCopy()).thenReturn(0);
Mockito.when(rowSet.getRow()).thenReturn(new String[] { values }).thenReturn(null);
Mockito.when(rowSet.isDone()).thenReturn(true);
RowMetaInterface allowedRowMeta = Mockito.mock(RowMetaInterface.class);
Mockito.when(rowSet.getRowMeta()).thenReturn(allowedRowMeta);
Mockito.when(rowSet.getRowMeta()).thenReturn(Mockito.mock(RowMetaInterface.class));
Mockito.when(allowedRowMeta.indexOfValue(field)).thenReturn(0);
Mockito.when(allowedRowMeta.getValueMeta(0)).thenReturn(Mockito.mock(ValueMetaInterface.class));
List<RowSet> rowSets = new ArrayList<>();
rowSets.add(rowSet);
validator.setInputRowSets(rowSets);
mockHelper.transMeta.setStep(0, stepMeta);
Mockito.when(mockHelper.transMeta.findStep(Mockito.eq(name))).thenReturn(stepMeta);
StepMeta stepMetaValidList = new StepMeta();
stepMetaValidList.setName(name);
meta.getStepIOMeta().getInfoStreams().get(0).setStepMeta(stepMetaValidList);
meta.getStepIOMeta().getInfoStreams().get(1).setStepMeta(stepMetaValidList);
Class<?> validatorClass = Validator.class;
Field metaField = validatorClass.getDeclaredField("meta");
metaField.setAccessible(true);
metaField.set(validator, meta);
ValidatorData data = new ValidatorData();
data.constantsMeta = new ValueMetaInterface[2];
Field dataField = validatorClass.getDeclaredField("data");
dataField.setAccessible(true);
dataField.set(validator, data);
data.listValues = new Object[2][2];
validator.readSourceValuesFromInfoSteps();
Assert.assertEquals(values, data.listValues[0][0]);
Assert.assertEquals(values, data.listValues[1][0]);
}
use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.
the class IngresVectorwiseTest method doOutput.
@SuppressWarnings("unused")
private BaseStep doOutput(List<Object[]> rows, String maxErrorsNumber) throws KettleException {
IngresVectorwiseLoaderData ivwData = new IngresVectorwiseLoaderData();
IngresVectorwiseLoaderTest ivwLoader = new IngresVectorwiseLoaderTest(stepMockHelper.stepMeta, ivwData, 0, stepMockHelper.transMeta, stepMockHelper.trans);
DatabaseMeta defMeta = mock(DatabaseMeta.class);
when(stepMockHelper.processRowsStepMetaInterface.getDatabaseMeta()).thenReturn(defMeta);
when(defMeta.getQuotedSchemaTableCombination(anyString(), anyString())).thenReturn("test_table");
ivwLoader.init(stepMockHelper.processRowsStepMetaInterface, ivwData);
RowSet rowSet = stepMockHelper.getMockInputRowSet(rows);
ivwLoader.addRowSetToInputRowSets(rowSet);
when(stepMockHelper.processRowsStepMetaInterface.isUsingVwload()).thenReturn(true);
when(stepMockHelper.processRowsStepMetaInterface.getBufferSize()).thenReturn("5000");
when(stepMockHelper.processRowsStepMetaInterface.getMaxNrErrors()).thenReturn(maxErrorsNumber);
when(stepMockHelper.processRowsStepMetaInterface.getFieldStream()).thenReturn(fieldStream);
when(stepMockHelper.processRowsStepMetaInterface.getFieldDatabase()).thenReturn(fieldStream);
File errorFile = new File("/tmp/error.txt");
File fifoFile = new File("/tmp/fifo");
try {
errorFile = createTemplateFile();
fifoFile = createTemplateFile();
boolean deleted = fifoFile.delete();
} catch (IOException e) {
e.printStackTrace();
}
when(stepMockHelper.processRowsStepMetaInterface.getErrorFileName()).thenReturn(errorFile.getPath());
when(stepMockHelper.processRowsStepMetaInterface.getFifoFileName()).thenReturn(fifoFile.getPath());
RowMetaInterface inputRowMeta = mock(RowMetaInterface.class);
ivwLoader.setInputRowMeta(inputRowMeta);
when(rowSet.getRowMeta()).thenReturn(inputRowMeta);
ValueMetaInteger valueMetaInteger = new ValueMetaInteger();
ValueMetaString valueMetaString = new ValueMetaString();
when(inputRowMeta.getValueMeta(0)).thenReturn(valueMetaInteger);
when(inputRowMeta.getValueMeta(1)).thenReturn(valueMetaString);
when(inputRowMeta.indexOfValue(fieldStream[0])).thenReturn(0);
when(inputRowMeta.indexOfValue(fieldStream[1])).thenReturn(1);
when(inputRowMeta.clone()).thenReturn(inputRowMeta);
for (Object[] row1 : rows) {
ivwLoader.processRow(stepMockHelper.processRowsStepMetaInterface, ivwData);
}
ivwLoader.processRow(stepMockHelper.processRowsStepMetaInterface, ivwData);
ivwLoader.dispose(stepMockHelper.processRowsStepMetaInterface, ivwData);
ivwLoader.getLogChannel().snap(Metrics.METRIC_STEP_EXECUTION_STOP);
return ivwLoader;
}
use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.
the class XMLInputStreamTest method testCorrectFileSelected.
private void testCorrectFileSelected(String filenameParam, int xmlTagsStartPosition) throws KettleException {
xmlInputStreamMeta.sourceFromInput = false;
xmlInputStreamMeta.setFilename(filenameParam);
xmlInputStreamData.outputRowMeta = new RowMeta();
RowMeta rm = new RowMeta();
String pathValue = getFile("default.xml");
ValueMetaString ms = new ValueMetaString("filename");
RowSet rs = new SingleRowRowSet();
rs.putRow(rm, new Object[] { pathValue });
rs.setDone();
when(stepMockHelper.transMeta.findNrPrevSteps(stepMockHelper.stepMeta)).thenReturn(1);
XMLInputStream xmlInputStream = new XMLInputStream(stepMockHelper.stepMeta, stepMockHelper.stepDataInterface, 0, stepMockHelper.transMeta, stepMockHelper.trans);
xmlInputStream.setInputRowMeta(rm);
xmlInputStream.getInputRowMeta().addValueMeta(ms);
xmlInputStream.addRowSetToInputRowSets(rs);
xmlInputStream.setOutputRowSets(new ArrayList<>());
xmlInputStream.init(xmlInputStreamMeta, xmlInputStreamData);
xmlInputStream.addRowListener(rl);
boolean haveRowsToRead;
do {
haveRowsToRead = !xmlInputStream.processRow(xmlInputStreamMeta, xmlInputStreamData);
} while (!haveRowsToRead);
assertEquals(INCORRECT_XML_DATA_TYPE_DESCRIPTION_MESSAGE, "START_ELEMENT", rl.getWritten().get(1)[xmlTagsStartPosition]);
}
use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.
the class XmlJoinOmitNullValuesTest method createSourceRowSet.
private RowSet createSourceRowSet(String sourceXml) {
RowSet sourceRowSet = smh.getMockInputRowSet(new String[] { sourceXml });
RowMetaInterface sourceRowMeta = mock(RowMetaInterface.class);
when(sourceRowMeta.getFieldNames()).thenReturn(new String[] { "sourceField" });
when(sourceRowSet.getRowMeta()).thenReturn(sourceRowMeta);
return sourceRowSet;
}
Aggregations