feat #I64L3Q 增加 @ScriptMethod 注解

This commit is contained in:
gaibu
2022-12-10 18:11:04 +08:00
parent 2adda1fdf2
commit b863908d78
35 changed files with 848 additions and 6 deletions

View File

@@ -0,0 +1,44 @@
package com.yomahub.liteflow.test.script.javascript.scriptmethod;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.slot.DefaultContext;
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;
@RunWith(SpringRunner.class)
@TestPropertySource(value = "classpath:/scriptmethod/application.properties")
@SpringBootTest(classes = LiteFlowScriptScriptMethodJsELTest.class)
@EnableAutoConfiguration
@ComponentScan({"com.yomahub.liteflow.test.script.javascript.scriptmethod.cmp","com.yomahub.liteflow.test.script.javascript.scriptmethod.bean"})
public class LiteFlowScriptScriptMethodJsELTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
@Test
public void testScriptBean1() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(response.isSuccess());
DefaultContext context = response.getFirstContextBean();
Assert.assertEquals("hello", context.getData("demo"));
}
@Test
public void testScriptBean2() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
Assert.assertTrue(response.isSuccess());
DefaultContext context = response.getFirstContextBean();
Assert.assertEquals("hello,kobe", context.getData("demo"));
}
}

View File

@@ -0,0 +1,28 @@
package com.yomahub.liteflow.test.script.javascript.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);
}
@ScriptMethod("demo3")
public String getDemoStr3(String name, String name2) {
return demoBean2.getDemoStr2(name) + name2;
}
}

View File

@@ -0,0 +1,11 @@
package com.yomahub.liteflow.test.script.javascript.scriptmethod.bean;
import org.springframework.stereotype.Component;
@Component
public class DemoBean2 {
public String getDemoStr2(String name){
return "hello,"+name;
}
}

View File

@@ -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.javascript.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!");
}
}

View File

@@ -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.javascript.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!");
}
}

View File

@@ -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.javascript.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!");
}
}

View File

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

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<nodes>
<node id="d" type="script" language="js">
<![CDATA[
var str = demo.getDemoStr1();
defaultContext.setData("demo", str);
]]>
</node>
<node id="e" type="script" language="js">
<![CDATA[
var str = demo2.getDemoStr2("kobe");
defaultContext.setData("demo", str);
]]>
</node>
</nodes>
<chain name="chain1">
THEN(a,b,c,d);
</chain>
<chain name="chain2">
THEN(a,b,c,e);
</chain>
</flow>