From 385b69ba981f4e8728402adc4b07a02a288ca58a Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Tue, 11 Apr 2023 16:13:20 +0800 Subject: [PATCH] =?UTF-8?q?bug=20#I6URNQ=20=E5=9C=A8CATCH=E8=A1=A8?= =?UTF-8?q?=E8=BE=BE=E4=B8=AD=E5=86=99=E5=8D=95=E7=8B=AC=E7=9A=84=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=EF=BC=8CSLOT=E4=B8=AD=E4=BC=9A=E6=8B=BF=E4=B8=8D?= =?UTF-8?q?=E5=88=B0=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../builder/el/operator/CatchOperator.java | 11 ++++++++++- .../loop/LiteFlowXmlScriptLoopGroovyELTest.java | 11 +++++++++++ .../test/script/groovy/loop/cmp/ECmp.java | 17 +++++++++++++++++ .../src/test/resources/loop/flow.xml | 15 +++++++++++++++ .../test/catchcase/CatchELSpringbootTest.java | 6 ++++++ .../src/test/resources/catchcase/flow.el.xml | 10 ++++++++-- 6 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/loop/cmp/ECmp.java diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/CatchOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/CatchOperator.java index b12ba067..362b484d 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/CatchOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/CatchOperator.java @@ -3,7 +3,9 @@ package com.yomahub.liteflow.builder.el.operator; import com.yomahub.liteflow.builder.el.operator.base.BaseOperator; import com.yomahub.liteflow.builder.el.operator.base.OperatorHelper; import com.yomahub.liteflow.flow.element.Executable; +import com.yomahub.liteflow.flow.element.Node; import com.yomahub.liteflow.flow.element.condition.CatchCondition; +import com.yomahub.liteflow.flow.element.condition.ThenCondition; /** * EL规则中的CATCH的操作符 用法:CATCH...DO... @@ -20,8 +22,15 @@ public class CatchOperator extends BaseOperator { Executable catchItem = OperatorHelper.convert(objects[0], Executable.class); CatchCondition catchCondition = new CatchCondition(); - catchCondition.setCatchItem(catchItem); + //如果是单个Node的话,要包装成THEN的CONDITION模式,否则CATCH不到异常 + if (catchItem instanceof Node){ + ThenCondition thenCondition = new ThenCondition(); + thenCondition.addExecutable(catchItem); + catchCondition.setCatchItem(thenCondition); + }else{ + catchCondition.setCatchItem(catchItem); + } return catchCondition; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/loop/LiteFlowXmlScriptLoopGroovyELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/loop/LiteFlowXmlScriptLoopGroovyELTest.java index 46cded74..c7bb258f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/loop/LiteFlowXmlScriptLoopGroovyELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/loop/LiteFlowXmlScriptLoopGroovyELTest.java @@ -2,6 +2,7 @@ package com.yomahub.liteflow.test.script.groovy.loop; 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; @@ -65,4 +66,14 @@ public class LiteFlowXmlScriptLoopGroovyELTest extends BaseTest { response.getExecuteStepStr()); } + // 测试在脚本中取到循环对象 + @Test + public void testLoop6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("e==>w==>w==>w", response.getExecuteStepStr()); + DefaultContext context = response.getFirstContextBean(); + Assert.assertEquals("jack-tom-frank", context.getData("test")); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/loop/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/loop/cmp/ECmp.java new file mode 100644 index 00000000..20b64445 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/loop/cmp/ECmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.script.groovy.loop.cmp; + +import cn.hutool.core.collection.CollUtil; +import com.yomahub.liteflow.core.NodeIteratorComponent; +import org.springframework.stereotype.Component; + +import java.util.Iterator; +import java.util.List; + +@Component("e") +public class ECmp extends NodeIteratorComponent { + @Override + public Iterator processIterator() throws Exception { + List list = CollUtil.toList("jack","tom","frank"); + return list.iterator(); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/loop/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/loop/flow.xml index 25ef4965..a6ef34ab 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/loop/flow.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/loop/flow.xml @@ -26,6 +26,17 @@ } ]]> + + + + @@ -47,4 +58,8 @@ WHILE(z).DO(THEN(a,d)).BREAK(y); + + + ITERATOR(e).DO(w); + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/catchcase/CatchELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/catchcase/CatchELSpringbootTest.java index fd7bb7ec..32c8294e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/catchcase/CatchELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/catchcase/CatchELSpringbootTest.java @@ -58,4 +58,10 @@ public class CatchELSpringbootTest extends BaseTest { Assert.assertEquals("LOOP_3==>a==>b==>a==>b==>a==>b", response.getExecuteStepStrWithoutTime()); } + @Test + public void testCatch5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("a==>d", response.getExecuteStepStrWithoutTime()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/catchcase/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/catchcase/flow.el.xml index 31017e0b..eb9f7873 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/catchcase/flow.el.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/catchcase/flow.el.xml @@ -4,13 +4,13 @@ CATCH( THEN(a,b) - ).DO(c) + ).DO(c); CATCH( THEN(a,b) - ).DO(d) + ).DO(d); @@ -26,4 +26,10 @@ ) ); + + + CATCH( + a + ).DO(d); + \ No newline at end of file