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());
}
Aggregations