Search in sources :

Example 31 with IMetaverseNode

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

the class MongoDbInputStepAnalyzerTest method testCreateOutputFieldNode.

@Test
public void testCreateOutputFieldNode() throws Exception {
    IAnalysisContext context = mock(IAnalysisContext.class);
    ValueMetaInterface vmi = new ValueMeta("field1");
    MongoField mongoField1 = new MongoField();
    mongoField1.m_fieldName = "field1";
    mongoField1.m_fieldPath = "$.field1";
    mongoField1.m_arrayIndexInfo = "range";
    mongoField1.m_occurenceFraction = "occurence";
    mongoField1.m_indexedVals = Arrays.asList(new String[] { "one", "two" });
    mongoField1.m_disparateTypes = true;
    mongoField1.m_kettleType = "ValueMetaString";
    mongoField1.m_outputIndex = 0;
    List<MongoField> mongoFields = Arrays.asList(mongoField1);
    when(meta.getMongoFields()).thenReturn(mongoFields);
    doReturn("thisStepName").when(analyzer).getStepName();
    when(node.getLogicalId()).thenReturn("logical id");
    IMetaverseNode node = analyzer.createOutputFieldNode(context, vmi, ExternalResourceStepAnalyzer.RESOURCE, DictionaryConst.NODE_TYPE_TRANS_FIELD);
    assertNotNull(node);
    assertEquals("field1", node.getName());
    assertEquals(mongoField1.m_fieldPath, node.getProperty(MongoDbInputStepAnalyzer.JSON_PATH));
    assertEquals(mongoField1.m_arrayIndexInfo, node.getProperty(MongoDbInputStepAnalyzer.MINMAX_RANGE));
    assertEquals(mongoField1.m_occurenceFraction, node.getProperty(MongoDbInputStepAnalyzer.OCCUR_RATIO));
    assertEquals(mongoField1.m_indexedVals, node.getProperty(MongoDbInputStepAnalyzer.INDEXED_VALS));
    assertEquals(mongoField1.m_disparateTypes, node.getProperty(MongoDbInputStepAnalyzer.DISPARATE_TYPES));
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) IAnalysisContext(org.pentaho.metaverse.api.IAnalysisContext) ValueMeta(org.pentaho.di.core.row.ValueMeta) MongoField(org.pentaho.mongo.wrapper.field.MongoField) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 32 with IMetaverseNode

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

the class TableOutputStepAnalyzerTest method testCustomAnalyze.

@Test
public void testCustomAnalyze() throws Exception {
    when(meta.truncateTable()).thenReturn(true);
    IMetaverseNode node = new MetaverseTransientNode("new node");
    analyzer.customAnalyze(meta, node);
    assertNotNull(node);
    assertTrue((Boolean) node.getProperty(TableOutputStepAnalyzer.TRUNCATE_TABLE));
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) MetaverseTransientNode(org.pentaho.dictionary.MetaverseTransientNode) Test(org.junit.Test)

Example 33 with IMetaverseNode

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

the class TransExecutorStepAnalyzerTest method testConnectResultFieldToSubTrans_noChildTransSteps.

@Test
public void testConnectResultFieldToSubTrans_noChildTransSteps() throws Exception {
    IMetaverseNode childTransNode = mock(IMetaverseNode.class);
    IMetaverseNode rootNode = mock(IMetaverseNode.class);
    when(childTransMeta.getSteps()).thenReturn(null);
    spyAnalyzer.linkResultFieldToSubTrans(rootNode, childTransMeta, childTransNode, descriptor);
    verify(builder, never()).addLink(any(IMetaverseNode.class), eq(DictionaryConst.LINK_DERIVES), any(IMetaverseNode.class));
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) Test(org.junit.Test)

Example 34 with IMetaverseNode

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

the class TransExecutorStepAnalyzerTest method testConnectToSubTransInputFields.

