Search in sources :

Example 1 with FileInputStepNode

use of org.pentaho.metaverse.frames.FileInputStepNode in project pentaho-metaverse by pentaho.

the class MetaverseValidationIT method testTextFileInputStep_filenameFromField.

@Test
public void testTextFileInputStep_filenameFromField() throws Exception {
    // this is testing a specific TextFileInputStep instance
    FileInputStepNode fileInputStepNode = root.getTextFileInputStepNode_filenameFromField();
    assertNotNull(fileInputStepNode);
    int countUses = getIterableSize(fileInputStepNode.getFileFieldNodesUses());
    int countInputs = getIterableSize(fileInputStepNode.getInputStreamFields());
    assertEquals(1, countUses);
    int fileFieldCount = 0;
    Iterable<StreamFieldNode> outFields = fileInputStepNode.getOutputStreamFields();
    int countOutputs = getIterableSize(outFields);
    for (StreamFieldNode outField : outFields) {
        assertNotNull(outField.getKettleType());
        if (!outField.getName().equals("filename")) {
            FieldNode fieldPopulatesMe = outField.getFieldPopulatesMe();
            assertNotNull(fieldPopulatesMe);
            assertEquals(DictionaryConst.NODE_TYPE_FILE_FIELD, fieldPopulatesMe.getType());
            assertEquals(fileInputStepNode, fieldPopulatesMe.getStepThatInputsMe());
            fileFieldCount++;
        }
    }
    // we should have one more input than file fields since we are reading it off of the input stream
    assertEquals(countInputs - 1, fileFieldCount);
    assertEquals(countOutputs, fileFieldCount);
    String filenameField = null;
    TransMeta tm = new TransMeta(new FileInputStream(fileInputStepNode.getTransNode().getPath()), null, true, null, null);
    for (StepMeta stepMeta : tm.getSteps()) {
        if (stepMeta.getName().equals(fileInputStepNode.getName())) {
            org.pentaho.di.trans.steps.fileinput.text.TextFileInputMeta meta = (org.pentaho.di.trans.steps.fileinput.text.TextFileInputMeta) getBaseStepMetaFromStepMeta(stepMeta);
            assertTrue(meta.isAcceptingFilenames());
            filenameField = meta.getAcceptingField();
            assertNotNull(filenameField);
            assertEquals(filenameField, fileInputStepNode.getFileFieldNodesUses().iterator().next().getName());
            // this was the one we cared about...
            break;
        }
    }
}
Also used : FieldNode(org.pentaho.metaverse.frames.FieldNode) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) TransMeta(org.pentaho.di.trans.TransMeta) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) FileInputStream(java.io.FileInputStream) CsvFileInputStepNode(org.pentaho.metaverse.frames.CsvFileInputStepNode) FileInputStepNode(org.pentaho.metaverse.frames.FileInputStepNode) FixedFileInputStepNode(org.pentaho.metaverse.frames.FixedFileInputStepNode) Test(org.junit.Test)

Example 2 with FileInputStepNode

use of org.pentaho.metaverse.frames.FileInputStepNode in project pentaho-metaverse by pentaho.

the class MetaverseValidationIT method testTextFileInputStep.

@Test
public void testTextFileInputStep() throws Exception {
    // this is testing a specific TextFileInputStep instance
    FileInputStepNode fileInputStepNode = (FileInputStepNode) root.getFileInputStepNode("Populate Table From File", "Sacramento crime stats 2006 file");
    assertNotNull(fileInputStepNode);
    Iterable<FramedMetaverseNode> inputFiles = fileInputStepNode.getInputFiles();
    int countInputFiles = getIterableSize(inputFiles);
    assertEquals(1, countInputFiles);
    for (FramedMetaverseNode inputFile : inputFiles) {
        assertTrue(inputFile.getName().endsWith("SacramentocrimeJanuary2006.csv"));
    }
    assertEquals("Old Text file input", fileInputStepNode.getStepType());
    int countUses = getIterableSize(fileInputStepNode.getFileFieldNodesUses());
    int countInputs = getIterableSize(fileInputStepNode.getInputStreamFields());
    assertEquals(0, countUses);
    int fileFieldCount = 0;
    Iterable<StreamFieldNode> outFields = fileInputStepNode.getOutputStreamFields();
    int countOutputs = getIterableSize(outFields);
    for (StreamFieldNode outField : outFields) {
        assertNotNull(outField.getKettleType());
        FieldNode fieldPopulatesMe = outField.getFieldPopulatesMe();
        assertNotNull(fieldPopulatesMe);
        assertEquals(DictionaryConst.NODE_TYPE_FILE_FIELD, fieldPopulatesMe.getType());
        assertEquals(fileInputStepNode, fieldPopulatesMe.getStepThatInputsMe());
        fileFieldCount++;
    }
    assertEquals(countInputs, fileFieldCount);
    assertEquals(countOutputs, fileFieldCount);
}
Also used : CsvFileInputStepNode(org.pentaho.metaverse.frames.CsvFileInputStepNode) FileInputStepNode(org.pentaho.metaverse.frames.FileInputStepNode) FixedFileInputStepNode(org.pentaho.metaverse.frames.FixedFileInputStepNode) FieldNode(org.pentaho.metaverse.frames.FieldNode) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) FramedMetaverseNode(org.pentaho.metaverse.frames.FramedMetaverseNode) Test(org.junit.Test)

