Skip to content

Commit

Permalink
feat: add officialAccount test
Browse files Browse the repository at this point in the history
  • Loading branch information
hongyiheng committed Jan 10, 2024
1 parent ea57b1e commit 3753dd4
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 6 deletions.
16 changes: 13 additions & 3 deletions src/main/java/io/github/doocs/im/ImClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@

import io.github.doocs.im.constant.ContentType;
import io.github.doocs.im.constant.Domain;
import io.github.doocs.im.core.*;
import io.github.doocs.im.core.Account;
import io.github.doocs.im.core.Audit;
import io.github.doocs.im.core.Group;
import io.github.doocs.im.core.Member;
import io.github.doocs.im.core.Message;
import io.github.doocs.im.core.OfficialAccount;
import io.github.doocs.im.core.Operation;
import io.github.doocs.im.core.Profile;
import io.github.doocs.im.core.RecentContact;
import io.github.doocs.im.core.Robot;
import io.github.doocs.im.core.Sns;
import io.github.doocs.im.util.RandomUtil;
import io.github.doocs.im.util.SigUtil;

Expand Down Expand Up @@ -39,7 +49,7 @@ public class ImClient {
public final RecentContact recentContact;
public final Robot robot;
public final Audit audit;
private final Official official;
public final OfficialAccount officialAccount;

public static ImClient getInstance(long sdkAppId, String userId, String key) {
return new ImClient(sdkAppId, userId, key);
Expand Down Expand Up @@ -96,7 +106,7 @@ public ImClient(long sdkAppId, String userId, String key, String domain, ClientC
recentContact = new RecentContact(this);
robot = new Robot(this);
audit = new Audit(this);
official = new Official(this);
officialAccount = new OfficialAccount(this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* @author hyh
* @since 2024/01/09 21:50
*/
public class Official {
public class OfficialAccount {
/**
* 公众号服务名
*/
Expand All @@ -32,7 +32,7 @@ public class Official {

private final ImClient imClient;

public Official(ImClient imClient) {
public OfficialAccount(ImClient imClient) {
this.imClient = imClient;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,70 @@ private CreateOfficialAccountRequest(Builder builder) {
this.customString = builder.customString;
}

public String getOwnerAccount() {
return ownerAccount;
}

public void setOwnerAccount(String ownerAccount) {
this.ownerAccount = ownerAccount;
}

public String getOfficialAccountUserID() {
return officialAccountUserID;
}

public void setOfficialAccountUserID(String officialAccountUserID) {
this.officialAccountUserID = officialAccountUserID;
}

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 getFaceUrl() {
return faceUrl;
}

public void setFaceUrl(String faceUrl) {
this.faceUrl = faceUrl;
}

public Integer getMaxSubscriberNum() {
return maxSubscriberNum;
}

public void setMaxSubscriberNum(Integer maxSubscriberNum) {
this.maxSubscriberNum = maxSubscriberNum;
}

public String getOrganization() {
return organization;
}

public void setOrganization(String organization) {
this.organization = organization;
}

public String getCustomString() {
return customString;
}

public void setCustomString(String customString) {
this.customString = customString;
}

public static Builder builder() {
return new Builder();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,18 @@ private DestroyOfficialAccountRequest(Builder builder) {
this.officialAccount = builder.officialAccount;
}

public String getOfficialAccount() {
return officialAccount;
}

public void setOfficialAccount(String officialAccount) {
this.officialAccount = officialAccount;
}

public static Builder builder() {
return new Builder();
}


public static final class Builder {
private String officialAccount;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,62 @@ private ModifyOfficialAccountBaseInfoRequest(Builder builder) {
this.maxSubscriberNum = builder.maxSubscriberNum;
}

public String getOfficialAccount() {
return officialAccount;
}

public void setOfficialAccount(String officialAccount) {
this.officialAccount = officialAccount;
}

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 getFaceUrl() {
return faceUrl;
}

public void setFaceUrl(String faceUrl) {
this.faceUrl = faceUrl;
}

public String getOrganization() {
return organization;
}

public void setOrganization(String organization) {
this.organization = organization;
}

public String getCustomString() {
return customString;
}

public void setCustomString(String customString) {
this.customString = customString;
}

public Integer getMaxSubscriberNum() {
return maxSubscriberNum;
}

public void setMaxSubscriberNum(Integer maxSubscriberNum) {
this.maxSubscriberNum = maxSubscriberNum;
}

public static Builder builder() {
return new Builder();
}
Expand Down
62 changes: 62 additions & 0 deletions src/test/java/io/github/doocs/im/core/OfficialAccountTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package io.github.doocs.im.core;

import io.github.doocs.im.ClientFactory;
import io.github.doocs.im.ImClient;
import io.github.doocs.im.constant.ActionStatus;
import io.github.doocs.im.model.request.CreateOfficialAccountRequest;
import io.github.doocs.im.model.request.DestroyOfficialAccountRequest;
import io.github.doocs.im.model.request.ModifyOfficialAccountBaseInfoRequest;
import io.github.doocs.im.model.response.CreateOfficialAccountResult;
import io.github.doocs.im.model.response.DestroyOfficialAccountResult;
import io.github.doocs.im.model.response.ModifyOfficialAccountBaseInfoResult;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.io.IOException;

/**
* 公众号测试类 {@link OfficialAccount}
*
* @author hyh
* @since 2024/1/10 10:00
*/
class OfficialAccountTest {
private static ImClient client;

@BeforeAll
static void setup() {
client = ClientFactory.getInstance();
Assertions.assertNotNull(client, "client is null");
}

@Test
void testCreateOfficialAccount() throws IOException {
CreateOfficialAccountRequest request = new CreateOfficialAccountRequest();
request.setOwnerAccount("test");
request.setName("test_official_account");
CreateOfficialAccountResult result = client.officialAccount.createOfficialAccount(request);
System.out.println(result);
Assertions.assertEquals(ActionStatus.OK, result.getActionStatus());
}

@Test
void tesDestroyOfficialAccount() throws IOException {
DestroyOfficialAccountRequest request = new DestroyOfficialAccountRequest();
request.setOfficialAccount("test_official_account_id");
DestroyOfficialAccountResult result = client.officialAccount.destroyOfficialAccount(request);
System.out.println(result);
Assertions.assertEquals(ActionStatus.OK, result.getActionStatus());
}

@Test
void testModifyOfficialAccountBaseInfo () throws IOException {
ModifyOfficialAccountBaseInfoRequest request = new ModifyOfficialAccountBaseInfoRequest();
request.setOfficialAccount("test_official_account_id");
request.setName("test_official_account2");
ModifyOfficialAccountBaseInfoResult result = client.officialAccount.modifyOfficialAccountBaseInfo(request);
System.out.println(result);
Assertions.assertEquals(ActionStatus.OK, result.getActionStatus());
}

}

0 comments on commit 3753dd4

Please sign in to comment.