use of org.pentaho.metaverse.api.IMetaverseNode in project pentaho-metaverse by pentaho.
the class ExternalResourceStepAnalyzerTest method testCreateInputFieldNode_resource.
@Test
public void testCreateInputFieldNode_resource() throws Exception {
IAnalysisContext context = mock(IAnalysisContext.class);
doReturn("thisStepName").when(analyzer).getStepName();
analyzer.rootNode = node;
when(node.getLogicalId()).thenReturn("logical id");
ValueMetaInterface vmi = new ValueMeta("name", 1);
IMetaverseNode inputFieldNode = analyzer.createInputFieldNode(context, vmi, ExternalResourceStepAnalyzer.RESOURCE, DictionaryConst.NODE_TYPE_TRANS_FIELD);
assertNotNull(inputFieldNode);
assertNotNull(inputFieldNode.getProperty(DictionaryConst.PROPERTY_KETTLE_TYPE));
assertEquals("thisStepName", inputFieldNode.getProperty(DictionaryConst.PROPERTY_TARGET_STEP));
assertEquals("INPUT_TYPE", inputFieldNode.getType());
// the input node should be added by this step
verify(builder).addNode(inputFieldNode);
}
use of org.pentaho.metaverse.api.IMetaverseNode in project pentaho-metaverse by pentaho.
the class StepAnalyzerTest method testGetInputFieldsWithException.
@Test
public void testGetInputFieldsWithException() {
analyzer = new StepAnalyzer() {
@Override
public void validateState(IComponentDescriptor descriptor, BaseStepMeta object) throws MetaverseAnalyzerException {
throw new MetaverseAnalyzerException("expected exception");
}
@Override
public Set<Class<? extends BaseStepMeta>> getSupportedSteps() {
return null;
}
@Override
protected Set getUsedFields(BaseStepMeta meta) {
// TODO Auto-generated method stub
return null;
}
@Override
protected void customAnalyze(BaseStepMeta meta, IMetaverseNode rootNode) throws MetaverseAnalyzerException {
// TODO Auto-generated method stub
}
};
assertNull(analyzer.getInputFields(null));
}
use of org.pentaho.metaverse.api.IMetaverseNode in project pentaho-metaverse by pentaho.
the class StepAnalyzerTest method testProcessInputs.
@Test
public void testProcessInputs() throws Exception {
String[] prevStepNames = new String[] { "prevStep", "prevStep2" };
when(parentTransMeta.getPrevStepNames(parentStepMeta)).thenReturn(prevStepNames);
Map<String, RowMetaInterface> inputRmis = new HashMap<>();
RowMetaInterface rowMetaInterface = mock(RowMetaInterface.class);
RowMetaInterface rowMetaInterface2 = mock(RowMetaInterface.class);
inputRmis.put("prevStep", rowMetaInterface);
inputRmis.put("prevStep2", rowMetaInterface2);
String[] inputFields1 = new String[] { "name", "address", "email", "age" };
String[] inputFields2 = new String[] { "employeeNumber", "occupation" };
when(rowMetaInterface.getFieldNames()).thenReturn(inputFields1);
when(rowMetaInterface2.getFieldNames()).thenReturn(inputFields2);
final List<ValueMetaInterface> vmis = new ArrayList<>();
for (String s : inputFields1) {
vmis.add(new ValueMeta(s));
}
final List<ValueMetaInterface> vmis2 = new ArrayList<>();
for (String s : inputFields2) {
vmis2.add(new ValueMeta(s));
}
when(rowMetaInterface.getValueMetaList()).thenReturn(vmis);
when(rowMetaInterface2.getValueMetaList()).thenReturn(vmis2);
IMetaverseNode inputNode = mock(IMetaverseNode.class);
doReturn(inputRmis).when(analyzer).getInputRowMetaInterfaces(baseStepMeta);
doReturn(inputNode).when(analyzer).createInputFieldNode(any(IAnalysisContext.class), any(ValueMetaInterface.class), anyString(), anyString());
StepNodes stepNodes = analyzer.processInputs(baseStepMeta);
assertNotNull(stepNodes);
verify(builder, times(6)).addLink(any(IMetaverseNode.class), eq(DictionaryConst.LINK_INPUTS), eq(rootNode));
}
use of org.pentaho.metaverse.api.IMetaverseNode in project pentaho-metaverse by pentaho.
the class StepAnalyzerTest method setUp.
@Before
public void setUp() throws Exception {
StepAnalyzer stepAnalyzer = new StepAnalyzer() {
@Override
protected Set<StepField> getUsedFields(BaseStepMeta meta) {
return null;
}
@Override
protected void customAnalyze(BaseStepMeta meta, IMetaverseNode rootNode) throws MetaverseAnalyzerException {
}
@Override
public Set<Class<? extends BaseStepMeta>> getSupportedSteps() {
return null;
}
};
analyzer = spy(stepAnalyzer);
analyzer.rootNode = rootNode;
analyzer.baseStepMeta = baseStepMeta;
analyzer.descriptor = descriptor;
analyzer.parentTransMeta = parentTransMeta;
analyzer.parentStepMeta = parentStepMeta;
usedFields = new HashSet<>();
inputs = new StepNodes();
inputs.addNode("prevStep", "name", fieldNode);
inputs.addNode("prevStep", "address", fieldNode);
inputs.addNode("prevStep", "email", fieldNode);
inputs.addNode("prevStep", "birthday", fieldNode);
inputs.addNode("prevStep2", "employeeNumber", fieldNode);
inputs.addNode("prevStep2", "occupation", fieldNode);
outputs = new StepNodes();
outputs.addNode("nextStep", "full name", fieldNode);
outputs.addNode("nextStep", "address", fieldNode);
outputs.addNode("nextStep", "email", fieldNode);
outputs.addNode("nextStep", "date of birth", fieldNode);
outputs.addNode("nextStep", "ID", fieldNode);
outputs.addNode("nextStep", "occupation", fieldNode);
doReturn(builder).when(analyzer).getMetaverseBuilder();
MetaverseObjectFactory factory = new MetaverseObjectFactory();
doReturn(factory).when(analyzer).getMetaverseObjectFactory();
when(descriptor.getContext()).thenReturn(context);
when(parentStepMeta.getName()).thenReturn("STEP NAME");
}
use of org.pentaho.metaverse.api.IMetaverseNode in project pentaho-metaverse by pentaho.
the class StepAnalyzerTest method testMapChange_originalFieldIsTransient.
@Test
public void testMapChange_originalFieldIsTransient() throws Exception {
doReturn(outputs).when(analyzer).getOutputs();
doReturn(inputs).when(analyzer).getInputs();
IMetaverseNode transientNode = mock(IMetaverseNode.class);
String shouldBeNull = null;
doReturn(transientNode).when(analyzer).createOutputFieldNode(any(IAnalysisContext.class), any(ValueMetaInterface.class), eq(shouldBeNull), eq(DictionaryConst.NODE_TYPE_TRANS_FIELD));
// zip is not in the inputs or outputs, it must have been a temporary fields used internally by step.
StepField original = new StepField(null, "zip");
StepField changed = new StepField("nextStep", "address");
ComponentDerivationRecord cdr = new ComponentDerivationRecord(original, changed);
analyzer.mapChange(cdr);
verify(builder).addLink(rootNode, DictionaryConst.LINK_TRANSIENT, transientNode);
verify(builder).addLink(rootNode, DictionaryConst.LINK_USES, transientNode);
verify(analyzer).linkChangeNodes(eq(transientNode), any(IMetaverseNode.class));
}
Aggregations