Search in sources :

Example 46 with StepField

use of org.pentaho.metaverse.api.StepField in project pentaho-metaverse by pentaho.

the class StepAnalyzerTest method testMapChange_changedFieldIsTransient.

@Test
public void testMapChange_changedFieldIsTransient() 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("nextStep", "address");
    StepField changed = new StepField(null, "zip");
    ComponentDerivationRecord cdr = new ComponentDerivationRecord(original, changed);
    analyzer.mapChange(cdr);
    verify(builder).addLink(rootNode, "transient", transientNode);
    verify(analyzer).linkChangeNodes(any(IMetaverseNode.class), eq(transientNode));
}
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)

Example 47 with StepField

use of org.pentaho.metaverse.api.StepField in project pentaho-metaverse by pentaho.

the class StepAnalyzerTest method testCreateStepFields.

@Test
public void testCreateStepFields() throws Exception {
    StepNodes stepNodes = new StepNodes();
    IMetaverseNode node = mock(IMetaverseNode.class);
    stepNodes.addNode("step1", "fieldname1", node);
    stepNodes.addNode("step2", "fieldname2", node);
    Set<StepField> test = analyzer.createStepFields("test", stepNodes);
    assertEquals(2, test.size());
    for (StepField stepField : test) {
        assertEquals("test", stepField.getFieldName());
    }
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) StepField(org.pentaho.metaverse.api.StepField) Test(org.junit.Test)

Example 48 with StepField

use of org.pentaho.metaverse.api.StepField in project pentaho-metaverse by pentaho.

the class StepAnalyzerTest method testIsPassthrough.

@Test
public void testIsPassthrough() throws Exception {
    doReturn(outputs).when(analyzer).getOutputs();
    StepField testField = new StepField("previousStep2", "occupation");
    assertTrue(analyzer.isPassthrough(testField));
}
Also used : StepField(org.pentaho.metaverse.api.StepField) Test(org.junit.Test)

Example 49 with StepField

use of org.pentaho.metaverse.api.StepField in project pentaho-metaverse by pentaho.

the class StepAnalyzerTest method testAnalyze.

@Test
public void testAnalyze() throws Exception {
    when(baseStepMeta.getParentStepMeta()).thenReturn(parentStepMeta);
    when(parentStepMeta.getCopies()).thenReturn(2);
    analyzer.setMetaverseBuilder(builder);
    doNothing().when(analyzer).validateState(descriptor, baseStepMeta);
    doReturn(null).when(analyzer).processInputs(baseStepMeta);
    doReturn(null).when(analyzer).processOutputs(baseStepMeta);
    Set<StepField> usedFields = new HashSet<>();
    usedFields.add(new StepField("inputStep", "name"));
    doReturn(usedFields).when(analyzer).getUsedFields(baseStepMeta);
    doNothing().when(analyzer).processUsedFields(usedFields);
    Set<ComponentDerivationRecord> changeRecords = new HashSet<>();
    changeRecords.add(mock(ComponentDerivationRecord.class));
    changeRecords.add(mock(ComponentDerivationRecord.class));
    doReturn(changeRecords).when(analyzer).getChanges();
    doNothing().when(analyzer).mapChange(any(ComponentDerivationRecord.class));
    MetaverseTransientNode node = new MetaverseTransientNode("hello");
    doNothing().when(analyzer).customAnalyze(baseStepMeta, node);
    when(parentStepMeta.getStepID()).thenReturn("step id");
    doReturn(node).when(analyzer).createNodeFromDescriptor(descriptor);
    IMetaverseNode analyzedNode = analyzer.analyze(descriptor, baseStepMeta);
    assertNotNull(analyzedNode.getProperty("stepType"));
    assertEquals(2, analyzedNode.getProperty("copies"));
    assertEquals(analyzer.getClass().getSimpleName(), analyzedNode.getProperty("_analyzer"));
    verify(builder).addNode(analyzedNode);
    verify(analyzer).processInputs(baseStepMeta);
    verify(analyzer).processOutputs(baseStepMeta);
    verify(analyzer).getUsedFields(baseStepMeta);
    verify(analyzer).processUsedFields(usedFields);
    verify(analyzer).getChanges();
    verify(analyzer, times(changeRecords.size())).mapChange(any(ComponentDerivationRecord.class));
    verify(analyzer).customAnalyze(baseStepMeta, analyzedNode);
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) StepField(org.pentaho.metaverse.api.StepField) MetaverseTransientNode(org.pentaho.dictionary.MetaverseTransientNode) ComponentDerivationRecord(org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 50 with StepField

use of org.pentaho.metaverse.api.StepField in project pentaho-kettle by pentaho.

the class GetXMLDataStepAnalyzerTest method testGetUsedFields.

@Test
public void testGetUsedFields() throws Exception {
    when(meta.isInFields()).thenReturn(true);
    when(meta.getXMLField()).thenReturn("xml");
    StepNodes inputs = new StepNodes();
    inputs.addNode("previousStep", "xml", node);
    inputs.addNode("previousStep", "otherField", node);
    doReturn(inputs).when(analyzer).getInputs();
    Set<StepField> usedFields = analyzer.getUsedFields(meta);
    assertEquals(1, usedFields.size());
    assertEquals("xml", usedFields.iterator().next().getFieldName());
}
Also used : StepField(org.pentaho.metaverse.api.StepField) StepNodes(org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes) Test(org.junit.Test)

Aggregations

StepField (org.pentaho.metaverse.api.StepField)53 Test (org.junit.Test)33 HashSet (java.util.HashSet)23 StepNodes (org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes)11 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)10 ComponentDerivationRecord (org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord)10 Matchers.anyString (org.mockito.Matchers.anyString)6 Before (org.junit.Before)4 SelectMetadataChange (org.pentaho.di.trans.steps.selectvalues.SelectMetadataChange)4 Set (java.util.Set)3 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)3 MetaverseObjectFactory (org.pentaho.metaverse.api.MetaverseObjectFactory)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)2 IAnalysisContext (org.pentaho.metaverse.api.IAnalysisContext)2 IExternalResourceInfo (org.pentaho.metaverse.api.model.IExternalResourceInfo)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Graph (com.tinkerpop.blueprints.Graph)1 Vertex (com.tinkerpop.blueprints.Vertex)1