mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
refactor ConfigFilter, remove ConfigLoader
This commit is contained in:
@@ -53,15 +53,16 @@ public class ConfigFilterTest extends ConfigFileGenerator {
|
||||
DruidDataSource dataSource = new DruidDataSource();
|
||||
dataSource.setFilters("config");
|
||||
dataSource.setConnectionProperties("config.file=abcdef");
|
||||
|
||||
Exception error = null;
|
||||
try {
|
||||
dataSource.init();
|
||||
Assert.assertTrue("It is here", false);
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
Assert.assertTrue(true);
|
||||
error = e;
|
||||
} finally {
|
||||
JdbcUtils.close(dataSource);
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -76,7 +77,8 @@ public class ConfigFilterTest extends ConfigFileGenerator {
|
||||
|
||||
try {
|
||||
dataSource.init();
|
||||
Assert.assertEquals("The password is " + dataSource.getPassword() + ", is not xiaoyu", "xiaoyu", dataSource.getPassword());
|
||||
Assert.assertEquals("The password is " + dataSource.getPassword() + ", is not xiaoyu", "xiaoyu",
|
||||
dataSource.getPassword());
|
||||
} finally {
|
||||
JdbcUtils.close(dataSource);
|
||||
}
|
||||
@@ -92,22 +94,23 @@ public class ConfigFilterTest extends ConfigFileGenerator {
|
||||
dataSource.setFilters("config");
|
||||
dataSource.setConnectionProperties("config.decrypt=ABCDEF");
|
||||
|
||||
Exception error = null;
|
||||
try {
|
||||
dataSource.init();
|
||||
Assert.assertTrue("It is here", false);
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
Assert.assertTrue(true);
|
||||
error = e;
|
||||
} finally {
|
||||
JdbcUtils.close(dataSource);
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInitRemoteConfigAndDecrypt() throws SQLException {
|
||||
DruidDataSource dataSource = new DruidDataSource();
|
||||
dataSource.setFilters("config");
|
||||
dataSource.setConnectionProperties("config.decrypt=RSA;config.file=" + FileConfigLoader.PROTOCOL_PREFIX + this.filePath);
|
||||
dataSource.setConnectionProperties("config.decrypt=RSA;config.file=" + FileConfigLoader.PROTOCOL_PREFIX
|
||||
+ this.filePath);
|
||||
try {
|
||||
dataSource.init();
|
||||
|
||||
@@ -136,13 +139,14 @@ public class ConfigFilterTest extends ConfigFileGenerator {
|
||||
dataSource.setFilters("config");
|
||||
dataSource.setConnectionProperties("config.file=abcdefeg");
|
||||
|
||||
Exception error = null;
|
||||
try {
|
||||
dataSource.init();
|
||||
Assert.assertTrue("Get here.", false);
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
error = e;
|
||||
} finally {
|
||||
JdbcUtils.close(dataSource);
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
package com.alibaba.druid.bvt.filter.config;
|
||||
|
||||
import com.alibaba.druid.filter.config.loader.ConfigLoader;
|
||||
import com.alibaba.druid.filter.config.loader.ConfigLoaderFactory;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author Jonas Yang
|
||||
*/
|
||||
public class ConfigLoaderFactoryTest {
|
||||
|
||||
@Test
|
||||
public void testInitConfigLoader() {
|
||||
ConfigLoader[] configLoaders = ConfigLoaderFactory.getConfigLoaders();
|
||||
Assert.assertTrue("The size is " + configLoaders.length + " , not 2", configLoaders.length == 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetConfigLoader() {
|
||||
ConfigLoader configLoader = ConfigLoaderFactory.getConfigLoader("abcde");
|
||||
Assert.assertEquals("The config is " + configLoader, null, configLoader);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddConfigLoader() {
|
||||
int size = ConfigLoaderFactory.getConfigLoaders().length;
|
||||
|
||||
ConfigLoaderFactory.addConfigLoader(new ConfigLoader() {
|
||||
@Override
|
||||
public String getId() {
|
||||
return "My Test"; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public Properties loadConfig(String protocol) {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSupported(String protocol) {
|
||||
if (protocol.startsWith("abc")) {
|
||||
return true;
|
||||
}
|
||||
return false; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
});
|
||||
|
||||
Assert.assertEquals("The size is " + ConfigLoaderFactory.getConfigLoaders().length, ConfigLoaderFactory.getConfigLoaders().length, size + 1);
|
||||
|
||||
ConfigLoader configLoader = ConfigLoaderFactory.getConfigLoader("abc");
|
||||
Assert.assertNotNull("The config loader is null", configLoader);
|
||||
Assert.assertEquals("The config loader's id is " + configLoader.getId(), "My Test", configLoader.getId());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user