feature #I7I3LL 测试用例更新为JUnit5

This commit is contained in:
Dale Lee
2023-07-14 11:06:08 +08:00
parent f521f92aaa
commit 09b7062cb8
6 changed files with 82 additions and 90 deletions

View File

@@ -6,17 +6,16 @@ import com.yomahub.liteflow.exception.WhenTimeoutException;
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.concurrent.TimeoutException;
import static com.yomahub.liteflow.test.maxWaitSeconds.cmp.CmpConfig.CONTENT_KEY;
@@ -27,11 +26,11 @@ import static com.yomahub.liteflow.test.maxWaitSeconds.cmp.CmpConfig.CONTENT_KEY
* @author DaleLee
* @since 2.11.0
*/
@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@TestPropertySource(value = "classpath:/maxWaitSeconds/application.properties")
@SpringBootTest(classes = MaxWaitSecondsELDeclMultiSpringbootTest.class)
@EnableAutoConfiguration
@ComponentScan({ "com.yomahub.liteflow.test.maxWaitSeconds.cmp" })
@ComponentScan({"com.yomahub.liteflow.test.maxWaitSeconds.cmp"})
public class MaxWaitSecondsELDeclMultiSpringbootTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
@@ -136,17 +135,17 @@ public class MaxWaitSecondsELDeclMultiSpringbootTest extends BaseTest {
@Test
public void testFinally1() {
LiteflowResponse response = flowExecutor.execute2Resp("finally", "arg");
Assert.assertFalse(response.isSuccess());
Assert.assertEquals(TimeoutException.class, response.getCause().getClass());
Assertions.assertFalse(response.isSuccess());
Assertions.assertEquals(TimeoutException.class, response.getCause().getClass());
// FINALLY 执行时在默认数据上下文中放入了 CONTENT_KEY
DefaultContext contextBean = response.getFirstContextBean();
Assert.assertTrue(contextBean.hasData(CONTENT_KEY));
Assertions.assertTrue(contextBean.hasData(CONTENT_KEY));
}
// 测试 maxWaitSeconds 关键字不能作用于 Finally
@Test
public void testFinally2() {
Assert.assertFalse(LiteFlowChainELBuilder.validate("THEN(a, b, FINALLY(c).maxWaitSeconds(10))"));
Assertions.assertFalse(LiteFlowChainELBuilder.validate("THEN(a, b, FINALLY(c).maxWaitSeconds(10))"));
}
// 测试 chain 的超时情况
@@ -163,18 +162,18 @@ public class MaxWaitSecondsELDeclMultiSpringbootTest extends BaseTest {
private void assertTimeout(String chainId) {
LiteflowResponse response = flowExecutor.execute2Resp(chainId, "arg");
Assert.assertFalse(response.isSuccess());
Assert.assertEquals(TimeoutException.class, response.getCause().getClass());
Assertions.assertFalse(response.isSuccess());
Assertions.assertEquals(TimeoutException.class, response.getCause().getClass());
}
private void assertWhenTimeout(String chainId) {
LiteflowResponse response = flowExecutor.execute2Resp(chainId, "arg");
Assert.assertFalse(response.isSuccess());
Assert.assertEquals(WhenTimeoutException.class, response.getCause().getClass());
Assertions.assertFalse(response.isSuccess());
Assertions.assertEquals(WhenTimeoutException.class, response.getCause().getClass());
}
private void assertNotTimeout(String chainId) {
LiteflowResponse response = flowExecutor.execute2Resp(chainId, "arg");
Assert.assertTrue(response.isSuccess());
Assertions.assertTrue(response.isSuccess());
}
}

View File

@@ -11,17 +11,16 @@ import com.yomahub.liteflow.test.BaseTest;
import com.yomahub.liteflow.test.maxWaitSeconds.cmp.ACmp;
import com.yomahub.liteflow.test.maxWaitSeconds.cmp.BCmp;
import com.yomahub.liteflow.test.maxWaitSeconds.cmp.CCmp;
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.concurrent.TimeoutException;
import static com.yomahub.liteflow.test.maxWaitSeconds.cmp.DCmp.CONTENT_KEY;
@@ -32,7 +31,7 @@ import static com.yomahub.liteflow.test.maxWaitSeconds.cmp.DCmp.CONTENT_KEY;
* @author DaleLee
* @since 2.11.0
*/
@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@TestPropertySource(value = "classpath:/maxWaitSeconds/application.properties")
@SpringBootTest(classes = MaxWaitSecondsELDeclSpringbootTest.class)
@EnableAutoConfiguration
@@ -141,11 +140,11 @@ public class MaxWaitSecondsELDeclSpringbootTest extends BaseTest {
@Test
public void testFinally1() {
LiteflowResponse response = flowExecutor.execute2Resp("finally", "arg");
Assert.assertFalse(response.isSuccess());
Assert.assertEquals(TimeoutException.class, response.getCause().getClass());
Assertions.assertFalse(response.isSuccess());
Assertions.assertEquals(TimeoutException.class, response.getCause().getClass());
// FINALLY 执行时在默认数据上下文中放入了 CONTENT_KEY
DefaultContext contextBean = response.getFirstContextBean();
Assert.assertTrue(contextBean.hasData(CONTENT_KEY));
Assertions.assertTrue(contextBean.hasData(CONTENT_KEY));
}
// 测试 maxWaitSeconds 关键字不能作用于 Finally
@@ -169,7 +168,7 @@ public class MaxWaitSecondsELDeclSpringbootTest extends BaseTest {
.setType(NodeTypeEnum.COMMON)
.setClazz(CCmp.class)
.build();
Assert.assertFalse(LiteFlowChainELBuilder.validate("THEN(a, b, FINALLY(c).maxWaitSeconds(10))"));
Assertions.assertFalse(LiteFlowChainELBuilder.validate("THEN(a, b, FINALLY(c).maxWaitSeconds(10))"));
}
// 测试 chain 的超时情况
@@ -186,18 +185,18 @@ public class MaxWaitSecondsELDeclSpringbootTest extends BaseTest {
private void assertTimeout(String chainId) {
LiteflowResponse response = flowExecutor.execute2Resp(chainId, "arg");
Assert.assertFalse(response.isSuccess());
Assert.assertEquals(TimeoutException.class, response.getCause().getClass());
Assertions.assertFalse(response.isSuccess());
Assertions.assertEquals(TimeoutException.class, response.getCause().getClass());
}
private void assertWhenTimeout(String chainId) {
LiteflowResponse response = flowExecutor.execute2Resp(chainId, "arg");
Assert.assertFalse(response.isSuccess());
Assert.assertEquals(WhenTimeoutException.class, response.getCause().getClass());
Assertions.assertFalse(response.isSuccess());
Assertions.assertEquals(WhenTimeoutException.class, response.getCause().getClass());
}
private void assertNotTimeout(String chainId) {
LiteflowResponse response = flowExecutor.execute2Resp(chainId, "arg");
Assert.assertTrue(response.isSuccess());
Assertions.assertTrue(response.isSuccess());
}
}

View File

@@ -13,9 +13,10 @@ import com.yomahub.liteflow.test.BaseTest;
import com.yomahub.liteflow.test.maxWaitSeconds.cmp.ACmp;
import com.yomahub.liteflow.test.maxWaitSeconds.cmp.BCmp;
import com.yomahub.liteflow.test.maxWaitSeconds.cmp.CCmp;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.util.concurrent.TimeoutException;
@@ -31,7 +32,7 @@ public class MaxWaitSecondsTest extends BaseTest {
private static FlowExecutor flowExecutor;
@BeforeClass
@BeforeAll
public static void init() {
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("maxWaitSeconds/flow.el.xml");
@@ -138,11 +139,11 @@ public class MaxWaitSecondsTest extends BaseTest {
@Test
public void testFinally1() {
LiteflowResponse response = flowExecutor.execute2Resp("finally", "arg");
Assert.assertFalse(response.isSuccess());
Assert.assertEquals(TimeoutException.class, response.getCause().getClass());
Assertions.assertFalse(response.isSuccess());
Assertions.assertEquals(TimeoutException.class, response.getCause().getClass());
// FINALLY 执行时在默认数据上下文中放入了 CONTENT_KEY
DefaultContext contextBean = response.getFirstContextBean();
Assert.assertTrue(contextBean.hasData(CONTENT_KEY));
Assertions.assertTrue(contextBean.hasData(CONTENT_KEY));
}
@@ -167,7 +168,7 @@ public class MaxWaitSecondsTest extends BaseTest {
.setType(NodeTypeEnum.COMMON)
.setClazz(CCmp.class)
.build();
Assert.assertFalse(LiteFlowChainELBuilder.validate("THEN(a, b, FINALLY(c).maxWaitSeconds(10))"));
Assertions.assertFalse(LiteFlowChainELBuilder.validate("THEN(a, b, FINALLY(c).maxWaitSeconds(10))"));
}
// 测试 chain 的超时情况
@@ -184,19 +185,19 @@ public class MaxWaitSecondsTest extends BaseTest {
private void assertTimeout(String chainId) {
LiteflowResponse response = flowExecutor.execute2Resp(chainId, "arg");
Assert.assertFalse(response.isSuccess());
Assert.assertEquals(TimeoutException.class, response.getCause().getClass());
Assertions.assertFalse(response.isSuccess());
Assertions.assertEquals(TimeoutException.class, response.getCause().getClass());
}
private void assertWhenTimeout(String chainId) {
LiteflowResponse response = flowExecutor.execute2Resp(chainId, "arg");
Assert.assertFalse(response.isSuccess());
Assert.assertEquals(WhenTimeoutException.class, response.getCause().getClass());
Assertions.assertFalse(response.isSuccess());
Assertions.assertEquals(WhenTimeoutException.class, response.getCause().getClass());
}
private void assertNotTimeout(String chainId) {
LiteflowResponse response = flowExecutor.execute2Resp(chainId, "arg");
Assert.assertTrue(response.isSuccess());
Assertions.assertTrue(response.isSuccess());
}
}

View File

@@ -11,11 +11,11 @@ import com.yomahub.liteflow.test.BaseTest;
import com.yomahub.liteflow.test.maxWaitSeconds.cmp.ACmp;
import com.yomahub.liteflow.test.maxWaitSeconds.cmp.BCmp;
import com.yomahub.liteflow.test.maxWaitSeconds.cmp.CCmp;
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.noear.solon.annotation.Inject;
import org.noear.solon.test.SolonJUnit4ClassRunner;
import org.noear.solon.test.SolonJUnit5Extension;
import org.noear.solon.test.annotation.TestPropertySource;
import java.util.concurrent.TimeoutException;
@@ -28,7 +28,7 @@ import static com.yomahub.liteflow.test.maxWaitSeconds.cmp.DCmp.CONTENT_KEY;
* @author DaleLee
* @since 2.11.0
*/
@RunWith(SolonJUnit4ClassRunner.class)
@ExtendWith(SolonJUnit5Extension.class)
@TestPropertySource("classpath:/maxWaitSeconds/application.properties")
public class MaxWaitSecondsSolonTest extends BaseTest {
@@ -135,11 +135,11 @@ public class MaxWaitSecondsSolonTest extends BaseTest {
@Test
public void testFinally1() {
LiteflowResponse response = flowExecutor.execute2Resp("finally", "arg");
Assert.assertFalse(response.isSuccess());
Assert.assertEquals(TimeoutException.class, response.getCause().getClass());
Assertions.assertFalse(response.isSuccess());
Assertions.assertEquals(TimeoutException.class, response.getCause().getClass());
// FINALLY 执行时在默认数据上下文中放入了 CONTENT_KEY
DefaultContext contextBean = response.getFirstContextBean();
Assert.assertTrue(contextBean.hasData(CONTENT_KEY));
Assertions.assertTrue(contextBean.hasData(CONTENT_KEY));
}
@@ -164,7 +164,7 @@ public class MaxWaitSecondsSolonTest extends BaseTest {
.setType(NodeTypeEnum.COMMON)
.setClazz(CCmp.class)
.build();
Assert.assertFalse(LiteFlowChainELBuilder.validate("THEN(a, b, FINALLY(c).maxWaitSeconds(10))"));
Assertions.assertFalse(LiteFlowChainELBuilder.validate("THEN(a, b, FINALLY(c).maxWaitSeconds(10))"));
}
// 测试 chain 的超时情况
@@ -181,18 +181,18 @@ public class MaxWaitSecondsSolonTest extends BaseTest {
private void assertTimeout(String chainId) {
LiteflowResponse response = flowExecutor.execute2Resp(chainId, "arg");
Assert.assertFalse(response.isSuccess());
Assert.assertEquals(TimeoutException.class, response.getCause().getClass());
Assertions.assertFalse(response.isSuccess());
Assertions.assertEquals(TimeoutException.class, response.getCause().getClass());
}
private void assertWhenTimeout(String chainId) {
LiteflowResponse response = flowExecutor.execute2Resp(chainId, "arg");
Assert.assertFalse(response.isSuccess());
Assert.assertEquals(WhenTimeoutException.class, response.getCause().getClass());
Assertions.assertFalse(response.isSuccess());
Assertions.assertEquals(WhenTimeoutException.class, response.getCause().getClass());
}
private void assertNotTimeout(String chainId) {
LiteflowResponse response = flowExecutor.execute2Resp(chainId, "arg");
Assert.assertTrue(response.isSuccess());
Assertions.assertTrue(response.isSuccess());
}
}

View File

@@ -11,17 +11,14 @@ import com.yomahub.liteflow.test.BaseTest;
import com.yomahub.liteflow.test.validateRule.cmp.ACmp;
import com.yomahub.liteflow.test.validateRule.cmp.BCmp;
import com.yomahub.liteflow.test.validateRule.cmp.CCmp;
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.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 javax.annotation.Resource;
import java.util.concurrent.TimeoutException;
import static com.yomahub.liteflow.test.maxWaitSeconds.cmp.DCmp.CONTENT_KEY;
@@ -32,7 +29,6 @@ import static com.yomahub.liteflow.test.maxWaitSeconds.cmp.DCmp.CONTENT_KEY;
* @author DaleLee
* @since 2.11.0
*/
@RunWith(SpringRunner.class)
@TestPropertySource(value = "classpath:/maxWaitSeconds/application.properties")
@SpringBootTest(classes = MaxWaitSecondsELSpringbootTest.class)
@EnableAutoConfiguration
@@ -143,12 +139,11 @@ public class MaxWaitSecondsELSpringbootTest extends BaseTest {
@Test
public void testFinally1() {
LiteflowResponse response = flowExecutor.execute2Resp("finally", "arg");
Assert.assertFalse(response.isSuccess());
Assert.assertEquals(TimeoutException.class, response.getCause().getClass());
Assertions.assertFalse(response.isSuccess());
Assertions.assertEquals(TimeoutException.class, response.getCause().getClass());
// FINALLY 执行时在默认数据上下文中放入了 CONTENT_KEY
DefaultContext contextBean = response.getFirstContextBean();
Assert.assertTrue(contextBean.hasData(CONTENT_KEY));
Assertions.assertTrue(contextBean.hasData(CONTENT_KEY));
}
// 测试 maxWaitSeconds 关键字不能作用于 Finally
@@ -172,7 +167,7 @@ public class MaxWaitSecondsELSpringbootTest extends BaseTest {
.setType(NodeTypeEnum.COMMON)
.setClazz(CCmp.class)
.build();
Assert.assertFalse(LiteFlowChainELBuilder.validate("THEN(a, b, FINALLY(c).maxWaitSeconds(10))"));
Assertions.assertFalse(LiteFlowChainELBuilder.validate("THEN(a, b, FINALLY(c).maxWaitSeconds(10))"));
}
// 测试 chain 的超时情况
@@ -189,18 +184,18 @@ public class MaxWaitSecondsELSpringbootTest extends BaseTest {
private void assertTimeout(String chainId) {
LiteflowResponse response = flowExecutor.execute2Resp(chainId, "arg");
Assert.assertFalse(response.isSuccess());
Assert.assertEquals(TimeoutException.class, response.getCause().getClass());
Assertions.assertFalse(response.isSuccess());
Assertions.assertEquals(TimeoutException.class, response.getCause().getClass());
}
private void assertWhenTimeout(String chainId) {
LiteflowResponse response = flowExecutor.execute2Resp(chainId, "arg");
Assert.assertFalse(response.isSuccess());
Assert.assertEquals(WhenTimeoutException.class, response.getCause().getClass());
Assertions.assertFalse(response.isSuccess());
Assertions.assertEquals(WhenTimeoutException.class, response.getCause().getClass());
}
private void assertNotTimeout(String chainId) {
LiteflowResponse response = flowExecutor.execute2Resp(chainId, "arg");
Assert.assertTrue(response.isSuccess());
Assertions.assertTrue(response.isSuccess());
}
}

View File

@@ -11,14 +11,13 @@ import com.yomahub.liteflow.test.BaseTest;
import com.yomahub.liteflow.test.maxWaitSeconds.cmp.ACmp;
import com.yomahub.liteflow.test.maxWaitSeconds.cmp.BCmp;
import com.yomahub.liteflow.test.maxWaitSeconds.cmp.CCmp;
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.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import javax.annotation.Resource;
import java.util.concurrent.TimeoutException;
import static com.yomahub.liteflow.test.maxWaitSeconds.cmp.DCmp.CONTENT_KEY;
@@ -29,7 +28,7 @@ import static com.yomahub.liteflow.test.maxWaitSeconds.cmp.DCmp.CONTENT_KEY;
* @author DaleLee
* @since 2.11.0
*/
@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@ContextConfiguration("classpath:/maxWaitSeconds/application.xml")
public class MaxWaitSecondsELSpringTest extends BaseTest {
@Resource
@@ -135,12 +134,11 @@ public class MaxWaitSecondsELSpringTest extends BaseTest {
@Test
public void testFinally1() {
LiteflowResponse response = flowExecutor.execute2Resp("finally", "arg");
Assert.assertFalse(response.isSuccess());
Assert.assertEquals(TimeoutException.class, response.getCause().getClass());
Assertions.assertFalse(response.isSuccess());
Assertions.assertEquals(TimeoutException.class, response.getCause().getClass());
// FINALLY 执行时在默认数据上下文中放入了 CONTENT_KEY
DefaultContext contextBean = response.getFirstContextBean();
Assert.assertTrue(contextBean.hasData(CONTENT_KEY));
Assertions.assertTrue(contextBean.hasData(CONTENT_KEY));
}
// 测试 maxWaitSeconds 关键字不能作用于 Finally
@@ -164,7 +162,7 @@ public class MaxWaitSecondsELSpringTest extends BaseTest {
.setType(NodeTypeEnum.COMMON)
.setClazz(CCmp.class)
.build();
Assert.assertFalse(LiteFlowChainELBuilder.validate("THEN(a, b, FINALLY(c).maxWaitSeconds(10))"));
Assertions.assertFalse(LiteFlowChainELBuilder.validate("THEN(a, b, FINALLY(c).maxWaitSeconds(10))"));
}
// 测试 chain 的超时情况
@@ -181,18 +179,18 @@ public class MaxWaitSecondsELSpringTest extends BaseTest {
private void assertTimeout(String chainId) {
LiteflowResponse response = flowExecutor.execute2Resp(chainId, "arg");
Assert.assertFalse(response.isSuccess());
Assert.assertEquals(TimeoutException.class, response.getCause().getClass());
Assertions.assertFalse(response.isSuccess());
Assertions.assertEquals(TimeoutException.class, response.getCause().getClass());
}
private void assertWhenTimeout(String chainId) {
LiteflowResponse response = flowExecutor.execute2Resp(chainId, "arg");
Assert.assertFalse(response.isSuccess());
Assert.assertEquals(WhenTimeoutException.class, response.getCause().getClass());
Assertions.assertFalse(response.isSuccess());
Assertions.assertEquals(WhenTimeoutException.class, response.getCause().getClass());
}
private void assertNotTimeout(String chainId) {
LiteflowResponse response = flowExecutor.execute2Resp(chainId, "arg");
Assert.assertTrue(response.isSuccess());
Assertions.assertTrue(response.isSuccess());
}
}