优化脚本测试用例

This commit is contained in:
everywhere.z 2022-11-25 16:03:38 +08:00
parent d2d6e13659
commit cec930269a
3 changed files with 39 additions and 16 deletions

View File

@ -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<String> list = ListUtil.toList(\"a\", \"b\", \"c\");" +
"List<String> 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<String> resultList = context.getData("resultList");
Assert.assertEquals(3, resultList.size());
}
//测试通过builder方式运行普通script节点以file的方式运行

View File

@ -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;
/**

View File

@ -3,12 +3,23 @@
<nodes>
<node id="s1" name="普通脚本1" type="script" language="groovy">
<![CDATA[
import cn.hutool.core.collection.ListUtil
import cn.hutool.core.date.DateUtil
import java.util.function.Consumer
import java.util.function.Function
import java.util.stream.Collectors
def date = DateUtil.parse("2022-10-17 13:31:43")
println(date)
defaultContext.setData("demoDate", date)
List<String> list = ListUtil.toList("a", "b", "c")
List<String> resultList = list.stream().map(s -> "hello," + s).collect(Collectors.toList())
defaultContext.setData("resultList", resultList)
class Student {
int studentID
String studentName
@ -17,11 +28,11 @@
Student student = new Student()
student.studentID = 100301
student.studentName = "张三"
defaultContext.setData("student",student)
defaultContext.setData("student", student)
def a=3
def b=2
defaultContext.setData("s1",a*b)
def a = 3
def b = 2
defaultContext.setData("s1", a * b)
]]>
</node>