use of org.pentaho.metaverse.frames.FileNode in project pentaho-metaverse by pentaho.
the class MdiValidationIT method verifyInjectorTextFileOutputNode.
private void verifyInjectorTextFileOutputNode(final TransformationStepNode mdiNode, final String outputFileName, final String[] expectedOutputFieldNameArray, final TransformationStepNode templateReadFromStepNode) {
final List<TransformationStepNode> mdiHopsToNodes = IteratorUtils.toList(mdiNode.getNextSteps().iterator());
assertEquals(1, mdiHopsToNodes.size());
// verify that the text file output step writes to the correct output file
final TransformationStepNode textFileOutputNode = mdiHopsToNodes.get(0);
assertEquals("Text file output", textFileOutputNode.getName());
final List<FileNode> writesToNodes = IteratorUtils.toList(textFileOutputNode.getWritesToFileNodes().iterator());
assertEquals(1, writesToNodes.size());
final FileNode fileNode = writesToNodes.get(0);
assertTrue(String.format("Path expected to end with '%s': %s", outputFileName, fileNode.getPath()), fileNode.getPath().endsWith(outputFileName));
// verify that the mdi node output fields are inputs into the text file output step
final List<StreamFieldNode> mdiOutputFields = IteratorUtils.toList(mdiNode.getOutputStreamFields().iterator());
final List<StreamFieldNode> mdiInputFields = IteratorUtils.toList(mdiNode.getInputStreamFields().iterator());
final List<StreamFieldNode> inputFields = IteratorUtils.toList(textFileOutputNode.getInputStreamFields().iterator());
assertEquals(mdiOutputFields.size(), inputFields.size());
final List<StreamFieldNode> tempalteReadFromStepOutputFields = templateReadFromStepNode == null ? new ArrayList() : IteratorUtils.toList(templateReadFromStepNode.getOutputStreamFields().iterator());
for (final StreamFieldNode field : inputFields) {
assertTrue(mdiOutputFields.contains(field));
// template node that is being read and that the same field is also an input into the mdi step node
if (templateReadFromStepNode != null) {
// there should be 1 field that derives this field, and it should be one of the mdi input fields, as well as
// one of the output fields from the template step that is being read from
assertEquals(1, getIterableSize(field.getFieldNodesThatDeriveMe()));
final StreamFieldNode derivingField = (StreamFieldNode) IteratorUtils.toList(field.getFieldNodesThatDeriveMe().iterator()).get(0);
assertTrue(mdiInputFields.contains(derivingField));
assertTrue(tempalteReadFromStepOutputFields.contains(derivingField));
assertEquals(field.getName(), derivingField.getName());
}
}
// verify that the text file output step has the expected output fields, and that each field is derived from an
// mdi output field with the same name
final List<StreamFieldNode> outputFields = IteratorUtils.toList(textFileOutputNode.getOutputStreamFields().iterator());
final List<String> expectedOutputFieldNames = Arrays.asList(expectedOutputFieldNameArray == null ? new String[] {} : expectedOutputFieldNameArray);
assertEquals(expectedOutputFieldNames.size(), outputFields.size());
for (final StreamFieldNode field : outputFields) {
assertTrue(expectedOutputFieldNames.contains(field.getName()));
// there should be 1 field that derives this field, and it should be one of the mdi output fields
assertEquals(1, getIterableSize(field.getFieldNodesThatDeriveMe()));
final StreamFieldNode derivingField = (StreamFieldNode) IteratorUtils.toList(field.getFieldNodesThatDeriveMe().iterator()).get(0);
assertTrue(mdiOutputFields.contains(derivingField));
assertEquals(field.getName(), derivingField.getName());
}
}
Aggregations