Search in sources :

Example 1 with FieldNode

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

the class MetaverseValidationIT method testFixedFileInputStep.

@Test
public void testFixedFileInputStep() throws Exception {
    // this is testing a specific FixedFileInputStep instance
    FixedFileInputStepNode fixedFileInputStepNode = root.getFixedFileInputStepNode();
    assertNotNull(fixedFileInputStepNode);
    Iterable<FramedMetaverseNode> inputFiles = fixedFileInputStepNode.getInputFiles();
    int countInputFiles = getIterableSize(inputFiles);
    assertEquals(1, countInputFiles);
    for (FramedMetaverseNode inputFile : inputFiles) {
        assertTrue(inputFile.getName().endsWith("Textfile input - fixed length sample data.txt"));
    }
    assertEquals("Fixed file input", fixedFileInputStepNode.getStepType());
    int countFileFieldNode = getIterableSize(fixedFileInputStepNode.getFileFieldNodesUses());
    assertEquals(0, countFileFieldNode);
    int countOutputs = getIterableSize(fixedFileInputStepNode.getOutputStreamFields());
    int fileFieldCount = 0;
    Iterable<StreamFieldNode> outFields = fixedFileInputStepNode.getOutputStreamFields();
    for (StreamFieldNode outField : outFields) {
        assertNotNull(outField.getKettleType());
        FieldNode fieldPopulatesMe = outField.getFieldPopulatesMe();
        assertNotNull(fieldPopulatesMe);
        assertEquals(DictionaryConst.NODE_TYPE_FILE_FIELD, fieldPopulatesMe.getType());
        assertEquals(fixedFileInputStepNode, fieldPopulatesMe.getStepThatInputsMe());
        fileFieldCount++;
    }
    assertEquals(countOutputs, fileFieldCount);
}
Also used : FieldNode(org.pentaho.metaverse.frames.FieldNode) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) FramedMetaverseNode(org.pentaho.metaverse.frames.FramedMetaverseNode) FixedFileInputStepNode(org.pentaho.metaverse.frames.FixedFileInputStepNode) Test(org.junit.Test)

Example 2 with FieldNode

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

the class MetaverseValidationIT method testNumberRangeStepNode_newField.

@Test
public void testNumberRangeStepNode_newField() throws Exception {
    TransformationStepNode numberRangeStepNode = root.getStepNode("number_range", "Number range");
    assertEquals(1, getIterableSize(numberRangeStepNode.getStreamFieldNodesUses()));
    StreamFieldNode usesNode = null;
    for (StreamFieldNode node : numberRangeStepNode.getStreamFieldNodesUses()) {
        usesNode = node;
        break;
    }
    NumberRangeMeta meta = (NumberRangeMeta) getStepMeta(numberRangeStepNode);
    assertEquals(meta.getInputField(), usesNode.getName());
    assertNull(usesNode.getOperations());
    Iterable<StreamFieldNode> outFields = numberRangeStepNode.getOutputStreamFields();
    int countOutputs = getIterableSize(outFields);
    assertEquals(2, countOutputs);
    for (StreamFieldNode outField : outFields) {
        assertNotNull(outField.getKettleType());
        if (outField.getName().equals(meta.getOutputField())) {
            Iterable<StreamFieldNode> fieldNodesThatDeriveMe = outField.getFieldNodesThatDeriveMe();
            assertNotNull(fieldNodesThatDeriveMe);
            int derivesCount = getIterableSize(outField.getFieldNodesThatDeriveMe());
            assertEquals(1, derivesCount);
            for (FieldNode derives : outField.getFieldNodesThatDeriveMe()) {
                assertEquals(usesNode.getName(), derives.getName());
                assertEquals(usesNode.getType(), derives.getType());
            }
            Operations ops = MetaverseUtil.convertOperationsStringToMap(outField.getOperations());
            List<IOperation> dataOps = ops.get(ChangeType.DATA);
            assertNotNull(dataOps);
            assertEquals(3, dataOps.size());
            for (IOperation dataOp : dataOps) {
                assertEquals(Operation.MAPPING_CATEGORY, dataOp.getCategory());
                assertEquals(DictionaryConst.PROPERTY_TRANSFORMS, dataOp.getName());
                assertTrue(dataOp.toString().contains(meta.getInputField()));
            }
            // there should not be any metadata operations
            assertNull(ops.get(ChangeType.METADATA));
        }
    }
}
Also used : IOperation(org.pentaho.metaverse.api.model.IOperation) FieldNode(org.pentaho.metaverse.frames.FieldNode) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) TransformationStepNode(org.pentaho.metaverse.frames.TransformationStepNode) NumberRangeMeta(org.pentaho.di.trans.steps.numberrange.NumberRangeMeta) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) Operations(org.pentaho.metaverse.api.model.Operations) Test(org.junit.Test)

