mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 12:12:08 +08:00
增加了新的rollback测试用例
This commit is contained in:
@@ -35,20 +35,61 @@ public class RollbackELDeclSpringbootTest extends BaseTest {
|
||||
Assertions.assertEquals("", response.getRollbackStepStr());
|
||||
}
|
||||
|
||||
// 测试产生异常之后的回滚顺序
|
||||
// 对串行编排与并行编排语法的测试
|
||||
@Test
|
||||
public void testRollbackStep() throws Exception {
|
||||
public void testWhenAndThen() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assertions.assertFalse(response.isSuccess());
|
||||
Assertions.assertEquals("d==>b==>a", response.getRollbackStepStr());
|
||||
}
|
||||
|
||||
// 声明式组件测试
|
||||
// 对条件编排语法的测试
|
||||
@Test
|
||||
public void testRollbackComponent() throws Exception {
|
||||
public void testIf() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg");
|
||||
Assertions.assertFalse(response.isSuccess());
|
||||
Assertions.assertEquals("e==>a", response.getRollbackStepStr());
|
||||
Assertions.assertEquals("d==>x", response.getRollbackStepStr());
|
||||
}
|
||||
|
||||
// 对选择编排语法的测试
|
||||
@Test
|
||||
public void testSwitch() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg");
|
||||
Assertions.assertFalse(response.isSuccess());
|
||||
Assertions.assertEquals("d==>f", response.getRollbackStepStr());
|
||||
}
|
||||
|
||||
// 对FOR循环编排语法的测试
|
||||
@Test
|
||||
public void testFor() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg");
|
||||
Assertions.assertFalse(response.isSuccess());
|
||||
Assertions.assertEquals("h==>b==>g", response.getRollbackStepStr());
|
||||
}
|
||||
|
||||
// 对WHILE循环编排语法的测试
|
||||
@Test
|
||||
public void testWhile() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg");
|
||||
Assertions.assertFalse(response.isSuccess());
|
||||
Assertions.assertEquals("d==>b==>a==>w", response.getRollbackStepStr());
|
||||
}
|
||||
|
||||
// 对ITERATOR迭代循环编排语法的测试
|
||||
@Test
|
||||
public void testIterator() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg");
|
||||
Assertions.assertFalse(response.isSuccess());
|
||||
Assertions.assertEquals("d==>b==>a==>i", response.getRollbackStepStr());
|
||||
}
|
||||
|
||||
@Test
|
||||
// 对捕获异常表达式的测试
|
||||
public void testCatch() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain8", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertNull(response.getCause());
|
||||
Assertions.assertEquals("", response.getRollbackStepStr());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,29 +1,19 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.test.rollback.cmp;
|
||||
|
||||
import com.yomahub.liteflow.annotation.LiteflowCmpDefine;
|
||||
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.core.NodeSwitchComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@LiteflowComponent("f")
|
||||
@LiteflowCmpDefine
|
||||
public class FCmp {
|
||||
@Component("f")
|
||||
public class FCmp extends NodeSwitchComponent {
|
||||
|
||||
@LiteflowMethod(LiteFlowMethodEnum.PROCESS)
|
||||
public void process(NodeComponent bindCmp) {
|
||||
System.out.println("FCmp executed!");
|
||||
}
|
||||
@Override
|
||||
public String processSwitch() {
|
||||
System.out.println("FCmp executed!");
|
||||
return "abc";
|
||||
}
|
||||
|
||||
@LiteflowMethod(LiteFlowMethodEnum.ROLLBACK)
|
||||
public void rollback(NodeComponent bindCmp) {
|
||||
System.out.println("FCmp rollback!");
|
||||
}
|
||||
@Override
|
||||
public void rollback() throws Exception {
|
||||
System.out.println("FCmp rollback!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.yomahub.liteflow.test.rollback.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeForComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("g")
|
||||
public class GCmp extends NodeForComponent {
|
||||
|
||||
@Override
|
||||
public int processFor() throws Exception {
|
||||
System.out.println("GCmp executed!");
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rollback() throws Exception {
|
||||
System.out.println("GCmp rollback!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.yomahub.liteflow.test.rollback.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeBreakComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("h")
|
||||
public class HCmp extends NodeBreakComponent {
|
||||
|
||||
@Override
|
||||
public boolean processBreak() throws Exception {
|
||||
System.out.println("HCmp executed!");
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rollback() throws Exception {
|
||||
System.out.println("HCmp rollback!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.yomahub.liteflow.test.rollback.cmp;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import com.yomahub.liteflow.core.NodeIteratorComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@Component("i")
|
||||
public class ICmp extends NodeIteratorComponent {
|
||||
|
||||
@Override
|
||||
public Iterator<?> processIterator() throws Exception {
|
||||
List<String> list = ListUtil.toList("jack", "mary", "tom");
|
||||
return list.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rollback() throws Exception {
|
||||
System.out.println("ICmp rollback!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.yomahub.liteflow.test.rollback.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeWhileComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("w")
|
||||
public class WCmp extends NodeWhileComponent {
|
||||
|
||||
@Override
|
||||
public boolean processWhile() throws Exception {
|
||||
System.out.println("WCmp executed!");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rollback() throws Exception {
|
||||
System.out.println("WCmp rollback!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.yomahub.liteflow.test.rollback.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeIfComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("x")
|
||||
public class XCmp extends NodeIfComponent {
|
||||
@Override
|
||||
public boolean processIf() throws Exception {
|
||||
System.out.println("XCmp executed!");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rollback() throws Exception {
|
||||
System.out.println("XCmp rollback!");
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow>
|
||||
<chain name="chain1">
|
||||
THEN( a, b, WHEN(c, d).ignoreError(true), CATCH(e), f );
|
||||
THEN( a, b, WHEN(c, d).ignoreError(true), CATCH(e) );
|
||||
</chain>
|
||||
|
||||
<chain name="chain2">
|
||||
@@ -9,6 +9,26 @@
|
||||
</chain>
|
||||
|
||||
<chain name="chain3">
|
||||
THEN( a, e, f );
|
||||
THEN( IF(x, d, a), CATCH(IF(x, d, a)) );
|
||||
</chain>
|
||||
|
||||
<chain name="chain4">
|
||||
SWITCH(f).TO(a, b).DEFAULT(d);
|
||||
</chain>
|
||||
|
||||
<chain name="chain5">
|
||||
FOR(g).DO(THEN(b, c)).BREAK(h);;
|
||||
</chain>
|
||||
|
||||
<chain name="chain6">
|
||||
WHILE(w).DO(THEN(a, b, d));
|
||||
</chain>
|
||||
|
||||
<chain name="chain7">
|
||||
ITERATOR(i).DO(THEN(a, b, d));
|
||||
</chain>
|
||||
|
||||
<chain name="chain8">
|
||||
CATCH( THEN(b, c, d) ).DO(a);
|
||||
</chain>
|
||||
</flow>
|
||||
Reference in New Issue
Block a user