mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-06-12 21:21:03 +08:00
#IB0SJ1 补充单元测试
This commit is contained in:
@@ -2,9 +2,13 @@ package com.yomahub.liteflow.test.instanceIds;
|
||||
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.flow.element.Node;
|
||||
import com.yomahub.liteflow.flow.entity.InstanceInfoDto;
|
||||
import com.yomahub.liteflow.flow.instanceId.NodeInstanceIdManageSpi;
|
||||
import com.yomahub.liteflow.flow.instanceId.NodeInstanceIdManageSpiHolder;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import com.yomahub.liteflow.util.JsonUtil;
|
||||
import org.assertj.core.util.Sets;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
@@ -13,100 +17,347 @@ import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 测试生成 instanceId
|
||||
*
|
||||
* @author Jay li
|
||||
* @since 2.13.0
|
||||
*/
|
||||
@TestPropertySource(value = "classpath:/instanceIds/application.properties")
|
||||
@SpringBootTest(classes = InstanceIdELSpringTest.class)
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan({ "com.yomahub.liteflow.test.instanceIds.cmp" })
|
||||
@ComponentScan({"com.yomahub.liteflow.test.instanceIds.cmp"})
|
||||
public class InstanceIdELSpringTest extends BaseTest {
|
||||
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
// 文件保存实例id
|
||||
@Test
|
||||
public void testInstanceIds1() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("a==>a==>a==>a", response.getExecuteStepStr());
|
||||
@Test
|
||||
public void testInstanceIds1() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("a==>a==>a==>a", response.getExecuteStepStr());
|
||||
|
||||
String executeStepStrWithInstanceId = response.getExecuteStepStrWithInstanceId();
|
||||
Set<String> strings = extractValues(executeStepStrWithInstanceId);
|
||||
System.out.println(executeStepStrWithInstanceId);
|
||||
Assertions.assertEquals(strings.size(), 4);
|
||||
}
|
||||
String executeStepStrWithInstanceId = response.getExecuteStepStrWithInstanceId();
|
||||
Set<String> strings = extractValues(executeStepStrWithInstanceId);
|
||||
System.out.println(executeStepStrWithInstanceId);
|
||||
Assertions.assertEquals(strings.size(), 4);
|
||||
}
|
||||
|
||||
// 重复调用实例id不变
|
||||
@Test
|
||||
public void testInstanceIds2() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("a==>a==>a==>a", response.getExecuteStepStr());
|
||||
// 重复调用实例id不变
|
||||
@Test
|
||||
public void testInstanceIds2() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("a==>a==>a==>a", response.getExecuteStepStr());
|
||||
|
||||
String executeStepStrWithInstanceId = response.getExecuteStepStrWithInstanceId();
|
||||
Set<String> set1 = extractValues(executeStepStrWithInstanceId);
|
||||
System.out.println(executeStepStrWithInstanceId);
|
||||
String executeStepStrWithInstanceId = response.getExecuteStepStrWithInstanceId();
|
||||
Set<String> set1 = extractValues(executeStepStrWithInstanceId);
|
||||
System.out.println(executeStepStrWithInstanceId);
|
||||
|
||||
Assertions.assertEquals(set1.size(), 4);
|
||||
Assertions.assertEquals(set1.size(), 4);
|
||||
|
||||
response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("a==>a==>a==>a", response.getExecuteStepStr());
|
||||
response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("a==>a==>a==>a", response.getExecuteStepStr());
|
||||
|
||||
executeStepStrWithInstanceId = response.getExecuteStepStrWithInstanceId();
|
||||
Set<String> set2 = extractValues(executeStepStrWithInstanceId);
|
||||
System.out.println(executeStepStrWithInstanceId);
|
||||
executeStepStrWithInstanceId = response.getExecuteStepStrWithInstanceId();
|
||||
Set<String> set2 = extractValues(executeStepStrWithInstanceId);
|
||||
System.out.println(executeStepStrWithInstanceId);
|
||||
|
||||
Assertions.assertEquals(set2.size(), 4);
|
||||
Assertions.assertEquals(set1, set2);
|
||||
}
|
||||
Assertions.assertEquals(set2.size(), 4);
|
||||
Assertions.assertEquals(set1, set2);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testInstanceIds3() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("a==>a==>a==>a", response.getExecuteStepStr());
|
||||
@Test
|
||||
public void testInstanceIds3() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("a==>a==>a==>a", response.getExecuteStepStr());
|
||||
|
||||
String executeStepStrWithInstanceId = response.getExecuteStepStrWithInstanceId();
|
||||
List<String> strings = extractValuesList(executeStepStrWithInstanceId);
|
||||
NodeInstanceIdManageSpi nodeInstanceIdManageSpi = NodeInstanceIdManageSpiHolder.getInstance().getNodeInstanceIdManageSpi();
|
||||
String executeStepStrWithInstanceId = response.getExecuteStepStrWithInstanceId();
|
||||
List<String> strings = extractValuesList(executeStepStrWithInstanceId);
|
||||
NodeInstanceIdManageSpi nodeInstanceIdManageSpi = NodeInstanceIdManageSpiHolder.getInstance().getNodeInstanceIdManageSpi();
|
||||
|
||||
for (int i = 0; i < strings.size(); i++) {
|
||||
Assertions.assertEquals(nodeInstanceIdManageSpi.getNodeLocationById("chain2", strings.get(i)), "a(" + i + ")");
|
||||
}
|
||||
for (int i = 0; i < strings.size(); i++) {
|
||||
Assertions.assertEquals(nodeInstanceIdManageSpi.getNodeLocationById("chain2", strings.get(i)), "a(" + i + ")");
|
||||
}
|
||||
|
||||
System.out.println(executeStepStrWithInstanceId);
|
||||
Assertions.assertEquals(strings.size(), 4);
|
||||
}
|
||||
System.out.println(executeStepStrWithInstanceId);
|
||||
Assertions.assertEquals(strings.size(), 4);
|
||||
}
|
||||
|
||||
public static Set<String> extractValues(String input) {
|
||||
Set<String> values = new HashSet<>();
|
||||
Pattern pattern = Pattern.compile("\\[(.*?)]");
|
||||
Matcher matcher = pattern.matcher(input);
|
||||
while (matcher.find()) {
|
||||
values.add(matcher.group(1));
|
||||
}
|
||||
return values;
|
||||
}
|
||||
public static Set<String> extractValues(String input) {
|
||||
Set<String> values = new HashSet<>();
|
||||
Pattern pattern = Pattern.compile("\\[(.*?)]");
|
||||
Matcher matcher = pattern.matcher(input);
|
||||
while (matcher.find()) {
|
||||
values.add(matcher.group(1));
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
public static List<String> extractValuesList(String input) {
|
||||
List<String> values = new ArrayList<>();
|
||||
Pattern pattern = Pattern.compile("\\[(.*?)]");
|
||||
Matcher matcher = pattern.matcher(input);
|
||||
while (matcher.find()) {
|
||||
values.add(matcher.group(1));
|
||||
}
|
||||
return values;
|
||||
}
|
||||
}
|
||||
public static List<String> extractValuesList(String input) {
|
||||
List<String> values = new ArrayList<>();
|
||||
Pattern pattern = Pattern.compile("\\[(.*?)]");
|
||||
Matcher matcher = pattern.matcher(input);
|
||||
while (matcher.find()) {
|
||||
values.add(matcher.group(1));
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
|
||||
// chain3 if 脚本
|
||||
@Test
|
||||
public void testSQLWithXmlChain3() {
|
||||
String chain4InstanceStr = queryInstanceStrByChainId("chain3");
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg");
|
||||
|
||||
Assertions.assertEquals("x1==>a==>b", response.getExecuteStepStr());
|
||||
System.out.println(chain4InstanceStr);
|
||||
Assertions.assertEquals(chain4InstanceStr, response.getExecuteStepStrWithInstanceId());
|
||||
List<String> extractStrings = extractValuesList(chain4InstanceStr);
|
||||
Assertions.assertEquals(Sets.newHashSet(extractStrings).size(), 3);
|
||||
}
|
||||
|
||||
|
||||
// chain5 switch 切换 for 表达式
|
||||
@Test
|
||||
public void testSQLWithXmlChain5() {
|
||||
String chainId = "chain5";
|
||||
|
||||
LiteflowResponse response = flowExecutor.execute2Resp(chainId, "arg");
|
||||
String executeStepStr = response.getExecuteStepStr();
|
||||
Assertions.assertEquals("e==>c", response.getExecuteStepStr());
|
||||
|
||||
String instancePath = constructInstancePath(executeStepStr, chainId);
|
||||
Assertions.assertEquals(instancePath, response.getExecuteStepStrWithInstanceId());
|
||||
List<String> extractStrings = extractValuesList(instancePath);
|
||||
Assertions.assertEquals(Sets.newHashSet(extractStrings).size(), 2);
|
||||
}
|
||||
|
||||
// FOR(x).DO(CATCH(THEN(a,b,a)));
|
||||
@Test
|
||||
public void testSQLWithXmlChain4() {
|
||||
String chainId = "chain4";
|
||||
LiteflowResponse response = flowExecutor.execute2Resp(chainId, "arg");
|
||||
String chain4InstanceStr2 = queryInstanceStrByChainId(chainId);
|
||||
String executeStepStr = response.getExecuteStepStr();
|
||||
Assertions.assertEquals("x==>a==>b==>a", executeStepStr);
|
||||
|
||||
String instancePath = constructInstancePath(executeStepStr, chainId);
|
||||
Assertions.assertEquals(instancePath, response.getExecuteStepStrWithInstanceId());
|
||||
|
||||
List<String> extractStrings = extractValuesList(chain4InstanceStr2);
|
||||
Assertions.assertEquals(Sets.newHashSet(extractStrings).size(), 4);
|
||||
}
|
||||
|
||||
|
||||
// THEN(a,WHEN(b, c), a)
|
||||
@Test
|
||||
public void testSQLWithXmlChain6() {
|
||||
String chainId = "chain6";
|
||||
|
||||
LiteflowResponse response = flowExecutor.execute2Resp(chainId, "arg");
|
||||
String executeStepStr = response.getExecuteStepStr();
|
||||
Assertions.assertEquals("a==>b==>c==>a", response.getExecuteStepStr());
|
||||
|
||||
String instancePath = constructInstancePath(executeStepStr, chainId);
|
||||
Assertions.assertEquals(instancePath, response.getExecuteStepStrWithInstanceId());
|
||||
List<String> extractStrings = extractValuesList(instancePath);
|
||||
Assertions.assertEquals(Sets.newHashSet(extractStrings).size(), 4);
|
||||
}
|
||||
|
||||
|
||||
// CATCH(THEN(a,b)).DO(c)
|
||||
@Test
|
||||
public void testSQLWithXmlChain7() {
|
||||
String chainId = "chain7";
|
||||
|
||||
LiteflowResponse response = flowExecutor.execute2Resp(chainId, "arg");
|
||||
String executeStepStr = response.getExecuteStepStr();
|
||||
Assertions.assertEquals("a==>b", response.getExecuteStepStr());
|
||||
|
||||
String instancePath = constructInstancePath(executeStepStr, chainId);
|
||||
Assertions.assertEquals(instancePath, response.getExecuteStepStrWithInstanceId());
|
||||
List<String> extractStrings = extractValuesList(instancePath);
|
||||
Assertions.assertEquals(Sets.newHashSet(extractStrings).size(), 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNodeByIdAndInstanceIdTest() {
|
||||
String[] chainIds = new String[]{"chain1", "chain2", "chain3", "chain4", "chain5", "chain6", "chain7"};
|
||||
for (String chainId : chainIds) {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp(chainId, "arg");
|
||||
String executeStepStrWithInstanceId = response.getExecuteStepStrWithInstanceId();
|
||||
|
||||
Map<String, String> instanceMap = extractKeyValuePairs(executeStepStrWithInstanceId);
|
||||
|
||||
NodeInstanceIdManageSpi nodeInstanceIdManageSpi = NodeInstanceIdManageSpiHolder.getInstance().getNodeInstanceIdManageSpi();
|
||||
for (Map.Entry<String, String> entry : instanceMap.entrySet()) {
|
||||
Node node = nodeInstanceIdManageSpi.getNodeByIdAndInstanceId(chainId, entry.getKey());
|
||||
Assertions.assertEquals(node.getId(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getNodeByIdAndIndexTest() {
|
||||
String[] chainIds = new String[]{"chain1", "chain2", "chain3", "chain4", "chain5", "chain6", "chain7"};
|
||||
for (String chainId : chainIds) {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp(chainId, "arg");
|
||||
String executeStepStrWithInstanceId = response.getExecuteStepStrWithInstanceId();
|
||||
|
||||
Map<String, String> instanceMap = extractKeyValuePairs(executeStepStrWithInstanceId);
|
||||
|
||||
Map<String, Integer> idCntMap = new HashMap<>();
|
||||
|
||||
NodeInstanceIdManageSpi nodeInstanceIdManageSpi = NodeInstanceIdManageSpiHolder.getInstance().getNodeInstanceIdManageSpi();
|
||||
for (Map.Entry<String, String> entry : instanceMap.entrySet()) {
|
||||
idCntMap.put(entry.getValue(), idCntMap.getOrDefault(entry.getValue(), -1) + 1);
|
||||
Node node = nodeInstanceIdManageSpi.getNodeByIdAndIndex(chainId, entry.getValue(), idCntMap.get(entry.getValue()));
|
||||
Assertions.assertEquals(node.getId(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNodeInstanceIdsTest() {
|
||||
String[] chainIds = new String[]{"chain1", "chain2", "chain3", "chain4", "chain5", "chain6", "chain7"};
|
||||
for (String chainId : chainIds) {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp(chainId, "arg");
|
||||
String executeStepStrWithInstanceId = response.getExecuteStepStrWithInstanceId();
|
||||
|
||||
Map<String, List<String>> instanceMap = extractKeyValues(executeStepStrWithInstanceId);
|
||||
|
||||
NodeInstanceIdManageSpi nodeInstanceIdManageSpi = NodeInstanceIdManageSpiHolder.getInstance().getNodeInstanceIdManageSpi();
|
||||
for (Map.Entry<String, List<String>> entry : instanceMap.entrySet()) {
|
||||
Assertions.assertEquals(entry.getValue(), nodeInstanceIdManageSpi.getNodeInstanceIds(chainId, entry.getKey()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private String constructInstancePath(String executeStepStr, String chainId) {
|
||||
Map<String, InstanceInfoDto> instanceMap = queryInstanceMapByChainId(chainId);
|
||||
String[] nodes = executeStepStr.split("==>");
|
||||
|
||||
StringBuilder nodePathStr = new StringBuilder();
|
||||
Map<String, Integer> tmpMap = new HashMap<>();
|
||||
for (String node : nodes) {
|
||||
tmpMap.put(node, tmpMap.getOrDefault(node, -1) + 1);
|
||||
nodePathStr.append("==>").append(node).append("[")
|
||||
.append(instanceMap.get(node + "_" + tmpMap.get(node)).getInstanceId())
|
||||
.append("]");
|
||||
}
|
||||
|
||||
return nodePathStr.toString().replaceFirst("==>", "");
|
||||
|
||||
}
|
||||
|
||||
|
||||
private String queryInstanceStrByChainId(String chainId) {
|
||||
// 查询数据库实例id
|
||||
String instanceId = queryInstanceIdInfo(chainId);
|
||||
// 解析 JSON
|
||||
List<InstanceInfoDto> instanceInfoDtos = JsonUtil.parseList(instanceId, InstanceInfoDto.class);
|
||||
// 构造实例id字符串
|
||||
StringBuilder result = new StringBuilder();
|
||||
int i = 0;
|
||||
|
||||
for (InstanceInfoDto dto : instanceInfoDtos) {
|
||||
result.append(dto.getNodeId()).append("[").append(dto.getInstanceId()).append("]");
|
||||
if (i + 1 < instanceInfoDtos.size()) {
|
||||
result.append("==>");
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
// key 为 nodeId_index
|
||||
private Map<String, InstanceInfoDto> queryInstanceMapByChainId(String chainId) {
|
||||
// 查询数据库实例id
|
||||
String instanceId = queryInstanceIdInfo(chainId);
|
||||
// 解析 JSON
|
||||
List<InstanceInfoDto> instanceInfos = JsonUtil.parseList(instanceId, InstanceInfoDto.class);
|
||||
// 构造实例id字符串
|
||||
Map<String, InstanceInfoDto> result = new HashMap<>();
|
||||
instanceInfos.forEach(instanceInfo -> result.put(instanceInfo.getNodeId() + "_" + instanceInfo.getIndex(), instanceInfo));
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* key 为 InstanceId value 为 nodeId
|
||||
*/
|
||||
private Map<String, String> extractKeyValuePairs(String input) {
|
||||
String[] parts = input.split("==>");
|
||||
|
||||
// 创建一个 Map 来存储结果
|
||||
Map<String, String> resultMap = new HashMap<>();
|
||||
|
||||
for (String part : parts) {
|
||||
// 去掉前后括号
|
||||
int startIndex = part.indexOf('[');
|
||||
int endIndex = part.lastIndexOf(']');
|
||||
|
||||
if (startIndex != -1 && endIndex != -1) {
|
||||
String value = part.substring(0, startIndex).trim();
|
||||
String key = part.substring(startIndex + 1, endIndex).trim();
|
||||
|
||||
// 将键值对放入 Map
|
||||
resultMap.put(key, value);
|
||||
}
|
||||
}
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* key 为 nodeId value 为 list InstanceId
|
||||
*/
|
||||
private Map<String, List<String>> extractKeyValues(String input) {
|
||||
String[] parts = input.split("==>");
|
||||
|
||||
// 创建一个 Map 来存储结果
|
||||
Map<String, List<String>> resultMap = new HashMap<>();
|
||||
|
||||
for (String part : parts) {
|
||||
// 去掉前后括号
|
||||
int startIndex = part.indexOf('[');
|
||||
int endIndex = part.lastIndexOf(']');
|
||||
|
||||
if (startIndex != -1 && endIndex != -1) {
|
||||
String key = part.substring(0, startIndex).trim();
|
||||
String value = part.substring(startIndex + 1, endIndex).trim();
|
||||
|
||||
List<String> mapOrDefault = resultMap.getOrDefault(key, new ArrayList<>());
|
||||
mapOrDefault.add(value);
|
||||
resultMap.put(key, mapOrDefault);
|
||||
}
|
||||
}
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
|
||||
public String queryInstanceIdInfo(String chainId) {
|
||||
NodeInstanceIdManageSpi nodeInstanceIdManageSpi = NodeInstanceIdManageSpiHolder.getInstance().getNodeInstanceIdManageSpi();
|
||||
List<String> readInstanceIdFiles = nodeInstanceIdManageSpi.readInstanceIdFile(chainId);
|
||||
|
||||
return readInstanceIdFiles.get(1);
|
||||
}
|
||||
}
|
||||
@@ -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.instanceIds.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeSwitchComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("e")
|
||||
public class ESwitchCmp extends NodeSwitchComponent {
|
||||
|
||||
@Override
|
||||
public String processSwitch() throws Exception {
|
||||
return "c";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.instanceIds.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeBooleanComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("x1")
|
||||
public class X1Cmp extends NodeBooleanComponent {
|
||||
|
||||
@Override
|
||||
public boolean processBoolean() throws Exception {
|
||||
return Boolean.parseBoolean(this.getTag());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.test.instanceIds.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeBooleanComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("x2")
|
||||
public class X2Cmp extends NodeBooleanComponent {
|
||||
|
||||
@Override
|
||||
public boolean processBoolean() throws Exception {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccess() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.yomahub.liteflow.test.instanceIds.cmp;
|
||||
|
||||
import com.yomahub.liteflow.annotation.LiteflowComponent;
|
||||
import com.yomahub.liteflow.annotation.LiteflowMethod;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
|
||||
import com.yomahub.liteflow.enums.NodeTypeEnum;
|
||||
|
||||
@LiteflowComponent("x")
|
||||
public class XCmp {
|
||||
|
||||
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_FOR, nodeType = NodeTypeEnum.FOR)
|
||||
public int processFor(NodeComponent bindCmp) throws Exception {
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,4 +7,24 @@
|
||||
<chain name="chain2">
|
||||
THEN(a,a,a,a);
|
||||
</chain>
|
||||
|
||||
<chain name="chain3">
|
||||
IF(x1.tag("true"), THEN(a, b));
|
||||
</chain>
|
||||
|
||||
<chain name="chain4">
|
||||
FOR(x).DO(CATCH(THEN(a,b,a)));
|
||||
</chain>
|
||||
|
||||
<chain name="chain5">
|
||||
THEN(SWITCH(e).to(b, c));
|
||||
</chain>
|
||||
|
||||
<chain name="chain6">
|
||||
THEN(a,WHEN(b, c),a);
|
||||
</chain>
|
||||
|
||||
<chain name="chain7">
|
||||
CATCH(THEN(a,b)).DO(c)
|
||||
</chain>
|
||||
</flow>
|
||||
@@ -32,7 +32,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author jay li
|
||||
* @since 2.12.0
|
||||
* @since 2.13.0
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/application-instanceId-xml.properties")
|
||||
@@ -47,27 +47,13 @@ public class SQLWithXmlELInstanceIdSpringbootTest extends BaseTest {
|
||||
@Test
|
||||
public void testSQLWithXmlChain() throws SQLException, JSONException {
|
||||
// 查询数据库实例id
|
||||
String instanceId = queryInstanceIdInfo("r_chain4");
|
||||
// 解析 JSON
|
||||
List<InstanceInfoDto> instanceInfos = JsonUtil.parseList(instanceId, InstanceInfoDto.class);
|
||||
// 构造实例id字符串
|
||||
StringBuilder result = new StringBuilder();
|
||||
int i = 0;
|
||||
|
||||
for (InstanceInfoDto dto : instanceInfos) {
|
||||
result.append(dto.getNodeId()).append("[").append(dto.getInstanceId()).append("]");
|
||||
if (i + 1 < instanceInfos.size()) {
|
||||
result.append("==>");
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
String result = queryInstanceStrByChainId("r_chain4");
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("r_chain4", "arg");
|
||||
Assertions.assertEquals("c==>b==>a", response.getExecuteStepStr());
|
||||
Assertions.assertEquals(result.toString(), response.getExecuteStepStrWithInstanceId());
|
||||
Assertions.assertEquals(result, response.getExecuteStepStrWithInstanceId());
|
||||
// 重复执行 检查实例id是否变化
|
||||
response = flowExecutor.execute2Resp("r_chain4", "arg");
|
||||
Assertions.assertEquals(result.toString(), response.getExecuteStepStrWithInstanceId());
|
||||
Assertions.assertEquals(result, response.getExecuteStepStrWithInstanceId());
|
||||
}
|
||||
|
||||
|
||||
@@ -172,6 +158,37 @@ public class SQLWithXmlELInstanceIdSpringbootTest extends BaseTest {
|
||||
}
|
||||
|
||||
|
||||
// THEN(a,WHEN(b, c), a)
|
||||
@Test
|
||||
public void testSQLWithXmlChain6() throws SQLException {
|
||||
String chainId = "chain6";
|
||||
|
||||
LiteflowResponse response = flowExecutor.execute2Resp(chainId, "arg");
|
||||
String executeStepStr = response.getExecuteStepStr();
|
||||
Assertions.assertEquals("a==>b==>c==>a", response.getExecuteStepStr());
|
||||
|
||||
String instancePath = constructInstancePath(executeStepStr, chainId);
|
||||
Assertions.assertEquals(instancePath, response.getExecuteStepStrWithInstanceId());
|
||||
List<String> extractStrings = extractValuesList(instancePath);
|
||||
Assertions.assertEquals(Sets.newHashSet(extractStrings).size(), 4);
|
||||
}
|
||||
|
||||
|
||||
// CATCH(THEN(a,b)).DO(c)
|
||||
@Test
|
||||
public void testSQLWithXmlChain7() throws SQLException {
|
||||
String chainId = "chain7";
|
||||
|
||||
LiteflowResponse response = flowExecutor.execute2Resp(chainId, "arg");
|
||||
String executeStepStr = response.getExecuteStepStr();
|
||||
Assertions.assertEquals("a==>b", response.getExecuteStepStr());
|
||||
|
||||
String instancePath = constructInstancePath(executeStepStr, chainId);
|
||||
Assertions.assertEquals(instancePath, response.getExecuteStepStrWithInstanceId());
|
||||
List<String> extractStrings = extractValuesList(instancePath);
|
||||
Assertions.assertEquals(Sets.newHashSet(extractStrings).size(), 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNodeByIdAndInstanceIdTest() throws SQLException {
|
||||
String[] chainIds = new String[]{"chain1", "chain2", "chain4","r_chain1","r_chain2","chain5"};
|
||||
@@ -247,6 +264,7 @@ public class SQLWithXmlELInstanceIdSpringbootTest extends BaseTest {
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 修改数据库数据
|
||||
private void changeData(String chainElData, String chainId) {
|
||||
LiteflowConfig liteflowConfig = LiteflowConfigGetter.get();
|
||||
|
||||
@@ -10,6 +10,8 @@ INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA,ROUTE,NAMESPACE) value
|
||||
INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA,CUSTOM_FILTER_TYPE) values ('demo','r_chain3','THEN(a,b,c);','biz1');
|
||||
INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA,CUSTOM_FILTER_TYPE) values ('demo','r_chain4','THEN(c,b,a);','biz2');
|
||||
INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA) values ('demo','chain5','THEN(SWITCH(e).to(b, c));');
|
||||
INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA) values ('demo','chain6','THEN(a,WHEN(b, c),a)');
|
||||
INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA) values ('demo','chain7','CATCH(THEN(a,b)).DO(c)');
|
||||
|
||||
DELETE FROM SCRIPT_NODE_TABLE;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user