sdk 测试代码中区分社区版和专业版

This commit is contained in:
imhao183
2020-08-24 09:50:29 +08:00
parent e41ae9a9e7
commit d89e641470
3 changed files with 106 additions and 97 deletions
@@ -61,8 +61,8 @@ public class CreateChannelAction extends AdminAction {
if (errorCode == ErrorCode.ERROR_CODE_SUCCESS) { if (errorCode == ErrorCode.ERROR_CODE_SUCCESS) {
byte[] data = new byte[byteBuf.readableBytes()]; byte[] data = new byte[byteBuf.readableBytes()];
byteBuf.readBytes(data); byteBuf.readBytes(data);
String secret = new String(data); String channelId = new String(data);
sendResponse(response, null, new OutputCreateChannel(inputCreateChannel.getTargetId(), secret)); sendResponse(response, null, new OutputCreateChannel(channelId));
} else { } else {
sendResponse(response, errorCode, null); sendResponse(response, errorCode, null);
} }
@@ -13,11 +13,9 @@ import cn.wildfirechat.proto.WFCMessage;
public class OutputCreateChannel { public class OutputCreateChannel {
private String targetId; private String targetId;
private String secret;
public OutputCreateChannel(String targetId, String secret) { public OutputCreateChannel(String targetId) {
this.targetId = targetId; this.targetId = targetId;
this.secret = secret;
} }
public String getTargetId() { public String getTargetId() {
@@ -27,12 +25,4 @@ public class OutputCreateChannel {
public void setTargetId(String targetId) { public void setTargetId(String targetId) {
this.targetId = targetId; this.targetId = targetId;
} }
public String getSecret() {
return secret;
}
public void setSecret(String secret) {
this.secret = secret;
}
} }
+103 -84
View File
@@ -17,13 +17,15 @@ import java.util.List;
import static cn.wildfirechat.proto.ProtoConstants.SystemSettingType.Group_Max_Member_Count; import static cn.wildfirechat.proto.ProtoConstants.SystemSettingType.Group_Max_Member_Count;
public class Main { public class Main {
private static boolean commercialServer = false;
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
//admin使用的是18080端口,超级管理接口,理论上不能对外开放端口,也不能让非内部服务知悉密钥。 //admin使用的是18080端口,超级管理接口,理论上不能对外开放端口,也不能让非内部服务知悉密钥。
testAdmin(); testAdmin();
//Robot和Channel都是使用的80端口,第三方可以创建或者为第三方创建,第三方可以使用robot或者channel与IM系统进行对接。 //Robot和Channel都是使用的80端口,第三方可以创建或者为第三方创建,第三方可以使用robot或者channel与IM系统进行对接。
testRobot(); testRobot();
//testChannel(); testChannel();
} }
@@ -37,7 +39,10 @@ public class Main {
testChatroom(); testChatroom();
testMessage(); testMessage();
testGeneralApi(); testGeneralApi();
testDevice(); if (commercialServer) {
testDevice();
}
System.out.println("Congratulation, all admin test case passed!!!!!!!"); System.out.println("Congratulation, all admin test case passed!!!!!!!");
} }
@@ -418,21 +423,24 @@ public class Main {
System.exit(-1); System.exit(-1);
} }
voidIMResult = GroupAdmin.muteGroupMemeber("user1", groupInfo.getTarget_id(), Arrays.asList("user4", "user5"), true, null, null); if (commercialServer) {
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) { voidIMResult = GroupAdmin.muteGroupMemeber("user1", groupInfo.getTarget_id(), Arrays.asList("user4", "user5"), true, null, null);
System.out.println("mute group member success"); if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
} else { System.out.println("mute group member success");
System.out.println("mute group member failure"); } else {
System.exit(-1); System.out.println("mute group member failure");
System.exit(-1);
}
voidIMResult = GroupAdmin.muteGroupMemeber("user1", groupInfo.getTarget_id(), Arrays.asList("user4", "user5"), false, null, null);
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("unmute group member success");
} else {
System.out.println("unmute group member failure");
System.exit(-1);
}
} }
voidIMResult = GroupAdmin.muteGroupMemeber("user1", groupInfo.getTarget_id(), Arrays.asList("user4", "user5"), false, null, null);
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("unmute group member success");
} else {
System.out.println("unmute group member failure");
System.exit(-1);
}
@@ -487,20 +495,22 @@ public class Main {
System.exit(-1); System.exit(-1);
} }
voidIMResult = MessageAdmin.deleteMessage(resultSendMessage.getResult().getMessageUid()); if (commercialServer) {
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) { voidIMResult = MessageAdmin.deleteMessage(resultSendMessage.getResult().getMessageUid());
System.out.println("delete message success"); if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
} else { System.out.println("delete message success");
System.out.println("delete message failure"); } else {
System.exit(-1); System.out.println("delete message failure");
} System.exit(-1);
}
IMResult<BroadMessageResult> resultBroadcastMessage = MessageAdmin.broadcastMessage("user1", 0, payload); IMResult<BroadMessageResult> resultBroadcastMessage = MessageAdmin.broadcastMessage("user1", 0, payload);
if (resultBroadcastMessage != null && resultBroadcastMessage.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) { if (resultBroadcastMessage != null && resultBroadcastMessage.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("broad message success, send message to " + resultBroadcastMessage.getResult().getCount() + " users"); System.out.println("broad message success, send message to " + resultBroadcastMessage.getResult().getCount() + " users");
} else { } else {
System.out.println("broad message failure"); System.out.println("broad message failure");
System.exit(-1); System.exit(-1);
}
} }
List<String> multicastReceivers = Arrays.asList("user2", "user3", "user4"); List<String> multicastReceivers = Arrays.asList("user2", "user3", "user4");
@@ -790,6 +800,8 @@ public class Main {
InputCreateChannel inputCreateChannel = new InputCreateChannel(); InputCreateChannel inputCreateChannel = new InputCreateChannel();
inputCreateChannel.setName("testChannel"); inputCreateChannel.setName("testChannel");
inputCreateChannel.setOwner("userId1"); inputCreateChannel.setOwner("userId1");
String secret = "channelsecret";
inputCreateChannel.setSecret(secret);
IMResult<OutputCreateChannel> resultCreateChannel = GeneralAdmin.createChannel(inputCreateChannel); IMResult<OutputCreateChannel> resultCreateChannel = GeneralAdmin.createChannel(inputCreateChannel);
if (resultCreateChannel != null && resultCreateChannel.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) { if (resultCreateChannel != null && resultCreateChannel.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("create channel success"); System.out.println("create channel success");
@@ -798,56 +810,61 @@ public class Main {
System.exit(-1); System.exit(-1);
} }
//2. 初始化api //2. 初始化api
ChannelServiceApi channelServiceApi = new ChannelServiceApi("http://localhost", resultCreateChannel.getResult().getTargetId(), resultCreateChannel.getResult().getSecret()); ChannelServiceApi channelServiceApi = new ChannelServiceApi("http://localhost", resultCreateChannel.getResult().getTargetId(), secret);
//3. 测试channel api功能
IMResult<Void> resultVoid = channelServiceApi.subscribe("userId2");
if (resultVoid != null && resultVoid.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("subscribe success");
} else {
System.out.println("subscribe failure");
System.exit(-1);
}
resultVoid = channelServiceApi.subscribe("userId3");
if (resultVoid != null && resultVoid.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("subscribe done");
} else {
System.out.println("subscribe failure");
System.exit(-1);
}
IMResult<OutputStringList> resultStringList = channelServiceApi.getSubscriberList(); if (commercialServer) {
if (resultStringList != null && resultStringList.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS && resultStringList.getResult().getList().contains("userId2") && resultStringList.getResult().getList().contains("userId3")) { //3. 测试channel api功能
System.out.println("get subscriber done"); IMResult<Void> resultVoid = channelServiceApi.subscribe("userId2");
} else { if (resultVoid != null && resultVoid.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("get subscriber failure"); System.out.println("subscribe success");
System.exit(-1); } else {
} System.out.println("subscribe failure");
System.exit(-1);
}
resultVoid = channelServiceApi.unsubscribe("userId2"); resultVoid = channelServiceApi.subscribe("userId3");
if (resultVoid != null && resultVoid.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) { if (resultVoid != null && resultVoid.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("unsubscriber done"); System.out.println("subscribe done");
} else { } else {
System.out.println("unsubscriber failure"); System.out.println("subscribe failure");
System.exit(-1); System.exit(-1);
} }
resultStringList = channelServiceApi.getSubscriberList(); IMResult<OutputStringList> resultStringList = channelServiceApi.getSubscriberList();
if (resultStringList != null && resultStringList.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS && resultStringList.getResult().getList().contains("userId3") && !resultStringList.getResult().getList().contains("userId2")) { if (resultStringList != null && resultStringList.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS && resultStringList.getResult().getList().contains("userId2") && resultStringList.getResult().getList().contains("userId3")) {
System.out.println("get subscriber done"); System.out.println("get subscriber done");
} else { } else {
System.out.println("get subscriber failure"); System.out.println("get subscriber failure");
System.exit(-1); System.exit(-1);
} }
IMResult<InputOutputUserInfo> resultGetUserInfo1 = channelServiceApi.getUserInfo("userId3"); resultVoid = channelServiceApi.unsubscribe("userId2");
if (resultGetUserInfo1 != null && resultGetUserInfo1.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) { if (resultVoid != null && resultVoid.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("get user info success"); System.out.println("unsubscriber done");
} else { } else {
System.out.println("get user info failure"); System.out.println("unsubscriber failure");
System.exit(-1); System.exit(-1);
}
resultStringList = channelServiceApi.getSubscriberList();
if (resultStringList != null && resultStringList.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS && resultStringList.getResult().getList().contains("userId3") && !resultStringList.getResult().getList().contains("userId2")) {
System.out.println("get subscriber done");
} else {
System.out.println("get subscriber failure");
System.exit(-1);
}
IMResult<InputOutputUserInfo> resultGetUserInfo1 = channelServiceApi.getUserInfo("userId3");
if (resultGetUserInfo1 != null && resultGetUserInfo1.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("get user info success");
} else {
System.out.println("get user info failure");
System.exit(-1);
}
} }
@@ -873,20 +890,22 @@ public class Main {
System.exit(-1); System.exit(-1);
} }
IMResult<Void> voidIMResult = channelServiceApi.modifyChannelInfo(ProtoConstants.ModifyChannelInfoType.Modify_Channel_Desc, "this is a test channel, update at:" + new Date().toString()); if (commercialServer) {
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) { IMResult<Void> voidIMResult = channelServiceApi.modifyChannelInfo(ProtoConstants.ModifyChannelInfoType.Modify_Channel_Desc, "this is a test channel, update at:" + new Date().toString());
System.out.println("modify channel profile success"); if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
} else { System.out.println("modify channel profile success");
System.out.println("modify channel profile failure"); } else {
System.exit(-1); System.out.println("modify channel profile failure");
} System.exit(-1);
}
IMResult<OutputGetChannelInfo> outputGetChannelInfoIMResult = channelServiceApi.getChannelInfo(); IMResult<OutputGetChannelInfo> outputGetChannelInfoIMResult = channelServiceApi.getChannelInfo();
if (outputGetChannelInfoIMResult != null && outputGetChannelInfoIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) { if (outputGetChannelInfoIMResult != null && outputGetChannelInfoIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("destroy user success"); System.out.println("destroy user success");
} else { } else {
System.out.println("destroy user failure"); System.out.println("destroy user failure");
System.exit(-1); System.exit(-1);
}
} }
} }