Example 3 with FileInputStepNode

use of org.pentaho.metaverse.frames.FileInputStepNode in project pentaho-metaverse by pentaho.

the class MetaverseValidationIT method testOldTextFileInputStep_filenameFromField.

@Test
public void testOldTextFileInputStep_filenameFromField() throws Exception {
    // this is testing a specific TextFileInputStep instance
    FileInputStepNode fileInputStepNode = root.getOldTextFileInputStepNode_filenameFromField();
    assertNotNull(fileInputStepNode);
    int countUses = getIterableSize(fileInputStepNode.getFileFieldNodesUses());
    int countInputs = getIterableSize(fileInputStepNode.getInputStreamFields());
    assertEquals(1, countUses);
    int fileFieldCount = 0;
    Iterable<StreamFieldNode> outFields = fileInputStepNode.getOutputStreamFields();
    int countOutputs = getIterableSize(outFields);
    for (StreamFieldNode outField : outFields) {
        assertNotNull(outField.getKettleType());
        if (!outField.getName().equals("filename")) {
            FieldNode fieldPopulatesMe = outField.getFieldPopulatesMe();
            assertNotNull(fieldPopulatesMe);
            assertEquals(DictionaryConst.NODE_TYPE_FILE_FIELD, fieldPopulatesMe.getType());
            assertEquals(fileInputStepNode, fieldPopulatesMe.getStepThatInputsMe());
            fileFieldCount++;
        }
    }
    // we should have one more input than file fields since we are reading it off of the input stream
    assertEquals(countInputs - 1, fileFieldCount);
    assertEquals(countOutputs, fileFieldCount);
    String filenameField = null;
    TransMeta tm = new TransMeta(new FileInputStream(fileInputStepNode.getTransNode().getPath()), null, true, null, null);
    for (StepMeta stepMeta : tm.getSteps()) {
        if (stepMeta.getName().equals(fileInputStepNode.getName())) {
            org.pentaho.di.trans.steps.textfileinput.TextFileInputMeta meta = (org.pentaho.di.trans.steps.textfileinput.TextFileInputMeta) getBaseStepMetaFromStepMeta(stepMeta);
            assertTrue(meta.isAcceptingFilenames());
            filenameField = meta.getAcceptingField();
            assertNotNull(filenameField);
            assertEquals(filenameField, fileInputStepNode.getFileFieldNodesUses().iterator().next().getName());
            // this was the one we cared about...
            break;
        }
    }
}
Also used : FieldNode(org.pentaho.metaverse.frames.FieldNode) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) TransMeta(org.pentaho.di.trans.TransMeta) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) FileInputStream(java.io.FileInputStream) CsvFileInputStepNode(org.pentaho.metaverse.frames.CsvFileInputStepNode) FileInputStepNode(org.pentaho.metaverse.frames.FileInputStepNode) FixedFileInputStepNode(org.pentaho.metaverse.frames.FixedFileInputStepNode) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 CsvFileInputStepNode (org.pentaho.metaverse.frames.CsvFileInputStepNode)3 FieldNode (org.pentaho.metaverse.frames.FieldNode)3 FileInputStepNode (org.pentaho.metaverse.frames.FileInputStepNode)3 FixedFileInputStepNode (org.pentaho.metaverse.frames.FixedFileInputStepNode)3 StreamFieldNode (org.pentaho.metaverse.frames.StreamFieldNode)3 FileInputStream (java.io.FileInputStream)2 TransMeta (org.pentaho.di.trans.TransMeta)2 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)2 StepMeta (org.pentaho.di.trans.step.StepMeta)2 FramedMetaverseNode (org.pentaho.metaverse.frames.FramedMetaverseNode)1