From c425997b3cf43e58b0ffecaa34e381e5a551f65e Mon Sep 17 00:00:00 2001 From: bryan31 Date: Thu, 9 Dec 2021 18:47:29 +0800 Subject: [PATCH] =?UTF-8?q?bug=20#I4LV63=20=E5=9C=A82.6.5=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E4=B8=AD=E5=A4=9A=E7=BA=BF=E7=A8=8Btag=E5=8F=96?= =?UTF-8?q?=E5=80=BC=E4=B8=AD=EF=BC=8Cxml=E6=B2=A1=E6=9C=89=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=8C=E8=80=8Cjson=E5=BD=A2=E5=BC=8F=E6=9C=89?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liteflow/parser/JsonFlowParser.java | 2 +- ...st.java => NodeTagSpringbootJsonTest.java} | 8 +-- .../test/tag/NodeTagSpringbootXmlTest.java | 59 +++++++++++++++++++ .../resources/tag/application-json.properties | 1 + ....properties => application-xml.properties} | 0 .../src/test/resources/tag/flow.json | 25 ++++++++ 6 files changed, 89 insertions(+), 6 deletions(-) rename liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/tag/{NodeTagSpringbootTest.java => NodeTagSpringbootJsonTest.java} (90%) create mode 100644 liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagSpringbootXmlTest.java create mode 100644 liteflow-testcase-springboot/src/test/resources/tag/application-json.properties rename liteflow-testcase-springboot/src/test/resources/tag/{application.properties => application-xml.properties} (100%) create mode 100644 liteflow-testcase-springboot/src/test/resources/tag/flow.json diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/JsonFlowParser.java b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/JsonFlowParser.java index 10d7730a1..6f1d55fbb 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/JsonFlowParser.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/JsonFlowParser.java @@ -170,7 +170,7 @@ public abstract class JsonFlowParser extends FlowParser { for (RegexNodeEntity realItem : regexEntity.getRealItemArray()) { if (FlowBus.containNode(realItem.getId())) { Node condNode = FlowBus.copyNode(realItem.getId()); - node.setTag(realItem.getTag()); + condNode.setTag(realItem.getTag()); node.setCondNode(condNode.getId(), condNode); } else if (hasChain(flowJsonObjectList, realItem.getId())) { Chain chain = FlowBus.getChain(realItem.getId()); diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagSpringbootTest.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagSpringbootJsonTest.java similarity index 90% rename from liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagSpringbootTest.java rename to liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagSpringbootJsonTest.java index 368fa8ee7..cb3468c96 100644 --- a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagSpringbootTest.java +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagSpringbootJsonTest.java @@ -15,8 +15,6 @@ import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; -import java.util.Set; -import java.util.function.Function; /** * springboot环境下隐私投递的测试 @@ -24,11 +22,11 @@ import java.util.function.Function; * @since 2.5.0 */ @RunWith(SpringRunner.class) -@TestPropertySource(value = "classpath:/tag/application.properties") -@SpringBootTest(classes = NodeTagSpringbootTest.class) +@TestPropertySource(value = "classpath:/tag/application-json.properties") +@SpringBootTest(classes = NodeTagSpringbootJsonTest.class) @EnableAutoConfiguration @ComponentScan({"com.yomahub.liteflow.test.tag.cmp"}) -public class NodeTagSpringbootTest extends BaseTest { +public class NodeTagSpringbootJsonTest extends BaseTest { @Resource private FlowExecutor flowExecutor; diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagSpringbootXmlTest.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagSpringbootXmlTest.java new file mode 100644 index 000000000..329ddda0c --- /dev/null +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagSpringbootXmlTest.java @@ -0,0 +1,59 @@ +package com.yomahub.liteflow.test.tag; + +import cn.hutool.core.collection.ConcurrentHashSet; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +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; + +/** + * springboot环境下隐私投递的测试 + * @author Bryan.Zhang + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/tag/application-xml.properties") +@SpringBootTest(classes = NodeTagSpringbootXmlTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.tag.cmp"}) +public class NodeTagSpringbootXmlTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testTag1() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("123",response.getSlot().getData("test")); + } + + @Test + public void testTag2() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>a==>a==>c==>e", response.getSlot().printStep()); + } + + //测试多线程when情况下的tag取值是否正确 + //这里循环多次的原因是,因为when多线程,有时候因为凑巧,可能正确。所以多次情况下在2.6.4版本肯定出错 + @Test + public void testTag3() throws Exception{ + for (int i = 0; i < 50; i++) { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + ConcurrentHashSet testSet = response.getSlot().getData("test"); + Assert.assertEquals(3, testSet.size()); + } + } +} diff --git a/liteflow-testcase-springboot/src/test/resources/tag/application-json.properties b/liteflow-testcase-springboot/src/test/resources/tag/application-json.properties new file mode 100644 index 000000000..2f9c09d4e --- /dev/null +++ b/liteflow-testcase-springboot/src/test/resources/tag/application-json.properties @@ -0,0 +1 @@ +liteflow.rule-source=tag/flow.json \ No newline at end of file diff --git a/liteflow-testcase-springboot/src/test/resources/tag/application.properties b/liteflow-testcase-springboot/src/test/resources/tag/application-xml.properties similarity index 100% rename from liteflow-testcase-springboot/src/test/resources/tag/application.properties rename to liteflow-testcase-springboot/src/test/resources/tag/application-xml.properties diff --git a/liteflow-testcase-springboot/src/test/resources/tag/flow.json b/liteflow-testcase-springboot/src/test/resources/tag/flow.json new file mode 100644 index 000000000..dd2c7aaa7 --- /dev/null +++ b/liteflow-testcase-springboot/src/test/resources/tag/flow.json @@ -0,0 +1,25 @@ +{ + "flow": { + "chain": [ + { + "name": "chain1", + "condition": [ + {"type": "then", "value": "a[1],a[2],a[3]"} + ] + }, + { + "name": "chain2", + "condition": [ + {"type": "then", "value": "a[1],a[2],a[3],c[2](d[5]|e[6])"} + ] + }, + { + "name": "chain3", + "condition": [ + {"type": "then", "value": "b1"}, + {"type": "when", "value": "b[1],b[2],b[3]"} + ] + } + ] + } +} \ No newline at end of file