use of org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes in project pentaho-kettle by pentaho.
the class GetXMLDataStepAnalyzerTest method testGetChangeRecords.
@Test
public void testGetChangeRecords() throws Exception {
when(meta.isInFields()).thenReturn(true);
when(meta.getIsAFile()).thenReturn(false);
when(meta.isReadUrl()).thenReturn(false);
when(meta.getXMLField()).thenReturn("xml");
analyzer.setBaseStepMeta(meta);
GetXMLDataField[] fields = new GetXMLDataField[2];
GetXMLDataField field1 = new GetXMLDataField("name");
GetXMLDataField field2 = new GetXMLDataField("age");
field1.setXPath("field1/xpath");
field2.setElementType(1);
field1.setResultType(1);
field2.setRepeated(true);
fields[0] = field1;
fields[1] = field2;
when(meta.getInputFields()).thenReturn(fields);
StepNodes inputs = new StepNodes();
inputs.addNode("previousStep", "xml", node);
doReturn(inputs).when(analyzer).getInputs();
Set<ComponentDerivationRecord> changeRecords = analyzer.getChangeRecords(meta);
assertNotNull(changeRecords);
assertEquals(2, changeRecords.size());
}
use of org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes in project pentaho-metaverse by pentaho.
the class RowsFromResultStepAnalyzer method processInputs.
@Override
protected StepNodes processInputs(RowsFromResultMeta meta) {
StepNodes inputs = new StepNodes();
// get all input steps
String[] fieldNames = meta.getFieldname();
for (int j = 0; j < fieldNames.length; j++) {
String fieldName = fieldNames[j];
RowMetaInterface rmi = null;
try {
rmi = parentTransMeta.getStepFields(parentStepMeta);
int type = rmi.getValueMeta(j).getType();
ValueMetaInterface vmi = rmi.getValueMeta(j);
// IMetaverseNode prevFieldNode = createInputFieldNode( StepAnalyzer.NONE, fieldName, type );
IMetaverseNode prevFieldNode = createInputFieldNode(descriptor.getContext(), vmi, StepAnalyzer.NONE, getInputNodeType());
getMetaverseBuilder().addLink(prevFieldNode, DictionaryConst.LINK_INPUTS, rootNode);
inputs.addNode(StepAnalyzer.NONE, fieldName, prevFieldNode);
} catch (KettleStepException e) {
// eat it
}
}
return inputs;
}
use of org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes in project pentaho-metaverse by pentaho.
the class CalculatorStepAnalyzerTest method testGetUsedFields.
@Test
public void testGetUsedFields() throws Exception {
StepNodes inputNodes = new StepNodes();
inputNodes.addNode("input", "height", node);
inputNodes.addNode("input", "width", node);
inputNodes.addNode("input", "radius", node);
inputNodes.addNode("input", "pi", node);
inputNodes.addNode("input", "two", node);
inputNodes.addNode("input", "NOT USED", node);
when(analyzer.getInputs()).thenReturn(inputNodes);
Set<StepField> usedFields = analyzer.getUsedFields(calculatorMeta);
assertEquals(5, usedFields.size());
}
use of org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes in project pentaho-metaverse by pentaho.
the class StreamLookupStepAnalyzerTest method setUp.
@Before
public void setUp() throws Exception {
streams = new ArrayList<>(2);
streams.add(stream1);
streams.add(stream2);
outValueMetas = new ArrayList<>(4);
outValueMetas.add(leftField1);
outValueMetas.add(leftField2);
outValueMetas.add(rightField1);
outValueMetas.add(rightField2);
when(streamLookupMeta.getStepIOMeta()).thenReturn(stepIoMeta);
when(streamLookupMeta.getParentStepMeta()).thenReturn(parentStepMeta);
when(streamLookupMeta.getKeylookup()).thenReturn(mockKeylookup);
when(streamLookupMeta.getKeystream()).thenReturn(mockKeystream);
when(streamLookupMeta.getValue()).thenReturn(mockValues);
when(streamLookupMeta.getValueName()).thenReturn(mockValueNames);
when(parentStepMeta.getParentTransMeta()).thenReturn(parentTransMeta);
when(stepIoMeta.getInfoStreams()).thenReturn(streams);
when(stepMeta1.getName()).thenReturn("step1");
when(stepMeta2.getName()).thenReturn("step2");
when(stream1.getStepMeta()).thenReturn(stepMeta1);
when(stream1.getStepname()).thenReturn("step1");
when(stream2.getStepMeta()).thenReturn(stepMeta2);
when(stream2.getStepname()).thenReturn("step2");
when(parentTransMeta.getStepFields(stepMeta1)).thenReturn(rowMeta1);
when(parentTransMeta.getStepFields(stepMeta2)).thenReturn(rowMeta2);
when(parentTransMeta.getStepFields(parentStepMeta)).thenReturn(stepRowMeta);
when(parentTransMeta.getStepFields("step1")).thenReturn(step1RowMeta);
when(parentTransMeta.getStepFields("step2")).thenReturn(step2RowMeta);
when(step1RowMeta.searchValueMeta(anyString())).thenReturn(mock(ValueMetaInterface.class));
String[] stepNames = { "step1", "step2" };
when(parentTransMeta.getPrevStepNames(any(StepMeta.class))).thenReturn(stepNames);
when(parentTransMeta.getPrevStepNames(anyString())).thenReturn(stepNames);
analyzer = spy(new StreamLookupStepAnalyzer());
analyzer.setParentStepMeta(parentStepMeta);
analyzer.setParentTransMeta(parentTransMeta);
analyzer.setMetaverseBuilder(builder);
inputs = new StepNodes();
inputs.addNode("step1", "Country", mockFieldNode);
inputs.addNode("step2", "State", mockFieldNode);
when(analyzer.getInputs()).thenReturn(inputs);
when(analyzer.getOutputFields(any(StreamLookupMeta.class))).thenReturn(outputRowMeta);
ValueMetaInterface searchFieldResult = mock(ValueMetaInterface.class);
when(outputRowMeta.searchValueMeta(anyString())).thenReturn(searchFieldResult);
when(searchFieldResult.getOrigin()).thenReturn("step1");
when(searchFieldResult.getName()).thenReturn("country_code");
}
use of org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes in project pentaho-metaverse by pentaho.
the class TableOutputStepAnalyzerTest method testGetChangeRecords.
@Test
public void testGetChangeRecords() throws Exception {
String[] tableFields = new String[] { "field1", "field2" };
when(meta.getFieldDatabase()).thenReturn(tableFields);
String[] streamFields = new String[] { "f1", "field2", "field3" };
when(meta.getFieldStream()).thenReturn(streamFields);
StepNodes inputs = new StepNodes();
inputs.addNode("prevStep", "f1", node);
inputs.addNode("prevStep", "field2", node);
inputs.addNode("prevStep", "field3", node);
inputs.addNode(ExternalResourceStepAnalyzer.RESOURCE, "field1", node);
inputs.addNode(ExternalResourceStepAnalyzer.RESOURCE, "field2", node);
doReturn(inputs).when(analyzer).getInputs();
Set<ComponentDerivationRecord> changeRecords = analyzer.getChangeRecords(meta);
assertNotNull(changeRecords);
assertEquals(tableFields.length, changeRecords.size());
for (ComponentDerivationRecord changeRecord : changeRecords) {
if ("f1".equals(changeRecord.getOriginalEntityName())) {
assertEquals("field1", changeRecord.getChangedEntityName());
} else if ("field2".equals(changeRecord.getOriginalEntityName())) {
assertEquals("field2", changeRecord.getChangedEntityName());
} else {
fail("We encountered a change record that shouldn't be here - " + changeRecord.toString());
}
}
}
Aggregations