Search in sources :

Example 16 with MetaverseTransientNode

use of org.pentaho.dictionary.MetaverseTransientNode in project pentaho-metaverse by pentaho.

the class StepAnalyzerTest method testCreateOutputFieldNode.

@Test
public void testCreateOutputFieldNode() throws Exception {
    doReturn("thisStepName").when(analyzer).getStepName();
    MetaverseTransientNode node = new MetaverseTransientNode("node id");
    doReturn(node).when(analyzer).createNodeFromDescriptor(any(IComponentDescriptor.class));
    ValueMetaInterface vmi = new ValueMeta("name", 1);
    IMetaverseNode outputFieldNode = analyzer.createOutputFieldNode(descriptor.getContext(), vmi, "thisStepName", DictionaryConst.NODE_TYPE_TRANS_FIELD);
    assertNotNull(outputFieldNode);
    assertNotNull(outputFieldNode.getProperty(DictionaryConst.PROPERTY_KETTLE_TYPE));
    assertEquals("thisStepName", outputFieldNode.getProperty(DictionaryConst.PROPERTY_TARGET_STEP));
    // the input node should be added by this step
    verify(builder).addNode(outputFieldNode);
}
Also used : IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) MetaverseTransientNode(org.pentaho.dictionary.MetaverseTransientNode) ValueMeta(org.pentaho.di.core.row.ValueMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 17 with MetaverseTransientNode

use of org.pentaho.dictionary.MetaverseTransientNode 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 18 with MetaverseTransientNode

use of org.pentaho.dictionary.MetaverseTransientNode in project pentaho-metaverse by pentaho.

the class StepAnalyzerTest method testCreateFieldNode_NoTargetStep.

@Test
public void testCreateFieldNode_NoTargetStep() throws Exception {
    IComponentDescriptor fieldDescriptor = mock(IComponentDescriptor.class);
    ValueMetaInterface fieldMeta = new ValueMeta("address");
    MetaverseTransientNode node = new MetaverseTransientNode("hello");
    doReturn(node).when(analyzer).createNodeFromDescriptor(fieldDescriptor);
    IMetaverseNode fieldNode = analyzer.createFieldNode(fieldDescriptor, fieldMeta, null, true);
    assertNotNull(fieldNode);
    assertNotNull(fieldNode.getProperty(DictionaryConst.PROPERTY_KETTLE_TYPE));
    assertNull(fieldNode.getProperty(DictionaryConst.PROPERTY_TARGET_STEP));
    // make sure it did not added to the graph
    verify(builder, never()).addNode(node);
}
Also used : IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) MetaverseTransientNode(org.pentaho.dictionary.MetaverseTransientNode) ValueMeta(org.pentaho.di.core.row.ValueMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Aggregations

MetaverseTransientNode (org.pentaho.dictionary.MetaverseTransientNode)18 Test (org.junit.Test)13 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)9 ValueMeta (org.pentaho.di.core.row.ValueMeta)5 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)5 IComponentDescriptor (org.pentaho.metaverse.api.IComponentDescriptor)5 Vertex (com.tinkerpop.blueprints.Vertex)4 Edge (com.tinkerpop.blueprints.Edge)3 Before (org.junit.Before)3 MetaverseLink (org.pentaho.dictionary.MetaverseLink)3 IMetaverseLink (org.pentaho.metaverse.api.IMetaverseLink)3 MetaverseComponentDescriptor (org.pentaho.metaverse.api.MetaverseComponentDescriptor)3 Matchers.anyString (org.mockito.Matchers.anyString)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 HashSet (java.util.HashSet)1 StepField (org.pentaho.metaverse.api.StepField)1 ComponentDerivationRecord (org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord)1