添加敏感词管理api测试代码

This commit is contained in:
imhao183
2020-09-20 08:40:22 +08:00
parent 76dedb3da7
commit ae3f0027ca
2 changed files with 36 additions and 1 deletions
@@ -39,6 +39,7 @@ public class Main {
testChatroom(); testChatroom();
testMessage(); testMessage();
testGeneralApi(); testGeneralApi();
testSensitiveApi();
if (commercialServer) { if (commercialServer) {
testDevice(); testDevice();
} }
@@ -969,6 +970,40 @@ public class Main {
} }
} }
} }
static void testSensitiveApi() throws Exception {
List<String> words = Arrays.asList("a","b","c");
IMResult<Void> addResult = SensitiveAdmin.addSensitives(words);
if (addResult != null && addResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("Add sensitive word response success");
} else {
System.out.println("Add sensitive word response error");
System.exit(-1);
}
IMResult<InputOutputSensitiveWords> swResult = SensitiveAdmin.getSensitives();
if (swResult != null && swResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS && swResult.getResult().getWords().containsAll(words)) {
System.out.println("Sensitive word added");
} else {
System.out.println("Sensitive word not added");
System.exit(-1);
}
IMResult<Void> removeResult = SensitiveAdmin.removeSensitives(words);
if (removeResult != null && removeResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("Remove sensitive word response success");
} else {
System.out.println("Remove sensitive word response error");
System.exit(-1);
}
swResult = SensitiveAdmin.getSensitives();
if (swResult != null && swResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS && !swResult.getResult().getWords().containsAll(words)) {
System.out.println("Sensitive word removed");
} else {
System.out.println("Sensitive word not removed");
System.exit(-1);
}
}
//*********************************************** //***********************************************
//**** 物联网相关的API,仅专业版支持 //**** 物联网相关的API,仅专业版支持
@@ -22,7 +22,7 @@ public class SensitiveAdmin {
return AdminHttpUtils.httpJsonPost(path, input, Void.class); return AdminHttpUtils.httpJsonPost(path, input, Void.class);
} }
public static IMResult<InputOutputSensitiveWords> getSensitives(List<String> sensitives) throws Exception { public static IMResult<InputOutputSensitiveWords> getSensitives() throws Exception {
String path = APIPath.Sensitive_Query; String path = APIPath.Sensitive_Query;
return AdminHttpUtils.httpJsonPost(path, null, InputOutputSensitiveWords.class); return AdminHttpUtils.httpJsonPost(path, null, InputOutputSensitiveWords.class);
} }