@Test public void testRetrieveFromJndi() throws Exception { MockInitialContextFactory.bind("java:comp/env/jdbc/JndiDB", dataSource); props.put(JdbcDataSource.JNDI_NAME, "java:comp/env/jdbc/JndiDB"); EasyMock.expect(dataSource.getConnection()).andReturn(connection); connection.setAutoCommit(false); // connection.setHoldability(1); mockControl.replay(); Connection conn = jdbcDataSource.createConnectionFactory(context, props).call(); mockControl.verify(); assertSame("connection", conn, connection); }
@Test public void testRetrieveFromDriverManager() throws Exception { DriverManager.registerDriver(driver); EasyMock.expect(driver.connect((String) EasyMock.notNull(), (Properties) EasyMock.notNull())) .andReturn(connection); connection.setAutoCommit(false); connection.setHoldability(1); props.put(JdbcDataSource.DRIVER, driver.getClass().getName()); props.put(JdbcDataSource.URL, "jdbc:fakedb"); props.put("holdability", "HOLD_CURSORS_OVER_COMMIT"); mockControl.replay(); Connection conn = jdbcDataSource.createConnectionFactory(context, props).call(); mockControl.verify(); assertSame("connection", conn, connection); }
@Test public void testRetrieveFromJndiWithCredentials() throws Exception { MockInitialContextFactory.bind("java:comp/env/jdbc/JndiDB", dataSource); props.put(JdbcDataSource.JNDI_NAME, "java:comp/env/jdbc/JndiDB"); props.put("user", "Fred"); props.put("password", "4r3d"); props.put("holdability", "HOLD_CURSORS_OVER_COMMIT"); EasyMock.expect(dataSource.getConnection("Fred", "4r3d")).andReturn(connection); connection.setAutoCommit(false); connection.setHoldability(1); mockControl.replay(); Connection conn = jdbcDataSource.createConnectionFactory(context, props).call(); mockControl.verify(); assertSame("connection", conn, connection); }