Skip to content

Commit

Permalink
tidy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
James Robertson authored and James Robertson committed Oct 31, 2022
1 parent 91ec311 commit 6d24a2d
Show file tree
Hide file tree
Showing 15 changed files with 202 additions and 83 deletions.
2 changes: 2 additions & 0 deletions samples/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 24 additions & 9 deletions samples/announcements/src/main/java/Sendbird.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,31 @@ public SendBirdGroupChannel viewChannelByUrl(String channelUrl){
return null;
}

public GcListChannelsResponse listChannels(){
public OcDeleteChannelByUrl200Response deleteChannelByUrl(String channelUrl){

try {
OcDeleteChannelByUrl200Response result = apiInstance.gcDeleteChannelByUrl(apiToken, channelUrl);
return result;
} catch (ApiException e) {
System.err.println("Exception when calling GroupChannelApi#gcViewChannelByUrl");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}

return null;
}

public GcListChannelsResponse listChannels(String nameStartswith){
String token = null; // String |
Integer limit = 10; // Integer |
String distinctMode = "distinct"; // String |
String distinctMode = "all"; // String |
String publicMode = null; // String |
String superMode = null; // String |
Integer createdAfter = null; // Integer |
Integer createdBefore = null; // Integer |
Boolean showEmpty = false; // Boolean |
Boolean showEmpty = true; // Boolean |
Boolean showMember = true; // Boolean |
Boolean showDeliveryReceipt = false; // Boolean |
Boolean showReadReceipt = true; // Boolean |
Expand All @@ -58,8 +74,8 @@ public GcListChannelsResponse listChannels(){
String customTypeStartswith = null; // String |
String channelUrls = null; // String |
String name = null; // String |
// String nameStartswith = null; // String |
String nameContains = null; // String |
String nameStartswith = null; // String |
String membersExactlyIn = null; // String |
String membersIncludeIn = null; // String |
String queryType = null; // String |
Expand Down Expand Up @@ -97,8 +113,7 @@ public GcListChannelsResponse listChannels(){

public SendBirdGroupChannel createChannel(List userIds){
GcCreateChannelData gcCreateChannelData = new GcCreateChannelData();
gcCreateChannelData.name("JAVA-SDK-GROUP");

gcCreateChannelData.name("SB::test-gc::Java::e2e::"+UUID.randomUUID().toString());

gcCreateChannelData.userIds(userIds);
gcCreateChannelData.isDistinct(false);
Expand Down Expand Up @@ -174,7 +189,7 @@ public User(ApiClient defaultClient){
public SendBirdUser createUser(){
CreateUserData createUserData = new CreateUserData(); // CreateUserData |
createUserData.userId(UUID.randomUUID().toString());
createUserData.nickname("nickname");
createUserData.nickname("SB::test-user::Java::e2e::"+UUID.randomUUID().toString());
try {
SendBirdUser result = apiInstance.createUser(apiToken, createUserData);
return result;
Expand Down Expand Up @@ -218,7 +233,7 @@ public SendBirdUser deleteUserById(String userId){
return null;
}

public ListUsersResponse listUsers(){
public ListUsersResponse listUsers(String nicknameStartswith){

try {
String token = null;
Expand All @@ -227,7 +242,7 @@ public ListUsersResponse listUsers(){
Boolean showBot = true;
String userIds = null;
String nickname = null;
String nicknameStartswith = null;
// String nicknameStartswith = nicknameStartswith;
String metadatakey = null;
String metadatavaluesIn = null;
ListUsersResponse result = apiInstance.listUsers(apiToken, token, limit, activeMode, showBot, userIds, nickname, nicknameStartswith, metadatakey, metadatavaluesIn);
Expand Down
38 changes: 34 additions & 4 deletions samples/announcements/src/test/java/AnnouncementsTest.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,47 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.openapitools.client.model.SendBirdUser;
import org.junit.jupiter.api.AfterAll;
import org.openapitools.client.model.*;
import org.sendbird.client.ApiClient;
import org.sendbird.client.Configuration;

import java.math.BigDecimal;

import static org.junit.jupiter.api.Assertions.*;

class AnnouncementsTest {


@Test
@DisplayName("send announcement")
void testSendAnnouncement() {
Announcements announcements = new Announcements();
announcements.sendAnnouncement();

}


@AfterAll
public static void tearDown() {
System.out.println("AbstractBaseTest.tearDown");
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("https://api-"+Config.appId+".sendbird.com");
User user = new User(defaultClient);
GroupChannel groupChannel = new GroupChannel(defaultClient);

ListUsersResponse users = user.listUsers("SB::test-user::Java::e2e::");
for (int i = 0; i < users.getUsers().size(); i++) {
String userIdToDelete = users.getUsers().get(i).getUserId();
user.deleteUserById(userIdToDelete);
}

GcListChannelsResponse groupChannelResponse = groupChannel.listChannels("SB::test-gc::Java::e2e::");
System.out.println(groupChannelResponse);

for (int i = 0; i < groupChannelResponse.getChannels().size(); i++) {
String channelUrlToDelete = groupChannelResponse.getChannels().get(i).getChannelUrl();
groupChannel.deleteChannelByUrl(channelUrlToDelete);
}

}



}
1 change: 1 addition & 0 deletions samples/authentication/src/main/java/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ public class Config {
public static String appId = "";

}

50 changes: 3 additions & 47 deletions samples/authentication/src/main/java/Sendbird.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public User(ApiClient defaultClient){
public SendBirdUser createUser(){
CreateUserData createUserData = new CreateUserData(); // CreateUserData |
createUserData.userId(UUID.randomUUID().toString());
createUserData.nickname("nickname");
createUserData.nickname("SB::test-user::Java::e2e::"+UUID.randomUUID().toString());
try {
SendBirdUser result = apiInstance.createUser(apiToken, createUserData);
return result;
Expand Down Expand Up @@ -65,7 +65,7 @@ public SendBirdUser deleteUserById(String userId){
return null;
}

public ListUsersResponse listUsers(){
public ListUsersResponse listUsers(String nicknameStartswith){

try {
String token = null;
Expand All @@ -74,7 +74,7 @@ public ListUsersResponse listUsers(){
Boolean showBot = true;
String userIds = null;
String nickname = null;
String nicknameStartswith = null;
// String nicknameStartswith = null;
String metadatakey = null;
String metadatavaluesIn = null;
ListUsersResponse result = apiInstance.listUsers(apiToken, token, limit, activeMode, showBot, userIds, nickname, nicknameStartswith, metadatakey, metadatavaluesIn);
Expand Down Expand Up @@ -124,47 +124,3 @@ public AddRegistrationOrDeviceTokenResponse addRegistrationOrDeviceToken(String
return null;
}
}

class Announcement {
ApiClient defaultClient;
String apiToken;
AnnouncementApi apiInstance;

public Announcement(ApiClient defaultClient) {
System.out.println("constructor");
apiInstance = new AnnouncementApi(defaultClient);
apiToken = Config.apiToken;
}

public ScheduleAnnouncementResponse scheduleAnnouncement(String message, String type, String userId, String content, String targetAt, List<String> targetList, String channelType){
ScheduleAnnouncementData scheduleAnnouncementData = new ScheduleAnnouncementData();
ScheduleAnnouncementDataMessage scheduleAnnouncementDataMessage = new ScheduleAnnouncementDataMessage();

scheduleAnnouncementDataMessage.type(type);
scheduleAnnouncementDataMessage.userId(userId);
scheduleAnnouncementDataMessage.content(content);


scheduleAnnouncementData.message(scheduleAnnouncementDataMessage);
scheduleAnnouncementData.messageType(type);
scheduleAnnouncementData.userId(userId);
scheduleAnnouncementData.content(content);
scheduleAnnouncementData.targetAt(targetAt);
scheduleAnnouncementData.targetList(targetList);
scheduleAnnouncementData.targetChannelType(channelType);

System.out.println(scheduleAnnouncementData);

try {
ScheduleAnnouncementResponse result = apiInstance.scheduleAnnouncement(apiToken, scheduleAnnouncementData);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling MessageApi#scheduleAnnouncement");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
return null;
}
}
21 changes: 20 additions & 1 deletion samples/authentication/src/test/java/AuthenticationTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.openapitools.client.model.SendBirdUser;
import org.openapitools.client.model.*;
import org.sendbird.client.ApiClient;
import org.sendbird.client.Configuration;

import java.math.BigDecimal;

Expand All @@ -15,5 +18,21 @@ void testGenerateSessionToken() {
auth.generateSessionToken();
}

@AfterAll
public static void tearDown() {
System.out.println("AbstractBaseTest.tearDown");
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("https://api-"+Config.appId+".sendbird.com");
User user = new User(defaultClient);

ListUsersResponse users = user.listUsers("SB::test-user::Java::e2e::");

for (int i = 0; i < users.getUsers().size(); i++) {
String userIdToDelete = users.getUsers().get(i).getUserId();
user.deleteUserById(userIdToDelete);
}

}


}
32 changes: 24 additions & 8 deletions samples/message-count/src/main/java/Sendbird.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ public GroupChannel(ApiClient defaultClient){

}

public OcDeleteChannelByUrl200Response deleteChannelByUrl(String channelUrl){

try {
OcDeleteChannelByUrl200Response result = apiInstance.gcDeleteChannelByUrl(apiToken, channelUrl);
return result;
} catch (ApiException e) {
System.err.println("Exception when calling GroupChannelApi#gcViewChannelByUrl");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}

return null;
}

public SendBirdGroupChannel viewChannelByUrl(String channelUrl){
Boolean showDeliveryReceipt = false; // Boolean |
Boolean showReadReceipt = false; // Boolean |
Expand All @@ -38,15 +54,15 @@ public SendBirdGroupChannel viewChannelByUrl(String channelUrl){
return null;
}

public GcListChannelsResponse listChannels(){
public GcListChannelsResponse listChannels(String nameStartswith){
String token = null; // String |
Integer limit = 10; // Integer |
String distinctMode = "distinct"; // String |
String distinctMode = "all"; // String |
String publicMode = null; // String |
String superMode = null; // String |
Integer createdAfter = null; // Integer |
Integer createdBefore = null; // Integer |
Boolean showEmpty = false; // Boolean |
Boolean showEmpty = true; // Boolean |
Boolean showMember = true; // Boolean |
Boolean showDeliveryReceipt = false; // Boolean |
Boolean showReadReceipt = true; // Boolean |
Expand All @@ -59,7 +75,7 @@ public GcListChannelsResponse listChannels(){
String channelUrls = null; // String |
String name = null; // String |
String nameContains = null; // String |
String nameStartswith = null; // String |
// String nameStartswith = null; // String |
String membersExactlyIn = null; // String |
String membersIncludeIn = null; // String |
String queryType = null; // String |
Expand Down Expand Up @@ -97,7 +113,7 @@ public GcListChannelsResponse listChannels(){

public SendBirdGroupChannel createChannel(List userIds){
GcCreateChannelData gcCreateChannelData = new GcCreateChannelData();
gcCreateChannelData.name("JAVA-SDK-GROUP");
gcCreateChannelData.name("SB::test-gc::Java::e2e::"+UUID.randomUUID().toString());


gcCreateChannelData.userIds(userIds);
Expand Down Expand Up @@ -175,7 +191,7 @@ public User(ApiClient defaultClient){
public SendBirdUser createUser(){
CreateUserData createUserData = new CreateUserData(); // CreateUserData |
createUserData.userId(UUID.randomUUID().toString());
createUserData.nickname("nickname");
createUserData.nickname("SB::test-user::Java::e2e::"+UUID.randomUUID().toString());
try {
SendBirdUser result = apiInstance.createUser(apiToken, createUserData);
return result;
Expand Down Expand Up @@ -219,7 +235,7 @@ public SendBirdUser deleteUserById(String userId){
return null;
}

public ListUsersResponse listUsers(){
public ListUsersResponse listUsers(String nicknameStartswith){

try {
String token = null;
Expand All @@ -228,7 +244,7 @@ public ListUsersResponse listUsers(){
Boolean showBot = true;
String userIds = null;
String nickname = null;
String nicknameStartswith = null;
// String nicknameStartswith = null;
String metadatakey = null;
String metadatavaluesIn = null;
ListUsersResponse result = apiInstance.listUsers(apiToken, token, limit, activeMode, showBot, userIds, nickname, nicknameStartswith, metadatakey, metadatavaluesIn);
Expand Down
29 changes: 29 additions & 0 deletions samples/message-count/src/test/java/MessageCountTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.openapitools.client.model.GcListChannelsResponse;
import org.openapitools.client.model.ListUsersResponse;
import org.openapitools.client.model.SendBirdUser;
import org.sendbird.client.ApiClient;
import org.sendbird.client.Configuration;

import java.math.BigDecimal;

Expand All @@ -17,4 +22,28 @@ void testCountUnreadMessages() {

}

@AfterAll
public static void tearDown() {
System.out.println("AbstractBaseTest.tearDown");
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("https://api-"+Config.appId+".sendbird.com");
User user = new User(defaultClient);
GroupChannel groupChannel = new GroupChannel(defaultClient);

ListUsersResponse users = user.listUsers("SB::test-user::Java::e2e::");
for (int i = 0; i < users.getUsers().size(); i++) {
String userIdToDelete = users.getUsers().get(i).getUserId();
user.deleteUserById(userIdToDelete);
}

GcListChannelsResponse groupChannelResponse = groupChannel.listChannels("SB::test-gc::Java::e2e::");
System.out.println(groupChannelResponse);

for (int i = 0; i < groupChannelResponse.getChannels().size(); i++) {
String channelUrlToDelete = groupChannelResponse.getChannels().get(i).getChannelUrl();
groupChannel.deleteChannelByUrl(channelUrlToDelete);
}

}

}
Loading

0 comments on commit 6d24a2d

Please sign in to comment.