From 33f05eb7cc23de57fb8ab7fac65d47b186488692 Mon Sep 17 00:00:00 2001
From: Dale Lee <1658850308@qq.com>
Date: Thu, 2 May 2024 15:33:16 +0800
Subject: [PATCH 1/4] =?UTF-8?q?feature=20#I9H6GN=20=E6=94=AF=E6=8C=81=20ko?=
=?UTF-8?q?tlin=20=E8=84=9A=E6=9C=AC=E8=AF=AD=E8=A8=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../liteflow/enums/ScriptTypeEnum.java | 3 +-
.../liteflow-script-kotlin/pom.xml | 29 ++++++
.../script/kotlin/KotlinScriptExecutor.java | 15 +++
...com.yomahub.liteflow.script.ScriptExecutor | 2 +
liteflow-script-plugin/pom.xml | 1 +
.../pom.xml | 32 +++++++
.../liteflow/test/script/BaseTest.java | 24 +++++
.../liteflow/test/script/kotlin/T2.java | 93 +++++++++++++++++++
.../test/script/kotlin/TestKotlin.java | 49 ++++++++++
.../LiteFlowKotlinScriptCommonELTest.java | 68 ++++++++++++++
.../test/script/kotlin/common/cmp/ACmp.java | 21 +++++
.../test/script/kotlin/common/cmp/BCmp.java | 21 +++++
.../test/script/kotlin/common/cmp/CCmp.java | 21 +++++
.../resources/common/application.properties | 1 +
.../src/test/resources/common/flow.xml | 72 ++++++++++++++
liteflow-testcase-el/pom.xml | 1 +
16 files changed, 452 insertions(+), 1 deletion(-)
create mode 100644 liteflow-script-plugin/liteflow-script-kotlin/pom.xml
create mode 100644 liteflow-script-plugin/liteflow-script-kotlin/src/main/java/com/yomahub/liteflow/script/kotlin/KotlinScriptExecutor.java
create mode 100644 liteflow-script-plugin/liteflow-script-kotlin/src/main/resources/META-INF/services/com.yomahub.liteflow.script.ScriptExecutor
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/pom.xml
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/BaseTest.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/T2.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/TestKotlin.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/LiteFlowKotlinScriptCommonELTest.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/cmp/ACmp.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/cmp/BCmp.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/cmp/CCmp.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/common/application.properties
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/common/flow.xml
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 f350b4169..c9a62570a 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 000000000..c89e6d796
--- /dev/null
+++ b/liteflow-script-plugin/liteflow-script-kotlin/pom.xml
@@ -0,0 +1,29 @@
+
+
+
+ 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
+ 1.9.23
+
+
+
\ 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 000000000..acdc490d0
--- /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 000000000..ccce7e1fb
--- /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 2c43fa16c..a188cd04b 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 000000000..e76dca32f
--- /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
+ 2.12.0
+ 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 000000000..6cb71ce88
--- /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/T2.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/T2.java
new file mode 100644
index 000000000..564cb33a3
--- /dev/null
+++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/T2.java
@@ -0,0 +1,93 @@
+package com.yomahub.liteflow.test.script.kotlin;
+
+import com.yomahub.liteflow.slot.DefaultContext;
+import org.junit.jupiter.api.Test;
+
+import javax.script.Bindings;
+import javax.script.Compilable;
+import javax.script.CompiledScript;
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+import javax.script.ScriptException;
+import javax.script.SimpleBindings;
+
+public class T2 {
+ @Test
+ public void test1() throws ScriptException {
+ // 初始化 ScriptEngineManager 和 Kotlin 脚本引擎
+ ScriptEngineManager manager = new ScriptEngineManager();
+ ScriptEngine engine = manager.getEngineByName("kotlin");
+
+ if (engine == null) {
+ throw new IllegalStateException("Kotlin script engine not found");
+ }
+
+ // 假设我们有以下Kotlin脚本,它期望一个名为'message'的外部参数
+ String script = "fun greet(name: String) {\n" +
+ " println(\"Hello, $name!\")\n" +
+ " }\n" +
+ " println(bindings[\"message\"])";
+
+
+ // 编译脚本为CompiledScript对象
+ Compilable compilable = (Compilable) engine;
+ CompiledScript compiledScript = compilable.compile(script);
+
+ // 准备脚本上下文,用于传递外部参数
+ Bindings bindings = engine.createBindings();
+ // 设置外部参数
+ bindings.put("message", "User");
+
+ // 使用相同的上下文多次执行已编译的脚本
+ for (int i = 0; i < 2; i++) {
+ compiledScript.eval(bindings);
+ }
+// engine.put("message","User");
+// engine.eval(script);
+ //engine.eval(script,bindings);
+ }
+
+ @Test
+ public void test2() throws ScriptException {
+ ScriptEngineManager manager = new ScriptEngineManager();
+ ScriptEngine engine = manager.getEngineByName("kotlin");
+ String script = "" +
+ "var defaultContext = bindings[\"defaultContext\"]\n" +
+ "println(defaultContext.getData(\"key\"))";
+ // 编译脚本为CompiledScript对象
+ Compilable compilable = (Compilable) engine;
+ CompiledScript compiledScript = compilable.compile(script);
+
+ // 准备脚本上下文,用于传递外部参数
+ Bindings bindings = new SimpleBindings();
+ DefaultContext context = new DefaultContext();
+ context.setData("key", "value");
+ // 设置外部参数
+ bindings.put("defaultContext", context);
+ compiledScript.eval(bindings);
+ }
+
+ @Test
+ public void test3() throws ScriptException {
+ ScriptEngineManager manager = new ScriptEngineManager();
+ ScriptEngine engine = manager.getEngineByName("kotlin");
+ String script =
+ "fun getNum() = 15\n" +
+ "getNum()";
+
+ // 编译脚本为CompiledScript对象
+ Compilable compilable = (Compilable) engine;
+ CompiledScript compiledScript = compilable.compile(script);
+
+ // 准备脚本上下文,用于传递外部参数
+// Bindings bindings = new SimpleBindings();
+// DefaultContext context = new DefaultContext();
+// context.setData("key", "value");
+// // 设置外部参数
+// bindings.put("defaultContext", context);
+ /* Object res = compiledScript.eval();
+ System.out.println(res);*/
+ Object eval = engine.eval(script);
+ System.out.println(eval);
+ }
+}
diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/TestKotlin.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/TestKotlin.java
new file mode 100644
index 000000000..7ddd0a878
--- /dev/null
+++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/TestKotlin.java
@@ -0,0 +1,49 @@
+package com.yomahub.liteflow.test.script.kotlin;
+
+import com.yomahub.liteflow.enums.ScriptTypeEnum;
+
+import javax.script.Compilable;
+import javax.script.CompiledScript;
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+import javax.script.ScriptException;
+
+public class TestKotlin {
+ public static void main(String[] args) throws ScriptException, NoSuchMethodException {
+ // 获取脚本引擎管理器
+ ScriptEngineManager manager = new ScriptEngineManager();
+
+ // 获取Kotlin脚本引擎
+ ScriptEngine engine = manager.getEngineByName(ScriptTypeEnum.KOTLIN.getEngineName()); // ".kts" 是Kotlin脚本文件的扩展名
+
+ // 检查是否找到了Kotlin脚本引擎
+ if (engine == null) {
+ System.out.println("No Kotlin script engine found.");
+ return;
+ }
+
+ System.out.println(engine instanceof Compilable);
+
+ // 定义一个Kotlin脚本
+ String script = "println(\"Hello, Kotlin JSR 223!\")";
+
+ Compilable compilable = (Compilable) engine;
+ CompiledScript compile = compilable.compile(script);
+ compile.eval();
+
+
+ // 编译并执行脚本
+ engine.eval(script);
+
+ // 如果ScriptEngine也实现了Invocable接口,我们可以调用脚本中的函数
+// if (engine instanceof Invocable) {
+// Invocable inv = (Invocable) engine;
+//
+// // 调用脚本中的greet函数
+// String greeting = (String) inv.invokeFunction("greet", "World");
+// System.out.println(greeting); // 输出: Hello, World!
+// } else {
+// System.out.println("The script engine does not support Invocable interface.");
+// }
+ }
+}
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 000000000..49629ce31
--- /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,68 @@
+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;
+
+@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 testCommon1() {
+ LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
+ Assertions.assertTrue(response.isSuccess());
+ DefaultContext context = response.getFirstContextBean();
+ Assertions.assertEquals(Integer.valueOf(5), context.getData("s1"));
+ }
+
+ @Test
+ public void testFor1() {
+ DefaultContext context = new DefaultContext();
+ context.setData("k1", 1);
+ context.setData("k2", 2);
+ LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg", context);
+ Assertions.assertTrue(response.isSuccess());
+ Assertions.assertEquals("s2==>a==>a==>a",response.getExecuteStepStr());
+ }
+
+ @Test
+ public void testIf1() {
+ LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg");
+ Assertions.assertTrue(response.isSuccess());
+ Assertions.assertEquals("s3==>b",response.getExecuteStepStr());
+ }
+
+ @Test
+ public void testIf2() {
+ LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg");
+ Assertions.assertTrue(response.isSuccess());
+ Assertions.assertEquals("s4",response.getExecuteStepStr());
+ }
+
+ @Test
+ public void testSwitch1() {
+ DefaultContext context = new DefaultContext();
+ context.setData("id", "c");
+ LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg", context);
+ Assertions.assertTrue(response.isSuccess());
+ Assertions.assertEquals("s5==>c",response.getExecuteStepStr());
+ }
+}
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 000000000..895686f17
--- /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 000000000..1c4eb6496
--- /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 000000000..661e979a0
--- /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/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 000000000..4c9c216b6
--- /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 000000000..35db6f006
--- /dev/null
+++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/common/flow.xml
@@ -0,0 +1,72 @@
+
+
+
+
+
+
+
+
+
+
+ 1
+ getBoolean1()
+ ]]>
+
+
+
+
+
+
+
+
+
+
+ THEN(a, b, c, s1);
+
+
+
+ FOR(s2).DO(a);
+
+
+
+ IF(s3, b);
+
+
+
+ IF(s4, b);
+
+
+
+ SWITCH(s5).TO(a, b, c);
+
+
\ No newline at end of file
diff --git a/liteflow-testcase-el/pom.xml b/liteflow-testcase-el/pom.xml
index 7323492cf..7c3ba26e0 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
--
Gitee
From c3a64bd0f492dc4128390f96f31ef5648b4c7923 Mon Sep 17 00:00:00 2001
From: Dale Lee <1658850308@qq.com>
Date: Thu, 2 May 2024 22:25:50 +0800
Subject: [PATCH 2/4] =?UTF-8?q?feature=20#I9H6GN=20=E5=AE=8C=E5=96=84?=
=?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../liteflow/test/script/kotlin/T2.java | 93 ------------
.../test/script/kotlin/TestKotlin.java | 49 -------
.../LiteFlowCmpDataKotlinScriptELTest.java | 36 +++++
.../test/script/kotlin/cmpdata/cmp/ACmp.java | 22 +++
.../LiteFlowKotlinScriptCommonELTest.java | 51 +++++--
...LiteFlowScriptContextbeanKotlinELTest.java | 57 ++++++++
.../kotlin/contextbean/bean/CheckContext.java | 28 ++++
.../contextbean/bean/Order2Context.java | 37 +++++
.../kotlin/contextbean/bean/OrderContext.java | 40 ++++++
.../script/kotlin/contextbean/cmp/ACmp.java | 21 +++
.../script/kotlin/contextbean/cmp/BCmp.java | 21 +++
.../script/kotlin/contextbean/cmp/CCmp.java | 21 +++
.../meta/LiteflowKotlinScriptMetaELTest.java | 37 +++++
.../test/script/kotlin/meta/cmp/ACmp.java | 21 +++
.../test/script/kotlin/meta/cmp/BCmp.java | 21 +++
.../test/script/kotlin/meta/cmp/CCmp.java | 21 +++
.../LiteflowKotlinScriptRefreshELTest.java | 48 +++++++
.../test/script/kotlin/refresh/cmp/ACmp.java | 21 +++
.../test/script/kotlin/refresh/cmp/BCmp.java | 21 +++
.../test/script/kotlin/refresh/cmp/CCmp.java | 21 +++
.../test/script/kotlin/refresh/cmp/DCmp.java | 24 ++++
.../LiteFlowKotlinScriptRemoveELTest.java | 114 +++++++++++++++
.../LiteFlowScriptScriptbeanKotlinELTest.java | 103 ++++++++++++++
.../kotlin/scriptbean/bean/DemoBean1.java | 23 +++
.../kotlin/scriptbean/bean/DemoBean2.java | 12 ++
.../kotlin/scriptbean/bean/DemoBean3.java | 22 +++
.../kotlin/scriptbean/bean/DemoBean4.java | 22 +++
.../kotlin/scriptbean/bean/DemoBean5.java | 24 ++++
.../script/kotlin/scriptbean/cmp/ACmp.java | 21 +++
.../script/kotlin/scriptbean/cmp/BCmp.java | 21 +++
.../script/kotlin/scriptbean/cmp/CCmp.java | 21 +++
...iteFlowScriptScriptMethodKotlinELTest.java | 45 ++++++
.../kotlin/scriptmethod/bean/DemoBean1.java | 24 ++++
.../kotlin/scriptmethod/bean/DemoBean2.java | 12 ++
.../script/kotlin/scriptmethod/cmp/ACmp.java | 21 +++
.../script/kotlin/scriptmethod/cmp/BCmp.java | 21 +++
.../script/kotlin/scriptmethod/cmp/CCmp.java | 21 +++
.../kotlin/throwException/TestException.java | 15 ++
.../ThrowExceptionScriptKotlinELTest.java | 37 +++++
.../kotlin/throwException/cmp/ACmp.java | 21 +++
.../ValidateKotlinScriptComponentTest.java | 26 ++++
.../resources/cmpdata/application.properties | 1 +
.../src/test/resources/cmpdata/flow.xml | 27 ++++
.../src/test/resources/common/flow.xml | 41 +++++-
.../contextbean/application.properties | 1 +
.../src/test/resources/contextbean/flow.xml | 45 ++++++
.../resources/meta/application.properties | 1 +
.../src/test/resources/meta/flow.xml | 24 ++++
.../resources/refresh/application.properties | 1 +
.../src/test/resources/refresh/flow.xml | 27 ++++
.../test/resources/refresh/flow_update.xml | 36 +++++
.../resources/remove/application.properties | 1 +
.../src/test/resources/remove/flow.xml | 34 +++++
.../src/test/resources/script-file/s7.kts | 6 +
.../scriptbean/application.properties | 1 +
.../src/test/resources/scriptbean/flow.xml | 134 ++++++++++++++++++
.../scriptmethod/application.properties | 1 +
.../src/test/resources/scriptmethod/flow.xml | 37 +++++
.../throwException/application.properties | 1 +
.../test/resources/throwException/flow.xml | 17 +++
60 files changed, 1610 insertions(+), 163 deletions(-)
delete mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/T2.java
delete mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/TestKotlin.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/cmpdata/LiteFlowCmpDataKotlinScriptELTest.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/cmpdata/cmp/ACmp.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/LiteFlowScriptContextbeanKotlinELTest.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/bean/CheckContext.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/bean/Order2Context.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/bean/OrderContext.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/cmp/ACmp.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/cmp/BCmp.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/cmp/CCmp.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/meta/LiteflowKotlinScriptMetaELTest.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/meta/cmp/ACmp.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/meta/cmp/BCmp.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/meta/cmp/CCmp.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/LiteflowKotlinScriptRefreshELTest.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/cmp/ACmp.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/cmp/BCmp.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/cmp/CCmp.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/cmp/DCmp.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/remove/LiteFlowKotlinScriptRemoveELTest.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/LiteFlowScriptScriptbeanKotlinELTest.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean1.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean2.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean3.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean4.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean5.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/cmp/ACmp.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/cmp/BCmp.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/cmp/CCmp.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/LiteFlowScriptScriptMethodKotlinELTest.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/bean/DemoBean1.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/bean/DemoBean2.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/cmp/ACmp.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/cmp/BCmp.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/cmp/CCmp.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/throwException/TestException.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/throwException/ThrowExceptionScriptKotlinELTest.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/throwException/cmp/ACmp.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/validate/ValidateKotlinScriptComponentTest.java
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/cmpdata/application.properties
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/cmpdata/flow.xml
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/contextbean/application.properties
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/contextbean/flow.xml
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/meta/application.properties
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/meta/flow.xml
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/refresh/application.properties
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/refresh/flow.xml
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/refresh/flow_update.xml
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/remove/application.properties
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/remove/flow.xml
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/script-file/s7.kts
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/scriptbean/application.properties
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/scriptbean/flow.xml
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/scriptmethod/application.properties
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/scriptmethod/flow.xml
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/throwException/application.properties
create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/throwException/flow.xml
diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/T2.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/T2.java
deleted file mode 100644
index 564cb33a3..000000000
--- a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/T2.java
+++ /dev/null
@@ -1,93 +0,0 @@
-package com.yomahub.liteflow.test.script.kotlin;
-
-import com.yomahub.liteflow.slot.DefaultContext;
-import org.junit.jupiter.api.Test;
-
-import javax.script.Bindings;
-import javax.script.Compilable;
-import javax.script.CompiledScript;
-import javax.script.ScriptEngine;
-import javax.script.ScriptEngineManager;
-import javax.script.ScriptException;
-import javax.script.SimpleBindings;
-
-public class T2 {
- @Test
- public void test1() throws ScriptException {
- // 初始化 ScriptEngineManager 和 Kotlin 脚本引擎
- ScriptEngineManager manager = new ScriptEngineManager();
- ScriptEngine engine = manager.getEngineByName("kotlin");
-
- if (engine == null) {
- throw new IllegalStateException("Kotlin script engine not found");
- }
-
- // 假设我们有以下Kotlin脚本,它期望一个名为'message'的外部参数
- String script = "fun greet(name: String) {\n" +
- " println(\"Hello, $name!\")\n" +
- " }\n" +
- " println(bindings[\"message\"])";
-
-
- // 编译脚本为CompiledScript对象
- Compilable compilable = (Compilable) engine;
- CompiledScript compiledScript = compilable.compile(script);
-
- // 准备脚本上下文,用于传递外部参数
- Bindings bindings = engine.createBindings();
- // 设置外部参数
- bindings.put("message", "User");
-
- // 使用相同的上下文多次执行已编译的脚本
- for (int i = 0; i < 2; i++) {
- compiledScript.eval(bindings);
- }
-// engine.put("message","User");
-// engine.eval(script);
- //engine.eval(script,bindings);
- }
-
- @Test
- public void test2() throws ScriptException {
- ScriptEngineManager manager = new ScriptEngineManager();
- ScriptEngine engine = manager.getEngineByName("kotlin");
- String script = "" +
- "var defaultContext = bindings[\"defaultContext\"]\n" +
- "println(defaultContext.getData(\"key\"))";
- // 编译脚本为CompiledScript对象
- Compilable compilable = (Compilable) engine;
- CompiledScript compiledScript = compilable.compile(script);
-
- // 准备脚本上下文,用于传递外部参数
- Bindings bindings = new SimpleBindings();
- DefaultContext context = new DefaultContext();
- context.setData("key", "value");
- // 设置外部参数
- bindings.put("defaultContext", context);
- compiledScript.eval(bindings);
- }
-
- @Test
- public void test3() throws ScriptException {
- ScriptEngineManager manager = new ScriptEngineManager();
- ScriptEngine engine = manager.getEngineByName("kotlin");
- String script =
- "fun getNum() = 15\n" +
- "getNum()";
-
- // 编译脚本为CompiledScript对象
- Compilable compilable = (Compilable) engine;
- CompiledScript compiledScript = compilable.compile(script);
-
- // 准备脚本上下文,用于传递外部参数
-// Bindings bindings = new SimpleBindings();
-// DefaultContext context = new DefaultContext();
-// context.setData("key", "value");
-// // 设置外部参数
-// bindings.put("defaultContext", context);
- /* Object res = compiledScript.eval();
- System.out.println(res);*/
- Object eval = engine.eval(script);
- System.out.println(eval);
- }
-}
diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/TestKotlin.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/TestKotlin.java
deleted file mode 100644
index 7ddd0a878..000000000
--- a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/TestKotlin.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package com.yomahub.liteflow.test.script.kotlin;
-
-import com.yomahub.liteflow.enums.ScriptTypeEnum;
-
-import javax.script.Compilable;
-import javax.script.CompiledScript;
-import javax.script.ScriptEngine;
-import javax.script.ScriptEngineManager;
-import javax.script.ScriptException;
-
-public class TestKotlin {
- public static void main(String[] args) throws ScriptException, NoSuchMethodException {
- // 获取脚本引擎管理器
- ScriptEngineManager manager = new ScriptEngineManager();
-
- // 获取Kotlin脚本引擎
- ScriptEngine engine = manager.getEngineByName(ScriptTypeEnum.KOTLIN.getEngineName()); // ".kts" 是Kotlin脚本文件的扩展名
-
- // 检查是否找到了Kotlin脚本引擎
- if (engine == null) {
- System.out.println("No Kotlin script engine found.");
- return;
- }
-
- System.out.println(engine instanceof Compilable);
-
- // 定义一个Kotlin脚本
- String script = "println(\"Hello, Kotlin JSR 223!\")";
-
- Compilable compilable = (Compilable) engine;
- CompiledScript compile = compilable.compile(script);
- compile.eval();
-
-
- // 编译并执行脚本
- engine.eval(script);
-
- // 如果ScriptEngine也实现了Invocable接口,我们可以调用脚本中的函数
-// if (engine instanceof Invocable) {
-// Invocable inv = (Invocable) engine;
-//
-// // 调用脚本中的greet函数
-// String greeting = (String) inv.invokeFunction("greet", "World");
-// System.out.println(greeting); // 输出: Hello, World!
-// } else {
-// System.out.println("The script engine does not support Invocable interface.");
-// }
- }
-}
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 000000000..c950c67dd
--- /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 000000000..1de2ccb9d
--- /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
index 49629ce31..17b619668 100644
--- 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
@@ -15,6 +15,12 @@ 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)
@@ -26,43 +32,60 @@ public class LiteFlowKotlinScriptCommonELTest extends BaseTest {
private FlowExecutor flowExecutor;
@Test
- public void testCommon1() {
- LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
+ 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 testFor1() {
+ public void testForScript1() {
DefaultContext context = new DefaultContext();
context.setData("k1", 1);
context.setData("k2", 2);
- LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg", context);
+ 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("s2==>a==>a==>a",response.getExecuteStepStr());
+ Assertions.assertEquals("s3==>b", response.getExecuteStepStr());
}
@Test
- public void testIf1() {
- LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg");
+ public void testBooleanScript2() {
+ LiteflowResponse response = flowExecutor.execute2Resp("testBooleanScript2", "arg");
Assertions.assertTrue(response.isSuccess());
- Assertions.assertEquals("s3==>b",response.getExecuteStepStr());
+ Assertions.assertEquals("s4", response.getExecuteStepStr());
}
@Test
- public void testIf2() {
- LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg");
+ public void testBooleanScript3() {
+ DefaultContext context = new DefaultContext();
+ context.setData("count", 2);
+ LiteflowResponse response = flowExecutor.execute2Resp("testBooleanScript3", "arg", context);
Assertions.assertTrue(response.isSuccess());
- Assertions.assertEquals("s4",response.getExecuteStepStr());
+ Assertions.assertEquals("s3==>b==>s6==>s3==>b==>s6==>s3==>b==>s6",response.getExecuteStepStr());
}
@Test
- public void testSwitch1() {
+ public void testSwitchScript1() {
DefaultContext context = new DefaultContext();
context.setData("id", "c");
- LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg", context);
+ LiteflowResponse response = flowExecutor.execute2Resp("testSwitchScript1", "arg", context);
Assertions.assertTrue(response.isSuccess());
- Assertions.assertEquals("s5==>c",response.getExecuteStepStr());
+ 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/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 000000000..d0bdba396
--- /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 000000000..9b385913e
--- /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 000000000..325548ef5
--- /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 000000000..31fcae998
--- /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 000000000..811c89889
--- /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 000000000..608f172b5
--- /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 000000000..a63216cb4
--- /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 000000000..c941b00a5
--- /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 000000000..baadb1aae
--- /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 000000000..c101ba3b4
--- /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 000000000..c02ae6b2a
--- /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 000000000..af0cd54ee
--- /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 000000000..80182dad6
--- /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 000000000..ad4d47c82
--- /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 000000000..aa4b37950
--- /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 000000000..2062df4d5
--- /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 000000000..3249d3a22
--- /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 000000000..20fc01efb
--- /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 000000000..8e650f774
--- /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 000000000..a074ad4ae
--- /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 000000000..4e31d7b8d
--- /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 000000000..d473f7163
--- /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 000000000..7f64ba0c3
--- /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 000000000..a1531df6b
--- /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 000000000..eac2a2dbb
--- /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 000000000..8c244ff40
--- /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 000000000..651796fb3
--- /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 000000000..640ef677e
--- /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 000000000..db6a06dce
--- /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 000000000..fe678737e
--- /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 000000000..af4217e6e
--- /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 000000000..ea5401aa8
--- /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 000000000..c4f2be49b
--- /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 000000000..2dd09ccc1
--- /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 000000000..7c41ce79e
--- /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 000000000..727b2641d
--- /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,26 @@
+package com.yomahub.liteflow.test.script.kotlin.validate;
+
+import com.yomahub.liteflow.enums.ScriptTypeEnum;
+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;
+
+@SpringBootTest(classes = ValidateKotlinScriptComponentTest.class)
+@EnableAutoConfiguration
+public class ValidateKotlinScriptComponentTest {
+ @Test
+ public void testGroovyScriptComponentValidateFunction(){
+ // 编译错误,字符串不能直接赋值给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 000000000..4cc9f322d
--- /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 000000000..4d333a05b
--- /dev/null
+++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/cmpdata/flow.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+ println(_meta)
+ 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/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/common/flow.xml
index 35db6f006..47d5e480b 100644
--- 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
@@ -8,6 +8,7 @@
fun sum(a: Int, b: Int) = a + b
var a = 2
var b = 3
+ // 从 bindings 中获取上下文
val defaultContext = bindings["defaultContext"] as DefaultContext
defaultContext.setData("s1", sum(a, b))
println("Hello Kotlin!")
@@ -15,20 +16,22 @@
1
+ // 函数名可以自定义,但必须返回 Boolean
getBoolean1()
]]>
@@ -45,28 +48,52 @@
fun getId(ctx: DefaultContext) : String {
return ctx.getData("id") as String
}
+ // 函数名可以自定义,但必须返回 String
getId(bindings["defaultContext"] as DefaultContext)
]]>
+
+
+
+
-
+
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 000000000..25ff2335a
--- /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 000000000..a7a290a7f
--- /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 000000000..8d0053721
--- /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 000000000..01afbc11f
--- /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 000000000..52bc92b94
--- /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 000000000..b74f49ba7
--- /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 000000000..94eebfa59
--- /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 000000000..21b596255
--- /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 000000000..84c3a55cc
--- /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 000000000..0b6107897
--- /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 000000000..8c26b5e80
--- /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 000000000..0edabf7a9
--- /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 000000000..1f247a584
--- /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 000000000..22f069ffc
--- /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 000000000..c30228a45
--- /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 000000000..b215e766b
--- /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
--
Gitee
From 90ed04e5b9a55b5435e89c7774cc1defbc98f452 Mon Sep 17 00:00:00 2001
From: Dale Lee <1658850308@qq.com>
Date: Sat, 4 May 2024 14:36:50 +0800
Subject: [PATCH 3/4] =?UTF-8?q?feature=20#I9H6GN=20=E8=AE=BE=E7=BD=AE=20ko?=
=?UTF-8?q?ltin=20=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../liteflow-script-kotlin/pom.xml | 1 -
.../pom.xml | 2 +-
.../ValidateKotlinScriptComponentTest.java | 22 ++++++++++++++++++-
.../src/test/resources/cmpdata/flow.xml | 2 --
.../src/test/resources/meta/flow.xml | 2 +-
pom.xml | 6 +++++
6 files changed, 29 insertions(+), 6 deletions(-)
diff --git a/liteflow-script-plugin/liteflow-script-kotlin/pom.xml b/liteflow-script-plugin/liteflow-script-kotlin/pom.xml
index c89e6d796..df3bed9da 100644
--- a/liteflow-script-plugin/liteflow-script-kotlin/pom.xml
+++ b/liteflow-script-plugin/liteflow-script-kotlin/pom.xml
@@ -23,7 +23,6 @@
org.jetbrains.kotlin
kotlin-scripting-jsr223
- 1.9.23
\ 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
index e76dca32f..0563cb2d5 100644
--- a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/pom.xml
+++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/pom.xml
@@ -21,7 +21,7 @@
com.yomahub
liteflow-script-kotlin
- 2.12.0
+ ${revision}
test
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
index 727b2641d..9c9e1885d 100644
--- 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
@@ -1,21 +1,41 @@
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 testGroovyScriptComponentValidateFunction(){
+ public void testScriptComponentValidateFunction() throws Exception {
// 编译错误,字符串不能直接赋值给Int
String wrongScript = "val number: Int = \"123\"";
// 使用转换函数
String correctScript = "val number: Int = \"123\".toInt()";
+// ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
+// ScriptEngine scriptEngine = scriptEngineManager.getEngineByName("kotlin");
+// Compilable compilable = (Compilable) scriptEngine;
+// compilable.compile(correctScript);
+
+// try {
+// ScriptExecutor scriptExecutor = ScriptExecutorFactory.loadInstance()
+// .getScriptExecutor(ScriptTypeEnum.KOTLIN.getDisplayName());
+// scriptExecutor.compile(wrongScript);
+// } catch (Exception e) {
+//
+// }
+
Assertions.assertTrue(ScriptValidator.validate(correctScript));
Assertions.assertFalse(ScriptValidator.validate(wrongScript));
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
index 4d333a05b..889ae01eb 100644
--- 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
@@ -4,11 +4,9 @@
- println(_meta)
var cmpData = _meta["cmpData"] as Map
var context = bindings["defaultContext"] as DefaultContext
context.setData("s1", cmpData["birth"])
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
index 01afbc11f..ff49ec51d 100644
--- 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
@@ -5,7 +5,7 @@
+ var _meta = bindings["_meta"] as Map
var nodeId = _meta["nodeId"]
var currChainId = _meta["currChainId"]
var requestData = _meta["requestData"]
diff --git a/pom.xml b/pom.xml
index fe2b4d1de..793082b57 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}
+
--
Gitee
From 621790896b41a059dc9931cf720c692a759a8127 Mon Sep 17 00:00:00 2001
From: Dale Lee <1658850308@qq.com>
Date: Sat, 4 May 2024 15:33:03 +0800
Subject: [PATCH 4/4] =?UTF-8?q?feature=20#I9H6GN=20=E4=BC=98=E5=8C=96?=
=?UTF-8?q?=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../validate/ValidateKotlinScriptComponentTest.java | 13 -------------
1 file changed, 13 deletions(-)
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
index 9c9e1885d..841d5933c 100644
--- 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
@@ -23,19 +23,6 @@ public class ValidateKotlinScriptComponentTest {
String wrongScript = "val number: Int = \"123\"";
// 使用转换函数
String correctScript = "val number: Int = \"123\".toInt()";
-// ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
-// ScriptEngine scriptEngine = scriptEngineManager.getEngineByName("kotlin");
-// Compilable compilable = (Compilable) scriptEngine;
-// compilable.compile(correctScript);
-
-// try {
-// ScriptExecutor scriptExecutor = ScriptExecutorFactory.loadInstance()
-// .getScriptExecutor(ScriptTypeEnum.KOTLIN.getDisplayName());
-// scriptExecutor.compile(wrongScript);
-// } catch (Exception e) {
-//
-// }
-
Assertions.assertTrue(ScriptValidator.validate(correctScript));
Assertions.assertFalse(ScriptValidator.validate(wrongScript));
--
Gitee