Skip to content

Commit

Permalink
update sdk test case
Browse files Browse the repository at this point in the history
  • Loading branch information
heavyrain2012 committed Jan 8, 2020
1 parent 3b61f8f commit 60730c5
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,19 @@ public int getAutomatic() {
public void setAutomatic(int automatic) {
this.automatic = automatic;
}

public static OutputGetChannelInfo fromPbInfo(WFCMessage.ChannelInfo channelInfo) {
OutputGetChannelInfo out = new OutputGetChannelInfo();
out.automatic = channelInfo.getAutomatic();
out.callback = channelInfo.getCallback();
out.channelId = channelInfo.getTargetId();
out.desc = channelInfo.getDesc();
out.extra = channelInfo.getExtra();
out.name = channelInfo.getName();
out.owner = channelInfo.getOwner();
out.portrait = channelInfo.getPortrait();
out.status = channelInfo.getStatus();
out.updateDt = channelInfo.getUpdateDt();
return out;
}
}
91 changes: 73 additions & 18 deletions sdk/src/main/java/cn/wildfirechat/sdk/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@

public class Main {
public static void main(String[] args) throws Exception {
testAdmin();
testRobot();
// testChannel();
}

static void testAdmin() throws Exception {
//初始化服务API
AdminHttpUtils.init("http://localhost:18080", "123456");

Expand Down Expand Up @@ -463,17 +469,18 @@ public static void main(String[] args) throws Exception {
System.out.println("destroy user failure");
System.exit(-1);
}
}


static void testRobot() throws Exception {
//初始化机器人API
RobotHttpUtils.init("http://localhost", "robot1", "123456");
//***********************************************
//**** 机器人API
//***********************************************
conversation = new Conversation();
Conversation conversation = new Conversation();
conversation.setTarget("user2");
conversation.setType(ProtoConstants.ConversationType.ConversationType_Private);
payload = new MessagePayload();
MessagePayload payload = new MessagePayload();
payload.setType(1);
payload.setSearchableContent("hello world");

Expand All @@ -492,13 +499,61 @@ public static void main(String[] args) throws Exception {
System.out.println("robot get user info by userId failure");
System.exit(-1);
}
}

//***测试频道API功能,仅专业版支持***
static void testChannel() throws Exception {
//初始化服务API
AdminHttpUtils.init("http://localhost:18080", "123456");

//先创建3个用户
InputOutputUserInfo userInfo = new InputOutputUserInfo();
userInfo.setUserId("userId1");
userInfo.setName("user1");
userInfo.setMobile("13900000000");
userInfo.setDisplayName("user 1");

IMResult<OutputCreateUser> resultCreateUser = UserAdmin.createUser(userInfo);
if (resultCreateUser != null && resultCreateUser.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("Create user " + resultCreateUser.getResult().getName() + " success");
} else {
System.out.println("Create user failure");
System.exit(-1);
}

userInfo = new InputOutputUserInfo();
userInfo.setUserId("userId2");
userInfo.setName("user2");
userInfo.setMobile("13900000002");
userInfo.setDisplayName("user 2");

resultCreateUser = UserAdmin.createUser(userInfo);
if (resultCreateUser != null && resultCreateUser.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("Create user " + resultCreateUser.getResult().getName() + " success");
} else {
System.out.println("Create user failure");
System.exit(-1);
}

userInfo = new InputOutputUserInfo();
userInfo.setUserId("userId3");
userInfo.setName("user3");
userInfo.setMobile("13900000003");
userInfo.setDisplayName("user 3");

resultCreateUser = UserAdmin.createUser(userInfo);
if (resultCreateUser != null && resultCreateUser.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("Create user " + resultCreateUser.getResult().getName() + " success");
} else {
System.out.println("Create user failure");
System.exit(-1);
}

//测试频道API功能,仅专业版支持
//1. 先使用admin api创建频道
inputCreateChannel = new InputCreateChannel();
InputCreateChannel inputCreateChannel = new InputCreateChannel();
inputCreateChannel.setName("testChannel");
inputCreateChannel.setOwner("user1");
resultCreateChannel = GeneralAdmin.createChannel(inputCreateChannel);
inputCreateChannel.setOwner("userId1");
IMResult<OutputCreateChannel> resultCreateChannel = GeneralAdmin.createChannel(inputCreateChannel);
if (resultCreateChannel != null && resultCreateChannel.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("create channel success");
} else {
Expand All @@ -507,18 +562,18 @@ public static void main(String[] args) throws Exception {
}

//2. 初始化api
ChannelServiceApi channelServiceApi = new ChannelServiceApi("http://localhost", inputCreateChannel.getTargetId(), inputCreateChannel.getSecret());
ChannelServiceApi channelServiceApi = new ChannelServiceApi("http://localhost", resultCreateChannel.getResult().getTargetId(), resultCreateChannel.getResult().getSecret());

//3. 测试channel api功能
resultVoid = channelServiceApi.subscribe("user2");
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("user3");
resultVoid = channelServiceApi.subscribe("userId3");
if (resultVoid != null && resultVoid.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("subscribe done");
} else {
Expand All @@ -527,14 +582,14 @@ public static void main(String[] args) throws Exception {
}

IMResult<OutputStringList> resultStringList = channelServiceApi.getSubscriberList();
if (resultStringList != null && resultStringList.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS && resultStringList.getResult().getList().contains("user2") && resultStringList.getResult().getList().contains("user3")) {
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");
} else {
System.out.println("get subscriber failure");
System.exit(-1);
}

resultVoid = channelServiceApi.unsubscribe("user2");
resultVoid = channelServiceApi.unsubscribe("userId2");
if (resultVoid != null && resultVoid.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("unsubscriber done");
} else {
Expand All @@ -543,14 +598,14 @@ public static void main(String[] args) throws Exception {
}

resultStringList = channelServiceApi.getSubscriberList();
if (resultStringList != null && resultStringList.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS && resultStringList.getResult().getList().contains("user3") && !resultStringList.getResult().getList().contains("user2")) {
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);
}

resultGetUserInfo1 = channelServiceApi.getUserInfo("user2");
IMResult<InputOutputUserInfo> resultGetUserInfo1 = channelServiceApi.getUserInfo("userId3");
if (resultGetUserInfo1 != null && resultGetUserInfo1.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("get user info success");
} else {
Expand All @@ -559,11 +614,11 @@ public static void main(String[] args) throws Exception {
}


payload = new MessagePayload();
MessagePayload payload = new MessagePayload();
payload.setType(1);
payload.setSearchableContent("hello world");

resultSendMessage = channelServiceApi.sendMessage(0, null,payload);
IMResult<SendMessageResult> resultSendMessage = channelServiceApi.sendMessage(0, null,payload);
if (resultSendMessage != null && resultSendMessage.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("send message to all the subscriber success");
} else {
Expand All @@ -573,15 +628,15 @@ public static void main(String[] args) throws Exception {

payload.setSearchableContent("hello to user2");

resultSendMessage = channelServiceApi.sendMessage(0, Arrays.asList("user2"),payload);
resultSendMessage = channelServiceApi.sendMessage(0, Arrays.asList("userId2"),payload);
if (resultSendMessage != null && resultSendMessage.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("send message to user2 success");
} else {
System.out.println("send message to user2 failure");
System.exit(-1);
}

voidIMResult = channelServiceApi.modifyChannelInfo(ProtoConstants.ModifyChannelInfoType.Modify_Channel_Desc, "this is a test channel, update at:" + new Date().toString());
IMResult<Void> voidIMResult = channelServiceApi.modifyChannelInfo(ProtoConstants.ModifyChannelInfoType.Modify_Channel_Desc, "this is a test channel, update at:" + new Date().toString());
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("modify channel profile success");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public <T> IMResult<T> httpJsonPost(String path, Object object, Class<T> clazz)
post.setHeader("sign", sign);


String jsonStr = null;
String jsonStr = "";
if (object != null) {
jsonStr = new Gson().toJson(object);
}
Expand Down

0 comments on commit 60730c5

Please sign in to comment.