enhancement #I7KR2F 测试用例全面更新为junit5

enhancement #I7J59V java17下进行完整的测试用例测试
This commit is contained in:
everywhere.z
2023-07-12 23:51:36 +08:00
parent 269e1ec145
commit fb87a1b06a
406 changed files with 4073 additions and 4052 deletions

View File

@@ -6,11 +6,11 @@ import com.yomahub.liteflow.property.LiteflowConfigGetter;
import com.yomahub.liteflow.spi.holder.SpiFactoryCleaner;
import com.yomahub.liteflow.spring.ComponentScanner;
import com.yomahub.liteflow.thread.ExecutorHelper;
import org.junit.AfterClass;
import org.junit.jupiter.api.AfterAll;
public class BaseTest {
@AfterClass
@AfterAll
public static void cleanScanCache() {
ComponentScanner.cleanCache();
FlowBus.cleanCache();

View File

@@ -4,9 +4,10 @@ import com.yomahub.liteflow.core.FlowExecutor;
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.test.context.junit.jupiter.SpringExtension;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.ComponentScan;
@@ -21,7 +22,7 @@ import javax.annotation.Resource;
* @author Bryan.Zhang
* @since 2.6.0
*/
@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@TestPropertySource(value = "classpath:/common/application.properties")
@SpringBootTest(classes = LiteflowXmlScriptJsCommonELTest.class)
@EnableAutoConfiguration
@@ -36,8 +37,8 @@ public class LiteflowXmlScriptJsCommonELTest extends BaseTest {
public void testCommon1() {
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
DefaultContext context = response.getFirstContextBean();
Assert.assertTrue(response.isSuccess());
Assert.assertEquals(Double.valueOf(11), context.getData("s1"));
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals(Double.valueOf(11), context.getData("s1"));
}
}

View File

@@ -6,9 +6,10 @@ import com.yomahub.liteflow.test.BaseTest;
import com.yomahub.liteflow.test.script.javascript.contextbean.bean.CheckContext;
import com.yomahub.liteflow.test.script.javascript.contextbean.bean.Order2Context;
import com.yomahub.liteflow.test.script.javascript.contextbean.bean.OrderContext;
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.test.context.junit.jupiter.SpringExtension;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.ComponentScan;
@@ -17,7 +18,7 @@ import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@TestPropertySource(value = "classpath:/contextbean/application.properties")
@SpringBootTest(classes = LiteFlowScriptContextbeanJavaScriptTest.class)
@EnableAutoConfiguration
@@ -32,13 +33,13 @@ public class LiteFlowScriptContextbeanJavaScriptTest extends BaseTest {
public void testContextBean1() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class,
Order2Context.class);
Assert.assertTrue(response.isSuccess());
Assertions.assertTrue(response.isSuccess());
OrderContext orderContext = response.getContextBean(OrderContext.class);
CheckContext checkContext = response.getContextBean(CheckContext.class);
Order2Context order2Context = response.getContextBean(Order2Context.class);
Assert.assertEquals("order1", orderContext.getOrderNo());
Assert.assertEquals("sign1", checkContext.getSign());
Assert.assertEquals("order2", order2Context.getOrderNo());
Assertions.assertEquals("order1", orderContext.getOrderNo());
Assertions.assertEquals("sign1", checkContext.getSign());
Assertions.assertEquals("order2", order2Context.getOrderNo());
}
@Test
@@ -51,7 +52,7 @@ public class LiteFlowScriptContextbeanJavaScriptTest extends BaseTest {
orderContext2.setOrderNo("order2");
LiteflowResponse response = flowExecutor.execute2Resp("chain2", null, orderContext, checkContext,
orderContext2);
Assert.assertTrue(response.isSuccess());
Assertions.assertTrue(response.isSuccess());
}

View File

@@ -3,9 +3,10 @@ package com.yomahub.liteflow.test.script.javascript.ifelse;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
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.test.context.junit.jupiter.SpringExtension;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.ComponentScan;
@@ -14,7 +15,7 @@ import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@TestPropertySource(value = "classpath:/ifelse/application.properties")
@SpringBootTest(classes = LiteFlowXmlScriptIfelseJsELTest.class)
@EnableAutoConfiguration
@@ -28,56 +29,56 @@ public class LiteFlowXmlScriptIfelseJsELTest extends BaseTest {
@Test
public void testIf1() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("x0==>a==>b", response.getExecuteStepStrWithoutTime());
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("x0==>a==>b", response.getExecuteStepStrWithoutTime());
}
// IF只有3个参数
@Test
public void testIf2() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime());
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime());
}
// IF有3个参数进行嵌套
@Test
public void testIf3() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime());
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime());
}
// IF有2个参数加上ELSE
@Test
public void testIf4() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime());
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime());
}
// IF有2个参数ELSE里再嵌套一个IF
@Test
public void testIf5() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime());
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime());
}
// 标准的IF ELIF ELSE
@Test
public void testIf6() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("x1==>x0==>c==>c", response.getExecuteStepStrWithoutTime());
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("x1==>x0==>c==>c", response.getExecuteStepStrWithoutTime());
}
// IF ELIF... ELSE 的形式
@Test
public void testIf7() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("x1==>x1==>x1==>x1==>d==>b==>a", response.getExecuteStepStrWithoutTime());
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("x1==>x1==>x1==>x1==>d==>b==>a", response.getExecuteStepStrWithoutTime());
}
}

