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;
}
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);
}
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());
}
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());
}
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());
}
Aggregations