diff --git a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/PluginRestTestCase.kt b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/PluginRestTestCase.kt index 19e2f61b..ad10e9ad 100644 --- a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/PluginRestTestCase.kt +++ b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/PluginRestTestCase.kt @@ -287,12 +287,59 @@ abstract class PluginRestTestCase : OpenSearchRestTestCase() { RestStatus.OK.status, client ) + refreshAllIndices() val configId = createResponse.get("config_id").asString Assert.assertNotNull(configId) Thread.sleep(100) return configId } + fun createConfigWithRequestJsonString( + createRequestJsonString: String, + client: RestClient = client() + ): String { + val createResponse = executeRequest( + RestRequest.Method.POST.name, + "${NotificationPlugin.PLUGIN_BASE_URI}/configs", + createRequestJsonString, + RestStatus.OK.status, + client + ) + refreshAllIndices() + Thread.sleep(100) + return createResponse.get("config_id").asString + } + + fun deleteConfig( + configId: String, + client: RestClient = client() + ): JsonObject { + val deleteResponse = executeRequest( + RestRequest.Method.DELETE.name, + "${NotificationPlugin.PLUGIN_BASE_URI}/configs/$configId", + "", + RestStatus.OK.status, + client + ) + refreshAllIndices() + return deleteResponse + } + + fun deleteConfigs( + configIds: Set, + client: RestClient = client() + ): JsonObject { + val deleteResponse = executeRequest( + RestRequest.Method.DELETE.name, + "${NotificationPlugin.PLUGIN_BASE_URI}/configs?config_id_list=${configIds.joinToString(separator = ",")}", + "", + RestStatus.OK.status, + client + ) + refreshAllIndices() + return deleteResponse + } + @After open fun wipeAllSettings() { wipeAllClusterSettings() diff --git a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/SecurityNotificationIT.kt b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/SecurityNotificationIT.kt index 47ab2b5e..ecda9fc3 100644 --- a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/SecurityNotificationIT.kt +++ b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/SecurityNotificationIT.kt @@ -74,14 +74,7 @@ class SecurityNotificationIT : PluginRestTestCase() { } """.trimIndent() try { - val createResponse = executeRequest( - RestRequest.Method.POST.name, - "${NotificationPlugin.PLUGIN_BASE_URI}/configs", - createRequestJsonString, - RestStatus.OK.status, - userClient!! - ) - val configId = createResponse.get("config_id").asString + val configId = createConfigWithRequestJsonString(createRequestJsonString, userClient!!) Assert.assertNotNull(configId) Thread.sleep(1000) @@ -159,13 +152,7 @@ class SecurityNotificationIT : PluginRestTestCase() { } } """.trimIndent() - val createResponse = executeRequest( - RestRequest.Method.POST.name, - "${NotificationPlugin.PLUGIN_BASE_URI}/configs", - createRequestJsonString, - RestStatus.OK.status - ) - val configId = createResponse.get("config_id").asString + val configId = createConfigWithRequestJsonString(createRequestJsonString) Assert.assertNotNull(configId) Thread.sleep(1000) @@ -278,13 +265,7 @@ class SecurityNotificationIT : PluginRestTestCase() { } } """.trimIndent() - val createResponse = executeRequest( - RestRequest.Method.POST.name, - "${NotificationPlugin.PLUGIN_BASE_URI}/configs", - createRequestJsonString, - RestStatus.OK.status - ) - val configId = createResponse.get("config_id").asString + val configId = createConfigWithRequestJsonString(createRequestJsonString) Assert.assertNotNull(configId) Thread.sleep(1000) @@ -340,24 +321,12 @@ class SecurityNotificationIT : PluginRestTestCase() { } } """.trimIndent() - val createResponse = executeRequest( - RestRequest.Method.POST.name, - "${NotificationPlugin.PLUGIN_BASE_URI}/configs", - createRequestJsonString, - RestStatus.OK.status - ) - val configId = createResponse.get("config_id").asString + val configId = createConfigWithRequestJsonString(createRequestJsonString) Assert.assertNotNull(configId) Thread.sleep(1000) // Delete Slack notification config - executeRequest( - RestRequest.Method.DELETE.name, - "${NotificationPlugin.PLUGIN_BASE_URI}/configs/$configId", - "", - RestStatus.OK.status, - userClient!! - ) + deleteConfig(configId, userClient!!) // Should not be able to find config executeRequest( @@ -477,13 +446,7 @@ class SecurityNotificationIT : PluginRestTestCase() { } } """.trimIndent() - val createResponse = executeRequest( - RestRequest.Method.POST.name, - "${NotificationPlugin.PLUGIN_BASE_URI}/configs", - createRequestJsonString, - RestStatus.OK.status - ) - val configId = createResponse.get("config_id").asString + val configId = createConfigWithRequestJsonString(createRequestJsonString) Assert.assertNotNull(configId) Thread.sleep(1000) @@ -521,13 +484,7 @@ class SecurityNotificationIT : PluginRestTestCase() { } } """.trimIndent() - val createResponse = executeRequest( - RestRequest.Method.POST.name, - "${NotificationPlugin.PLUGIN_BASE_URI}/configs", - createRequestJsonString, - RestStatus.OK.status - ) - val configId = createResponse.get("config_id").asString + val configId = createConfigWithRequestJsonString(createRequestJsonString) Assert.assertNotNull(configId) Thread.sleep(1000) diff --git a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/bwc/NotificationsBackwardsCompatibilityIT.kt b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/bwc/NotificationsBackwardsCompatibilityIT.kt index f1976c93..76f0e183 100644 --- a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/bwc/NotificationsBackwardsCompatibilityIT.kt +++ b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/bwc/NotificationsBackwardsCompatibilityIT.kt @@ -104,13 +104,7 @@ class NotificationsBackwardsCompatibilityIT : PluginRestTestCase() { } } """.trimIndent() - val createResponse = executeRequest( - RestRequest.Method.POST.name, - "${NotificationPlugin.PLUGIN_BASE_URI}/configs", - requestJsonString, - RestStatus.OK.status - ) - val createdConfigId = createResponse.get("config_id").asString + val createdConfigId = createConfigWithRequestJsonString(requestJsonString) assertNotNull(createdConfigId) Thread.sleep(100) } diff --git a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/ChimeNotificationConfigCrudIT.kt b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/ChimeNotificationConfigCrudIT.kt index 6fac691b..f708a6d2 100644 --- a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/ChimeNotificationConfigCrudIT.kt +++ b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/ChimeNotificationConfigCrudIT.kt @@ -39,13 +39,7 @@ class ChimeNotificationConfigCrudIT : PluginRestTestCase() { } } """.trimIndent() - val createResponse = executeRequest( - RestRequest.Method.POST.name, - "$PLUGIN_BASE_URI/configs", - createRequestJsonString, - RestStatus.OK.status - ) - val configId = createResponse.get("config_id").asString + val configId = createConfigWithRequestJsonString(createRequestJsonString) Assert.assertNotNull(configId) Thread.sleep(1000) @@ -114,12 +108,7 @@ class ChimeNotificationConfigCrudIT : PluginRestTestCase() { Thread.sleep(100) // Delete chime notification config - val deleteResponse = executeRequest( - RestRequest.Method.DELETE.name, - "$PLUGIN_BASE_URI/configs/$configId", - "", - RestStatus.OK.status - ) + val deleteResponse = deleteConfig(configId) Assert.assertEquals("OK", deleteResponse.get("delete_response_list").asJsonObject.get(configId).asString) Thread.sleep(1000) @@ -189,13 +178,7 @@ class ChimeNotificationConfigCrudIT : PluginRestTestCase() { } } """.trimIndent() - val createResponse = executeRequest( - RestRequest.Method.POST.name, - "$PLUGIN_BASE_URI/configs", - createRequestJsonString, - RestStatus.OK.status - ) - val configId = createResponse.get("config_id").asString + val configId = createConfigWithRequestJsonString(createRequestJsonString) Assert.assertNotNull(configId) Thread.sleep(1000) @@ -283,13 +266,7 @@ class ChimeNotificationConfigCrudIT : PluginRestTestCase() { } } """.trimIndent() - val createResponse = executeRequest( - RestRequest.Method.POST.name, - "$PLUGIN_BASE_URI/configs", - createRequestJsonString, - RestStatus.OK.status - ) - val configId = createResponse.get("config_id").asString + val configId = createConfigWithRequestJsonString(createRequestJsonString) Assert.assertNotNull(configId) Thread.sleep(1000) diff --git a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/CreateNotificationConfigIT.kt b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/CreateNotificationConfigIT.kt index a8fe39fc..2d86dfe6 100644 --- a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/CreateNotificationConfigIT.kt +++ b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/CreateNotificationConfigIT.kt @@ -44,13 +44,7 @@ class CreateNotificationConfigIT : PluginRestTestCase() { } } """.trimIndent() - val createResponse = executeRequest( - RestRequest.Method.POST.name, - "$PLUGIN_BASE_URI/configs", - createRequestJsonString, - RestStatus.OK.status - ) - val configId = createResponse.get("config_id").asString + val configId = createConfigWithRequestJsonString(createRequestJsonString) Assert.assertNotNull(configId) Thread.sleep(1000) @@ -90,13 +84,8 @@ class CreateNotificationConfigIT : PluginRestTestCase() { } } """.trimIndent() - val createResponse = executeRequest( - RestRequest.Method.POST.name, - "$PLUGIN_BASE_URI/configs", - createRequestJsonString, - RestStatus.OK.status - ) - Assert.assertEquals(configId, createResponse.get("config_id").asString) + val createdConfigId = createConfigWithRequestJsonString(createRequestJsonString) + Assert.assertEquals(configId, createdConfigId) Thread.sleep(1000) // Get chime notification config diff --git a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/DeleteNotificationConfigIT.kt b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/DeleteNotificationConfigIT.kt index d42a5f9f..12d84ef4 100644 --- a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/DeleteNotificationConfigIT.kt +++ b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/DeleteNotificationConfigIT.kt @@ -12,44 +12,10 @@ import org.opensearch.notifications.verifyMultiConfigIdEquals import org.opensearch.notifications.verifySingleConfigIdEquals import org.opensearch.rest.RestRequest import org.opensearch.rest.RestStatus -import kotlin.random.Random class DeleteNotificationConfigIT : PluginRestTestCase() { private val charPool: List = ('a'..'z') + ('A'..'Z') + ('0'..'9') - private fun getCreateRequestJsonString(): String { - val randomString = (1..20) - .map { Random.nextInt(0, charPool.size) } - .map(charPool::get) - .joinToString("") - return """ - { - "config_id":"$randomString", - "config":{ - "name":"this is a sample config name $randomString", - "description":"this is a sample config description $randomString", - "config_type":"slack", - "is_enabled":true, - "slack":{"url":"https://domain.com/sample_slack_url#$randomString"} - } - } - """.trimIndent() - } - - private fun createConfig(): String { - val createRequestJsonString = getCreateRequestJsonString() - val createResponse = executeRequest( - RestRequest.Method.POST.name, - "$PLUGIN_BASE_URI/configs", - createRequestJsonString, - RestStatus.OK.status - ) - val configId = createResponse.get("config_id").asString - Assert.assertNotNull(configId) - Thread.sleep(100) - return configId - } - fun `test Delete single notification config`() { val configId = createConfig() Thread.sleep(1000) @@ -65,12 +31,7 @@ class DeleteNotificationConfigIT : PluginRestTestCase() { Thread.sleep(100) // Delete notification config - val deleteResponse = executeRequest( - RestRequest.Method.DELETE.name, - "$PLUGIN_BASE_URI/configs/$configId", - "", - RestStatus.OK.status - ) + val deleteResponse = deleteConfig(configId) Assert.assertEquals("OK", deleteResponse.get("delete_response_list").asJsonObject.get(configId).asString) Thread.sleep(100) @@ -122,12 +83,7 @@ class DeleteNotificationConfigIT : PluginRestTestCase() { Thread.sleep(100) // Delete notification config - val deleteResponse = executeRequest( - RestRequest.Method.DELETE.name, - "$PLUGIN_BASE_URI/configs?config_id_list=${configIds.joinToString(separator = ",")}", - "", - RestStatus.OK.status - ) + val deleteResponse = deleteConfigs(configIds) val deletedObject = deleteResponse.get("delete_response_list").asJsonObject configIds.forEach { Assert.assertEquals("OK", deletedObject.get(it).asString) @@ -203,12 +159,7 @@ class DeleteNotificationConfigIT : PluginRestTestCase() { val remainingIds = partitions.second.toSet() // Delete notification config - val deleteResponse = executeRequest( - RestRequest.Method.DELETE.name, - "$PLUGIN_BASE_URI/configs?config_id_list=${deletedIds.joinToString(separator = ",")}", - "", - RestStatus.OK.status - ) + val deleteResponse = deleteConfigs(deletedIds) val deletedObject = deleteResponse.get("delete_response_list").asJsonObject deletedIds.forEach { Assert.assertEquals("OK", deletedObject.get(it).asString) diff --git a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/EmailNotificationConfigCrudIT.kt b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/EmailNotificationConfigCrudIT.kt index bae9c455..fb9b7912 100644 --- a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/EmailNotificationConfigCrudIT.kt +++ b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/EmailNotificationConfigCrudIT.kt @@ -58,13 +58,7 @@ class EmailNotificationConfigCrudIT : PluginRestTestCase() { } } """.trimIndent() - val createSmtpAccountResponse = executeRequest( - RestRequest.Method.POST.name, - "$PLUGIN_BASE_URI/configs", - createSmtpAccountRequestJsonString, - RestStatus.OK.status - ) - val smtpAccountConfigId = createSmtpAccountResponse.get("config_id").asString + val smtpAccountConfigId = createConfigWithRequestJsonString(createSmtpAccountRequestJsonString) Assert.assertNotNull(smtpAccountConfigId) Thread.sleep(100) @@ -95,13 +89,7 @@ class EmailNotificationConfigCrudIT : PluginRestTestCase() { } } """.trimIndent() - val createEmailGroupResponse = executeRequest( - RestRequest.Method.POST.name, - "$PLUGIN_BASE_URI/configs", - createEmailGroupRequestJsonString, - RestStatus.OK.status - ) - val emailGroupConfigId = createEmailGroupResponse.get("config_id").asString + val emailGroupConfigId = createConfigWithRequestJsonString(createEmailGroupRequestJsonString) Assert.assertNotNull(emailGroupConfigId) Thread.sleep(100) @@ -140,13 +128,7 @@ class EmailNotificationConfigCrudIT : PluginRestTestCase() { } } """.trimIndent() - val createEmailResponse = executeRequest( - RestRequest.Method.POST.name, - "$PLUGIN_BASE_URI/configs", - createEmailRequestJsonString, - RestStatus.OK.status - ) - val emailConfigId = createEmailResponse.get("config_id").asString + val emailConfigId = createConfigWithRequestJsonString(createEmailRequestJsonString) Assert.assertNotNull(emailConfigId) Thread.sleep(1000) @@ -268,12 +250,7 @@ class EmailNotificationConfigCrudIT : PluginRestTestCase() { Thread.sleep(100) // Delete email notification config - val deleteResponse = executeRequest( - RestRequest.Method.DELETE.name, - "$PLUGIN_BASE_URI/configs/$emailConfigId", - "", - RestStatus.OK.status - ) + val deleteResponse = deleteConfig(emailConfigId) Assert.assertEquals("OK", deleteResponse.get("delete_response_list").asJsonObject.get(emailConfigId).asString) Thread.sleep(1000) @@ -319,13 +296,7 @@ class EmailNotificationConfigCrudIT : PluginRestTestCase() { } } """.trimIndent() - val createSesAccountResponse = executeRequest( - RestRequest.Method.POST.name, - "$PLUGIN_BASE_URI/configs", - createSesAccountRequestJsonString, - RestStatus.OK.status - ) - val sesAccountConfigId = createSesAccountResponse.get("config_id").asString + val sesAccountConfigId = createConfigWithRequestJsonString(createSesAccountRequestJsonString) Assert.assertNotNull(sesAccountConfigId) Thread.sleep(100) @@ -356,13 +327,7 @@ class EmailNotificationConfigCrudIT : PluginRestTestCase() { } } """.trimIndent() - val createEmailGroupResponse = executeRequest( - RestRequest.Method.POST.name, - "$PLUGIN_BASE_URI/configs", - createEmailGroupRequestJsonString, - RestStatus.OK.status - ) - val emailGroupConfigId = createEmailGroupResponse.get("config_id").asString + val emailGroupConfigId = createConfigWithRequestJsonString(createEmailGroupRequestJsonString) Assert.assertNotNull(emailGroupConfigId) Thread.sleep(100) @@ -401,13 +366,7 @@ class EmailNotificationConfigCrudIT : PluginRestTestCase() { } } """.trimIndent() - val createEmailResponse = executeRequest( - RestRequest.Method.POST.name, - "$PLUGIN_BASE_URI/configs", - createEmailRequestJsonString, - RestStatus.OK.status - ) - val emailConfigId = createEmailResponse.get("config_id").asString + val emailConfigId = createConfigWithRequestJsonString(createEmailRequestJsonString) Assert.assertNotNull(emailConfigId) Thread.sleep(1000) @@ -527,12 +486,7 @@ class EmailNotificationConfigCrudIT : PluginRestTestCase() { Thread.sleep(100) // Delete email notification config - val deleteResponse = executeRequest( - RestRequest.Method.DELETE.name, - "$PLUGIN_BASE_URI/configs/$emailConfigId", - "", - RestStatus.OK.status - ) + val deleteResponse = deleteConfig(emailConfigId) Assert.assertEquals("OK", deleteResponse.get("delete_response_list").asJsonObject.get(emailConfigId).asString) Thread.sleep(1000) @@ -565,13 +519,7 @@ class EmailNotificationConfigCrudIT : PluginRestTestCase() { } } """.trimIndent() - val createSmtpAccountResponse = executeRequest( - RestRequest.Method.POST.name, - "$PLUGIN_BASE_URI/configs", - createSmtpAccountRequestJsonString, - RestStatus.OK.status - ) - val smtpAccountConfigId = createSmtpAccountResponse.get("config_id").asString + val smtpAccountConfigId = createConfigWithRequestJsonString(createSmtpAccountRequestJsonString) Assert.assertNotNull(smtpAccountConfigId) Thread.sleep(100) @@ -608,13 +556,7 @@ class EmailNotificationConfigCrudIT : PluginRestTestCase() { } } """.trimIndent() - val createEmailResponse = executeRequest( - RestRequest.Method.POST.name, - "$PLUGIN_BASE_URI/configs", - createEmailRequestJsonString, - RestStatus.OK.status - ) - val emailConfigId = createEmailResponse.get("config_id").asString + val emailConfigId = createConfigWithRequestJsonString(createEmailRequestJsonString) Assert.assertNotNull(emailConfigId) Thread.sleep(1000) @@ -714,13 +656,7 @@ class EmailNotificationConfigCrudIT : PluginRestTestCase() { } } """.trimIndent() - val createSmtpAccountResponse = executeRequest( - RestRequest.Method.POST.name, - "$PLUGIN_BASE_URI/configs", - createSmtpAccountRequestJsonString, - RestStatus.OK.status - ) - val smtpAccountConfigId = createSmtpAccountResponse.get("config_id").asString + val smtpAccountConfigId = createConfigWithRequestJsonString(createSmtpAccountRequestJsonString) Assert.assertNotNull(smtpAccountConfigId) Thread.sleep(100) @@ -794,13 +730,7 @@ class EmailNotificationConfigCrudIT : PluginRestTestCase() { } } """.trimIndent() - val createEmailGroupResponse = executeRequest( - RestRequest.Method.POST.name, - "$PLUGIN_BASE_URI/configs", - createEmailGroupRequestJsonString, - RestStatus.OK.status - ) - val emailGroupConfigId = createEmailGroupResponse.get("config_id").asString + val emailGroupConfigId = createConfigWithRequestJsonString(createEmailGroupRequestJsonString) Assert.assertNotNull(emailGroupConfigId) Thread.sleep(100) @@ -857,13 +787,7 @@ class EmailNotificationConfigCrudIT : PluginRestTestCase() { } } """.trimIndent() - val createSmtpAccountResponse = executeRequest( - RestRequest.Method.POST.name, - "$PLUGIN_BASE_URI/configs", - createSmtpAccountRequestJsonString, - RestStatus.OK.status - ) - val smtpAccountConfigId = createSmtpAccountResponse.get("config_id").asString + val smtpAccountConfigId = createConfigWithRequestJsonString(createSmtpAccountRequestJsonString) Assert.assertNotNull(smtpAccountConfigId) Thread.sleep(100) val createEmailRequestJsonString = """ @@ -918,24 +842,12 @@ class EmailNotificationConfigCrudIT : PluginRestTestCase() { } } """.trimIndent() - val createSmtpAccountResponse = executeRequest( - RestRequest.Method.POST.name, - "$PLUGIN_BASE_URI/configs", - createSmtpAccountRequestJsonString, - RestStatus.OK.status - ) - val smtpAccountConfigId = createSmtpAccountResponse.get("config_id").asString + val smtpAccountConfigId = createConfigWithRequestJsonString(createSmtpAccountRequestJsonString) Assert.assertNotNull(smtpAccountConfigId) Thread.sleep(100) // Create another smtp account - val anotherAccountResponse = executeRequest( - RestRequest.Method.POST.name, - "$PLUGIN_BASE_URI/configs", - createSmtpAccountRequestJsonString, - RestStatus.OK.status - ) - val anotherAccountConfigId = anotherAccountResponse.get("config_id").asString + val anotherAccountConfigId = createConfigWithRequestJsonString(createSmtpAccountRequestJsonString) Assert.assertNotNull(anotherAccountConfigId) Thread.sleep(100) val createEmailRequestJsonString = """ diff --git a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/QueryNotificationConfigIT.kt b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/QueryNotificationConfigIT.kt index 48720824..24c0c693 100644 --- a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/QueryNotificationConfigIT.kt +++ b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/QueryNotificationConfigIT.kt @@ -18,80 +18,10 @@ import org.opensearch.notifications.verifySingleConfigIdEquals import org.opensearch.rest.RestRequest import org.opensearch.rest.RestStatus import java.time.Instant -import kotlin.random.Random class QueryNotificationConfigIT : PluginRestTestCase() { private val charPool: List = ('a'..'z') + ('A'..'Z') + ('0'..'9') - private fun getCreateRequestJsonString( - nameSubstring: String, - configType: ConfigType, - isEnabled: Boolean - ): String { - val randomString = (1..20) - .map { Random.nextInt(0, charPool.size) } - .map(charPool::get) - .joinToString("") - val configObjectString = when (configType) { - ConfigType.SLACK -> """ - "slack":{"url":"https://slack.domain.com/sample_slack_url#$randomString"} - """.trimIndent() - ConfigType.CHIME -> """ - "chime":{"url":"https://chime.domain.com/sample_chime_url#$randomString"} - """.trimIndent() - ConfigType.WEBHOOK -> """ - "webhook":{"url":"https://web.domain.com/sample_web_url#$randomString"} - """.trimIndent() - ConfigType.SMTP_ACCOUNT -> """ - "smtp_account":{ - "host":"smtp.domain.com", - "port":"4321", - "method":"ssl", - "from_address":"$randomString@from.com" - } - """.trimIndent() - ConfigType.EMAIL_GROUP -> """ - "email_group":{ - "recipient_list":[ - {"recipient":"$randomString+recipient1@from.com"}, - {"recipient":"$randomString+recipient2@from.com"} - ] - } - """.trimIndent() - else -> throw IllegalArgumentException("Unsupported configType=$configType") - } - return """ - { - "config_id":"$randomString", - "config":{ - "name":"$nameSubstring:this is a sample config name $randomString", - "description":"this is a sample config description $randomString", - "config_type":"$configType", - "is_enabled":$isEnabled, - $configObjectString - } - } - """.trimIndent() - } - - private fun createConfig( - nameSubstring: String = "", - configType: ConfigType = ConfigType.SLACK, - isEnabled: Boolean = true - ): String { - val createRequestJsonString = getCreateRequestJsonString(nameSubstring, configType, isEnabled) - val createResponse = executeRequest( - RestRequest.Method.POST.name, - "$PLUGIN_BASE_URI/configs", - createRequestJsonString, - RestStatus.OK.status - ) - val configId = createResponse.get("config_id").asString - Assert.assertNotNull(configId) - Thread.sleep(100) - return configId - } - fun `test Get single notification config as part of path`() { val configId = createConfig() Thread.sleep(1000) @@ -857,13 +787,8 @@ class QueryNotificationConfigIT : PluginRestTestCase() { } } """.trimIndent() - val createResponse = executeRequest( - RestRequest.Method.POST.name, - "$PLUGIN_BASE_URI/configs", - createRequestJsonString, - RestStatus.OK.status - ) - Assert.assertEquals(absentId, createResponse.get("config_id").asString) + val createdConfigId = createConfigWithRequestJsonString(createRequestJsonString) + Assert.assertEquals(absentId, createdConfigId) Thread.sleep(1000) // Get chime notification config diff --git a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/SlackNotificationConfigCrudIT.kt b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/SlackNotificationConfigCrudIT.kt index fb645e81..9fbcdfbb 100644 --- a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/SlackNotificationConfigCrudIT.kt +++ b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/SlackNotificationConfigCrudIT.kt @@ -40,13 +40,7 @@ class SlackNotificationConfigCrudIT : PluginRestTestCase() { } } """.trimIndent() - val createResponse = executeRequest( - RestRequest.Method.POST.name, - "$PLUGIN_BASE_URI/configs", - createRequestJsonString, - RestStatus.OK.status - ) - val configId = createResponse.get("config_id").asString + val configId = createConfigWithRequestJsonString(createRequestJsonString) Assert.assertNotNull(configId) Thread.sleep(1000) @@ -115,12 +109,7 @@ class SlackNotificationConfigCrudIT : PluginRestTestCase() { Thread.sleep(100) // Delete slack notification config - val deleteResponse = executeRequest( - RestRequest.Method.DELETE.name, - "$PLUGIN_BASE_URI/configs/$configId", - "", - RestStatus.OK.status - ) + val deleteResponse = deleteConfig(configId) Assert.assertEquals("OK", deleteResponse.get("delete_response_list").asJsonObject.get(configId).asString) Thread.sleep(1000) diff --git a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/SnsNotificationConfigCrudIT.kt b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/SnsNotificationConfigCrudIT.kt index 33138f67..2300dbcf 100644 --- a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/SnsNotificationConfigCrudIT.kt +++ b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/SnsNotificationConfigCrudIT.kt @@ -40,13 +40,7 @@ class SnsNotificationConfigCrudIT : PluginRestTestCase() { } } """.trimIndent() - val createResponse = executeRequest( - RestRequest.Method.POST.name, - "$PLUGIN_BASE_URI/configs", - createRequestJsonString, - RestStatus.OK.status - ) - val configId = createResponse.get("config_id").asString + val configId = createConfigWithRequestJsonString(createRequestJsonString) Assert.assertNotNull(configId) Thread.sleep(1000) @@ -115,12 +109,7 @@ class SnsNotificationConfigCrudIT : PluginRestTestCase() { Thread.sleep(100) // Delete SNS notification config - val deleteResponse = executeRequest( - RestRequest.Method.DELETE.name, - "$PLUGIN_BASE_URI/configs/$configId", - "", - RestStatus.OK.status - ) + val deleteResponse = deleteConfig(configId) Assert.assertEquals("OK", deleteResponse.get("delete_response_list").asJsonObject.get(configId).asString) Thread.sleep(1000) diff --git a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/WebhookNotificationConfigCrudIT.kt b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/WebhookNotificationConfigCrudIT.kt index 9203d788..939a1647 100644 --- a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/WebhookNotificationConfigCrudIT.kt +++ b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/WebhookNotificationConfigCrudIT.kt @@ -48,13 +48,7 @@ class WebhookNotificationConfigCrudIT : PluginRestTestCase() { } } """.trimIndent() - val createResponse = executeRequest( - RestRequest.Method.POST.name, - "$PLUGIN_BASE_URI/configs", - createRequestJsonString, - RestStatus.OK.status - ) - val configId = createResponse.get("config_id").asString + val configId = createConfigWithRequestJsonString(createRequestJsonString) Assert.assertNotNull(configId) Thread.sleep(1000) @@ -131,12 +125,7 @@ class WebhookNotificationConfigCrudIT : PluginRestTestCase() { Thread.sleep(100) // Delete webhook notification config - val deleteResponse = executeRequest( - RestRequest.Method.DELETE.name, - "$PLUGIN_BASE_URI/configs/$configId", - "", - RestStatus.OK.status - ) + val deleteResponse = deleteConfig(configId) Assert.assertEquals("OK", deleteResponse.get("delete_response_list").asJsonObject.get(configId).asString) Thread.sleep(1000) diff --git a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/send/SendTestMessageRestHandlerIT.kt b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/send/SendTestMessageRestHandlerIT.kt index 5545c6c3..bcbde29f 100644 --- a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/send/SendTestMessageRestHandlerIT.kt +++ b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/send/SendTestMessageRestHandlerIT.kt @@ -30,13 +30,7 @@ internal class SendTestMessageRestHandlerIT : PluginRestTestCase() { } } """.trimIndent() - val createResponse = executeRequest( - RestRequest.Method.POST.name, - "$PLUGIN_BASE_URI/configs", - createRequestJsonString, - RestStatus.OK.status - ) - val configId = createResponse.get("config_id").asString + val configId = createConfigWithRequestJsonString(createRequestJsonString) Assert.assertNotNull(configId) Thread.sleep(1000) @@ -69,13 +63,7 @@ internal class SendTestMessageRestHandlerIT : PluginRestTestCase() { } } """.trimIndent() - val createResponse = executeRequest( - RestRequest.Method.POST.name, - "$PLUGIN_BASE_URI/configs", - createRequestJsonString, - RestStatus.OK.status - ) - val configId = createResponse.get("config_id").asString + val configId = createConfigWithRequestJsonString(createRequestJsonString) Assert.assertNotNull(configId) Thread.sleep(1000) @@ -111,13 +99,7 @@ internal class SendTestMessageRestHandlerIT : PluginRestTestCase() { } } """.trimIndent() - val createResponse = executeRequest( - RestRequest.Method.POST.name, - "$PLUGIN_BASE_URI/configs", - createRequestJsonString, - RestStatus.OK.status - ) - val configId = createResponse.get("config_id").asString + val configId = createConfigWithRequestJsonString(createRequestJsonString) Assert.assertNotNull(configId) Thread.sleep(1000) @@ -159,13 +141,7 @@ internal class SendTestMessageRestHandlerIT : PluginRestTestCase() { } } """.trimIndent() - val createResponse = executeRequest( - RestRequest.Method.POST.name, - "$PLUGIN_BASE_URI/configs", - smtpAccountCreateRequestJsonString, - RestStatus.OK.status - ) - val smtpAccountConfigId = createResponse.get("config_id").asString + val smtpAccountConfigId = createConfigWithRequestJsonString(smtpAccountCreateRequestJsonString) Assert.assertNotNull(smtpAccountConfigId) Thread.sleep(1000) @@ -187,13 +163,7 @@ internal class SendTestMessageRestHandlerIT : PluginRestTestCase() { } """.trimIndent() - val emailCreateResponse = executeRequest( - RestRequest.Method.POST.name, - "$PLUGIN_BASE_URI/configs", - emailCreateRequestJsonString, - RestStatus.OK.status - ) - val emailConfigId = emailCreateResponse.get("config_id").asString + val emailConfigId = createConfigWithRequestJsonString(emailCreateRequestJsonString) Assert.assertNotNull(emailConfigId) Thread.sleep(1000)