优化脚本测试用例
This commit is contained in:
parent
d2d6e13659
commit
cec930269a
|
@ -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的方式运行
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,25 +3,36 @@
|
|||
<nodes>
|
||||
<node id="s1" name="普通脚本1" type="script" language="groovy">
|
||||
<![CDATA[
|
||||
import cn.hutool.core.date.DateUtil
|
||||
import cn.hutool.core.collection.ListUtil
|
||||
import cn.hutool.core.date.DateUtil
|
||||
|
||||
def date = DateUtil.parse("2022-10-17 13:31:43")
|
||||
println(date)
|
||||
defaultContext.setData("demoDate", date)
|
||||
import java.util.function.Consumer
|
||||
import java.util.function.Function
|
||||
import java.util.stream.Collectors
|
||||
|
||||
class Student {
|
||||
int studentID
|
||||
String studentName
|
||||
}
|
||||
def date = DateUtil.parse("2022-10-17 13:31:43")
|
||||
println(date)
|
||||
defaultContext.setData("demoDate", date)
|
||||
|
||||
Student student = new Student()
|
||||
student.studentID = 100301
|
||||
student.studentName = "张三"
|
||||
defaultContext.setData("student",student)
|
||||
List<String> list = ListUtil.toList("a", "b", "c")
|
||||
|
||||
def a=3
|
||||
def b=2
|
||||
defaultContext.setData("s1",a*b)
|
||||
List<String> 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)
|
||||
]]>
|
||||
</node>
|
||||
|
||||
|
|
Loading…
Reference in New Issue