Search in sources :

Example 6 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 DatabaseMetaData (java.sql.DatabaseMetaData)4 SQLException (java.sql.SQLException)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 SybaseAdapter (org.apache.cayenne.dba.sybase.SybaseAdapter)4 AdhocObjectFactory (org.apache.cayenne.di.AdhocObjectFactory)4 ClassLoaderManager (org.apache.cayenne.di.ClassLoaderManager)4 DIBootstrap (org.apache.cayenne.di.DIBootstrap)4