Skip to content

Commit

Permalink
Replace creating config from JSON string calls with helper method tha…
Browse files Browse the repository at this point in the history
…t refreshes indices

Signed-off-by: Mohammad Qureshi <[email protected]>
  • Loading branch information
qreshi committed Jan 5, 2023
1 parent fe14159 commit e8c6ae7
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 239 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,22 @@ abstract class PluginRestTestCase : OpenSearchRestTestCase() {
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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -243,13 +230,7 @@ class SecurityNotificationIT : PluginRestTestCase() {
}
""".trimIndent()

executeRequest(
RestRequest.Method.POST.name,
"${NotificationPlugin.PLUGIN_BASE_URI}/configs",
createRequestJsonString,
RestStatus.FORBIDDEN.status,
userClient!!
)
createConfigWithRequestJsonString(createRequestJsonString, userClient!!)
deleteUserWithCustomRole(user, NOTIFICATION_NO_ACCESS_ROLE)
}

Expand Down Expand Up @@ -278,13 +259,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)

Expand Down Expand Up @@ -340,13 +315,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)

Expand Down Expand Up @@ -471,13 +440,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)

Expand Down Expand Up @@ -515,13 +478,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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -184,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)

Expand Down Expand Up @@ -278,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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -314,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)

Expand Down Expand Up @@ -351,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)

Expand Down Expand Up @@ -396,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)

Expand Down Expand Up @@ -555,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)

Expand Down Expand Up @@ -598,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)

Expand Down Expand Up @@ -704,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)

Expand Down Expand Up @@ -784,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)

Expand Down Expand Up @@ -847,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 = """
Expand Down Expand Up @@ -908,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 = """
Expand Down
Loading

0 comments on commit e8c6ae7

Please sign in to comment.