mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 20:22:07 +08:00
feature #I69M1M 对上下文在脚本中的引用,支持自定义名称
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
package com.yomahub.liteflow.test.script.python.contextbean;
|
||||
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import com.yomahub.liteflow.test.script.python.contextbean.bean.CheckContext;
|
||||
import com.yomahub.liteflow.test.script.python.contextbean.bean.Order2Context;
|
||||
import com.yomahub.liteflow.test.script.python.contextbean.bean.OrderContext;
|
||||
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:/contextbean/application.properties")
|
||||
@SpringBootTest(classes = LiteFlowScriptContextbeanPythonTest.class)
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan({"com.yomahub.liteflow.test.script.python.contextbean.cmp","com.yomahub.liteflow.test.script.python.contextbean.bean"})
|
||||
public class LiteFlowScriptContextbeanPythonTest extends BaseTest {
|
||||
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
@Test
|
||||
public void testContextBean1() throws Exception{
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class, Order2Context.class);
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
OrderContext orderContext = response.getContextBean(OrderContext.class);
|
||||
CheckContext checkContext = response.getContextBean(CheckContext.class);
|
||||
Order2Context order2Context = response.getContextBean(Order2Context.class);
|
||||
Assert.assertEquals(30, orderContext.getOrderType());
|
||||
Assert.assertEquals("d", checkContext.getSign());
|
||||
Assert.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);
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.yomahub.liteflow.test.script.python.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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.yomahub.liteflow.test.script.python.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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.yomahub.liteflow.test.script.python.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;
|
||||
}
|
||||
}
|
||||
@@ -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.python.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!");
|
||||
}
|
||||
}
|
||||
@@ -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.python.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!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.python.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!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
liteflow.rule-source=contextbean/flow.xml
|
||||
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow>
|
||||
|
||||
<nodes>
|
||||
<node id="d" type="script">
|
||||
<![CDATA[
|
||||
a=6
|
||||
b=10
|
||||
if a>5:
|
||||
b=5
|
||||
print 'hello'
|
||||
else:
|
||||
print 'hi'
|
||||
order.setOrderType(a*b)
|
||||
checkContext.setSign(_meta.get("nodeId"))
|
||||
order2Context.setOrderNo("order2")
|
||||
]]>
|
||||
</node>
|
||||
|
||||
<node id="e" type="script">
|
||||
<![CDATA[
|
||||
orderNo = order.getOrderNo()
|
||||
print orderNo
|
||||
sign = checkContext.getSign()
|
||||
print sign
|
||||
orderNo2 = order2Context.getOrderNo()
|
||||
print orderNo2
|
||||
]]>
|
||||
</node>
|
||||
</nodes>
|
||||
|
||||
<chain name="chain1">
|
||||
THEN(a,b,c,d);
|
||||
</chain>
|
||||
|
||||
<chain name="chain2">
|
||||
THEN(a,b,c,e);
|
||||
</chain>
|
||||
|
||||
</flow>
|
||||
Reference in New Issue
Block a user