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(meta.getFilePaths(Mockito.any(VariableSpace.class))).thenReturn(filePaths);
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());
}
use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.
the class TextFileOutputExternalResourceConsumerTest method testTextFileOutputExternalResourceConsumer.
@Test
public void testTextFileOutputExternalResourceConsumer() throws Exception {
StepMeta stepMeta = new StepMeta("test", meta);
StepMeta spyMeta = spy(stepMeta);
when(tfo.getStepMeta()).thenReturn(spyMeta);
when(tfo.getStepDataInterface()).thenReturn(data);
when(meta.getParentStepMeta()).thenReturn(spyMeta);
when(spyMeta.getParentTransMeta()).thenReturn(transMeta);
when(meta.getFileName()).thenReturn(null);
when(meta.isFileNameInField()).thenReturn(false);
String[] filePaths = { "/path/to/file1", "/another/path/to/file2" };
when(meta.getFiles(Mockito.any(VariableSpace.class))).thenReturn(filePaths);
assertFalse(consumer.isDataDriven(meta));
Collection<IExternalResourceInfo> resources = consumer.getResourcesFromMeta(meta);
assertFalse(resources.isEmpty());
assertEquals(2, resources.size());
when(meta.isFileNameInField()).thenReturn(true);
when(meta.getExtension()).thenReturn("txt");
assertTrue(consumer.isDataDriven(meta));
assertTrue(consumer.getResourcesFromMeta(meta).isEmpty());
data.fileName = "/path/to/row/file";
when(tfo.buildFilename(Mockito.anyString(), Mockito.anyBoolean())).thenAnswer(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
return (args[0].toString() + ".txt");
}
});
resources = consumer.getResourcesFromRow(tfo, rmi, new String[] { "id", "name" });
assertFalse(resources.isEmpty());
assertEquals(1, resources.size());
when(data.fileName).thenThrow(KettleException.class);
resources = consumer.getResourcesFromRow(tfo, rmi, new String[] { "id", "name" });
assertTrue(resources.isEmpty());
assertEquals(TextFileOutputMeta.class, consumer.getMetaClass());
}
use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.
the class TextFileOutputStepAnalyzerTest method testCreateResourceNode.
@Test
public void testCreateResourceNode() throws Exception {
IExternalResourceInfo res = mock(IExternalResourceInfo.class);
when(res.getName()).thenReturn("file:///Users/home/tmp/xyz.ktr");
IMetaverseNode resourceNode = analyzer.createResourceNode(res);
assertNotNull(resourceNode);
assertEquals(DictionaryConst.NODE_TYPE_FILE, resourceNode.getType());
}
use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.
the class ExecutionDataTest method testAddExternalResource.
@Test
public void testAddExternalResource() {
IExternalResourceInfo externalResource = new BaseResourceInfo();
assertEquals(executionData.getExternalResources().size(), 0);
executionData.addExternalResource("testStep", externalResource);
assertEquals(executionData.getExternalResources().get("testStep").get(0), externalResource);
}
use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.
the class KettleAnalyzerUtil method getResourcesFromRow.
public static Collection<IExternalResourceInfo> getResourcesFromRow(BaseFileInputStep step, RowMetaInterface rowMeta, Object[] row) {
Collection<IExternalResourceInfo> resources = new LinkedList<>();
// For some reason the step doesn't return the StepMetaInterface directly, so go around it
BaseFileInputMeta meta = (BaseFileInputMeta) step.getStepMetaInterface();
if (meta == null) {
meta = (BaseFileInputMeta) step.getStepMeta().getStepMetaInterface();
}
try {
String filename = meta == null ? null : step.environmentSubstitute(rowMeta.getString(row, meta.getAcceptingField(), null));
if (!Const.isEmpty(filename)) {
FileObject fileObject = KettleVFS.getFileObject(filename, step);
resources.add(ExternalResourceInfoFactory.createFileResource(fileObject, true));
}
} catch (KettleException kve) {
// TODO throw exception or ignore?
}
return resources;
}
Aggregations