单元测试-分类归纳

This commit is contained in:
dongguo.tao
2021-04-07 16:23:43 +08:00
parent c4174fafd7
commit d4887c07a8
10 changed files with 169 additions and 8 deletions

View File

@@ -0,0 +1,17 @@
package com.yomahub.liteflow.test.parsecustom;
import com.yomahub.liteflow.parser.ClassJsonFlowParser;
/**
* 模拟用户自定义源解析
* @author dongguo.tao
* @date 2021/4/7
*/
public class CustomJsonFlowParser extends ClassJsonFlowParser {
@Override
public String parseCustom() {
//模拟自定义解析结果
String content = "{\"flow\":{\"nodes\":{\"node\":[{\"id\":\"a\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.ACmp\"},{\"id\":\"b\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.BCmp\"},{\"id\":\"c\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.CCmp\"},{\"id\":\"d\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.DCmp\"},{\"id\":\"e\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.ECmp\"},{\"id\":\"f\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.FCmp\"},{\"id\":\"g\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.GCmp\"}]},\"chain\":[{\"name\":\"chain2\",\"condition\":[{\"type\":\"then\",\"value\":\"c,g,f\"}]},{\"name\":\"chain1\",\"condition\":[{\"type\":\"then\",\"value\":\"a,c\"},{\"type\":\"when\",\"value\":\"b,d,e(f|g)\"},{\"type\":\"then\",\"value\":\"chain2\"}]}]}}";
return content;
}
}

View File

@@ -26,7 +26,7 @@ public class CustomParserJsonSpringTest extends BaseTest {
//测试spring场景的自定义json parser
@Test
public void testSpringboot() throws Exception{
public void testSpringCustomParser() throws Exception{
LiteflowResponse<Slot> response = flowExecutor.execute("chain1", "args");
Assert.assertTrue(response.isSuccess());
}

View File

@@ -0,0 +1,26 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author dongguo.tao
* @email taodongguo@foxmail.com
* @Date 2020/4/7
*/
package com.yomahub.liteflow.test.parsecustom.cmp;
import cn.hutool.core.util.StrUtil;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.exception.FlowSystemException;
import org.springframework.stereotype.Component;
@Component("a")
public class ACmp extends NodeComponent {
@Override
public void process() {
String str = this.getSlot().getRequestData();
if(StrUtil.isNotBlank(str) && str.equals("exception")) {
throw new FlowSystemException("chain execute execption");
}
System.out.println("ACmp executed!");
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author dongguo.tao
* @email taodongguo@foxmail.com
* @Date 2020/4/7
*/
package com.yomahub.liteflow.test.parsecustom.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("b")
public class BCmp extends NodeComponent {
@Override
public void process() {
System.out.println("BCmp executed!");
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author dongguo.tao
* @email taodongguo@foxmail.com
* @Date 2020/4/7
*/
package com.yomahub.liteflow.test.parsecustom.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("c")
public class CCmp extends NodeComponent {
@Override
public void process() {
System.out.println("CCmp executed!");
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author dongguo.tao
* @email taodongguo@foxmail.com
* @Date 2020/4/7
*/
package com.yomahub.liteflow.test.parsecustom.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("d")
public class DCmp extends NodeComponent {
@Override
public void process() {
System.out.println("DCmp executed!");
}
}

View File

@@ -0,0 +1,20 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author dongguo.tao
* @email taodongguo@foxmail.com
* @Date 2020/4/7
*/
package com.yomahub.liteflow.test.parsecustom.cmp;
import com.yomahub.liteflow.core.NodeCondComponent;
import org.springframework.stereotype.Component;
@Component("e")
public class ECmp extends NodeCondComponent {
@Override
public String processCond() throws Exception {
return "g";
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author dongguo.tao
* @email taodongguo@foxmail.com
* @Date 2020/4/7
*/
package com.yomahub.liteflow.test.parsecustom.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("f")
public class FCmp extends NodeComponent {
@Override
public void process() {
System.out.println("FCmp executed!");
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author dongguo.tao
* @email taodongguo@foxmail.com
* @Date 2020/4/7
*/
package com.yomahub.liteflow.test.parsecustom.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("g")
public class GCmp extends NodeComponent {
@Override
public void process() {
System.out.println("GCmp executed!");
}
}

View File

@@ -18,11 +18,4 @@
<property name="liteflowConfig" ref="liteflowConfig"/>
</bean>
<!-- <bean id="flowExecutor" class="com.yomahub.liteflow.core.FlowExecutor">-->
<!-- <property name="rulePath">-->
<!-- <list>-->
<!-- <value>com.yomahub.liteflow.test.parsecustom.CustomJsonFlowParser</value>-->
<!-- </list>-->
<!-- </property>-->
<!-- </bean>-->
</beans>