Search in sources :

Example 1 with ExcelInputStepNode

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

the class MetaverseValidationIT method testExcelInputStep.

@Test
public void testExcelInputStep() throws Exception {
    // this is testing a specific TextFileInputStep instance
    ExcelInputStepNode excelInputStepNode = root.getExcelInputStepNode();
    assertNotNull(excelInputStepNode);
    Iterable<FramedMetaverseNode> inputFiles = excelInputStepNode.getInputFiles();
    int countInputFiles = getIterableSize(inputFiles);
    assertEquals(1, countInputFiles);
    for (FramedMetaverseNode inputFile : inputFiles) {
        assertTrue(inputFile.getName().endsWith("SacramentoCrime.xls"));
    }
    assertEquals("Microsoft Excel Input", excelInputStepNode.getStepType());
    int countUses = getIterableSize(excelInputStepNode.getFileFieldNodesUses());
    int countInputs = getIterableSize(excelInputStepNode.getInputStreamFields());
    assertEquals(0, countUses);
    int fileFieldCount = 0;
    Iterable<StreamFieldNode> outFields = excelInputStepNode.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(excelInputStepNode, fieldPopulatesMe.getStepThatInputsMe());
        fileFieldCount++;
    }
    assertEquals(countInputs, fileFieldCount);
    assertEquals(countOutputs, fileFieldCount);
}
Also used : FieldNode(org.pentaho.metaverse.frames.FieldNode) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) ExcelInputStepNode(org.pentaho.metaverse.frames.ExcelInputStepNode) FramedMetaverseNode(org.pentaho.metaverse.frames.FramedMetaverseNode) Test(org.junit.Test)

Example 2 with ExcelInputStepNode

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

the class MetaverseValidationIT method testExcelInputStep_filenameFromField.

@Test
public void testExcelInputStep_filenameFromField() throws Exception {
    // this is testing a specific TextFileInputStep instance
    ExcelInputStepNode excelInputStepNode = root.getExcelInputFileNameFromFieldStepNode();
    assertNotNull(excelInputStepNode);
    int countUses = getIterableSize(excelInputStepNode.getFileFieldNodesUses());
    int countInputs = getIterableSize(excelInputStepNode.getInputStreamFields());
    assertEquals(1, countUses);
    int fileFieldCount = 0;
    Iterable<StreamFieldNode> outFields = excelInputStepNode.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(excelInputStepNode, 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 - 1, fileFieldCount);
    String filenameField = null;
    TransMeta tm = new TransMeta(new FileInputStream(excelInputStepNode.getTransNode().getPath()), null, true, null, null);
    for (StepMeta stepMeta : tm.getSteps()) {
        if (stepMeta.getName().equals(excelInputStepNode.getName())) {
            ExcelInputMeta meta = (ExcelInputMeta) getBaseStepMetaFromStepMeta(stepMeta);
            assertTrue(meta.isAcceptingFilenames());
            filenameField = meta.getAcceptingField();
            assertNotNull(filenameField);
            assertEquals(filenameField, excelInputStepNode.getFileFieldNodesUses().iterator().next().getName());
            // this was the one we cared about...
            break;
        }
    }
}
Also used : ExcelInputMeta(org.pentaho.di.trans.steps.excelinput.ExcelInputMeta) FieldNode(org.pentaho.metaverse.frames.FieldNode) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) TransMeta(org.pentaho.di.trans.TransMeta) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) ExcelInputStepNode(org.pentaho.metaverse.frames.ExcelInputStepNode) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 ExcelInputStepNode (org.pentaho.metaverse.frames.ExcelInputStepNode)2 FieldNode (org.pentaho.metaverse.frames.FieldNode)2 StreamFieldNode (org.pentaho.metaverse.frames.StreamFieldNode)2 FileInputStream (java.io.FileInputStream)1 TransMeta (org.pentaho.di.trans.TransMeta)1 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)1 StepMeta (org.pentaho.di.trans.step.StepMeta)1 ExcelInputMeta (org.pentaho.di.trans.steps.excelinput.ExcelInputMeta)1 FramedMetaverseNode (org.pentaho.metaverse.frames.FramedMetaverseNode)1