Search in sources :

Example 1 with MockDataSource

use of com.mockrunner.mock.jdbc.MockDataSource 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")));
}
Also used : RuntimeProperties(org.apache.cayenne.configuration.RuntimeProperties) Injector(org.apache.cayenne.di.Injector) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) PkGenerator(org.apache.cayenne.dba.PkGenerator) DefaultClassLoaderManager(org.apache.cayenne.di.spi.DefaultClassLoaderManager) DefaultValueObjectTypeRegistry(org.apache.cayenne.access.types.DefaultValueObjectTypeRegistry) JdbcAdapter(org.apache.cayenne.dba.JdbcAdapter) Module(org.apache.cayenne.di.Module) AdhocObjectFactory(org.apache.cayenne.di.AdhocObjectFactory) ArrayList(java.util.ArrayList) DefaultRuntimeProperties(org.apache.cayenne.configuration.DefaultRuntimeProperties) Slf4jJdbcEventLogger(org.apache.cayenne.log.Slf4jJdbcEventLogger) ValueObjectTypeRegistry(org.apache.cayenne.access.types.ValueObjectTypeRegistry) JdbcEventLogger(org.apache.cayenne.log.JdbcEventLogger) MockConnection(com.mockrunner.mock.jdbc.MockConnection) DIBootstrap(org.apache.cayenne.di.DIBootstrap) Key(org.apache.cayenne.di.Key) BatchTranslatorFactory(org.apache.cayenne.access.translator.batch.BatchTranslatorFactory) ValueComparisonStrategyFactory(org.apache.cayenne.reflect.generic.ValueComparisonStrategyFactory) ResourceLocator(org.apache.cayenne.resource.ResourceLocator) ClassLoaderResourceLocator(org.apache.cayenne.resource.ClassLoaderResourceLocator) Constants(org.apache.cayenne.configuration.Constants) DefaultAdhocObjectFactory(org.apache.cayenne.di.spi.DefaultAdhocObjectFactory) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ClassLoaderManager(org.apache.cayenne.di.ClassLoaderManager) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) AutoAdapter(org.apache.cayenne.dba.AutoAdapter) List(java.util.List) DbAdapter(org.apache.cayenne.dba.DbAdapter) DbEntity(org.apache.cayenne.map.DbEntity) SybaseAdapter(org.apache.cayenne.dba.sybase.SybaseAdapter) Assert(org.junit.Assert) MockDataSource(com.mockrunner.mock.jdbc.MockDataSource) DefaultValueComparisonStrategyFactory(org.apache.cayenne.reflect.generic.DefaultValueComparisonStrategyFactory) JdbcPkGenerator(org.apache.cayenne.dba.JdbcPkGenerator) Mockito.mock(org.mockito.Mockito.mock) DefaultAdhocObjectFactory(org.apache.cayenne.di.spi.DefaultAdhocObjectFactory) ArrayList(java.util.ArrayList) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) DefaultRuntimeProperties(org.apache.cayenne.configuration.DefaultRuntimeProperties) AutoAdapter(org.apache.cayenne.dba.AutoAdapter) MockConnection(com.mockrunner.mock.jdbc.MockConnection) DbAdapter(org.apache.cayenne.dba.DbAdapter) DbEntity(org.apache.cayenne.map.DbEntity) MockDataSource(com.mockrunner.mock.jdbc.MockDataSource) Slf4jJdbcEventLogger(org.apache.cayenne.log.Slf4jJdbcEventLogger) Injector(org.apache.cayenne.di.Injector) Module(org.apache.cayenne.di.Module) JdbcPkGenerator(org.apache.cayenne.dba.JdbcPkGenerator) DefaultClassLoaderManager(org.apache.cayenne.di.spi.DefaultClassLoaderManager) Test(org.junit.Test)

Example 2 with MockDataSource

