diff --git a/mattermost4j-core/src/test/java/net/bis5/mattermost/client4/MattermostApiTest.java b/mattermost4j-core/src/test/java/net/bis5/mattermost/client4/MattermostApiTest.java index 8440d7d4..4425f2d9 100644 --- a/mattermost4j-core/src/test/java/net/bis5/mattermost/client4/MattermostApiTest.java +++ b/mattermost4j-core/src/test/java/net/bis5/mattermost/client4/MattermostApiTest.java @@ -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 @@ -2683,6 +2697,13 @@ public void testHook_IncomingWebhook_Post() { // System @Nested class SystemApiTest { + @Test + public void databaseRecycle() { + th.logout().loginSystemAdmin(); + + ApiResponse result = assertNoError(client.databaseRecycle()); + assertTrue(result.readEntity()); + } @Test public void getAnalytics() { @@ -2732,6 +2753,50 @@ public void getAnalyticsSpecifiedTeam() { assertThat(userCountRow.getValue().intValue(), is(1)); } + @Test + public void getOldClientConfig() { + ApiResponse> response = assertNoError(client.getOldClientConfig()); + Map clientConfig = response.readEntity(); + assertTrue(clientConfig.containsKey("Version")); + } + + @Test + public void getOldClientLicense() { + ApiResponse> response = assertNoError(client.getOldClientLicense()); + Map clientLicense = response.readEntity(); + assertTrue(clientLicense.containsKey("IsLicensed")); + } + + @Test + public void ping() { + ApiResponse result = assertNoError(client.getPing()); + assertTrue(result.readEntity()); + } + + @Test + public void invalidateCache() { + th.logout().loginSystemAdmin(); + + ApiResponse result = assertNoError(client.invalidateCaches()); + assertTrue(result.readEntity()); + } + + @Test + public void reloadConfig() { + th.logout().loginSystemAdmin(); + + ApiResponse result = assertNoError(client.reloadConfig()); + assertTrue(result.readEntity()); + } + + @Test + public void testEmail() { + th.useSmtp(INBUCKET_HOST, INBUCKET_PORT).logout().loginSystemAdmin(); + + ApiResponse result = assertNoError(client.testEmail()); + assertTrue(result.readEntity()); + } + @Test public void uploadLicenseFile() throws IOException { Path licenseFile = Files.createTempFile(null, null); // invalid contents @@ -2753,5 +2818,4 @@ public void removeLicense() { assertNoError(client.removeLicense()); } } - } diff --git a/mattermost4j-core/src/test/java/net/bis5/mattermost/client4/TestHelper.java b/mattermost4j-core/src/test/java/net/bis5/mattermost/client4/TestHelper.java index 682387f7..d8508e37 100644 --- a/mattermost4j-core/src/test/java/net/bis5/mattermost/client4/TestHelper.java +++ b/mattermost4j-core/src/test/java/net/bis5/mattermost/client4/TestHelper.java @@ -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; /** @@ -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("test@example.com"); 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("test@example.com"); + config.getEmailSettings().setConnectionSecurity(ConnectionSecurity.NONE); + config = checkNoError(client.updateConfig(config)).readEntity(); + logout().loginBasic(); + return this; + } + public TestHelper initBasic() { teamAdminUser = createUser(); loginTeamAdmin();