Search in sources :

Example 41 with IExternalResourceInfo

use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.

the class HTTPClientExternalResourceConsumer method getResourcesFromRow.

@Override
public Collection<IExternalResourceInfo> getResourcesFromRow(HTTP httpClientInput, RowMetaInterface rowMeta, Object[] row) {
    Collection<IExternalResourceInfo> resources = new LinkedList<IExternalResourceInfo>();
    // For some reason the step doesn't return the StepMetaInterface directly, so go around it
    HTTPMeta meta = (HTTPMeta) httpClientInput.getStepMetaInterface();
    if (meta == null) {
        meta = (HTTPMeta) httpClientInput.getStepMeta().getStepMetaInterface();
    }
    if (meta != null) {
        try {
            String url;
            if (meta.isUrlInField()) {
                url = rowMeta.getString(row, meta.getUrlField(), null);
            } else {
                url = meta.getUrl();
            }
            if (!Const.isEmpty(url)) {
                WebServiceResourceInfo resourceInfo = (WebServiceResourceInfo) ExternalResourceInfoFactory.createURLResource(url, true);
                if (ArrayUtils.isNotEmpty(meta.getHeaderField())) {
                    for (int i = 0; i < meta.getHeaderField().length; i++) {
                        String field = meta.getHeaderField()[i];
                        String label = meta.getHeaderParameter()[i];
                        resourceInfo.addHeader(label, rowMeta.getString(row, field, null));
                    }
                }
                if (ArrayUtils.isNotEmpty(meta.getArgumentField())) {
                    for (int i = 0; i < meta.getArgumentField().length; i++) {
                        String field = meta.getArgumentField()[i];
                        String label = meta.getArgumentParameter()[i];
                        resourceInfo.addParameter(label, rowMeta.getString(row, field, null));
                    }
                }
                resources.add(resourceInfo);
            }
        } catch (KettleException kve) {
        // TODO throw exception or ignore?
        }
    }
    return resources;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) WebServiceResourceInfo(org.pentaho.metaverse.api.model.WebServiceResourceInfo) LinkedList(java.util.LinkedList) HTTPMeta(org.pentaho.di.trans.steps.http.HTTPMeta)

Example 42 with IExternalResourceInfo

use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.

the class StepExternalResourceConsumerListenerTest method testCallStepAddExternalResources.

@Test
public void testCallStepAddExternalResources() {
    StepExternalResourceConsumerListener stepExtensionPoint = new StepExternalResourceConsumerListener();
    stepExtensionPoint.addExternalResources(null, null);
    StepInterface mockStep = mock(StepInterface.class);
    Trans mockTrans = mock(Trans.class);
    when(mockStep.getTrans()).thenReturn(mockTrans);
    IExecutionProfile executionProfile = mock(IExecutionProfile.class);
    IExecutionData executionData = mock(IExecutionData.class);
    when(executionProfile.getExecutionData()).thenReturn(executionData);
    LineageHolder holder = new LineageHolder();
    holder.setExecutionProfile(executionProfile);
    TransLineageHolderMap.getInstance().putLineageHolder(mockTrans, holder);
    Collection<IExternalResourceInfo> externalResources = new ArrayList<IExternalResourceInfo>();
    stepExtensionPoint.addExternalResources(externalResources, mockStep);
    IExternalResourceInfo externalResource = mock(IExternalResourceInfo.class);
    externalResources.add(externalResource);
    stepExtensionPoint.addExternalResources(externalResources, mockStep);
}
Also used : StepInterface(org.pentaho.di.trans.step.StepInterface) IExecutionData(org.pentaho.metaverse.api.model.IExecutionData) IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) IExecutionProfile(org.pentaho.metaverse.api.model.IExecutionProfile) ArrayList(java.util.ArrayList) Trans(org.pentaho.di.trans.Trans) LineageHolder(org.pentaho.metaverse.api.model.LineageHolder) Test(org.junit.Test)

Example 43 with IExternalResourceInfo

use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.

the class ExcelInputStepAnalyzerTest method resourcesFromRowGotSuccessfullyWhenStepInputMetaInterfaceIsNull.

@Test
public void resourcesFromRowGotSuccessfullyWhenStepInputMetaInterfaceIsNull() throws Exception {
    StepMeta mockedStepMeta = mock(StepMeta.class);
    when(excelInput.getStepMetaInterface()).thenReturn(null);
    when(excelInput.getStepMeta()).thenReturn(mockedStepMeta);
    when(mockedStepMeta.getStepMetaInterface()).thenReturn(new ExcelInputMeta());
    when(rmi.getString(Mockito.any(Object[].class), Mockito.anyString(), Mockito.anyString())).thenReturn("/path/to/row/file");
    Collection<IExternalResourceInfo> resources = consumer.getResourcesFromRow(excelInput, rmi, ROW);
    assertEquals(1, resources.size());
}
Also used : ExcelInputMeta(org.pentaho.di.trans.steps.excelinput.ExcelInputMeta) IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Test(org.junit.Test)

Example 44 with IExternalResourceInfo

use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.

the class ExcelOutputStepAnalyzerTest method testExcelOutputExternalResourceConsumer.

