1
0

优化存储读写,增加一些查询接口

This commit is contained in:
2025-01-07 14:18:35 +08:00
parent dddc9d7171
commit 2c75cad680
9 changed files with 181 additions and 18 deletions

View File

@@ -1,10 +1,12 @@
package com.lanyuanxiaoyao.flowable.test;
import com.lanyuanxiaoyao.flowable.core.helper.ListHelper;
import com.lanyuanxiaoyao.flowable.core.helper.MapHelper;
import com.lanyuanxiaoyao.flowable.core.manager.FlowableManager;
import com.lanyuanxiaoyao.flowable.core.model.FlowableAction;
import com.lanyuanxiaoyao.flowable.core.model.FlowableHandler;
import com.lanyuanxiaoyao.flowable.core.model.FlowableInstance;
import com.lanyuanxiaoyao.flowable.core.model.FlowableListener;
import com.lanyuanxiaoyao.flowable.core.model.FlowableNode;
import com.lanyuanxiaoyao.flowable.test.accessor.RoleCheckAccessor;
import com.lanyuanxiaoyao.flowable.test.handler.TwoApproveHandler;
@@ -12,7 +14,10 @@ import java.util.Map;
import java.util.UUID;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
/**
* 集成测试
@@ -21,6 +26,7 @@ import org.junit.jupiter.api.Test;
* @version 20241231
*/
@Slf4j
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public abstract class TestFlowableManager {
protected abstract FlowableManager flowableManager();
@@ -41,10 +47,23 @@ public abstract class TestFlowableManager {
.build();
}
@Test
@Order(1)
public void testRepository() {
FlowableManager manager = flowableManager();
FlowableNode node1 = createManualNode();
Assertions.assertFalse(manager.existsNode(node1.getNodeId()));
manager.create(node1);
Assertions.assertTrue(manager.existsNode(node1.getNodeId()));
Assertions.assertNotNull(manager.getNode(node1.getNodeId()));
Assertions.assertEquals(1, manager.listNodes().size());
}
/**
* 单节点审批
*/
@Test
@Order(2)
public void testSingleNode() {
FlowableManager manager = flowableManager();
FlowableNode node1 = createManualNode();
@@ -69,6 +88,7 @@ public abstract class TestFlowableManager {
}
@Test
@Order(3)
public void testMultiNode() {
FlowableManager manager = flowableManager();
FlowableNode node1 = createManualNode(
@@ -105,6 +125,7 @@ public abstract class TestFlowableManager {
}
@Test
@Order(4)
public void testTerminal() {
FlowableManager manager = flowableManager();
FlowableNode node1 = createManualNode();
@@ -115,7 +136,7 @@ public abstract class TestFlowableManager {
Assertions.assertEquals(FlowableInstance.Status.RUNNING, manager.getInstance(instanceId).getStatus());
manager.terminal(instanceId, "d896b642-a1d8-499c-92e7-bed63581f2f8");
Assertions.assertEquals(FlowableInstance.Status.ERROR, manager.getInstance(instanceId).getStatus());
Assertions.assertEquals(FlowableInstance.Status.TERMINAL, manager.getInstance(instanceId).getStatus());
Assertions.assertEquals(1, manager.listHistories(instanceId).size());
Assertions.assertEquals(FlowableAction.TERMINAL, manager.listHistories(instanceId).get(0).getAction());
Assertions.assertEquals("d896b642-a1d8-499c-92e7-bed63581f2f8", manager.listHistories(instanceId).get(0).getComment());
@@ -124,6 +145,7 @@ public abstract class TestFlowableManager {
}
@Test
@Order(5)
public void testSuspend() {
FlowableManager manager = flowableManager();
FlowableNode node = FlowableNode.builder()
@@ -142,9 +164,10 @@ public abstract class TestFlowableManager {
Assertions.assertEquals(FlowableInstance.Status.COMPLETED, manager.getInstance(instanceId).getStatus());
}
protected abstract Class<? extends FlowableHandler> getAutomaticNodeClass();
protected abstract Class<? extends FlowableHandler> getHandler();
@Test
@Order(6)
public void testAutomaticNode() {
FlowableManager manager = flowableManager();
FlowableNode node = FlowableNode.builder()
@@ -152,7 +175,7 @@ public abstract class TestFlowableManager {
.name("5d60dab0-7691-4543-b753-af7ac02cb7ec")
.description("5d60dab0-7691-4543-b753-af7ac02cb7ec")
.type(FlowableNode.Type.AUTOMATIC)
.handler(getAutomaticNodeClass().getName())
.handler(getHandler().getName())
.build();
manager.create(node);
String instanceId = manager.start(node.getNodeId());
@@ -160,6 +183,7 @@ public abstract class TestFlowableManager {
}
@Test
@Order(7)
public void testNodeContext() {
FlowableManager manager = flowableManager();
FlowableNode node1 = createManualNode(
@@ -182,6 +206,7 @@ public abstract class TestFlowableManager {
}
@Test
@Order(8)
public void testAccessor() {
FlowableManager manager = flowableManager();
FlowableNode node = FlowableNode.builder()

View File

@@ -22,6 +22,11 @@ public class InMemoryFlowableRepository implements FlowableRepository {
private static final Map<String, FlowableInstance> instances = new HashMap<>();
private static final Map<String, List<FlowableHistory>> histories = new HashMap<>();
@Override
public boolean existsNode(String nodeId) {
return nodes.containsKey(nodeId);
}
@Override
public void saveNode(FlowableNode node) {
nodes.put(node.getNodeId(), node);
@@ -44,6 +49,11 @@ public class InMemoryFlowableRepository implements FlowableRepository {
return new ArrayList<>(nodes.values());
}
@Override
public boolean existsInstance(String instanceId) {
return instances.containsKey(instanceId);
}
@Override
public void saveInstance(FlowableInstance instance) {
instances.put(instance.getInstanceId(), instance);
@@ -59,6 +69,11 @@ public class InMemoryFlowableRepository implements FlowableRepository {
return new ArrayList<>(instances.values());
}
@Override
public boolean existsHistory(String historyId) {
return histories.containsKey(historyId);
}
@Override
public void saveHistory(FlowableHistory history) {
String instanceId = history.getInstanceId();