View File

@@ -3,9 +3,10 @@ package com.yomahub.liteflow.test.script.javascript.loop;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
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.test.context.junit.jupiter.SpringExtension;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.ComponentScan;
@@ -14,7 +15,7 @@ import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@TestPropertySource(value = "classpath:/loop/application.properties")
@SpringBootTest(classes = LiteFlowXmlScriptLoopJsELTest.class)
@EnableAutoConfiguration
@@ -28,31 +29,31 @@ public class LiteFlowXmlScriptLoopJsELTest extends BaseTest {
@Test
public void testLoop1() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("LOOP_2==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr());
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("LOOP_2==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr());
}
// FPR循环由For组件定义
@Test
public void testLoop2() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("x==>a==>b==>c==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr());
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("x==>a==>b==>c==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr());
}
// FOR循环中加入BREAK组件
@Test
public void testLoop3() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg");
Assert.assertTrue(response.isSuccess());
Assertions.assertTrue(response.isSuccess());
}
// WHILE循环
@Test
public void testLoop4() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z",
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z",
response.getExecuteStepStr());
}
@@ -60,8 +61,8 @@ public class LiteFlowXmlScriptLoopJsELTest extends BaseTest {
@Test
public void testLoop5() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y",
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y",
response.getExecuteStepStr());
}

View File

@@ -7,9 +7,10 @@ import com.yomahub.liteflow.flow.FlowBus;
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.test.context.junit.jupiter.SpringExtension;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.ComponentScan;
@@ -24,7 +25,7 @@ import javax.annotation.Resource;
* @author Bryan.Zhang
* @since 2.6.0
*/
@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@TestPropertySource(value = "classpath:/refresh/application.properties")
@SpringBootTest(classes = LiteflowXmlScriptJsRefreshELTest.class)
@EnableAutoConfiguration
@@ -39,8 +40,8 @@ public class LiteflowXmlScriptJsRefreshELTest extends BaseTest {
public void testRefresh1() throws Exception {
// 根据配置加载的应该是flow.xml执行原来的规则
LiteflowResponse responseOld = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(responseOld.isSuccess());
Assert.assertEquals("d==>s1[选择脚本]==>a", responseOld.getExecuteStepStr());
Assertions.assertTrue(responseOld.isSuccess());
Assertions.assertEquals("d==>s1[选择脚本]==>a", responseOld.getExecuteStepStr());
// 更改规则重新加载更改的规则内容从flow_update.xml里读取这里只是为了模拟下获取新的内容。不一定是从文件中读取
String newContent = ResourceUtil.readUtf8Str("classpath: /refresh/flow_update.xml");
// 进行刷新
@@ -48,8 +49,8 @@ public class LiteflowXmlScriptJsRefreshELTest extends BaseTest {
// 重新执行chain2这个链路结果会变
LiteflowResponse responseNew = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(responseNew.isSuccess());
Assert.assertEquals("d==>s1[选择脚本_改]==>b==>s2[普通脚本_新增]", responseNew.getExecuteStepStr());
Assertions.assertTrue(responseNew.isSuccess());
Assertions.assertEquals("d==>s1[选择脚本_改]==>b==>s2[普通脚本_新增]", responseNew.getExecuteStepStr());
}
}

View File

@@ -4,9 +4,10 @@ import com.yomahub.liteflow.core.FlowExecutor;
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.test.context.junit.jupiter.SpringExtension;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.ComponentScan;
@@ -15,7 +16,7 @@ import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@TestPropertySource(value = "classpath:/scriptbean/application.properties")
@SpringBootTest(classes = LiteFlowScriptScriptbeanJsELTest.class)
@EnableAutoConfiguration
@@ -29,17 +30,17 @@ public class LiteFlowScriptScriptbeanJsELTest extends BaseTest {
@Test
public void testScriptBean1() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(response.isSuccess());
Assertions.assertTrue(response.isSuccess());
DefaultContext context = response.getFirstContextBean();
Assert.assertEquals("hello", context.getData("demo"));
Assertions.assertEquals("hello", context.getData("demo"));
}
@Test
public void testScriptBean2() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
Assert.assertTrue(response.isSuccess());
Assertions.assertTrue(response.isSuccess());
DefaultContext context = response.getFirstContextBean();
Assert.assertEquals("hello,kobe", context.getData("demo"));
Assertions.assertEquals("hello,kobe", context.getData("demo"));
}
}

