Skip to content

Commit

Permalink
Add Tests for System API (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
maruTA-bis5 authored Jan 22, 2019
1 parent a358af9 commit 494d711
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,26 @@
public class MattermostApiTest {

private static final String APPLICATION = getApplicationUrl();
private static final String INBUCKET_HOST = getInbucketHost();
private static final String INBUCKET_PORT = getInbucketPort();
private MattermostClient client;
private static TestHelper th;

private static String getApplicationUrl() {
String url = System.getenv("MATTERMOST_URL");
return url != null ? url : "http://localhost:8065";
return getEnv("MATTERMOST_URL", "http://localhost:8065");
}

private static String getEnv(String varName, String defaultValue) {
String val = System.getenv(varName);
return val != null ? val : defaultValue;
}

private static String getInbucketHost() {
return getEnv("INBUCKET_HOST", "localhost");
}

private static String getInbucketPort() {
return getEnv("INBUCKET_PORT", "2500");
}

@BeforeAll
Expand Down Expand Up @@ -2683,6 +2697,13 @@ public void testHook_IncomingWebhook_Post() {
// System
@Nested
class SystemApiTest {
@Test
public void databaseRecycle() {
th.logout().loginSystemAdmin();

ApiResponse<Boolean> result = assertNoError(client.databaseRecycle());
assertTrue(result.readEntity());
}

@Test
public void getAnalytics() {
Expand Down Expand Up @@ -2732,6 +2753,50 @@ public void getAnalyticsSpecifiedTeam() {
assertThat(userCountRow.getValue().intValue(), is(1));
}

@Test
public void getOldClientConfig() {
ApiResponse<Map<String, String>> response = assertNoError(client.getOldClientConfig());
Map<String, String> clientConfig = response.readEntity();
assertTrue(clientConfig.containsKey("Version"));
}

@Test
public void getOldClientLicense() {
ApiResponse<Map<String, String>> response = assertNoError(client.getOldClientLicense());
Map<String, String> clientLicense = response.readEntity();
assertTrue(clientLicense.containsKey("IsLicensed"));
}

@Test
public void ping() {
ApiResponse<Boolean> result = assertNoError(client.getPing());
assertTrue(result.readEntity());
}

@Test
public void invalidateCache() {
th.logout().loginSystemAdmin();

ApiResponse<Boolean> result = assertNoError(client.invalidateCaches());
assertTrue(result.readEntity());
}

@Test
public void reloadConfig() {
th.logout().loginSystemAdmin();

ApiResponse<Boolean> result = assertNoError(client.reloadConfig());
assertTrue(result.readEntity());
}

@Test
public void testEmail() {
th.useSmtp(INBUCKET_HOST, INBUCKET_PORT).logout().loginSystemAdmin();

ApiResponse<Boolean> result = assertNoError(client.testEmail());
assertTrue(result.readEntity());
}

@Test
public void uploadLicenseFile() throws IOException {
Path licenseFile = Files.createTempFile(null, null); // invalid contents
Expand All @@ -2753,5 +2818,4 @@ public void removeLicense() {
assertNoError(client.removeLicense());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import net.bis5.mattermost.model.Team;
import net.bis5.mattermost.model.TeamType;
import net.bis5.mattermost.model.User;
import net.bis5.mattermost.model.config.consts.ConnectionSecurity;
import org.apache.commons.lang3.RandomStringUtils;

/**
Expand Down Expand Up @@ -71,17 +72,25 @@ public TestHelper setup() {
config.getServiceSettings().setEnableCommands(true);
config.getServiceSettings().setEnableEmailInvitations(true);
config.getServiceSettings().setEnableUserAccessTokens(true);
// TODO un-comment these lines when Dockerfile setup.
// config.getEmailSettings().setSendEmailNotifications(true);
// config.getEmailSettings().setSmtpServer("localhost");
// config.getEmailSettings().setSmtpPort("9000");
// config.getEmailSettings().setFeedbackEmail("[email protected]");
config.getTeamSettings().setEnableOpenServer(true);
config = checkNoError(client.updateConfig(config)).readEntity();
client.logout();
return this;
}

public TestHelper useSmtp(String inbucketHost, String inbucketPort) {
logout().loginSystemAdmin();
Config config = client.getConfig().readEntity();
config.getEmailSettings().setSendEmailNotifications(true);
config.getEmailSettings().setSmtpServer(inbucketHost);
config.getEmailSettings().setSmtpPort(inbucketPort);
config.getEmailSettings().setFeedbackEmail("[email protected]");
config.getEmailSettings().setConnectionSecurity(ConnectionSecurity.NONE);
config = checkNoError(client.updateConfig(config)).readEntity();
logout().loginBasic();
return this;
}

public TestHelper initBasic() {
teamAdminUser = createUser();
loginTeamAdmin();
Expand Down

0 comments on commit 494d711

Please sign in to comment.