<dev>
1. 完成功能 2. 增加单元测试
Showing
| package com.zorkdata.desensitization.constans; | ||
| /** | ||
| * @author: LiaoMingtao | ||
| * @date: 2021/2/24 | ||
| */ | ||
| public final class ZorkdataFlag { | ||
|
||
| /** | ||
| * 不存在 Req与Ans | ||
| */ | ||
| public static final String STR1 = "1"; | ||
| /** | ||
| * 日志普通列没有message字段 | ||
| */ | ||
| public static final String STR2= "2"; | ||
| /** | ||
| * 包含Ans但不包含Ans | ||
| */ | ||
| public static final String STR3= "3"; | ||
| } | ||
This diff is collapsed.
| 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"); | ||
|
||
| 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 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:
-
⛔ Remove this hard-coded password.📘 -
🚫 Define a constant instead of duplicating this literal " {\n" 11 times.📘 -
🚫 [Define a constant instead of duplicating this literal " "type": \n" 11 times.📘 -
🚫 Define a constant instead of duplicating this literal " "string",\n" 6 times.📘 -
🚫 Define a constant instead of duplicating this literal " "null"\n" 6 times.📘 -
🚫 [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)📘 -
🚫 Define a constant instead of duplicating this literal " },\n" 9 times.📘 -
🚫 Define a constant instead of duplicating this literal " "null",\n" 5 times.📘 -
🚫 Define a constant instead of duplicating this literal " {\n" 5 times.📘 -
🚫 Define a constant instead of duplicating this literal " "type": "map",\n" 5 times.📘 -
🚫 Define a constant instead of duplicating this literal " "values": "string"\n" 3 times.📘 -
🚫 Define a constant instead of duplicating this literal " }\n" 5 times.📘 -
🚫 Define a constant instead of duplicating this literal "序列化失败" 13 times.📘 -
🚫 Refactor this method to reduce its Cognitive Complexity from 22 to the 15 allowed.📘 -
🚫 Refactor this method to reduce its Cognitive Complexity from 22 to the 15 allowed.📘 -
🚫 Refactor this method to reduce its Cognitive Complexity from 22 to the 15 allowed.📘 -
🚫 Refactor this method to reduce its Cognitive Complexity from 19 to the 15 allowed.📘 -
🚫 Change this "try" to a try-with-resources. (sonar.java.source not set. Assuming 7 or greater.)📘 -
🚫 Refactor this code to not throw exceptions in finally blocks.📘 -
🚫 Refactor this code to not throw exceptions in finally blocks.📘 -
🚫 Change this "try" to a try-with-resources. (sonar.java.source not set. Assuming 7 or greater.)📘 -
⚠ Rename "jsonObject" which hides the field declared at line 39.📘 -
⚠ Remove this expression which always evaluates to "true"📘 -
⚠ Remove this expression which always evaluates to "true"📘 -
⚠ This block of commented-out lines of code should be removed.📘 -
⚠ 及时清理不再使用的代码段或配置信息。📘 -
⚠ Remove this expression which always evaluates to "true"📘 -
⚠ Iterate over the "entrySet" instead of the "keySet".📘 -
⚠ Remove this conditional structure or edit its code blocks so that they're not all the same.📘 -
⚠ Iterate over the "entrySet" instead of the "keySet".📘
- ... 143 more
-