浏览代码

feature #I44FT8 支持脚本语言的组件,并支持动态刷新脚本(版本特性)

bryan31 3 年之前
父节点
当前提交
a51ecd5ca1

+ 9 - 0
liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/scriptnode/LiteflowScriptSpringbootTest.java

@@ -31,10 +31,19 @@ public class LiteflowScriptSpringbootTest extends BaseTest {
     @Resource
     private FlowExecutor flowExecutor;
 
+    //测试普通脚本节点
     @Test
     public void testScript1() {
         LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg");
         Assert.assertTrue(response.isSuccess());
         Assert.assertEquals(Integer.valueOf(6), response.getSlot().getData("s1"));
     }
+
+    //测试条件脚本节点
+    @Test
+    public void testScript2() {
+        LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain2", "arg");
+        Assert.assertTrue(response.isSuccess());
+        Assert.assertEquals("d==>s2==>b", response.getSlot().printStep());
+    }
 }

+ 24 - 0
liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/scriptnode/cmp/DCmp.java

@@ -0,0 +1,24 @@
+/**
+ * <p>Title: liteflow</p>
+ * <p>Description: 轻量级的组件式流程框架</p>
+ * @author Bryan.Zhang
+ * @email weenyc31@163.com
+ * @Date 2020/4/1
+ */
+package com.yomahub.liteflow.test.scriptnode.cmp;
+
+import com.yomahub.liteflow.annotation.LiteflowComponent;
+import com.yomahub.liteflow.core.NodeComponent;
+import com.yomahub.liteflow.entity.data.Slot;
+
+@LiteflowComponent("d")
+public class DCmp extends NodeComponent {
+
+	@Override
+	public void process() {
+		Slot slot = this.getSlot();
+		slot.setData("count",97);
+		System.out.println("DCmp executed!");
+	}
+
+}

+ 15 - 0
liteflow-spring-boot-starter/src/test/resources/scriptnode/flow.xml

@@ -8,9 +8,24 @@
                 slot.setData("s1",a*b);
             ]]>
         </node>
+
+        <node id="s2" type="cond_script">
+            <![CDATA[
+                count = slot.getData("count");
+                if(count > 100){
+                    return "a";
+                }else{
+                    return "b";
+                }
+            ]]>
+        </node>
     </nodes>
 
     <chain name="chain1">
         <then value="a,b,c,s1"/>
     </chain>
+
+    <chain name="chain2">
+        <then value="d,s2(a|b)"/>
+    </chain>
 </flow>