Search in sources :

Example 1 with StepNodes

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());
}
Also used : ComponentDerivationRecord(org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord) StepNodes(org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes) Test(org.junit.Test)

Example 2 with StepNodes

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;
}
Also used : KettleStepException(org.pentaho.di.core.exception.KettleStepException) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StepNodes(org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 3 with StepNodes

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());
}
Also used : StepField(org.pentaho.metaverse.api.StepField) StepNodes(org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes) Test(org.junit.Test)

Example 4 with StepNodes

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");
}
Also used : StreamLookupMeta(org.pentaho.di.trans.steps.streamlookup.StreamLookupMeta) Matchers.anyString(org.mockito.Matchers.anyString) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) StepNodes(org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Before(org.junit.Before)

Example 5 with StepNodes

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());
        }
    }
}
Also used : ComponentDerivationRecord(org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord) StepNodes(org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes) Test(org.junit.Test)

Aggregations

StepNodes (org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes)17 Test (org.junit.Test)10 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)7 Before (org.junit.Before)6 StepField (org.pentaho.metaverse.api.StepField)5 Matchers.anyString (org.mockito.Matchers.anyString)4 TransMeta (org.pentaho.di.trans.TransMeta)4 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)4 IComponentDescriptor (org.pentaho.metaverse.api.IComponentDescriptor)4 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)2 MetaverseComponentDescriptor (org.pentaho.metaverse.api.MetaverseComponentDescriptor)2 ComponentDerivationRecord (org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 KettleStepException (org.pentaho.di.core.exception.KettleStepException)1 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)1 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)1 StepMeta (org.pentaho.di.trans.step.StepMeta)1 SelectMetadataChange (org.pentaho.di.trans.steps.selectvalues.SelectMetadataChange)1