mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 20:22:07 +08:00
enhancement #IACEGB 上下文超类判断的获取和转换
This commit is contained in:
@@ -4,6 +4,7 @@ import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import com.yomahub.liteflow.test.contextBean.context.TestContext;
|
||||
import com.yomahub.liteflow.test.contextBean.context.TestSubContext;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
@@ -12,6 +13,7 @@ import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* ContextBean测试
|
||||
@@ -36,7 +38,7 @@ public class ContextBeanSpringbootTest extends BaseTest {
|
||||
Assertions.assertEquals("J001", context.getSkuCode());
|
||||
}
|
||||
|
||||
// new一个上下文的情况
|
||||
// 利用别名取上下文
|
||||
@Test
|
||||
public void testContextBean2() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", new TestContext("J001", "test"));
|
||||
@@ -44,4 +46,13 @@ public class ContextBeanSpringbootTest extends BaseTest {
|
||||
TestContext context = response.getContextBean("skuContext");
|
||||
Assertions.assertEquals("J001", context.getSkuCode());
|
||||
}
|
||||
|
||||
// 利用超类取上下文
|
||||
@Test
|
||||
public void testContextBean3() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg", new TestSubContext("J001", "test", new BigDecimal("10.5")));
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
TestContext context = response.getContextBean(TestContext.class);
|
||||
Assertions.assertEquals("J001", context.getSkuCode());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.contextBean.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.test.contextBean.context.TestContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("c")
|
||||
public class CCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
TestContext context = this.getContextBean(TestContext.class);
|
||||
context.setSkuCode("J001");
|
||||
System.out.println("CCmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,9 +5,12 @@ import com.yomahub.liteflow.context.ContextBean;
|
||||
@ContextBean("skuContext")
|
||||
public class TestContext {
|
||||
|
||||
private String skuCode;
|
||||
protected String skuCode;
|
||||
|
||||
private String skuName;
|
||||
protected String skuName;
|
||||
|
||||
public TestContext() {
|
||||
}
|
||||
|
||||
public TestContext(String skuCode, String skuName) {
|
||||
this.skuCode = skuCode;
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.yomahub.liteflow.test.contextBean.context;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class TestSubContext extends TestContext{
|
||||
|
||||
private BigDecimal price;
|
||||
|
||||
|
||||
|
||||
public TestSubContext(String skuCode, String skuName, BigDecimal price) {
|
||||
super(skuCode, skuName);
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public BigDecimal getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(BigDecimal price) {
|
||||
this.price = price;
|
||||
}
|
||||
}
|
||||
@@ -4,4 +4,8 @@
|
||||
<chain name="chain1">
|
||||
THEN(a,b);
|
||||
</chain>
|
||||
|
||||
<chain name="chain2">
|
||||
THEN(c,b);
|
||||
</chain>
|
||||
</flow>
|
||||
Reference in New Issue
Block a user