-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert empty httpEntity to {} to avoid DeliveryStatus initialization…
… exception (#648) * convert empty httpEntity to {} to avoid DeliveryStatus initialization exception Signed-off-by: Hailong Cui <[email protected]> * add integTest case for webhook empty response Signed-off-by: Hailong Cui <[email protected]> --------- Signed-off-by: Hailong Cui <[email protected]>
- Loading branch information
1 parent
464fdb2
commit 94c225d
Showing
6 changed files
with
106 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...ications/src/test/kotlin/org/opensearch/integtest/send/SendTestMessageWithMockServerIT.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.integtest.send | ||
|
||
import com.google.gson.JsonArray | ||
import com.google.gson.JsonObject | ||
import com.sun.net.httpserver.HttpServer | ||
import org.junit.AfterClass | ||
import org.junit.Assert | ||
import org.junit.BeforeClass | ||
import org.opensearch.integtest.PluginRestTestCase | ||
import org.opensearch.notifications.NotificationPlugin.Companion.PLUGIN_BASE_URI | ||
import org.opensearch.rest.RestRequest | ||
import org.opensearch.rest.RestStatus | ||
import java.net.InetAddress | ||
import java.net.InetSocketAddress | ||
|
||
internal class SendTestMessageWithMockServerIT : PluginRestTestCase() { | ||
|
||
fun `test webhook return with empty entity`() { | ||
val url = "http://${server.address.hostString}:${server.address.port}/webhook" | ||
logger.info("webhook url = {}", url) | ||
// Create webhook notification config | ||
val createRequestJsonString = """ | ||
{ | ||
"config":{ | ||
"name":"this is a sample config name", | ||
"description":"this is a sample config description", | ||
"config_type":"webhook", | ||
"is_enabled":true, | ||
"webhook":{ | ||
"url":"$url", | ||
"header_params": { | ||
"Content-type": "text/plain" | ||
} | ||
} | ||
} | ||
} | ||
""".trimIndent() | ||
val configId = createConfigWithRequestJsonString(createRequestJsonString) | ||
Assert.assertNotNull(configId) | ||
Thread.sleep(1000) | ||
|
||
// send test message | ||
val sendResponse = executeRequest( | ||
RestRequest.Method.POST.name, "$PLUGIN_BASE_URI/feature/test/$configId", "", RestStatus.OK.status | ||
) | ||
|
||
logger.info(sendResponse) | ||
|
||
// verify failure response is with message | ||
val deliveryStatus = (sendResponse.get("status_list") as JsonArray).get(0).asJsonObject | ||
.get("delivery_status") as JsonObject | ||
Assert.assertEquals(deliveryStatus.get("status_code").asString, "200") | ||
Assert.assertEquals(deliveryStatus.get("status_text").asString, "{}") | ||
} | ||
|
||
companion object { | ||
private lateinit var server: HttpServer | ||
|
||
@JvmStatic | ||
@BeforeClass | ||
fun setupWebhook() { | ||
server = HttpServer.create(InetSocketAddress(InetAddress.getLoopbackAddress(), 0), 0) | ||
|
||
server.createContext("/webhook") { | ||
it.sendResponseHeaders(200, -1) | ||
} | ||
server.start() | ||
} | ||
|
||
@JvmStatic | ||
@AfterClass | ||
fun stopMockServer() { | ||
server.stop(1) | ||
} | ||
} | ||
} |