Commit 9dda48ab authored by DeleMing's avatar DeleMing

<dev>

1. 完成功能
2. 增加单元测试
parent 7bdc64f5
Pipeline #21176 failed with stages
in 31 seconds
......@@ -206,6 +206,13 @@
<artifactId>snakeyaml</artifactId>
<version>1.16</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
......
......@@ -44,7 +44,7 @@ public class JobInitConfig implements Serializable {
this.ip = MapUtils.getString(conf, ConfigConstants.IP_KEY);
this.mac = MapUtils.getString(conf, ConfigConstants.MAC_KEY);
this.position = MapUtils.getString(conf, ConfigConstants.POSITION_KEY);
this.password = MapUtils.getString(conf, ConfigConstants.POSITION_KEY);
this.password = MapUtils.getString(conf, ConfigConstants.PASSWORD_KEY);
}
private String jobName;
......
......@@ -14,5 +14,13 @@ public final class GeneralConstants {
public static final String FILE_SEPARATOR = "/";
public static final String AVRO_SUFFIX = ".avro";
public static final String EMPTY_STR = "";
public static final String HOSTNAME = "hostname";
public static final String MESSAGE = "message";
public static final String ANS = "Ans: ";
public static final String REQ = "Req: ";
public static final String ZORKDATA_FLAG = "zorkdata_flag";
public static final String SYMBOL_STR = "&";
public static final String CODE_MSG = "CODE,MSG;";
public static final String SEMICOLON = ";";
}
package com.zorkdata.desensitization.constans;
/**
* @author: LiaoMingtao
* @date: 2021/2/24
*/
public final class ZorkdataFlag {
  • Add a private constructor to hide the implicit public one. 📘

Please register or sign in to reply
/**
* 不存在 Req与Ans
*/
public static final String STR1 = "1";
/**
* 日志普通列没有message字段
*/
public static final String STR2= "2";
/**
* 包含Ans但不包含Ans
*/
public static final String STR3= "3";
}
package com.zorkdata.desensitization.function;
import com.alibaba.fastjson.JSON;
import com.zorkdata.desensitization.config.JobConfig;
import com.zorkdata.desensitization.config.JobInitConfig;
import com.zorkdata.desensitization.constans.ConfigConstants;
import com.zorkdata.desensitization.constans.GeneralConstants;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
/**
* @author: LiaoMingtao
* @date: 2021/2/25
*/
@Slf4j
public class DesensitizationFunctionTest {
/**
* Req Ans 都有
*/
@Test
public void test1() {
Map<String, String> conf = new HashMap<>(8);
conf.put(ConfigConstants.JOB_NAME, "jobName");
  • 🚫 Define a constant instead of duplicating this literal "jobName" 3 times. 📘

Please register or sign in to reply
conf.put(ConfigConstants.SOURCE_PARALLELISM, "1");
conf.put(ConfigConstants.TRANSFORMER_PARALLELISM, "1");
conf.put(ConfigConstants.SINK_PARALLELISM, "1");
conf.put(ConfigConstants.HDFS_URI, "1");
conf.put(ConfigConstants.HDFS_USER, "1");
conf.put(ConfigConstants.HDFS_SRC, "1");
conf.put(ConfigConstants.HDFS_DEST, "1");
conf.put(ConfigConstants.MATCH_HOSTNAME, "*");
conf.put(ConfigConstants.START_TIME, "2020-11-07 21:22:20");
  • 🚫 Define a constant instead of duplicating this literal "2020-11-07 21:22:20" 3 times. 📘

Please register or sign in to reply
conf.put(ConfigConstants.END_TIME, "2020-11-07 23:40:30");
  • 🚫 Define a constant instead of duplicating this literal "2020-11-07 23:40:30" 3 times. 📘

Please register or sign in to reply
conf.put(ConfigConstants.NAME_KEY, "key1");
conf.put(ConfigConstants.MOBILE_KEY, "key1");
conf.put(ConfigConstants.PHONE_KEY, "key1");
conf.put(ConfigConstants.EMAIL_KEY, "key1");
conf.put(ConfigConstants.ID_KEY, "key1");
conf.put(ConfigConstants.BANK_CARD_KEY, "key1");
conf.put(ConfigConstants.ADDRESS_KEY, "key1");
conf.put(ConfigConstants.IP_KEY, "key3");
conf.put(ConfigConstants.MAC_KEY, "key1");
conf.put(ConfigConstants.PASSWORD_KEY, "key4");
conf.put(ConfigConstants.POSITION_KEY, "key5");
JobInitConfig jobInitConfig = new JobInitConfig(conf);
JobConfig jobConfig = new JobConfig(jobInitConfig);
DesensitizationFunction<Object, Object> desensitizationFunction = new DesensitizationFunction(jobConfig);
Map<String, String> map = new HashMap<>(8);
String message = "YYYYMMDD-*** NodeId=***, QueueId=**, MsgId=***********************, Len=***,\n" +
"Buf=01280000000000000000100000000000000040F2E92B8E7AKCXP00 GV2gODkBbGg= 410570 00220000000 Req: ************&key1=value1&key2=value2 Ans: NodeId=***, QueueId=**, MsgId=***********************, Len=***,\n" +
"Buf=01280000000000000000100000000000000040F2E92B8E7AKCXP00 GV2gODkBbGg= 410570 00220000000 **************************LEVEL,CODE,MSG;key3,key4,key5;value3,value4,value5,value3,value4,value5&_EORS_2=*****************************;";
map.put(GeneralConstants.MESSAGE, message);
desensitizationFunction.desensitizationNormalFieldMessage(map);
log.info(JSON.toJSONString(map));
}
/**
* 只有Req
*/
@Test
public void test2() {
Map<String, String> conf = new HashMap<>(8);
conf.put(ConfigConstants.JOB_NAME, "jobName");
conf.put(ConfigConstants.SOURCE_PARALLELISM, "1");
conf.put(ConfigConstants.TRANSFORMER_PARALLELISM, "1");
conf.put(ConfigConstants.SINK_PARALLELISM, "1");
conf.put(ConfigConstants.HDFS_URI, "1");
conf.put(ConfigConstants.HDFS_USER, "1");
conf.put(ConfigConstants.HDFS_SRC, "1");
conf.put(ConfigConstants.HDFS_DEST, "1");
conf.put(ConfigConstants.MATCH_HOSTNAME, "*");
conf.put(ConfigConstants.START_TIME, "2020-11-07 21:22:20");
conf.put(ConfigConstants.END_TIME, "2020-11-07 23:40:30");
conf.put(ConfigConstants.NAME_KEY, "key1");
conf.put(ConfigConstants.MOBILE_KEY, "key1");
conf.put(ConfigConstants.PHONE_KEY, "key1");
conf.put(ConfigConstants.EMAIL_KEY, "key1");
conf.put(ConfigConstants.ID_KEY, "key1");
conf.put(ConfigConstants.BANK_CARD_KEY, "key1");
conf.put(ConfigConstants.ADDRESS_KEY, "key1");
conf.put(ConfigConstants.IP_KEY, "key3");
conf.put(ConfigConstants.MAC_KEY, "key1");
conf.put(ConfigConstants.PASSWORD_KEY, "key4");
conf.put(ConfigConstants.POSITION_KEY, "key5");
JobInitConfig jobInitConfig = new JobInitConfig(conf);
JobConfig jobConfig = new JobConfig(jobInitConfig);
DesensitizationFunction<Object, Object> desensitizationFunction = new DesensitizationFunction(jobConfig);
Map<String, String> map = new HashMap<>(8);
String message = "YYYYMMDD-*** NodeId=***, QueueId=**, MsgId=***********************, Len=***,\n" +
"Buf=01280000000000000000100000000000000040F2E92B8E7AKCXP00 GV2gODkBbGg= 410570 00220000000 Req: ************&key1=value1&key2=value2 ";
map.put(GeneralConstants.MESSAGE, message);
desensitizationFunction.desensitizationNormalFieldMessage(map);
log.info(JSON.toJSONString(map));
}
@Test
public void test3() {
Map<String, String> conf = new HashMap<>(8);
conf.put(ConfigConstants.JOB_NAME, "jobName");
conf.put(ConfigConstants.SOURCE_PARALLELISM, "1");
conf.put(ConfigConstants.TRANSFORMER_PARALLELISM, "1");
conf.put(ConfigConstants.SINK_PARALLELISM, "1");
conf.put(ConfigConstants.HDFS_URI, "1");
conf.put(ConfigConstants.HDFS_USER, "1");
conf.put(ConfigConstants.HDFS_SRC, "1");
conf.put(ConfigConstants.HDFS_DEST, "1");
conf.put(ConfigConstants.MATCH_HOSTNAME, "*");
conf.put(ConfigConstants.START_TIME, "2020-11-07 21:22:20");
conf.put(ConfigConstants.END_TIME, "2020-11-07 23:40:30");
conf.put(ConfigConstants.NAME_KEY, "key1");
conf.put(ConfigConstants.MOBILE_KEY, "key1");
conf.put(ConfigConstants.PHONE_KEY, "key1");
conf.put(ConfigConstants.EMAIL_KEY, "key1");
conf.put(ConfigConstants.ID_KEY, "key1");
conf.put(ConfigConstants.BANK_CARD_KEY, "key1");
conf.put(ConfigConstants.ADDRESS_KEY, "key1");
conf.put(ConfigConstants.IP_KEY, "key3");
conf.put(ConfigConstants.MAC_KEY, "key1");
conf.put(ConfigConstants.PASSWORD_KEY, "key2");
conf.put(ConfigConstants.POSITION_KEY, "key5");
JobInitConfig jobInitConfig = new JobInitConfig(conf);
JobConfig jobConfig = new JobConfig(jobInitConfig);
DesensitizationFunction<Object, Object> desensitizationFunction = new DesensitizationFunction(jobConfig);
Map<String, String> map = new HashMap<>(8);
String message = "YYYYMMDD-*** NodeId=***, QueueId=**, MsgId=***********************, Len=***," +
"Buf=01280000000000000000100000000000000040F2E92B8E7AKCXP00 GV2gODkBbGg= Ans: NodeId=***, QueueId=**, MsgId=***********************, Len=***," +
"Buf=01280000000000000000100000000000000040F2E92B8E7AKCXP00 GV2gODkBbGg= 410570 00220000000 **************************LEVEL,CODE,MSG;key3,key4,key5;value3,value4,value5,value3,value4,value5&_EORS_2=*****************************;";
map.put(GeneralConstants.MESSAGE, message);
desensitizationFunction.desensitizationNormalFieldMessage(map);
log.info(JSON.toJSONString(map));
}
}
\ No newline at end of file
  • SonarQube analysis reported 180 issues

    • 1 blocker
    • 🚫 24 critical
    • 131 major
    • 🔽 21 minor
    • 3 info

    Watch the comments in this conversation to review them.

    Top 30 extra issues

    Note: The following issues were found on lines that were not modified in the commit. Because these issues can't be reported as line comments, they are summarized here:

    1. Remove this hard-coded password. 📘
    2. 🚫 Define a constant instead of duplicating this literal " {\n" 11 times. 📘
    3. 🚫 [Define a constant instead of duplicating this literal " "type": \n" 11 times. 📘
    4. 🚫 Define a constant instead of duplicating this literal " "string",\n" 6 times. 📘
    5. 🚫 Define a constant instead of duplicating this literal " "null"\n" 6 times. 📘
    6. 🚫 [Define a constant instead of duplicating this literal " ]\n" 11 times.](https://git.zorkdata.com/liaomingtao/transaction-log-desensitization/blob/9dda48ab988584fc38f1352af2dbfdbb2d7c39b2/src/main/java/com/zorkdata/desensitization/avro/AvroSchemaDef.java#L23) 📘
    7. 🚫 Define a constant instead of duplicating this literal " },\n" 9 times. 📘
    8. 🚫 Define a constant instead of duplicating this literal " "null",\n" 5 times. 📘
    9. 🚫 Define a constant instead of duplicating this literal " {\n" 5 times. 📘
    10. 🚫 Define a constant instead of duplicating this literal " "type": "map",\n" 5 times. 📘
    11. 🚫 Define a constant instead of duplicating this literal " "values": "string"\n" 3 times. 📘
    12. 🚫 Define a constant instead of duplicating this literal " }\n" 5 times. 📘
    13. 🚫 Define a constant instead of duplicating this literal "序列化失败" 13 times. 📘
    14. 🚫 Refactor this method to reduce its Cognitive Complexity from 22 to the 15 allowed. 📘
    15. 🚫 Refactor this method to reduce its Cognitive Complexity from 22 to the 15 allowed. 📘
    16. 🚫 Refactor this method to reduce its Cognitive Complexity from 22 to the 15 allowed. 📘
    17. 🚫 Refactor this method to reduce its Cognitive Complexity from 19 to the 15 allowed. 📘
    18. 🚫 Change this "try" to a try-with-resources. (sonar.java.source not set. Assuming 7 or greater.) 📘
    19. 🚫 Refactor this code to not throw exceptions in finally blocks. 📘
    20. 🚫 Refactor this code to not throw exceptions in finally blocks. 📘
    21. 🚫 Change this "try" to a try-with-resources. (sonar.java.source not set. Assuming 7 or greater.) 📘
    22. Rename "jsonObject" which hides the field declared at line 39. 📘
    23. Remove this expression which always evaluates to "true" 📘
    24. Remove this expression which always evaluates to "true" 📘
    25. This block of commented-out lines of code should be removed. 📘
    26. 及时清理不再使用的代码段或配置信息。 📘
    27. Remove this expression which always evaluates to "true" 📘
    28. Iterate over the "entrySet" instead of the "keySet". 📘
    29. Remove this conditional structure or edit its code blocks so that they're not all the same. 📘
    30. Iterate over the "entrySet" instead of the "keySet". 📘
    • ... 143 more
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment