Search in sources :

Example 86 with IMetaverseNode

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

the class MongoDbInputStepAnalyzerTest method testCreateOutputFieldNode_noFields.

@Test
public void testCreateOutputFieldNode_noFields() throws Exception {
    ValueMetaInterface vmi = new ValueMeta("field1");
    IAnalysisContext context = mock(IAnalysisContext.class);
    when(meta.getMongoFields()).thenReturn(null);
    doReturn("thisStepName").when(analyzer).getStepName();
    when(node.getLogicalId()).thenReturn("logical id");
    IMetaverseNode node = analyzer.createOutputFieldNode(context, vmi, ExternalResourceStepAnalyzer.RESOURCE, DictionaryConst.NODE_TYPE_TRANS_FIELD);
    assertEquals("field1", node.getName());
    assertNull(node.getProperty(MongoDbInputStepAnalyzer.JSON_PATH));
    assertNull(node.getProperty(MongoDbInputStepAnalyzer.MINMAX_RANGE));
    assertNull(node.getProperty(MongoDbInputStepAnalyzer.OCCUR_RATIO));
    assertNull(node.getProperty(MongoDbInputStepAnalyzer.INDEXED_VALS));
    assertNull(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) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 87 with IMetaverseNode

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

the class MongoDbInputStepAnalyzerTest method testCustomAnalyze.

@Test
public void testCustomAnalyze() throws Exception {
    when(meta.getJsonQuery()).thenReturn("{test:test}");
    when(meta.getCollection()).thenReturn("myCollection");
    when(meta.getQueryIsPipeline()).thenReturn(true);
    IMetaverseNode node = new MetaverseTransientNode("new node");
    analyzer.customAnalyze(meta, node);
    assertNotNull(node);
    assertEquals("{test:test}", node.getProperty(DictionaryConst.PROPERTY_QUERY));
    assertEquals("myCollection", node.getProperty(MongoDbInputStepAnalyzer.COLLECTION));
    assertTrue((Boolean) node.getProperty(MongoDbInputStepAnalyzer.AGG_PIPELINE));
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) MetaverseTransientNode(org.pentaho.dictionary.MetaverseTransientNode) Test(org.junit.Test)

Example 88 with IMetaverseNode

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

the class RestClientStepAnalyzerTest method testCreateResourceNode.

@Test
public void testCreateResourceNode() throws Exception {
    IExternalResourceInfo res = mock(IExternalResourceInfo.class);
    when(res.getName()).thenReturn("http://my.rest.url");
    IMetaverseNode resourceNode = analyzer.createResourceNode(res);
    assertNotNull(resourceNode);
    assertEquals(DictionaryConst.NODE_TYPE_WEBSERVICE, resourceNode.getType());
    assertEquals("http://my.rest.url", resourceNode.getName());
}
Also used : IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) Test(org.junit.Test)

Example 89 with IMetaverseNode

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

the class StringsReplaceStepAnalyzerTest method setUp.

@Before
public void setUp() throws Exception {
    when(stringsReplaceMeta.getFieldInStream()).thenReturn(new String[] { "firstName", "middleName", "lastName" });
    when(stringsReplaceMeta.getFieldOutStream()).thenReturn(new String[] { "", "MN", "lastName" });
    when(stringsReplaceMeta.getFieldReplaceByString()).thenReturn(new String[] { "Tom", "Dick", "Harry" });
    when(stringsReplaceMeta.getReplaceString()).thenReturn(new String[] { "Bill", "Steve", "Jeff" });
    analyzer = spy(new StringsReplaceStepAnalyzer());
    stepFields = new HashSet<>();
    stepFields.add(new StepField("prev", "firstName"));
    stepFields.add(new StepField("prev", "middleName"));
    stepFields.add(new StepField("prev", "lastName"));
    StepNodes stepNodes = mock(StepNodes.class);
    when(stepNodes.findNodes(anyString())).thenAnswer(new Answer<List<IMetaverseNode>>() {

        @Override
        public List<IMetaverseNode> answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            List<IMetaverseNode> foundNodes = new ArrayList<>();
            String fieldName = (String) args[0];
            if (fieldName.equals("firstName") || fieldName.equals("middleName") || fieldName.equals("lastName")) {
                foundNodes.add(mock(IMetaverseNode.class));
            }
            return foundNodes;
        }
    });
    when(analyzer.getInputs()).thenReturn(stepNodes);
    doReturn(stepFields).when(analyzer).createStepFields(anyString(), any(StepNodes.class));
    // Call customAnalyze() for coverage, it does nothing
    analyzer.customAnalyze(stringsReplaceMeta, mock(IMetaverseNode.class));
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) StepField(org.pentaho.metaverse.api.StepField) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArrayList(java.util.ArrayList) List(java.util.List) Matchers.anyString(org.mockito.Matchers.anyString) StepNodes(org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes) Before(org.junit.Before)

Example 90 with IMetaverseNode

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

the class TableInputStepAnalyzerTest method testCreateTableNode.

@Test
public void testCreateTableNode() throws Exception {
    BaseDatabaseResourceInfo resourceInfo = mock(BaseDatabaseResourceInfo.class);
    Map<Object, Object> attributes = new HashMap<>();
    attributes.put(DictionaryConst.PROPERTY_QUERY, "select * from mytable");
    when(resourceInfo.getAttributes()).thenReturn(attributes);
    IMetaverseNode connectionNode = mock(IMetaverseNode.class);
    doReturn(connectionNode).when(analyzer).getConnectionNode();
    when(connectionNode.getLogicalId()).thenReturn("CONNECTION_ID");
    IMetaverseNode resourceNode = analyzer.createTableNode(resourceInfo);
    assertEquals("select * from mytable", resourceNode.getProperty(DictionaryConst.PROPERTY_QUERY));
    assertEquals("SQL", resourceNode.getName());
    assertEquals("CONNECTION_ID", resourceNode.getProperty(DictionaryConst.PROPERTY_NAMESPACE));
}
Also used : BaseDatabaseResourceInfo(org.pentaho.metaverse.api.model.BaseDatabaseResourceInfo) HashMap(java.util.HashMap) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) 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