刘光辉
13 小时以前 34981c30a78e8bbd7791131059a9210f9928b62c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package jnpf.limsService.support;
 
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
 
/**
 * 稳定性销毁申请流程状态同步的静态回归检查。
 */
public class LimsWendingxingXiaohuiFlowStatusChecks {
 
    private static final Path REPOSITORY_ROOT = Paths.get("").toAbsolutePath().normalize();
 
    public static void main(String[] args) throws IOException {
        String controller = readIfExists("jnpf-lims/jnpf-lims-controller/src/main/java/jnpf/limsController/LimsWendingxingKaocaJihuaController.java");
        String entity = readIfExists("jnpf-lims/jnpf-lims-entity/src/main/java/jnpf/limsEntity/LimsWendingxingXiaohuiShenqingEntity.java");
        String mapper = readIfExists("jnpf-lims/jnpf-lims-biz/src/main/java/jnpf/limsMapper/LimsWendingxingXiaohuiShenqingMapper.java");
        String service = readIfExists("jnpf-lims/jnpf-lims-biz/src/main/java/jnpf/limsService/LimsWendingxingXiaohuiShenqingService.java");
        String implementation = readIfExists("jnpf-lims/jnpf-lims-biz/src/main/java/jnpf/limsService/impl/LimsWendingxingXiaohuiShenqingServiceImpl.java");
        String resolver = readIfExists("jnpf-lims/jnpf-lims-biz/src/main/java/jnpf/limsService/support/LimsWendingxingXiaohuiFlowStatusResolver.java");
 
        require(controller, "@PostMapping(\"/xiaohui/shenqing/flow-status/start\")",
                "start route missing");
        require(controller, "@PostMapping(\"/xiaohui/shenqing/flow-status/end\")",
                "end route missing");
        require(controller, "workFlowApi.getInfoSubmit(param.getTaskId())",
                "end must query workflow state");
        require(controller, "xiaohuiService.syncFlowStarted", "start must delegate to service");
        require(controller, "xiaohuiService.syncFlowEnded", "end must delegate to service");
        require(entity, "@TableName(\"lims_wendingxing_xiaohui_shenqing\")",
                "entity table mapping missing");
        require(entity, "private String bizStatus;", "biz_status mapping missing");
        require(mapper, "SuperMapper<LimsWendingxingXiaohuiShenqingEntity>",
                "mapper contract missing");
        require(service, "void syncFlowStarted(String flowId, String taskId)",
                "start service contract missing");
        require(service, "void syncFlowEnded(String flowId, String taskId, Integer flowState)",
                "end service contract missing");
        require(implementation, "LimsWendingxingXiaohuiFlowStatusResolver.PROCESSING",
                "start target missing");
        require(implementation, "LimsWendingxingXiaohuiFlowStatusResolver.COMPLETED",
                "end target missing");
        require(implementation, "getFTenantId", "update must be tenant scoped");
        require(implementation, "getFDeleteMark", "query and update must ignore deleted applications");
        require(resolver, "case 2:", "approved terminal status missing");
        require(resolver, "case 3:", "rejected terminal status missing");
        require(resolver, "case 4:", "cancelled terminal status missing");
        require(resolver, "case 7:", "revoked terminal status missing");
        require(resolver, "case 9:", "terminated terminal status missing");
 
        int[] terminalStates = {2, 3, 4, 7, 9};
        for (int state : terminalStates) {
            requireTrue(LimsWendingxingXiaohuiFlowStatusResolver.isTerminal(state),
                    "flow state must be terminal: " + state);
        }
        Integer[] activeOrUnknownStates = {null, 0, 1, 5, 6, 8, 10};
        for (Integer state : activeOrUnknownStates) {
            requireTrue(!LimsWendingxingXiaohuiFlowStatusResolver.isTerminal(state),
                    "flow state must not be terminal: " + state);
        }
    }
 
    private static String readIfExists(String relativePath) throws IOException {
        Path path = REPOSITORY_ROOT.resolve(relativePath);
        if (!Files.exists(path)) {
            return "";
        }
        return new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
    }
 
    private static void require(String source, String expected, String message) {
        if (!source.contains(expected)) {
            throw new AssertionError(message);
        }
    }
 
    private static void requireTrue(boolean condition, String message) {
        if (!condition) {
            throw new AssertionError(message);
        }
    }
}