mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-08-18 20:38:02 +08:00
change line sep
This commit is contained in:
@@ -1,31 +1,31 @@
|
||||
package cn.hutool.extra.cglib;
|
||||
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class CglibUtilTest {
|
||||
|
||||
@Test
|
||||
public void copyTest() {
|
||||
SampleBean bean = new SampleBean();
|
||||
bean.setValue("Hello world");
|
||||
|
||||
OtherSampleBean otherBean = new OtherSampleBean();
|
||||
CglibUtil.copy(bean, otherBean);
|
||||
Assert.assertEquals("Hello world", otherBean.getValue());
|
||||
|
||||
OtherSampleBean otherBean2 = CglibUtil.copy(bean, OtherSampleBean.class);
|
||||
Assert.assertEquals("Hello world", otherBean2.getValue());
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class SampleBean {
|
||||
private String value;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class OtherSampleBean {
|
||||
private String value;
|
||||
}
|
||||
}
|
||||
package cn.hutool.extra.cglib;
|
||||
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class CglibUtilTest {
|
||||
|
||||
@Test
|
||||
public void copyTest() {
|
||||
SampleBean bean = new SampleBean();
|
||||
bean.setValue("Hello world");
|
||||
|
||||
OtherSampleBean otherBean = new OtherSampleBean();
|
||||
CglibUtil.copy(bean, otherBean);
|
||||
Assert.assertEquals("Hello world", otherBean.getValue());
|
||||
|
||||
OtherSampleBean otherBean2 = CglibUtil.copy(bean, OtherSampleBean.class);
|
||||
Assert.assertEquals("Hello world", otherBean2.getValue());
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class SampleBean {
|
||||
private String value;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class OtherSampleBean {
|
||||
private String value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,62 +1,62 @@
|
||||
package cn.hutool.extra.compress;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.extra.compress.archiver.StreamArchiver;
|
||||
import org.apache.commons.compress.archivers.ArchiveStreamFactory;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class ArchiverTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void zipTest(){
|
||||
final File file = FileUtil.file("d:/test/compress/test.zip");
|
||||
StreamArchiver.create(CharsetUtil.CHARSET_UTF_8, ArchiveStreamFactory.ZIP, file)
|
||||
.add(FileUtil.file("d:/Java"), (f)->{
|
||||
Console.log("Add: {}", f.getPath());
|
||||
return true;
|
||||
})
|
||||
.finish().close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void tarTest(){
|
||||
final File file = FileUtil.file("d:/test/compress/test.tar");
|
||||
StreamArchiver.create(CharsetUtil.CHARSET_UTF_8, ArchiveStreamFactory.TAR, file)
|
||||
.add(FileUtil.file("d:/Java"), (f)->{
|
||||
Console.log("Add: {}", f.getPath());
|
||||
return true;
|
||||
})
|
||||
.finish().close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void cpioTest(){
|
||||
final File file = FileUtil.file("d:/test/compress/test.cpio");
|
||||
StreamArchiver.create(CharsetUtil.CHARSET_UTF_8, ArchiveStreamFactory.CPIO, file)
|
||||
.add(FileUtil.file("d:/Java"), (f)->{
|
||||
Console.log("Add: {}", f.getPath());
|
||||
return true;
|
||||
})
|
||||
.finish().close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void senvenZTest(){
|
||||
final File file = FileUtil.file("d:/test/compress/test.7z");
|
||||
CompressUtil.createArchiver(CharsetUtil.CHARSET_UTF_8, ArchiveStreamFactory.SEVEN_Z, file)
|
||||
.add(FileUtil.file("d:/Java/apache-maven-3.6.3"), (f)->{
|
||||
Console.log("Add: {}", f.getPath());
|
||||
return true;
|
||||
})
|
||||
.finish().close();
|
||||
}
|
||||
}
|
||||
package cn.hutool.extra.compress;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.extra.compress.archiver.StreamArchiver;
|
||||
import org.apache.commons.compress.archivers.ArchiveStreamFactory;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class ArchiverTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void zipTest(){
|
||||
final File file = FileUtil.file("d:/test/compress/test.zip");
|
||||
StreamArchiver.create(CharsetUtil.CHARSET_UTF_8, ArchiveStreamFactory.ZIP, file)
|
||||
.add(FileUtil.file("d:/Java"), (f)->{
|
||||
Console.log("Add: {}", f.getPath());
|
||||
return true;
|
||||
})
|
||||
.finish().close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void tarTest(){
|
||||
final File file = FileUtil.file("d:/test/compress/test.tar");
|
||||
StreamArchiver.create(CharsetUtil.CHARSET_UTF_8, ArchiveStreamFactory.TAR, file)
|
||||
.add(FileUtil.file("d:/Java"), (f)->{
|
||||
Console.log("Add: {}", f.getPath());
|
||||
return true;
|
||||
})
|
||||
.finish().close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void cpioTest(){
|
||||
final File file = FileUtil.file("d:/test/compress/test.cpio");
|
||||
StreamArchiver.create(CharsetUtil.CHARSET_UTF_8, ArchiveStreamFactory.CPIO, file)
|
||||
.add(FileUtil.file("d:/Java"), (f)->{
|
||||
Console.log("Add: {}", f.getPath());
|
||||
return true;
|
||||
})
|
||||
.finish().close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void senvenZTest(){
|
||||
final File file = FileUtil.file("d:/test/compress/test.7z");
|
||||
CompressUtil.createArchiver(CharsetUtil.CHARSET_UTF_8, ArchiveStreamFactory.SEVEN_Z, file)
|
||||
.add(FileUtil.file("d:/Java/apache-maven-3.6.3"), (f)->{
|
||||
Console.log("Add: {}", f.getPath());
|
||||
return true;
|
||||
})
|
||||
.finish().close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
package cn.hutool.extra.compress;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.extra.compress.extractor.Extractor;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ExtractorTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void zipTest(){
|
||||
Extractor extractor = CompressUtil.createExtractor(
|
||||
CharsetUtil.defaultCharset(),
|
||||
FileUtil.file("d:/test/compress/test.zip"));
|
||||
|
||||
extractor.extract(FileUtil.file("d:/test/compress/test2/"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void sevenZTest(){
|
||||
Extractor extractor = CompressUtil.createExtractor(
|
||||
CharsetUtil.defaultCharset(),
|
||||
FileUtil.file("d:/test/compress/test.7z"));
|
||||
|
||||
extractor.extract(FileUtil.file("d:/test/compress/test2/"));
|
||||
}
|
||||
}
|
||||
package cn.hutool.extra.compress;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.extra.compress.extractor.Extractor;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ExtractorTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void zipTest(){
|
||||
Extractor extractor = CompressUtil.createExtractor(
|
||||
CharsetUtil.defaultCharset(),
|
||||
FileUtil.file("d:/test/compress/test.zip"));
|
||||
|
||||
extractor.extract(FileUtil.file("d:/test/compress/test2/"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void sevenZTest(){
|
||||
Extractor extractor = CompressUtil.createExtractor(
|
||||
CharsetUtil.defaultCharset(),
|
||||
FileUtil.file("d:/test/compress/test.7z"));
|
||||
|
||||
extractor.extract(FileUtil.file("d:/test/compress/test2/"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
package cn.hutool.extra.emoji;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class EmojiUtilTest {
|
||||
|
||||
@Test
|
||||
public void toUnicodeTest() {
|
||||
String emoji = EmojiUtil.toUnicode(":smile:");
|
||||
Assert.assertEquals("😄", emoji);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toAliasTest() {
|
||||
String alias = EmojiUtil.toAlias("😄");
|
||||
Assert.assertEquals(":smile:", alias);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void containsEmojiTest() {
|
||||
boolean containsEmoji = EmojiUtil.containsEmoji("测试一下是否包含EMOJ:😄");
|
||||
Assert.assertTrue(containsEmoji);
|
||||
boolean notContainsEmoji = EmojiUtil.containsEmoji("不包含EMOJ:^_^");
|
||||
Assert.assertFalse(notContainsEmoji);
|
||||
|
||||
}
|
||||
}
|
||||
package cn.hutool.extra.emoji;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class EmojiUtilTest {
|
||||
|
||||
@Test
|
||||
public void toUnicodeTest() {
|
||||
String emoji = EmojiUtil.toUnicode(":smile:");
|
||||
Assert.assertEquals("😄", emoji);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toAliasTest() {
|
||||
String alias = EmojiUtil.toAlias("😄");
|
||||
Assert.assertEquals(":smile:", alias);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void containsEmojiTest() {
|
||||
boolean containsEmoji = EmojiUtil.containsEmoji("测试一下是否包含EMOJ:😄");
|
||||
Assert.assertTrue(containsEmoji);
|
||||
boolean notContainsEmoji = EmojiUtil.containsEmoji("不包含EMOJ:^_^");
|
||||
Assert.assertFalse(notContainsEmoji);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,63 +1,63 @@
|
||||
package cn.hutool.extra.expression;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import cn.hutool.extra.expression.engine.aviator.AviatorEngine;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Aviator引擎单元测试,来自https://github.com/looly/hutool/pull/1203
|
||||
*/
|
||||
public class AviatorTest {
|
||||
|
||||
@Test
|
||||
public void simpleTest(){
|
||||
Foo foo = new Foo(100, 3.14f, DateUtil.parseDate("2020-11-12"));
|
||||
ExpressionEngine engine = new AviatorEngine();
|
||||
String exp =
|
||||
"\"[foo i=\"+ foo.i + \", f=\" + foo.f + \", date.year=\" + (foo.date.year+1900) + \", date.month=\" + foo.date.month + \", bars[0].name=\" + #foo.bars[0].name + \"]\"";
|
||||
String result = (String) engine.eval(exp, Dict.create().set("foo", foo));
|
||||
Assert.assertEquals("[foo i=100, f=3.14, date.year=2020, date.month=10, bars[0].name=bar]", result);
|
||||
|
||||
// Assignment.
|
||||
exp = "#foo.bars[0].name='hello aviator' ; #foo.bars[0].name";
|
||||
result = (String) engine.eval(exp, Dict.create().set("foo", foo));
|
||||
Assert.assertEquals("hello aviator", result);
|
||||
Assert.assertEquals("hello aviator", foo.bars[0].getName());
|
||||
|
||||
exp = "foo.bars[0] = nil ; foo.bars[0]";
|
||||
result = (String) engine.eval(exp, Dict.create().set("foo", foo));
|
||||
Console.log("Execute expression: " + exp);
|
||||
Assert.assertNull(result);
|
||||
Assert.assertNull(foo.bars[0]);
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Bar {
|
||||
public Bar() {
|
||||
this.name = "bar";
|
||||
}
|
||||
private String name;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Foo {
|
||||
int i;
|
||||
float f;
|
||||
Date date;
|
||||
Bar[] bars = new Bar[1];
|
||||
|
||||
public Foo(final int i, final float f, final Date date) {
|
||||
super();
|
||||
this.i = i;
|
||||
this.f = f;
|
||||
this.date = date;
|
||||
this.bars[0] = new Bar();
|
||||
}
|
||||
}
|
||||
}
|
||||
package cn.hutool.extra.expression;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import cn.hutool.extra.expression.engine.aviator.AviatorEngine;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Aviator引擎单元测试,来自https://github.com/looly/hutool/pull/1203
|
||||
*/
|
||||
public class AviatorTest {
|
||||
|
||||
@Test
|
||||
public void simpleTest(){
|
||||
Foo foo = new Foo(100, 3.14f, DateUtil.parseDate("2020-11-12"));
|
||||
ExpressionEngine engine = new AviatorEngine();
|
||||
String exp =
|
||||
"\"[foo i=\"+ foo.i + \", f=\" + foo.f + \", date.year=\" + (foo.date.year+1900) + \", date.month=\" + foo.date.month + \", bars[0].name=\" + #foo.bars[0].name + \"]\"";
|
||||
String result = (String) engine.eval(exp, Dict.create().set("foo", foo));
|
||||
Assert.assertEquals("[foo i=100, f=3.14, date.year=2020, date.month=10, bars[0].name=bar]", result);
|
||||
|
||||
// Assignment.
|
||||
exp = "#foo.bars[0].name='hello aviator' ; #foo.bars[0].name";
|
||||
result = (String) engine.eval(exp, Dict.create().set("foo", foo));
|
||||
Assert.assertEquals("hello aviator", result);
|
||||
Assert.assertEquals("hello aviator", foo.bars[0].getName());
|
||||
|
||||
exp = "foo.bars[0] = nil ; foo.bars[0]";
|
||||
result = (String) engine.eval(exp, Dict.create().set("foo", foo));
|
||||
Console.log("Execute expression: " + exp);
|
||||
Assert.assertNull(result);
|
||||
Assert.assertNull(foo.bars[0]);
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Bar {
|
||||
public Bar() {
|
||||
this.name = "bar";
|
||||
}
|
||||
private String name;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Foo {
|
||||
int i;
|
||||
float f;
|
||||
Date date;
|
||||
Bar[] bars = new Bar[1];
|
||||
|
||||
public Foo(final int i, final float f, final Date date) {
|
||||
super();
|
||||
this.i = i;
|
||||
this.f = f;
|
||||
this.date = date;
|
||||
this.bars[0] = new Bar();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,84 +1,84 @@
|
||||
package cn.hutool.extra.expression;
|
||||
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import cn.hutool.extra.expression.engine.jexl.JexlEngine;
|
||||
import cn.hutool.extra.expression.engine.jfireel.JfireELEngine;
|
||||
import cn.hutool.extra.expression.engine.mvel.MvelEngine;
|
||||
import cn.hutool.extra.expression.engine.rhino.RhinoEngine;
|
||||
import cn.hutool.extra.expression.engine.spel.SpELEngine;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ExpressionUtilTest {
|
||||
|
||||
@Test
|
||||
public void evalTest(){
|
||||
final Dict dict = Dict.create()
|
||||
.set("a", 100.3)
|
||||
.set("b", 45)
|
||||
.set("c", -199.100);
|
||||
final Object eval = ExpressionUtil.eval("a-(b-c)", dict);
|
||||
Assert.assertEquals(-143.8, (double)eval, 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jexlTest(){
|
||||
ExpressionEngine engine = new JexlEngine();
|
||||
|
||||
final Dict dict = Dict.create()
|
||||
.set("a", 100.3)
|
||||
.set("b", 45)
|
||||
.set("c", -199.100);
|
||||
final Object eval = engine.eval("a-(b-c)", dict);
|
||||
Assert.assertEquals(-143.8, (double)eval, 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mvelTest(){
|
||||
ExpressionEngine engine = new MvelEngine();
|
||||
|
||||
final Dict dict = Dict.create()
|
||||
.set("a", 100.3)
|
||||
.set("b", 45)
|
||||
.set("c", -199.100);
|
||||
final Object eval = engine.eval("a-(b-c)", dict);
|
||||
Assert.assertEquals(-143.8, (double)eval, 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jfireELTest(){
|
||||
ExpressionEngine engine = new JfireELEngine();
|
||||
|
||||
final Dict dict = Dict.create()
|
||||
.set("a", 100.3)
|
||||
.set("b", 45)
|
||||
.set("c", -199.100);
|
||||
final Object eval = engine.eval("a-(b-c)", dict);
|
||||
Assert.assertEquals(-143.8, (double)eval, 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spELTest(){
|
||||
ExpressionEngine engine = new SpELEngine();
|
||||
|
||||
final Dict dict = Dict.create()
|
||||
.set("a", 100.3)
|
||||
.set("b", 45)
|
||||
.set("c", -199.100);
|
||||
final Object eval = engine.eval("#a-(#b-#c)", dict);
|
||||
Assert.assertEquals(-143.8, (double)eval, 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rhinoTest(){
|
||||
ExpressionEngine engine = new RhinoEngine();
|
||||
|
||||
final Dict dict = Dict.create()
|
||||
.set("a", 100.3)
|
||||
.set("b", 45)
|
||||
.set("c", -199.100);
|
||||
final Object eval = engine.eval("a-(b-c)", dict);
|
||||
Assert.assertEquals(-143.8, (double)eval, 2);
|
||||
}
|
||||
|
||||
}
|
||||
package cn.hutool.extra.expression;
|
||||
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import cn.hutool.extra.expression.engine.jexl.JexlEngine;
|
||||
import cn.hutool.extra.expression.engine.jfireel.JfireELEngine;
|
||||
import cn.hutool.extra.expression.engine.mvel.MvelEngine;
|
||||
import cn.hutool.extra.expression.engine.rhino.RhinoEngine;
|
||||
import cn.hutool.extra.expression.engine.spel.SpELEngine;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ExpressionUtilTest {
|
||||
|
||||
@Test
|
||||
public void evalTest(){
|
||||
final Dict dict = Dict.create()
|
||||
.set("a", 100.3)
|
||||
.set("b", 45)
|
||||
.set("c", -199.100);
|
||||
final Object eval = ExpressionUtil.eval("a-(b-c)", dict);
|
||||
Assert.assertEquals(-143.8, (double)eval, 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jexlTest(){
|
||||
ExpressionEngine engine = new JexlEngine();
|
||||
|
||||
final Dict dict = Dict.create()
|
||||
.set("a", 100.3)
|
||||
.set("b", 45)
|
||||
.set("c", -199.100);
|
||||
final Object eval = engine.eval("a-(b-c)", dict);
|
||||
Assert.assertEquals(-143.8, (double)eval, 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mvelTest(){
|
||||
ExpressionEngine engine = new MvelEngine();
|
||||
|
||||
final Dict dict = Dict.create()
|
||||
.set("a", 100.3)
|
||||
.set("b", 45)
|
||||
.set("c", -199.100);
|
||||
final Object eval = engine.eval("a-(b-c)", dict);
|
||||
Assert.assertEquals(-143.8, (double)eval, 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jfireELTest(){
|
||||
ExpressionEngine engine = new JfireELEngine();
|
||||
|
||||
final Dict dict = Dict.create()
|
||||
.set("a", 100.3)
|
||||
.set("b", 45)
|
||||
.set("c", -199.100);
|
||||
final Object eval = engine.eval("a-(b-c)", dict);
|
||||
Assert.assertEquals(-143.8, (double)eval, 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spELTest(){
|
||||
ExpressionEngine engine = new SpELEngine();
|
||||
|
||||
final Dict dict = Dict.create()
|
||||
.set("a", 100.3)
|
||||
.set("b", 45)
|
||||
.set("c", -199.100);
|
||||
final Object eval = engine.eval("#a-(#b-#c)", dict);
|
||||
Assert.assertEquals(-143.8, (double)eval, 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rhinoTest(){
|
||||
ExpressionEngine engine = new RhinoEngine();
|
||||
|
||||
final Dict dict = Dict.create()
|
||||
.set("a", 100.3)
|
||||
.set("b", 45)
|
||||
.set("c", -199.100);
|
||||
final Object eval = engine.eval("a-(b-c)", dict);
|
||||
Assert.assertEquals(-143.8, (double)eval, 2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,83 +1,83 @@
|
||||
package cn.hutool.extra.ftp;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.extra.ssh.Sftp;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FtpTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void cdTest() {
|
||||
Ftp ftp = new Ftp("looly.centos");
|
||||
|
||||
ftp.cd("/file/aaa");
|
||||
Console.log(ftp.pwd());
|
||||
|
||||
IoUtil.close(ftp);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void uploadTest() {
|
||||
Ftp ftp = new Ftp("looly.centos");
|
||||
|
||||
List<String> ls = ftp.ls("/file");
|
||||
Console.log(ls);
|
||||
|
||||
boolean upload = ftp.upload("/file/aaa", FileUtil.file("E:/qrcodeWithLogo.jpg"));
|
||||
Console.log(upload);
|
||||
|
||||
IoUtil.close(ftp);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void reconnectIfTimeoutTest() throws InterruptedException {
|
||||
Ftp ftp = new Ftp("looly.centos");
|
||||
|
||||
Console.log("打印pwd: " + ftp.pwd());
|
||||
|
||||
Console.log("休眠一段时间,然后再次发送pwd命令,抛出异常表明连接超时");
|
||||
Thread.sleep(35 * 1000);
|
||||
|
||||
try{
|
||||
Console.log("打印pwd: " + ftp.pwd());
|
||||
}catch (FtpException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Console.log("判断是否超时并重连...");
|
||||
ftp.reconnectIfTimeout();
|
||||
|
||||
Console.log("打印pwd: " + ftp.pwd());
|
||||
|
||||
IoUtil.close(ftp);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void recursiveDownloadFolder() {
|
||||
Ftp ftp = new Ftp("looly.centos");
|
||||
ftp.recursiveDownloadFolder("/",FileUtil.file("d:/test/download"));
|
||||
|
||||
IoUtil.close(ftp);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void recursiveDownloadFolderSftp() {
|
||||
Sftp ftp = new Sftp("127.0.0.1", 22, "test", "test");
|
||||
|
||||
ftp.cd("/file/aaa");
|
||||
Console.log(ftp.pwd());
|
||||
ftp.recursiveDownloadFolder("/",FileUtil.file("d:/test/download"));
|
||||
|
||||
IoUtil.close(ftp);
|
||||
}
|
||||
}
|
||||
package cn.hutool.extra.ftp;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.extra.ssh.Sftp;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FtpTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void cdTest() {
|
||||
Ftp ftp = new Ftp("looly.centos");
|
||||
|
||||
ftp.cd("/file/aaa");
|
||||
Console.log(ftp.pwd());
|
||||
|
||||
IoUtil.close(ftp);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void uploadTest() {
|
||||
Ftp ftp = new Ftp("looly.centos");
|
||||
|
||||
List<String> ls = ftp.ls("/file");
|
||||
Console.log(ls);
|
||||
|
||||
boolean upload = ftp.upload("/file/aaa", FileUtil.file("E:/qrcodeWithLogo.jpg"));
|
||||
Console.log(upload);
|
||||
|
||||
IoUtil.close(ftp);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void reconnectIfTimeoutTest() throws InterruptedException {
|
||||
Ftp ftp = new Ftp("looly.centos");
|
||||
|
||||
Console.log("打印pwd: " + ftp.pwd());
|
||||
|
||||
Console.log("休眠一段时间,然后再次发送pwd命令,抛出异常表明连接超时");
|
||||
Thread.sleep(35 * 1000);
|
||||
|
||||
try{
|
||||
Console.log("打印pwd: " + ftp.pwd());
|
||||
}catch (FtpException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Console.log("判断是否超时并重连...");
|
||||
ftp.reconnectIfTimeout();
|
||||
|
||||
Console.log("打印pwd: " + ftp.pwd());
|
||||
|
||||
IoUtil.close(ftp);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void recursiveDownloadFolder() {
|
||||
Ftp ftp = new Ftp("looly.centos");
|
||||
ftp.recursiveDownloadFolder("/",FileUtil.file("d:/test/download"));
|
||||
|
||||
IoUtil.close(ftp);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void recursiveDownloadFolderSftp() {
|
||||
Sftp ftp = new Sftp("127.0.0.1", 22, "test", "test");
|
||||
|
||||
ftp.cd("/file/aaa");
|
||||
Console.log(ftp.pwd());
|
||||
ftp.recursiveDownloadFolder("/",FileUtil.file("d:/test/download"));
|
||||
|
||||
IoUtil.close(ftp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package cn.hutool.extra.ftp;
|
||||
|
||||
public class SimpleFtpServerTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SimpleFtpServer
|
||||
.create()
|
||||
.addAnonymous("d:/test/ftp/")
|
||||
.start();
|
||||
}
|
||||
}
|
||||
package cn.hutool.extra.ftp;
|
||||
|
||||
public class SimpleFtpServerTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SimpleFtpServer
|
||||
.create()
|
||||
.addAnonymous("d:/test/ftp/")
|
||||
.start();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
package cn.hutool.extra.mail;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* 默认邮件帐户设置测试
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
public class MailAccountTest {
|
||||
|
||||
@Test
|
||||
public void parseSettingTest() {
|
||||
MailAccount account = GlobalMailAccount.INSTANCE.getAccount();
|
||||
account.getSmtpProps();
|
||||
|
||||
Assert.assertNotNull(account.getCharset());
|
||||
Assert.assertTrue(account.isSslEnable());
|
||||
}
|
||||
}
|
||||
package cn.hutool.extra.mail;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* 默认邮件帐户设置测试
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
public class MailAccountTest {
|
||||
|
||||
@Test
|
||||
public void parseSettingTest() {
|
||||
MailAccount account = GlobalMailAccount.INSTANCE.getAccount();
|
||||
account.getSmtpProps();
|
||||
|
||||
Assert.assertNotNull(account.getCharset());
|
||||
Assert.assertTrue(account.isSslEnable());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,70 +1,70 @@
|
||||
package cn.hutool.extra.mail;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
|
||||
/**
|
||||
* 邮件发送测试
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
public class MailTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void sendWithFileTest() {
|
||||
MailUtil.send("hutool@foxmail.com", "测试", "<h1>邮件来自Hutool测试</h1>", true, FileUtil.file("d:/测试附件文本.txt"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void sendWithLongNameFileTest() {
|
||||
//附件名长度大于60时的测试
|
||||
MailUtil.send("hutool@foxmail.com", "测试", "<h1>邮件来自Hutool测试</h1>", true, FileUtil.file("d:/6-LongLong一阶段平台建设周报2018.3.12-3.16.xlsx"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void sendWithImageTest() {
|
||||
Map<String, InputStream> map = new HashMap<>();
|
||||
map.put("testImage", FileUtil.getInputStream("f:/test/me.png"));
|
||||
MailUtil.sendHtml("hutool@foxmail.com", "测试", "<h1>邮件来自Hutool测试</h1><img src=\"cid:testImage\" />", map);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void sendHtmlTest() {
|
||||
MailUtil.send("hutool@foxmail.com", "测试", "<h1>邮件来自Hutool测试</h1>", true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void sendByAccountTest() {
|
||||
MailAccount account = new MailAccount();
|
||||
account.setHost("smtp.yeah.net");
|
||||
account.setPort(465);
|
||||
account.setSslEnable(true);
|
||||
account.setFrom("hutool@yeah.net");
|
||||
account.setUser("hutool");
|
||||
account.setPass("q1w2e3");
|
||||
MailUtil.send(account, "914104645@qq.com", "测试", "<h1>邮件来自Hutool测试</h1>", true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mailAccountTest() {
|
||||
MailAccount account = new MailAccount();
|
||||
account.setFrom("hutool@yeah.net");
|
||||
account.setDebug(true);
|
||||
account.defaultIfEmpty();
|
||||
Properties props = account.getSmtpProps();
|
||||
Assert.assertEquals("true", props.getProperty("mail.debug"));
|
||||
}
|
||||
}
|
||||
package cn.hutool.extra.mail;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
|
||||
/**
|
||||
* 邮件发送测试
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
public class MailTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void sendWithFileTest() {
|
||||
MailUtil.send("hutool@foxmail.com", "测试", "<h1>邮件来自Hutool测试</h1>", true, FileUtil.file("d:/测试附件文本.txt"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void sendWithLongNameFileTest() {
|
||||
//附件名长度大于60时的测试
|
||||
MailUtil.send("hutool@foxmail.com", "测试", "<h1>邮件来自Hutool测试</h1>", true, FileUtil.file("d:/6-LongLong一阶段平台建设周报2018.3.12-3.16.xlsx"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void sendWithImageTest() {
|
||||
Map<String, InputStream> map = new HashMap<>();
|
||||
map.put("testImage", FileUtil.getInputStream("f:/test/me.png"));
|
||||
MailUtil.sendHtml("hutool@foxmail.com", "测试", "<h1>邮件来自Hutool测试</h1><img src=\"cid:testImage\" />", map);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void sendHtmlTest() {
|
||||
MailUtil.send("hutool@foxmail.com", "测试", "<h1>邮件来自Hutool测试</h1>", true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void sendByAccountTest() {
|
||||
MailAccount account = new MailAccount();
|
||||
account.setHost("smtp.yeah.net");
|
||||
account.setPort(465);
|
||||
account.setSslEnable(true);
|
||||
account.setFrom("hutool@yeah.net");
|
||||
account.setUser("hutool");
|
||||
account.setPass("q1w2e3");
|
||||
MailUtil.send(account, "914104645@qq.com", "测试", "<h1>邮件来自Hutool测试</h1>", true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mailAccountTest() {
|
||||
MailAccount account = new MailAccount();
|
||||
account.setFrom("hutool@yeah.net");
|
||||
account.setDebug(true);
|
||||
account.defaultIfEmpty();
|
||||
Properties props = account.getSmtpProps();
|
||||
Assert.assertEquals("true", props.getProperty("mail.debug"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,55 +1,55 @@
|
||||
package cn.hutool.extra.pinyin;
|
||||
|
||||
import cn.hutool.extra.pinyin.engine.bopomofo4j.Bopomofo4jEngine;
|
||||
import cn.hutool.extra.pinyin.engine.pinyin4j.Pinyin4jEngine;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class PinyinUtilTest {
|
||||
|
||||
@Test
|
||||
public void getPinyinTest(){
|
||||
final String pinyin = PinyinUtil.getPinyin("你好", " ");
|
||||
Assert.assertEquals("ni hao", pinyin);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPinyinByPinyin4jTest() {
|
||||
final Pinyin4jEngine engine = new Pinyin4jEngine();
|
||||
final String pinyin = engine.getPinyin("你好h", " ");
|
||||
Assert.assertEquals("ni hao h", pinyin);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPinyinByBopomofo4jTest() {
|
||||
final Bopomofo4jEngine engine = new Bopomofo4jEngine();
|
||||
final String pinyin = engine.getPinyin("你好h", " ");
|
||||
Assert.assertEquals("ni haoh", pinyin);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPinyinUpperCaseTest(){
|
||||
final String pinyin = PinyinUtil.getPinyin("你好怡", " ");
|
||||
Assert.assertEquals("ni hao yi", pinyin);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFirstLetterTest(){
|
||||
final String result = PinyinUtil.getFirstLetter("H是第一个", ", ");
|
||||
Assert.assertEquals("h, s, d, y, g", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFirstLetterByPinyin4jTest(){
|
||||
final Pinyin4jEngine engine = new Pinyin4jEngine();
|
||||
final String result = engine.getFirstLetter("林海", "");
|
||||
Assert.assertEquals("lh", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFirstLetterByBopomofo4jTest(){
|
||||
final Bopomofo4jEngine engine = new Bopomofo4jEngine();
|
||||
final String result = engine.getFirstLetter("林海", "");
|
||||
Assert.assertEquals("lh", result);
|
||||
}
|
||||
}
|
||||
package cn.hutool.extra.pinyin;
|
||||
|
||||
import cn.hutool.extra.pinyin.engine.bopomofo4j.Bopomofo4jEngine;
|
||||
import cn.hutool.extra.pinyin.engine.pinyin4j.Pinyin4jEngine;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class PinyinUtilTest {
|
||||
|
||||
@Test
|
||||
public void getPinyinTest(){
|
||||
final String pinyin = PinyinUtil.getPinyin("你好", " ");
|
||||
Assert.assertEquals("ni hao", pinyin);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPinyinByPinyin4jTest() {
|
||||
final Pinyin4jEngine engine = new Pinyin4jEngine();
|
||||
final String pinyin = engine.getPinyin("你好h", " ");
|
||||
Assert.assertEquals("ni hao h", pinyin);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPinyinByBopomofo4jTest() {
|
||||
final Bopomofo4jEngine engine = new Bopomofo4jEngine();
|
||||
final String pinyin = engine.getPinyin("你好h", " ");
|
||||
Assert.assertEquals("ni haoh", pinyin);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPinyinUpperCaseTest(){
|
||||
final String pinyin = PinyinUtil.getPinyin("你好怡", " ");
|
||||
Assert.assertEquals("ni hao yi", pinyin);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFirstLetterTest(){
|
||||
final String result = PinyinUtil.getFirstLetter("H是第一个", ", ");
|
||||
Assert.assertEquals("h, s, d, y, g", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFirstLetterByPinyin4jTest(){
|
||||
final Pinyin4jEngine engine = new Pinyin4jEngine();
|
||||
final String result = engine.getFirstLetter("林海", "");
|
||||
Assert.assertEquals("lh", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFirstLetterByBopomofo4jTest(){
|
||||
final Bopomofo4jEngine engine = new Bopomofo4jEngine();
|
||||
final String result = engine.getFirstLetter("林海", "");
|
||||
Assert.assertEquals("lh", result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,71 +1,71 @@
|
||||
package cn.hutool.extra.qrcode;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* 二维码工具类单元测试
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
public class QrCodeUtilTest {
|
||||
|
||||
@Test
|
||||
public void generateTest() {
|
||||
final BufferedImage image = QrCodeUtil.generate("https://hutool.cn/", 300, 300);
|
||||
Assert.assertNotNull(image);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void generateCustomTest() {
|
||||
QrConfig config = new QrConfig();
|
||||
config.setMargin(0);
|
||||
config.setForeColor(Color.CYAN);
|
||||
// 背景色透明
|
||||
config.setBackColor(null);
|
||||
config.setErrorCorrection(ErrorCorrectionLevel.H);
|
||||
QrCodeUtil.generate("https://hutool.cn/", config, FileUtil.file("d:/qrcodeCustom.png"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void generateWithLogoTest() {
|
||||
QrCodeUtil.generate(//
|
||||
"http://hutool.cn/", //
|
||||
QrConfig.create().setImg("e:/pic/face.jpg"), //
|
||||
FileUtil.file("e:/qrcodeWithLogo.jpg"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void decodeTest() {
|
||||
String decode = QrCodeUtil.decode(FileUtil.file("e:/pic/qr.png"));
|
||||
Console.log(decode);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void generateAsBase64Test(){
|
||||
String base64 = QrCodeUtil.generateAsBase64("http://hutool.cn/", new QrConfig(400, 400), "png");
|
||||
System.out.println(base64);
|
||||
|
||||
byte[] bytes = FileUtil.readBytes(
|
||||
new File("d:/test/qr.png"));
|
||||
String encode = Base64.encode(bytes);
|
||||
String base641 = QrCodeUtil.generateAsBase64("http://hutool.cn/", new QrConfig(400, 400), "png", encode);
|
||||
System.out.println(base641);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
package cn.hutool.extra.qrcode;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* 二维码工具类单元测试
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
public class QrCodeUtilTest {
|
||||
|
||||
@Test
|
||||
public void generateTest() {
|
||||
final BufferedImage image = QrCodeUtil.generate("https://hutool.cn/", 300, 300);
|
||||
Assert.assertNotNull(image);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void generateCustomTest() {
|
||||
QrConfig config = new QrConfig();
|
||||
config.setMargin(0);
|
||||
config.setForeColor(Color.CYAN);
|
||||
// 背景色透明
|
||||
config.setBackColor(null);
|
||||
config.setErrorCorrection(ErrorCorrectionLevel.H);
|
||||
QrCodeUtil.generate("https://hutool.cn/", config, FileUtil.file("d:/qrcodeCustom.png"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void generateWithLogoTest() {
|
||||
QrCodeUtil.generate(//
|
||||
"http://hutool.cn/", //
|
||||
QrConfig.create().setImg("e:/pic/face.jpg"), //
|
||||
FileUtil.file("e:/qrcodeWithLogo.jpg"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void decodeTest() {
|
||||
String decode = QrCodeUtil.decode(FileUtil.file("e:/pic/qr.png"));
|
||||
Console.log(decode);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void generateAsBase64Test(){
|
||||
String base64 = QrCodeUtil.generateAsBase64("http://hutool.cn/", new QrConfig(400, 400), "png");
|
||||
System.out.println(base64);
|
||||
|
||||
byte[] bytes = FileUtil.readBytes(
|
||||
new File("d:/test/qr.png"));
|
||||
String encode = Base64.encode(bytes);
|
||||
String base641 = QrCodeUtil.generateAsBase64("http://hutool.cn/", new QrConfig(400, 400), "png", encode);
|
||||
System.out.println(base641);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,72 +1,72 @@
|
||||
package cn.hutool.extra.spring;
|
||||
|
||||
import cn.hutool.core.lang.TypeReference;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = {SpringUtil.class, SpringUtilTest.Demo2.class})
|
||||
//@Import(cn.hutool.extra.spring.SpringUtil.class)
|
||||
public class SpringUtilTest {
|
||||
|
||||
/**
|
||||
* 注册验证bean
|
||||
*/
|
||||
@Test
|
||||
public void registerBeanTest() {
|
||||
Demo2 registerBean = new Demo2();
|
||||
registerBean.setId(123);
|
||||
registerBean.setName("222");
|
||||
SpringUtil.registerBean("registerBean", registerBean);
|
||||
|
||||
Demo2 registerBean2 = SpringUtil.getBean("registerBean");
|
||||
Assert.assertEquals(123, registerBean2.getId());
|
||||
Assert.assertEquals("222", registerBean2.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanTest(){
|
||||
final Demo2 testDemo = SpringUtil.getBean("testDemo");
|
||||
Assert.assertEquals(12345, testDemo.getId());
|
||||
Assert.assertEquals("test", testDemo.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanWithTypeReferenceTest() {
|
||||
Map<String, Object> mapBean = SpringUtil.getBean(new TypeReference<Map<String, Object>>() {});
|
||||
Assert.assertNotNull(mapBean);
|
||||
Assert.assertEquals("value1", mapBean.get("key1"));
|
||||
Assert.assertEquals("value2", mapBean.get("key2"));
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Demo2{
|
||||
private long id;
|
||||
private String name;
|
||||
|
||||
@Bean(name="testDemo")
|
||||
public Demo2 generateDemo() {
|
||||
Demo2 demo = new Demo2();
|
||||
demo.setId(12345);
|
||||
demo.setName("test");
|
||||
return demo;
|
||||
}
|
||||
|
||||
@Bean(name="mapDemo")
|
||||
public Map<String, Object> generateMap() {
|
||||
HashMap<String, Object> map = MapUtil.newHashMap();
|
||||
map.put("key1", "value1");
|
||||
map.put("key2", "value2");
|
||||
return map;
|
||||
}
|
||||
}
|
||||
}
|
||||
package cn.hutool.extra.spring;
|
||||
|
||||
import cn.hutool.core.lang.TypeReference;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = {SpringUtil.class, SpringUtilTest.Demo2.class})
|
||||
//@Import(cn.hutool.extra.spring.SpringUtil.class)
|
||||
public class SpringUtilTest {
|
||||
|
||||
/**
|
||||
* 注册验证bean
|
||||
*/
|
||||
@Test
|
||||
public void registerBeanTest() {
|
||||
Demo2 registerBean = new Demo2();
|
||||
registerBean.setId(123);
|
||||
registerBean.setName("222");
|
||||
SpringUtil.registerBean("registerBean", registerBean);
|
||||
|
||||
Demo2 registerBean2 = SpringUtil.getBean("registerBean");
|
||||
Assert.assertEquals(123, registerBean2.getId());
|
||||
Assert.assertEquals("222", registerBean2.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanTest(){
|
||||
final Demo2 testDemo = SpringUtil.getBean("testDemo");
|
||||
Assert.assertEquals(12345, testDemo.getId());
|
||||
Assert.assertEquals("test", testDemo.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanWithTypeReferenceTest() {
|
||||
Map<String, Object> mapBean = SpringUtil.getBean(new TypeReference<Map<String, Object>>() {});
|
||||
Assert.assertNotNull(mapBean);
|
||||
Assert.assertEquals("value1", mapBean.get("key1"));
|
||||
Assert.assertEquals("value2", mapBean.get("key2"));
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Demo2{
|
||||
private long id;
|
||||
private String name;
|
||||
|
||||
@Bean(name="testDemo")
|
||||
public Demo2 generateDemo() {
|
||||
Demo2 demo = new Demo2();
|
||||
demo.setId(12345);
|
||||
demo.setName("test");
|
||||
return demo;
|
||||
}
|
||||
|
||||
@Bean(name="mapDemo")
|
||||
public Map<String, Object> generateMap() {
|
||||
HashMap<String, Object> map = MapUtil.newHashMap();
|
||||
map.put("key1", "value1");
|
||||
map.put("key2", "value2");
|
||||
return map;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,74 +1,74 @@
|
||||
package cn.hutool.extra.spring;
|
||||
|
||||
import cn.hutool.core.lang.TypeReference;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = {SpringUtilWithAutoConfigTest.Demo2.class})
|
||||
//@Import(cn.hutool.extra.spring.SpringUtil.class)
|
||||
@EnableAutoConfiguration
|
||||
public class SpringUtilWithAutoConfigTest {
|
||||
|
||||
/**
|
||||
* 注册验证bean
|
||||
*/
|
||||
@Test
|
||||
public void registerBeanTest() {
|
||||
Demo2 registerBean = new Demo2();
|
||||
registerBean.setId(123);
|
||||
registerBean.setName("222");
|
||||
SpringUtil.registerBean("registerBean", registerBean);
|
||||
|
||||
Demo2 registerBean2 = SpringUtil.getBean("registerBean");
|
||||
Assert.assertEquals(123, registerBean2.getId());
|
||||
Assert.assertEquals("222", registerBean2.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanTest(){
|
||||
final Demo2 testDemo = SpringUtil.getBean("testDemo");
|
||||
Assert.assertEquals(12345, testDemo.getId());
|
||||
Assert.assertEquals("test", testDemo.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanWithTypeReferenceTest() {
|
||||
Map<String, Object> mapBean = SpringUtil.getBean(new TypeReference<Map<String, Object>>() {});
|
||||
Assert.assertNotNull(mapBean);
|
||||
Assert.assertEquals("value1", mapBean.get("key1"));
|
||||
Assert.assertEquals("value2", mapBean.get("key2"));
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Demo2{
|
||||
private long id;
|
||||
private String name;
|
||||
|
||||
@Bean(name="testDemo")
|
||||
public Demo2 generateDemo() {
|
||||
Demo2 demo = new Demo2();
|
||||
demo.setId(12345);
|
||||
demo.setName("test");
|
||||
return demo;
|
||||
}
|
||||
|
||||
@Bean(name="mapDemo")
|
||||
public Map<String, Object> generateMap() {
|
||||
HashMap<String, Object> map = MapUtil.newHashMap();
|
||||
map.put("key1", "value1");
|
||||
map.put("key2", "value2");
|
||||
return map;
|
||||
}
|
||||
}
|
||||
}
|
||||
package cn.hutool.extra.spring;
|
||||
|
||||
import cn.hutool.core.lang.TypeReference;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = {SpringUtilWithAutoConfigTest.Demo2.class})
|
||||
//@Import(cn.hutool.extra.spring.SpringUtil.class)
|
||||
@EnableAutoConfiguration
|
||||
public class SpringUtilWithAutoConfigTest {
|
||||
|
||||
/**
|
||||
* 注册验证bean
|
||||
*/
|
||||
@Test
|
||||
public void registerBeanTest() {
|
||||
Demo2 registerBean = new Demo2();
|
||||
registerBean.setId(123);
|
||||
registerBean.setName("222");
|
||||
SpringUtil.registerBean("registerBean", registerBean);
|
||||
|
||||
Demo2 registerBean2 = SpringUtil.getBean("registerBean");
|
||||
Assert.assertEquals(123, registerBean2.getId());
|
||||
Assert.assertEquals("222", registerBean2.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanTest(){
|
||||
final Demo2 testDemo = SpringUtil.getBean("testDemo");
|
||||
Assert.assertEquals(12345, testDemo.getId());
|
||||
Assert.assertEquals("test", testDemo.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanWithTypeReferenceTest() {
|
||||
Map<String, Object> mapBean = SpringUtil.getBean(new TypeReference<Map<String, Object>>() {});
|
||||
Assert.assertNotNull(mapBean);
|
||||
Assert.assertEquals("value1", mapBean.get("key1"));
|
||||
Assert.assertEquals("value2", mapBean.get("key2"));
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Demo2{
|
||||
private long id;
|
||||
private String name;
|
||||
|
||||
@Bean(name="testDemo")
|
||||
public Demo2 generateDemo() {
|
||||
Demo2 demo = new Demo2();
|
||||
demo.setId(12345);
|
||||
demo.setName("test");
|
||||
return demo;
|
||||
}
|
||||
|
||||
@Bean(name="mapDemo")
|
||||
public Map<String, Object> generateMap() {
|
||||
HashMap<String, Object> map = MapUtil.newHashMap();
|
||||
map.put("key1", "value1");
|
||||
map.put("key2", "value2");
|
||||
return map;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,84 +1,84 @@
|
||||
package cn.hutool.extra.ssh;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import com.jcraft.jsch.Session;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Jsch工具类单元测试
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
public class JschUtilTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void bindPortTest() {
|
||||
//新建会话,此会话用于ssh连接到跳板机(堡垒机),此处为10.1.1.1:22
|
||||
Session session = JschUtil.getSession("looly.centos", 22, "test", "123456");
|
||||
// 将堡垒机保护的内网8080端口映射到localhost,我们就可以通过访问http://localhost:8080/访问内网服务了
|
||||
JschUtil.bindPort(session, "172.20.12.123", 8080, 8080);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void bindRemotePort() throws InterruptedException {
|
||||
// 建立会话
|
||||
Session session = JschUtil.getSession("looly.centos", 22, "test", "123456");
|
||||
// 绑定ssh服务端8089端口到本机的8000端口上
|
||||
boolean b = JschUtil.bindRemotePort(session, 8089, "localhost", 8000);
|
||||
Assert.assertTrue(b);
|
||||
// 保证一直运行
|
||||
// while (true){
|
||||
// Thread.sleep(3000);
|
||||
// }
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void sftpTest() {
|
||||
Session session = JschUtil.getSession("looly.centos", 22, "root", "123456");
|
||||
Sftp sftp = JschUtil.createSftp(session);
|
||||
sftp.mkDirs("/opt/test/aaa/bbb");
|
||||
Console.log("OK");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void reconnectIfTimeoutTest() throws InterruptedException {
|
||||
Session session = JschUtil.getSession("sunnyserver", 22,"mysftp","liuyang1234");
|
||||
Sftp sftp = JschUtil.createSftp(session);
|
||||
|
||||
Console.log("打印pwd: " + sftp.pwd());
|
||||
Console.log("cd / : " + sftp.cd("/"));
|
||||
Console.log("休眠一段时间,查看是否超时");
|
||||
Thread.sleep(30 * 1000);
|
||||
|
||||
try{
|
||||
// 当连接超时时,isConnected()仍然返回true,pwd命令也能正常返回,因此,利用发送cd命令的返回结果,来判断是否连接超时
|
||||
Console.log("isConnected " + sftp.getClient().isConnected());
|
||||
Console.log("打印pwd: " + sftp.pwd());
|
||||
Console.log("cd / : " + sftp.cd("/"));
|
||||
}catch (JschRuntimeException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Console.log("调用reconnectIfTimeout方法,判断是否超时并重连");
|
||||
sftp.reconnectIfTimeout();
|
||||
|
||||
Console.log("打印pwd: " + sftp.pwd());
|
||||
|
||||
IoUtil.close(sftp);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void getSessionTest(){
|
||||
JschUtil.getSession("192.168.1.134", 22, "root", "aaa", null);
|
||||
}
|
||||
}
|
||||
package cn.hutool.extra.ssh;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import com.jcraft.jsch.Session;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Jsch工具类单元测试
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
public class JschUtilTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void bindPortTest() {
|
||||
//新建会话,此会话用于ssh连接到跳板机(堡垒机),此处为10.1.1.1:22
|
||||
Session session = JschUtil.getSession("looly.centos", 22, "test", "123456");
|
||||
// 将堡垒机保护的内网8080端口映射到localhost,我们就可以通过访问http://localhost:8080/访问内网服务了
|
||||
JschUtil.bindPort(session, "172.20.12.123", 8080, 8080);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void bindRemotePort() throws InterruptedException {
|
||||
// 建立会话
|
||||
Session session = JschUtil.getSession("looly.centos", 22, "test", "123456");
|
||||
// 绑定ssh服务端8089端口到本机的8000端口上
|
||||
boolean b = JschUtil.bindRemotePort(session, 8089, "localhost", 8000);
|
||||
Assert.assertTrue(b);
|
||||
// 保证一直运行
|
||||
// while (true){
|
||||
// Thread.sleep(3000);
|
||||
// }
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void sftpTest() {
|
||||
Session session = JschUtil.getSession("looly.centos", 22, "root", "123456");
|
||||
Sftp sftp = JschUtil.createSftp(session);
|
||||
sftp.mkDirs("/opt/test/aaa/bbb");
|
||||
Console.log("OK");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void reconnectIfTimeoutTest() throws InterruptedException {
|
||||
Session session = JschUtil.getSession("sunnyserver", 22,"mysftp","liuyang1234");
|
||||
Sftp sftp = JschUtil.createSftp(session);
|
||||
|
||||
Console.log("打印pwd: " + sftp.pwd());
|
||||
Console.log("cd / : " + sftp.cd("/"));
|
||||
Console.log("休眠一段时间,查看是否超时");
|
||||
Thread.sleep(30 * 1000);
|
||||
|
||||
try{
|
||||
// 当连接超时时,isConnected()仍然返回true,pwd命令也能正常返回,因此,利用发送cd命令的返回结果,来判断是否连接超时
|
||||
Console.log("isConnected " + sftp.getClient().isConnected());
|
||||
Console.log("打印pwd: " + sftp.pwd());
|
||||
Console.log("cd / : " + sftp.cd("/"));
|
||||
}catch (JschRuntimeException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Console.log("调用reconnectIfTimeout方法,判断是否超时并重连");
|
||||
sftp.reconnectIfTimeout();
|
||||
|
||||
Console.log("打印pwd: " + sftp.pwd());
|
||||
|
||||
IoUtil.close(sftp);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void getSessionTest(){
|
||||
JschUtil.getSession("192.168.1.134", 22, "root", "aaa", null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
package cn.hutool.extra.template;
|
||||
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import cn.hutool.extra.template.engine.beetl.BeetlUtil;
|
||||
import org.beetl.core.Configuration;
|
||||
import org.beetl.core.GroupTemplate;
|
||||
import org.beetl.core.Template;
|
||||
import org.beetl.core.resource.StringTemplateResourceLoader;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* BeetlUtil单元测试
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class BeetlUtilTest {
|
||||
|
||||
@Test
|
||||
public void renderStrTest() throws IOException {
|
||||
GroupTemplate groupTemplate = BeetlUtil.createGroupTemplate(new StringTemplateResourceLoader(), Configuration.defaultConfiguration());
|
||||
Template template = BeetlUtil.getTemplate(groupTemplate, "hello,${name}");
|
||||
String result = BeetlUtil.render(template, Dict.create().set("name", "hutool"));
|
||||
|
||||
Assert.assertEquals("hello,hutool", result);
|
||||
|
||||
String renderFromStr = BeetlUtil.renderFromStr("hello,${name}", Dict.create().set("name", "hutool"));
|
||||
Assert.assertEquals("hello,hutool", renderFromStr);
|
||||
|
||||
}
|
||||
}
|
||||
package cn.hutool.extra.template;
|
||||
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import cn.hutool.extra.template.engine.beetl.BeetlUtil;
|
||||
import org.beetl.core.Configuration;
|
||||
import org.beetl.core.GroupTemplate;
|
||||
import org.beetl.core.Template;
|
||||
import org.beetl.core.resource.StringTemplateResourceLoader;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* BeetlUtil单元测试
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class BeetlUtilTest {
|
||||
|
||||
@Test
|
||||
public void renderStrTest() throws IOException {
|
||||
GroupTemplate groupTemplate = BeetlUtil.createGroupTemplate(new StringTemplateResourceLoader(), Configuration.defaultConfiguration());
|
||||
Template template = BeetlUtil.getTemplate(groupTemplate, "hello,${name}");
|
||||
String result = BeetlUtil.render(template, Dict.create().set("name", "hutool"));
|
||||
|
||||
Assert.assertEquals("hello,hutool", result);
|
||||
|
||||
String renderFromStr = BeetlUtil.renderFromStr("hello,${name}", Dict.create().set("name", "hutool"));
|
||||
Assert.assertEquals("hello,hutool", renderFromStr);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,155 +1,155 @@
|
||||
package cn.hutool.extra.template;
|
||||
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import cn.hutool.extra.template.TemplateConfig.ResourceMode;
|
||||
import cn.hutool.extra.template.engine.beetl.BeetlEngine;
|
||||
import cn.hutool.extra.template.engine.enjoy.EnjoyEngine;
|
||||
import cn.hutool.extra.template.engine.freemarker.FreemarkerEngine;
|
||||
import cn.hutool.extra.template.engine.rythm.RythmEngine;
|
||||
import cn.hutool.extra.template.engine.thymeleaf.ThymeleafEngine;
|
||||
import cn.hutool.extra.template.engine.velocity.VelocityEngine;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 模板引擎单元测试
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
public class TemplateUtilTest {
|
||||
|
||||
@Test
|
||||
public void createEngineTest() {
|
||||
// 字符串模板, 默认模板引擎,此处为Beetl
|
||||
TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig());
|
||||
Template template = engine.getTemplate("hello,${name}");
|
||||
String result = template.render(Dict.create().set("name", "hutool"));
|
||||
Assert.assertEquals("hello,hutool", result);
|
||||
|
||||
// classpath中获取模板
|
||||
engine = TemplateUtil.createEngine(new TemplateConfig("templates", ResourceMode.CLASSPATH));
|
||||
Template template2 = engine.getTemplate("beetl_test.btl");
|
||||
String result2 = template2.render(Dict.create().set("name", "hutool"));
|
||||
Assert.assertEquals("hello,hutool", result2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beetlEngineTest() {
|
||||
// 字符串模板
|
||||
TemplateEngine engine = new BeetlEngine(new TemplateConfig("templates"));
|
||||
Template template = engine.getTemplate("hello,${name}");
|
||||
String result = template.render(Dict.create().set("name", "hutool"));
|
||||
Assert.assertEquals("hello,hutool", result);
|
||||
|
||||
// classpath中获取模板
|
||||
engine = new BeetlEngine(new TemplateConfig("templates", ResourceMode.CLASSPATH));
|
||||
Template template2 = engine.getTemplate("beetl_test.btl");
|
||||
String result2 = template2.render(Dict.create().set("name", "hutool"));
|
||||
Assert.assertEquals("hello,hutool", result2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rythmEngineTest() {
|
||||
// 字符串模板
|
||||
TemplateEngine engine = TemplateUtil.createEngine(
|
||||
new TemplateConfig("templates").setCustomEngine(RythmEngine.class));
|
||||
Template template = engine.getTemplate("hello,@name");
|
||||
String result = template.render(Dict.create().set("name", "hutool"));
|
||||
Assert.assertEquals("hello,hutool", result);
|
||||
|
||||
// classpath中获取模板
|
||||
Template template2 = engine.getTemplate("rythm_test.tmpl");
|
||||
String result2 = template2.render(Dict.create().set("name", "hutool"));
|
||||
Assert.assertEquals("hello,hutool", result2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void freemarkerEngineTest() {
|
||||
// 字符串模板
|
||||
TemplateEngine engine = TemplateUtil.createEngine(
|
||||
new TemplateConfig("templates", ResourceMode.STRING).setCustomEngine(FreemarkerEngine.class));
|
||||
Template template = engine.getTemplate("hello,${name}");
|
||||
String result = template.render(Dict.create().set("name", "hutool"));
|
||||
Assert.assertEquals("hello,hutool", result);
|
||||
|
||||
//ClassPath模板
|
||||
engine = TemplateUtil.createEngine(
|
||||
new TemplateConfig("templates", ResourceMode.CLASSPATH).setCustomEngine(FreemarkerEngine.class));
|
||||
template = engine.getTemplate("freemarker_test.ftl");
|
||||
result = template.render(Dict.create().set("name", "hutool"));
|
||||
Assert.assertEquals("hello,hutool", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void velocityEngineTest() {
|
||||
// 字符串模板
|
||||
TemplateEngine engine = TemplateUtil.createEngine(
|
||||
new TemplateConfig("templates", ResourceMode.STRING).setCustomEngine(VelocityEngine.class));
|
||||
Template template = engine.getTemplate("你好,$name");
|
||||
String result = template.render(Dict.create().set("name", "hutool"));
|
||||
Assert.assertEquals("你好,hutool", result);
|
||||
|
||||
//ClassPath模板
|
||||
engine = TemplateUtil.createEngine(
|
||||
new TemplateConfig("templates", ResourceMode.CLASSPATH).setCustomEngine(VelocityEngine.class));
|
||||
template = engine.getTemplate("velocity_test.vtl");
|
||||
result = template.render(Dict.create().set("name", "hutool"));
|
||||
Assert.assertEquals("你好,hutool", result);
|
||||
|
||||
template = engine.getTemplate("templates/velocity_test.vtl");
|
||||
result = template.render(Dict.create().set("name", "hutool"));
|
||||
Assert.assertEquals("你好,hutool", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enjoyEngineTest() {
|
||||
// 字符串模板
|
||||
TemplateEngine engine = TemplateUtil.createEngine(
|
||||
new TemplateConfig("templates").setCustomEngine(EnjoyEngine.class));
|
||||
Template template = engine.getTemplate("#(x + 123)");
|
||||
String result = template.render(Dict.create().set("x", 1));
|
||||
Assert.assertEquals("124", result);
|
||||
|
||||
//ClassPath模板
|
||||
engine = new EnjoyEngine(
|
||||
new TemplateConfig("templates", ResourceMode.CLASSPATH).setCustomEngine(EnjoyEngine.class));
|
||||
template = engine.getTemplate("enjoy_test.etl");
|
||||
result = template.render(Dict.create().set("x", 1));
|
||||
Assert.assertEquals("124", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void thymeleafEngineTest() {
|
||||
// 字符串模板
|
||||
TemplateEngine engine = TemplateUtil.createEngine(
|
||||
new TemplateConfig("templates").setCustomEngine(ThymeleafEngine.class));
|
||||
Template template = engine.getTemplate("<h3 th:text=\"${message}\"></h3>");
|
||||
String result = template.render(Dict.create().set("message", "Hutool"));
|
||||
Assert.assertEquals("<h3>Hutool</h3>", result);
|
||||
|
||||
//ClassPath模板
|
||||
engine = TemplateUtil.createEngine(
|
||||
new TemplateConfig("templates", ResourceMode.CLASSPATH).setCustomEngine(ThymeleafEngine.class));
|
||||
template = engine.getTemplate("thymeleaf_test.ttl");
|
||||
result = template.render(Dict.create().set("message", "Hutool"));
|
||||
Assert.assertEquals("<h3>Hutool</h3>", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void renderToFileTest() {
|
||||
TemplateEngine engine = new BeetlEngine(new TemplateConfig("templates", ResourceMode.CLASSPATH));
|
||||
Template template = engine.getTemplate("freemarker_test.ftl");
|
||||
|
||||
final Map<String, Object> bindingMap = new HashMap<>();
|
||||
bindingMap.put("name", "aa");
|
||||
File outputFile = new File("e:/test.txt");
|
||||
template.render(bindingMap, outputFile);
|
||||
}
|
||||
}
|
||||
package cn.hutool.extra.template;
|
||||
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import cn.hutool.extra.template.TemplateConfig.ResourceMode;
|
||||
import cn.hutool.extra.template.engine.beetl.BeetlEngine;
|
||||
import cn.hutool.extra.template.engine.enjoy.EnjoyEngine;
|
||||
import cn.hutool.extra.template.engine.freemarker.FreemarkerEngine;
|
||||
import cn.hutool.extra.template.engine.rythm.RythmEngine;
|
||||
import cn.hutool.extra.template.engine.thymeleaf.ThymeleafEngine;
|
||||
import cn.hutool.extra.template.engine.velocity.VelocityEngine;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 模板引擎单元测试
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
public class TemplateUtilTest {
|
||||
|
||||
@Test
|
||||
public void createEngineTest() {
|
||||
// 字符串模板, 默认模板引擎,此处为Beetl
|
||||
TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig());
|
||||
Template template = engine.getTemplate("hello,${name}");
|
||||
String result = template.render(Dict.create().set("name", "hutool"));
|
||||
Assert.assertEquals("hello,hutool", result);
|
||||
|
||||
// classpath中获取模板
|
||||
engine = TemplateUtil.createEngine(new TemplateConfig("templates", ResourceMode.CLASSPATH));
|
||||
Template template2 = engine.getTemplate("beetl_test.btl");
|
||||
String result2 = template2.render(Dict.create().set("name", "hutool"));
|
||||
Assert.assertEquals("hello,hutool", result2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beetlEngineTest() {
|
||||
// 字符串模板
|
||||
TemplateEngine engine = new BeetlEngine(new TemplateConfig("templates"));
|
||||
Template template = engine.getTemplate("hello,${name}");
|
||||
String result = template.render(Dict.create().set("name", "hutool"));
|
||||
Assert.assertEquals("hello,hutool", result);
|
||||
|
||||
// classpath中获取模板
|
||||
engine = new BeetlEngine(new TemplateConfig("templates", ResourceMode.CLASSPATH));
|
||||
Template template2 = engine.getTemplate("beetl_test.btl");
|
||||
String result2 = template2.render(Dict.create().set("name", "hutool"));
|
||||
Assert.assertEquals("hello,hutool", result2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rythmEngineTest() {
|
||||
// 字符串模板
|
||||
TemplateEngine engine = TemplateUtil.createEngine(
|
||||
new TemplateConfig("templates").setCustomEngine(RythmEngine.class));
|
||||
Template template = engine.getTemplate("hello,@name");
|
||||
String result = template.render(Dict.create().set("name", "hutool"));
|
||||
Assert.assertEquals("hello,hutool", result);
|
||||
|
||||
// classpath中获取模板
|
||||
Template template2 = engine.getTemplate("rythm_test.tmpl");
|
||||
String result2 = template2.render(Dict.create().set("name", "hutool"));
|
||||
Assert.assertEquals("hello,hutool", result2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void freemarkerEngineTest() {
|
||||
// 字符串模板
|
||||
TemplateEngine engine = TemplateUtil.createEngine(
|
||||
new TemplateConfig("templates", ResourceMode.STRING).setCustomEngine(FreemarkerEngine.class));
|
||||
Template template = engine.getTemplate("hello,${name}");
|
||||
String result = template.render(Dict.create().set("name", "hutool"));
|
||||
Assert.assertEquals("hello,hutool", result);
|
||||
|
||||
//ClassPath模板
|
||||
engine = TemplateUtil.createEngine(
|
||||
new TemplateConfig("templates", ResourceMode.CLASSPATH).setCustomEngine(FreemarkerEngine.class));
|
||||
template = engine.getTemplate("freemarker_test.ftl");
|
||||
result = template.render(Dict.create().set("name", "hutool"));
|
||||
Assert.assertEquals("hello,hutool", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void velocityEngineTest() {
|
||||
// 字符串模板
|
||||
TemplateEngine engine = TemplateUtil.createEngine(
|
||||
new TemplateConfig("templates", ResourceMode.STRING).setCustomEngine(VelocityEngine.class));
|
||||
Template template = engine.getTemplate("你好,$name");
|
||||
String result = template.render(Dict.create().set("name", "hutool"));
|
||||
Assert.assertEquals("你好,hutool", result);
|
||||
|
||||
//ClassPath模板
|
||||
engine = TemplateUtil.createEngine(
|
||||
new TemplateConfig("templates", ResourceMode.CLASSPATH).setCustomEngine(VelocityEngine.class));
|
||||
template = engine.getTemplate("velocity_test.vtl");
|
||||
result = template.render(Dict.create().set("name", "hutool"));
|
||||
Assert.assertEquals("你好,hutool", result);
|
||||
|
||||
template = engine.getTemplate("templates/velocity_test.vtl");
|
||||
result = template.render(Dict.create().set("name", "hutool"));
|
||||
Assert.assertEquals("你好,hutool", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enjoyEngineTest() {
|
||||
// 字符串模板
|
||||
TemplateEngine engine = TemplateUtil.createEngine(
|
||||
new TemplateConfig("templates").setCustomEngine(EnjoyEngine.class));
|
||||
Template template = engine.getTemplate("#(x + 123)");
|
||||
String result = template.render(Dict.create().set("x", 1));
|
||||
Assert.assertEquals("124", result);
|
||||
|
||||
//ClassPath模板
|
||||
engine = new EnjoyEngine(
|
||||
new TemplateConfig("templates", ResourceMode.CLASSPATH).setCustomEngine(EnjoyEngine.class));
|
||||
template = engine.getTemplate("enjoy_test.etl");
|
||||
result = template.render(Dict.create().set("x", 1));
|
||||
Assert.assertEquals("124", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void thymeleafEngineTest() {
|
||||
// 字符串模板
|
||||
TemplateEngine engine = TemplateUtil.createEngine(
|
||||
new TemplateConfig("templates").setCustomEngine(ThymeleafEngine.class));
|
||||
Template template = engine.getTemplate("<h3 th:text=\"${message}\"></h3>");
|
||||
String result = template.render(Dict.create().set("message", "Hutool"));
|
||||
Assert.assertEquals("<h3>Hutool</h3>", result);
|
||||
|
||||
//ClassPath模板
|
||||
engine = TemplateUtil.createEngine(
|
||||
new TemplateConfig("templates", ResourceMode.CLASSPATH).setCustomEngine(ThymeleafEngine.class));
|
||||
template = engine.getTemplate("thymeleaf_test.ttl");
|
||||
result = template.render(Dict.create().set("message", "Hutool"));
|
||||
Assert.assertEquals("<h3>Hutool</h3>", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void renderToFileTest() {
|
||||
TemplateEngine engine = new BeetlEngine(new TemplateConfig("templates", ResourceMode.CLASSPATH));
|
||||
Template template = engine.getTemplate("freemarker_test.ftl");
|
||||
|
||||
final Map<String, Object> bindingMap = new HashMap<>();
|
||||
bindingMap.put("name", "aa");
|
||||
File outputFile = new File("e:/test.txt");
|
||||
template.render(bindingMap, outputFile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,99 +1,99 @@
|
||||
package cn.hutool.extra.template;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.thymeleaf.context.Context;
|
||||
import org.thymeleaf.templateresolver.StringTemplateResolver;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import cn.hutool.extra.template.engine.thymeleaf.ThymeleafEngine;
|
||||
|
||||
/**
|
||||
* Thymeleaf单元测试
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
public class ThymeleafTest {
|
||||
|
||||
@Test
|
||||
public void thymeleafEngineTest() {
|
||||
Map<String, Object> map1 = new HashMap<>();
|
||||
map1.put("name", "a");
|
||||
|
||||
Map<String, Object> map2 = new HashMap<>();
|
||||
map2.put("name", "b");
|
||||
|
||||
// 日期测试
|
||||
Map<String, Object> map3 = new HashMap<>();
|
||||
map3.put("name", DateUtil.parse("2019-01-01"));
|
||||
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
list.add(map1);
|
||||
list.add(map2);
|
||||
list.add(map3);
|
||||
|
||||
// 字符串模板
|
||||
TemplateEngine engine = new ThymeleafEngine(new TemplateConfig());
|
||||
Template template = engine.getTemplate("<h3 th:each=\"item : ${list}\" th:text=\"${item.name}\"></h3>");
|
||||
String render = template.render(Dict.create().set("list", list));
|
||||
Assert.assertEquals("<h3>a</h3><h3>b</h3><h3>2019-01-01 00:00:00</h3>", render);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void thymeleafEngineTest2() {
|
||||
Map<String, Object> map1 = new HashMap<>();
|
||||
map1.put("name", "a");
|
||||
|
||||
Map<String, Object> map2 = new HashMap<>();
|
||||
map2.put("name", "b");
|
||||
|
||||
// 日期测试
|
||||
Map<String, Object> map3 = new HashMap<>();
|
||||
map3.put("name", DateUtil.parse("2019-01-01"));
|
||||
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
list.add(map1);
|
||||
list.add(map2);
|
||||
list.add(map3);
|
||||
|
||||
LinkedHashMap<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("list", list);
|
||||
|
||||
hutoolApi(map);
|
||||
thymeleaf(map);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
private static void thymeleaf(Map map) {
|
||||
org.thymeleaf.TemplateEngine templateEngine = new org.thymeleaf.TemplateEngine();
|
||||
StringTemplateResolver stringTemplateResolver = new StringTemplateResolver();
|
||||
templateEngine.addTemplateResolver(stringTemplateResolver);
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
Context context = new Context(Locale.getDefault(), map);
|
||||
templateEngine.process("<h3 th:each=\"item : ${list}\" th:text=\"${item.name}\"></h3>", context, writer);
|
||||
|
||||
Assert.assertEquals("<h3>a</h3><h3>b</h3><h3>2019-01-01 00:00:00</h3>", writer.toString());
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static void hutoolApi(Map map) {
|
||||
|
||||
// 字符串模板
|
||||
TemplateEngine engine = new ThymeleafEngine(new TemplateConfig());
|
||||
Template template = engine.getTemplate("<h3 th:each=\"item : ${list}\" th:text=\"${item.name}\"></h3>");
|
||||
// "<h3 th:text=\"${nestMap.nestKey}\"></h3>"
|
||||
String render = template.render(map);
|
||||
Assert.assertEquals("<h3>a</h3><h3>b</h3><h3>2019-01-01 00:00:00</h3>", render);
|
||||
}
|
||||
}
|
||||
package cn.hutool.extra.template;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.thymeleaf.context.Context;
|
||||
import org.thymeleaf.templateresolver.StringTemplateResolver;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import cn.hutool.extra.template.engine.thymeleaf.ThymeleafEngine;
|
||||
|
||||
/**
|
||||
* Thymeleaf单元测试
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
public class ThymeleafTest {
|
||||
|
||||
@Test
|
||||
public void thymeleafEngineTest() {
|
||||
Map<String, Object> map1 = new HashMap<>();
|
||||
map1.put("name", "a");
|
||||
|
||||
Map<String, Object> map2 = new HashMap<>();
|
||||
map2.put("name", "b");
|
||||
|
||||
// 日期测试
|
||||
Map<String, Object> map3 = new HashMap<>();
|
||||
map3.put("name", DateUtil.parse("2019-01-01"));
|
||||
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
list.add(map1);
|
||||
list.add(map2);
|
||||
list.add(map3);
|
||||
|
||||
// 字符串模板
|
||||
TemplateEngine engine = new ThymeleafEngine(new TemplateConfig());
|
||||
Template template = engine.getTemplate("<h3 th:each=\"item : ${list}\" th:text=\"${item.name}\"></h3>");
|
||||
String render = template.render(Dict.create().set("list", list));
|
||||
Assert.assertEquals("<h3>a</h3><h3>b</h3><h3>2019-01-01 00:00:00</h3>", render);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void thymeleafEngineTest2() {
|
||||
Map<String, Object> map1 = new HashMap<>();
|
||||
map1.put("name", "a");
|
||||
|
||||
Map<String, Object> map2 = new HashMap<>();
|
||||
map2.put("name", "b");
|
||||
|
||||
// 日期测试
|
||||
Map<String, Object> map3 = new HashMap<>();
|
||||
map3.put("name", DateUtil.parse("2019-01-01"));
|
||||
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
list.add(map1);
|
||||
list.add(map2);
|
||||
list.add(map3);
|
||||
|
||||
LinkedHashMap<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("list", list);
|
||||
|
||||
hutoolApi(map);
|
||||
thymeleaf(map);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
private static void thymeleaf(Map map) {
|
||||
org.thymeleaf.TemplateEngine templateEngine = new org.thymeleaf.TemplateEngine();
|
||||
StringTemplateResolver stringTemplateResolver = new StringTemplateResolver();
|
||||
templateEngine.addTemplateResolver(stringTemplateResolver);
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
Context context = new Context(Locale.getDefault(), map);
|
||||
templateEngine.process("<h3 th:each=\"item : ${list}\" th:text=\"${item.name}\"></h3>", context, writer);
|
||||
|
||||
Assert.assertEquals("<h3>a</h3><h3>b</h3><h3>2019-01-01 00:00:00</h3>", writer.toString());
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static void hutoolApi(Map map) {
|
||||
|
||||
// 字符串模板
|
||||
TemplateEngine engine = new ThymeleafEngine(new TemplateConfig());
|
||||
Template template = engine.getTemplate("<h3 th:each=\"item : ${list}\" th:text=\"${item.name}\"></h3>");
|
||||
// "<h3 th:text=\"${nestMap.nestKey}\"></h3>"
|
||||
String render = template.render(map);
|
||||
Assert.assertEquals("<h3>a</h3><h3>b</h3><h3>2019-01-01 00:00:00</h3>", render);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
package cn.hutool.extra.template;
|
||||
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.extra.template.engine.velocity.VelocityEngine;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class VelocityTest {
|
||||
|
||||
@Test
|
||||
public void charsetTest(){
|
||||
final TemplateConfig config = new TemplateConfig("templates", TemplateConfig.ResourceMode.CLASSPATH);
|
||||
config.setCustomEngine(VelocityEngine.class);
|
||||
config.setCharset(CharsetUtil.CHARSET_GBK);
|
||||
final TemplateEngine engine = TemplateUtil.createEngine(config);
|
||||
Template template = engine.getTemplate("velocity_test_gbk.vtl");
|
||||
String result = template.render(Dict.create().set("name", "hutool"));
|
||||
Assert.assertEquals("你好,hutool", result);
|
||||
}
|
||||
}
|
||||
package cn.hutool.extra.template;
|
||||
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.extra.template.engine.velocity.VelocityEngine;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class VelocityTest {
|
||||
|
||||
@Test
|
||||
public void charsetTest(){
|
||||
final TemplateConfig config = new TemplateConfig("templates", TemplateConfig.ResourceMode.CLASSPATH);
|
||||
config.setCustomEngine(VelocityEngine.class);
|
||||
config.setCharset(CharsetUtil.CHARSET_GBK);
|
||||
final TemplateEngine engine = TemplateUtil.createEngine(config);
|
||||
Template template = engine.getTemplate("velocity_test_gbk.vtl");
|
||||
String result = template.render(Dict.create().set("name", "hutool"));
|
||||
Assert.assertEquals("你好,hutool", result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,104 +1,104 @@
|
||||
package cn.hutool.extra.tokenizer;
|
||||
|
||||
import cn.hutool.core.collection.IterUtil;
|
||||
import cn.hutool.extra.tokenizer.engine.analysis.SmartcnEngine;
|
||||
import cn.hutool.extra.tokenizer.engine.hanlp.HanLPEngine;
|
||||
import cn.hutool.extra.tokenizer.engine.ikanalyzer.IKAnalyzerEngine;
|
||||
import cn.hutool.extra.tokenizer.engine.jcseg.JcsegEngine;
|
||||
import cn.hutool.extra.tokenizer.engine.jieba.JiebaEngine;
|
||||
import cn.hutool.extra.tokenizer.engine.mmseg.MmsegEngine;
|
||||
import cn.hutool.extra.tokenizer.engine.mynlp.MynlpEngine;
|
||||
import cn.hutool.extra.tokenizer.engine.word.WordEngine;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* 模板引擎单元测试
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
public class TokenizerUtilTest {
|
||||
|
||||
String text = "这两个方法的区别在于返回值";
|
||||
|
||||
@Test
|
||||
public void createEngineTest() {
|
||||
// 默认分词引擎,此处为Ansj
|
||||
TokenizerEngine engine = TokenizerUtil.createEngine();
|
||||
Result result = engine.parse(text);
|
||||
checkResult(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hanlpTest() {
|
||||
TokenizerEngine engine = new HanLPEngine();
|
||||
Result result = engine.parse(text);
|
||||
String resultStr = IterUtil.join((Iterator<Word>)result, " ");
|
||||
Assert.assertEquals("这 两 个 方法 的 区别 在于 返回 值", resultStr);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ikAnalyzerTest() {
|
||||
TokenizerEngine engine = new IKAnalyzerEngine();
|
||||
Result result = engine.parse(text);
|
||||
String resultStr = IterUtil.join((Iterator<Word>)result, " ");
|
||||
Assert.assertEquals("这两个 方法 的 区别 在于 返回值", resultStr);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jcsegTest() {
|
||||
TokenizerEngine engine = new JcsegEngine();
|
||||
Result result = engine.parse(text);
|
||||
checkResult(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jiebaTest() {
|
||||
TokenizerEngine engine = new JiebaEngine();
|
||||
Result result = engine.parse(text);
|
||||
String resultStr = IterUtil.join((Iterator<Word>)result, " ");
|
||||
Assert.assertEquals("这 两个 方法 的 区别 在于 返回值", resultStr);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mmsegTest() {
|
||||
TokenizerEngine engine = new MmsegEngine();
|
||||
Result result = engine.parse(text);
|
||||
checkResult(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void smartcnTest() {
|
||||
TokenizerEngine engine = new SmartcnEngine();
|
||||
Result result = engine.parse(text);
|
||||
String resultStr = IterUtil.join((Iterator<Word>)result, " ");
|
||||
Assert.assertEquals("这 两 个 方法 的 区别 在于 返回 值", resultStr);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wordTest() {
|
||||
TokenizerEngine engine = new WordEngine();
|
||||
Result result = engine.parse(text);
|
||||
String resultStr = IterUtil.join((Iterator<Word>)result, " ");
|
||||
Assert.assertEquals("这两个 方法 的 区别 在于 返回值", resultStr);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void mynlpTest() {
|
||||
// 此单元测试需要JDK8,默认忽略
|
||||
TokenizerEngine engine = new MynlpEngine();
|
||||
Result result = engine.parse(text);
|
||||
String resultStr = IterUtil.join((Iterator<Word>)result, " ");
|
||||
Assert.assertEquals("这 两个 方法 的 区别 在于 返回 值", resultStr);
|
||||
}
|
||||
|
||||
private void checkResult(Result result) {
|
||||
String resultStr = IterUtil.join((Iterator<Word>)result, " ");
|
||||
Assert.assertEquals("这 两个 方法 的 区别 在于 返回 值", resultStr);
|
||||
}
|
||||
}
|
||||
package cn.hutool.extra.tokenizer;
|
||||
|
||||
import cn.hutool.core.collection.IterUtil;
|
||||
import cn.hutool.extra.tokenizer.engine.analysis.SmartcnEngine;
|
||||
import cn.hutool.extra.tokenizer.engine.hanlp.HanLPEngine;
|
||||
import cn.hutool.extra.tokenizer.engine.ikanalyzer.IKAnalyzerEngine;
|
||||
import cn.hutool.extra.tokenizer.engine.jcseg.JcsegEngine;
|
||||
import cn.hutool.extra.tokenizer.engine.jieba.JiebaEngine;
|
||||
import cn.hutool.extra.tokenizer.engine.mmseg.MmsegEngine;
|
||||
import cn.hutool.extra.tokenizer.engine.mynlp.MynlpEngine;
|
||||
import cn.hutool.extra.tokenizer.engine.word.WordEngine;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* 模板引擎单元测试
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
public class TokenizerUtilTest {
|
||||
|
||||
String text = "这两个方法的区别在于返回值";
|
||||
|
||||
@Test
|
||||
public void createEngineTest() {
|
||||
// 默认分词引擎,此处为Ansj
|
||||
TokenizerEngine engine = TokenizerUtil.createEngine();
|
||||
Result result = engine.parse(text);
|
||||
checkResult(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hanlpTest() {
|
||||
TokenizerEngine engine = new HanLPEngine();
|
||||
Result result = engine.parse(text);
|
||||
String resultStr = IterUtil.join((Iterator<Word>)result, " ");
|
||||
Assert.assertEquals("这 两 个 方法 的 区别 在于 返回 值", resultStr);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ikAnalyzerTest() {
|
||||
TokenizerEngine engine = new IKAnalyzerEngine();
|
||||
Result result = engine.parse(text);
|
||||
String resultStr = IterUtil.join((Iterator<Word>)result, " ");
|
||||
Assert.assertEquals("这两个 方法 的 区别 在于 返回值", resultStr);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jcsegTest() {
|
||||
TokenizerEngine engine = new JcsegEngine();
|
||||
Result result = engine.parse(text);
|
||||
checkResult(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jiebaTest() {
|
||||
TokenizerEngine engine = new JiebaEngine();
|
||||
Result result = engine.parse(text);
|
||||
String resultStr = IterUtil.join((Iterator<Word>)result, " ");
|
||||
Assert.assertEquals("这 两个 方法 的 区别 在于 返回值", resultStr);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mmsegTest() {
|
||||
TokenizerEngine engine = new MmsegEngine();
|
||||
Result result = engine.parse(text);
|
||||
checkResult(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void smartcnTest() {
|
||||
TokenizerEngine engine = new SmartcnEngine();
|
||||
Result result = engine.parse(text);
|
||||
String resultStr = IterUtil.join((Iterator<Word>)result, " ");
|
||||
Assert.assertEquals("这 两 个 方法 的 区别 在于 返回 值", resultStr);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wordTest() {
|
||||
TokenizerEngine engine = new WordEngine();
|
||||
Result result = engine.parse(text);
|
||||
String resultStr = IterUtil.join((Iterator<Word>)result, " ");
|
||||
Assert.assertEquals("这两个 方法 的 区别 在于 返回值", resultStr);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void mynlpTest() {
|
||||
// 此单元测试需要JDK8,默认忽略
|
||||
TokenizerEngine engine = new MynlpEngine();
|
||||
Result result = engine.parse(text);
|
||||
String resultStr = IterUtil.join((Iterator<Word>)result, " ");
|
||||
Assert.assertEquals("这 两个 方法 的 区别 在于 返回 值", resultStr);
|
||||
}
|
||||
|
||||
private void checkResult(Result result) {
|
||||
String resultStr = IterUtil.join((Iterator<Word>)result, " ");
|
||||
Assert.assertEquals("这 两个 方法 的 区别 在于 返回 值", resultStr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,62 +1,62 @@
|
||||
#\u9ed8\u8ba4\u914d\u7f6e
|
||||
ENGINE=org.beetl.core.engine.FastRuntimeEngine
|
||||
|
||||
# \u6307\u5b9a\u4e86\u5360\u4f4d\u7b26\u53f7\uff0c\u9ed8\u8ba4\u662f${ }\uff0c\u4e5f\u53ef\u4ee5\u6307\u5b9a\u4e3a\u5176\u4ed6\u5360\u4f4d\u7b26\u3002
|
||||
DELIMITER_PLACEHOLDER_START=${
|
||||
DELIMITER_PLACEHOLDER_END=}
|
||||
|
||||
# \u6307\u5b9a\u4e86\u8bed\u53e5\u7684\u5b9a\u754c\u7b26\u53f7\uff0c\u9ed8\u8ba4\u662f<% %>\uff0c\u4e5f\u53ef\u4ee5\u6307\u5b9a\u4e3a\u5176\u4ed6\u5b9a\u754c\u7b26\u53f7
|
||||
DELIMITER_STATEMENT_START=<%
|
||||
DELIMITER_STATEMENT_END=%>
|
||||
|
||||
# \u6307\u5b9aIO\u8f93\u51fa\u6a21\u5f0f\uff0c\u9ed8\u8ba4\u662fFALSE,\u5373\u901a\u5e38\u7684\u5b57\u7b26\u8f93\u51fa\uff0c\u5728\u8003\u8651\u9ad8\u6027\u80fd\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u6210true\u3002\u8be6\u7ec6\u8bf7\u53c2\u8003\u9ad8\u7ea7\u7528\u6cd5
|
||||
DIRECT_BYTE_OUTPUT = FALSE
|
||||
|
||||
# \u6307\u5b9a\u4e86\u652f\u6301HTML\u6807\u7b7e\uff0c\u4e14\u7b26\u53f7\u4e3a#,\u9ed8\u8ba4\u914d\u7f6e\u4e0b\uff0c\u6a21\u677f\u5f15\u64ce\u8bc6\u522b<#tag ></#tag>\u8fd9\u6837\u7684\u7c7b\u4f3chtml\u6807\u7b7e\uff0c\u5e76\u80fd\u8c03\u7528\u76f8\u5e94\u7684\u6807\u7b7e\u51fd\u6570\u6216\u8005\u6a21\u677f\u6587\u4ef6\u3002\u4f60\u4e5f\u53ef\u4ee5\u6307\u5b9a\u522b\u7684\u7b26\u53f7\uff0c\u5982bg: \u5219\u8bc6\u522b<bg:
|
||||
HTML_TAG_SUPPORT = true
|
||||
HTML_TAG_FLAG = #
|
||||
|
||||
# \u6307\u5b9a\u5982\u679c\u6807\u7b7e\u5c5e\u6027\u6709var\uff0c\u5219\u8ba4\u4e3a\u662f\u9700\u8981\u7ed1\u5b9a\u53d8\u91cf\u7ed9\u6a21\u677f\u7684\u6807\u7b7e\u51fd\u6570
|
||||
HTML_TAG_BINDING_ATTRIBUTE = var
|
||||
|
||||
# \u6307\u5b9a\u5141\u8bb8\u672c\u5730Class\u76f4\u63a5\u8c03\u7528
|
||||
NATIVE_CALL = TRUE
|
||||
|
||||
# \u6307\u5b9a\u6a21\u677f\u5b57\u7b26\u96c6\u662fUTF-8
|
||||
TEMPLATE_CHARSET = UTF-8
|
||||
|
||||
# \u6307\u5b9a\u5f02\u5e38\u7684\u89e3\u6790\u7c7b\uff0c\u9ed8\u8ba4\u662fConsoleErrorHandler\uff0c\u4ed6\u5c06\u5728render\u53d1\u751f\u5f02\u5e38\u7684\u65f6\u5019\u5728\u540e\u53f0\u6253\u5370\u51fa\u9519\u8bef\u4fe1\u606f\uff08System.out)
|
||||
ERROR_HANDLER = org.beetl.core.ConsoleErrorHandler
|
||||
|
||||
# \u6307\u5b9a\u4e86\u672c\u5730Class\u8c03\u7528\u7684\u5b89\u5168\u7b56\u7565
|
||||
NATIVE_SECUARTY_MANAGER= org.beetl.core.DefaultNativeSecurityManager
|
||||
|
||||
# \u914d\u7f6e\u4e86\u662f\u5426\u8fdb\u884c\u4e25\u683cMVC\uff0c\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u6b64\u5904\u8bbe\u7f6e\u4e3afalse
|
||||
MVC_STRICT = FALSE
|
||||
|
||||
#\u8d44\u6e90\u914d\u7f6e\uff0cresource\u540e\u7684\u5c5e\u6027\u53ea\u9650\u4e8e\u7279\u5b9aResourceLoader
|
||||
RESOURCE_LOADER=org.beetl.core.resource.ClasspathResourceLoader
|
||||
|
||||
#classpath \u6839\u8def\u5f84
|
||||
RESOURCE.root= /
|
||||
|
||||
#\u662f\u5426\u68c0\u6d4b\u6587\u4ef6\u53d8\u5316,\u5f00\u53d1\u7528true\u5408\u9002\uff0c\u4f46\u7ebf\u4e0a\u8981\u6539\u4e3afalse
|
||||
RESOURCE.autoCheck= true
|
||||
|
||||
#\u81ea\u5b9a\u4e49\u811a\u672c\u65b9\u6cd5\u6587\u4ef6\u7684Root\u76ee\u5f55\u548c\u540e\u7f00
|
||||
RESOURCE.functionRoot = functions
|
||||
RESOURCE.functionSuffix = html
|
||||
|
||||
#\u81ea\u5b9a\u4e49\u6807\u7b7e\u6587\u4ef6Root\u76ee\u5f55\u548c\u540e\u7f00
|
||||
RESOURCE.tagRoot = htmltag
|
||||
RESOURCE.tagSuffix = tag
|
||||
|
||||
##### \u6269\u5c55 ##############
|
||||
# \u5185\u7f6e\u7684\u65b9\u6cd5
|
||||
FN.date = org.beetl.ext.fn.DateFunction
|
||||
#\u5185\u7f6e\u7684\u529f\u80fd\u5305
|
||||
FNP.strutil = org.beetl.ext.fn.StringUtil
|
||||
# \u5185\u7f6e\u7684\u9ed8\u8ba4\u683c\u5f0f\u5316\u51fd\u6570
|
||||
FTC.java.util.Date = org.beetl.ext.format.DateFormat
|
||||
# \u6807\u7b7e\u7c7b
|
||||
#\u9ed8\u8ba4\u914d\u7f6e
|
||||
ENGINE=org.beetl.core.engine.FastRuntimeEngine
|
||||
|
||||
# \u6307\u5b9a\u4e86\u5360\u4f4d\u7b26\u53f7\uff0c\u9ed8\u8ba4\u662f${ }\uff0c\u4e5f\u53ef\u4ee5\u6307\u5b9a\u4e3a\u5176\u4ed6\u5360\u4f4d\u7b26\u3002
|
||||
DELIMITER_PLACEHOLDER_START=${
|
||||
DELIMITER_PLACEHOLDER_END=}
|
||||
|
||||
# \u6307\u5b9a\u4e86\u8bed\u53e5\u7684\u5b9a\u754c\u7b26\u53f7\uff0c\u9ed8\u8ba4\u662f<% %>\uff0c\u4e5f\u53ef\u4ee5\u6307\u5b9a\u4e3a\u5176\u4ed6\u5b9a\u754c\u7b26\u53f7
|
||||
DELIMITER_STATEMENT_START=<%
|
||||
DELIMITER_STATEMENT_END=%>
|
||||
|
||||
# \u6307\u5b9aIO\u8f93\u51fa\u6a21\u5f0f\uff0c\u9ed8\u8ba4\u662fFALSE,\u5373\u901a\u5e38\u7684\u5b57\u7b26\u8f93\u51fa\uff0c\u5728\u8003\u8651\u9ad8\u6027\u80fd\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u6210true\u3002\u8be6\u7ec6\u8bf7\u53c2\u8003\u9ad8\u7ea7\u7528\u6cd5
|
||||
DIRECT_BYTE_OUTPUT = FALSE
|
||||
|
||||
# \u6307\u5b9a\u4e86\u652f\u6301HTML\u6807\u7b7e\uff0c\u4e14\u7b26\u53f7\u4e3a#,\u9ed8\u8ba4\u914d\u7f6e\u4e0b\uff0c\u6a21\u677f\u5f15\u64ce\u8bc6\u522b<#tag ></#tag>\u8fd9\u6837\u7684\u7c7b\u4f3chtml\u6807\u7b7e\uff0c\u5e76\u80fd\u8c03\u7528\u76f8\u5e94\u7684\u6807\u7b7e\u51fd\u6570\u6216\u8005\u6a21\u677f\u6587\u4ef6\u3002\u4f60\u4e5f\u53ef\u4ee5\u6307\u5b9a\u522b\u7684\u7b26\u53f7\uff0c\u5982bg: \u5219\u8bc6\u522b<bg:
|
||||
HTML_TAG_SUPPORT = true
|
||||
HTML_TAG_FLAG = #
|
||||
|
||||
# \u6307\u5b9a\u5982\u679c\u6807\u7b7e\u5c5e\u6027\u6709var\uff0c\u5219\u8ba4\u4e3a\u662f\u9700\u8981\u7ed1\u5b9a\u53d8\u91cf\u7ed9\u6a21\u677f\u7684\u6807\u7b7e\u51fd\u6570
|
||||
HTML_TAG_BINDING_ATTRIBUTE = var
|
||||
|
||||
# \u6307\u5b9a\u5141\u8bb8\u672c\u5730Class\u76f4\u63a5\u8c03\u7528
|
||||
NATIVE_CALL = TRUE
|
||||
|
||||
# \u6307\u5b9a\u6a21\u677f\u5b57\u7b26\u96c6\u662fUTF-8
|
||||
TEMPLATE_CHARSET = UTF-8
|
||||
|
||||
# \u6307\u5b9a\u5f02\u5e38\u7684\u89e3\u6790\u7c7b\uff0c\u9ed8\u8ba4\u662fConsoleErrorHandler\uff0c\u4ed6\u5c06\u5728render\u53d1\u751f\u5f02\u5e38\u7684\u65f6\u5019\u5728\u540e\u53f0\u6253\u5370\u51fa\u9519\u8bef\u4fe1\u606f\uff08System.out)
|
||||
ERROR_HANDLER = org.beetl.core.ConsoleErrorHandler
|
||||
|
||||
# \u6307\u5b9a\u4e86\u672c\u5730Class\u8c03\u7528\u7684\u5b89\u5168\u7b56\u7565
|
||||
NATIVE_SECUARTY_MANAGER= org.beetl.core.DefaultNativeSecurityManager
|
||||
|
||||
# \u914d\u7f6e\u4e86\u662f\u5426\u8fdb\u884c\u4e25\u683cMVC\uff0c\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u6b64\u5904\u8bbe\u7f6e\u4e3afalse
|
||||
MVC_STRICT = FALSE
|
||||
|
||||
#\u8d44\u6e90\u914d\u7f6e\uff0cresource\u540e\u7684\u5c5e\u6027\u53ea\u9650\u4e8e\u7279\u5b9aResourceLoader
|
||||
RESOURCE_LOADER=org.beetl.core.resource.ClasspathResourceLoader
|
||||
|
||||
#classpath \u6839\u8def\u5f84
|
||||
RESOURCE.root= /
|
||||
|
||||
#\u662f\u5426\u68c0\u6d4b\u6587\u4ef6\u53d8\u5316,\u5f00\u53d1\u7528true\u5408\u9002\uff0c\u4f46\u7ebf\u4e0a\u8981\u6539\u4e3afalse
|
||||
RESOURCE.autoCheck= true
|
||||
|
||||
#\u81ea\u5b9a\u4e49\u811a\u672c\u65b9\u6cd5\u6587\u4ef6\u7684Root\u76ee\u5f55\u548c\u540e\u7f00
|
||||
RESOURCE.functionRoot = functions
|
||||
RESOURCE.functionSuffix = html
|
||||
|
||||
#\u81ea\u5b9a\u4e49\u6807\u7b7e\u6587\u4ef6Root\u76ee\u5f55\u548c\u540e\u7f00
|
||||
RESOURCE.tagRoot = htmltag
|
||||
RESOURCE.tagSuffix = tag
|
||||
|
||||
##### \u6269\u5c55 ##############
|
||||
# \u5185\u7f6e\u7684\u65b9\u6cd5
|
||||
FN.date = org.beetl.ext.fn.DateFunction
|
||||
#\u5185\u7f6e\u7684\u529f\u80fd\u5305
|
||||
FNP.strutil = org.beetl.ext.fn.StringUtil
|
||||
# \u5185\u7f6e\u7684\u9ed8\u8ba4\u683c\u5f0f\u5316\u51fd\u6570
|
||||
FTC.java.util.Date = org.beetl.ext.format.DateFormat
|
||||
# \u6807\u7b7e\u7c7b
|
||||
TAG.include= org.beetl.ext.tag.IncludeTag
|
||||
@@ -1,22 +1,22 @@
|
||||
# **************************************************************
|
||||
# ----- Setting File with UTF8-----
|
||||
# ----- 邮件发送功能的账户信息配置文件 -----
|
||||
# ----- 此邮箱专门注册用于Hutool发送邮件测试,为公开邮箱 -----
|
||||
# **************************************************************
|
||||
|
||||
# 邮件服务器的SMTP地址
|
||||
host = smtp.yeah.net
|
||||
# 邮件服务器的SMTP端口
|
||||
port = 465
|
||||
# 发件人(必须正确,否则发送失败)
|
||||
from = 小磊<hutool@yeah.net>
|
||||
# 用户名(注意:如果使用foxmail邮箱,此处user为qq号)
|
||||
user = hutool
|
||||
# 密码
|
||||
pass = q1w2e3
|
||||
# 使用 STARTTLS安全连接
|
||||
starttlsEnable = true
|
||||
# 是否开启SSL
|
||||
sslEnable = true
|
||||
# 调试模式
|
||||
# **************************************************************
|
||||
# ----- Setting File with UTF8-----
|
||||
# ----- 邮件发送功能的账户信息配置文件 -----
|
||||
# ----- 此邮箱专门注册用于Hutool发送邮件测试,为公开邮箱 -----
|
||||
# **************************************************************
|
||||
|
||||
# 邮件服务器的SMTP地址
|
||||
host = smtp.yeah.net
|
||||
# 邮件服务器的SMTP端口
|
||||
port = 465
|
||||
# 发件人(必须正确,否则发送失败)
|
||||
from = 小磊<hutool@yeah.net>
|
||||
# 用户名(注意:如果使用foxmail邮箱,此处user为qq号)
|
||||
user = hutool
|
||||
# 密码
|
||||
pass = q1w2e3
|
||||
# 使用 STARTTLS安全连接
|
||||
starttlsEnable = true
|
||||
# 是否开启SSL
|
||||
sslEnable = true
|
||||
# 调试模式
|
||||
debug = true
|
||||
@@ -1,68 +1,68 @@
|
||||
#---------------------------------------------------------------------------
|
||||
# Template for beetl.properties
|
||||
# see http://ibeetl.com/guide/beetl.html#header-c6267
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
#\u9ed8\u8ba4\u914d\u7f6e
|
||||
|
||||
#\u5f15\u64ce\u5b9e\u73b0\u7c7b\uff0c\u9ed8\u8ba4\u5373\u53ef
|
||||
ENGINE=org.beetl.core.engine.FastRuntimeEngine
|
||||
|
||||
#\u5360\u4f4d\u7b26\u53f7\u5f00\u59cb
|
||||
DELIMITER_PLACEHOLDER_START=${
|
||||
#\u5360\u4f4d\u7b26\u53f7\u7ed3\u675f
|
||||
DELIMITER_PLACEHOLDER_END=}
|
||||
|
||||
#\u8bed\u53e5\u7684\u5b9a\u754c\u7b26\u53f7\u5f00\u59cb
|
||||
DELIMITER_STATEMENT_START=<%
|
||||
#\u8bed\u53e5\u7684\u5b9a\u754c\u7b26\u53f7\u7ed3\u675f
|
||||
DELIMITER_STATEMENT_END=%>
|
||||
|
||||
#IO\u8f93\u51fa\u6a21\u5f0f\uff0c\u9ed8\u8ba4\u662fFALSE,\u5373\u901a\u5e38\u7684\u5b57\u7b26\u8f93\u51fa\uff0c\u5728\u8003\u8651\u9ad8\u6027\u80fd\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u6210true
|
||||
DIRECT_BYTE_OUTPUT = FALSE
|
||||
|
||||
#\u652f\u6301HTML\u6807\u7b7e\uff0c\u4e14\u7b26\u53f7\u4e3a#,\u9ed8\u8ba4\u914d\u7f6e\u4e0b\uff0c\u6a21\u677f\u5f15\u64ce\u8bc6\u522b<#tag ></#tag>\u8fd9\u6837\u7684\u7c7b\u4f3chtml\u6807\u7b7e\uff0c\u5e76\u80fd\u8c03\u7528\u76f8\u5e94\u7684\u6807\u7b7e\u51fd\u6570\u6216\u8005\u6a21\u677f\u6587\u4ef6\u3002\u4f60\u4e5f\u53ef\u4ee5\u6307\u5b9a\u522b\u7684\u7b26\u53f7\uff0c\u5982bg: \u5219\u8bc6\u522b<bg:
|
||||
HTML_TAG_SUPPORT = true
|
||||
HTML_TAG_FLAG = #
|
||||
|
||||
#\u6307\u5b9a\u5982\u679c\u6807\u7b7e\u5c5e\u6027\u6709var\uff0c\u5219\u8ba4\u4e3a\u662f\u9700\u8981\u7ed1\u5b9a\u53d8\u91cf\u7ed9\u6a21\u677f\u7684\u6807\u7b7e\u51fd\u6570
|
||||
HTML_TAG_BINDING_ATTRIBUTE = var
|
||||
|
||||
#\u6307\u5b9a\u5141\u8bb8\u672c\u5730Class\u76f4\u63a5\u8c03\u7528
|
||||
NATIVE_CALL = TRUE
|
||||
|
||||
#\u6307\u5b9a\u6a21\u677f\u5b57\u7b26\u96c6\u662fUTF-8
|
||||
TEMPLATE_CHARSET = UTF-8
|
||||
|
||||
#\u6307\u5b9a\u5f02\u5e38\u7684\u89e3\u6790\u7c7b\uff0c\u9ed8\u8ba4\u662fConsoleErrorHandler\uff0c\u4ed6\u5c06\u5728render\u53d1\u751f\u5f02\u5e38\u7684\u65f6\u5019\u5728\u540e\u53f0\u6253\u5370\u51fa\u9519\u8bef\u4fe1\u606f\uff08System.out)
|
||||
ERROR_HANDLER = org.beetl.core.ConsoleErrorHandler
|
||||
|
||||
#\u6307\u5b9a\u4e86\u672c\u5730Class\u8c03\u7528\u7684\u5b89\u5168\u7b56\u7565
|
||||
NATIVE_SECUARTY_MANAGER= org.beetl.core.DefaultNativeSecurityManager
|
||||
|
||||
#\u914d\u7f6e\u4e86\u662f\u5426\u8fdb\u884c\u4e25\u683cMVC\uff0c\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u6b64\u5904\u8bbe\u7f6e\u4e3afalse
|
||||
MVC_STRICT = FALSE
|
||||
|
||||
|
||||
#\u9ed8\u8ba4\u4f7f\u7528\u7684\u6a21\u677f\u8d44\u6e90\u52a0\u8f7d\u5668\uff0c\u8d44\u6e90\u914d\u7f6e\uff0cresource\u540e\u7684\u5c5e\u6027\u53ea\u9650\u4e8e\u7279\u5b9aResourceLoader
|
||||
RESOURCE_LOADER=org.beetl.core.resource.ClasspathResourceLoader
|
||||
#classpath \u6839\u8def\u5f84
|
||||
RESOURCE.root= /
|
||||
#\u662f\u5426\u68c0\u6d4b\u6587\u4ef6\u53d8\u5316
|
||||
RESOURCE.autoCheck= true
|
||||
#\u81ea\u5b9a\u4e49\u811a\u672c\u65b9\u6cd5\u6587\u4ef6\u7684Root\u76ee\u5f55\u548c\u540e\u7f00
|
||||
RESOURCE.functionRoot = functions
|
||||
RESOURCE.functionSuffix = html
|
||||
#\u81ea\u5b9a\u4e49\u6807\u7b7e\u6587\u4ef6Root\u76ee\u5f55\u548c\u540e\u7f00
|
||||
RESOURCE.tagRoot = htmltag
|
||||
RESOURCE.tagSuffix = tag
|
||||
|
||||
##### \u6269\u5c55 ##############
|
||||
## \u5185\u7f6e\u7684\u65b9\u6cd5
|
||||
FN.date = org.beetl.ext.fn.DateFunction
|
||||
##\u5185\u7f6e\u7684\u529f\u80fd\u5305
|
||||
FNP.strutil = org.beetl.ext.fn.StringUtil
|
||||
##\u5185\u7f6e\u7684\u9ed8\u8ba4\u683c\u5f0f\u5316\u51fd\u6570
|
||||
FTC.java.util.Date = org.beetl.ext.format.DateFormat
|
||||
## \u6807\u7b7e\u7c7b
|
||||
#---------------------------------------------------------------------------
|
||||
# Template for beetl.properties
|
||||
# see http://ibeetl.com/guide/beetl.html#header-c6267
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
#\u9ed8\u8ba4\u914d\u7f6e
|
||||
|
||||
#\u5f15\u64ce\u5b9e\u73b0\u7c7b\uff0c\u9ed8\u8ba4\u5373\u53ef
|
||||
ENGINE=org.beetl.core.engine.FastRuntimeEngine
|
||||
|
||||
#\u5360\u4f4d\u7b26\u53f7\u5f00\u59cb
|
||||
DELIMITER_PLACEHOLDER_START=${
|
||||
#\u5360\u4f4d\u7b26\u53f7\u7ed3\u675f
|
||||
DELIMITER_PLACEHOLDER_END=}
|
||||
|
||||
#\u8bed\u53e5\u7684\u5b9a\u754c\u7b26\u53f7\u5f00\u59cb
|
||||
DELIMITER_STATEMENT_START=<%
|
||||
#\u8bed\u53e5\u7684\u5b9a\u754c\u7b26\u53f7\u7ed3\u675f
|
||||
DELIMITER_STATEMENT_END=%>
|
||||
|
||||
#IO\u8f93\u51fa\u6a21\u5f0f\uff0c\u9ed8\u8ba4\u662fFALSE,\u5373\u901a\u5e38\u7684\u5b57\u7b26\u8f93\u51fa\uff0c\u5728\u8003\u8651\u9ad8\u6027\u80fd\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u6210true
|
||||
DIRECT_BYTE_OUTPUT = FALSE
|
||||
|
||||
#\u652f\u6301HTML\u6807\u7b7e\uff0c\u4e14\u7b26\u53f7\u4e3a#,\u9ed8\u8ba4\u914d\u7f6e\u4e0b\uff0c\u6a21\u677f\u5f15\u64ce\u8bc6\u522b<#tag ></#tag>\u8fd9\u6837\u7684\u7c7b\u4f3chtml\u6807\u7b7e\uff0c\u5e76\u80fd\u8c03\u7528\u76f8\u5e94\u7684\u6807\u7b7e\u51fd\u6570\u6216\u8005\u6a21\u677f\u6587\u4ef6\u3002\u4f60\u4e5f\u53ef\u4ee5\u6307\u5b9a\u522b\u7684\u7b26\u53f7\uff0c\u5982bg: \u5219\u8bc6\u522b<bg:
|
||||
HTML_TAG_SUPPORT = true
|
||||
HTML_TAG_FLAG = #
|
||||
|
||||
#\u6307\u5b9a\u5982\u679c\u6807\u7b7e\u5c5e\u6027\u6709var\uff0c\u5219\u8ba4\u4e3a\u662f\u9700\u8981\u7ed1\u5b9a\u53d8\u91cf\u7ed9\u6a21\u677f\u7684\u6807\u7b7e\u51fd\u6570
|
||||
HTML_TAG_BINDING_ATTRIBUTE = var
|
||||
|
||||
#\u6307\u5b9a\u5141\u8bb8\u672c\u5730Class\u76f4\u63a5\u8c03\u7528
|
||||
NATIVE_CALL = TRUE
|
||||
|
||||
#\u6307\u5b9a\u6a21\u677f\u5b57\u7b26\u96c6\u662fUTF-8
|
||||
TEMPLATE_CHARSET = UTF-8
|
||||
|
||||
#\u6307\u5b9a\u5f02\u5e38\u7684\u89e3\u6790\u7c7b\uff0c\u9ed8\u8ba4\u662fConsoleErrorHandler\uff0c\u4ed6\u5c06\u5728render\u53d1\u751f\u5f02\u5e38\u7684\u65f6\u5019\u5728\u540e\u53f0\u6253\u5370\u51fa\u9519\u8bef\u4fe1\u606f\uff08System.out)
|
||||
ERROR_HANDLER = org.beetl.core.ConsoleErrorHandler
|
||||
|
||||
#\u6307\u5b9a\u4e86\u672c\u5730Class\u8c03\u7528\u7684\u5b89\u5168\u7b56\u7565
|
||||
NATIVE_SECUARTY_MANAGER= org.beetl.core.DefaultNativeSecurityManager
|
||||
|
||||
#\u914d\u7f6e\u4e86\u662f\u5426\u8fdb\u884c\u4e25\u683cMVC\uff0c\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u6b64\u5904\u8bbe\u7f6e\u4e3afalse
|
||||
MVC_STRICT = FALSE
|
||||
|
||||
|
||||
#\u9ed8\u8ba4\u4f7f\u7528\u7684\u6a21\u677f\u8d44\u6e90\u52a0\u8f7d\u5668\uff0c\u8d44\u6e90\u914d\u7f6e\uff0cresource\u540e\u7684\u5c5e\u6027\u53ea\u9650\u4e8e\u7279\u5b9aResourceLoader
|
||||
RESOURCE_LOADER=org.beetl.core.resource.ClasspathResourceLoader
|
||||
#classpath \u6839\u8def\u5f84
|
||||
RESOURCE.root= /
|
||||
#\u662f\u5426\u68c0\u6d4b\u6587\u4ef6\u53d8\u5316
|
||||
RESOURCE.autoCheck= true
|
||||
#\u81ea\u5b9a\u4e49\u811a\u672c\u65b9\u6cd5\u6587\u4ef6\u7684Root\u76ee\u5f55\u548c\u540e\u7f00
|
||||
RESOURCE.functionRoot = functions
|
||||
RESOURCE.functionSuffix = html
|
||||
#\u81ea\u5b9a\u4e49\u6807\u7b7e\u6587\u4ef6Root\u76ee\u5f55\u548c\u540e\u7f00
|
||||
RESOURCE.tagRoot = htmltag
|
||||
RESOURCE.tagSuffix = tag
|
||||
|
||||
##### \u6269\u5c55 ##############
|
||||
## \u5185\u7f6e\u7684\u65b9\u6cd5
|
||||
FN.date = org.beetl.ext.fn.DateFunction
|
||||
##\u5185\u7f6e\u7684\u529f\u80fd\u5305
|
||||
FNP.strutil = org.beetl.ext.fn.StringUtil
|
||||
##\u5185\u7f6e\u7684\u9ed8\u8ba4\u683c\u5f0f\u5316\u51fd\u6570
|
||||
FTC.java.util.Date = org.beetl.ext.format.DateFormat
|
||||
## \u6807\u7b7e\u7c7b
|
||||
TAG.include= org.beetl.ext.tag.IncludeTag
|
||||
@@ -1,40 +1,40 @@
|
||||
# **************************************************************
|
||||
# ----- Setting File with UTF8-----
|
||||
# ----- 邮件发送功能的账户信息配置文件 -----
|
||||
# ----- 此邮箱专门注册用于Hutool发送邮件测试,为公开邮箱 -----
|
||||
# **************************************************************
|
||||
|
||||
# 邮件服务器的SMTP地址
|
||||
host = smtp.yeah.net
|
||||
# 邮件服务器的SMTP端口
|
||||
port = 465
|
||||
# 发件人(必须正确,否则发送失败)
|
||||
from = 小磊<hutool@yeah.net>
|
||||
# 用户名
|
||||
user = hutool
|
||||
# 密码
|
||||
pass = q1w2e3
|
||||
|
||||
# 是否打开调试模式,调试模式会显示与邮件服务器通信过程,默认不开启
|
||||
debug = true
|
||||
# 编码,决定了邮件正文编码和发件人、收件人、抄送人、密送人姓名中的中文编码,默认UTF-8
|
||||
charset = UTF-8
|
||||
|
||||
#使用 STARTTLS安全连接
|
||||
startttlsEnable = true
|
||||
#使用 SSL安全连接
|
||||
sslEnable = true
|
||||
# 指定实现javax.net.SocketFactory接口的类的名称,这个类将被用于创建SMTP的套接字
|
||||
socketFactoryClass = javax.net.ssl.SSLSocketFactory
|
||||
# 如果设置为true,未能创建一个套接字使用指定的套接字工厂类将导致使用java.net.Socket创建的套接字类, 默认值为true
|
||||
socketFactoryFallback = true
|
||||
# 指定的端口连接到在使用指定的套接字工厂。如果没有设置,将使用默认端口456
|
||||
socketFactoryPort = 465
|
||||
|
||||
# 对于超长参数是否切分为多份,默认为false(国内邮箱附件不支持切分的附件名)
|
||||
splitlongparameters = false
|
||||
|
||||
# SMTP超时时长,单位毫秒,缺省值不超时
|
||||
timeout = 0
|
||||
# Socket连接超时值,单位毫秒,缺省值不超时
|
||||
# **************************************************************
|
||||
# ----- Setting File with UTF8-----
|
||||
# ----- 邮件发送功能的账户信息配置文件 -----
|
||||
# ----- 此邮箱专门注册用于Hutool发送邮件测试,为公开邮箱 -----
|
||||
# **************************************************************
|
||||
|
||||
# 邮件服务器的SMTP地址
|
||||
host = smtp.yeah.net
|
||||
# 邮件服务器的SMTP端口
|
||||
port = 465
|
||||
# 发件人(必须正确,否则发送失败)
|
||||
from = 小磊<hutool@yeah.net>
|
||||
# 用户名
|
||||
user = hutool
|
||||
# 密码
|
||||
pass = q1w2e3
|
||||
|
||||
# 是否打开调试模式,调试模式会显示与邮件服务器通信过程,默认不开启
|
||||
debug = true
|
||||
# 编码,决定了邮件正文编码和发件人、收件人、抄送人、密送人姓名中的中文编码,默认UTF-8
|
||||
charset = UTF-8
|
||||
|
||||
#使用 STARTTLS安全连接
|
||||
startttlsEnable = true
|
||||
#使用 SSL安全连接
|
||||
sslEnable = true
|
||||
# 指定实现javax.net.SocketFactory接口的类的名称,这个类将被用于创建SMTP的套接字
|
||||
socketFactoryClass = javax.net.ssl.SSLSocketFactory
|
||||
# 如果设置为true,未能创建一个套接字使用指定的套接字工厂类将导致使用java.net.Socket创建的套接字类, 默认值为true
|
||||
socketFactoryFallback = true
|
||||
# 指定的端口连接到在使用指定的套接字工厂。如果没有设置,将使用默认端口456
|
||||
socketFactoryPort = 465
|
||||
|
||||
# 对于超长参数是否切分为多份,默认为false(国内邮箱附件不支持切分的附件名)
|
||||
splitlongparameters = false
|
||||
|
||||
# SMTP超时时长,单位毫秒,缺省值不超时
|
||||
timeout = 0
|
||||
# Socket连接超时值,单位毫秒,缺省值不超时
|
||||
connectionTimeout = 0
|
||||
@@ -1,52 +1,52 @@
|
||||
##这是一行注释,不会输出
|
||||
#*
|
||||
这是多行注释,不会输出
|
||||
多行注释
|
||||
*#
|
||||
// ---------- 1.变量赋值输出------------
|
||||
Welcome $name to hutool.cn!
|
||||
today is $date.
|
||||
tdday is $mydae.//未被定义的变量将当成字符串
|
||||
|
||||
// -----------2.设置变量值,所有变量都以$开头----------------
|
||||
#set( $iAmVariable = "good!" )
|
||||
Welcome $name to Javayou.com!
|
||||
today is $date.
|
||||
$iAmVariable
|
||||
|
||||
//-------------3.if,else判断--------------------------
|
||||
#set ($admin = "admin")
|
||||
#set ($user = "user")
|
||||
#if ($admin == $user)
|
||||
Welcome admin!
|
||||
#else
|
||||
Welcome user!
|
||||
#end
|
||||
|
||||
//--------------4.迭代数据List---------------------
|
||||
#foreach( $product in $list )
|
||||
$product
|
||||
#end
|
||||
|
||||
// ------------5.迭代数据HashSet-----------------
|
||||
#foreach($key in $hashVariable.keySet() )
|
||||
$key ‘s value: $ hashVariable.get($key)
|
||||
#end
|
||||
|
||||
//-----------6.迭代数据List Bean($velocityCount为列举序号,默认从1开始,可调整)
|
||||
#foreach ($s in $listBean)
|
||||
<$velocityCount> Address: $s.address
|
||||
#end
|
||||
|
||||
//-------------7.模板嵌套---------------------
|
||||
#foreach ($element in $list)
|
||||
#foreach ($element in $list)
|
||||
inner:This is ($velocityCount)- $element.
|
||||
#end
|
||||
outer:This is ($velocityCount)- $element.
|
||||
#end
|
||||
|
||||
//-----------8.导入其它文件,多个文件用逗号隔开(非模板静态)--------------
|
||||
#include("com/test2/test.txt")
|
||||
//-----------8.导入其它文件,多个文件用逗号隔开(模板文件)--------------
|
||||
##这是一行注释,不会输出
|
||||
#*
|
||||
这是多行注释,不会输出
|
||||
多行注释
|
||||
*#
|
||||
// ---------- 1.变量赋值输出------------
|
||||
Welcome $name to hutool.cn!
|
||||
today is $date.
|
||||
tdday is $mydae.//未被定义的变量将当成字符串
|
||||
|
||||
// -----------2.设置变量值,所有变量都以$开头----------------
|
||||
#set( $iAmVariable = "good!" )
|
||||
Welcome $name to Javayou.com!
|
||||
today is $date.
|
||||
$iAmVariable
|
||||
|
||||
//-------------3.if,else判断--------------------------
|
||||
#set ($admin = "admin")
|
||||
#set ($user = "user")
|
||||
#if ($admin == $user)
|
||||
Welcome admin!
|
||||
#else
|
||||
Welcome user!
|
||||
#end
|
||||
|
||||
//--------------4.迭代数据List---------------------
|
||||
#foreach( $product in $list )
|
||||
$product
|
||||
#end
|
||||
|
||||
// ------------5.迭代数据HashSet-----------------
|
||||
#foreach($key in $hashVariable.keySet() )
|
||||
$key ‘s value: $ hashVariable.get($key)
|
||||
#end
|
||||
|
||||
//-----------6.迭代数据List Bean($velocityCount为列举序号,默认从1开始,可调整)
|
||||
#foreach ($s in $listBean)
|
||||
<$velocityCount> Address: $s.address
|
||||
#end
|
||||
|
||||
//-------------7.模板嵌套---------------------
|
||||
#foreach ($element in $list)
|
||||
#foreach ($element in $list)
|
||||
inner:This is ($velocityCount)- $element.
|
||||
#end
|
||||
outer:This is ($velocityCount)- $element.
|
||||
#end
|
||||
|
||||
//-----------8.导入其它文件,多个文件用逗号隔开(非模板静态)--------------
|
||||
#include("com/test2/test.txt")
|
||||
//-----------8.导入其它文件,多个文件用逗号隔开(模板文件)--------------
|
||||
#parse("com/test2/test.txt")
|
||||
@@ -1,2 +1,2 @@
|
||||
@args String name
|
||||
@args String name
|
||||
hello,@name
|
||||
Reference in New Issue
Block a user