对测试用例的改动

This commit is contained in:
bryan31
2021-03-31 19:22:43 +08:00
parent 16620ada87
commit 926f41c7cc
15 changed files with 16 additions and 92 deletions

View File

@@ -0,0 +1,17 @@
package com.yomahub.liteflow.test.aop.aspect;
import cn.hutool.core.util.StrUtil;
import com.yomahub.liteflow.aop.ICmpAroundAspect;
import com.yomahub.liteflow.entity.data.Slot;
public class CmpAspect implements ICmpAroundAspect {
@Override
public void beforeProcess(String nodeId, Slot slot) {
slot.setData(nodeId, "before");
}
@Override
public void afterProcess(String nodeId, Slot slot) {
slot.setData(nodeId, StrUtil.format("{}_{}", slot.getData(nodeId), "after"));
}
}

View File

@@ -0,0 +1,27 @@
package com.yomahub.liteflow.test.aop.aspect;
import cn.hutool.core.util.StrUtil;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.entity.data.Slot;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
@Aspect
public class CustomAspect {
@Pointcut("execution(* com.yomahub.liteflow.test.aop.cmp1.*.process())")
public void cut() {
}
@Around("cut()")
public Object around(ProceedingJoinPoint jp) throws Throwable {
NodeComponent cmp = (NodeComponent) jp.getThis();
Slot slot = cmp.getSlot();
slot.setData(cmp.getNodeId(), "before");
Object returnObj = jp.proceed();
slot.setData(cmp.getNodeId(), StrUtil.format("{}_{}", slot.getData(cmp.getNodeId()), "after"));
return returnObj;
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.aop.cmp1;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("a")
public class ACmp extends NodeComponent {
@Override
public void process() {
System.out.println("Acomp executed!");
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.aop.cmp1;
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("Bcomp executed!");
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.aop.cmp1;
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("Ccomp executed!");
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.aop.cmp2;
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("Dcomp executed!");
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.aop.cmp2;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("e")
public class ECmp extends NodeComponent {
@Override
public void process() {
System.out.println("Ecomp executed!");
}
}

View File

@@ -0,0 +1,53 @@
package com.yomahub.liteflow.test.aop.run;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.entity.data.Slot;
import com.yomahub.liteflow.test.aop.aspect.CustomAspect;
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.context.annotation.Import;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
/**
* 切面场景单元测试
* @author Bryan.Zhang
*/
@RunWith(SpringRunner.class)
@ActiveProfiles("aop")
@SpringBootTest(classes = LFCustomAOPTest.class)
@EnableAutoConfiguration
@Import(CustomAspect.class)
@ComponentScan({"com.yomahub.liteflow.test.aop.cmp1","com.yomahub.liteflow.test.aop.cmp2"})
public class LFCustomAOPTest {
@Resource
private FlowExecutor flowExecutor;
//测试自定义AOP串行场景
@Test
public void testCustomAopS() throws Exception{
LiteflowResponse<Slot> response= flowExecutor.execute("chain1", "it's a request");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("before_after", response.getData().getData("a"));
Assert.assertEquals("before_after", response.getData().getData("b"));
Assert.assertEquals("before_after", response.getData().getData("c"));
}
//测试自定义AOP并行场景
@Test
public void testCustomAopP() throws Exception{
LiteflowResponse<Slot> response= flowExecutor.execute("chain2", "it's a request");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("before_after", response.getData().getData("a"));
Assert.assertEquals("before_after", response.getData().getData("b"));
Assert.assertEquals("before_after", response.getData().getData("c"));
}
}

View File

@@ -0,0 +1,57 @@
package com.yomahub.liteflow.test.aop.run;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.entity.data.Slot;
import com.yomahub.liteflow.test.aop.aspect.CmpAspect;
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.context.annotation.Import;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
/**
* 切面场景单元测试
* @author Bryan.Zhang
*/
@RunWith(SpringRunner.class)
@ActiveProfiles("aop")
@SpringBootTest(classes = LFGlobalAOPTest.class)
@EnableAutoConfiguration
@Import(CmpAspect.class)
@ComponentScan({"com.yomahub.liteflow.test.aop.cmp1","com.yomahub.liteflow.test.aop.cmp2"})
public class LFGlobalAOPTest {
@Resource
private FlowExecutor flowExecutor;
//测试全局AOP串行场景
@Test
public void testGlobalAopS() throws Exception{
LiteflowResponse<Slot> response= flowExecutor.execute("chain1", "it's a request");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("before_after", response.getData().getData("a"));
Assert.assertEquals("before_after", response.getData().getData("b"));
Assert.assertEquals("before_after", response.getData().getData("c"));
Assert.assertEquals("before_after", response.getData().getData("d"));
Assert.assertEquals("before_after", response.getData().getData("e"));
}
//测试全局AOP并行场景
@Test
public void testGlobalAopP() throws Exception{
LiteflowResponse<Slot> response= flowExecutor.execute("chain2", "it's a request");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("before_after", response.getData().getData("a"));
Assert.assertEquals("before_after", response.getData().getData("b"));
Assert.assertEquals("before_after", response.getData().getData("c"));
Assert.assertEquals("before_after", response.getData().getData("d"));
Assert.assertEquals("before_after", response.getData().getData("e"));
}
}

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<chain name="chain1">
<then value="a,b,c,d,e"/>
</chain>
<chain name="chain2">
<then value="a,b,c"/>
<when value="d,e"/>
</chain>
</flow>

View File

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