浏览代码

!33 【测试用例】liteflow开启和关闭
Merge pull request !33 from 请叫我猿叔叔/testcase_I4BGK9

铂赛东 3 年之前
父节点
当前提交
ee62f8f367

+ 17 - 2
liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/enable/LiteflowEnableSpringbootTest.java

@@ -1,10 +1,14 @@
 package com.yomahub.liteflow.test.enable;
 
+import com.yomahub.liteflow.property.LiteflowConfig;
 import com.yomahub.liteflow.test.BaseTest;
+import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
 import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.ApplicationContext;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.test.context.TestPropertySource;
 import org.springframework.test.context.junit4.SpringRunner;
@@ -12,6 +16,7 @@ import org.springframework.test.context.junit4.SpringRunner;
 
 /**
  * 测试springboot下的enable参数
+ *
  * @author Bryan.Zhang
  * @since 2.5.10
  */
@@ -22,8 +27,18 @@ import org.springframework.test.context.junit4.SpringRunner;
 @ComponentScan({"com.yomahub.liteflow.test.enable.cmp"})
 public class LiteflowEnableSpringbootTest extends BaseTest {
 
+    @Autowired
+    private ApplicationContext context;
+
+
     @Test
-    public void testConfig() {
-        System.out.println("成功启动,并且打印");
+    public void testEnable() {
+        LiteflowConfig config = context.getBean(LiteflowConfig.class);
+        Boolean enable = config.getEnable();
+        if (enable) {
+            System.out.println("成功启动,并且打印");
+            return;
+        }
+        Assert.assertFalse(enable);
     }
 }

+ 1 - 1
liteflow-testcase-springboot/src/test/resources/enable/application.properties

@@ -1,2 +1,2 @@
 liteflow.enable=false
-liteflow.rule-source=enable/flow.xml
+liteflow.rule-source=enable/flow.xml

+ 45 - 0
liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/enable/LiteflowEnableSpringTest.java

@@ -0,0 +1,45 @@
+package com.yomahub.liteflow.test.enable;
+
+import com.yomahub.liteflow.core.FlowExecutor;
+import com.yomahub.liteflow.entity.data.DefaultSlot;
+import com.yomahub.liteflow.entity.data.LiteflowResponse;
+import com.yomahub.liteflow.property.LiteflowConfig;
+import com.yomahub.liteflow.test.BaseTest;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import javax.annotation.Resource;
+
+/**
+ * spring环境下enable参数
+ *
+ * @author qjwyss
+ * @since 2.6.0
+ */
+@RunWith(SpringRunner.class)
+@ContextConfiguration("classpath:/enable/application-local.xml")
+public class LiteflowEnableSpringTest extends BaseTest {
+    @Resource
+    private FlowExecutor flowExecutor;
+
+    @Autowired
+    private ApplicationContext context;
+
+    @Test
+    public void testEnable() throws Exception {
+        LiteflowConfig config = context.getBean(LiteflowConfig.class);
+        Boolean enable = config.getEnable();
+        if (enable) {
+            LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg");
+            Assert.assertTrue(response.isSuccess());
+            return;
+        }
+
+        Assert.assertFalse(enable);
+    }
+}

+ 20 - 0
liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/enable/cmp/ACmp.java

@@ -0,0 +1,20 @@
+/**
+ * <p>Title: liteflow</p>
+ * <p>Description: 轻量级的组件式流程框架</p>
+ * @author Bryan.Zhang
+ * @email weenyc31@163.com
+ * @Date 2020/4/1
+ */
+package com.yomahub.liteflow.test.enable.cmp;
+
+import com.yomahub.liteflow.core.NodeComponent;
+import org.springframework.stereotype.Component;
+
+@Component("a")
+public class ACmp extends NodeComponent {
+
+	@Override
+	public void process() {
+		System.out.println("ACmp executed!");
+	}
+}

+ 21 - 0
liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/enable/cmp/BCmp.java

@@ -0,0 +1,21 @@
+/**
+ * <p>Title: liteflow</p>
+ * <p>Description: 轻量级的组件式流程框架</p>
+ * @author Bryan.Zhang
+ * @email weenyc31@163.com
+ * @Date 2020/4/1
+ */
+package com.yomahub.liteflow.test.enable.cmp;
+
+import com.yomahub.liteflow.core.NodeComponent;
+import org.springframework.stereotype.Component;
+
+@Component("b")
+public class BCmp extends NodeComponent {
+
+	@Override
+	public void process() {
+		System.out.println("BCmp executed!");
+	}
+
+}

+ 21 - 0
liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/enable/cmp/CCmp.java

@@ -0,0 +1,21 @@
+/**
+ * <p>Title: liteflow</p>
+ * <p>Description: 轻量级的组件式流程框架</p>
+ * @author Bryan.Zhang
+ * @email weenyc31@163.com
+ * @Date 2020/4/1
+ */
+package com.yomahub.liteflow.test.enable.cmp;
+
+import com.yomahub.liteflow.core.NodeComponent;
+import org.springframework.stereotype.Component;
+
+@Component("c")
+public class CCmp extends NodeComponent {
+
+	@Override
+	public void process() {
+		System.out.println("CCmp executed!");
+	}
+
+}

+ 24 - 0
liteflow-testcase-springnative/src/test/resources/enable/application-local.xml

@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns="http://www.springframework.org/schema/beans"
+       xmlns:context="http://www.springframework.org/schema/context"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans
+       http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
+       http://www.springframework.org/schema/context
+       http://www.springframework.org/schema/context/spring-context-4.0.xsd">
+
+    <context:component-scan base-package="com.yomahub.liteflow.test.enable.cmp" />
+
+    <bean id="springAware" class="com.yomahub.liteflow.util.SpringAware"/>
+
+    <bean class="com.yomahub.liteflow.spring.ComponentScanner"/>
+
+    <bean id="liteflowConfig" class="com.yomahub.liteflow.property.LiteflowConfig">
+        <property name="ruleSource" value="enable/flow.json"/>
+        <property name="enable" value="true"/>
+    </bean>
+
+    <bean id="flowExecutor" class="com.yomahub.liteflow.core.FlowExecutor">
+        <property name="liteflowConfig" ref="liteflowConfig"/>
+    </bean>
+</beans>

+ 28 - 0
liteflow-testcase-springnative/src/test/resources/enable/flow.json

@@ -0,0 +1,28 @@
+{
+  "flow": {
+    "nodes": {
+      "node": [
+        {
+          "id": "a",
+          "class": "com.yomahub.liteflow.test.enable.cmp.ACmp"
+        },
+        {
+          "id": "b",
+          "class": "com.yomahub.liteflow.test.enable.cmp.BCmp"
+        },
+        {
+          "id": "c",
+          "class": "com.yomahub.liteflow.test.enable.cmp.CCmp"
+        }
+      ]
+    },
+    "chain": [
+      {
+        "name": "chain1",
+        "condition": [
+          {"type": "then", "value": "a,b,c"}
+        ]
+      }
+    ]
+  }
+}