@Test public void testUpdateConnection() { try { InMemoryConnectionServiceImpl serv = new InMemoryConnectionServiceImpl(); List<IDatabaseConnection> conns = serv.getConnections(); assertTrue(conns != null && conns.size() == 0); IDatabaseConnection connection = new DatabaseConnection(); connection.setName("Connection 1"); connection.setUsername("admin"); connection.setPassword("password"); serv.addConnection(connection); conns = serv.getConnections(); assertTrue(conns.get(0).getUsername().equals("admin")); assertTrue(conns.get(0).getPassword().equals("password")); connection = new DatabaseConnection(); connection.setName("Connection 1"); connection.setUsername("root"); connection.setPassword("pass"); serv.updateConnection(connection); List<IDatabaseConnection> conns1 = serv.getConnections(); assertTrue(conns1 != null && conns1.size() > 0); assertTrue(conns1.size() == conns.size()); assertTrue(conns1.get(0).getUsername().equals("root")); assertTrue(conns1.get(0).getPassword().equals("pass")); } catch (Exception ex) { fail(); } }
@Test public void testDeleteConnections() { try { InMemoryConnectionServiceImpl serv = new InMemoryConnectionServiceImpl(); List<IDatabaseConnection> conns = serv.getConnections(); assertTrue(conns != null && conns.size() == 0); IDatabaseConnection connection = new DatabaseConnection(); connection.setName("Connection 1"); serv.addConnection(connection); connection = new DatabaseConnection(); connection.setName("Connection 2"); serv.addConnection(connection); conns = serv.getConnections(); assertTrue(conns != null && conns.size() == 2); try { serv.deleteConnection(connection); connection = serv.getConnectionByName("Connection 2"); fail(); } catch (Exception ex) { } try { serv.deleteConnection("Connection 1"); connection = serv.getConnectionByName("Connection 1"); fail(); } catch (Exception ex) { } } catch (Exception ex) { fail(); } }
@Test public void testAddConnections() { try { InMemoryConnectionServiceImpl serv = new InMemoryConnectionServiceImpl(); List<IDatabaseConnection> conns = serv.getConnections(); assertTrue(conns != null && conns.size() == 0); IDatabaseConnection connection = new DatabaseConnection(); connection.setName("Connection 1"); serv.addConnection(connection); connection = new DatabaseConnection(); connection.setName("Connection 1"); try { // validate adding connection with existing name serv.addConnection(connection); fail(); } catch (ConnectionServiceException e) { } connection = new DatabaseConnection(); connection.setName("Connection 2"); serv.addConnection(connection); conns = serv.getConnections(); assertTrue(conns != null && conns.size() > 0); } catch (Exception ex) { fail(); } }
private static IDatabaseConnection createConnectionObject() { IDatabaseConnection connection = new DatabaseConnection(); connection.setAccessType(DatabaseAccessType.NATIVE); // connection.setDriverClass("org.hsqldb.jdbcDriver"); // connection.setUrl("jdbc:hsqldb:hsql://localhost:9001/sampledata"); connection.setUsername("pentaho_user"); connection.setPassword("password"); connection.setName(CONNECTION_NAME); return connection; }