final Map<String, String> properties = new HashMap<String, String>();
properties.put(PropertyDataSourceFactory.JDBC_DRIVER_PROPERTY, "x");
properties.put(PropertyDataSourceFactory.JDBC_URL_PROPERTY, "y");
DefaultDataSourceFactoryLoader factoryLoader = new DefaultDataSourceFactoryLoader() {
@Override
protected String getProperty(String key) {
return properties.get(key);
}
};
injector.injectMembers(factoryLoader);
DataSourceFactory factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
assertNotNull(factory);
assertTrue(factory instanceof PropertyDataSourceFactory);
properties.remove(PropertyDataSourceFactory.JDBC_URL_PROPERTY);
factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
assertNotNull(factory);
assertFalse(factory instanceof PropertyDataSourceFactory);
properties.put(PropertyDataSourceFactory.JDBC_URL_PROPERTY + ".X.node2", "y");
factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
assertNotNull(factory);
assertFalse(factory instanceof PropertyDataSourceFactory);
properties.put(PropertyDataSourceFactory.JDBC_URL_PROPERTY + ".X.node1", "y");
factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
assertNotNull(factory);
assertTrue(factory instanceof PropertyDataSourceFactory);
}