feature #I7HJFX 升级原本ParallelLoop的测试用例到Junit5
This commit is contained in:
parent
ecfdb208b0
commit
2614c9d135
|
@ -6,14 +6,15 @@ import com.yomahub.liteflow.exception.LiteFlowException;
|
|||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
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 org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
@ -25,7 +26,7 @@ import java.util.regex.Pattern;
|
|||
* @author zhhhhy
|
||||
* @since 2.11.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/parallelLoop/application.properties")
|
||||
@SpringBootTest(classes = ParallelLoopELDeclSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -39,46 +40,46 @@ public class ParallelLoopELDeclSpringbootTest extends BaseTest {
|
|||
@Test
|
||||
public void testParallelLoop1() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
//测试并行FOR循环,循环次数由For组件定义
|
||||
@Test
|
||||
public void testParallelLoop2() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
//测试并行FOR循环中的BREAK组件能够正常发挥作用
|
||||
@Test
|
||||
public void testParallelLoop3() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
//测试并行FOR循环中,主线程是否会正常等待所有并行子项完成后再继续执行
|
||||
@Test
|
||||
public void testParallelLoop4() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
@Test
|
||||
//测试并行FOR循环中,某个并行子项抛出异常
|
||||
public void testParallelLoop5() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg");
|
||||
Assert.assertFalse(response.isSuccess());
|
||||
Assert.assertEquals("300", response.getCode());
|
||||
Assert.assertNotNull(response.getCause());
|
||||
Assert.assertTrue(response.getCause() instanceof LiteFlowException);
|
||||
Assert.assertNotNull(response.getSlot());
|
||||
Assertions.assertFalse(response.isSuccess());
|
||||
Assertions.assertEquals("300", response.getCode());
|
||||
Assertions.assertNotNull(response.getCause());
|
||||
Assertions.assertTrue(response.getCause() instanceof LiteFlowException);
|
||||
Assertions.assertNotNull(response.getSlot());
|
||||
}
|
||||
|
||||
//并行的条件循环
|
||||
@Test
|
||||
public void testParallelLoop6() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
//并行的迭代循环
|
||||
|
@ -86,7 +87,7 @@ public class ParallelLoopELDeclSpringbootTest extends BaseTest {
|
|||
public void testParallelLoop7() throws Exception {
|
||||
List<String> list = ListUtil.toList("1", "2", "3", "4", "5");
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain7", list);
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
//测试并行FOR循环中的index
|
||||
|
@ -94,13 +95,13 @@ public class ParallelLoopELDeclSpringbootTest extends BaseTest {
|
|||
public void testParallelLoop8() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain8", "arg");
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
String regex = "(?!.*(.).*\\1)[0-4]{5}"; //匹配不包含重复数字的0-4的5位数字
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
//e1,e2,e3分别并行执行5次,因此单个循环的顺序可以是任意的
|
||||
Assert.assertTrue(pattern.matcher(context.getData("loop_e1")).matches());
|
||||
Assert.assertTrue(pattern.matcher(context.getData("loop_e2")).matches());
|
||||
Assert.assertTrue(pattern.matcher(context.getData("loop_e3")).matches());
|
||||
Assertions.assertTrue(pattern.matcher(context.getData("loop_e1")).matches());
|
||||
Assertions.assertTrue(pattern.matcher(context.getData("loop_e2")).matches());
|
||||
Assertions.assertTrue(pattern.matcher(context.getData("loop_e3")).matches());
|
||||
}
|
||||
|
||||
|
||||
|
@ -109,8 +110,8 @@ public class ParallelLoopELDeclSpringbootTest extends BaseTest {
|
|||
public void testParallelLoop9() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain9", "arg");
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertTrue(context.getData("threadName").toString().startsWith("customer-loop-thead"));
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-loop-thead"));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -6,14 +6,14 @@ import com.yomahub.liteflow.exception.LiteFlowException;
|
|||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
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 org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
@ -25,7 +25,7 @@ import java.util.regex.Pattern;
|
|||
* @author zhhhhy
|
||||
* @since 2.11.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/parallelLoop/application.properties")
|
||||
@SpringBootTest(classes = ParallelLoopELDeclSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -39,46 +39,46 @@ public class ParallelLoopELDeclSpringbootTest extends BaseTest {
|
|||
@Test
|
||||
public void testParallelLoop1() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
//测试并行FOR循环,循环次数由For组件定义
|
||||
@Test
|
||||
public void testParallelLoop2() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
//测试并行FOR循环中的BREAK组件能够正常发挥作用
|
||||
@Test
|
||||
public void testParallelLoop3() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
//测试并行FOR循环中,主线程是否会正常等待所有并行子项完成后再继续执行
|
||||
@Test
|
||||
public void testParallelLoop4() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
@Test
|
||||
//测试并行FOR循环中,某个并行子项抛出异常
|
||||
public void testParallelLoop5() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg");
|
||||
Assert.assertFalse(response.isSuccess());
|
||||
Assert.assertEquals("300", response.getCode());
|
||||
Assert.assertNotNull(response.getCause());
|
||||
Assert.assertTrue(response.getCause() instanceof LiteFlowException);
|
||||
Assert.assertNotNull(response.getSlot());
|
||||
Assertions.assertFalse(response.isSuccess());
|
||||
Assertions.assertEquals("300", response.getCode());
|
||||
Assertions.assertNotNull(response.getCause());
|
||||
Assertions.assertTrue(response.getCause() instanceof LiteFlowException);
|
||||
Assertions.assertNotNull(response.getSlot());
|
||||
}
|
||||
|
||||
//并行的条件循环
|
||||
@Test
|
||||
public void testParallelLoop6() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
//并行的迭代循环
|
||||
|
@ -86,7 +86,7 @@ public class ParallelLoopELDeclSpringbootTest extends BaseTest {
|
|||
public void testParallelLoop7() throws Exception {
|
||||
List<String> list = ListUtil.toList("1", "2", "3", "4", "5");
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain7", list);
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
//测试并行FOR循环中的index
|
||||
|
@ -94,13 +94,13 @@ public class ParallelLoopELDeclSpringbootTest extends BaseTest {
|
|||
public void testParallelLoop8() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain8", "arg");
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
String regex = "(?!.*(.).*\\1)[0-4]{5}"; //匹配不包含重复数字的0-4的5位数字
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
//e1,e2,e3分别并行执行5次,因此单个循环的顺序可以是任意的
|
||||
Assert.assertTrue(pattern.matcher(context.getData("loop_e1")).matches());
|
||||
Assert.assertTrue(pattern.matcher(context.getData("loop_e2")).matches());
|
||||
Assert.assertTrue(pattern.matcher(context.getData("loop_e3")).matches());
|
||||
Assertions.assertTrue(pattern.matcher(context.getData("loop_e1")).matches());
|
||||
Assertions.assertTrue(pattern.matcher(context.getData("loop_e2")).matches());
|
||||
Assertions.assertTrue(pattern.matcher(context.getData("loop_e3")).matches());
|
||||
}
|
||||
|
||||
|
||||
|
@ -109,8 +109,8 @@ public class ParallelLoopELDeclSpringbootTest extends BaseTest {
|
|||
public void testParallelLoop9() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain9", "arg");
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertTrue(context.getData("threadName").toString().startsWith("customer-loop-thead"));
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-loop-thead"));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue