mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
clean history
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package cn.hutool.setting.test;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.log.LogFactory;
|
||||
import cn.hutool.log.dialect.console.ConsoleLogFactory;
|
||||
import cn.hutool.setting.dialect.Props;
|
||||
|
||||
/**
|
||||
* Setting单元测试
|
||||
* @author Looly
|
||||
*
|
||||
*/
|
||||
public class PropsTest {
|
||||
|
||||
@Before
|
||||
public void init(){
|
||||
LogFactory.setCurrentLogFactory(ConsoleLogFactory.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propTest(){
|
||||
Props props = new Props("test.properties");
|
||||
String user = props.getProperty("user");
|
||||
Assert.assertEquals(user, "root");
|
||||
|
||||
String driver = props.getStr("driver");
|
||||
Assert.assertEquals(driver, "com.mysql.jdbc.Driver");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void propTestForAbsPAth(){
|
||||
Props props = new Props("d:/test.properties");
|
||||
String user = props.getProperty("user");
|
||||
Assert.assertEquals(user, "root");
|
||||
|
||||
String driver = props.getStr("driver");
|
||||
Assert.assertEquals(driver, "com.mysql.jdbc.Driver");
|
||||
}
|
||||
}
|
@@ -0,0 +1,58 @@
|
||||
package cn.hutool.setting.test;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.setting.Setting;
|
||||
|
||||
/**
|
||||
* Setting单元测试
|
||||
* @author Looly
|
||||
*
|
||||
*/
|
||||
public class SettingTest {
|
||||
|
||||
@Test
|
||||
public void settingTest(){
|
||||
Setting setting = new Setting("test.setting", true);
|
||||
|
||||
String driver = setting.getByGroup("driver", "demo");
|
||||
Assert.assertEquals("com.mysql.jdbc.Driver", driver);
|
||||
|
||||
//本分组变量替换
|
||||
String user = setting.getByGroup("user", "demo");
|
||||
Assert.assertEquals("rootcom.mysql.jdbc.Driver", user);
|
||||
|
||||
//跨分组变量替换
|
||||
String user2 = setting.getByGroup("user2", "demo");
|
||||
Assert.assertEquals("rootcom.mysql.jdbc.Driver", user2);
|
||||
|
||||
//默认值测试
|
||||
String value = setting.getStr("keyNotExist", "defaultTest");
|
||||
Assert.assertEquals("defaultTest", value);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void settingTestForAbsPath(){
|
||||
Setting setting = new Setting("d:\\excel-plugin\\other.setting", true);
|
||||
Console.log(setting.getStr("a"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void settingTestForCustom() {
|
||||
Setting setting = new Setting();
|
||||
|
||||
setting.put("group1", "user", "root");
|
||||
setting.put("group2", "user", "root2");
|
||||
setting.put("group3", "user", "root3");
|
||||
setting.set("user", "root4");
|
||||
|
||||
Assert.assertEquals("root", setting.getByGroup("user", "group1"));
|
||||
Assert.assertEquals("root2", setting.getByGroup("user", "group2"));
|
||||
Assert.assertEquals("root3", setting.getByGroup("user", "group3"));
|
||||
Assert.assertEquals("root4", setting.get("user"));
|
||||
}
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
package cn.hutool.setting.test;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.setting.SettingUtil;
|
||||
|
||||
public class SettingUtilTest {
|
||||
|
||||
@Test
|
||||
public void getTest() {
|
||||
String driver = SettingUtil.get("test").get("demo", "driver");
|
||||
Assert.assertEquals("com.mysql.jdbc.Driver", driver);
|
||||
}
|
||||
}
|
24
hutool-setting/src/test/resources/example/example.set
Normal file
24
hutool-setting/src/test/resources/example/example.set
Normal file
@@ -0,0 +1,24 @@
|
||||
# -------------------------------------------------------------
|
||||
# ----- GroupedSet File with UTF8-----
|
||||
# @see com.xiaoleilu.hutool.lang.GroupedSet
|
||||
# -------------------------------------------------------------
|
||||
|
||||
无分组值1
|
||||
无分组值2
|
||||
|
||||
[分组1]
|
||||
值1
|
||||
值2
|
||||
值3
|
||||
|
||||
[特殊分组]
|
||||
1
|
||||
2
|
||||
3
|
||||
\#转义注释符
|
||||
|
||||
[]
|
||||
空分组值1
|
||||
空分组会合并到无分组里
|
||||
|
||||
[没有值的分组]
|
20
hutool-setting/src/test/resources/example/example.setting
Normal file
20
hutool-setting/src/test/resources/example/example.setting
Normal file
@@ -0,0 +1,20 @@
|
||||
# -------------------------------------------------------------
|
||||
# ----- Setting File with UTF8-----
|
||||
# ----- 数据库配置文件 -----
|
||||
# -------------------------------------------------------------
|
||||
|
||||
# 键值都支持中文,默认UTF-8编码,可以在new Setting的时候设置编码
|
||||
key = value
|
||||
|
||||
#中括表示一个分组,其下面的所有属性归属于这个分组,在此分组名为demo,也可以没有分组
|
||||
#分组后的键值对在Setting对象中表现形式是:demo.key,也可以使用相应的方法取值
|
||||
[demo]
|
||||
# 类似于Properties的键值对
|
||||
key = value
|
||||
# 支持变量替换(在new Setting的时候需要设置isUseVariable为true)
|
||||
key2 = value${key}
|
||||
|
||||
#中括号开始表示新的分组开始,分组相互独立,键值与其他分组互不影响
|
||||
[demo2]
|
||||
key = value2
|
||||
key2 = value
|
@@ -0,0 +1,13 @@
|
||||
#--------------------------------------
|
||||
# GroupSet配置文件样例
|
||||
#每一个分组下有一组set集合
|
||||
# author xiaoleilu
|
||||
#--------------------------------------
|
||||
|
||||
[group1]
|
||||
value1
|
||||
value2
|
||||
|
||||
[group2]
|
||||
value1
|
||||
value2
|
13
hutool-setting/src/test/resources/test.properties
Normal file
13
hutool-setting/src/test/resources/test.properties
Normal file
@@ -0,0 +1,13 @@
|
||||
# -------------------------------------------------------------
|
||||
# ----- Setting File with UTF8-----
|
||||
# ----- \u6570\u636e\u5e93\u914d\u7f6e\u6587\u4ef6 -----
|
||||
# -------------------------------------------------------------
|
||||
|
||||
#\u6570\u636e\u5e93\u9a71\u52a8\u540d\uff0c\u5982\u679c\u4e0d\u6307\u5b9a\uff0c\u5219\u4f1a\u6839\u636eurl\u81ea\u52a8\u5224\u5b9a
|
||||
driver = com.mysql.jdbc.Driver
|
||||
#JDBC url\uff0c\u5fc5\u987b
|
||||
url = jdbc:mysql://fedora.vmware:3306/extractor
|
||||
#\u7528\u6237\u540d\uff0c\u5fc5\u987b
|
||||
user = root
|
||||
#\u5bc6\u7801\uff0c\u5fc5\u987b\uff0c\u5982\u679c\u5bc6\u7801\u4e3a\u7a7a\uff0c\u8bf7\u586b\u5199 pass =
|
||||
pass = 123456
|
16
hutool-setting/src/test/resources/test.setting
Normal file
16
hutool-setting/src/test/resources/test.setting
Normal file
@@ -0,0 +1,16 @@
|
||||
# -------------------------------------------------------------
|
||||
# ----- Setting File with UTF8-----
|
||||
# ----- 数据库配置文件 -----
|
||||
# -------------------------------------------------------------
|
||||
|
||||
#中括表示一个分组,其下面的所有属性归属于这个分组,在此分组名为demo,也可以没有分组
|
||||
[demo]
|
||||
#数据库驱动名,如果不指定,则会根据url自动判定
|
||||
driver = com.mysql.jdbc.Driver
|
||||
#JDBC url,必须
|
||||
url = jdbc:mysql://fedora.vmware:3306/extractor
|
||||
#用户名,必须
|
||||
user = root${driver}
|
||||
user2 = root${demo.driver}
|
||||
#密码,必须,如果密码为空,请填写 pass =
|
||||
pass = 123456
|
Reference in New Issue
Block a user