change line sep

This commit is contained in:
Looly
2021-01-20 17:10:45 +08:00
parent 720d24566b
commit 4e38adb32d
1450 changed files with 183940 additions and 183940 deletions

View File

@@ -1,123 +1,123 @@
package cn.hutool.setting.test;
import cn.hutool.core.date.DateUtil;
import cn.hutool.log.LogFactory;
import cn.hutool.log.dialect.console.ConsoleLogFactory;
import cn.hutool.setting.dialect.Props;
import lombok.Data;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* Setting单元测试
*
* @author Looly
*
*/
public class PropsTest {
@Before
public void init() {
LogFactory.setCurrentLogFactory(ConsoleLogFactory.class);
}
@Test
public void propTest() {
//noinspection MismatchedQueryAndUpdateOfCollection
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() {
//noinspection MismatchedQueryAndUpdateOfCollection
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");
}
@Test
public void toBeanTest() {
Props props = Props.getProp("to_bean_test.properties");
ConfigProperties cfg = props.toBean(ConfigProperties.class, "mail");
Assert.assertEquals("mailer@mail.com", cfg.getHost());
Assert.assertEquals(9000, cfg.getPort());
Assert.assertEquals("mailer@mail.com", cfg.getFrom());
Assert.assertEquals("john", cfg.getCredentials().getUsername());
Assert.assertEquals("password", cfg.getCredentials().getPassword());
Assert.assertEquals("SHA1", cfg.getCredentials().getAuthMethod());
Assert.assertEquals("true", cfg.getAdditionalHeaders().get("redelivery"));
Assert.assertEquals("true", cfg.getAdditionalHeaders().get("secure"));
Assert.assertEquals("admin@mail.com", cfg.getDefaultRecipients().get(0));
Assert.assertEquals("owner@mail.com", cfg.getDefaultRecipients().get(1));
}
@Test
public void toBeanWithNullPrefixTest(){
Props configProp = new Props();
configProp.setProperty("createTime", Objects.requireNonNull(DateUtil.parse("2020-01-01")));
configProp.setProperty("isInit", true);
configProp.setProperty("stairPlan", 1);
configProp.setProperty("stageNum", 2);
configProp.setProperty("version", 3);
SystemConfig systemConfig = configProp.toBean(SystemConfig.class);
Assert.assertEquals(DateUtil.parse("2020-01-01"), systemConfig.getCreateTime());
Assert.assertEquals(true, systemConfig.getIsInit());
Assert.assertEquals("1", systemConfig.getStairPlan());
Assert.assertEquals(new Integer(2), systemConfig.getStageNum());
Assert.assertEquals("3", systemConfig.getVersion());
}
@Data
public static class ConfigProperties {
private String host;
private int port;
private String from;
private Credentials credentials;
private List<String> defaultRecipients;
private Map<String, String> additionalHeaders;
}
@Data
public static class Credentials {
private String authMethod;
private String username;
private String password;
}
@Data
public static class SystemConfig {
private Boolean isInit;//是否初始化
private Date createTime;//系统创建时间
private String version;//系统版本
private String ServiceOS;//服务器系统
private String stairPlan;//周期计划 1 自然年周期2 自然月周期3 季度周期 4 自定义周期
private Date startDate;//周期开始日期
private Date nextStartDate;//下一周期开始日期
private Integer stageNum;//阶段数目
private Integer[] stageContent;//阶段详情
private Date theStageTime;//当前阶段开始日期
private Date nextStageTime;//当前阶段结束日期/下一阶段开始日期
}
}
package cn.hutool.setting.test;
import cn.hutool.core.date.DateUtil;
import cn.hutool.log.LogFactory;
import cn.hutool.log.dialect.console.ConsoleLogFactory;
import cn.hutool.setting.dialect.Props;
import lombok.Data;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* Setting单元测试
*
* @author Looly
*
*/
public class PropsTest {
@Before
public void init() {
LogFactory.setCurrentLogFactory(ConsoleLogFactory.class);
}
@Test
public void propTest() {
//noinspection MismatchedQueryAndUpdateOfCollection
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() {
//noinspection MismatchedQueryAndUpdateOfCollection
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");
}
@Test
public void toBeanTest() {
Props props = Props.getProp("to_bean_test.properties");
ConfigProperties cfg = props.toBean(ConfigProperties.class, "mail");
Assert.assertEquals("mailer@mail.com", cfg.getHost());
Assert.assertEquals(9000, cfg.getPort());
Assert.assertEquals("mailer@mail.com", cfg.getFrom());
Assert.assertEquals("john", cfg.getCredentials().getUsername());
Assert.assertEquals("password", cfg.getCredentials().getPassword());
Assert.assertEquals("SHA1", cfg.getCredentials().getAuthMethod());
Assert.assertEquals("true", cfg.getAdditionalHeaders().get("redelivery"));
Assert.assertEquals("true", cfg.getAdditionalHeaders().get("secure"));
Assert.assertEquals("admin@mail.com", cfg.getDefaultRecipients().get(0));
Assert.assertEquals("owner@mail.com", cfg.getDefaultRecipients().get(1));
}
@Test
public void toBeanWithNullPrefixTest(){
Props configProp = new Props();
configProp.setProperty("createTime", Objects.requireNonNull(DateUtil.parse("2020-01-01")));
configProp.setProperty("isInit", true);
configProp.setProperty("stairPlan", 1);
configProp.setProperty("stageNum", 2);
configProp.setProperty("version", 3);
SystemConfig systemConfig = configProp.toBean(SystemConfig.class);
Assert.assertEquals(DateUtil.parse("2020-01-01"), systemConfig.getCreateTime());
Assert.assertEquals(true, systemConfig.getIsInit());
Assert.assertEquals("1", systemConfig.getStairPlan());
Assert.assertEquals(new Integer(2), systemConfig.getStageNum());
Assert.assertEquals("3", systemConfig.getVersion());
}
@Data
public static class ConfigProperties {
private String host;
private int port;
private String from;
private Credentials credentials;
private List<String> defaultRecipients;
private Map<String, String> additionalHeaders;
}
@Data
public static class Credentials {
private String authMethod;
private String username;
private String password;
}
@Data
public static class SystemConfig {
private Boolean isInit;//是否初始化
private Date createTime;//系统创建时间
private String version;//系统版本
private String ServiceOS;//服务器系统
private String stairPlan;//周期计划 1 自然年周期2 自然月周期3 季度周期 4 自定义周期
private Date startDate;//周期开始日期
private Date nextStartDate;//下一周期开始日期
private Integer stageNum;//阶段数目
private Integer[] stageContent;//阶段详情
private Date theStageTime;//当前阶段开始日期
private Date nextStageTime;//当前阶段结束日期/下一阶段开始日期
}
}

View File

@@ -1,22 +1,22 @@
package cn.hutool.setting.test;
import cn.hutool.setting.dialect.PropsUtil;
import org.junit.Assert;
import org.junit.Test;
import java.util.Objects;
public class PropsUtilTest {
@Test
public void getTest() {
String driver = PropsUtil.get("test").getStr("driver");
Assert.assertEquals("com.mysql.jdbc.Driver", driver);
}
@Test
public void getFirstFoundTest() {
String driver = Objects.requireNonNull(PropsUtil.getFirstFound("test2", "test")).getStr("driver");
Assert.assertEquals("com.mysql.jdbc.Driver", driver);
}
}
package cn.hutool.setting.test;
import cn.hutool.setting.dialect.PropsUtil;
import org.junit.Assert;
import org.junit.Test;
import java.util.Objects;
public class PropsUtilTest {
@Test
public void getTest() {
String driver = PropsUtil.get("test").getStr("driver");
Assert.assertEquals("com.mysql.jdbc.Driver", driver);
}
@Test
public void getFirstFoundTest() {
String driver = Objects.requireNonNull(PropsUtil.getFirstFound("test2", "test")).getStr("driver");
Assert.assertEquals("com.mysql.jdbc.Driver", driver);
}
}

View File

@@ -1,71 +1,71 @@
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() {
//noinspection MismatchedQueryAndUpdateOfCollection
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() {
//noinspection MismatchedQueryAndUpdateOfCollection
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"));
}
/**
* 测试写出是否正常
*/
@Test
public void storeTest() {
Setting setting = new Setting("test.setting");
setting.set("testKey", "testValue");
setting.store();
}
}
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() {
//noinspection MismatchedQueryAndUpdateOfCollection
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() {
//noinspection MismatchedQueryAndUpdateOfCollection
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"));
}
/**
* 测试写出是否正常
*/
@Test
public void storeTest() {
Setting setting = new Setting("test.setting");
setting.set("testKey", "testValue");
setting.store();
}
}

View File

@@ -1,29 +1,29 @@
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);
}
@Test
public void getTest2() {
String driver = SettingUtil.get("example/example").get("demo", "key");
Assert.assertEquals("value", driver);
}
@Test
public void getFirstFoundTest() {
//noinspection ConstantConditions
String driver = SettingUtil.getFirstFound("test2", "test")
.get("demo", "driver");
Assert.assertEquals("com.mysql.jdbc.Driver", driver);
}
}
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);
}
@Test
public void getTest2() {
String driver = SettingUtil.get("example/example").get("demo", "key");
Assert.assertEquals("value", driver);
}
@Test
public void getFirstFoundTest() {
//noinspection ConstantConditions
String driver = SettingUtil.getFirstFound("test2", "test")
.get("demo", "driver");
Assert.assertEquals("com.mysql.jdbc.Driver", driver);
}
}

