Search in sources :

Example 1 with CalculatorStepNode

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

the class MetaverseValidationIT method testCalculatorStepNode.

@Test
public void testCalculatorStepNode() throws Exception {
    CalculatorStepNode node = root.getCalculatorStepNode();
    Set<String> usedFields = new HashSet<String>();
    CalculatorMeta calculatorMeta = (CalculatorMeta) getStepMeta(node);
    for (CalculatorMetaFunction calculatorMetaFunction : calculatorMeta.getCalculation()) {
        String fieldName = calculatorMetaFunction.getFieldA();
        if (!StringUtils.isEmpty(fieldName)) {
            usedFields.add(fieldName);
        }
        fieldName = calculatorMetaFunction.getFieldB();
        if (!StringUtils.isEmpty(fieldName)) {
            usedFields.add(fieldName);
        }
        fieldName = calculatorMetaFunction.getFieldC();
        if (!StringUtils.isEmpty(fieldName)) {
            usedFields.add(fieldName);
        }
    }
    int expectedUsedFieldCount = usedFields.size();
    // Make sure we have the right number of links used, created and deleted.
    List<String> nodeUses = new ArrayList<String>();
    for (StreamFieldNode sfn : node.getStreamFieldNodesUses()) {
        nodeUses.add(sfn.getName());
    }
    StreamFieldNode area = null;
    StreamFieldNode kelvin = null;
    StreamFieldNode celsius = null;
    List<String> nodeOutputs = new ArrayList<String>();
    for (StreamFieldNode sfn : node.getOutputStreamFields()) {
        nodeOutputs.add(sfn.getName());
        Operations ops = MetaverseUtil.convertOperationsStringToMap(sfn.getOperations());
        if (sfn.getName().equals("area")) {
            area = sfn;
            assertNotNull(ops.get(ChangeType.DATA));
            assertEquals(Operation.CALC_CATEGORY, ops.get(ChangeType.DATA).get(0).getCategory());
        } else if (sfn.getName().equals("celsius")) {
            celsius = sfn;
            assertNotNull(ops);
            assertNotNull(ops.get(ChangeType.DATA));
            assertEquals(Operation.CALC_CATEGORY, ops.get(ChangeType.DATA).get(0).getCategory());
        } else if (sfn.getName().equals("kelvin")) {
            kelvin = sfn;
            assertNotNull(ops);
            assertNotNull(ops.get(ChangeType.DATA));
            assertEquals(Operation.CALC_CATEGORY, ops.get(ChangeType.DATA).get(0).getCategory());
        }
    }
    assertEquals(2, getIterableSize(area.getFieldNodesThatDeriveMe()));
    String[] fieldsThatDerive = new String[2];
    fieldsThatDerive = new String[2];
    int i = 0;
    for (StreamFieldNode sfn : celsius.getFieldNodesThatDeriveMe()) {
        fieldsThatDerive[i++] = sfn.getName();
    }
    assertTrue(Arrays.asList(fieldsThatDerive).contains("tempCelsius"));
    assertTrue(Arrays.asList(fieldsThatDerive).contains("tempRatio"));
    fieldsThatDerive = new String[2];
    i = 0;
    for (StreamFieldNode sfn : kelvin.getFieldNodesThatDeriveMe()) {
        fieldsThatDerive[i++] = sfn.getName();
    }
    assertTrue(Arrays.asList(fieldsThatDerive).contains("tempKelvin"));
    assertTrue(Arrays.asList(fieldsThatDerive).contains("tempRatio"));
    assertEquals(expectedUsedFieldCount, nodeUses.size());
    assertEquals(getExpectedOutputFieldCount(calculatorMeta), nodeOutputs.size());
}
Also used : CalculatorStepNode(org.pentaho.metaverse.frames.CalculatorStepNode) ArrayList(java.util.ArrayList) CalculatorMeta(org.pentaho.di.trans.steps.calculator.CalculatorMeta) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) CalculatorMetaFunction(org.pentaho.di.trans.steps.calculator.CalculatorMetaFunction) Operations(org.pentaho.metaverse.api.model.Operations) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1 CalculatorMeta (org.pentaho.di.trans.steps.calculator.CalculatorMeta)1 CalculatorMetaFunction (org.pentaho.di.trans.steps.calculator.CalculatorMetaFunction)1 Operations (org.pentaho.metaverse.api.model.Operations)1 CalculatorStepNode (org.pentaho.metaverse.frames.CalculatorStepNode)1 StreamFieldNode (org.pentaho.metaverse.frames.StreamFieldNode)1