刘光辉
14 小时以前 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
package jnpf.limsService.support;
 
import jnpf.audit.sdk.aspect.AuditLogAspect;
import jnpf.limsEntity.LimsQingyandanEntity;
 
import java.lang.reflect.Method;
import java.util.Map;
 
/** Verifies that layer-2 entity snapshots use physical database column names. */
public final class AuditLogEntityColumnProbe {
 
    private AuditLogEntityColumnProbe() {
    }
 
    @SuppressWarnings("unchecked")
    public static void main(String[] args) throws Exception {
        LimsQingyandanEntity entity = new LimsQingyandanEntity();
        entity.setId("row-1");
        entity.setBizStatus("confirmed");
        entity.setBizSign("sign-reference");
 
        Method mapper = AuditLogAspect.class.getDeclaredMethod("entityToColumnMap", Object.class);
        mapper.setAccessible(true);
        Map<String, Object> columns = (Map<String, Object>) mapper.invoke(null, entity);
 
        check("row-1".equals(columns.get("f_id")), "@TableId f_id");
        check("confirmed".equals(columns.get("biz_status")), "@TableField biz_status");
        check("sign-reference".equals(columns.get("biz_sign")), "diff value is not masked");
        check(!columns.containsKey("bizStatus") && !columns.containsKey("bizSign"),
                "Java property names must not leak into field_diffs");
        System.out.println("AuditLogEntityColumnProbe: all checks passed");
    }
 
    private static void check(boolean condition, String name) {
        if (!condition) {
            throw new AssertionError(name);
        }
    }
}