bug #I4FYKA jsonparser好像缺少脚本条件组件的解析

This commit is contained in:
bryan31
2021-11-04 19:54:28 +08:00
parent a380c97209
commit 7ac63c21fc
19 changed files with 323 additions and 16 deletions

View File

@@ -0,0 +1,69 @@
package com.yomahub.liteflow.test.script.qlexpress;
import cn.hutool.core.io.resource.ResourceUtil;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.enums.FlowParserTypeEnum;
import com.yomahub.liteflow.flow.FlowBus;
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.6.0
*/
@RunWith(SpringRunner.class)
@TestPropertySource(value = "classpath:/json-script/application.properties")
@SpringBootTest(classes = LiteflowJsonScriptQLExpressTest.class)
@EnableAutoConfiguration
@ComponentScan({"com.yomahub.liteflow.test.script.qlexpress.cmp"})
public class LiteflowJsonScriptQLExpressTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
//测试普通脚本节点
@Test
public void testScript1() {
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals(Integer.valueOf(6), response.getSlot().getData("s1"));
}
//测试条件脚本节点
@Test
public void testScript2() {
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain2", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("d==>s2[条件脚本]==>b", response.getSlot().printStep());
}
@Test
public void testScript3() throws Exception{
//根据配置加载的应该是flow.xml执行原来的规则
LiteflowResponse<DefaultSlot> responseOld = flowExecutor.execute2Resp("chain2", "arg");
Assert.assertTrue(responseOld.isSuccess());
Assert.assertEquals("d==>s2[条件脚本]==>b", responseOld.getSlot().printStep());
//更改规则重新加载更改的规则内容从flow_update.xml里读取这里只是为了模拟下获取新的内容。不一定是从文件中读取
String newContent = ResourceUtil.readUtf8Str("classpath: /json-script/flow_update.json");
//进行刷新
FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_JSON, newContent);
//重新执行chain2这个链路结果会变
LiteflowResponse<DefaultSlot> responseNew = flowExecutor.execute2Resp("chain2", "arg");
Assert.assertTrue(responseNew.isSuccess());
Assert.assertEquals("d==>s2[条件脚本_改]==>a==>s3[普通脚本_新增]", responseNew.getSlot().printStep());
}
}

View File

@@ -25,11 +25,11 @@ import javax.annotation.Resource;
* @since 2.6.0
*/
@RunWith(SpringRunner.class)
@TestPropertySource(value = "classpath:/script/application.properties")
@SpringBootTest(classes = LiteflowScriptQLExpressTest.class)
@TestPropertySource(value = "classpath:/xml-script/application.properties")
@SpringBootTest(classes = LiteflowXmlScriptQLExpressTest.class)
@EnableAutoConfiguration
@ComponentScan({"com.yomahub.liteflow.test.script.qlexpress.cmp"})
public class LiteflowScriptQLExpressTest extends BaseTest {
public class LiteflowXmlScriptQLExpressTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
@@ -57,7 +57,7 @@ public class LiteflowScriptQLExpressTest extends BaseTest {
Assert.assertTrue(responseOld.isSuccess());
Assert.assertEquals("d==>s2[条件脚本]==>b", responseOld.getSlot().printStep());
//更改规则重新加载更改的规则内容从flow_update.xml里读取这里只是为了模拟下获取新的内容不一定是从文件中读取
String newContent = ResourceUtil.readUtf8Str("classpath: /script/flow_update.xml");
String newContent = ResourceUtil.readUtf8Str("classpath: /xml-script/flow_update.xml");
//进行刷新
FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_XML, newContent);

View File

@@ -0,0 +1 @@
liteflow.rule-source=json-script/flow.json

View File

@@ -0,0 +1,34 @@
{
"flow": {
"nodes": {
"node": [
{
"id": "s1",
"name": "普通脚本",
"type": "script",
"value": "a=3;b=2;slot.setData(\"s1\",a*b);"
},
{
"id": "s2",
"name": "条件脚本",
"type": "cond_script",
"value": "count = slot.getData(\"count\");if(count > 100){return \"a\";}else{return \"b\";}"
}
]
},
"chain": [
{
"name": "chain1",
"condition": [
{"type": "then", "value": "a,b,c,s1"}
]
},
{
"name": "chain2",
"condition": [
{"type": "then", "value": "d,s2(a|b)"}
]
}
]
}
}

View File

@@ -0,0 +1,40 @@
{
"flow": {
"nodes": {
"node": [
{
"id": "s1",
"name": "普通脚本",
"type": "script",
"value": "a=3;b=2;slot.setData(\"s1\",a*b);"
},
{
"id": "s2",
"name": "条件脚本_改",
"type": "cond_script",
"value": "count = slot.getData(\"count\");if(count > 150){return \"b\";}else{return \"a\";}"
},
{
"id": "s3",
"name": "普通脚本_新增",
"type": "script",
"value": "a=3;b=2;c=10;slot.setData(\"s1\",a*b+c);"
}
]
},
"chain": [
{
"name": "chain1",
"condition": [
{"type": "then", "value": "a,b,c,s1"}
]
},
{
"name": "chain2",
"condition": [
{"type": "then", "value": "d,s2(a|b),s3"}
]
}
]
}
}

View File

@@ -1 +0,0 @@
liteflow.rule-source=script/flow.xml

View File

@@ -0,0 +1 @@
liteflow.rule-source=xml-script/flow.xml