Search in sources :

Example 56 with IMetaverseNode

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);
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) IAnalysisContext(org.pentaho.metaverse.api.IAnalysisContext) ValueMeta(org.pentaho.di.core.row.ValueMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 57 with IMetaverseNode

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));
}
Also used : IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) HashSet(java.util.HashSet) Set(java.util.Set) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Test(org.junit.Test)

Example 58 with IMetaverseNode

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));
}
Also used : HashMap(java.util.HashMap) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) ArrayList(java.util.ArrayList) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) IAnalysisContext(org.pentaho.metaverse.api.IAnalysisContext) Matchers.anyString(org.mockito.Matchers.anyString) ValueMeta(org.pentaho.di.core.row.ValueMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 59 with IMetaverseNode

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");
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) MetaverseObjectFactory(org.pentaho.metaverse.api.MetaverseObjectFactory) StepField(org.pentaho.metaverse.api.StepField) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Before(org.junit.Before)

Example 60 with IMetaverseNode

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));
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) StepField(org.pentaho.metaverse.api.StepField) ComponentDerivationRecord(org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord) IAnalysisContext(org.pentaho.metaverse.api.IAnalysisContext) Matchers.anyString(org.mockito.Matchers.anyString) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Aggregations

IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)131 Test (org.junit.Test)77 IComponentDescriptor (org.pentaho.metaverse.api.IComponentDescriptor)30 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)23 MetaverseComponentDescriptor (org.pentaho.metaverse.api.MetaverseComponentDescriptor)16 ValueMeta (org.pentaho.di.core.row.ValueMeta)13 IExternalResourceInfo (org.pentaho.metaverse.api.model.IExternalResourceInfo)12 IAnalysisContext (org.pentaho.metaverse.api.IAnalysisContext)11 MetaverseAnalyzerException (org.pentaho.metaverse.api.MetaverseAnalyzerException)11 Vertex (com.tinkerpop.blueprints.Vertex)10 ArrayList (java.util.ArrayList)10 INamespace (org.pentaho.metaverse.api.INamespace)10 TransMeta (org.pentaho.di.trans.TransMeta)9 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)9 MetaverseTransientNode (org.pentaho.dictionary.MetaverseTransientNode)9 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)8 Namespace (org.pentaho.metaverse.api.Namespace)8 StepField (org.pentaho.metaverse.api.StepField)8 HashMap (java.util.HashMap)7 Matchers.anyString (org.mockito.Matchers.anyString)7