瀏覽代碼

feature #I5WNMG 脚本组件支持javascript的语法

everywhere.z 2 年之前
父節點
當前提交
09db166b91
共有 38 個文件被更改,包括 769 次插入14 次删除
  1. 2 1
      liteflow-script-plugin/liteflow-script-javascript/src/main/java/com/yomahub/liteflow/script/javascript/JavaScriptExecutor.java
  2. 1 1
      liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/LiteflowXmlScriptGroovyELTest.java
  3. 2 2
      liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/scriptbean/flow.xml
  4. 1 1
      liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/xml-script/flow.el.xml
  5. 2 5
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/common/LiteflowXmlScriptJsCommonELTest.java
  6. 82 0
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/ifelse/LiteFlowXmlScriptIfelseJsELTest.java
  7. 20 0
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/ifelse/cmp/ACmp.java
  8. 21 0
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/ifelse/cmp/BCmp.java
  9. 21 0
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/ifelse/cmp/CCmp.java
  10. 24 0
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/ifelse/cmp/DCmp.java
  11. 65 0
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/loop/LiteFlowXmlScriptLoopJsELTest.java
  12. 1 1
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/loop/cmp/ACmp.java
  13. 1 1
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/loop/cmp/BCmp.java
  14. 1 1
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/loop/cmp/CCmp.java
  15. 1 1
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/loop/cmp/DCmp.java
  16. 54 0
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/refresh/LiteflowXmlScriptJsRefreshELTest.java
  17. 20 0
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/refresh/cmp/ACmp.java
  18. 21 0
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/refresh/cmp/BCmp.java
  19. 21 0
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/refresh/cmp/CCmp.java
  20. 24 0
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/refresh/cmp/DCmp.java
  21. 44 0
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptbean/LiteFlowScriptScriptbeanJsELTest.java
  22. 22 0
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptbean/bean/DemoBean1.java
  23. 11 0
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptbean/bean/DemoBean2.java
  24. 20 0
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptbean/cmp/ACmp.java
  25. 21 0
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptbean/cmp/BCmp.java
  26. 21 0
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptbean/cmp/CCmp.java
  27. 40 0
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/sw/LiteflowXmlScriptJsSwitchELTest.java
  28. 1 0
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/ifelse/application.properties
  29. 54 0
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/ifelse/flow.xml
  30. 1 0
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/loop/application.properties
  31. 50 0
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/loop/flow.xml
  32. 1 0
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/refresh/application.properties
  33. 21 0
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/refresh/flow.xml
  34. 28 0
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/refresh/flow_update.xml
  35. 1 0
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/scriptbean/application.properties
  36. 27 0
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/scriptbean/flow.xml
  37. 1 0
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/sw/application.properties
  38. 20 0
      liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/sw/flow.xml

+ 2 - 1
liteflow-script-plugin/liteflow-script-javascript/src/main/java/com/yomahub/liteflow/script/javascript/JavaScriptExecutor.java

