Unverified Commit f41f5d39 authored by Yang Libin's avatar Yang Libin Committed by GitHub

feat: add group api and fix unit tests (#17)

* feat: add group api and fix unit tests * docs: update readme
parent db65892c
......@@ -62,8 +62,8 @@
### 6. 群组管理
- [x] 获取 App 中的所有群组
- [ ] 创建群组
- [ ] 获取群详细资料
- [x] 创建群组
- [x] 获取群详细资料
- [ ] 获取群成员详细资料
- [ ] 修改群基础资料
- [ ] 增加群成员
......
package com.qcloud.im.core;
import com.qcloud.im.IMClient;
import com.qcloud.im.model.request.CreateGroupRequest;
import com.qcloud.im.model.request.GetAppidGroupListRequest;
import com.qcloud.im.model.request.GetGroupInfoRequest;
import com.qcloud.im.model.response.CreateGroupResult;
import com.qcloud.im.model.response.GetAppidGroupListResult;
import com.qcloud.im.model.response.GetGroupInfoResult;
import com.qcloud.im.util.HttpUtil;
import com.qcloud.im.util.JsonUtil;
......@@ -51,4 +55,16 @@ public class Group {
String result = HttpUtil.post(url, JsonUtil.obj2Str(getAppidGroupListRequest), null);
return JsonUtil.str2Obj(result, GetAppidGroupListResult.class);
}
public CreateGroupResult createGroup(CreateGroupRequest createGroupRequest) throws IOException {
String url = imClient.getUrl(SERVICE_NAME, CREATE_GROUP_COMMAND);
String result = HttpUtil.post(url, JsonUtil.obj2Str(createGroupRequest), null);
return JsonUtil.str2Obj(result, CreateGroupResult.class);
}
public GetGroupInfoResult getGroupInfo(GetGroupInfoRequest getGroupInfoRequest) throws IOException {
String url = imClient.getUrl(SERVICE_NAME, GET_GROUP_INFO_COMMAND);
String result = HttpUtil.post(url, JsonUtil.obj2Str(getGroupInfoRequest), null);
return JsonUtil.str2Obj(result, GetGroupInfoResult.class);
}
}
package com.qcloud.im.model.request;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
import java.util.Map;
/**
* @author bingo
* @since 2021/8/1 11:12
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class CreateGroupRequest extends GenericRequest {
@JsonProperty("Owner_Account")
private String ownerAccount;
@JsonProperty("Type")
private String type;
@JsonProperty("GroupId")
private String groupId;
@JsonProperty("Name")
private String name;
@JsonProperty("Introduction")
private String introduction;
@JsonProperty("Notification")
private String notification;
@JsonProperty("FaceUrl")
private String faceUrl;
@JsonProperty("MaxMemberCount")
private Integer maxMemberCount;
@JsonProperty("ApplyJoinOption")
private String applyJoinOption;
@JsonProperty("AppDefinedData")
private List<Map<String, Object>> appDefinedData;
@JsonProperty("MemberList")
private List<MemberProfile> memberList;
@JsonProperty("AppMemberDefinedData")
private List<Map<String, Object>> appMemberDefinedData;
public String getOwnerAccount() {
return ownerAccount;
}
public void setOwnerAccount(String ownerAccount) {
this.ownerAccount = ownerAccount;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getGroupId() {
return groupId;
}
public void setGroupId(String groupId) {
this.groupId = groupId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getIntroduction() {
return introduction;
}
public void setIntroduction(String introduction) {
this.introduction = introduction;
}
public String getNotification() {
return notification;
}
public void setNotification(String notification) {
this.notification = notification;
}
public String getFaceUrl() {
return faceUrl;
}
public void setFaceUrl(String faceUrl) {
this.faceUrl = faceUrl;
}
public Integer getMaxMemberCount() {
return maxMemberCount;
}
public void setMaxMemberCount(Integer maxMemberCount) {
this.maxMemberCount = maxMemberCount;
}
public String getApplyJoinOption() {
return applyJoinOption;
}
public void setApplyJoinOption(String applyJoinOption) {
this.applyJoinOption = applyJoinOption;
}
public List<Map<String, Object>> getAppDefinedData() {
return appDefinedData;
}
public void setAppDefinedData(List<Map<String, Object>> appDefinedData) {
this.appDefinedData = appDefinedData;
}
public List<MemberProfile> getMemberList() {
return memberList;
}
public void setMemberList(List<MemberProfile> memberList) {
this.memberList = memberList;
}
public List<Map<String, Object>> getAppMemberDefinedData() {
return appMemberDefinedData;
}
public void setAppMemberDefinedData(List<Map<String, Object>> appMemberDefinedData) {
this.appMemberDefinedData = appMemberDefinedData;
}
}
package com.qcloud.im.model.request;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
/**
* @author bingo
* @since 2021/8/1 11:33
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class GetGroupInfoRequest extends GenericRequest {
@JsonProperty("GroupIdList")
private List<String> groupIdList;
@JsonProperty("ResponseFilter")
private ResponseFilter responseFilter;
public List<String> getGroupIdList() {
return groupIdList;
}
public void setGroupIdList(List<String> groupIdList) {
this.groupIdList = groupIdList;
}
public ResponseFilter getResponseFilter() {
return responseFilter;
}
public void setResponseFilter(ResponseFilter responseFilter) {
this.responseFilter = responseFilter;
}
}
package com.qcloud.im.model.request;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* @author bingo
* @since 2021/8/1 11:20
*/
public class MemberProfile {
@JsonProperty("Member_Account")
private String memberAccount;
@JsonProperty("Role")
private String role;
@JsonProperty("JoinTime")
private Integer joinTime;
@JsonProperty("MsgSeq")
private Integer msgSeq;
@JsonProperty("MsgFlag")
private String msgFlag;
@JsonProperty("LastSendMsgTime")
private Integer lastSendMsgTime;
@JsonProperty("NameCard")
private String nameCard;
}
package com.qcloud.im.model.request;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
/**
* @author bingo
* @since 2021/8/1 11:35
*/
public class ResponseFilter {
@JsonProperty("GroupBaseInfoFilter")
private List<String> groupBaseInfoFilter;
@JsonProperty("MemberInfoFilter")
private List<String> memberInfoFilter;
@JsonProperty("AppDefinedDataFilter_Group")
private List<String> appDefinedDataFilterGroup;
@JsonProperty("AppDefinedDataFilter_GroupMember")
private List<String> appDefinedDataFilterGroupMember;
public List<String> getGroupBaseInfoFilter() {
return groupBaseInfoFilter;
}
public void setGroupBaseInfoFilter(List<String> groupBaseInfoFilter) {
this.groupBaseInfoFilter = groupBaseInfoFilter;
}
public List<String> getMemberInfoFilter() {
return memberInfoFilter;
}
public void setMemberInfoFilter(List<String> memberInfoFilter) {
this.memberInfoFilter = memberInfoFilter;
}
public List<String> getAppDefinedDataFilterGroup() {
return appDefinedDataFilterGroup;
}
public void setAppDefinedDataFilterGroup(List<String> appDefinedDataFilterGroup) {
this.appDefinedDataFilterGroup = appDefinedDataFilterGroup;
}
public List<String> getAppDefinedDataFilterGroupMember() {
return appDefinedDataFilterGroupMember;
}
public void setAppDefinedDataFilterGroupMember(List<String> appDefinedDataFilterGroupMember) {
this.appDefinedDataFilterGroupMember = appDefinedDataFilterGroupMember;
}
}
package com.qcloud.im.model.response;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* @author bingo
* @since 2021/8/1 11:24
*/
public class CreateGroupResult extends GenericResult {
@JsonProperty("GroupId")
private String groupId;
public String getGroupId() {
return groupId;
}
public void setGroupId(String groupId) {
this.groupId = groupId;
}
@Override
public String toString() {
return "CreateGroupResult{" +
"groupId='" + groupId + '\'' +
'}';
}
}
package com.qcloud.im.model.response;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
/**
* @author bingo
* @since 2021/8/1 11:47
*/
public class GetGroupInfoResult extends GenericResult {
@JsonProperty("GroupInfo")
private List<GroupInfoResultItem> groupInfo;
public List<GroupInfoResultItem> getGroupInfo() {
return groupInfo;
}
public void setGroupInfo(List<GroupInfoResultItem> groupInfo) {
this.groupInfo = groupInfo;
}
@Override
public String toString() {
return "GetGroupInfoResult{" +
"groupInfo=" + groupInfo +
'}';
}
}
package com.qcloud.im.model.response;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* 群基础资料
* https://cloud.tencent.com/document/product/269/1502#.E7.BE.A4.E7.BB.84.E6.95.B0.E6.8D.AE.E7.BB.93.E6.9E.84.E4.BB.8B.E7.BB.8D
*
* @author bingo
* @since 2021/8/1 11:39
*/
public class GroupInfoResultItem {
@JsonProperty("GroupId")
private String groupId;
@JsonProperty("Type")
private String type;
@JsonProperty("Name")
private String name;
@JsonProperty("Introduction")
private String introduction;
@JsonProperty("Notification")
private String notification;
@JsonProperty("FaceUrl")
private String faceUrl;
@JsonProperty("Owner_Account")
private String ownerAccount;
@JsonProperty("CreateTime")
private Integer createTime;
@JsonProperty("InfoSeq")
private Integer infoSeq;
@JsonProperty("LastInfoTime")
private Integer lastInfoTime;
@JsonProperty("LastMsgTime")
private Integer lastMsgTime;
@JsonProperty("NextMsgSeq")
private Integer nextMsgSeq;
@JsonProperty("MemberNum")
private Integer memberNum;
@JsonProperty("MaxMemberNum")
private Integer maxMemberNum;
@JsonProperty("ApplyJoinOption")
private String applyJoinOption;
public String getGroupId() {
return groupId;
}
public void setGroupId(String groupId) {
this.groupId = groupId;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getIntroduction() {
return introduction;
}
public void setIntroduction(String introduction) {
this.introduction = introduction;
}
public String getNotification() {
return notification;
}
public void setNotification(String notification) {
this.notification = notification;
}
public String getFaceUrl() {
return faceUrl;
}
public void setFaceUrl(String faceUrl) {
this.faceUrl = faceUrl;
}
public String getOwnerAccount() {
return ownerAccount;
}
public void setOwnerAccount(String ownerAccount) {
this.ownerAccount = ownerAccount;
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
public Integer getInfoSeq() {
return infoSeq;
}
public void setInfoSeq(Integer infoSeq) {
this.infoSeq = infoSeq;
}
public Integer getLastInfoTime() {
return lastInfoTime;
}
public void setLastInfoTime(Integer lastInfoTime) {
this.lastInfoTime = lastInfoTime;
}
public Integer getLastMsgTime() {
return lastMsgTime;
}
public void setLastMsgTime(Integer lastMsgTime) {
this.lastMsgTime = lastMsgTime;
}
public Integer getNextMsgSeq() {
return nextMsgSeq;
}
public void setNextMsgSeq(Integer nextMsgSeq) {
this.nextMsgSeq = nextMsgSeq;
}
public Integer getMemberNum() {
return memberNum;
}
public void setMemberNum(Integer memberNum) {
this.memberNum = memberNum;
}
public Integer getMaxMemberNum() {
return maxMemberNum;
}
public void setMaxMemberNum(Integer maxMemberNum) {
this.maxMemberNum = maxMemberNum;
}
public String getApplyJoinOption() {
return applyJoinOption;
}
public void setApplyJoinOption(String applyJoinOption) {
this.applyJoinOption = applyJoinOption;
}
@Override
public String toString() {
return "GroupInfoResultItem{" +
"groupId='" + groupId + '\'' +
", type='" + type + '\'' +
", name='" + name + '\'' +
", introduction='" + introduction + '\'' +
", notification='" + notification + '\'' +
", faceUrl='" + faceUrl + '\'' +
", ownerAccount='" + ownerAccount + '\'' +
", createTime=" + createTime +
", infoSeq=" + infoSeq +
", lastInfoTime=" + lastInfoTime +
", lastMsgTime=" + lastMsgTime +
", nextMsgSeq=" + nextMsgSeq +
", memberNum=" + memberNum +
", maxMemberNum=" + maxMemberNum +
", applyJoinOption='" + applyJoinOption + '\'' +
'}';
}
}
package com.qcloud.im;
import com.qcloud.im.model.request.CreateGroupRequest;
import com.qcloud.im.model.request.GetAppidGroupListRequest;
import com.qcloud.im.model.request.GetGroupInfoRequest;
import com.qcloud.im.model.response.CreateGroupResult;
import com.qcloud.im.model.response.GetAppidGroupListResult;
import com.qcloud.im.model.response.GetGroupInfoResult;
import org.junit.Assert;
import org.junit.Test;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.Properties;
/**
......@@ -18,7 +23,7 @@ public class GroupTest {
private static final IMClient client;
static {
InputStream resourceAsStream = AccountTest.class.getClassLoader().getResourceAsStream("app.properties");
InputStream resourceAsStream = GroupTest.class.getClassLoader().getResourceAsStream("app.properties");
try {
properties.load(resourceAsStream);
} catch (IOException e) {
......@@ -40,4 +45,34 @@ public class GroupTest {
System.out.println(result);
Assert.assertEquals(0, (int) result.getErrorCode());
}
@Test
public void testCreateGroup() throws IOException {
CreateGroupRequest request = new CreateGroupRequest();
request.setOwnerAccount("bingo");
request.setType("Public");
request.setGroupId("MyFirstGroup");
request.setName("TestGroup");
request.setIntroduction("This is group Introduction");
request.setNotification("This is group Notification");
request.setFaceUrl("http://this.is.face.url");
request.setMaxMemberCount(5000);
request.setApplyJoinOption("FreeAccess");
// Map<String, Object> map = new HashMap<>();
// map.put("Key", "test1");
// map.put("Value", "test2");
// request.setAppDefinedData(Collections.singletonList(map));
CreateGroupResult result = client.group.createGroup(request);
System.out.println(result);
Assert.assertEquals(0, (int) result.getErrorCode());
}
@Test
public void testGetGroupInfo() throws IOException {
GetGroupInfoRequest request = new GetGroupInfoRequest();
request.setGroupIdList(Collections.singletonList("MyFirstGroup"));
GetGroupInfoResult result = client.group.getGroupInfo(request);
System.out.println(result);
Assert.assertEquals(0, (int) result.getErrorCode());
}
}
......@@ -18,7 +18,7 @@ public class MemberTest {
private static final IMClient client;
static {
InputStream resourceAsStream = AccountTest.class.getClassLoader().getResourceAsStream("app.properties");
InputStream resourceAsStream = MemberTest.class.getClassLoader().getResourceAsStream("app.properties");
try {
properties.load(resourceAsStream);
} catch (IOException e) {
......
......@@ -20,7 +20,7 @@ public class MessageTest {
private static final IMClient client;
static {
InputStream resourceAsStream = AccountTest.class.getClassLoader().getResourceAsStream("app.properties");
InputStream resourceAsStream = MessageTest.class.getClassLoader().getResourceAsStream("app.properties");
try {
properties.load(resourceAsStream);
} catch (IOException e) {
......
......@@ -24,7 +24,7 @@ public class ProfileTest {
private static final IMClient client;
static {
InputStream resourceAsStream = AccountTest.class.getClassLoader().getResourceAsStream("app.properties");
InputStream resourceAsStream = ProfileTest.class.getClassLoader().getResourceAsStream("app.properties");
try {
properties.load(resourceAsStream);
} catch (IOException e) {
......
......@@ -18,7 +18,7 @@ public class SNSTest {
private static final IMClient client;
static {
InputStream resourceAsStream = AccountTest.class.getClassLoader().getResourceAsStream("app.properties");
InputStream resourceAsStream = SNSTest.class.getClassLoader().getResourceAsStream("app.properties");
try {
properties.load(resourceAsStream);
} catch (IOException e) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment