diff --git a/liteflow-testcase-el/liteflow-testcase-el-etcd-springboot/src/test/java/com/yomahub/liteflow/test/etcd/EtcdWithXmlELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-etcd-springboot/src/test/java/com/yomahub/liteflow/test/etcd/EtcdWithXmlELSpringbootTest.java index cc222159f..5a1cfb098 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-etcd-springboot/src/test/java/com/yomahub/liteflow/test/etcd/EtcdWithXmlELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-etcd-springboot/src/test/java/com/yomahub/liteflow/test/etcd/EtcdWithXmlELSpringbootTest.java @@ -2,6 +2,7 @@ package com.yomahub.liteflow.test.etcd; import cn.hutool.core.util.ReflectUtil; import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.enums.FlowParserTypeEnum; import com.yomahub.liteflow.flow.FlowBus; import com.yomahub.liteflow.flow.LiteflowResponse; import com.yomahub.liteflow.parser.etcd.EtcdClient; @@ -12,11 +13,14 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.*; import org.junit.runner.RunWith; import org.mockito.Answers; +import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener; import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestExecutionListeners; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; @@ -44,7 +48,6 @@ public class EtcdWithXmlELSpringbootTest extends BaseTest { @Before public void setUp(){ - //其实只有@Mock才需要initMocks方法,@MockBean不需要initMocks的 MockitoAnnotations.initMocks(this); } @@ -56,7 +59,7 @@ public class EtcdWithXmlELSpringbootTest extends BaseTest { @Test public void testEtcdNodeWithXml1() throws Exception { String flowXml = "THEN(a, b, c);"; - when(etcdClient.get(any())).thenReturn(flowXml); + when(etcdClient.get(anyString())).thenReturn(flowXml); LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); Assert.assertTrue(response.isSuccess()); @@ -67,14 +70,14 @@ public class EtcdWithXmlELSpringbootTest extends BaseTest { public void testEtcdNodeWithXml2() throws Exception { String flowXml = "THEN(a, b, c);"; String changedFlowXml = "THEN(a, c);"; - when(etcdClient.get(any())).thenReturn(flowXml).thenReturn(changedFlowXml); + when(etcdClient.get(anyString())).thenReturn(flowXml).thenReturn(changedFlowXml); LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); Assert.assertTrue(response.isSuccess()); Assert.assertEquals("a==>b==>c", response.getExecuteStepStr()); // 手动触发一次 模拟节点数据变更 - flowExecutor.reloadRule(); + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML,changedFlowXml); LiteflowResponse response2 = flowExecutor.execute2Resp("chain1", "arg"); Assert.assertTrue(response2.isSuccess()); diff --git a/liteflow-testcase-el/liteflow-testcase-el-nacos-springboot/src/test/java/com/yomahub/liteflow/test/nacos/NacosWithXmlELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-nacos-springboot/src/test/java/com/yomahub/liteflow/test/nacos/NacosWithXmlELSpringbootTest.java index 1d15c1abb..cfdebcee5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nacos-springboot/src/test/java/com/yomahub/liteflow/test/nacos/NacosWithXmlELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nacos-springboot/src/test/java/com/yomahub/liteflow/test/nacos/NacosWithXmlELSpringbootTest.java @@ -1,5 +1,6 @@ package com.yomahub.liteflow.test.nacos; +import com.alibaba.nacos.client.config.NacosConfigService; import com.alibaba.nacos.client.config.impl.LocalConfigInfoProcessor; import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.enums.FlowParserTypeEnum; @@ -14,12 +15,16 @@ 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.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.ComponentScan; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.when; + /** * springboot环境下的nacos配置源功能测试 * nacos存储数据的格式为xml文件 @@ -36,38 +41,34 @@ public class NacosWithXmlELSpringbootTest extends BaseTest { @Resource private FlowExecutor flowExecutor; - private NacosParserHelper helper; - - // 写到本地. - final String flowXml = "THEN(a, b, c);"; - - // 2次写入本地 - final String changedFlowXml = "THEN(a, c);"; - - private static NacosParserVO nacosParserVO = new NacosParserVO(); - - static { - // 这里的信息必须 = application-xml.properties liteflow.rule-source-ext-data - nacosParserVO.setServerAddr("127.0.0.1:8848"); - nacosParserVO.setDataId("LiteFlow"); - nacosParserVO.setGroup("LITE_FLOW_GROUP"); - nacosParserVO.setNamespace(""); - } + @MockBean + private NacosConfigService nacosConfigService; @After - public void clean() { - LocalConfigInfoProcessor.cleanAllSnapshot(); + public void after(){ + FlowBus.cleanCache(); } @Test - public void testNacosWithXml() throws Exception { - // envName 把数据写到本地,作为快照数据.始终会取到 - String envName = "fixed-127.0.0.1_8848"; - LocalConfigInfoProcessor.saveSnapshot(envName,nacosParserVO.getDataId(),nacosParserVO.getGroup(),nacosParserVO.getNamespace(),flowXml); + public void testNacosWithXml1() throws Exception { + String flowXml = "THEN(a, b, c);"; + when(nacosConfigService.getConfig(anyString(), anyString(), anyLong())).thenReturn(flowXml); + + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertEquals("a==>b==>c", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testNacosWithXml2() throws Exception { + String flowXml = "THEN(a, b, c);"; + String changedFlowXml = "THEN(a, c);"; + when(nacosConfigService.getConfig(anyString(), anyString(), anyLong())).thenReturn(flowXml).thenReturn(changedFlowXml); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); Assert.assertEquals("a==>b==>c", response.getExecuteStepStrWithoutTime()); FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML,changedFlowXml); + response = flowExecutor.execute2Resp("chain1", "arg"); Assert.assertEquals("a==>c", response.getExecuteStepStrWithoutTime()); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nacos-springboot/src/test/resources/nacos/application-xml.properties b/liteflow-testcase-el/liteflow-testcase-el-nacos-springboot/src/test/resources/nacos/application-xml.properties index d87229360..fc030f84e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nacos-springboot/src/test/resources/nacos/application-xml.properties +++ b/liteflow-testcase-el/liteflow-testcase-el-nacos-springboot/src/test/resources/nacos/application-xml.properties @@ -1,4 +1,2 @@ -liteflow.rule-source-ext-data={"serverAddr":"127.0.0.1:8848"} -#liteflow.rule-source-ext-data={"serverAddr":"127.0.0.1:8848","dataId":"LiteFlow","group":"LITE_FLOW_GROUP"} -#liteflow.rule-source-ext-data={"serverAddr":"192.168.10.147:8848","dataId":"LiteFlow","group":"LITE_FLOW_GROUP","namespace":"","username":"","password":""} +liteflow.rule-source-ext-data={"serverAddr":"192.168.10.147:8848","dataId":"LiteFlow","group":"LITE_FLOW_GROUP","namespace":"","username":"","password":""} liteflow.parse-on-start=false \ No newline at end of file