Example 3 with FieldNode

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

the class MetaverseValidationIT method testValueMapperStepNode_newField.

@Test
public void testValueMapperStepNode_newField() throws Exception {
    TransformationStepNode valueMapperStepNode = root.getStepNode("value_mapper", "Value Mapper - new field");
    assertEquals(1, getIterableSize(valueMapperStepNode.getStreamFieldNodesUses()));
    StreamFieldNode usesNode = valueMapperStepNode.getStreamFieldNodesUses().iterator().next();
    ValueMapperMeta meta = (ValueMapperMeta) getStepMeta(valueMapperStepNode);
    assertEquals(meta.getFieldToUse(), usesNode.getName());
    assertNull(usesNode.getOperations());
    Iterable<StreamFieldNode> inFields = valueMapperStepNode.getInputStreamFields();
    int countInputs = getIterableSize(inFields);
    Iterable<StreamFieldNode> outFields = valueMapperStepNode.getOutputStreamFields();
    int countOutputs = getIterableSize(outFields);
    assertEquals(countInputs + 1, countOutputs);
    for (StreamFieldNode outField : outFields) {
        assertNotNull(outField.getKettleType());
        if (outField.getName().equals(meta.getTargetField())) {
            Iterable<StreamFieldNode> fieldNodesThatDeriveMe = outField.getFieldNodesThatDeriveMe();
            assertNotNull(fieldNodesThatDeriveMe);
            int derivesCount = getIterableSize(outField.getFieldNodesThatDeriveMe());
            assertEquals(1, derivesCount);
            for (FieldNode derives : outField.getFieldNodesThatDeriveMe()) {
                assertEquals(usesNode.getName(), derives.getName());
                assertEquals(usesNode.getType(), derives.getType());
            }
            Operations ops = MetaverseUtil.convertOperationsStringToMap(outField.getOperations());
            List<IOperation> dataOps = ops.get(ChangeType.DATA);
            assertNotNull(dataOps);
            assertEquals(1, dataOps.size());
            for (IOperation dataOp : dataOps) {
                assertEquals(Operation.MAPPING_CATEGORY, dataOp.getCategory());
                assertEquals(DictionaryConst.PROPERTY_TRANSFORMS, dataOp.getName());
            }
            // there should not be any metadata operations
            assertNull(ops.get(ChangeType.METADATA));
        }
    }
}
Also used : IOperation(org.pentaho.metaverse.api.model.IOperation) FieldNode(org.pentaho.metaverse.frames.FieldNode) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) TransformationStepNode(org.pentaho.metaverse.frames.TransformationStepNode) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) Operations(org.pentaho.metaverse.api.model.Operations) ValueMapperMeta(org.pentaho.di.trans.steps.valuemapper.ValueMapperMeta) Test(org.junit.Test)

Example 4 with FieldNode

use of org.pentaho.metaverse.frames.FieldNode 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 5 with FieldNode

use of org.pentaho.metaverse.frames.FieldNode 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)

Aggregations

Test (org.junit.Test)9 FieldNode (org.pentaho.metaverse.frames.FieldNode)9 StreamFieldNode (org.pentaho.metaverse.frames.StreamFieldNode)9 CsvFileInputStepNode (org.pentaho.metaverse.frames.CsvFileInputStepNode)4 FixedFileInputStepNode (org.pentaho.metaverse.frames.FixedFileInputStepNode)4 FramedMetaverseNode (org.pentaho.metaverse.frames.FramedMetaverseNode)4 FileInputStream (java.io.FileInputStream)3 TransMeta (org.pentaho.di.trans.TransMeta)3 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)3 StepMeta (org.pentaho.di.trans.step.StepMeta)3 FileInputStepNode (org.pentaho.metaverse.frames.FileInputStepNode)3 IOperation (org.pentaho.metaverse.api.model.IOperation)2 Operations (org.pentaho.metaverse.api.model.Operations)2 ExcelInputStepNode (org.pentaho.metaverse.frames.ExcelInputStepNode)2 TransformationStepNode (org.pentaho.metaverse.frames.TransformationStepNode)2 ExcelInputMeta (org.pentaho.di.trans.steps.excelinput.ExcelInputMeta)1 NumberRangeMeta (org.pentaho.di.trans.steps.numberrange.NumberRangeMeta)1 ValueMapperMeta (org.pentaho.di.trans.steps.valuemapper.ValueMapperMeta)1