use of com.qlangtech.tis.manage.common.Config in project tis by qlangtech.
the class TestSysInitializeAction method testSystemDBInitializWithDerby.
// public void testInitializeAppAndSchema() throws Exception {
// request.setParameter("emethod", "init");
// request.setParameter("action", "sys_initialize_action");
//
// ActionProxy proxy = getActionProxy("/runtime/index_query.ajax");
// assertNotNull(proxy);
// SysInitializeAction initAction = (SysInitializeAction) proxy.getAction();
// assertNotNull(initAction);
// initAction.initializeAppAndSchema();
//
// }
/**
* 测试系统数据库初始化
*/
public void testSystemDBInitializWithDerby() throws Exception {
File initialSuccessToken = SysInitializeAction.getSysInitializedTokenFile();
FileUtils.deleteQuietly(initialSuccessToken);
final String tis_ansible_home = StringUtils.defaultIfEmpty(System.getenv("tis_ansible_home"), "/opt/misc/tis-ansible");
String[] args = new String[] { tis_ansible_home + "/tis_console_derby.sql", Config.DB_TYPE_DERBY };
Config config = this.mock("config", Config.class);
EasyMock.expect(config.getZkHost()).andReturn("192.168.28.200:2181/tis/cloud");
EasyMock.expect(config.getRuntime()).andReturn(RunEnvironment.DAILY.getKeyName()).anyTimes();
Config.TisDbConfig mockDBType = new Config.TisDbConfig();
mockDBType.dbtype = Config.DB_TYPE_DERBY;
mockDBType.dbname = "tis_console_db";
File dbDir = new File(Config.getDataDir(), mockDBType.dbname);
FileUtils.deleteQuietly(dbDir);
EasyMock.expect(config.getDbConfig()).andReturn(mockDBType).anyTimes();
Config.setConfig(config);
replay();
int[] tryIndex = new int[1];
AtomicBoolean hasExecDSCreateInspector = new AtomicBoolean();
TISDataSourceFactory.dsCreateInspector = new TISDataSourceFactory.IDSCreatorInspect() {
@Override
public void checkDataSource(boolean getDSFromJNDI, BasicDataSource dataSource) {
assertFalse(getDSFromJNDI);
if (tryIndex[0]++ == 0) {
assertEquals("jdbc:derby:" + mockDBType.dbname + ";create=true", dataSource.getUrl());
} else {
assertEquals("jdbc:derby:" + mockDBType.dbname + ";create=false", dataSource.getUrl());
}
hasExecDSCreateInspector.set(true);
}
};
SysInitializeAction.main(args);
assertTrue("hasExecDSCreateInspector must be true", hasExecDSCreateInspector.get());
// File initialSuccessToken = SysInitializeAction.getSysInitializedTokenFile();
assertTrue("initialSuccessToken fiel:" + initialSuccessToken.getAbsolutePath(), initialSuccessToken.exists());
assertEquals("create db 2 times", tryIndex[0], 2);
assertTrue("dbDir must exist:" + dbDir.getAbsolutePath(), dbDir.exists());
verifyAll();
}
use of com.qlangtech.tis.manage.common.Config in project tis by qlangtech.
the class TisPropertiesFileConfigurationProvider method toMap.
@Override
protected Map<String, String> toMap(Properties properties) {
PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper("${", "}");
Config config = Config.getInstance();
PropertyPlaceholderHelper.PlaceholderResolver resolver = new PropertyPlaceholderHelper.PlaceholderResolver() {
@Override
public String resolvePlaceholder(String placeholderName) {
return config.getAllKV().get(placeholderName);
}
};
Map<String, String> result = super.toMap(properties);
return result.entrySet().stream().collect(Collectors.toMap((e) -> e.getKey(), (e) -> helper.replacePlaceholders(e.getValue(), resolver)));
}
Aggregations