增加了新的rollback测试用例

This commit is contained in:
rain
2023-08-18 14:47:35 +08:00
parent 1da30a66bb
commit 05492fc198
43 changed files with 1086 additions and 40 deletions

View File

@@ -10,6 +10,7 @@ import org.noear.solon.annotation.Inject;
import org.noear.solon.test.SolonJUnit5Extension;
import org.noear.solon.test.annotation.TestPropertySource;
@ExtendWith(SolonJUnit5Extension.class)
@TestPropertySource("classpath:/rollback/application.properties")
public class RollbackSpringbootTest extends BaseTest {
@@ -26,12 +27,61 @@ public class RollbackSpringbootTest 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 testIf() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg");
Assertions.assertFalse(response.isSuccess());
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());
}
}

View File

@@ -0,0 +1,19 @@
package com.yomahub.liteflow.test.rollback.cmp;
import com.yomahub.liteflow.core.NodeSwitchComponent;
import org.noear.solon.annotation.Component;
@Component("f")
public class FCmp extends NodeSwitchComponent {
@Override
public String processSwitch() {
System.out.println("FCmp executed!");
return "abc";
}
@Override
public void rollback() throws Exception {
System.out.println("FCmp rollback!");
}
}

View File

@@ -0,0 +1,19 @@
package com.yomahub.liteflow.test.rollback.cmp;
import com.yomahub.liteflow.core.NodeForComponent;
import org.noear.solon.annotation.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!");
}
}

View File

@@ -0,0 +1,19 @@
package com.yomahub.liteflow.test.rollback.cmp;
import com.yomahub.liteflow.core.NodeBreakComponent;
import org.noear.solon.annotation.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!");
}
}

View File

@@ -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.noear.solon.annotation.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!");
}
}

View File

@@ -0,0 +1,19 @@
package com.yomahub.liteflow.test.rollback.cmp;
import com.yomahub.liteflow.core.NodeWhileComponent;
import org.noear.solon.annotation.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!");
}
}

View File

@@ -0,0 +1,18 @@
package com.yomahub.liteflow.test.rollback.cmp;
import com.yomahub.liteflow.core.NodeIfComponent;
import org.noear.solon.annotation.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!");
}
}

View File

@@ -7,4 +7,28 @@
<chain name="chain2">
THEN( a, b, WHEN(c, d) );
</chain>
<chain name="chain3">
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>