assertTrue(ds.getPassword().equals(pwd)); assertTrue(ds.getUsername().equals(uname));
@Test public void testStandardUsage() throws Exception { final String jdbcUrl = "url"; final String uname = "uname"; final String pwd = "pwd"; class TestDriverManagerDataSource extends DriverManagerDataSource { @Override protected Connection getConnectionFromDriverManager(String url, Properties props) { assertEquals(jdbcUrl, url); assertEquals(uname, props.getProperty("user")); assertEquals(pwd, props.getProperty("password")); return connection; } } DriverManagerDataSource ds = new TestDriverManagerDataSource(); //ds.setDriverClassName("foobar"); ds.setUrl(jdbcUrl); ds.setUsername(uname); ds.setPassword(pwd); Connection actualCon = ds.getConnection(); assertTrue(actualCon == connection); assertTrue(ds.getUrl().equals(jdbcUrl)); assertTrue(ds.getPassword().equals(pwd)); assertTrue(ds.getUsername().equals(uname)); }
@Test public void testSuccessfulDriverInitInConvertGeneric() throws DBDatasourceServiceException { when( databaseType.getShortName() ).thenReturn( "GENERIC" ); when( connection.getAttributes() ).thenReturn( ImmutableMap.of( GenericDatabaseDialect.ATTRIBUTE_CUSTOM_DRIVER_CLASS, nativeDriverName ) ); when( connection.getUsername() ).thenReturn( "suzy" ); when( connection.getPassword() ).thenReturn( "password" ); when( ( (IDriverLocator) driverLocatorDialect ).initialize( nativeDriverName ) ).thenReturn( true ); DriverManagerDataSource dataSource = (DriverManagerDataSource) PooledDatasourceHelper.convert( connection, () -> dialectService ); verify( ( (IDriverLocator) driverLocatorDialect ), times( 1 ) ).initialize( nativeDriverName ); assertThat( dataSource.getUrl(), is( jdbcUrl ) ); assertThat( dataSource.getUsername(), is( "suzy" ) ); assertThat( dataSource.getPassword(), is( "password" ) ); }