use of org.pentaho.di.trans.steps.textfileoutput.TextFileOutputMeta in project pentaho-kettle by pentaho.
the class TransMetaTest method testGetPreviousStepsWhenStreamLookupStepPassedShouldClearCacheAndCallFindPreviousStepsWithFalseParam.
@Test
public void testGetPreviousStepsWhenStreamLookupStepPassedShouldClearCacheAndCallFindPreviousStepsWithFalseParam() {
TransMeta transMeta = mock(TransMeta.class);
StepMeta stepMeta = new StepMeta("stream_lookup_id", "stream_lookup_name", new StreamLookupMeta());
List<StepMeta> expectedResult = new ArrayList<>();
List<StepMeta> invalidResult = new ArrayList<>();
expectedResult.add(new StepMeta("correct_mock", "correct_mock", new TextFileOutputMeta()));
invalidResult.add(new StepMeta("incorrect_mock", "incorrect_mock", new TextFileOutputMeta()));
doNothing().when(transMeta).clearPreviousStepCache();
when(transMeta.findPreviousSteps(any(StepMeta.class), eq(false))).thenReturn(expectedResult);
when(transMeta.findPreviousSteps(any(StepMeta.class), eq(true))).thenReturn(invalidResult);
when(transMeta.getPreviousSteps(any())).thenCallRealMethod();
List<StepMeta> actualResult = transMeta.getPreviousSteps(stepMeta);
verify(transMeta, times(1)).clearPreviousStepCache();
assertEquals(expectedResult, actualResult);
}
use of org.pentaho.di.trans.steps.textfileoutput.TextFileOutputMeta in project pentaho-metaverse by pentaho.
the class MetaverseValidationIT method testTextFileOutputStepNode.
@Test
public void testTextFileOutputStepNode() throws Exception {
TextFileOutputStepNode textFileOutputStepNode = root.getTextFileOutputStepNode("textFileOutput", "Text file output");
TextFileOutputMeta meta = (TextFileOutputMeta) getStepMeta(textFileOutputStepNode);
TransMeta tm = meta.getParentStepMeta().getParentTransMeta();
String[] fileNames = meta.getFiles(tm);
RowMetaInterface incomingFields = tm.getPrevStepFields(meta.getParentStepMeta());
int outputFields = getExpectedOutputFieldCount(meta);
assertNotNull(textFileOutputStepNode);
// should write to one file
Iterable<FramedMetaverseNode> outputFiles = textFileOutputStepNode.getOutputFiles();
assertEquals(fileNames.length, getIterableSize(outputFiles));
int i = 0;
for (FramedMetaverseNode node : outputFiles) {
assertEquals(normalizeFilePath(fileNames[i++]), normalizeFilePath(node.getName()));
}
Iterable<StreamFieldNode> outFields = textFileOutputStepNode.getOutputStreamFields();
int outFieldCount = getIterableSize(outFields);
// should have output stream nodes as well as file nodes
assertEquals(outputFields + meta.getOutputFields().length, outFieldCount);
int fileFieldCount = 0;
for (StreamFieldNode outField : outFields) {
if (DictionaryConst.NODE_TYPE_FILE_FIELD.equals(outField.getType())) {
ValueMetaInterface vmi = incomingFields.searchValueMeta(outField.getName());
assertEquals(vmi.getName(), outField.getFieldPopulatesMe().getName());
fileFieldCount++;
}
}
assertEquals(fileFieldCount, outFieldCount / 2);
}
use of org.pentaho.di.trans.steps.textfileoutput.TextFileOutputMeta in project pentaho-metaverse by pentaho.
the class TextFileOutputExternalResourceConsumer method getResourcesFromRow.
@Override
public Collection<IExternalResourceInfo> getResourcesFromRow(TextFileOutput textFileOutput, RowMetaInterface rowMeta, Object[] row) {
Collection<IExternalResourceInfo> resources = new LinkedList<IExternalResourceInfo>();
// For some reason the step doesn't return the StepMetaInterface directly, so go around it
TextFileOutputMeta meta = (TextFileOutputMeta) textFileOutput.getStepMeta().getStepMetaInterface();
try {
TextFileOutputData data = ((TextFileOutputData) textFileOutput.getStepDataInterface());
String filename = rowMeta.getString(row, meta.getFileNameField(), meta.getFileName());
if (null != data) {
// For some reason, the first call to process row doesn't have the data.fileName filled in, so
// fall back to the filename field value, and then to the meta's filename
filename = textFileOutput.buildFilename(Const.isEmpty(data.fileName) ? filename : data.fileName, true);
}
if (!Const.isEmpty(filename)) {
FileObject fileObject = KettleVFS.getFileObject(filename);
resources.add(ExternalResourceInfoFactory.createFileResource(fileObject, false));
}
} catch (KettleException kve) {
// TODO throw exception or ignore?
}
return resources;
}
use of org.pentaho.di.trans.steps.textfileoutput.TextFileOutputMeta in project pentaho-metaverse by pentaho.
the class MetaverseValidationIT method testTextFileOutputStepNode_FileFromStreamField.
@Test
public void testTextFileOutputStepNode_FileFromStreamField() throws Exception {
TextFileOutputStepNode textFileOutputStepNode = root.getTextFileOutputStepNode("textFileOutput", "Text file output - file from field");
TextFileOutputMeta meta = (TextFileOutputMeta) getStepMeta(textFileOutputStepNode);
TransMeta tm = meta.getParentStepMeta().getParentTransMeta();
RowMetaInterface incomingFields = tm.getPrevStepFields(meta.getParentStepMeta());
int outputFields = getExpectedOutputFieldCount(meta);
assertNotNull(textFileOutputStepNode);
// should write to one file
Iterable<FramedMetaverseNode> outputFiles = textFileOutputStepNode.getOutputFiles();
assertEquals(0, getIterableSize(outputFiles));
Iterable<StreamFieldNode> usedFields = textFileOutputStepNode.getStreamFieldNodesUses();
int usedFieldCount = getIterableSize(usedFields);
assertEquals(1, usedFieldCount);
Iterable<StreamFieldNode> outFields = textFileOutputStepNode.getOutputStreamFields();
int outFieldCount = getIterableSize(outFields);
// should have output stream nodes as well as file nodes
assertEquals(outputFields + meta.getOutputFields().length, outFieldCount);
int fileFieldCount = 0;
for (StreamFieldNode outField : outFields) {
if (DictionaryConst.NODE_TYPE_FILE_FIELD.equals(outField.getType())) {
ValueMetaInterface vmi = incomingFields.searchValueMeta(outField.getName());
assertEquals(vmi.getName(), outField.getFieldPopulatesMe().getName());
fileFieldCount++;
}
}
assertEquals(fileFieldCount, outFieldCount / 2);
}
use of org.pentaho.di.trans.steps.textfileoutput.TextFileOutputMeta in project pentaho-kettle by pentaho.
the class TransMetaTest method testGetPreviousStepsWhenNotStreamLookupStepPassedShouldCallFindPreviousStepsWithTrueParam.
@Test
public void testGetPreviousStepsWhenNotStreamLookupStepPassedShouldCallFindPreviousStepsWithTrueParam() {
TransMeta transMeta = mock(TransMeta.class);
StepMeta stepMeta = new StepMeta("not_stream_lookup_id", "not_stream_lookup_name", new TextFileOutputMeta());
List<StepMeta> expectedResult = new ArrayList<>();
List<StepMeta> invalidResult = new ArrayList<>();
expectedResult.add(new StepMeta("correct_mock", "correct_mock", new TextFileOutputMeta()));
invalidResult.add(new StepMeta("incorrect_mock", "incorrect_mock", new TextFileOutputMeta()));
doNothing().when(transMeta).clearPreviousStepCache();
when(transMeta.getPreviousSteps(any())).thenCallRealMethod();
when(transMeta.findPreviousSteps(any(StepMeta.class))).thenCallRealMethod();
when(transMeta.findPreviousSteps(any(StepMeta.class), eq(true))).thenReturn(expectedResult);
when(transMeta.findPreviousSteps(any(StepMeta.class), eq(false))).thenReturn(invalidResult);
List<StepMeta> actualResult = transMeta.getPreviousSteps(stepMeta);
verify(transMeta, times(0)).clearPreviousStepCache();
assertEquals(expectedResult, actualResult);
}
Aggregations