Search in sources :

Example 1 with ValueMapperMeta

use of org.pentaho.di.trans.steps.valuemapper.ValueMapperMeta 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 2 with ValueMapperMeta

use of org.pentaho.di.trans.steps.valuemapper.ValueMapperMeta in project pentaho-metaverse by pentaho.

the class MetaverseValidationIT method testValueMapperStepNode_overwrite.

@Test
public void testValueMapperStepNode_overwrite() throws Exception {
    TransformationStepNode valueMapperStepNode = root.getStepNode("value_mapper", "Value Mapper - overwrite");
    assertEquals(1, getIterableSize(valueMapperStepNode.getStreamFieldNodesUses()));
    StreamFieldNode usesNode = valueMapperStepNode.getStreamFieldNodesUses().iterator().next();
    ValueMapperMeta meta = (ValueMapperMeta) getStepMeta(valueMapperStepNode);
    assertEquals(meta.getFieldToUse(), usesNode.getName());
    Iterable<StreamFieldNode> inFields = valueMapperStepNode.getInputStreamFields();
    int countInputs = getIterableSize(inFields);
    Iterable<StreamFieldNode> outFields = valueMapperStepNode.getOutputStreamFields();
    int countOutputs = getIterableSize(outFields);
    assertEquals(countInputs, countOutputs);
    for (StreamFieldNode outField : outFields) {
        assertNotNull(outField.getKettleType());
        if (outField.getName().equals(meta.getTargetField())) {
            Operations ops = MetaverseUtil.convertOperationsStringToMap(usesNode.getOperations());
            List<IOperation> dataOps = ops.get(ChangeType.DATA);
            assertNotNull(dataOps);
            assertEquals(meta.getSourceValue().length, dataOps.size());
            for (int i = 0; i < dataOps.size(); i++) {
                IOperation dataOp = dataOps.get(i);
                assertEquals(DictionaryConst.PROPERTY_TRANSFORMS, dataOp.getName());
                assertEquals(dataOp.toString(), meta.getSourceValue()[i] + " -> " + meta.getTargetValue()[i]);
            }
            // there should not be any metadata operations
            assertNull(ops.get(ChangeType.METADATA));
        }
    }
    int derivedCount = getIterableSize(usesNode.getFieldNodesDerivedFromMe());
    assertEquals(1, derivedCount);
}
Also used : IOperation(org.pentaho.metaverse.api.model.IOperation) 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)

Aggregations

Test (org.junit.Test)2 ValueMapperMeta (org.pentaho.di.trans.steps.valuemapper.ValueMapperMeta)2 IOperation (org.pentaho.metaverse.api.model.IOperation)2 Operations (org.pentaho.metaverse.api.model.Operations)2 StreamFieldNode (org.pentaho.metaverse.frames.StreamFieldNode)2 TransformationStepNode (org.pentaho.metaverse.frames.TransformationStepNode)2 FieldNode (org.pentaho.metaverse.frames.FieldNode)1