use of com.mockrunner.mock.jdbc.MockDataSource 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")));
}
Also used : RuntimeProperties(org.apache.cayenne.configuration.RuntimeProperties) Injector(org.apache.cayenne.di.Injector) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) PkGenerator(org.apache.cayenne.dba.PkGenerator) DefaultClassLoaderManager(org.apache.cayenne.di.spi.DefaultClassLoaderManager) DefaultValueObjectTypeRegistry(org.apache.cayenne.access.types.DefaultValueObjectTypeRegistry) JdbcAdapter(org.apache.cayenne.dba.JdbcAdapter) Module(org.apache.cayenne.di.Module) AdhocObjectFactory(org.apache.cayenne.di.AdhocObjectFactory) ArrayList(java.util.ArrayList) DefaultRuntimeProperties(org.apache.cayenne.configuration.DefaultRuntimeProperties) Slf4jJdbcEventLogger(org.apache.cayenne.log.Slf4jJdbcEventLogger) ValueObjectTypeRegistry(org.apache.cayenne.access.types.ValueObjectTypeRegistry) JdbcEventLogger(org.apache.cayenne.log.JdbcEventLogger) MockConnection(com.mockrunner.mock.jdbc.MockConnection) DIBootstrap(org.apache.cayenne.di.DIBootstrap) Key(org.apache.cayenne.di.Key) BatchTranslatorFactory(org.apache.cayenne.access.translator.batch.BatchTranslatorFactory) ValueComparisonStrategyFactory(org.apache.cayenne.reflect.generic.ValueComparisonStrategyFactory) ResourceLocator(org.apache.cayenne.resource.ResourceLocator) ClassLoaderResourceLocator(org.apache.cayenne.resource.ClassLoaderResourceLocator) Constants(org.apache.cayenne.configuration.Constants) DefaultAdhocObjectFactory(org.apache.cayenne.di.spi.DefaultAdhocObjectFactory) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ClassLoaderManager(org.apache.cayenne.di.ClassLoaderManager) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) AutoAdapter(org.apache.cayenne.dba.AutoAdapter) List(java.util.List) DbAdapter(org.apache.cayenne.dba.DbAdapter) DbEntity(org.apache.cayenne.map.DbEntity) SybaseAdapter(org.apache.cayenne.dba.sybase.SybaseAdapter) Assert(org.junit.Assert) MockDataSource(com.mockrunner.mock.jdbc.MockDataSource) DefaultValueComparisonStrategyFactory(org.apache.cayenne.reflect.generic.DefaultValueComparisonStrategyFactory) JdbcPkGenerator(org.apache.cayenne.dba.JdbcPkGenerator) Mockito.mock(org.mockito.Mockito.mock) DefaultAdhocObjectFactory(org.apache.cayenne.di.spi.DefaultAdhocObjectFactory) ArrayList(java.util.ArrayList) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) DefaultRuntimeProperties(org.apache.cayenne.configuration.DefaultRuntimeProperties) AutoAdapter(org.apache.cayenne.dba.AutoAdapter) DbAdapter(org.apache.cayenne.dba.DbAdapter) DbEntity(org.apache.cayenne.map.DbEntity) Slf4jJdbcEventLogger(org.apache.cayenne.log.Slf4jJdbcEventLogger) Injector(org.apache.cayenne.di.Injector) MockDataSource(com.mockrunner.mock.jdbc.MockDataSource) ClassLoaderResourceLocator(org.apache.cayenne.resource.ClassLoaderResourceLocator) Module(org.apache.cayenne.di.Module) JdbcPkGenerator(org.apache.cayenne.dba.JdbcPkGenerator) DefaultClassLoaderManager(org.apache.cayenne.di.spi.DefaultClassLoaderManager) DefaultValueObjectTypeRegistry(org.apache.cayenne.access.types.DefaultValueObjectTypeRegistry) ResourceLocator(org.apache.cayenne.resource.ResourceLocator) ClassLoaderResourceLocator(org.apache.cayenne.resource.ClassLoaderResourceLocator) Test(org.junit.Test)

Example 3 with MockDataSource