@Test
public void testConnectToSubTransInputFields() throws Exception {
    IMetaverseNode childTransNode = mock(IMetaverseNode.class);
    IMetaverseNode outNode = mock(IMetaverseNode.class);
    StepNodes inputs = new StepNodes();
    inputs.addNode("previousStep", "first", outNode);
    inputs.addNode("previousStep", "last", outNode);
    doReturn(inputs).when(spyAnalyzer).getInputs();
    doNothing().when(spyAnalyzer).linkUsedFieldToSubTrans(any(IMetaverseNode.class), any(TransMeta.class), any(IMetaverseNode.class), any(IComponentDescriptor.class));
    spyAnalyzer.connectToSubTransInputFields(meta, childTransMeta, childTransNode, descriptor);
    verify(spyAnalyzer, times(inputs.getFieldNames().size())).linkUsedFieldToSubTrans(any(IMetaverseNode.class), any(TransMeta.class), any(IMetaverseNode.class), any(IComponentDescriptor.class));
}
Also used : IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) StepNodes(org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes) Test(org.junit.Test)

Example 35 with IMetaverseNode

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

the class TransExecutorStepAnalyzerTest method testLinkUsedFieldToSubTrans.

@Test
public void testLinkUsedFieldToSubTrans() throws Exception {
    IMetaverseNode childTransNode = mock(IMetaverseNode.class);
    IMetaverseNode originalFieldNode = mock(IMetaverseNode.class);
    when(originalFieldNode.getName()).thenReturn(resultsFieldNames[1]);
    List<StepMeta> childTransSteps = new ArrayList<StepMeta>();
    StepMeta dummy = mock(StepMeta.class);
    when(dummy.getStepMetaInterface()).thenReturn(mock(DummyTransMeta.class));
    childTransSteps.add(dummy);
    StepMeta rowsFromResult = mock(StepMeta.class);
    RowsFromResultMeta mockRowsFromResultMeta = mock(RowsFromResultMeta.class);
    when(rowsFromResult.getStepMetaInterface()).thenReturn(mockRowsFromResultMeta);
    when(rowsFromResult.getName()).thenReturn("stepName");
    childTransSteps.add(rowsFromResult);
    when(mockRowsFromResultMeta.getFieldname()).thenReturn(resultsFieldNames);
    StepMeta rowsParentStepMeta = mock(StepMeta.class);
    TransMeta rowsParentTransMeta = mock(TransMeta.class);
    RowMetaInterface rmiRows = mock(RowMetaInterface.class);
    when(mockRowsFromResultMeta.getParentStepMeta()).thenReturn(rowsParentStepMeta);
    when(rowsParentStepMeta.getParentTransMeta()).thenReturn(rowsParentTransMeta);
    when(rowsParentTransMeta.getStepFields(rowsFromResult)).thenReturn(rmiRows);
    when(rmiRows.getFieldNames()).thenReturn(resultsFieldNames);
    ValueMetaInterface vmi = mock(ValueMetaInterface.class);
    when(rmiRows.getValueMeta(anyInt())).thenReturn(vmi);
    when(childTransMeta.getSteps()).thenReturn(childTransSteps);
    IMetaverseNode subFieldNode = mock(IMetaverseNode.class);
    doReturn(subFieldNode).when(spyAnalyzer).createFieldNode(any(IComponentDescriptor.class), any(ValueMetaInterface.class), eq("stepName"), eq(false));
    spyAnalyzer.linkUsedFieldToSubTrans(originalFieldNode, childTransMeta, childTransNode, descriptor);
    verify(spyAnalyzer).createFieldNode(any(IComponentDescriptor.class), any(ValueMetaInterface.class), eq("stepName"), eq(false));
    verify(builder).addLink(eq(originalFieldNode), eq(DictionaryConst.LINK_DERIVES), eq(subFieldNode));
}
Also used : IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) ArrayList(java.util.ArrayList) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) RowsFromResultMeta(org.pentaho.di.trans.steps.rowsfromresult.RowsFromResultMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) 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