@Test
public void testSwitchDataSource() throws SQLException, ClassNotFoundException {

	BoneCPDataSource mockDataSource = createNiceMock(BoneCPDataSource.class);
	DynamicDataSourceProxy ddsp = new DynamicDataSourceProxy();
	// Test #1: Check for correct instance.
	ddsp.setTargetDataSource(new DelegatingDataSource());
	try{
		ddsp.switchDataSource(null);
		fail("Should throw an exception");
	} catch(SQLException e){
		// do nothing
	}
	
	// Test #2: Given a good config, should initialize pool and switch datasource to it
	BoneCPConfig config = new BoneCPConfig();
	config.setJdbcUrl("jdbc:mock");
	config.setUsername("sa");
	config.setPassword("");
	config.setMinConnectionsPerPartition(2);
	config.setMaxConnectionsPerPartition(2);
	config.setPartitionCount(1);
	
	ddsp = new DynamicDataSourceProxy(mockDataSource);
	// Old datasource should be closed.
	mockDataSource.close();
	expectLastCall().once();
	replay(mockDataSource);
	ddsp.switchDataSource(config);
	// and a new datasource should be in place
	assertNotSame(mockDataSource, ddsp.getTargetDataSource());
	verify(mockDataSource);
}