Browse Source

feat #I6BDLN 监听路径去重功能增加单元测试

gaibu 2 năm trước cách đây
mục cha
commit
ec48c71a9d

+ 43 - 0
liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java

@@ -0,0 +1,43 @@
+package com.yomahub.liteflow.test.monitorFile;
+
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.io.resource.ClassPathResource;
+import cn.hutool.core.util.CharsetUtil;
+import com.yomahub.liteflow.core.FlowExecutor;
+import com.yomahub.liteflow.flow.LiteflowResponse;
+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.ComponentScan;
+import org.springframework.test.context.TestPropertySource;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import javax.annotation.Resource;
+import java.io.File;
+
+@RunWith(SpringRunner.class)
+@TestPropertySource(value = "classpath:/monitorFile/application.properties")
+@SpringBootTest(classes = MonitorFileELSpringbootTest.class)
+@EnableAutoConfiguration
+@ComponentScan({"com.yomahub.liteflow.test.monitorFile.cmp"})
+public class MonitorFileELSpringbootTest {
+
+    @Resource
+    private FlowExecutor flowExecutor;
+
+    @Test
+    public void testMonitor() throws Exception{
+        String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath();
+        String content = FileUtil.readUtf8String(absolutePath);
+        String newContent = content.replace("THEN(a, b, c);", "THEN(a, c, b);");
+        FileUtil.writeString(newContent,new File(absolutePath), CharsetUtil.CHARSET_UTF_8);
+
+        Thread.sleep(1000);
+
+        LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
+        Assert.assertEquals("a==>c==>b", response.getExecuteStepStr());
+    }
+
+}

+ 28 - 0
liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java

@@ -0,0 +1,28 @@
+/**
+ * <p>Title: liteflow</p>
+ * <p>Description: 轻量级的组件式流程框架</p>
+ * @author Bryan.Zhang
+ * @email weenyc31@163.com
+ * @Date 2020/4/1
+ */
+package com.yomahub.liteflow.test.monitorFile.cmp;
+
+import com.yomahub.liteflow.core.NodeComponent;
+import org.springframework.stereotype.Component;
+
+import java.util.Random;
+
+@Component("a")
+public class ACmp extends NodeComponent {
+
+	@Override
+	public void process() {
+		try {
+			Thread.sleep(new Random().nextInt(2000));
+		}catch (Exception e){
+			e.printStackTrace();
+		}
+
+		System.out.println("ACmp executed!");
+	}
+}

+ 28 - 0
liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/BCmp.java

@@ -0,0 +1,28 @@
+/**
+ * <p>Title: liteflow</p>
+ * <p>Description: 轻量级的组件式流程框架</p>
+ * @author Bryan.Zhang
+ * @email weenyc31@163.com
+ * @Date 2020/4/1
+ */
+package com.yomahub.liteflow.test.monitorFile.cmp;
+
+import com.yomahub.liteflow.core.NodeComponent;
+import org.springframework.stereotype.Component;
+
+import java.util.Random;
+
+@Component("b")
+public class BCmp extends NodeComponent {
+
+	@Override
+	public void process() {
+		try {
+			Thread.sleep(new Random().nextInt(2000));
+		}catch (Exception e){
+			e.printStackTrace();
+		}
+		System.out.println("BCmp executed!");
+	}
+
+}

+ 28 - 0
liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CCmp.java

@@ -0,0 +1,28 @@
+/**
+ * <p>Title: liteflow</p>
+ * <p>Description: 轻量级的组件式流程框架</p>
+ * @author Bryan.Zhang
+ * @email weenyc31@163.com
+ * @Date 2020/4/1
+ */
+package com.yomahub.liteflow.test.monitorFile.cmp;
+
+import com.yomahub.liteflow.core.NodeComponent;
+import org.springframework.stereotype.Component;
+
+import java.util.Random;
+
+@Component("c")
+public class CCmp extends NodeComponent {
+
+	@Override
+	public void process() {
+		try {
+			Thread.sleep(new Random().nextInt(2000));
+		}catch (Exception e){
+			e.printStackTrace();
+		}
+		System.out.println("CCmp executed!");
+	}
+
+}

+ 2 - 0
liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/monitorFile/application.properties

@@ -0,0 +1,2 @@
+liteflow.rule-source=monitorFile/flow.el.xml
+liteflow.enable-monitor-file=true

+ 7 - 0
liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/monitorFile/flow.el.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<flow>
+    <chain name="chain1">
+        THEN(a, b, c);
+    </chain>
+
+</flow>