Selaa lähdekoodia

feature #I44FT8 支持脚本语言的组件,并支持动态刷新脚本(版本特性)

bryan31 3 vuotta sitten
vanhempi
säilyke
c3ada6cf71

+ 68 - 0
liteflow-testcase-script-groovy/pom.xml

@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>liteflow</artifactId>
+        <groupId>com.yomahub</groupId>
+        <version>2.5.11</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>liteflow-testcase-script-groovy</artifactId>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.yomahub</groupId>
+            <artifactId>liteflow-spring-boot-starter</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <version>${springboot.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.aspectj</groupId>
+            <artifactId>aspectjweaver</artifactId>
+            <version>1.8.13</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.curator</groupId>
+            <artifactId>curator-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.101tec</groupId>
+            <artifactId>zkclient</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.yomahub</groupId>
+            <artifactId>liteflow-script-groovy</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <version>${springboot.version}</version>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-deploy-plugin</artifactId>
+                <version>2.8.2</version>
+                <configuration>
+                    <skip>true</skip>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>

+ 14 - 0
liteflow-testcase-script-groovy/src/test/java/com/yomahub/liteflow/test/BaseTest.java

@@ -0,0 +1,14 @@
+package com.yomahub.liteflow.test;
+
+import com.yomahub.liteflow.flow.FlowBus;
+import com.yomahub.liteflow.spring.ComponentScanner;
+import org.junit.AfterClass;
+
+public class BaseTest {
+
+    @AfterClass
+    public static void cleanScanCache(){
+        ComponentScanner.cleanCache();
+        FlowBus.cleanCache();
+    }
+}

+ 49 - 0
liteflow-testcase-script-groovy/src/test/java/com/yomahub/liteflow/test/script/groovy/LiteflowScriptGroovyTest.java

@@ -0,0 +1,49 @@
+package com.yomahub.liteflow.test.script.groovy;
+
+import com.yomahub.liteflow.core.FlowExecutor;
+import com.yomahub.liteflow.entity.data.DefaultSlot;
+import com.yomahub.liteflow.entity.data.LiteflowResponse;
+import com.yomahub.liteflow.test.BaseTest;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+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.junit4.SpringRunner;
+
+import javax.annotation.Resource;
+
+
+/**
+ * 测试springboot下的脚本组件
+ * @author Bryan.Zhang
+ * @since 2.5.11
+ */
+@RunWith(SpringRunner.class)
+@TestPropertySource(value = "classpath:/script/application.properties")
+@SpringBootTest(classes = LiteflowScriptGroovyTest.class)
+@EnableAutoConfiguration
+@ComponentScan({"com.yomahub.liteflow.test.script.groovy.cmp"})
+public class LiteflowScriptGroovyTest extends BaseTest {
+
+    @Resource
+    private FlowExecutor flowExecutor;
+
+    //测试普通脚本节点
+    @Test
+    public void testScript1() {
+        LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg");
+        Assert.assertTrue(response.isSuccess());
+        Assert.assertEquals(Integer.valueOf(6), response.getSlot().getData("s1"));
+    }
+
+    //测试条件脚本节点
+    @Test
+    public void testScript2() {
+        LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain2", "arg");
+        Assert.assertTrue(response.isSuccess());
+        Assert.assertEquals("d==>s2==>b", response.getSlot().printStep());
+    }
+}

+ 20 - 0
liteflow-testcase-script-groovy/src/test/java/com/yomahub/liteflow/test/script/groovy/cmp/ACmp.java

@@ -0,0 +1,20 @@
+/**
+ * <p>Title: liteflow</p>
+ * <p>Description: 轻量级的组件式流程框架</p>
+ * @author Bryan.Zhang
+ * @email weenyc31@163.com
+ * @Date 2020/4/1
+ */
+package com.yomahub.liteflow.test.script.groovy.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!");
+	}
+}

+ 21 - 0
liteflow-testcase-script-groovy/src/test/java/com/yomahub/liteflow/test/script/groovy/cmp/BCmp.java

@@ -0,0 +1,21 @@
+/**
+ * <p>Title: liteflow</p>
+ * <p>Description: 轻量级的组件式流程框架</p>
+ * @author Bryan.Zhang
+ * @email weenyc31@163.com
+ * @Date 2020/4/1
+ */
+package com.yomahub.liteflow.test.script.groovy.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!");
+	}
+
+}

+ 21 - 0
liteflow-testcase-script-groovy/src/test/java/com/yomahub/liteflow/test/script/groovy/cmp/CCmp.java

@@ -0,0 +1,21 @@
+/**
+ * <p>Title: liteflow</p>
+ * <p>Description: 轻量级的组件式流程框架</p>
+ * @author Bryan.Zhang
+ * @email weenyc31@163.com
+ * @Date 2020/4/1
+ */
+package com.yomahub.liteflow.test.script.groovy.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!");
+	}
+
+}

+ 24 - 0
liteflow-testcase-script-groovy/src/test/java/com/yomahub/liteflow/test/script/groovy/cmp/DCmp.java

@@ -0,0 +1,24 @@
+/**
+ * <p>Title: liteflow</p>
+ * <p>Description: 轻量级的组件式流程框架</p>
+ * @author Bryan.Zhang
+ * @email weenyc31@163.com
+ * @Date 2020/4/1
+ */
+package com.yomahub.liteflow.test.script.groovy.cmp;
+
+import com.yomahub.liteflow.annotation.LiteflowComponent;
+import com.yomahub.liteflow.core.NodeComponent;
+import com.yomahub.liteflow.entity.data.Slot;
+
+@LiteflowComponent("d")
+public class DCmp extends NodeComponent {
+
+	@Override
+	public void process() {
+		Slot slot = this.getSlot();
+		slot.setData("count",97);
+		System.out.println("DCmp executed!");
+	}
+
+}

+ 1 - 0
liteflow-testcase-script-groovy/src/test/resources/script/application.properties

@@ -0,0 +1 @@
+liteflow.rule-source=script/flow.xml

+ 31 - 0
liteflow-testcase-script-groovy/src/test/resources/script/flow.xml

@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<flow>
+    <nodes>
+        <node id="s1" type="script">
+            <![CDATA[
+                a=3;
+                b=2;
+                slot.setData("s1",a*b);
+            ]]>
+        </node>
+
+        <node id="s2" type="cond_script">
+            <![CDATA[
+                count = slot.getData("count");
+                if(count > 100){
+                    return "a";
+                }else{
+                    return "b";
+                }
+            ]]>
+        </node>
+    </nodes>
+
+    <chain name="chain1">
+        <then value="a,b,c,s1"/>
+    </chain>
+
+    <chain name="chain2">
+        <then value="d,s2(a|b)"/>
+    </chain>
+</flow>

+ 1 - 0
pom.xml

@@ -253,6 +253,7 @@
 		<module>liteflow-testcase-springboot</module>
 		<module>liteflow-testcase-springnative</module>
 		<module>liteflow-testcase-script-qlexpress</module>
+		<module>liteflow-testcase-script-groovy</module>
 	</modules>
 
 	<distributionManagement>