View File

@@ -4,9 +4,10 @@ import com.yomahub.liteflow.core.FlowExecutor;
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.test.context.junit.jupiter.SpringExtension;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.ComponentScan;
@@ -15,7 +16,7 @@ import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@TestPropertySource(value = "classpath:/scriptmethod/application.properties")
@SpringBootTest(classes = LiteFlowScriptScriptMethodJsELTest.class)
@EnableAutoConfiguration
@@ -29,17 +30,17 @@ public class LiteFlowScriptScriptMethodJsELTest extends BaseTest {
@Test
public void testScriptBean1() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(response.isSuccess());
Assertions.assertTrue(response.isSuccess());
DefaultContext context = response.getFirstContextBean();
Assert.assertEquals("hello", context.getData("demo"));
Assertions.assertEquals("hello", context.getData("demo"));
}
@Test
public void testScriptBean2() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
Assert.assertTrue(response.isSuccess());
Assertions.assertTrue(response.isSuccess());
DefaultContext context = response.getFirstContextBean();
Assert.assertEquals("hello,kobe", context.getData("demo"));
Assertions.assertEquals("hello,kobe", context.getData("demo"));
}
}

View File

@@ -3,9 +3,10 @@ package com.yomahub.liteflow.test.script.javascript.sw;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
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.test.context.junit.jupiter.SpringExtension;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.ComponentScan;
@@ -20,7 +21,7 @@ import javax.annotation.Resource;
* @author Bryan.Zhang
* @since 2.6.0
*/
@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@TestPropertySource(value = "classpath:/sw/application.properties")
@SpringBootTest(classes = LiteflowXmlScriptJsSwitchELTest.class)
@EnableAutoConfiguration
@@ -34,8 +35,8 @@ public class LiteflowXmlScriptJsSwitchELTest extends BaseTest {
@Test
public void testSw1() {
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("d==>s1[选择脚本]==>a", response.getExecuteStepStr());
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("d==>s1[选择脚本]==>a", response.getExecuteStepStr());
}
}

View File

@@ -4,9 +4,10 @@ import com.yomahub.liteflow.core.FlowExecutor;
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.test.context.junit.jupiter.SpringExtension;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.ComponentScan;
@@ -21,7 +22,7 @@ import javax.annotation.Resource;
* @author Bryan.Zhang
* @since 2.6.0
*/
@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@TestPropertySource(value = "classpath:/throwException/application.properties")
@SpringBootTest(classes = ThrowExceptionScriptJsCommonELTest.class)
@EnableAutoConfiguration
@@ -36,7 +37,7 @@ public class ThrowExceptionScriptJsCommonELTest extends BaseTest {
public void testCommon1() {
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
DefaultContext context = response.getFirstContextBean();
Assert.assertFalse(response.isSuccess());
Assertions.assertFalse(response.isSuccess());
}
}