|
@@ -2,6 +2,7 @@ package com.yomahub.liteflow.test.etcd;
|
|
|
|
|
|
import cn.hutool.core.util.ReflectUtil;
|
|
import cn.hutool.core.util.ReflectUtil;
|
|
import com.yomahub.liteflow.core.FlowExecutor;
|
|
import com.yomahub.liteflow.core.FlowExecutor;
|
|
|
|
+import com.yomahub.liteflow.enums.FlowParserTypeEnum;
|
|
import com.yomahub.liteflow.flow.FlowBus;
|
|
import com.yomahub.liteflow.flow.FlowBus;
|
|
import com.yomahub.liteflow.flow.LiteflowResponse;
|
|
import com.yomahub.liteflow.flow.LiteflowResponse;
|
|
import com.yomahub.liteflow.parser.etcd.EtcdClient;
|
|
import com.yomahub.liteflow.parser.etcd.EtcdClient;
|
|
@@ -12,11 +13,14 @@ import com.yomahub.liteflow.test.BaseTest;
|
|
import org.junit.*;
|
|
import org.junit.*;
|
|
import org.junit.runner.RunWith;
|
|
import org.junit.runner.RunWith;
|
|
import org.mockito.Answers;
|
|
import org.mockito.Answers;
|
|
|
|
+import org.mockito.Mock;
|
|
import org.mockito.MockitoAnnotations;
|
|
import org.mockito.MockitoAnnotations;
|
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
|
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.context.annotation.ComponentScan;
|
|
|
|
+import org.springframework.test.context.TestExecutionListeners;
|
|
import org.springframework.test.context.TestPropertySource;
|
|
import org.springframework.test.context.TestPropertySource;
|
|
import org.springframework.test.context.junit4.SpringRunner;
|
|
import org.springframework.test.context.junit4.SpringRunner;
|
|
|
|
|
|
@@ -44,7 +48,6 @@ public class EtcdWithXmlELSpringbootTest extends BaseTest {
|
|
|
|
|
|
@Before
|
|
@Before
|
|
public void setUp(){
|
|
public void setUp(){
|
|
- //其实只有@Mock才需要initMocks方法,@MockBean不需要initMocks的
|
|
|
|
MockitoAnnotations.initMocks(this);
|
|
MockitoAnnotations.initMocks(this);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -56,7 +59,7 @@ public class EtcdWithXmlELSpringbootTest extends BaseTest {
|
|
@Test
|
|
@Test
|
|
public void testEtcdNodeWithXml1() throws Exception {
|
|
public void testEtcdNodeWithXml1() throws Exception {
|
|
String flowXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><flow><chain name=\"chain1\">THEN(a, b, c);</chain></flow>";
|
|
String flowXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><flow><chain name=\"chain1\">THEN(a, b, c);</chain></flow>";
|
|
- when(etcdClient.get(any())).thenReturn(flowXml);
|
|
|
|
|
|
+ when(etcdClient.get(anyString())).thenReturn(flowXml);
|
|
|
|
|
|
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
|
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
|
Assert.assertTrue(response.isSuccess());
|
|
Assert.assertTrue(response.isSuccess());
|
|
@@ -67,14 +70,14 @@ public class EtcdWithXmlELSpringbootTest extends BaseTest {
|
|
public void testEtcdNodeWithXml2() throws Exception {
|
|
public void testEtcdNodeWithXml2() throws Exception {
|
|
String flowXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><flow><chain name=\"chain1\">THEN(a, b, c);</chain></flow>";
|
|
String flowXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><flow><chain name=\"chain1\">THEN(a, b, c);</chain></flow>";
|
|
String changedFlowXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><flow><chain name=\"chain1\">THEN(a, c);</chain></flow>";
|
|
String changedFlowXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><flow><chain name=\"chain1\">THEN(a, c);</chain></flow>";
|
|
- when(etcdClient.get(any())).thenReturn(flowXml).thenReturn(changedFlowXml);
|
|
|
|
|
|
+ when(etcdClient.get(anyString())).thenReturn(flowXml).thenReturn(changedFlowXml);
|
|
|
|
|
|
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
|
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
|
Assert.assertTrue(response.isSuccess());
|
|
Assert.assertTrue(response.isSuccess());
|
|
Assert.assertEquals("a==>b==>c", response.getExecuteStepStr());
|
|
Assert.assertEquals("a==>b==>c", response.getExecuteStepStr());
|
|
|
|
|
|
// 手动触发一次 模拟节点数据变更
|
|
// 手动触发一次 模拟节点数据变更
|
|
- flowExecutor.reloadRule();
|
|
|
|
|
|
+ FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML,changedFlowXml);
|
|
|
|
|
|
LiteflowResponse response2 = flowExecutor.execute2Resp("chain1", "arg");
|
|
LiteflowResponse response2 = flowExecutor.execute2Resp("chain1", "arg");
|
|
Assert.assertTrue(response2.isSuccess());
|
|
Assert.assertTrue(response2.isSuccess());
|