View File

@@ -1,24 +1,24 @@
# -------------------------------------------------------------
# ----- GroupedSet File with UTF8-----
# @see com.xiaoleilu.hutool.lang.GroupedSet
# -------------------------------------------------------------
无分组值1
无分组值2
[分组1]
值1
值2
值3
[特殊分组]
1
2
3
\#转义注释符
[]
空分组值1
空分组会合并到无分组里
# -------------------------------------------------------------
# ----- GroupedSet File with UTF8-----
# @see com.xiaoleilu.hutool.lang.GroupedSet
# -------------------------------------------------------------
无分组值1
无分组值2
[分组1]
值1
值2
值3
[特殊分组]
1
2
3
\#转义注释符
[]
空分组值1
空分组会合并到无分组里
[没有值的分组]

View File

@@ -1,20 +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
# -------------------------------------------------------------
# ----- 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

View File

@@ -1,13 +1,13 @@
#--------------------------------------
# GroupSet配置文件样例
#每一个分组下有一组set集合
# author xiaoleilu
#--------------------------------------
[group1]
value1
value2
[group2]
value1
#--------------------------------------
# GroupSet配置文件样例
#每一个分组下有一组set集合
# author xiaoleilu
#--------------------------------------
[group1]
value1
value2
[group2]
value1
value2

View File

@@ -1,13 +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 =
# -------------------------------------------------------------
# ----- 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

View File

@@ -1,16 +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 =
# -------------------------------------------------------------
# ----- 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

View File

@@ -1,20 +1,20 @@
#Simple properties
mail.host=mailer@mail.com
mail.port=9000
mail.from=mailer@mail.com
#List properties
mail.defaultRecipients[0]=admin@mail.com
mail.defaultRecipients[1]=owner@mail.com
#Map Properties
mail.additionalHeaders.redelivery=true
mail.additionalHeaders.secure=true
#Object properties
mail.credentials.username=john
mail.credentials.password=password
mail.credentials.authMethod=SHA1
# ignore properties
#Simple properties
mail.host=mailer@mail.com
mail.port=9000
mail.from=mailer@mail.com
#List properties
mail.defaultRecipients[0]=admin@mail.com
mail.defaultRecipients[1]=owner@mail.com
#Map Properties
mail.additionalHeaders.redelivery=true
mail.additionalHeaders.secure=true
#Object properties
mail.credentials.username=john
mail.credentials.password=password
mail.credentials.authMethod=SHA1
# ignore properties
mail.ignore.filed = balabala