diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/LiteFlowXmlScriptBuilderGroovyELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/LiteFlowXmlScriptBuilderGroovyELTest.java index ede70c12..35cbc16f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/LiteFlowXmlScriptBuilderGroovyELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/LiteFlowXmlScriptBuilderGroovyELTest.java @@ -15,6 +15,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; +import java.util.List; @RunWith(SpringRunner.class) @SpringBootTest(classes = LiteFlowXmlScriptBuilderGroovyELTest.class) @@ -46,7 +47,12 @@ public class LiteFlowXmlScriptBuilderGroovyELTest extends BaseTest { .setId("s1") .setName("普通脚本S1") .setType(NodeTypeEnum.SCRIPT) - .setScript("Integer a=3;Integer b=2;defaultContext.setData(\"s1\",a*b)") + .setScript("import cn.hutool.core.collection.ListUtil;" + + "import java.util.stream.Collectors;" + + "Integer a=3;Integer b=2;defaultContext.setData(\"s1\",a*b);" + + "List list = ListUtil.toList(\"a\", \"b\", \"c\");" + + "List resultList = list.stream().map(s -> \"hello,\" + s).collect(Collectors.toList());" + + "defaultContext.setData(\"resultList\", resultList)") .build(); LiteFlowChainELBuilder.createChain().setChainName("chain1") @@ -58,6 +64,8 @@ public class LiteFlowXmlScriptBuilderGroovyELTest extends BaseTest { DefaultContext context = response.getFirstContextBean(); Assert.assertTrue(response.isSuccess()); Assert.assertEquals(Integer.valueOf(6), context.getData("s1")); + List resultList = context.getData("resultList"); + Assert.assertEquals(3, resultList.size()); } //测试通过builder方式运行普通script节点,以file的方式运行 diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/LiteflowXmlScriptGroovyELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/LiteflowXmlScriptGroovyELTest.java index ae7a065b..3850663d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/LiteflowXmlScriptGroovyELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/LiteflowXmlScriptGroovyELTest.java @@ -1,5 +1,6 @@ package com.yomahub.liteflow.test.script.groovy; +import cn.hutool.core.collection.ListUtil; import cn.hutool.core.io.resource.ResourceUtil; import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.flow.LiteflowResponse; @@ -17,6 +18,9 @@ import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; +import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; /** diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/xml-script/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/xml-script/flow.el.xml index b1a1ab8e..f332b224 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/xml-script/flow.el.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/xml-script/flow.el.xml @@ -3,25 +3,36 @@ list = ListUtil.toList("a", "b", "c") - def a=3 - def b=2 - defaultContext.setData("s1",a*b) + List resultList = list.stream().map(s -> "hello," + s).collect(Collectors.toList()) + + defaultContext.setData("resultList", resultList) + + class Student { + int studentID + String studentName + } + + Student student = new Student() + student.studentID = 100301 + student.studentName = "张三" + defaultContext.setData("student", student) + + def a = 3 + def b = 2 + defaultContext.setData("s1", a * b) ]]>