@Test
public void testExcelOutputExternalResourceConsumer() throws Exception {
    ExcelOutputExternalResourceConsumer consumer = new ExcelOutputExternalResourceConsumer();
    StepMeta meta = new StepMeta("test", this.meta);
    StepMeta spyMeta = spy(meta);
    when(this.meta.getParentStepMeta()).thenReturn(spyMeta);
    when(spyMeta.getParentTransMeta()).thenReturn(transMeta);
    when(this.meta.getFileName()).thenReturn(null);
    String[] filePaths = { "/path/to/file1", "/another/path/to/file2" };
    when(this.meta.getFiles(Mockito.any(VariableSpace.class))).thenReturn(filePaths);
    assertFalse(consumer.isDataDriven(this.meta));
    Collection<IExternalResourceInfo> resources = consumer.getResourcesFromMeta(this.meta);
    assertFalse(resources.isEmpty());
    assertEquals(2, resources.size());
    when(this.meta.getExtension()).thenReturn("xls");
    assertFalse(consumer.getResourcesFromMeta(this.meta).isEmpty());
    data.realFilename = "/path/to/row/file";
    when(step.buildFilename()).thenAnswer(new Answer<String>() {

        @Override
        public String answer(InvocationOnMock invocation) throws Throwable {
            return (data.realFilename + ".xls");
        }
    });
    resources = consumer.getResourcesFromRow(step, rmi, new String[] { "id", "name" });
    assertFalse(resources.isEmpty());
    assertEquals(1, resources.size());
    resources = consumer.getResourcesFromRow(step, rmi, new String[] { "id", "name" });
    assertFalse(resources.isEmpty());
    assertEquals(ExcelOutputMeta.class, consumer.getMetaClass());
}
Also used : IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) VariableSpace(org.pentaho.di.core.variables.VariableSpace) InvocationOnMock(org.mockito.invocation.InvocationOnMock) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Test(org.junit.Test)

Example 45 with IExternalResourceInfo

use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.

the class TextFileInputStepAnalyzerTest method testTextFileInputExternalResourceConsumer.

@Test
public void testTextFileInputExternalResourceConsumer() throws Exception {
    TextFileInputExternalResourceConsumer consumer = new TextFileInputExternalResourceConsumer();
    StepMeta spyMeta = spy(new StepMeta("test", meta));
    when(meta.getParentStepMeta()).thenReturn(spyMeta);
    when(spyMeta.getParentTransMeta()).thenReturn(transMeta);
    when(meta.getFileName()).thenReturn(null);
    when(meta.isAcceptingFilenames()).thenReturn(false);
    String[] filePaths = { "/path/to/file1", "/another/path/to/file2" };
    when(fileInputList.getFileStrings()).thenReturn(filePaths);
    when(meta.getFileInputList(Mockito.any(VariableSpace.class))).thenReturn(fileInputList);
    assertFalse(consumer.isDataDriven(meta));
    Collection<IExternalResourceInfo> resources = consumer.getResourcesFromMeta(meta);
    assertFalse(resources.isEmpty());
    assertEquals(2, resources.size());
    when(meta.isAcceptingFilenames()).thenReturn(true);
    assertTrue(consumer.isDataDriven(meta));
    assertTrue(consumer.getResourcesFromMeta(meta).isEmpty());
    when(mockRowMetaInterface.getString(Mockito.any(Object[].class), Mockito.anyString(), Mockito.anyString())).thenReturn("/path/to/row/file");
    when(mockTextFileInput.getStepMetaInterface()).thenReturn(meta);
    resources = consumer.getResourcesFromRow(mockTextFileInput, mockRowMetaInterface, new String[] { "id", "name" });
    assertFalse(resources.isEmpty());
    assertEquals(1, resources.size());
    when(mockRowMetaInterface.getString(Mockito.any(Object[].class), Mockito.anyString(), Mockito.anyString())).thenThrow(KettleException.class);
    resources = consumer.getResourcesFromRow(mockTextFileInput, mockRowMetaInterface, new String[] { "id", "name" });
    assertTrue(resources.isEmpty());
    assertEquals(TextFileInputMeta.class, consumer.getMetaClass());
}
Also used : IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) VariableSpace(org.pentaho.di.core.variables.VariableSpace) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Test(org.junit.Test)

Aggregations

IExternalResourceInfo (org.pentaho.metaverse.api.model.IExternalResourceInfo)64 Test (org.junit.Test)38 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)16 StepMeta (org.pentaho.di.trans.step.StepMeta)16 LinkedList (java.util.LinkedList)12 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)12 HashSet (java.util.HashSet)10 KettleException (org.pentaho.di.core.exception.KettleException)10 ArrayList (java.util.ArrayList)8 VariableSpace (org.pentaho.di.core.variables.VariableSpace)8 FileObject (org.apache.commons.vfs2.FileObject)7 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)5 IExecutionProfile (org.pentaho.metaverse.api.model.IExecutionProfile)5 List (java.util.List)4 IAnalysisContext (org.pentaho.metaverse.api.IAnalysisContext)4 IStepExternalResourceConsumer (org.pentaho.metaverse.api.analyzer.kettle.step.IStepExternalResourceConsumer)3 WebServiceResourceInfo (org.pentaho.metaverse.api.model.WebServiceResourceInfo)3 Before (org.junit.Before)2 Matchers.anyString (org.mockito.Matchers.anyString)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2