use of com.mockrunner.mock.jdbc.MockDataSource 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")));
}
Also used : RuntimeProperties(org.apache.cayenne.configuration.RuntimeProperties) Injector(org.apache.cayenne.di.Injector) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) PkGenerator(org.apache.cayenne.dba.PkGenerator) DefaultClassLoaderManager(org.apache.cayenne.di.spi.DefaultClassLoaderManager) DefaultValueObjectTypeRegistry(org.apache.cayenne.access.types.DefaultValueObjectTypeRegistry) JdbcAdapter(org.apache.cayenne.dba.JdbcAdapter) Module(org.apache.cayenne.di.Module) AdhocObjectFactory(org.apache.cayenne.di.AdhocObjectFactory) ArrayList(java.util.ArrayList) DefaultRuntimeProperties(org.apache.cayenne.configuration.DefaultRuntimeProperties) Slf4jJdbcEventLogger(org.apache.cayenne.log.Slf4jJdbcEventLogger) ValueObjectTypeRegistry(org.apache.cayenne.access.types.ValueObjectTypeRegistry) JdbcEventLogger(org.apache.cayenne.log.JdbcEventLogger) MockConnection(com.mockrunner.mock.jdbc.MockConnection) DIBootstrap(org.apache.cayenne.di.DIBootstrap) Key(org.apache.cayenne.di.Key) BatchTranslatorFactory(org.apache.cayenne.access.translator.batch.BatchTranslatorFactory) ValueComparisonStrategyFactory(org.apache.cayenne.reflect.generic.ValueComparisonStrategyFactory) ResourceLocator(org.apache.cayenne.resource.ResourceLocator) ClassLoaderResourceLocator(org.apache.cayenne.resource.ClassLoaderResourceLocator) Constants(org.apache.cayenne.configuration.Constants) DefaultAdhocObjectFactory(org.apache.cayenne.di.spi.DefaultAdhocObjectFactory) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ClassLoaderManager(org.apache.cayenne.di.ClassLoaderManager) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) AutoAdapter(org.apache.cayenne.dba.AutoAdapter) List(java.util.List) DbAdapter(org.apache.cayenne.dba.DbAdapter) DbEntity(org.apache.cayenne.map.DbEntity) SybaseAdapter(org.apache.cayenne.dba.sybase.SybaseAdapter) Assert(org.junit.Assert) MockDataSource(com.mockrunner.mock.jdbc.MockDataSource) DefaultValueComparisonStrategyFactory(org.apache.cayenne.reflect.generic.DefaultValueComparisonStrategyFactory) JdbcPkGenerator(org.apache.cayenne.dba.JdbcPkGenerator) Mockito.mock(org.mockito.Mockito.mock) DefaultAdhocObjectFactory(org.apache.cayenne.di.spi.DefaultAdhocObjectFactory) ArrayList(java.util.ArrayList) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) DefaultRuntimeProperties(org.apache.cayenne.configuration.DefaultRuntimeProperties) AutoAdapter(org.apache.cayenne.dba.AutoAdapter) MockConnection(com.mockrunner.mock.jdbc.MockConnection) DbAdapter(org.apache.cayenne.dba.DbAdapter) DbEntity(org.apache.cayenne.map.DbEntity) MockDataSource(com.mockrunner.mock.jdbc.MockDataSource) Slf4jJdbcEventLogger(org.apache.cayenne.log.Slf4jJdbcEventLogger) Injector(org.apache.cayenne.di.Injector) Module(org.apache.cayenne.di.Module) JdbcPkGenerator(org.apache.cayenne.dba.JdbcPkGenerator) DefaultClassLoaderManager(org.apache.cayenne.di.spi.DefaultClassLoaderManager) Test(org.junit.Test)

Example 4 with MockDataSource

use of com.mockrunner.mock.jdbc.MockDataSource in project cayenne by apache.

the class DefaultDbAdapterFactoryTest method testCreatedAdapter_Custom.

@Test
public void testCreatedAdapter_Custom() throws Exception {
    DataNodeDescriptor nodeDescriptor = new DataNodeDescriptor();
    nodeDescriptor.setAdapterType(SybaseAdapter.class.getName());
    List<DbAdapterDetector> detectors = new ArrayList<>();
    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);
        binder.bind(ValueComparisonStrategyFactory.class).to(DefaultValueComparisonStrategyFactory.class);
    };
    Injector injector = DIBootstrap.createInjector(testModule);
    DefaultDbAdapterFactory factory = new DefaultDbAdapterFactory(detectors);
    injector.injectMembers(factory);
    DbAdapter createdAdapter = factory.createAdapter(nodeDescriptor, new MockDataSource());
    assertNotNull(createdAdapter);
    assertTrue("Unexpected class: " + createdAdapter.getClass().getName(), createdAdapter instanceof SybaseAdapter);
}
Also used : RuntimeProperties(org.apache.cayenne.configuration.RuntimeProperties) Injector(org.apache.cayenne.di.Injector) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) PkGenerator(org.apache.cayenne.dba.PkGenerator) DefaultClassLoaderManager(org.apache.cayenne.di.spi.DefaultClassLoaderManager) DefaultValueObjectTypeRegistry(org.apache.cayenne.access.types.DefaultValueObjectTypeRegistry) JdbcAdapter(org.apache.cayenne.dba.JdbcAdapter) Module(org.apache.cayenne.di.Module) AdhocObjectFactory(org.apache.cayenne.di.AdhocObjectFactory) ArrayList(java.util.ArrayList) DefaultRuntimeProperties(org.apache.cayenne.configuration.DefaultRuntimeProperties) Slf4jJdbcEventLogger(org.apache.cayenne.log.Slf4jJdbcEventLogger) ValueObjectTypeRegistry(org.apache.cayenne.access.types.ValueObjectTypeRegistry) JdbcEventLogger(org.apache.cayenne.log.JdbcEventLogger) MockConnection(com.mockrunner.mock.jdbc.MockConnection) DIBootstrap(org.apache.cayenne.di.DIBootstrap) Key(org.apache.cayenne.di.Key) BatchTranslatorFactory(org.apache.cayenne.access.translator.batch.BatchTranslatorFactory) ValueComparisonStrategyFactory(org.apache.cayenne.reflect.generic.ValueComparisonStrategyFactory) ResourceLocator(org.apache.cayenne.resource.ResourceLocator) ClassLoaderResourceLocator(org.apache.cayenne.resource.ClassLoaderResourceLocator) Constants(org.apache.cayenne.configuration.Constants) DefaultAdhocObjectFactory(org.apache.cayenne.di.spi.DefaultAdhocObjectFactory) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ClassLoaderManager(org.apache.cayenne.di.ClassLoaderManager) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) AutoAdapter(org.apache.cayenne.dba.AutoAdapter) List(java.util.List) DbAdapter(org.apache.cayenne.dba.DbAdapter) DbEntity(org.apache.cayenne.map.DbEntity) SybaseAdapter(org.apache.cayenne.dba.sybase.SybaseAdapter) Assert(org.junit.Assert) MockDataSource(com.mockrunner.mock.jdbc.MockDataSource) DefaultValueComparisonStrategyFactory(org.apache.cayenne.reflect.generic.DefaultValueComparisonStrategyFactory) JdbcPkGenerator(org.apache.cayenne.dba.JdbcPkGenerator) Mockito.mock(org.mockito.Mockito.mock) DefaultAdhocObjectFactory(org.apache.cayenne.di.spi.DefaultAdhocObjectFactory) ArrayList(java.util.ArrayList) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) DefaultRuntimeProperties(org.apache.cayenne.configuration.DefaultRuntimeProperties) DefaultValueComparisonStrategyFactory(org.apache.cayenne.reflect.generic.DefaultValueComparisonStrategyFactory) SybaseAdapter(org.apache.cayenne.dba.sybase.SybaseAdapter) DbAdapter(org.apache.cayenne.dba.DbAdapter) Slf4jJdbcEventLogger(org.apache.cayenne.log.Slf4jJdbcEventLogger) Injector(org.apache.cayenne.di.Injector) MockDataSource(com.mockrunner.mock.jdbc.MockDataSource) ClassLoaderResourceLocator(org.apache.cayenne.resource.ClassLoaderResourceLocator) Module(org.apache.cayenne.di.Module) JdbcPkGenerator(org.apache.cayenne.dba.JdbcPkGenerator) DefaultClassLoaderManager(org.apache.cayenne.di.spi.DefaultClassLoaderManager) DefaultValueObjectTypeRegistry(org.apache.cayenne.access.types.DefaultValueObjectTypeRegistry) ResourceLocator(org.apache.cayenne.resource.ResourceLocator) ClassLoaderResourceLocator(org.apache.cayenne.resource.ClassLoaderResourceLocator) Test(org.junit.Test)

