diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/enums/ScriptTypeEnum.java b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/ScriptTypeEnum.java index f350b416..c9a62570 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/enums/ScriptTypeEnum.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/ScriptTypeEnum.java @@ -8,7 +8,8 @@ public enum ScriptTypeEnum { PYTHON("python", "python"), LUA("luaj", "lua"), AVIATOR("AviatorScript", "aviator"), - JAVA("java", "java"); + JAVA("java", "java"), + KOTLIN("kotlin", "kotlin"); private String engineName; diff --git a/liteflow-script-plugin/liteflow-script-kotlin/pom.xml b/liteflow-script-plugin/liteflow-script-kotlin/pom.xml new file mode 100644 index 00000000..df3bed9d --- /dev/null +++ b/liteflow-script-plugin/liteflow-script-kotlin/pom.xml @@ -0,0 +1,28 @@ + + + + liteflow-script-plugin + com.yomahub + ${revision} + ../pom.xml + + 4.0.0 + + liteflow-script-kotlin + + + + com.yomahub + liteflow-core + ${revision} + true + provided + + + org.jetbrains.kotlin + kotlin-scripting-jsr223 + + + \ No newline at end of file diff --git a/liteflow-script-plugin/liteflow-script-kotlin/src/main/java/com/yomahub/liteflow/script/kotlin/KotlinScriptExecutor.java b/liteflow-script-plugin/liteflow-script-kotlin/src/main/java/com/yomahub/liteflow/script/kotlin/KotlinScriptExecutor.java new file mode 100644 index 00000000..acdc490d --- /dev/null +++ b/liteflow-script-plugin/liteflow-script-kotlin/src/main/java/com/yomahub/liteflow/script/kotlin/KotlinScriptExecutor.java @@ -0,0 +1,15 @@ +package com.yomahub.liteflow.script.kotlin; + +import com.yomahub.liteflow.enums.ScriptTypeEnum; +import com.yomahub.liteflow.script.jsr223.JSR223ScriptExecutor; + +/** + * Kotlin脚本执行器 + * @author DaleLee + */ +public class KotlinScriptExecutor extends JSR223ScriptExecutor { + @Override + public ScriptTypeEnum scriptType() { + return ScriptTypeEnum.KOTLIN; + } +} diff --git a/liteflow-script-plugin/liteflow-script-kotlin/src/main/resources/META-INF/services/com.yomahub.liteflow.script.ScriptExecutor b/liteflow-script-plugin/liteflow-script-kotlin/src/main/resources/META-INF/services/com.yomahub.liteflow.script.ScriptExecutor new file mode 100644 index 00000000..ccce7e1f --- /dev/null +++ b/liteflow-script-plugin/liteflow-script-kotlin/src/main/resources/META-INF/services/com.yomahub.liteflow.script.ScriptExecutor @@ -0,0 +1,2 @@ +# Kotlin的实现 +com.yomahub.liteflow.script.kotlin.KotlinScriptExecutor \ No newline at end of file diff --git a/liteflow-script-plugin/pom.xml b/liteflow-script-plugin/pom.xml index 2c43fa16..a188cd04 100644 --- a/liteflow-script-plugin/pom.xml +++ b/liteflow-script-plugin/pom.xml @@ -23,6 +23,7 @@ liteflow-script-lua liteflow-script-aviator liteflow-script-java + liteflow-script-kotlin \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/pom.xml b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/pom.xml new file mode 100644 index 00000000..0563cb2d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/pom.xml @@ -0,0 +1,32 @@ + + + + liteflow-testcase-el + com.yomahub + ${revision} + ../pom.xml + + 4.0.0 + + liteflow-testcase-el-script-kotlin-springboot + + + + com.yomahub + liteflow-spring-boot-starter + ${revision} + + + com.yomahub + liteflow-script-kotlin + ${revision} + test + + + org.springframework.boot + spring-boot-starter-test + + + diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/BaseTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/BaseTest.java new file mode 100644 index 00000000..6cb71ce8 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/BaseTest.java @@ -0,0 +1,24 @@ +package com.yomahub.liteflow.test.script; + +import com.yomahub.liteflow.core.FlowInitHook; +import com.yomahub.liteflow.flow.FlowBus; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.spi.holder.SpiFactoryCleaner; +import com.yomahub.liteflow.spring.ComponentScanner; +import com.yomahub.liteflow.thread.ExecutorHelper; +import org.junit.jupiter.api.AfterAll; + +public class BaseTest { + + @AfterAll + public static void cleanScanCache() { + ComponentScanner.cleanCache(); + FlowBus.cleanCache(); + ExecutorHelper.loadInstance().clearExecutorServiceMap(); + SpiFactoryCleaner.clean(); + LiteflowConfigGetter.clean(); + FlowInitHook.cleanHook(); + FlowBus.clearStat(); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/cmpdata/LiteFlowCmpDataKotlinScriptELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/cmpdata/LiteFlowCmpDataKotlinScriptELTest.java new file mode 100644 index 00000000..c950c67d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/cmpdata/LiteFlowCmpDataKotlinScriptELTest.java @@ -0,0 +1,36 @@ +package com.yomahub.liteflow.test.script.kotlin.cmpdata; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.script.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +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.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; + +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/cmpdata/application.properties") +@SpringBootTest(classes = LiteFlowCmpDataKotlinScriptELTest.class) +@EnableAutoConfiguration +@ComponentScan({ "com.yomahub.liteflow.test.script.kotlin.cmpdata.cmp" }) +public class LiteFlowCmpDataKotlinScriptELTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testCmpData1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("1995-10-01", context.getData("s1")); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/cmpdata/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/cmpdata/cmp/ACmp.java new file mode 100644 index 00000000..1de2ccb9 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/cmpdata/cmp/ACmp.java @@ -0,0 +1,22 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.cmpdata.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(this.getCmpData(String.class)); + System.out.println("ACmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/LiteFlowKotlinScriptCommonELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/LiteFlowKotlinScriptCommonELTest.java new file mode 100644 index 00000000..17b61966 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/LiteFlowKotlinScriptCommonELTest.java @@ -0,0 +1,91 @@ +package com.yomahub.liteflow.test.script.kotlin.common; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.script.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +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.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; + +/** + * Kotlin 脚本测试 + * + * @author DaleLee + */ + +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/common/application.properties") +@SpringBootTest(classes = LiteFlowKotlinScriptCommonELTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.script.kotlin.common.cmp"}) +public class LiteFlowKotlinScriptCommonELTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testCommonScript1() { + LiteflowResponse response = flowExecutor.execute2Resp("testCommonScript1", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals(Integer.valueOf(5), context.getData("s1")); + } + + @Test + public void testForScript1() { + DefaultContext context = new DefaultContext(); + context.setData("k1", 1); + context.setData("k2", 2); + LiteflowResponse response = flowExecutor.execute2Resp("testForScript1", "arg", context); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("s2==>a==>a==>a", response.getExecuteStepStr()); + } + + @Test + public void testBooleanScript1() { + LiteflowResponse response = flowExecutor.execute2Resp("testBooleanScript1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("s3==>b", response.getExecuteStepStr()); + } + + @Test + public void testBooleanScript2() { + LiteflowResponse response = flowExecutor.execute2Resp("testBooleanScript2", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("s4", response.getExecuteStepStr()); + } + + @Test + public void testBooleanScript3() { + DefaultContext context = new DefaultContext(); + context.setData("count", 2); + LiteflowResponse response = flowExecutor.execute2Resp("testBooleanScript3", "arg", context); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("s3==>b==>s6==>s3==>b==>s6==>s3==>b==>s6",response.getExecuteStepStr()); + } + + @Test + public void testSwitchScript1() { + DefaultContext context = new DefaultContext(); + context.setData("id", "c"); + LiteflowResponse response = flowExecutor.execute2Resp("testSwitchScript1", "arg", context); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("s5==>c", response.getExecuteStepStr()); + } + + @Test + public void testFileScript1() { + LiteflowResponse response = flowExecutor.execute2Resp("testFileScript1", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals(Integer.valueOf(6), context.getData("s7")); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/cmp/ACmp.java new file mode 100644 index 00000000..895686f1 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/cmp/ACmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.common.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!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/cmp/BCmp.java new file mode 100644 index 00000000..1c4eb649 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/cmp/BCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.common.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!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/cmp/CCmp.java new file mode 100644 index 00000000..661e979a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/cmp/CCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.common.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!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/LiteFlowScriptContextbeanKotlinELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/LiteFlowScriptContextbeanKotlinELTest.java new file mode 100644 index 00000000..d0bdba39 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/LiteFlowScriptContextbeanKotlinELTest.java @@ -0,0 +1,57 @@ +package com.yomahub.liteflow.test.script.kotlin.contextbean; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.test.script.BaseTest; +import com.yomahub.liteflow.test.script.kotlin.contextbean.bean.CheckContext; +import com.yomahub.liteflow.test.script.kotlin.contextbean.bean.Order2Context; +import com.yomahub.liteflow.test.script.kotlin.contextbean.bean.OrderContext; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +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.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; + +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/contextbean/application.properties") +@SpringBootTest(classes = LiteFlowScriptContextbeanKotlinELTest.class) +@EnableAutoConfiguration +@ComponentScan({ "com.yomahub.liteflow.test.script.kotlin.contextbean.cmp", + "com.yomahub.liteflow.test.script.kotlin.contextbean.bean" }) +public class LiteFlowScriptContextbeanKotlinELTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testContextBean1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class, + Order2Context.class); + Assertions.assertTrue(response.isSuccess()); + OrderContext orderContext = response.getContextBean(OrderContext.class); + CheckContext checkContext = response.getContextBean(CheckContext.class); + Order2Context order2Context = response.getContextBean(Order2Context.class); + Assertions.assertEquals("order1", orderContext.getOrderNo()); + Assertions.assertEquals("sign1", checkContext.getSign()); + Assertions.assertEquals("order2", order2Context.getOrderNo()); + } + + @Test + public void testContextBean2() throws Exception { + OrderContext orderContext = new OrderContext(); + orderContext.setOrderNo("order1"); + CheckContext checkContext = new CheckContext(); + checkContext.setSign("sign1"); + Order2Context orderContext2 = new Order2Context(); + orderContext2.setOrderNo("order2"); + LiteflowResponse response = flowExecutor.execute2Resp("chain2", null, orderContext, checkContext, + orderContext2); + Assertions.assertTrue(response.isSuccess()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/bean/CheckContext.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/bean/CheckContext.java new file mode 100644 index 00000000..9b385913 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/bean/CheckContext.java @@ -0,0 +1,28 @@ +package com.yomahub.liteflow.test.script.kotlin.contextbean.bean; + +import com.yomahub.liteflow.context.ContextBean; + +@ContextBean +public class CheckContext { + + private String sign; + + private int randomId; + + public String getSign() { + return sign; + } + + public void setSign(String sign) { + this.sign = sign; + } + + public int getRandomId() { + return randomId; + } + + public void setRandomId(int randomId) { + this.randomId = randomId; + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/bean/Order2Context.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/bean/Order2Context.java new file mode 100644 index 00000000..325548ef --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/bean/Order2Context.java @@ -0,0 +1,37 @@ +package com.yomahub.liteflow.test.script.kotlin.contextbean.bean; + +import java.util.Date; + +public class Order2Context { + + private String orderNo; + + private int orderType; + + private Date createTime; + + public String getOrderNo() { + return orderNo; + } + + public void setOrderNo(String orderNo) { + this.orderNo = orderNo; + } + + public int getOrderType() { + return orderType; + } + + public void setOrderType(int orderType) { + this.orderType = orderType; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/bean/OrderContext.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/bean/OrderContext.java new file mode 100644 index 00000000..31fcae99 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/bean/OrderContext.java @@ -0,0 +1,40 @@ +package com.yomahub.liteflow.test.script.kotlin.contextbean.bean; + +import com.yomahub.liteflow.context.ContextBean; + +import java.util.Date; + +@ContextBean("order") +public class OrderContext { + + private String orderNo; + + private int orderType; + + private Date createTime; + + public String getOrderNo() { + return orderNo; + } + + public void setOrderNo(String orderNo) { + this.orderNo = orderNo; + } + + public int getOrderType() { + return orderType; + } + + public void setOrderType(int orderType) { + this.orderType = orderType; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/cmp/ACmp.java new file mode 100644 index 00000000..811c8988 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/cmp/ACmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.contextbean.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!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/cmp/BCmp.java new file mode 100644 index 00000000..608f172b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/cmp/BCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.contextbean.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!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/cmp/CCmp.java new file mode 100644 index 00000000..a63216cb --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/cmp/CCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.contextbean.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!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/meta/LiteflowKotlinScriptMetaELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/meta/LiteflowKotlinScriptMetaELTest.java new file mode 100644 index 00000000..c941b00a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/meta/LiteflowKotlinScriptMetaELTest.java @@ -0,0 +1,37 @@ +package com.yomahub.liteflow.test.script.kotlin.meta; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.script.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +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.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; + +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/meta/application.properties") +@SpringBootTest(classes = LiteflowKotlinScriptMetaELTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.script.kotlin.meta.cmp"}) +public class LiteflowKotlinScriptMetaELTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testMeta() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("chain1", context.getData("currChainId")); + Assertions.assertEquals("arg", context.getData("requestData")); + Assertions.assertEquals("s1", context.getData("nodeId")); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/meta/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/meta/cmp/ACmp.java new file mode 100644 index 00000000..baadb1aa --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/meta/cmp/ACmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.meta.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!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/meta/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/meta/cmp/BCmp.java new file mode 100644 index 00000000..c101ba3b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/meta/cmp/BCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.meta.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!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/meta/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/meta/cmp/CCmp.java new file mode 100644 index 00000000..c02ae6b2 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/meta/cmp/CCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.meta.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!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/LiteflowKotlinScriptRefreshELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/LiteflowKotlinScriptRefreshELTest.java new file mode 100644 index 00000000..af0cd54e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/LiteflowKotlinScriptRefreshELTest.java @@ -0,0 +1,48 @@ +package com.yomahub.liteflow.test.script.kotlin.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.test.script.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +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.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; + +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/refresh/application.properties") +@SpringBootTest(classes = LiteflowKotlinScriptRefreshELTest.class) +@EnableAutoConfiguration +@ComponentScan({ "com.yomahub.liteflow.test.script.kotlin.refresh.cmp" }) +public class LiteflowKotlinScriptRefreshELTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + // 测试脚本的热重载 + @Test + public void testRefresh1() throws Exception { + // 根据配置,加载的应该是flow.xml,执行原来的规则 + LiteflowResponse responseOld = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertTrue(responseOld.isSuccess()); + Assertions.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"); + Assertions.assertTrue(responseNew.isSuccess()); + Assertions.assertEquals("d==>s1[选择脚本_改]==>b==>s2[普通脚本_新增]", responseNew.getExecuteStepStr()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/cmp/ACmp.java new file mode 100644 index 00000000..80182dad --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/cmp/ACmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.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!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/cmp/BCmp.java new file mode 100644 index 00000000..ad4d47c8 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/cmp/BCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.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!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/cmp/CCmp.java new file mode 100644 index 00000000..aa4b3795 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/cmp/CCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.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!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/cmp/DCmp.java new file mode 100644 index 00000000..2062df4d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/cmp/DCmp.java @@ -0,0 +1,24 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.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!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/remove/LiteFlowKotlinScriptRemoveELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/remove/LiteFlowKotlinScriptRemoveELTest.java new file mode 100644 index 00000000..3249d3a2 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/remove/LiteFlowKotlinScriptRemoveELTest.java @@ -0,0 +1,114 @@ +package com.yomahub.liteflow.test.script.kotlin.remove; + +import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.enums.ScriptTypeEnum; +import com.yomahub.liteflow.exception.ELParseException; +import com.yomahub.liteflow.flow.FlowBus; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.script.ScriptExecutor; +import com.yomahub.liteflow.script.ScriptExecutorFactory; +import com.yomahub.liteflow.script.exception.ScriptLoadException; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.script.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 测试脚本的卸载和重载功能 + * + * @author DaleLee + */ +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/remove/application.properties") +@SpringBootTest(classes = LiteFlowKotlinScriptRemoveELTest.class) +@EnableAutoConfiguration +public class LiteFlowKotlinScriptRemoveELTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + private ScriptExecutor scriptExecutor = ScriptExecutorFactory.loadInstance() + .getScriptExecutor(ScriptTypeEnum.KOTLIN.getDisplayName()); + + // 仅卸载脚本 + @Test + public void testUnload() { + flowExecutor.reloadRule(); + + // 获取节点id + List nodeIds = scriptExecutor.getNodeIds(); + Assertions.assertEquals(2, nodeIds.size()); + Assertions.assertTrue(nodeIds.contains("s1")); + Assertions.assertTrue(nodeIds.contains("s2")); + + // 保证脚本可以正常运行 + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals(Integer.valueOf(6), context.getData("s1")); + + // 卸载脚本 + scriptExecutor.unLoad("s1"); + response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals(ScriptLoadException.class, response.getCause().getClass()); + Assertions.assertEquals("script for node[s1] is not loaded", response.getMessage()); + + // 脚本已卸载 + Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s1")); + } + + // 卸载节点和脚本 + @Test + public void testRemove() { + flowExecutor.reloadRule(); + + // 保证脚本可以正常运行 + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals(Integer.valueOf(5), context.getData("s2")); + + // 卸载节点 + FlowBus.unloadScriptNode("s2"); + + // 旧 chain 报脚本加载错误 + response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertEquals(ScriptLoadException.class, response.getCause().getClass()); + + // 新 chian 会找不到节点 + Assertions.assertThrows(ELParseException.class, + () -> LiteFlowChainELBuilder.createChain() + .setChainId("chain3") + .setEL("THEN(s2)") + .build()); + + // 节点已卸载 + Assertions.assertFalse(FlowBus.containNode("s2")); + // 脚本已卸载 + Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s2")); + } + + // 重载脚本 + @Test + public void testReloadScript() { + flowExecutor.reloadRule(); + String script = "(bindings[\"defaultContext\"] as? DefaultContext)?.setData(\"s1\", \"abc\")"; + FlowBus.reloadScript("s1", script); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + // 执行结果变更 + Assertions.assertEquals("abc", context.getData("s1")); + // 脚本变更 + Assertions.assertEquals(FlowBus.getNode("s1").getScript(), script); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/LiteFlowScriptScriptbeanKotlinELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/LiteFlowScriptScriptbeanKotlinELTest.java new file mode 100644 index 00000000..20fc01ef --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/LiteFlowScriptScriptbeanKotlinELTest.java @@ -0,0 +1,103 @@ +package com.yomahub.liteflow.test.script.kotlin.scriptbean; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.exception.ScriptBeanMethodInvokeException; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.script.ScriptBeanManager; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.script.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +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.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.Map; + +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/scriptbean/application.properties") +@SpringBootTest(classes = LiteFlowScriptScriptbeanKotlinELTest.class) +@EnableAutoConfiguration +@ComponentScan({ "com.yomahub.liteflow.test.script.kotlin.scriptbean.cmp", + "com.yomahub.liteflow.test.script.kotlin.scriptbean.bean" }) +public class LiteFlowScriptScriptbeanKotlinELTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testScriptBean1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals("hello", context.getData("demo")); + } + + @Test + public void testScriptBean2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals("hello,kobe", context.getData("demo")); + } + + // 测试scriptBean includeMethodName配置包含情况下 + @Test + public void testScriptBean3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals("hello,kobe", context.getData("demo")); + } + + // 测试scriptBean includeMethodName配置不包含情况下 + @Test + public void testScriptBean4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals(ScriptBeanMethodInvokeException.class, response.getCause().getClass()); + } + + // 测试scriptBean excludeMethodName配置不包含情况下 + @Test + public void testScriptBean5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals("hello,kobe", context.getData("demo")); + } + + // 测试scriptBean excludeMethodName配置包含情况下 + @Test + public void testScriptBean6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals(ScriptBeanMethodInvokeException.class, response.getCause().getClass()); + } + + // 测试在ScriptBeanManager里放入上下文,实现自定义脚本引用名称 + @Test + public void testScriptBean7() throws Exception { + Map map = new HashMap<>(); + ScriptBeanManager.addScriptBean("abcCx", map); + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg", map); + Assertions.assertTrue(response.isSuccess()); + Map context = response.getFirstContextBean(); + Assertions.assertEquals("hello", context.get("demo")); + } + + //测试用构造方法的方式注入bean的场景 + @Test + public void testScriptBean8() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain8", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals("hello,jordan", context.getData("demo")); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean1.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean1.java new file mode 100644 index 00000000..8e650f77 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean1.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.script.kotlin.scriptbean.bean; + +import com.yomahub.liteflow.script.annotation.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); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean2.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean2.java new file mode 100644 index 00000000..a074ad4a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean2.java @@ -0,0 +1,12 @@ +package com.yomahub.liteflow.test.script.kotlin.scriptbean.bean; + +import org.springframework.stereotype.Component; + +@Component +public class DemoBean2 { + + public String getDemoStr2(String name) { + return "hello," + name; + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean3.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean3.java new file mode 100644 index 00000000..4e31d7b8 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean3.java @@ -0,0 +1,22 @@ +package com.yomahub.liteflow.test.script.kotlin.scriptbean.bean; + +import com.yomahub.liteflow.script.annotation.ScriptBean; +import org.springframework.stereotype.Component; + +@Component +@ScriptBean(name = "demo3", includeMethodName = { "test1", "test2" }) +public class DemoBean3 { + + public String test1(String name) { + return "hello," + name; + } + + public String test2(String name) { + return "hello," + name; + } + + public String test3(String name) { + return "hello," + name; + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean4.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean4.java new file mode 100644 index 00000000..d473f716 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean4.java @@ -0,0 +1,22 @@ +package com.yomahub.liteflow.test.script.kotlin.scriptbean.bean; + +import com.yomahub.liteflow.script.annotation.ScriptBean; +import org.springframework.stereotype.Component; + +@Component +@ScriptBean(name = "demo4", excludeMethodName = { "test2", "test3" }) +public class DemoBean4 { + + public String test1(String name) { + return "hello," + name; + } + + public String test2(String name) { + return "hello," + name; + } + + public String test3(String name) { + return "hello," + name; + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean5.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean5.java new file mode 100644 index 00000000..7f64ba0c --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean5.java @@ -0,0 +1,24 @@ +package com.yomahub.liteflow.test.script.kotlin.scriptbean.bean; + +import com.yomahub.liteflow.script.annotation.ScriptBean; +import org.springframework.stereotype.Component; + +@Component +@ScriptBean("demo5") +public class DemoBean5 { + + private final DemoBean2 demoBean2; + + public DemoBean5(DemoBean2 demoBean2) { + this.demoBean2 = demoBean2; + } + + public String getDemoStr1() { + return "hello"; + } + + public String getDemoStr2(String name) { + return demoBean2.getDemoStr2(name); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/cmp/ACmp.java new file mode 100644 index 00000000..a1531df6 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/cmp/ACmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.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!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/cmp/BCmp.java new file mode 100644 index 00000000..eac2a2db --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/cmp/BCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.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!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/cmp/CCmp.java new file mode 100644 index 00000000..8c244ff4 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/cmp/CCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.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!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/LiteFlowScriptScriptMethodKotlinELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/LiteFlowScriptScriptMethodKotlinELTest.java new file mode 100644 index 00000000..651796fb --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/LiteFlowScriptScriptMethodKotlinELTest.java @@ -0,0 +1,45 @@ +package com.yomahub.liteflow.test.script.kotlin.scriptmethod; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.script.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +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.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; + +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/scriptmethod/application.properties") +@SpringBootTest(classes = LiteFlowScriptScriptMethodKotlinELTest.class) +@EnableAutoConfiguration +@ComponentScan({ "com.yomahub.liteflow.test.script.kotlin.scriptmethod.cmp", + "com.yomahub.liteflow.test.script.kotlin.scriptmethod.bean" }) +public class LiteFlowScriptScriptMethodKotlinELTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testScriptBean1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals("hello", context.getData("demo")); + } + + @Test + public void testScriptBean2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals("hello,kobe", context.getData("demo")); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/bean/DemoBean1.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/bean/DemoBean1.java new file mode 100644 index 00000000..640ef677 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/bean/DemoBean1.java @@ -0,0 +1,24 @@ +package com.yomahub.liteflow.test.script.kotlin.scriptmethod.bean; + +import com.yomahub.liteflow.script.annotation.ScriptMethod; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +@Component +public class DemoBean1 { + + @Resource + private DemoBean2 demoBean2; + + @ScriptMethod("demo") + public String getDemoStr1() { + return "hello"; + } + + @ScriptMethod("demo2") + public String getDemoStr2(String name) { + return demoBean2.getDemoStr2(name); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/bean/DemoBean2.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/bean/DemoBean2.java new file mode 100644 index 00000000..db6a06dc --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/bean/DemoBean2.java @@ -0,0 +1,12 @@ +package com.yomahub.liteflow.test.script.kotlin.scriptmethod.bean; + +import org.springframework.stereotype.Component; + +@Component +public class DemoBean2 { + + public String getDemoStr2(String name) { + return "hello," + name; + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/cmp/ACmp.java new file mode 100644 index 00000000..fe678737 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/cmp/ACmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.scriptmethod.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!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/cmp/BCmp.java new file mode 100644 index 00000000..af4217e6 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/cmp/BCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.scriptmethod.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!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/cmp/CCmp.java new file mode 100644 index 00000000..ea5401aa --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/cmp/CCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.scriptmethod.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!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/throwException/TestException.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/throwException/TestException.java new file mode 100644 index 00000000..c4f2be49 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/throwException/TestException.java @@ -0,0 +1,15 @@ +package com.yomahub.liteflow.test.script.kotlin.throwException; + +import com.yomahub.liteflow.exception.LiteFlowException; + +public class TestException extends LiteFlowException { + + public TestException(String message) { + super(message); + } + + public TestException(String code, String message) { + super(code, message); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/throwException/ThrowExceptionScriptKotlinELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/throwException/ThrowExceptionScriptKotlinELTest.java new file mode 100644 index 00000000..2dd09ccc --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/throwException/ThrowExceptionScriptKotlinELTest.java @@ -0,0 +1,37 @@ +package com.yomahub.liteflow.test.script.kotlin.throwException; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.test.script.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +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.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; + +/** + * 测试 springboot下的 Kotlin 脚本抛错 + */ +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/throwException/application.properties") +@SpringBootTest(classes = ThrowExceptionScriptKotlinELTest.class) +@EnableAutoConfiguration +@ComponentScan({ "com.yomahub.liteflow.test.script.kotlin.throwException.cmp" }) +public class ThrowExceptionScriptKotlinELTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void test1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals("T01", response.getCode()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/throwException/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/throwException/cmp/ACmp.java new file mode 100644 index 00000000..7c41ce79 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/throwException/cmp/ACmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.throwException.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!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/validate/ValidateKotlinScriptComponentTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/validate/ValidateKotlinScriptComponentTest.java new file mode 100644 index 00000000..841d5933 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/validate/ValidateKotlinScriptComponentTest.java @@ -0,0 +1,33 @@ +package com.yomahub.liteflow.test.script.kotlin.validate; + +import com.yomahub.liteflow.enums.ScriptTypeEnum; +import com.yomahub.liteflow.script.ScriptExecutor; +import com.yomahub.liteflow.script.ScriptExecutorFactory; +import com.yomahub.liteflow.script.validator.ScriptValidator; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; + +import javax.script.Compilable; +import javax.script.ScriptEngine; +import javax.script.ScriptEngineManager; +import javax.script.ScriptException; + +@SpringBootTest(classes = ValidateKotlinScriptComponentTest.class) +@EnableAutoConfiguration +public class ValidateKotlinScriptComponentTest { + @Test + public void testScriptComponentValidateFunction() throws Exception { + // 编译错误,字符串不能直接赋值给Int + String wrongScript = "val number: Int = \"123\""; + // 使用转换函数 + String correctScript = "val number: Int = \"123\".toInt()"; + + Assertions.assertTrue(ScriptValidator.validate(correctScript)); + Assertions.assertFalse(ScriptValidator.validate(wrongScript)); + + Assertions.assertTrue(ScriptValidator.validate(correctScript, ScriptTypeEnum.KOTLIN)); + Assertions.assertFalse(ScriptValidator.validate(correctScript, ScriptTypeEnum.JS)); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/cmpdata/application.properties b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/cmpdata/application.properties new file mode 100644 index 00000000..4cc9f322 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/cmpdata/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=cmpdata/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/cmpdata/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/cmpdata/flow.xml new file mode 100644 index 00000000..889ae01e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/cmpdata/flow.xml @@ -0,0 +1,25 @@ + + + + + + + var cmpData = _meta["cmpData"] as Map + var context = bindings["defaultContext"] as DefaultContext + context.setData("s1", cmpData["birth"]) + ]]> + + + + + cmpData = '{"name":"jack","age":27,"birth":"1995-10-01"}'; + + THEN( + s1.data(cmpData), + a + ); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/common/application.properties b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/common/application.properties new file mode 100644 index 00000000..4c9c216b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/common/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=common/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/common/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/common/flow.xml new file mode 100644 index 00000000..47d5e480 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/common/flow.xml @@ -0,0 +1,99 @@ + + + + + + + + + + + 1 + // 函数名可以自定义,但必须返回 Boolean + getBoolean1() + ]]> + + + + + + + + + + + + + + + THEN(a, b, c, s1); + + + + FOR(s2).DO(a); + + + + IF(s3, b); + + + + IF(s4, b); + + + + WHILE(s3).DO(b).BREAK(s6); + + + + SWITCH(s5).TO(a, b, c); + + + + THEN(s7); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/contextbean/application.properties b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/contextbean/application.properties new file mode 100644 index 00000000..25ff2335 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/contextbean/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=contextbean/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/contextbean/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/contextbean/flow.xml new file mode 100644 index 00000000..a7a290a7 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/contextbean/flow.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + THEN(a,b,c,d); + + + + THEN(a,b,c,e); + + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/meta/application.properties b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/meta/application.properties new file mode 100644 index 00000000..8d005372 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/meta/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=meta/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/meta/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/meta/flow.xml new file mode 100644 index 00000000..ff49ec51 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/meta/flow.xml @@ -0,0 +1,24 @@ + + + + + + var nodeId = _meta["nodeId"] + var currChainId = _meta["currChainId"] + var requestData = _meta["requestData"] + + var context = bindings["defaultContext"] as DefaultContext + context.setData("nodeId",nodeId) + context.setData("currChainId",currChainId) + context.setData("requestData",requestData) + ]]> + + + + + THEN(a, b, c, s1); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/refresh/application.properties b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/refresh/application.properties new file mode 100644 index 00000000..52bc92b9 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/refresh/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=refresh/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/refresh/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/refresh/flow.xml new file mode 100644 index 00000000..b74f49ba --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/refresh/flow.xml @@ -0,0 +1,27 @@ + + + + + 100) { + return "a"; + } else { + return "b"; + } + } + getId() + ]]> + + + + + + THEN(d, SWITCH(s1).to(a,b)); + + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/refresh/flow_update.xml b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/refresh/flow_update.xml new file mode 100644 index 00000000..94eebfa5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/refresh/flow_update.xml @@ -0,0 +1,36 @@ + + + + + 100) { + return "b"; + } else { + return "a"; + } + } + getId() + ]]> + + + + + + + + + THEN(d, SWITCH(s1).to(a,b), s2); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/remove/application.properties b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/remove/application.properties new file mode 100644 index 00000000..21b59625 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/remove/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=remove/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/remove/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/remove/flow.xml new file mode 100644 index 00000000..84c3a55c --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/remove/flow.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + THEN(s1); + + + + THEN(s2); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/script-file/s7.kts b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/script-file/s7.kts new file mode 100644 index 00000000..0b610789 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/script-file/s7.kts @@ -0,0 +1,6 @@ +import com.yomahub.liteflow.slot.DefaultContext + +var a = 2 +var b = 3 +val defaultContext = bindings["defaultContext"] as DefaultContext +defaultContext.setData("s7", a * b) \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/scriptbean/application.properties b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/scriptbean/application.properties new file mode 100644 index 00000000..8c26b5e8 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/scriptbean/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=scriptbean/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/scriptbean/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/scriptbean/flow.xml new file mode 100644 index 00000000..0edabf7a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/scriptbean/flow.xml @@ -0,0 +1,134 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + abcCx.put("demo", str) + ]]> + + + + + + + + + THEN(a,b,c,d); + + + + THEN(a,b,c,e); + + + + THEN(a,b,c,s1); + + + + THEN(a,b,c,s2); + + + + THEN(a,b,c,s3); + + + + THEN(a,b,c,s4); + + + + THEN(a,b,c,s5); + + + + THEN(a,b,c,f); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/scriptmethod/application.properties b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/scriptmethod/application.properties new file mode 100644 index 00000000..1f247a58 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/scriptmethod/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=scriptmethod/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/scriptmethod/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/scriptmethod/flow.xml new file mode 100644 index 00000000..22f069ff --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/scriptmethod/flow.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + THEN(a,b,c,d); + + + + THEN(a,b,c,e); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/throwException/application.properties b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/throwException/application.properties new file mode 100644 index 00000000..c30228a4 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/throwException/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=throwException/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/throwException/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/throwException/flow.xml new file mode 100644 index 00000000..b215e766 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/throwException/flow.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + THEN(a, s1); + + \ No newline at end of file diff --git a/liteflow-testcase-el/pom.xml b/liteflow-testcase-el/pom.xml index 7323492c..7c3ba26e 100644 --- a/liteflow-testcase-el/pom.xml +++ b/liteflow-testcase-el/pom.xml @@ -39,6 +39,7 @@ liteflow-testcase-el-script-java-springboot liteflow-testcase-el-builder liteflow-testcase-el-routechain + liteflow-testcase-el-script-kotlin-springboot diff --git a/pom.xml b/pom.xml index 8fdff57a..439f5668 100644 --- a/pom.xml +++ b/pom.xml @@ -76,6 +76,7 @@ 1.3.5 3.21.0 3.1.11 + 1.9.23 @@ -314,6 +315,11 @@ redisson ${redisson.version} + + org.jetbrains.kotlin + kotlin-scripting-jsr223 + ${kotlin.version} +