use of org.apache.cayenne.dba.AutoAdapter in project cayenne by apache.
the class DefaultDbAdapterFactoryTest method testCreatedAdapter_Auto.
@Test
public void testCreatedAdapter_Auto() throws Exception {
final DbAdapter adapter = mock(JdbcAdapter.class);
when(adapter.createTable(any(DbEntity.class))).thenReturn("XXXXX");
when(adapter.unwrap()).thenReturn(adapter);
List<DbAdapterDetector> detectors = new ArrayList<>();
detectors.add(md -> adapter);
MockConnection connection = new MockConnection();
MockDataSource dataSource = new MockDataSource();
dataSource.setupConnection(connection);
Module testModule = binder -> {
ServerModule.contributeProperties(binder);
ServerModule.contributePkGenerators(binder);
binder.bind(PkGenerator.class).to(JdbcPkGenerator.class);
binder.bind(PkGeneratorFactoryProvider.class).to(PkGeneratorFactoryProvider.class);
binder.bind(JdbcEventLogger.class).to(Slf4jJdbcEventLogger.class);
binder.bind(ClassLoaderManager.class).to(DefaultClassLoaderManager.class);
binder.bind(AdhocObjectFactory.class).to(DefaultAdhocObjectFactory.class);
binder.bind(RuntimeProperties.class).to(DefaultRuntimeProperties.class);
binder.bind(BatchTranslatorFactory.class).toInstance(mock(BatchTranslatorFactory.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")));
}
use of org.apache.cayenne.dba.AutoAdapter in project cayenne by apache.
the class DbGeneratorTaskTest method testSetAdapter.
@Test
public void testSetAdapter() throws Exception {
DataSource ds = mock(DataSource.class);
Injector injector = DIBootstrap.createInjector(new ToolsModule(mock(Logger.class)));
DbGeneratorTask task = new DbGeneratorTask();
DbAdapter autoAdapter = task.getAdapter(injector, ds);
assertTrue(autoAdapter instanceof AutoAdapter);
task.setAdapter(SQLServerAdapter.class.getName());
DbAdapter sqlServerAdapter = task.getAdapter(injector, ds);
assertTrue(sqlServerAdapter instanceof SQLServerAdapter);
}
use of org.apache.cayenne.dba.AutoAdapter in project cayenne by apache.
the class DefaultDbAdapterFactoryTest method testCreatedAdapter_Generic.
@Test
public void testCreatedAdapter_Generic() throws Exception {
List<DbAdapterDetector> detectors = new ArrayList<DbAdapterDetector>();
Module testModule = binder -> {
ServerModule.contributeProperties(binder);
ServerModule.contributeDefaultTypes(binder);
ServerModule.contributeUserTypes(binder);
ServerModule.contributeTypeFactories(binder);
ServerModule.contributePkGenerators(binder);
binder.bind(PkGenerator.class).to(JdbcPkGenerator.class);
binder.bind(PkGeneratorFactoryProvider.class).to(PkGeneratorFactoryProvider.class);
binder.bind(JdbcEventLogger.class).to(Slf4jJdbcEventLogger.class);
binder.bind(ClassLoaderManager.class).to(DefaultClassLoaderManager.class);
binder.bind(AdhocObjectFactory.class).to(DefaultAdhocObjectFactory.class);
binder.bind(ResourceLocator.class).to(ClassLoaderResourceLocator.class);
binder.bind(Key.get(ResourceLocator.class, Constants.SERVER_RESOURCE_LOCATOR)).to(ClassLoaderResourceLocator.class);
binder.bind(RuntimeProperties.class).to(DefaultRuntimeProperties.class);
binder.bind(BatchTranslatorFactory.class).toInstance(mock(BatchTranslatorFactory.class));
ServerModule.contributeValueObjectTypes(binder);
binder.bind(ValueObjectTypeRegistry.class).to(DefaultValueObjectTypeRegistry.class);
};
Injector injector = DIBootstrap.createInjector(testModule);
DefaultDbAdapterFactory factory = new DefaultDbAdapterFactory(detectors);
injector.injectMembers(factory);
DbAdapter createdAdapter = factory.createAdapter(new DataNodeDescriptor(), new MockDataSource());
assertNotNull(createdAdapter);
assertTrue("Unexpected class: " + createdAdapter.getClass().getName(), createdAdapter instanceof AutoAdapter);
assertEquals("CREATE TABLE Test ()", createdAdapter.createTable(new DbEntity("Test")));
}
use of org.apache.cayenne.dba.AutoAdapter in project cayenne by apache.
the class DefaultDbAdapterFactoryTest method testCreatedAdapter_AutoExplicit.
@Test
public void testCreatedAdapter_AutoExplicit() throws Exception {
final DbAdapter adapter = mock(JdbcAdapter.class);
when(adapter.createTable(any(DbEntity.class))).thenReturn("XXXXX");
when(adapter.unwrap()).thenReturn(adapter);
List<DbAdapterDetector> detectors = new ArrayList<>();
detectors.add(md -> adapter);
MockConnection connection = new MockConnection();
MockDataSource dataSource = new MockDataSource();
dataSource.setupConnection(connection);
Module testModule = binder -> {
ServerModule.contributeProperties(binder);
ServerModule.contributePkGenerators(binder);
binder.bind(PkGenerator.class).to(JdbcPkGenerator.class);
binder.bind(PkGeneratorFactoryProvider.class).to(PkGeneratorFactoryProvider.class);
binder.bind(ClassLoaderManager.class).to(DefaultClassLoaderManager.class);
binder.bind(JdbcEventLogger.class).to(Slf4jJdbcEventLogger.class);
binder.bind(AdhocObjectFactory.class).to(DefaultAdhocObjectFactory.class);
binder.bind(RuntimeProperties.class).to(DefaultRuntimeProperties.class);
binder.bind(BatchTranslatorFactory.class).toInstance(mock(BatchTranslatorFactory.class));
};
Injector injector = DIBootstrap.createInjector(testModule);
DefaultDbAdapterFactory factory = new DefaultDbAdapterFactory(detectors);
injector.injectMembers(factory);
DataNodeDescriptor nodeDescriptor = new DataNodeDescriptor();
nodeDescriptor.setAdapterType(AutoAdapter.class.getName());
DbAdapter createdAdapter = factory.createAdapter(nodeDescriptor, dataSource);
assertTrue(createdAdapter instanceof AutoAdapter);
assertEquals("XXXXX", createdAdapter.createTable(new DbEntity("Test")));
}
use of org.apache.cayenne.dba.AutoAdapter in project cayenne by apache.
the class ToolsModuleTest method testDbApdater.
@Test
public void testDbApdater() throws Exception {
Logger log = mock(Logger.class);
Injector i = DIBootstrap.createInjector(new ToolsModule(log));
DbAdapterFactory factory = i.getInstance(DbAdapterFactory.class);
DataNodeDescriptor nodeDescriptor = mock(DataNodeDescriptor.class);
DataSource dataSource = mock(DataSource.class);
assertTrue(factory.createAdapter(nodeDescriptor, dataSource) instanceof AutoAdapter);
}
Aggregations