use of org.pentaho.di.core.database.DatabaseMeta 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.di.core.database.DatabaseMeta in project pentaho-metaverse by pentaho.
the class AbstractMetaJsonSerializer method serializeConnections.
protected void serializeConnections(T meta, JsonGenerator json) throws IOException {
// connections
json.writeArrayFieldStart(JSON_PROPERTY_CONNECTIONS);
for (DatabaseMeta dbmeta : meta.getDatabases()) {
BaseResourceInfo resourceInfo = (BaseResourceInfo) ExternalResourceInfoFactory.createDatabaseResource(dbmeta);
resourceInfo.setInput(true);
json.writeObject(resourceInfo);
}
json.writeEndArray();
}
use of org.pentaho.di.core.database.DatabaseMeta in project pentaho-metaverse by pentaho.
the class TransMetaJsonDeserializerTest method testDeserializeConnections.
@Test
public void testDeserializeConnections() throws Exception {
JndiResourceInfo jndi = new JndiResourceInfo("jndi");
jndi.setPluginId("ORACLE");
JdbcResourceInfo jdbc = new JdbcResourceInfo("localhost", "test", 5432, "sa", "password");
jdbc.setPluginId("POSTGRESQL");
transMeta = spy(new TransMeta());
root_connectionsArray.add(root_connectionsArray_Node0);
root_connectionsArray.add(root_connectionsArray_Node1);
when(root_connectionsArray_Node0.toString()).thenReturn("mocked jdbc");
when(root_connectionsArray_Node0.get(IInfo.JSON_PROPERTY_CLASS)).thenReturn(root_connectionsArray_Node0_classNode);
when(root_connectionsArray_Node0_classNode.asText()).thenReturn(JdbcResourceInfo.class.getName());
when(root_connectionsArray_Node1.toString()).thenReturn("mocked jndi");
when(root_connectionsArray_Node1.get(IInfo.JSON_PROPERTY_CLASS)).thenReturn(root_connectionsArray_Node1_classNode);
when(root_connectionsArray_Node1_classNode.asText()).thenReturn(JndiResourceInfo.class.getName());
when(mapper.readValue("mocked jdbc", JdbcResourceInfo.class)).thenReturn(jdbc);
when(mapper.readValue("mocked jndi", JndiResourceInfo.class)).thenReturn(jndi);
deserializer.deserializeConnections(transMeta, root, mapper);
assertEquals(root_connectionsArray.size(), transMeta.getDatabases().size());
for (DatabaseMeta databaseMeta : transMeta.getDatabases()) {
assertNotNull(databaseMeta.getDatabaseInterface());
}
}
use of org.pentaho.di.core.database.DatabaseMeta in project pentaho-kettle by pentaho.
the class AbstractMeta method loadSharedObject.
protected boolean loadSharedObject(SharedObjectInterface object) {
if (object instanceof DatabaseMeta) {
DatabaseMeta databaseMeta = (DatabaseMeta) object;
databaseMeta.shareVariablesWith(this);
addOrReplaceDatabase(databaseMeta);
} else if (object instanceof SlaveServer) {
SlaveServer slaveServer = (SlaveServer) object;
slaveServer.shareVariablesWith(this);
addOrReplaceSlaveServer(slaveServer);
} else {
return false;
}
return true;
}
use of org.pentaho.di.core.database.DatabaseMeta in project pentaho-kettle by pentaho.
the class AbstractMeta method addDatabase.
protected void addDatabase(DatabaseMeta databaseMeta, boolean replace) {
int index = databases.indexOf(databaseMeta);
if (index < 0) {
addDatabase(databaseMeta);
} else if (replace) {
DatabaseMeta previous = getDatabase(index);
previous.replaceMeta(databaseMeta);
previous.setShared(databaseMeta.isShared());
}
changedDatabases = true;
}
Aggregations