public class DefaultDbAdapterFactoryTest extends TestCase {
public void testCreatedAdapter_Auto() throws Exception {
final DbAdapter adapter = new MockDbAdapter() {
@Override
public String createTable(DbEntity ent) {
return "XXXXX";
}
};
List<DbAdapterDetector> detectors = new ArrayList<DbAdapterDetector>();
detectors.add(new DbAdapterDetector() {
public DbAdapter createAdapter(DatabaseMetaData md) throws SQLException {
return adapter;
}
});
MockConnection connection = new MockConnection();
MockDataSource dataSource = new MockDataSource();
dataSource.setupConnection(connection);
Module testModule = new Module() {
public void configure(Binder binder) {
binder.bind(JdbcEventLogger.class).to(CommonsJdbcEventLogger.class);
binder.bind(AdhocObjectFactory.class).to(DefaultAdhocObjectFactory.class);
}
};
Injector injector = DIBootstrap.createInjector(testModule);
DefaultDbAdapterFactory factory = new DefaultDbAdapterFactory(detectors);
injector.injectMembers(factory);
DbAdapter createdAdapter = factory.createAdapter(
new DataNodeDescriptor(),
dataSource);
assertTrue(createdAdapter instanceof AutoAdapter);
assertEquals("XXXXX", createdAdapter.createTable(new DbEntity("Test")));
}