use of org.pentaho.metaverse.api.model.JndiResourceInfo 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.metaverse.api.model.JndiResourceInfo in project pentaho-metaverse by pentaho.
the class TransMetaJsonDeserializer method deserializeConnections.
protected void deserializeConnections(TransMeta transMeta, JsonNode node, ObjectMapper mapper) {
ArrayNode connectionsArrayNode = (ArrayNode) node.get(TransMetaJsonSerializer.JSON_PROPERTY_CONNECTIONS);
IExternalResourceInfo conn = null;
for (int i = 0; i < connectionsArrayNode.size(); i++) {
JsonNode connNode = connectionsArrayNode.get(i);
String className = connNode.get(IInfo.JSON_PROPERTY_CLASS).asText();
try {
Class clazz = this.getClass().getClassLoader().loadClass(className);
conn = (IExternalResourceInfo) clazz.newInstance();
conn = mapper.readValue(connNode.toString(), conn.getClass());
DatabaseMeta dbMeta = null;
if (conn instanceof JdbcResourceInfo) {
JdbcResourceInfo db = (JdbcResourceInfo) conn;
dbMeta = new DatabaseMeta(db.getName(), db.getPluginId(), DatabaseMeta.getAccessTypeDesc(DatabaseMeta.TYPE_ACCESS_NATIVE), db.getServer(), db.getDatabaseName(), String.valueOf(db.getPort()), db.getUsername(), db.getPassword());
} else if (conn instanceof JndiResourceInfo) {
JndiResourceInfo db = (JndiResourceInfo) conn;
dbMeta = new DatabaseMeta(db.getName(), db.getPluginId(), DatabaseMeta.getAccessTypeDesc(DatabaseMeta.TYPE_ACCESS_JNDI), null, null, null, null, null);
}
transMeta.addDatabase(dbMeta);
} catch (Exception e) {
LOGGER.warn(Messages.getString("WARNING.Deserialization.Trans.Connections", conn.getName(), transMeta.getName()), e);
}
}
}
Aggregations