diff --git a/alerting/src/test/kotlin/org/opensearch/alerting/AlertingRestTestCase.kt b/alerting/src/test/kotlin/org/opensearch/alerting/AlertingRestTestCase.kt index d46325a50..1dbf6e8fd 100644 --- a/alerting/src/test/kotlin/org/opensearch/alerting/AlertingRestTestCase.kt +++ b/alerting/src/test/kotlin/org/opensearch/alerting/AlertingRestTestCase.kt @@ -596,9 +596,17 @@ abstract class AlertingRestTestCase : ODFERestTestCase() { client.makeRequest("POST", "$ALERTING_BASE_URI/_execute", params, monitor.toHttpEntityWithUser()) protected fun indexDoc(index: String, id: String, doc: String, refresh: Boolean = true): Response { + return indexDoc(client(), index, id, doc, refresh) + } + + protected fun indexDocWithAdminClient(index: String, id: String, doc: String, refresh: Boolean = true): Response { + return indexDoc(adminClient(), index, id, doc, refresh) + } + + private fun indexDoc(client: RestClient, index: String, id: String, doc: String, refresh: Boolean = true): Response { val requestBody = StringEntity(doc, APPLICATION_JSON) val params = if (refresh) mapOf("refresh" to "true") else mapOf() - val response = client().makeRequest("PUT", "$index/_doc/$id", params, requestBody) + val response = client.makeRequest("PUT", "$index/_doc/$id", params, requestBody) assertTrue( "Unable to index doc: '${doc.take(15)}...' to index: '$index'", listOf(RestStatus.OK, RestStatus.CREATED).contains(response.restStatus()) diff --git a/alerting/src/test/kotlin/org/opensearch/alerting/util/destinationmigration/DestinationMigrationUtilServiceIT.kt b/alerting/src/test/kotlin/org/opensearch/alerting/util/destinationmigration/DestinationMigrationUtilServiceIT.kt index b8d6de389..8dd942de3 100644 --- a/alerting/src/test/kotlin/org/opensearch/alerting/util/destinationmigration/DestinationMigrationUtilServiceIT.kt +++ b/alerting/src/test/kotlin/org/opensearch/alerting/util/destinationmigration/DestinationMigrationUtilServiceIT.kt @@ -46,8 +46,8 @@ class DestinationMigrationUtilServiceIT : AlertingRestTestCase() { val emailGroupDoc = "{\"email_group\" : ${emailGroup.toJsonString()}}" val emailAccountId = UUID.randomUUID().toString() val emailGroupId = UUID.randomUUID().toString() - indexDoc(SCHEDULED_JOBS_INDEX, emailAccountId, emailAccountDoc) - indexDoc(SCHEDULED_JOBS_INDEX, emailGroupId, emailGroupDoc) + indexDocWithAdminClient(SCHEDULED_JOBS_INDEX, emailAccountId, emailAccountDoc) + indexDocWithAdminClient(SCHEDULED_JOBS_INDEX, emailGroupId, emailGroupDoc) val recipient = Recipient(Recipient.RecipientType.EMAIL, null, "test@email.com") val email = Email(emailAccountId, listOf(recipient)) @@ -75,7 +75,7 @@ class DestinationMigrationUtilServiceIT : AlertingRestTestCase() { "destination" : ${destination.toJsonString()} } """.trimIndent() - indexDoc(SCHEDULED_JOBS_INDEX, destination.id, dest) + indexDocWithAdminClient(SCHEDULED_JOBS_INDEX, destination.id, dest) ids.add(destination.id) }