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