支持绝对路径的模糊匹配

This commit is contained in:
rain
2023-10-09 16:11:29 +08:00
parent 70954b4ae2
commit 4742ffea28
17 changed files with 233 additions and 49 deletions

View File

@@ -1,9 +1,15 @@
package com.yomahub.liteflow.test.absoluteConfigPath;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.CharsetUtil;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.property.LiteflowConfigGetter;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.noear.solon.annotation.Inject;
@@ -19,18 +25,43 @@ import org.slf4j.LoggerFactory;
* @since 2.6.4
*/
@ExtendWith(SolonJUnit5Extension.class)
@TestPropertySource("classpath:/absoluteConfigPath/application.properties")
public class AbsoluteConfigPathELSpringbootTest extends BaseTest {
private final Logger log = LoggerFactory.getLogger(this.getClass());
@Inject
private FlowExecutor flowExecutor;
@Test
public void testAbsoluteConfig() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
Assertions.assertTrue(response.isSuccess());
Assertions.assertTrue(() -> {
LiteflowConfig config = LiteflowConfigGetter.get();
config.setRuleSource("C:/LiteFlow/Test/a/b/c/flow.el.xml");
flowExecutor.reloadRule();
return flowExecutor.execute2Resp("chain1", "arg").isSuccess();
});
}
@Test
public void testAbsolutePathMatch() throws Exception {
Assertions.assertTrue(() -> {
LiteflowConfig config = LiteflowConfigGetter.get();
config.setRuleSource("C:/LiteFlow/Tes*/**/c/*.el.xml");
flowExecutor.reloadRule();
return flowExecutor.execute2Resp("chain1", "arg").isSuccess();
});
}
@BeforeAll
public static void createFiles() {
String filePath = "C:/LiteFlow/Test/a/b/c";
String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><flow><chain name=\"chain1\">WHEN(a, b, c);</chain></flow>";
FileUtil.mkdir(filePath);
FileUtil.writeString(content, filePath + "/flow.el.xml", CharsetUtil.CHARSET_UTF_8);
}
@AfterAll
public static void removeFiles() {
FileUtil.del("C:/LiteFlow");
}
}

View File

@@ -1,2 +1 @@
liteflow.rule-source=/usr/local/flow.el.xml
#liteflow.rule-source=/usr/**/*.xml
liteflow.rule-source=C:/LiteFlow/Test/a/b/c/flow.el.xml

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--这里只是内容,在这个测试用例中这个文件请移到/usr/local/flow.xml中文件目录支持绝对路径的模糊匹配也可以将此文件移入任意/usr/**/*.xml中-->
<!--这里只是内容,文件目录支持绝对路径的模糊匹配-->
<flow>
<chain name="chain1">
WHEN(a,b,c);