From b1e1cfce5e6c552ff6327692b7c696a197fee176 Mon Sep 17 00:00:00 2001 From: tangkc Date: Mon, 13 Jun 2022 14:40:33 +0800 Subject: [PATCH] =?UTF-8?q?[I5BR5M]chain=20=E9=87=8D=E5=A4=8D=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/Exception1SpringBootTest.java | 27 ++++++++++++------- .../resources/exception/flow-exception.xml | 10 +++++++ .../test/exception/Exception1Test.java | 20 +++++++++++--- .../resources/exception/flow-exception.xml | 10 +++++++ .../exception/Exception1SpringBootTest.java | 25 ++++++++++------- .../resources/exception/flow-exception.xml | 10 +++++++ .../test/exception/Exception1SpringTest.java | 17 ++++++++++++ .../resources/exception/flow-exception.xml | 10 +++++++ 8 files changed, 106 insertions(+), 23 deletions(-) create mode 100644 liteflow-testcase-declare-component/src/test/resources/exception/flow-exception.xml create mode 100644 liteflow-testcase-nospring/src/test/resources/exception/flow-exception.xml create mode 100644 liteflow-testcase-springboot/src/test/resources/exception/flow-exception.xml create mode 100644 liteflow-testcase-springnative/src/test/resources/exception/flow-exception.xml diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/Exception1SpringBootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/Exception1SpringBootTest.java index 338fbe424..bd1e2fa90 100644 --- a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/Exception1SpringBootTest.java +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/Exception1SpringBootTest.java @@ -1,26 +1,17 @@ package com.yomahub.liteflow.test.exception; import com.yomahub.liteflow.core.FlowExecutor; -import com.yomahub.liteflow.exception.ChainNotFoundException; import com.yomahub.liteflow.exception.ConfigErrorException; import com.yomahub.liteflow.exception.FlowExecutorNotInitException; -import com.yomahub.liteflow.exception.FlowSystemException; -import com.yomahub.liteflow.flow.LiteflowResponse; import com.yomahub.liteflow.property.LiteflowConfig; import com.yomahub.liteflow.property.LiteflowConfigGetter; -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.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.util.ReflectionUtils; import javax.annotation.Resource; @@ -34,10 +25,26 @@ import javax.annotation.Resource; @SpringBootTest(classes = Exception1SpringBootTest.class) @EnableAutoConfiguration public class Exception1SpringBootTest extends BaseTest { - + @Resource private FlowExecutor flowExecutor; + /** + * 验证 chain 节点重复的异常 + */ + @Test(expected = FlowExecutorNotInitException.class) + public void testChainDuplicateException() { + try { + LiteflowConfig config = LiteflowConfigGetter.get(); + config.setRuleSource("exception/flow-exception.xml"); + flowExecutor.init(); + } catch (Exception ex) { + // 这里需要 catch 是因为,异常是往上抛的,最后被包装成了 FlowExecutorNotInitException + Assert.assertTrue(ex.getMessage().contains("[chain name duplicate]")); + throw ex; + } + } + @Test(expected = ConfigErrorException.class) public void testConfigErrorException() { flowExecutor.setLiteflowConfig(null); diff --git a/liteflow-testcase-declare-component/src/test/resources/exception/flow-exception.xml b/liteflow-testcase-declare-component/src/test/resources/exception/flow-exception.xml new file mode 100644 index 000000000..662226def --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/exception/flow-exception.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/exception/Exception1Test.java b/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/exception/Exception1Test.java index c988a9b5a..b062dd7fb 100644 --- a/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/exception/Exception1Test.java +++ b/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/exception/Exception1Test.java @@ -2,14 +2,10 @@ package com.yomahub.liteflow.test.exception; import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.core.FlowExecutorHolder; -import com.yomahub.liteflow.exception.ChainNotFoundException; import com.yomahub.liteflow.exception.ConfigErrorException; import com.yomahub.liteflow.exception.FlowExecutorNotInitException; -import com.yomahub.liteflow.exception.FlowSystemException; -import com.yomahub.liteflow.flow.LiteflowResponse; import com.yomahub.liteflow.property.LiteflowConfig; import com.yomahub.liteflow.property.LiteflowConfigGetter; -import com.yomahub.liteflow.slot.DefaultContext; import com.yomahub.liteflow.test.BaseTest; import org.junit.Assert; import org.junit.BeforeClass; @@ -33,6 +29,22 @@ public class Exception1Test extends BaseTest { flowExecutor = FlowExecutorHolder.loadInstance(config); } + /** + * 验证 chain 节点重复的异常 + */ + @Test(expected = FlowExecutorNotInitException.class) + public void testChainDuplicateException() { + try { + LiteflowConfig config = LiteflowConfigGetter.get(); + config.setRuleSource("exception/flow-exception.xml"); + flowExecutor.init(); + } catch (Exception ex) { + // 这里需要 catch 是因为,异常是往上抛的,最后被包装成了 FlowExecutorNotInitException + Assert.assertTrue(ex.getMessage().contains("[chain name duplicate]")); + throw ex; + } + } + @Test(expected = ConfigErrorException.class) public void testConfigErrorException() { flowExecutor.setLiteflowConfig(null); diff --git a/liteflow-testcase-nospring/src/test/resources/exception/flow-exception.xml b/liteflow-testcase-nospring/src/test/resources/exception/flow-exception.xml new file mode 100644 index 000000000..662226def --- /dev/null +++ b/liteflow-testcase-nospring/src/test/resources/exception/flow-exception.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception1SpringBootTest.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception1SpringBootTest.java index 5a79866e4..65b7b7edc 100644 --- a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception1SpringBootTest.java +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception1SpringBootTest.java @@ -1,26 +1,17 @@ package com.yomahub.liteflow.test.exception; import com.yomahub.liteflow.core.FlowExecutor; -import com.yomahub.liteflow.exception.ChainNotFoundException; import com.yomahub.liteflow.exception.ConfigErrorException; import com.yomahub.liteflow.exception.FlowExecutorNotInitException; -import com.yomahub.liteflow.exception.FlowSystemException; -import com.yomahub.liteflow.flow.LiteflowResponse; import com.yomahub.liteflow.property.LiteflowConfig; import com.yomahub.liteflow.property.LiteflowConfigGetter; -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.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.util.ReflectionUtils; import javax.annotation.Resource; @@ -38,6 +29,22 @@ public class Exception1SpringBootTest extends BaseTest { @Resource private FlowExecutor flowExecutor; + /** + * 验证 chain 节点重复的异常 + */ + @Test(expected = FlowExecutorNotInitException.class) + public void testChainDuplicateException() { + try { + LiteflowConfig config = LiteflowConfigGetter.get(); + config.setRuleSource("exception/flow-exception.xml"); + flowExecutor.init(); + } catch (Exception ex) { + // 这里需要 catch 是因为,异常是往上抛的,最后被包装成了 FlowExecutorNotInitException + Assert.assertTrue(ex.getMessage().contains("[chain name duplicate]")); + throw ex; + } + } + @Test(expected = ConfigErrorException.class) public void testConfigErrorException() { flowExecutor.setLiteflowConfig(null); diff --git a/liteflow-testcase-springboot/src/test/resources/exception/flow-exception.xml b/liteflow-testcase-springboot/src/test/resources/exception/flow-exception.xml new file mode 100644 index 000000000..662226def --- /dev/null +++ b/liteflow-testcase-springboot/src/test/resources/exception/flow-exception.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/exception/Exception1SpringTest.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/exception/Exception1SpringTest.java index 3bccb2781..fbb9d3c9e 100644 --- a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/exception/Exception1SpringTest.java +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/exception/Exception1SpringTest.java @@ -6,6 +6,7 @@ import com.yomahub.liteflow.exception.FlowExecutorNotInitException; import com.yomahub.liteflow.property.LiteflowConfig; import com.yomahub.liteflow.property.LiteflowConfigGetter; import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; @@ -26,6 +27,22 @@ public class Exception1SpringTest extends BaseTest { @Resource private FlowExecutor flowExecutor; + /** + * 验证 chain 节点重复的异常 + */ + @Test(expected = FlowExecutorNotInitException.class) + public void testChainDuplicateException() { + try { + LiteflowConfig config = LiteflowConfigGetter.get(); + config.setRuleSource("exception/flow-exception.xml"); + flowExecutor.init(); + } catch (Exception ex) { + // 这里需要 catch 是因为,异常是往上抛的,最后被包装成了 FlowExecutorNotInitException + Assert.assertTrue(ex.getMessage().contains("[chain name duplicate]")); + throw ex; + } + } + @Test(expected = ConfigErrorException.class) public void testConfigErrorException() { flowExecutor.setLiteflowConfig(null); diff --git a/liteflow-testcase-springnative/src/test/resources/exception/flow-exception.xml b/liteflow-testcase-springnative/src/test/resources/exception/flow-exception.xml new file mode 100644 index 000000000..662226def --- /dev/null +++ b/liteflow-testcase-springnative/src/test/resources/exception/flow-exception.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file