@@ -40,7 +40,8 @@ public class JavaScriptExecutor implements ScriptExecutor {
     @Override
     public void load(String nodeId, String script) {
         try{
-            CompiledScript compiledScript = ((Compilable) scriptEngine).compile(script);
+            String wrapScript = StrUtil.format("function process(){{}} process();",script);
+            CompiledScript compiledScript = ((Compilable) scriptEngine).compile(wrapScript);
             compiledScriptMap.put(nodeId, compiledScript);
         }catch (Exception e){
             String errorMsg = StrUtil.format("script loading error for node[{}], error msg:{}", nodeId, e.getMessage());

+ 1 - 1
liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/LiteflowXmlScriptGroovyELTest.java

@@ -43,7 +43,7 @@ public class LiteflowXmlScriptGroovyELTest extends BaseTest {
         Assert.assertEquals(Integer.valueOf(6), context.getData("s1"));
     }
 
-    //测试条件脚本节点
+    //测试选择脚本节点
     @Test
     public void testScript2() {
         LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");

+ 2 - 2
liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/scriptbean/flow.xml

@@ -18,10 +18,10 @@
     </nodes>
 
     <chain name="chain1">
-        THEN(a,b,c,d)
+        THEN(a,b,c,d);
     </chain>
 
     <chain name="chain2">
-        THEN(a,b,c,e)
+        THEN(a,b,c,e);
     </chain>
 </flow>

+ 1 - 1
liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/xml-script/flow.el.xml

@@ -25,7 +25,7 @@
             ]]>
         </node>
 
-        <node id="s2" name="条件脚本" type="switch_script">
+        <node id="s2" name="选择脚本" type="switch_script">
             <![CDATA[
                 count = defaultContext.getData("count");
                 if(count > 100){

+ 2 - 5
liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/common/LiteflowXmlScriptJsELTest.java → liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/common/LiteflowXmlScriptJsCommonELTest.java

@@ -1,9 +1,6 @@
 package com.yomahub.liteflow.test.script.javascript.common;
 
-import cn.hutool.core.io.resource.ResourceUtil;
 import com.yomahub.liteflow.core.FlowExecutor;
-import com.yomahub.liteflow.enums.FlowParserTypeEnum;
-import com.yomahub.liteflow.flow.FlowBus;
 import com.yomahub.liteflow.flow.LiteflowResponse;
 import com.yomahub.liteflow.slot.DefaultContext;
 import com.yomahub.liteflow.test.BaseTest;
@@ -26,10 +23,10 @@ import javax.annotation.Resource;
  */
 @RunWith(SpringRunner.class)
 @TestPropertySource(value = "classpath:/common/application.properties")
-@SpringBootTest(classes = LiteflowXmlScriptJsELTest.class)
+@SpringBootTest(classes = LiteflowXmlScriptJsCommonELTest.class)
 @EnableAutoConfiguration
 @ComponentScan({"com.yomahub.liteflow.test.script.javascript.common.cmp"})
-public class LiteflowXmlScriptJsELTest extends BaseTest {
+public class LiteflowXmlScriptJsCommonELTest extends BaseTest {
 
     @Resource
     private FlowExecutor flowExecutor;

+ 82 - 0
liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/ifelse/LiteFlowXmlScriptIfelseJsELTest.java

@@ -0,0 +1,82 @@
+package com.yomahub.liteflow.test.script.javascript.ifelse;
+
+import com.yomahub.liteflow.core.FlowExecutor;
+import com.yomahub.liteflow.flow.LiteflowResponse;
+import com.yomahub.liteflow.test.BaseTest;
+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;
+
+@RunWith(SpringRunner.class)
+@TestPropertySource(value = "classpath:/ifelse/application.properties")
+@SpringBootTest(classes = LiteFlowXmlScriptIfelseJsELTest.class)
+@EnableAutoConfiguration
+@ComponentScan({"com.yomahub.liteflow.test.script.javascript.ifelse.cmp"})
+public class LiteFlowXmlScriptIfelseJsELTest extends BaseTest {
+
+    @Resource
+    private FlowExecutor flowExecutor;
+
+    //IF只有2个参数
+    @Test
+    public void testIf1() throws Exception{
+        LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
+        Assert.assertTrue(response.isSuccess());
+        Assert.assertEquals("x0==>a==>b", response.getExecuteStepStrWithoutTime());
+    }
+
+    //IF只有3个参数
+    @Test
+    public void testIf2() throws Exception{
+        LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
+        Assert.assertTrue(response.isSuccess());
+        Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime());
+    }
+
+    //IF有3个参数,进行嵌套
+    @Test
+    public void testIf3() throws Exception{
+        LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg");
+        Assert.assertTrue(response.isSuccess());
+        Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime());
+    }
+
+    //IF有2个参数,加上ELSE
+    @Test
+    public void testIf4() throws Exception{
+        LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg");
+        Assert.assertTrue(response.isSuccess());
+        Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime());
+    }
+
+    //IF有2个参数,ELSE里再嵌套一个IF
+    @Test
+    public void testIf5() throws Exception{
+        LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg");
+        Assert.assertTrue(response.isSuccess());
+        Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime());
+    }
+
+    //标准的IF ELIF ELSE
+    @Test
+    public void testIf6() throws Exception{
+        LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg");
+        Assert.assertTrue(response.isSuccess());
+        Assert.assertEquals("x1==>x0==>c==>c", response.getExecuteStepStrWithoutTime());
+    }
+
+    //IF ELIF... ELSE 的形式
+    @Test
+    public void testIf7() throws Exception{
+        LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg");
+        Assert.assertTrue(response.isSuccess());
+        Assert.assertEquals("x1==>x1==>x1==>x1==>d==>b==>a", response.getExecuteStepStrWithoutTime());
+    }
+}

+ 20 - 0
liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/ifelse/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.script.javascript.ifelse.cmp;
+
+import com.yomahub.liteflow.annotation.LiteflowComponent;
+import com.yomahub.liteflow.core.NodeComponent;
+
+@LiteflowComponent("a")
+public class ACmp extends NodeComponent {
+
+	@Override
+	public void process() {
+		System.out.println("ACmp executed!");
+	}
+}

+ 21 - 0
liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/ifelse/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.script.javascript.ifelse.cmp;
+
+import com.yomahub.liteflow.annotation.LiteflowComponent;
+import com.yomahub.liteflow.core.NodeComponent;
+
+@LiteflowComponent("b")
+public class BCmp extends NodeComponent {
+
+	@Override
+	public void process() {
+		System.out.println("BCmp executed!");
+	}
+
+}

+ 21 - 0
liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/ifelse/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.script.javascript.ifelse.cmp;
+
+import com.yomahub.liteflow.annotation.LiteflowComponent;
+import com.yomahub.liteflow.core.NodeComponent;
+
+@LiteflowComponent("c")
+public class CCmp extends NodeComponent {
+
+	@Override
+	public void process() {
+		System.out.println("CCmp executed!");
+	}
+
+}

+ 24 - 0
liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/ifelse/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.script.javascript.ifelse.cmp;
+
+import com.yomahub.liteflow.annotation.LiteflowComponent;
+import com.yomahub.liteflow.core.NodeComponent;
+import com.yomahub.liteflow.slot.DefaultContext;
+
+@LiteflowComponent("d")
+public class DCmp extends NodeComponent {
+
+	@Override
+	public void process() {
+		DefaultContext context = this.getFirstContextBean();
+		context.setData("count",198);
+		System.out.println("DCmp executed!");
+	}
+
+}

+ 65 - 0
liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/loop/LiteFlowXmlScriptLoopJsELTest.java

@@ -0,0 +1,65 @@
+package com.yomahub.liteflow.test.script.javascript.loop;
+
+import com.yomahub.liteflow.core.FlowExecutor;
+import com.yomahub.liteflow.flow.LiteflowResponse;
+import com.yomahub.liteflow.test.BaseTest;
+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;
+
+@RunWith(SpringRunner.class)
+@TestPropertySource(value = "classpath:/loop/application.properties")
+@SpringBootTest(classes = LiteFlowXmlScriptLoopJsELTest.class)
+@EnableAutoConfiguration
+@ComponentScan({"com.yomahub.liteflow.test.script.javascript.loop.cmp"})
+public class LiteFlowXmlScriptLoopJsELTest extends BaseTest {
+
+    @Resource
+    private FlowExecutor flowExecutor;
+
+    //FOR循环数字直接在el中定义
+    @Test
+    public void testLoop1() throws Exception{
+        LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
+        Assert.assertTrue(response.isSuccess());
+        Assert.assertEquals("LOOP_2==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr());
+    }
+
+    //FPR循环由For组件定义
+    @Test
+    public void testLoop2() throws Exception{
+        LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
+        Assert.assertTrue(response.isSuccess());
+        Assert.assertEquals("x==>a==>b==>c==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr());
+    }
+
+    //FOR循环中加入BREAK组件
+    @Test
+    public void testLoop3() throws Exception{
+        LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg");
+        Assert.assertTrue(response.isSuccess());
+    }
+
+    //WHILE循环
+    @Test
+    public void testLoop4() throws Exception{
+        LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg");
+        Assert.assertTrue(response.isSuccess());
+        Assert.assertEquals("z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z", response.getExecuteStepStr());
+    }
+
+    //WHILE循环加入BREAK
+    @Test
+    public void testLoop5() throws Exception{
+        LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg");
+        Assert.assertTrue(response.isSuccess());
+        Assert.assertEquals("z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y", response.getExecuteStepStr());
+    }
+}

+ 1 - 1
liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/loop/cmp/ACmp.java → liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/loop/cmp/ACmp.java

@@ -5,7 +5,7 @@
  * @email weenyc31@163.com
  * @Date 2020/4/1
  */
-package com.yomahub.liteflow.test.script.groovy.loop.cmp;
+package com.yomahub.liteflow.test.script.javascript.loop.cmp;
 
 import com.yomahub.liteflow.core.NodeComponent;
 import org.springframework.stereotype.Component;

+ 1 - 1
liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/loop/cmp/BCmp.java → liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/loop/cmp/BCmp.java

@@ -5,7 +5,7 @@
  * @email weenyc31@163.com
  * @Date 2020/4/1
  */
-package com.yomahub.liteflow.test.script.groovy.loop.cmp;
+package com.yomahub.liteflow.test.script.javascript.loop.cmp;
 
 import com.yomahub.liteflow.core.NodeComponent;
 import org.springframework.stereotype.Component;

+ 1 - 1
liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/loop/cmp/CCmp.java → liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/loop/cmp/CCmp.java

@@ -5,7 +5,7 @@
  * @email weenyc31@163.com
  * @Date 2020/4/1
  */
-package com.yomahub.liteflow.test.script.groovy.loop.cmp;
+package com.yomahub.liteflow.test.script.javascript.loop.cmp;
 
 import com.yomahub.liteflow.core.NodeComponent;
 import org.springframework.stereotype.Component;

+ 1 - 1
liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/loop/cmp/DCmp.java → liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/loop/cmp/DCmp.java

@@ -5,7 +5,7 @@
  * @email weenyc31@163.com
  * @Date 2020/4/1
  */
-package com.yomahub.liteflow.test.script.groovy.loop.cmp;
+package com.yomahub.liteflow.test.script.javascript.loop.cmp;
 
 import com.yomahub.liteflow.core.NodeComponent;
 import com.yomahub.liteflow.slot.DefaultContext;

+ 54 - 0
liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/refresh/LiteflowXmlScriptJsRefreshELTest.java

@@ -0,0 +1,54 @@
+package com.yomahub.liteflow.test.script.javascript.refresh;
+
+import cn.hutool.core.io.resource.ResourceUtil;
+import com.yomahub.liteflow.core.FlowExecutor;
+import com.yomahub.liteflow.enums.FlowParserTypeEnum;
+import com.yomahub.liteflow.flow.FlowBus;
+import com.yomahub.liteflow.flow.LiteflowResponse;
+import com.yomahub.liteflow.slot.DefaultContext;
+import com.yomahub.liteflow.test.BaseTest;
+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;
+
+
+/**
+ * 测试springboot下的groovy脚本组件,基于xml配置
+ * @author Bryan.Zhang
+ * @since 2.6.0
+ */
+@RunWith(SpringRunner.class)
+@TestPropertySource(value = "classpath:/refresh/application.properties")
+@SpringBootTest(classes = LiteflowXmlScriptJsRefreshELTest.class)
+@EnableAutoConfiguration
+@ComponentScan({"com.yomahub.liteflow.test.script.javascript.refresh.cmp"})
+public class LiteflowXmlScriptJsRefreshELTest extends BaseTest {
+
+    @Resource
+    private FlowExecutor flowExecutor;
+
+    //测试脚本的热重载
+    @Test
+    public void testRefresh1() throws Exception{
+        //根据配置,加载的应该是flow.xml,执行原来的规则
+        LiteflowResponse responseOld = flowExecutor.execute2Resp("chain1", "arg");
+        Assert.assertTrue(responseOld.isSuccess());
+        Assert.assertEquals("d==>s1[选择脚本]==>a", responseOld.getExecuteStepStr());
+        //更改规则,重新加载,更改的规则内容从flow_update.xml里读取,这里只是为了模拟下获取新的内容。不一定是从文件中读取
+        String newContent = ResourceUtil.readUtf8Str("classpath: /refresh/flow_update.xml");
+        //进行刷新
+        FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, newContent);
+
+        //重新执行chain2这个链路,结果会变
+        LiteflowResponse responseNew = flowExecutor.execute2Resp("chain1", "arg");
+        Assert.assertTrue(responseNew.isSuccess());
+        Assert.assertEquals("d==>s1[选择脚本_改]==>b==>s2[普通脚本_新增]", responseNew.getExecuteStepStr());
+    }
+}

+ 20 - 0
liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/refresh/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.script.javascript.refresh.cmp;
+
+import com.yomahub.liteflow.annotation.LiteflowComponent;
+import com.yomahub.liteflow.core.NodeComponent;
+
+@LiteflowComponent("a")
+public class ACmp extends NodeComponent {
+
+	@Override
+	public void process() {
+		System.out.println("ACmp executed!");
+	}
+}

+ 21 - 0
liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/refresh/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.script.javascript.refresh.cmp;
+
+import com.yomahub.liteflow.annotation.LiteflowComponent;
+import com.yomahub.liteflow.core.NodeComponent;
+
+@LiteflowComponent("b")
+public class BCmp extends NodeComponent {
+
+	@Override
+	public void process() {
+		System.out.println("BCmp executed!");
+	}
+
+}

+ 21 - 0
liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/refresh/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.script.javascript.refresh.cmp;
+
+import com.yomahub.liteflow.annotation.LiteflowComponent;
+import com.yomahub.liteflow.core.NodeComponent;
+
+@LiteflowComponent("c")
+public class CCmp extends NodeComponent {
+
+	@Override
+	public void process() {
+		System.out.println("CCmp executed!");
+	}
+
+}

+ 24 - 0
liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/refresh/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.script.javascript.refresh.cmp;
+
+import com.yomahub.liteflow.annotation.LiteflowComponent;
+import com.yomahub.liteflow.core.NodeComponent;
+import com.yomahub.liteflow.slot.DefaultContext;
+
+@LiteflowComponent("d")
+public class DCmp extends NodeComponent {
+
+	@Override
+	public void process() {
+		DefaultContext context = this.getFirstContextBean();
+		context.setData("count",198);
+		System.out.println("DCmp executed!");
+	}
+
+}

+ 44 - 0
liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptbean/LiteFlowScriptScriptbeanJsELTest.java

@@ -0,0 +1,44 @@
+package com.yomahub.liteflow.test.script.javascript.scriptbean;
+
+import com.yomahub.liteflow.core.FlowExecutor;
+import com.yomahub.liteflow.flow.LiteflowResponse;
+import com.yomahub.liteflow.slot.DefaultContext;
+import com.yomahub.liteflow.test.BaseTest;
+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;
+
+@RunWith(SpringRunner.class)
+@TestPropertySource(value = "classpath:/scriptbean/application.properties")
+@SpringBootTest(classes = LiteFlowScriptScriptbeanJsELTest.class)
+@EnableAutoConfiguration
+@ComponentScan({"com.yomahub.liteflow.test.script.javascript.scriptbean.cmp","com.yomahub.liteflow.test.script.javascript.scriptbean.bean"})
+public class LiteFlowScriptScriptbeanJsELTest extends BaseTest {
+
+    @Resource
+    private FlowExecutor flowExecutor;
+
+    @Test
+    public void testScriptBean1() throws Exception{
+        LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
+        Assert.assertTrue(response.isSuccess());
+        DefaultContext context = response.getFirstContextBean();
+        Assert.assertEquals("hello", context.getData("demo"));
+    }
+
+    @Test
+    public void testScriptBean2() throws Exception{
+        LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
+        Assert.assertTrue(response.isSuccess());
+        DefaultContext context = response.getFirstContextBean();
+        Assert.assertEquals("hello,kobe", context.getData("demo"));
+    }
+
+}

+ 22 - 0
liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptbean/bean/DemoBean1.java

@@ -0,0 +1,22 @@
+package com.yomahub.liteflow.test.script.javascript.scriptbean.bean;
+
+import com.yomahub.liteflow.script.ScriptBean;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+
+@Component
+@ScriptBean("demo")
+public class DemoBean1 {
+
+    @Resource
+    private DemoBean2 demoBean2;
+
+    public String getDemoStr1(){
+        return "hello";
+    }
+
+    public String getDemoStr2(String name){
+        return demoBean2.getDemoStr2(name);
+    }
+}

+ 11 - 0
liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptbean/bean/DemoBean2.java

@@ -0,0 +1,11 @@
+package com.yomahub.liteflow.test.script.javascript.scriptbean.bean;
+
+import org.springframework.stereotype.Component;
+
+@Component
+public class DemoBean2 {
+
+    public String getDemoStr2(String name){
+        return "hello,"+name;
+    }
+}

+ 20 - 0
liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptbean/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.script.javascript.scriptbean.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-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptbean/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.script.javascript.scriptbean.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-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptbean/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.script.javascript.scriptbean.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!");
+	}
+
+}

+ 40 - 0
liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/sw/LiteflowXmlScriptJsSwitchELTest.java

@@ -0,0 +1,40 @@
+package com.yomahub.liteflow.test.script.javascript.sw;
+
+import com.yomahub.liteflow.core.FlowExecutor;
+import com.yomahub.liteflow.flow.LiteflowResponse;
+import com.yomahub.liteflow.test.BaseTest;
+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;
+
+
+/**
+ * 测试springboot下的groovy脚本组件,基于xml配置
+ * @author Bryan.Zhang
+ * @since 2.6.0
+ */
+@RunWith(SpringRunner.class)
+@TestPropertySource(value = "classpath:/sw/application.properties")
+@SpringBootTest(classes = LiteflowXmlScriptJsSwitchELTest.class)
+@EnableAutoConfiguration
+@ComponentScan({"com.yomahub.liteflow.test.script.javascript.sw.cmp"})
+public class LiteflowXmlScriptJsSwitchELTest extends BaseTest {
+
+    @Resource
+    private FlowExecutor flowExecutor;
+
+    //测试选择脚本节点
+    @Test
+    public void testSw1() {
+        LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
+        Assert.assertTrue(response.isSuccess());
+        Assert.assertEquals("d==>s1[选择脚本]==>a", response.getExecuteStepStr());
+    }
+}

+ 1 - 0
liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/ifelse/application.properties

@@ -0,0 +1 @@
+liteflow.rule-source=ifelse/flow.xml

+ 54 - 0
liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/ifelse/flow.xml

@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<flow>
+    <nodes>
+        <node id="x0" type="if_script">
+            <![CDATA[
+                return true;
+            ]]>
+        </node>
+
+        <node id="x1" type="if_script">
+            <![CDATA[
+                return false;
+            ]]>
+        </node>
+    </nodes>
+
+    <chain name="chain1">
+        IF(x0, THEN(a, b));
+    </chain>
+
+    <chain name="chain2">
+        IF(x1, THEN(a, b), THEN(c, d));
+    </chain>
+
+    <chain name="chain3">
+        item = IF(x1, a, THEN(c, c, b));
+        IF(
+            x1,
+            a,
+            item
+        );
+    </chain>
+
+    <chain name="chain4">
+        IF(x1, THEN(a, b)).ELSE(THEN(c, d));
+    </chain>
+
+    <chain name="chain5">
+        item = IF(x1, a, THEN(c, c, b));
+
+        IF(x1, THEN(a, b)).ELSE(item);
+    </chain>
+
+    <chain name="chain6">
+        IF(x1, THEN(a, b)).ELIF(x0, THEN(c, c)).ELSE(d);
+    </chain>
+
+    <chain name="chain7">
+        IF(x1, a).ELIF(x1, b)
+                              .ELIF(x1, c)
+                              .ELIF(x1, d)
+                              .ELSE(THEN(d, b, a));
+    </chain>
+</flow>

+ 1 - 0
liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/loop/application.properties

@@ -0,0 +1 @@
+liteflow.rule-source=loop/flow.xml

+ 50 - 0
liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/loop/flow.xml

@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<flow>
+
+    <nodes>
+        <node id="x" type="for_script">
+            <![CDATA[
+                return 3;
+            ]]>
+        </node>
+
+        <node id="y" type="break_script">
+            <![CDATA[
+                var count = defaultContext.getData("test");
+                return count > 3;
+            ]]>
+        </node>
+
+        <node id="z" type="while_script">
+            <![CDATA[
+                var key = "test";
+                if (defaultContext.hasData(key)){
+                    var count = defaultContext.getData("test");
+                    return count < 5;
+                }else{
+                    return true;
+                }
+            ]]>
+        </node>
+    </nodes>
+
+    <chain name="chain1">
+        FOR(2).DO(THEN(a,b,c));
+    </chain>
+
+    <chain name="chain2">
+        FOR(x).DO(THEN(a,b,c));
+    </chain>
+
+    <chain name="chain3">
+        FOR(10).DO(THEN(a,b,d)).BREAK(y);
+    </chain>
+
+    <chain name="chain4">
+        WHILE(z).DO(THEN(a,d));
+    </chain>
+
+    <chain name="chain5">
+        WHILE(z).DO(THEN(a,d)).BREAK(y);
+    </chain>
+</flow>

+ 1 - 0
liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/refresh/application.properties

@@ -0,0 +1 @@
+liteflow.rule-source=refresh/flow.xml

+ 21 - 0
liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/refresh/flow.xml

@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<flow>
+    <nodes>
+        <node id="s1" name="选择脚本" type="switch_script">
+            <![CDATA[
+                var count = defaultContext.getData("count");
+                if(count > 100){
+                    return "a";
+                }else{
+                    return "b";
+                }
+            ]]>
+        </node>
+
+    </nodes>
+
+    <chain name="chain1">
+        THEN(d, SWITCH(s1).to(a,b));
+    </chain>
+
+</flow>

+ 28 - 0
liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/refresh/flow_update.xml

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<flow>
+    <nodes>
+        <node id="s1" name="选择脚本_改" type="switch_script">
+            <![CDATA[
+                var count = defaultContext.getData("count");
+                if(count > 150){
+                    return "b";
+                }else{
+                    return "a";
+                }
+            ]]>
+        </node>
+
+        <node id="s2" name="普通脚本_新增" type="script">
+            <![CDATA[
+                var a=3;
+                var b=2;
+                var c=10;
+                defaultContext.setData("s1",a*b+c);
+            ]]>
+        </node>
+    </nodes>
+
+    <chain name="chain1">
+        THEN(d, SWITCH(s1).to(a,b), s2);
+    </chain>
+</flow>

+ 1 - 0
liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/scriptbean/application.properties

@@ -0,0 +1 @@
+liteflow.rule-source=scriptbean/flow.xml

+ 27 - 0
liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/scriptbean/flow.xml

@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<flow>
+
+    <nodes>
+        <node id="d" type="script">
+            <![CDATA[
+                var str = demo.getDemoStr1();
+                defaultContext.setData("demo", str);
+            ]]>
+        </node>
+
+        <node id="e" type="script">
+            <![CDATA[
+                var str = demo.getDemoStr2("kobe");
+                defaultContext.setData("demo", str);
+            ]]>
+        </node>
+    </nodes>
+
+    <chain name="chain1">
+        THEN(a,b,c,d);
+    </chain>
+
+    <chain name="chain2">
+        THEN(a,b,c,e);
+    </chain>
+</flow>

+ 1 - 0
liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/sw/application.properties

@@ -0,0 +1 @@
+liteflow.rule-source=sw/flow.xml

+ 20 - 0
liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/sw/flow.xml

@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<flow>
+    <nodes>
+        <node id="s1" name="选择脚本" type="switch_script">
+            <![CDATA[
+                var count = defaultContext.getData('count');
+                if(count > 100){
+                    return 'a';
+                }else{
+                    return 'b';
+                }
+            ]]>
+        </node>
+    </nodes>
+
+    <chain name="chain1">
+        THEN(d, SWITCH(s1).to(a,b));
+    </chain>
+
+</flow>