use of org.apache.cayenne.configuration.RuntimeProperties in project cayenne by apache.
the class DefaultDataSourceFactoryLoaderTest method testGetDataSourceFactory_UnusedProperties.
@Test
public void testGetDataSourceFactory_UnusedProperties() throws Exception {
final RuntimeProperties properties = mock(RuntimeProperties.class);
when(properties.get(Constants.JDBC_DRIVER_PROPERTY)).thenReturn("x");
when(properties.get(Constants.JDBC_URL_PROPERTY)).thenReturn(null);
when(properties.get(Constants.JDBC_USERNAME_PROPERTY)).thenReturn("username");
when(properties.get(Constants.JDBC_PASSWORD_PROPERTY)).thenReturn("12345");
DataChannelDescriptor channelDescriptor = new DataChannelDescriptor();
channelDescriptor.setName("X");
DataNodeDescriptor nodeDescriptor = new DataNodeDescriptor();
nodeDescriptor.setName("node1");
nodeDescriptor.setDataSourceFactoryType(MockDataSourceFactory1.class.getName());
nodeDescriptor.setDataChannelDescriptor(channelDescriptor);
Module testModule = binder -> {
binder.bind(ClassLoaderManager.class).to(DefaultClassLoaderManager.class);
binder.bind(AdhocObjectFactory.class).to(DefaultAdhocObjectFactory.class);
binder.bind(ResourceLocator.class).to(MockResourceLocator.class);
binder.bind(Key.get(ResourceLocator.class, Constants.SERVER_RESOURCE_LOCATOR)).to(MockResourceLocator.class);
binder.bind(RuntimeProperties.class).toInstance(properties);
binder.bind(JdbcEventLogger.class).to(Slf4jJdbcEventLogger.class);
};
Injector injector = DIBootstrap.createInjector(testModule);
DelegatingDataSourceFactory factoryLoader = new DelegatingDataSourceFactory();
injector.injectMembers(factoryLoader);
DataSourceFactory factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
assertNotNull(factory);
assertFalse(factory instanceof PropertyDataSourceFactory);
nodeDescriptor.setName("node2");
when(properties.get(Constants.JDBC_MIN_CONNECTIONS_PROPERTY + ".X.node2")).thenReturn("3");
when(properties.get(Constants.JDBC_PASSWORD_PROPERTY + ".X.node2")).thenReturn("123456");
factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
assertNotNull(factory);
assertFalse(factory instanceof PropertyDataSourceFactory);
nodeDescriptor.setName("node3");
when(properties.get(Constants.JDBC_URL_PROPERTY + ".X.node3")).thenReturn("url");
factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
assertNotNull(factory);
assertTrue(factory instanceof PropertyDataSourceFactory);
}
use of org.apache.cayenne.configuration.RuntimeProperties in project cayenne by apache.
the class DefaultDataSourceFactoryLoaderTest method testGetDataSourceFactory_Property.
@Test
public void testGetDataSourceFactory_Property() throws Exception {
final RuntimeProperties properties = mock(RuntimeProperties.class);
when(properties.get(Constants.JDBC_DRIVER_PROPERTY)).thenReturn("x");
when(properties.get(Constants.JDBC_URL_PROPERTY)).thenReturn("y");
DataChannelDescriptor channelDescriptor = new DataChannelDescriptor();
channelDescriptor.setName("X");
DataNodeDescriptor nodeDescriptor = new DataNodeDescriptor();
nodeDescriptor.setName("node1");
nodeDescriptor.setDataSourceFactoryType(MockDataSourceFactory1.class.getName());
nodeDescriptor.setDataChannelDescriptor(channelDescriptor);
Module testModule = binder -> {
binder.bind(ClassLoaderManager.class).to(DefaultClassLoaderManager.class);
binder.bind(AdhocObjectFactory.class).to(DefaultAdhocObjectFactory.class);
binder.bind(ResourceLocator.class).to(MockResourceLocator.class);
binder.bind(Key.get(ResourceLocator.class, Constants.SERVER_RESOURCE_LOCATOR)).to(MockResourceLocator.class);
binder.bind(RuntimeProperties.class).toInstance(properties);
binder.bind(JdbcEventLogger.class).to(Slf4jJdbcEventLogger.class);
};
Injector injector = DIBootstrap.createInjector(testModule);
DelegatingDataSourceFactory factoryLoader = new DelegatingDataSourceFactory();
injector.injectMembers(factoryLoader);
DataSourceFactory factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
assertNotNull(factory);
assertTrue(factory instanceof PropertyDataSourceFactory);
when(properties.get(Constants.JDBC_URL_PROPERTY)).thenReturn(null);
factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
assertNotNull(factory);
assertFalse(factory instanceof PropertyDataSourceFactory);
when(properties.get(Constants.JDBC_URL_PROPERTY + ".X.node2")).thenReturn("y");
factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
assertNotNull(factory);
assertFalse(factory instanceof PropertyDataSourceFactory);
when(properties.get(Constants.JDBC_URL_PROPERTY + ".X.node1")).thenReturn("y");
factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
assertNotNull(factory);
assertTrue(factory instanceof PropertyDataSourceFactory);
}
use of org.apache.cayenne.configuration.RuntimeProperties in project cayenne by apache.
the class PerAdapterProviderTest method before.
@Before
public void before() {
ResourceLocator locator = new ClassLoaderResourceLocator(new DefaultClassLoaderManager());
RuntimeProperties runtimeProperties = mock(RuntimeProperties.class);
ValueObjectTypeRegistry valueObjectTypeRegistry = mock(ValueObjectTypeRegistry.class);
this.oracleAdapter = new OracleAdapter(runtimeProperties, Collections.<ExtendedType>emptyList(), Collections.<ExtendedType>emptyList(), Collections.<ExtendedTypeFactory>emptyList(), locator, valueObjectTypeRegistry);
this.derbyAdapter = new DerbyAdapter(runtimeProperties, Collections.<ExtendedType>emptyList(), Collections.<ExtendedType>emptyList(), Collections.<ExtendedTypeFactory>emptyList(), locator, valueObjectTypeRegistry);
this.autoDerbyAdapter = new AutoAdapter(new Provider<DbAdapter>() {
@Override
public DbAdapter get() throws DIRuntimeException {
return derbyAdapter;
}
}, new Slf4jJdbcEventLogger(runtimeProperties));
}
Aggregations