刘光辉
2 小时以前 06f314545ac3514d7ce28939920866ae8188d31c
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
package jnpf.bizcommon.audit.service.listener;
 
import com.alibaba.fastjson.JSON;
import jnpf.bizcommon.audit.service.support.AuditQueryResponseSanitizer;
import org.junit.jupiter.api.Test;
import java.util.*;
import static org.junit.jupiter.api.Assertions.*;
 
public class DmsWorkflowAuditEventTest {
    @Test public void frozenContextSurvivesMessageJsonAndDetailSanitizing() {
        Map<String,Object> context = new LinkedHashMap<>();
        context.put("taskId", "task"); context.put("operatorId", "round-2");
        context.put("nodeId", "node"); context.put("nodeCode", "review"); context.put("nodeName", "审核");
        context.put("untrustedExtra", "ignored");
        Map<String,Object> wire = JSON.parseObject(JSON.toJSONString(Map.of("workflowAuditContext", context)));
        Map<String,Object> extra = new LinkedHashMap<>();
        AuditVisualLogListener.appendDmsWorkflowContext(extra, "dms_wenjian_xinzeng_shenhe", "task", wire);
        Map<?,?> visible = (Map<?,?>) JSON.parseObject(AuditQueryResponseSanitizer.sanitizeJson(JSON.toJSONString(extra))).get("workflow");
        assertEquals("round-2", visible.get("operatorId")); assertEquals("审核", visible.get("nodeName"));
        assertEquals(5, visible.size());
    }
    @Test public void unrelatedTablesAndMismatchedInstancesCannotAcquireContext() {
        Map<String,Object> form = Map.of("workflowAuditContext", Map.of("taskId", "task", "operatorId", "round"));
        Map<String,Object> extra = new LinkedHashMap<>();
        AuditVisualLogListener.appendDmsWorkflowContext(extra, "lims_other", "task", form);
        AuditVisualLogListener.appendDmsWorkflowContext(extra, "dms_wenjian_xiuding_shenhe", "other", form);
        AuditVisualLogListener.appendDmsWorkflowContext(extra, "dms_wenjian_xiuding_shenhe", null, form);
        assertTrue(extra.isEmpty());
    }
    @Test public void historicalEventsWithoutContextAreNotAssignedAnInventedNode() {
        Map<String,Object> extra = new LinkedHashMap<>();
        AuditVisualLogListener.appendDmsWorkflowContext(extra, "dms_wenjian_xiuding_shenhe", "task", Map.of());
        assertTrue(extra.isEmpty());
    }
}