From 9925986494c4c510f72931792be27ebcf7c703da Mon Sep 17 00:00:00 2001 From: shenchong <569471293@qq.com> Date: Thu, 24 May 2018 13:12:00 +0800 Subject: [PATCH 1/3] add and perfect java examples --- .../server/example/comm/ResponseHandler.java | 6 + .../test/java/com/easemob/ChatGroupTest.java | 55 +++---- .../test/java/com/easemob/ChatRoomTest.java | 23 +-- .../java/com/easemob/SendMessageTest.java | 102 +++++++++++-- .../src/test/java/com/easemob/UserTest.java | 135 ++++++++++++++++-- 5 files changed, 261 insertions(+), 60 deletions(-) diff --git a/emchat-server-java/src/main/java/com/easemob/server/example/comm/ResponseHandler.java b/emchat-server-java/src/main/java/com/easemob/server/example/comm/ResponseHandler.java index c76700c..443cc13 100644 --- a/emchat-server-java/src/main/java/com/easemob/server/example/comm/ResponseHandler.java +++ b/emchat-server-java/src/main/java/com/easemob/server/example/comm/ResponseHandler.java @@ -16,6 +16,7 @@ public class ResponseHandler { public Object handle(EasemobAPI easemobAPI) { Object result = null; + StringBuffer stringBuffer = new StringBuffer(); try { result = easemobAPI.invokeEasemobAPI(); } catch (ApiException e) { @@ -44,6 +45,11 @@ public Object handle(EasemobAPI easemobAPI) { Gson gson = new Gson(); Map map = gson.fromJson(e.getResponseBody(), Map.class); logger.error("error_code:{} error_msg:{} error_desc:{}", e.getCode(), e.getMessage(), map.get("error_description")); + + // 将未捕捉的exception返回上层 + if (result == null) { + result = e.getResponseBody(); + } } return result; } diff --git a/emchat-server-java/src/test/java/com/easemob/ChatGroupTest.java b/emchat-server-java/src/test/java/com/easemob/ChatGroupTest.java index 61991a3..5251260 100644 --- a/emchat-server-java/src/test/java/com/easemob/ChatGroupTest.java +++ b/emchat-server-java/src/test/java/com/easemob/ChatGroupTest.java @@ -24,8 +24,8 @@ public void getChatGroups() { @Test public void getGroupsInfo() { String[] grousIds = new String[2]; - grousIds[0] = "11189173157890"; - grousIds[1] = "259168197054300592"; + grousIds[0] = "49985791000577"; + grousIds[1] = "49985853915137"; Object result = easemobChatGroup.getChatGroupDetails(grousIds); logger.info(result.toString()); } @@ -33,7 +33,7 @@ public void getGroupsInfo() { @Test public void createGroup() { Group group = new Group(); - group.groupname("groupA").desc("a new group")._public(true).maxusers(50).approval(false).owner("stringa"); + group.groupname("groupA").desc("a new group")._public(true).maxusers(50).approval(false).owner("easemob_test_a_004"); Object result = easemobChatGroup.createChatGroup(group); logger.info(result.toString()); } @@ -41,19 +41,26 @@ public void createGroup() { @Test public void changeGroupInfo() { ModifyGroup group = new ModifyGroup(); - String groupId = "11361107116036"; + String groupId = "49985853915137"; group.description("change group info").groupname("changed group").maxusers(300); Object result = easemobChatGroup.modifyChatGroup(groupId, group); logger.info(result.toString()); } + @Test + public void getUsersFromGroup() { + String groupId = "49985853915137"; + Object result = easemobChatGroup.getChatGroupUsers(groupId); + logger.info(result.toString()); + } + @Test public void addUsers() { - String groupId = "11361107116036"; + String groupId = "49985853915137"; UserNames userNames = new UserNames(); UserName userList = new UserName(); - userList.add("qwqwqw"); - userList.add("qwqwqww"); + userList.add("easemob_test_b_004"); + userList.add("easemob_test_b_003"); userNames.usernames(userList); Object result = easemobChatGroup.addBatchUsersToChatGroup(groupId, userNames); logger.info(result.toString()); @@ -61,37 +68,37 @@ public void addUsers() { @Test public void removeUsersFromGroup() { - String groupId = "11361107116036"; + String groupId = "49985853915137"; String[] userIds = new String[2]; - userIds[0] = "qwqwqw"; - userIds[1] = "qwqwqww"; + userIds[0] = "easemob_test_b_004"; + userIds[1] = "easemob_test_b_003"; Object result = easemobChatGroup.removeBatchUsersFromChatGroup(groupId, userIds); logger.info(result.toString()); } @Test - public void getUsersFromGroup() { - String groupId = "11361107116036"; - Object result = easemobChatGroup.getChatGroupUsers(groupId); + public void transferGroupOwner() { + String groupId = "49985853915137"; + NewOwner newOwner = new NewOwner(); + newOwner.newowner("easemob_test_b_004"); + Object result = easemobChatGroup.transferChatGroupOwner(groupId, newOwner); logger.info(result.toString()); } @Test - public void transferGroupOwner() { - String groupId = "11361107116036"; - NewOwner newOwner = new NewOwner(); - newOwner.newowner("qwqwqww"); - Object result = easemobChatGroup.transferChatGroupOwner(groupId, newOwner); + public void getChatGroupBlockUsers(){ + String groupId = "49985853915137"; + Object result = easemobChatGroup.getChatGroupBlockUsers(groupId); logger.info(result.toString()); } @Test public void addBlockUsers() { - String groupId = "11361107116036"; + String groupId = "49985853915137"; UserNames userNames = new UserNames(); UserName userList = new UserName(); - userList.add("qwqwqw"); - userList.add("qwqwqww"); + userList.add("easemob_test_b_004"); + userList.add("easemob_test_b_003"); userNames.usernames(userList); Object result = easemobChatGroup.addBatchBlockUsersToChatGroup(groupId, userNames); logger.info(result.toString()); @@ -99,10 +106,10 @@ public void addBlockUsers() { @Test public void removeBlockUser() { - String groupId = "11361107116036"; + String groupId = "49985853915137"; String[] userIds = new String[2]; - userIds[0] = "qwqwqw"; - userIds[1] = "qwqwqww"; + userIds[0] = "easemob_test_b_004"; + userIds[1] = "easemob_test_b_003"; Object result = easemobChatGroup.removeBatchBlockUsersFromChatGroup(groupId, userIds); logger.info(result.toString()); } diff --git a/emchat-server-java/src/test/java/com/easemob/ChatRoomTest.java b/emchat-server-java/src/test/java/com/easemob/ChatRoomTest.java index 6afbe47..4b8fe0e 100644 --- a/emchat-server-java/src/test/java/com/easemob/ChatRoomTest.java +++ b/emchat-server-java/src/test/java/com/easemob/ChatRoomTest.java @@ -20,14 +20,14 @@ public class ChatRoomTest { @Test public void createChatRoom() { Chatroom chatroom = new Chatroom(); - chatroom.name("myChatRoom").description("test chatroom").maxusers(200).owner("stringa"); + chatroom.name("myChatRoom").description("test chatroom").maxusers(200).owner("easemob_test_a_004"); Object result = easemobChatRoom.createChatRoom(chatroom); logger.info(result.toString()); } @Test public void changeChatRoomInfo() { - String roomId = "11368499576837"; + String roomId = "49986023784449"; ModifyChatroom chatroom = new ModifyChatroom(); chatroom.name("changeRoom").description("test changeromm info").maxusers(100); Object result = easemobChatRoom.modifyChatRoom(roomId, chatroom); @@ -41,12 +41,19 @@ public void getAllRoom() { } @Test - public void addUsersToRoom() { + public void getChatRoomDetail(){ String roomId = "11368499576837"; + Object result = easemobChatRoom.getChatRoomDetail(roomId); + logger.info(result.toString()); + } + + @Test + public void addUsersToRoom() { + String roomId = "49986023784449"; UserNames userNames = new UserNames(); UserName userList = new UserName(); - userList.add("qwqwqw"); - userList.add("qwqwqww"); + userList.add("easemob_test_b_004"); + userList.add("easemob_test_b_003"); userNames.usernames(userList); Object result = easemobChatRoom.addBatchUsersToChatRoom(roomId, userNames); logger.info(result.toString()); @@ -54,10 +61,10 @@ public void addUsersToRoom() { @Test public void deleteUsersFromRoom() { - String roomId = "11368499576837"; + String roomId = "49986023784449"; String[] userIds = new String[2]; - userIds[0] = "qwqwqw"; - userIds[1] = "qwqwqww"; + userIds[0] = "easemob_test_b_004"; + userIds[1] = "easemob_test_b_003"; Object result = easemobChatRoom.removeBatchUsersFromChatRoom(roomId, userIds); logger.info(result.toString()); } diff --git a/emchat-server-java/src/test/java/com/easemob/SendMessageTest.java b/emchat-server-java/src/test/java/com/easemob/SendMessageTest.java index 642985f..ad66bee 100644 --- a/emchat-server-java/src/test/java/com/easemob/SendMessageTest.java +++ b/emchat-server-java/src/test/java/com/easemob/SendMessageTest.java @@ -6,7 +6,6 @@ import io.swagger.client.model.MsgContent; import io.swagger.client.model.UserName; import org.junit.Test; - import java.util.HashMap; import java.util.Map; @@ -22,10 +21,10 @@ public void sendText() { MsgContent msgContent = new MsgContent(); msgContent.type(MsgContent.TypeEnum.TXT).msg("helloword"); UserName userName = new UserName(); - userName.add("qwqwqww"); + userName.add("easemob_test_a_004"); Map ext = new HashMap<>(); ext.put("test_key","test_value"); - msg.from("stringa").target(userName).targetType("users").msg(msgContent).ext(ext); + msg.from("easemob_test_b_004").target(userName).targetType("users").msg(msgContent).ext(ext); System.out.println(new GsonBuilder().create().toJson(msg)); Object result = easemobSendMessage.sendMessage(msg); System.out.println(result); @@ -34,43 +33,120 @@ public void sendText() { @Test public void sendImage() { Msg msg = new Msg(); - ImageMsgContent msgContent = new ImageMsgContent(); - msgContent.url("http://test_url").secret("test_sec").filename("filename").size(new ImageMsgContent.Size(480, 720)) - .type(MsgContent.TypeEnum.IMG).msg("this is an image message"); + FileMsgContent msgContent = new FileMsgContent(); + msgContent.url("http://a1.easemob.com/1122161011178276/testapp/chatfiles/bd825310-5cde-11e8-b1f2-5f70c14699e0").secret("vYJTGlzeEei-kpPGPscCt7pY9PB4ipz04rs8o9uqgh3jzlGt").filename("filename.jpg").size(new FileMsgContent.Size(480, 720)) + .type(MsgContent.TypeEnum.IMG); + UserName userName = new UserName(); + userName.add("easemob_test_a_004"); + msg.from("easemob_test_b_004").target(userName).targetType("users").msg(msgContent); + System.out.println(new GsonBuilder().create().toJson(msg)); + Object result = easemobSendMessage.sendMessage(msg); + System.out.println(result); + } + + @Test + public void sendAudio() { + Msg msg = new Msg(); + FileMsgContent msgContent = new FileMsgContent(); + msgContent.url("https://a1.easemob.com/1122161011178276/testapp/chatfiles/0e9656e0-5e6d-11e8-b447-33a9eeb51e5a").secret("DpZW6l5tEeiw16_MfaWGq2m486jTAjjJOVB1ZbqfbwyvkKc5").file_length(8678).length(6).filename("filename.amr").type(MsgContent.TypeEnum.AUDIO); + UserName userName = new UserName(); + userName.add("easemob_test_a_004"); + msg.from("easemob_test_b_004").target(userName).targetType("users").msg(msgContent); + System.out.println(new GsonBuilder().create().toJson(msg)); + Object result = easemobSendMessage.sendMessage(msg); + System.out.println(result); + } + + @Test + public void sendVideo() { + Msg msg = new Msg(); + FileMsgContent msgContent = new FileMsgContent(); + msgContent.url("http://a1.easemob.com/1122161011178276/testapp/chatfiles/bd825310-5cde-11e8-b1f2-5f70c14699e0").secret("vYJTGlzeEei-kpPGPscCt7pY9PB4ipz04rs8o9uqgh3jzlGt").thumb("http://a1.easemob.com/1122161011178276/testapp/chatfiles/bd825310-5cde-11e8-b1f2-5f70c14699e0").thumb_secret("vYJTGlzeEei-kpPGPscCt7pY9PB4ipz04rs8o9uqgh3jzlGt").file_length(58103).length(5).filename("filename.mp4").type(MsgContent.TypeEnum.VIDEO); + UserName userName = new UserName(); + userName.add("easemob_test_a_004"); + msg.from("easemob_test_b_004").target(userName).targetType("users").msg(msgContent); + System.out.println(new GsonBuilder().create().toJson(msg)); + Object result = easemobSendMessage.sendMessage(msg); + System.out.println(result); + } + + @Test + public void sendCmd() { + Msg msg = new Msg(); + MsgContent msgContent = new MsgContent().type(MsgContent.TypeEnum.CMD); + UserName userName = new UserName(); + userName.add("easemob_test_a_004"); + msg.from("easemob_test_b_004").target(userName).targetType("users").action("action").msg(msgContent); + System.out.println(new GsonBuilder().create().toJson(msg)); + Object result = easemobSendMessage.sendMessage(msg); + System.out.println(result); + } + + @Test + public void sendTextWhitExt() { + Msg msg = new Msg(); + MsgContent msgContent = new MsgContent(); + msgContent.type(MsgContent.TypeEnum.TXT).msg("扩展消息"); UserName userName = new UserName(); - userName.add("receiver"); - msg.from("sender").target(userName).targetType("users").msg(msgContent); + userName.add("easemob_test_a_004"); + Map ext = new HashMap<>(); + ext.put("test_key","test_value"); + msg.from("easemob_test_b_004").target(userName).targetType("users").msg(msgContent).ext(ext); System.out.println(new GsonBuilder().create().toJson(msg)); Object result = easemobSendMessage.sendMessage(msg); System.out.println(result); } - static class ImageMsgContent extends MsgContent { + static class FileMsgContent extends MsgContent { private String url; private String filename; private String secret; private Size size; + private long length; + private String thumb; + private long file_length; + private String thumb_secret; - ImageMsgContent url(String url) { + FileMsgContent url(String url) { this.url = url; return this; } - ImageMsgContent filename(String filename) { + FileMsgContent filename(String filename) { this.filename = filename; return this; } - ImageMsgContent secret(String secret) { + FileMsgContent secret(String secret) { this.secret = secret; return this; } - ImageMsgContent size(Size size) { + FileMsgContent size(Size size) { this.size = size; return this; } + FileMsgContent length(long length) { + this.length = length; + return this; + } + + FileMsgContent thumb(String thumb) { + this.thumb = thumb; + return this; + } + + FileMsgContent file_length(long file_length) { + this.file_length = file_length; + return this; + } + + FileMsgContent thumb_secret(String thumb_secret) { + this.thumb_secret = thumb_secret; + return this; + } + static class Size { private long width; private long height; diff --git a/emchat-server-java/src/test/java/com/easemob/UserTest.java b/emchat-server-java/src/test/java/com/easemob/UserTest.java index 97d9ee9..58d01df 100644 --- a/emchat-server-java/src/test/java/com/easemob/UserTest.java +++ b/emchat-server-java/src/test/java/com/easemob/UserTest.java @@ -1,16 +1,12 @@ package com.easemob; import com.easemob.server.example.api.impl.EasemobIMUsers; -import io.swagger.client.model.NewPassword; -import io.swagger.client.model.RegisterUsers; -import io.swagger.client.model.User; +import io.swagger.client.model.*; import org.junit.Assert; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Random; - /** * Created by easemob on 2017/3/21. */ @@ -20,32 +16,42 @@ public class UserTest { private EasemobIMUsers easemobIMUsers = new EasemobIMUsers(); @Test - public void createUser() { + public void createUserSingleTest() { RegisterUsers users = new RegisterUsers(); - User user = new User().username("aaaa123456" + new Random().nextInt(500)).password("123456"); - User user1 = new User().username("aaa123456" + new Random().nextInt(500)).password("123456"); + User user = new User().username("easemob_test_a_004").password("123456"); users.add(user); - users.add(user1); Object result = easemobIMUsers.createNewIMUserSingle(users); logger.info(result.toString()); Assert.assertNotNull(result); } @Test - public void getUserByName() { - String userName = "stringa"; + public void createUserBatchTest() { + RegisterUsers users = new RegisterUsers(); + User user1 = new User().username("easemob_test_a_004").password("123456"); + User user2 = new User().username("easemob_test_b_004").password("123456"); + users.add(user1); + users.add(user2); + Object result = easemobIMUsers.createNewIMUserBatch(users); + logger.info(result.toString()); + Assert.assertNotNull(result); + } + + @Test + public void getUserByNameTest() { + String userName = "easemob_test_a_001"; Object result = easemobIMUsers.getIMUserByUserName(userName); logger.info(result.toString()); } @Test - public void gerUsers() { + public void getUsersTest() { Object result = easemobIMUsers.getIMUsersBatch(5L, null); logger.info(result.toString()); } @Test - public void changePassword() { + public void changePasswordTest() { String userName = "stringa"; NewPassword psd = new NewPassword().newpassword("123"); Object result = easemobIMUsers.modifyIMUserPasswordWithAdminToken(userName, psd); @@ -53,9 +59,108 @@ public void changePassword() { } @Test - public void getFriend() { - String userName = "stringa"; + public void changeNicknameTest(){ + String userName = "easemob_test_a_001"; + Nickname nickname = new Nickname().nickname("easemob_test_a_001"); + Object result = easemobIMUsers.modifyIMUserNickNameWithAdminToken(userName, nickname); + logger.info(result.toString()); + } + + @Test + public void addFriendTest(){ + String userName = "easemob_test_a_004"; + String friendName = "easemob_test_b_004"; + Object result = easemobIMUsers.addFriendSingle(userName, friendName); + logger.info(result.toString()); + } + + @Test + public void deleteFriendTest(){ + String userName = "easemob_test_a_004"; + String friendName = "easemob_test_b_004"; + Object result = easemobIMUsers.deleteFriendSingle(userName, friendName); + logger.info(result.toString()); + } + + @Test + public void getFriendTest() { + String userName = "easemob_test_a_004"; Object result = easemobIMUsers.getFriends(userName); logger.info(result.toString()); } + + @Test + public void getBlackListTest(){ + String userName = "easemob_test_a_001"; + Object result = easemobIMUsers.getBlackList(userName); + logger.info(result.toString()); + } + + @Test + public void addToBlackListTest(){ + String userName = "easemob_test_a_001"; + UserName blackUserNames = new UserName(); + blackUserNames.add("easemob_test_b_002"); + blackUserNames.add("easemob_test_b_003"); + UserNames userNames = new UserNames().usernames(blackUserNames); + Object result = easemobIMUsers.addToBlackList(userName, userNames); + logger.info(result.toString()); + } + + @Test + public void removeFromBlackListTest(){ + String userName = "easemob_test_a_001"; + String blackUserName = "easemob_test_b_003"; + Object result = easemobIMUsers.removeFromBlackList(userName, blackUserName); + logger.info(result.toString()); + } + + @Test + public void getIMUserStatusTest(){ + String userName = "easemob_test_a_001"; + Object result = easemobIMUsers.getIMUserStatus(userName); + logger.info(result.toString()); + } + + @Test + public void getOfflineMsgCountTest(){ + String userName = "easemob_test_a_001"; + Object result = easemobIMUsers.getOfflineMsgCount(userName); + logger.info(result.toString()); + } + + @Test + public void deactivateIMUserTest(){ + String userName = "easemob_test_a_001"; + Object result = easemobIMUsers.deactivateIMUser(userName); + logger.info(result.toString()); + } + + @Test + public void activateIMUserTest(){ + String userName = "easemob_test_a_001"; + Object result = easemobIMUsers.activateIMUser(userName); + logger.info(result.toString()); + } + + @Test + public void disconnectIMUserTest(){ + String userName = "easemob_test_a_001"; + Object result = easemobIMUsers.disconnectIMUser(userName); + logger.info(result.toString()); + } + + @Test + public void getUserJoinedChatGroups(){ + String userName = "easemob_test_a_001"; + Object result = easemobIMUsers.getIMUserAllChatGroups(userName); + logger.info(result.toString()); + } + + @Test + public void getUserJoinedChatRooms(){ + String userName = "easemob_test_a_001"; + Object result = easemobIMUsers.getIMUserAllChatRooms(userName); + logger.info(result.toString()); + } } From e115a18b9ec171bb7a3f18eb2276006d30d9e519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=86=B2?= <569471293@qq.com> Date: Thu, 24 May 2018 13:26:10 +0800 Subject: [PATCH 2/3] add and perfect java examples --- .../java/com/easemob/server/example/comm/ResponseHandler.java | 1 - 1 file changed, 1 deletion(-) diff --git a/emchat-server-java/src/main/java/com/easemob/server/example/comm/ResponseHandler.java b/emchat-server-java/src/main/java/com/easemob/server/example/comm/ResponseHandler.java index 443cc13..d855e90 100644 --- a/emchat-server-java/src/main/java/com/easemob/server/example/comm/ResponseHandler.java +++ b/emchat-server-java/src/main/java/com/easemob/server/example/comm/ResponseHandler.java @@ -16,7 +16,6 @@ public class ResponseHandler { public Object handle(EasemobAPI easemobAPI) { Object result = null; - StringBuffer stringBuffer = new StringBuffer(); try { result = easemobAPI.invokeEasemobAPI(); } catch (ApiException e) { From 72c0462bccf8e8c95415ba43a1a11e6f96a36109 Mon Sep 17 00:00:00 2001 From: shenchong <569471293@qq.com> Date: Wed, 30 May 2018 16:57:06 +0800 Subject: [PATCH 3/3] add and perfect java examples --- .../server/example/comm/ResponseHandler.java | 10 ++-- .../test/java/com/easemob/ChatGroupTest.java | 34 +++++++++++ .../java/com/easemob/ChatMessagesTest.java | 4 ++ .../test/java/com/easemob/ChatRoomTest.java | 19 ++++++ .../src/test/java/com/easemob/FileTest.java | 8 +++ .../java/com/easemob/SendMessageTest.java | 19 ++++++ .../java/com/easemob/TokenGenerateTest.java | 4 ++ .../src/test/java/com/easemob/UserTest.java | 58 +++++++++++++++++++ 8 files changed, 150 insertions(+), 6 deletions(-) diff --git a/emchat-server-java/src/main/java/com/easemob/server/example/comm/ResponseHandler.java b/emchat-server-java/src/main/java/com/easemob/server/example/comm/ResponseHandler.java index 443cc13..4848bcf 100644 --- a/emchat-server-java/src/main/java/com/easemob/server/example/comm/ResponseHandler.java +++ b/emchat-server-java/src/main/java/com/easemob/server/example/comm/ResponseHandler.java @@ -16,10 +16,13 @@ public class ResponseHandler { public Object handle(EasemobAPI easemobAPI) { Object result = null; - StringBuffer stringBuffer = new StringBuffer(); try { result = easemobAPI.invokeEasemobAPI(); } catch (ApiException e) { + + /** + * 请求状态码非200时,捕获异常,也可以抛出上层处理。 + */ if (e.getCode() == 401) { logger.info("The current token is invalid, re-generating token for you and calling it again"); TokenUtil.initTokenByProp(); @@ -45,11 +48,6 @@ public Object handle(EasemobAPI easemobAPI) { Gson gson = new Gson(); Map map = gson.fromJson(e.getResponseBody(), Map.class); logger.error("error_code:{} error_msg:{} error_desc:{}", e.getCode(), e.getMessage(), map.get("error_description")); - - // 将未捕捉的exception返回上层 - if (result == null) { - result = e.getResponseBody(); - } } return result; } diff --git a/emchat-server-java/src/test/java/com/easemob/ChatGroupTest.java b/emchat-server-java/src/test/java/com/easemob/ChatGroupTest.java index 5251260..7901f16 100644 --- a/emchat-server-java/src/test/java/com/easemob/ChatGroupTest.java +++ b/emchat-server-java/src/test/java/com/easemob/ChatGroupTest.java @@ -8,11 +8,15 @@ /** * Created by easemob on 2017/3/22. + * API 文档地址:http://docs.easemob.com/im/100serverintegration/60groupmgmt */ public class ChatGroupTest { private EasemobChatGroup easemobChatGroup = new EasemobChatGroup(); private static final Logger logger = LoggerFactory.getLogger(ChatGroupTest.class); + /** + * 分页获取 APP 下的群组 + */ @Test public void getChatGroups() { Long limit = 5L; @@ -21,6 +25,9 @@ public void getChatGroups() { logger.info(result.toString()); } + /** + * 获取群组详情 + */ @Test public void getGroupsInfo() { String[] grousIds = new String[2]; @@ -30,6 +37,9 @@ public void getGroupsInfo() { logger.info(result.toString()); } + /** + * 创建一个群组 + */ @Test public void createGroup() { Group group = new Group(); @@ -38,6 +48,9 @@ public void createGroup() { logger.info(result.toString()); } + /** + * 修改群组信息 + */ @Test public void changeGroupInfo() { ModifyGroup group = new ModifyGroup(); @@ -47,6 +60,9 @@ public void changeGroupInfo() { logger.info(result.toString()); } + /** + * 分页获取群组成员 + */ @Test public void getUsersFromGroup() { String groupId = "49985853915137"; @@ -54,6 +70,9 @@ public void getUsersFromGroup() { logger.info(result.toString()); } + /** + * 添加群组成员[批量] + */ @Test public void addUsers() { String groupId = "49985853915137"; @@ -66,6 +85,9 @@ public void addUsers() { logger.info(result.toString()); } + /** + * 移除群组成员[批量] + */ @Test public void removeUsersFromGroup() { String groupId = "49985853915137"; @@ -76,6 +98,9 @@ public void removeUsersFromGroup() { logger.info(result.toString()); } + /** + * 转让群组 + */ @Test public void transferGroupOwner() { String groupId = "49985853915137"; @@ -85,6 +110,9 @@ public void transferGroupOwner() { logger.info(result.toString()); } + /** + * 查询群组黑名单 + */ @Test public void getChatGroupBlockUsers(){ String groupId = "49985853915137"; @@ -92,6 +120,9 @@ public void getChatGroupBlockUsers(){ logger.info(result.toString()); } + /** + * 添加用户至群组黑名单 + */ @Test public void addBlockUsers() { String groupId = "49985853915137"; @@ -104,6 +135,9 @@ public void addBlockUsers() { logger.info(result.toString()); } + /** + * 从群组黑名单移除用户 + */ @Test public void removeBlockUser() { String groupId = "49985853915137"; diff --git a/emchat-server-java/src/test/java/com/easemob/ChatMessagesTest.java b/emchat-server-java/src/test/java/com/easemob/ChatMessagesTest.java index cf1c4fe..f402807 100644 --- a/emchat-server-java/src/test/java/com/easemob/ChatMessagesTest.java +++ b/emchat-server-java/src/test/java/com/easemob/ChatMessagesTest.java @@ -10,12 +10,16 @@ /** * Created by easemob on 2017/3/22. + * API 文档地址:http://docs.easemob.com/im/100serverintegration/30chatlog */ public class ChatMessagesTest { private EasemobChatMessage easemobChatMessage = new EasemobChatMessage(); private static final Logger logger = LoggerFactory.getLogger(ChatMessagesTest.class); private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyyMMddHH"); + /** + * 获取聊天记录文件url + */ @Test public void getChatMessagesDownloadUrl() { Calendar calendar = Calendar.getInstance(); diff --git a/emchat-server-java/src/test/java/com/easemob/ChatRoomTest.java b/emchat-server-java/src/test/java/com/easemob/ChatRoomTest.java index 4b8fe0e..acb9c09 100644 --- a/emchat-server-java/src/test/java/com/easemob/ChatRoomTest.java +++ b/emchat-server-java/src/test/java/com/easemob/ChatRoomTest.java @@ -11,12 +11,16 @@ /** * Created by easemob on 2017/3/23. + * API 地址:http://docs.easemob.com/im/100serverintegration/70chatroommgmt */ public class ChatRoomTest { private EasemobChatRoom easemobChatRoom = new EasemobChatRoom(); private static final Logger logger = LoggerFactory.getLogger(ChatRoomTest.class); + /** + * 创建一个聊天室 + */ @Test public void createChatRoom() { Chatroom chatroom = new Chatroom(); @@ -25,6 +29,9 @@ public void createChatRoom() { logger.info(result.toString()); } + /** + * 修改聊天室信息 + */ @Test public void changeChatRoomInfo() { String roomId = "49986023784449"; @@ -34,12 +41,18 @@ public void changeChatRoomInfo() { logger.info(result.toString()); } + /** + * 获取 APP 中所有的聊天室 + */ @Test public void getAllRoom() { Object result = easemobChatRoom.getAllChatRooms(); logger.info(result.toString()); } + /** + * 获取聊天室详情 + */ @Test public void getChatRoomDetail(){ String roomId = "11368499576837"; @@ -47,6 +60,9 @@ public void getChatRoomDetail(){ logger.info(result.toString()); } + /** + * 添加聊天室成员 + */ @Test public void addUsersToRoom() { String roomId = "49986023784449"; @@ -59,6 +75,9 @@ public void addUsersToRoom() { logger.info(result.toString()); } + /** + * 删除聊天室成员 + */ @Test public void deleteUsersFromRoom() { String roomId = "49986023784449"; diff --git a/emchat-server-java/src/test/java/com/easemob/FileTest.java b/emchat-server-java/src/test/java/com/easemob/FileTest.java index 109fc54..6da0a2d 100644 --- a/emchat-server-java/src/test/java/com/easemob/FileTest.java +++ b/emchat-server-java/src/test/java/com/easemob/FileTest.java @@ -9,10 +9,15 @@ /** * Created by easemob on 2017/3/22. + * API 文档地址:http://docs.easemob.com/im/100serverintegration/40fileoperation */ public class FileTest { private EasemobFile easemobFile = new EasemobFile(); + /** + * 上传文件 + * 示例:上传图片文件 + */ @Test public void uploadFile() { String path = TokenUtil.class.getClassLoader().getResource("pic/chick.jpg").getPath(); @@ -22,6 +27,9 @@ public void uploadFile() { Assert.assertNotNull(result); } + /** + * 下载文件 + */ @Test public void downloadFile() { String uuid = "5deca060-0ea9-11e7-959e-0d3820191bac"; diff --git a/emchat-server-java/src/test/java/com/easemob/SendMessageTest.java b/emchat-server-java/src/test/java/com/easemob/SendMessageTest.java index ad66bee..b3ecae5 100644 --- a/emchat-server-java/src/test/java/com/easemob/SendMessageTest.java +++ b/emchat-server-java/src/test/java/com/easemob/SendMessageTest.java @@ -11,10 +11,14 @@ /** * Created by easemob on 2017/3/22. + * API 地址:http://docs.easemob.com/im/100serverintegration/50messages */ public class SendMessageTest { private EasemobSendMessage easemobSendMessage = new EasemobSendMessage(); + /** + * 发送文本消息 + */ @Test public void sendText() { Msg msg = new Msg(); @@ -30,6 +34,9 @@ public void sendText() { System.out.println(result); } + /** + * 发送图片消息 + */ @Test public void sendImage() { Msg msg = new Msg(); @@ -44,6 +51,9 @@ public void sendImage() { System.out.println(result); } + /** + * 发送语音消息 + */ @Test public void sendAudio() { Msg msg = new Msg(); @@ -57,6 +67,9 @@ public void sendAudio() { System.out.println(result); } + /** + * 发送视频消息 + */ @Test public void sendVideo() { Msg msg = new Msg(); @@ -70,6 +83,9 @@ public void sendVideo() { System.out.println(result); } + /** + * 发送透传消息 + */ @Test public void sendCmd() { Msg msg = new Msg(); @@ -82,6 +98,9 @@ public void sendCmd() { System.out.println(result); } + /** + * 发送文本消息带扩展 + */ @Test public void sendTextWhitExt() { Msg msg = new Msg(); diff --git a/emchat-server-java/src/test/java/com/easemob/TokenGenerateTest.java b/emchat-server-java/src/test/java/com/easemob/TokenGenerateTest.java index 67decd3..a36637f 100644 --- a/emchat-server-java/src/test/java/com/easemob/TokenGenerateTest.java +++ b/emchat-server-java/src/test/java/com/easemob/TokenGenerateTest.java @@ -7,10 +7,14 @@ /** * Created by easemob on 2017/3/21. + * API 文档地址:http://docs.easemob.com/im/100serverintegration/20users */ public class TokenGenerateTest { private EasemobAuthToken easemobAuthToken = new EasemobAuthToken(); + /** + * 获取管理员token + */ @Test public void testTokenGet() throws ApiException { System.out.println(easemobAuthToken.getAuthToken()); diff --git a/emchat-server-java/src/test/java/com/easemob/UserTest.java b/emchat-server-java/src/test/java/com/easemob/UserTest.java index 58d01df..7f6f098 100644 --- a/emchat-server-java/src/test/java/com/easemob/UserTest.java +++ b/emchat-server-java/src/test/java/com/easemob/UserTest.java @@ -9,12 +9,16 @@ /** * Created by easemob on 2017/3/21. + * API 文档地址:http://docs.easemob.com/im/100serverintegration/20users */ public class UserTest { private static final Logger logger = LoggerFactory.getLogger(UserTest.class); private EasemobIMUsers easemobIMUsers = new EasemobIMUsers(); + /** + * 注册 IM 用户[单个] + */ @Test public void createUserSingleTest() { RegisterUsers users = new RegisterUsers(); @@ -25,6 +29,9 @@ public void createUserSingleTest() { Assert.assertNotNull(result); } + /** + * 注册 IM 用户[批量] + */ @Test public void createUserBatchTest() { RegisterUsers users = new RegisterUsers(); @@ -37,6 +44,9 @@ public void createUserBatchTest() { Assert.assertNotNull(result); } + /** + * 获取 IM 用户[单个] + */ @Test public void getUserByNameTest() { String userName = "easemob_test_a_001"; @@ -44,12 +54,18 @@ public void getUserByNameTest() { logger.info(result.toString()); } + /** + * 获取 IM 用户[批量] + */ @Test public void getUsersTest() { Object result = easemobIMUsers.getIMUsersBatch(5L, null); logger.info(result.toString()); } + /** + * 重置 IM 用户密码 + */ @Test public void changePasswordTest() { String userName = "stringa"; @@ -58,6 +74,9 @@ public void changePasswordTest() { logger.info(result.toString()); } + /** + * 修改用户推送显示昵称 + */ @Test public void changeNicknameTest(){ String userName = "easemob_test_a_001"; @@ -66,6 +85,9 @@ public void changeNicknameTest(){ logger.info(result.toString()); } + /** + * 给 IM 用户添加好友 + */ @Test public void addFriendTest(){ String userName = "easemob_test_a_004"; @@ -74,6 +96,9 @@ public void addFriendTest(){ logger.info(result.toString()); } + /** + * 解除 IM 用户的好友关系 + */ @Test public void deleteFriendTest(){ String userName = "easemob_test_a_004"; @@ -82,6 +107,9 @@ public void deleteFriendTest(){ logger.info(result.toString()); } + /** + * 获取 IM 用户的好友列表 + */ @Test public void getFriendTest() { String userName = "easemob_test_a_004"; @@ -89,6 +117,9 @@ public void getFriendTest() { logger.info(result.toString()); } + /** + * 获取 IM 用户的黑名单 + */ @Test public void getBlackListTest(){ String userName = "easemob_test_a_001"; @@ -96,6 +127,9 @@ public void getBlackListTest(){ logger.info(result.toString()); } + /** + * 往 IM 用户的黑名单中加人 + */ @Test public void addToBlackListTest(){ String userName = "easemob_test_a_001"; @@ -107,6 +141,9 @@ public void addToBlackListTest(){ logger.info(result.toString()); } + /** + * 从 IM 用户的黑名单中减人 + */ @Test public void removeFromBlackListTest(){ String userName = "easemob_test_a_001"; @@ -115,6 +152,9 @@ public void removeFromBlackListTest(){ logger.info(result.toString()); } + /** + * 查看用户在线状态 + */ @Test public void getIMUserStatusTest(){ String userName = "easemob_test_a_001"; @@ -122,6 +162,9 @@ public void getIMUserStatusTest(){ logger.info(result.toString()); } + /** + * 查询离线消息数 + */ @Test public void getOfflineMsgCountTest(){ String userName = "easemob_test_a_001"; @@ -129,6 +172,9 @@ public void getOfflineMsgCountTest(){ logger.info(result.toString()); } + /** + * 用户账号禁用 + */ @Test public void deactivateIMUserTest(){ String userName = "easemob_test_a_001"; @@ -136,6 +182,9 @@ public void deactivateIMUserTest(){ logger.info(result.toString()); } + /** + * 用户账号解禁 + */ @Test public void activateIMUserTest(){ String userName = "easemob_test_a_001"; @@ -143,6 +192,9 @@ public void activateIMUserTest(){ logger.info(result.toString()); } + /** + * 强制用户下线 + */ @Test public void disconnectIMUserTest(){ String userName = "easemob_test_a_001"; @@ -150,6 +202,9 @@ public void disconnectIMUserTest(){ logger.info(result.toString()); } + /** + * 获取一个用户参与的所有群组 + */ @Test public void getUserJoinedChatGroups(){ String userName = "easemob_test_a_001"; @@ -157,6 +212,9 @@ public void getUserJoinedChatGroups(){ logger.info(result.toString()); } + /** + * 获取一个用户参与的所有聊天室 + */ @Test public void getUserJoinedChatRooms(){ String userName = "easemob_test_a_001";