use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.
the class RestClientExternalResourceConsumerTest method testGetResourcesFromRow_fieldsForMethodAndBody.
@Test
public void testGetResourcesFromRow_fieldsForMethodAndBody() throws Exception {
when(meta.isUrlInField()).thenReturn(true);
when(meta.getUrlField()).thenReturn("url");
when(meta.getHeaderField()).thenReturn(null);
when(meta.getParameterField()).thenReturn(null);
when(meta.isDynamicMethod()).thenReturn(true);
when(meta.getMethodFieldName()).thenReturn("method");
when(meta.getBodyField()).thenReturn("body");
when(rmi.getString(row, "method", null)).thenReturn(row[2].toString());
when(rmi.getString(row, "body", null)).thenReturn(row[2].toString());
Collection<IExternalResourceInfo> resourcesFromMeta = consumer.getResourcesFromRow(step, rmi, row);
assertEquals(1, resourcesFromMeta.size());
IExternalResourceInfo resourceInfo = resourcesFromMeta.toArray(new IExternalResourceInfo[1])[0];
assertEquals(row[0], resourceInfo.getName());
assertNotNull(resourceInfo.getAttributes());
}
use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.
the class TableOutputExternalResourceConsumerTest method testGetResourcesFromMeta_static.
@Test
public void testGetResourcesFromMeta_static() throws Exception {
TableOutputMeta meta = mock(TableOutputMeta.class);
DatabaseMeta dbMeta = mock(DatabaseMeta.class);
DatabaseInterface dbi = mock(DatabaseInterface.class);
when(meta.getDatabaseMeta()).thenReturn(dbMeta);
when(meta.getTableName()).thenReturn("tableName");
when(meta.getSchemaName()).thenReturn("schemaName");
when(meta.getParentStepMeta()).thenReturn(parentStepMeta);
when(parentStepMeta.getParentTransMeta()).thenReturn(parentTransMeta);
when(parentTransMeta.environmentSubstitute("tableName")).thenReturn("tableName");
when(parentTransMeta.environmentSubstitute("schemaName")).thenReturn("schemaName");
when(dbMeta.getAccessTypeDesc()).thenReturn("JNDI");
when(dbMeta.getName()).thenReturn("TestConnection");
when(dbMeta.getDescription()).thenReturn("my conn description");
when(dbMeta.getDatabaseInterface()).thenReturn(dbi);
when(dbi.getPluginId()).thenReturn("POSTGRESQL");
Collection<IExternalResourceInfo> resources = consumer.getResourcesFromMeta(meta, new AnalysisContext(DictionaryConst.CONTEXT_STATIC));
assertEquals(1, resources.size());
IExternalResourceInfo res = resources.iterator().next();
assertEquals("TestConnection", res.getName());
assertEquals("tableName", res.getAttributes().get(DictionaryConst.PROPERTY_TABLE));
assertEquals("schemaName", res.getAttributes().get(DictionaryConst.PROPERTY_SCHEMA));
}
use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.
the class ExecutionDataTest method testGetSetExternalResources.
@Test
public void testGetSetExternalResources() {
Map<String, List<IExternalResourceInfo>> resourceMap = new HashMap<String, List<IExternalResourceInfo>>();
List<IExternalResourceInfo> externalResources = new ArrayList<IExternalResourceInfo>();
externalResources.add(new BaseResourceInfo());
assertEquals(executionData.getExternalResources().size(), 0);
resourceMap.put("testStep", externalResources);
executionData.setExternalResources(resourceMap);
assertEquals(executionData.getExternalResources().get("testStep").size(), 1);
}
use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.
the class AbstractStepMetaJsonSerializerTest method testWriteExternalResources.
@Test
public void testWriteExternalResources() throws Exception {
StepExternalResourceConsumerProvider mockConsumerMap = mock(StepExternalResourceConsumerProvider.class);
List<IStepExternalResourceConsumer> consumers = new ArrayList<IStepExternalResourceConsumer>();
Set<IExternalResourceInfo> externalResources = new HashSet<IExternalResourceInfo>();
IExternalResourceInfo info = mock(IExternalResourceInfo.class);
externalResources.add(info);
IStepExternalResourceConsumer consumer = mock(IStepExternalResourceConsumer.class);
when(consumer.getResourcesFromMeta(anyObject())).thenReturn(externalResources);
consumers.add(consumer);
Class<? extends BaseStepMeta> stepMetaClass = BaseStepMeta.class;
when(mockConsumerMap.getExternalResourceConsumers(any(Collection.class))).thenReturn(consumers);
serializer.setStepExternalResourceConsumerProvider(mockConsumerMap);
serializer.writeExternalResources(spyMeta, json, provider);
verify(mockConsumerMap).getExternalResourceConsumers(any(Collection.class));
verify(json).writeArrayFieldStart(AbstractStepMetaJsonSerializer.JSON_PROPERTY_EXTERNAL_RESOURCES);
verify(consumer).getResourcesFromMeta(anyObject());
verify(json, times(externalResources.size())).writeObject(any(IExternalResourceInfo.class));
verify(json).writeEndArray();
}
use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.
the class ConnectionExternalResourceStepAnalyzerTest method setUp.
@Before
public void setUp() throws Exception {
analyzer = spy(new ConnectionExternalResourceStepAnalyzer<BaseStepMeta>() {
@Override
protected IMetaverseNode createTableNode(IExternalResourceInfo resource) throws MetaverseAnalyzerException {
return tableNode;
}
@Override
public String getResourceInputNodeType() {
return "INPUT_TYPE";
}
@Override
public String getResourceOutputNodeType() {
return "OUTPUT_TYPE";
}
@Override
public boolean isOutput() {
return false;
}
@Override
public boolean isInput() {
return true;
}
@Override
protected Set<StepField> getUsedFields(BaseStepMeta meta) {
Set<StepField> stepFields = new HashSet<>();
stepFields.add(new StepField("prevStep", "filename"));
return stepFields;
}
@Override
public Set<Class<? extends BaseStepMeta>> getSupportedSteps() {
return null;
}
});
when(analyzer.getMetaverseBuilder()).thenReturn(builder);
analyzer.descriptor = descriptor;
when(descriptor.getContext()).thenReturn(context);
analyzer.parentTransMeta = parentTransMeta;
analyzer.parentStepMeta = parentStepMeta;
analyzer.setMetaverseObjectFactory(new MetaverseObjectFactory());
}
Aggregations