Example 5 with MockDataSource

use of com.mockrunner.mock.jdbc.MockDataSource in project cayenne by apache.

the class JNDIDataSourceFactoryIT method testGetDataSource_NameBound.

@Test
public void testGetDataSource_NameBound() throws Exception {
    DataNodeDescriptor descriptor = new DataNodeDescriptor();
    descriptor.setParameters("jdbc/TestDS");
    JNDISetup.doSetup();
    MockDataSource dataSource = new MockDataSource();
    InitialContext context = new InitialContext();
    context.bind(descriptor.getParameters(), dataSource);
    try {
        JNDIDataSourceFactory factory = new JNDIDataSourceFactory();
        injector.injectMembers(factory);
        assertSame(dataSource, factory.getDataSource(descriptor));
    } finally {
        // since the context is shared, must clear it after the test
        context.unbind(descriptor.getParameters());
    }
}
Also used : MockDataSource(com.mockrunner.mock.jdbc.MockDataSource) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Aggregations

MockDataSource (com.mockrunner.mock.jdbc.MockDataSource)6 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)6 Test (org.junit.Test)6 MockConnection (com.mockrunner.mock.jdbc.MockConnection)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 BatchTranslatorFactory (org.apache.cayenne.access.translator.batch.BatchTranslatorFactory)4 DefaultValueObjectTypeRegistry (org.apache.cayenne.access.types.DefaultValueObjectTypeRegistry)4 ValueObjectTypeRegistry (org.apache.cayenne.access.types.ValueObjectTypeRegistry)4 Constants (org.apache.cayenne.configuration.Constants)4 DefaultRuntimeProperties (org.apache.cayenne.configuration.DefaultRuntimeProperties)4 RuntimeProperties (org.apache.cayenne.configuration.RuntimeProperties)4 AutoAdapter (org.apache.cayenne.dba.AutoAdapter)4 DbAdapter (org.apache.cayenne.dba.DbAdapter)4 JdbcAdapter (org.apache.cayenne.dba.JdbcAdapter)4 JdbcPkGenerator (org.apache.cayenne.dba.JdbcPkGenerator)4 PkGenerator (org.apache.cayenne.dba.PkGenerator)4 SybaseAdapter (org.apache.cayenne.dba.sybase.SybaseAdapter)4 AdhocObjectFactory (org.apache.cayenne.di.AdhocObjectFactory)4 ClassLoaderManager (org.apache.cayenne.di.ClassLoaderManager)4