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 f350b4169b4a9be9a6fe22f58a54f9f77c501111..c9a62570afd139ba3df8428485198879882bbb3b 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 0000000000000000000000000000000000000000..df3bed9dae03ae9cc7e50d82bf414d9df710c092 --- /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 0000000000000000000000000000000000000000..acdc490d02e176c28a9d7620e751dc44baab2c43 --- /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 0000000000000000000000000000000000000000..ccce7e1fbd7a3430de7cf635b60a7069a159137d --- /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 2c43fa16c40690f9c22d30223d8fa42fc7421b46..a188cd04be030154cc344fedb46f2e4581c57e50 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 0000000000000000000000000000000000000000..0563cb2d50d72d8e9e52a68eb70732b413290f20 --- /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 0000000000000000000000000000000000000000..6cb71ce880112f2ceda1fcdab1566c1d4e0b70b7 --- /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 0000000000000000000000000000000000000000..c950c67dd59524f5b18ee5dca105743ea693a710 --- /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 0000000000000000000000000000000000000000..1de2ccb9d25000a4cd2202fd85c8bc35219974c2 --- /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 0000000000000000000000000000000000000000..17b619668c8668957f058afbeb78f703cfaac5ea --- /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 0000000000000000000000000000000000000000..895686f1754df3aba3feb2b425eede2ecc78e95c --- /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 0000000000000000000000000000000000000000..1c4eb649633a6a3706004de6202e0588cf225ea0 --- /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 0000000000000000000000000000000000000000..661e979a02fdde37336a30854af2e781fecbbf2b --- /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 0000000000000000000000000000000000000000..d0bdba3963f5330826e4283a9cb9f18c256ecd00 --- /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 0000000000000000000000000000000000000000..9b385913eb7824c14e88f0f022eb09104fb956a4 --- /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 0000000000000000000000000000000000000000..325548ef5150af223024da14df21c29ea5823d7e --- /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 0000000000000000000000000000000000000000..31fcae9988eb16164a8470816314d0eec0aad364 --- /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 0000000000000000000000000000000000000000..811c898898ad6ca42186173b58e66fa7130e46db --- /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 0000000000000000000000000000000000000000..608f172b545d672c5c85eb5ac36db2624b453ff5 --- /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 0000000000000000000000000000000000000000..a63216cb436b109e79f3730dd61bacac78993ca4 --- /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 0000000000000000000000000000000000000000..c941b00a5e61c8165047eb432d9e4cf33391ffeb --- /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 0000000000000000000000000000000000000000..baadb1aaeae3bdb7aa262fa3c4114edce96afb24 --- /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 0000000000000000000000000000000000000000..c101ba3b403d8ee59c30ada00d4e06b1eb5d187e --- /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 0000000000000000000000000000000000000000..c02ae6b2af1c46509baea912af6dddb6a0dcbe1d --- /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 0000000000000000000000000000000000000000..af0cd54eee4ede7a09be4a8f7ba8308686254f1b --- /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 0000000000000000000000000000000000000000..80182dad6ab6e491900f9eb5ec8e95ea02cd7f26 --- /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 0000000000000000000000000000000000000000..ad4d47c82de76f364edc5251dda412bde6719435 --- /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 0000000000000000000000000000000000000000..aa4b37950980e9f37ad870bb503acfa5ec61c6d9 --- /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 0000000000000000000000000000000000000000..2062df4d5ce429d4b66ec2c1e8098041661baeea --- /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 0000000000000000000000000000000000000000..3249d3a22b2f1cd95e4fdc07cf190a83d13a8cc6 --- /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 0000000000000000000000000000000000000000..20fc01efb18a9047e48819aff7b92bf6b53df4d1 --- /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 0000000000000000000000000000000000000000..8e650f7746cc9bdba281f321ab836b18e319c33e --- /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 0000000000000000000000000000000000000000..a074ad4aecc19d4fb3f714b567a554069b2b2d93 --- /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 0000000000000000000000000000000000000000..4e31d7b8d7fc71faa7266deb1d2c5483008f88ab --- /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 0000000000000000000000000000000000000000..d473f7163e0e34f1aa58770d3822d8745a81d35c --- /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 0000000000000000000000000000000000000000..7f64ba0c3bbe54ddb1559ea336549435fab5c608 --- /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 0000000000000000000000000000000000000000..a1531df6bdb90ade882f7df66901a913abd9a6b3 --- /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 0000000000000000000000000000000000000000..eac2a2dbb1764f96ea5eb46bf9f362955cc50464 --- /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 0000000000000000000000000000000000000000..8c244ff404dc38fdbb5c21ea32b041cfcefd252a --- /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 0000000000000000000000000000000000000000..651796fb36282b4fcfcc2d493d61a4cd31e2cb8f --- /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 0000000000000000000000000000000000000000..640ef677e2f116da065dd698a3cd834a41c8c033 --- /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 0000000000000000000000000000000000000000..db6a06dce33a4c5c9c27a1b2b065e560bd36404f --- /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 0000000000000000000000000000000000000000..fe678737ebbb53bc455f4ed2ac3ee999c17e9382 --- /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 0000000000000000000000000000000000000000..af4217e6e2753e12f30b66e72a0c71561b693cea --- /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 0000000000000000000000000000000000000000..ea5401aa8d5d97c7f460c02f11a758a974769538 --- /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 0000000000000000000000000000000000000000..c4f2be49b89b0c3e77137ae8df8c8077bd454f8e --- /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 0000000000000000000000000000000000000000..2dd09ccc11d5c57e3b9e4852e895fb4c0455c1f1 --- /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 0000000000000000000000000000000000000000..7c41ce79e2c8a397deedc4bef5257fc242493c4d --- /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 0000000000000000000000000000000000000000..841d5933c74c71f316a75707627e103b2084c9d6 --- /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 0000000000000000000000000000000000000000..4cc9f322d6353e8a2b1be001557e157e4030e790 --- /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 0000000000000000000000000000000000000000..889ae01eb607b5f5f83746c7e568f201c741e06f --- /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 0000000000000000000000000000000000000000..4c9c216b605f905fdf6aee5ddc7af8db74598c72 --- /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 0000000000000000000000000000000000000000..47d5e480bfdc18b03aa194afc8ce274e2128ff03 --- /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 0000000000000000000000000000000000000000..25ff2335ad9f3972ac438f1beb8d8bea3bd94206 --- /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 0000000000000000000000000000000000000000..a7a290a7fb77a9240b73922c6c958db82807ee5a --- /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 0000000000000000000000000000000000000000..8d0053721bc9f56c78f76d0e92d629be343db071 --- /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 0000000000000000000000000000000000000000..ff49ec51d257c0a3f7bf667570d612d83aa734a5 --- /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 0000000000000000000000000000000000000000..52bc92b9491a1d09a25f66fa4bbcca6d73ef5b67 --- /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 0000000000000000000000000000000000000000..b74f49ba7bb73b1a35935d9af07371eb6c24bc8d --- /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 0000000000000000000000000000000000000000..94eebfa59746a1061c50be60846c06ca6b3fcc01 --- /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 0000000000000000000000000000000000000000..21b596255201080ea2a9e7ce9d65fee7181db82c --- /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 0000000000000000000000000000000000000000..84c3a55ccf9506c865a9875bd046c5a2d9eda480 --- /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 0000000000000000000000000000000000000000..0b6107897194d4a51150377fae919afc0e5b78ee --- /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 0000000000000000000000000000000000000000..8c26b5e8033967c222422631d2be579ab96d1192 --- /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 0000000000000000000000000000000000000000..0edabf7a9597478767ffc1c5bf0c0d5706189faf --- /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 0000000000000000000000000000000000000000..1f247a584b80d5c02ed5fc7e0572b42f87a1edde --- /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 0000000000000000000000000000000000000000..22f069ffc5e0580444629a7d4189e206fcb1c7c2 --- /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 0000000000000000000000000000000000000000..c30228a45e7b6f5ace58964d33be3a431cf1c578 --- /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 0000000000000000000000000000000000000000..b215e766b4db04b8b176700e490e9c69db6b19bf --- /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 7323492cf93efc183741c56ef199dff1bf710828..7c3ba26e053500ce31df48be58b5fe6b60c3d711 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 fe2b4d1de43afbfab175a2c26312abd354e37af4..793082b57154c0e3a740b0bce89f8abe1d53fd7a 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} +