Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert empty httpEntity to {} to avoid DeliveryStatus initialization exception #648

Merged
merged 2 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ class DestinationHttpClient {
@Throws(IOException::class)
fun getResponseString(response: CloseableHttpResponse): String {
val entity: HttpEntity = response.entity ?: return "{}"
return EntityUtils.toString(entity)
val responseString = EntityUtils.toString(entity)
// DeliveryStatus need statusText must not be empty, convert empty response to {}
return if (responseString.isNullOrEmpty()) "{}" else responseString
}

@Throws(IOException::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ internal class ChimeDestinationTests {
@Test
fun `test chime message empty entity response`() {
val mockHttpClient: CloseableHttpClient = EasyMock.createMock(CloseableHttpClient::class.java)
val expectedWebhookResponse = DestinationMessageResponse(RestStatus.OK.status, "")
val expectedWebhookResponse = DestinationMessageResponse(RestStatus.OK.status, "{}")

val httpResponse = mockk<CloseableHttpResponse>()
EasyMock.expect(mockHttpClient.execute(EasyMock.anyObject(HttpPost::class.java))).andReturn(httpResponse)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ internal class CustomWebhookDestinationTests {
@MethodSource("methodToHttpRequestType")
fun `test custom webhook message empty entity response`(method: String, expectedHttpClass: Class<HttpUriRequest>) {
val mockHttpClient: CloseableHttpClient = EasyMock.createMock(CloseableHttpClient::class.java)
val expectedWebhookResponse = DestinationMessageResponse(RestStatus.OK.status, "")
val expectedWebhookResponse = DestinationMessageResponse(RestStatus.OK.status, "{}")

val httpResponse = mockk<CloseableHttpResponse>()
EasyMock.expect(mockHttpClient.execute(EasyMock.anyObject(HttpPost::class.java))).andReturn(httpResponse)
Expand Down Expand Up @@ -218,4 +218,17 @@ internal class CustomWebhookDestinationTests {
val actualRequestBody = httpClient.buildRequestBody(destination, message)
assertEquals(messageText, actualRequestBody)
}

@Test
fun `test get response string`() {
val httpClient = DestinationHttpClient()
val response = mockk<CloseableHttpResponse>()
every { response.entity } returns null
var responseString = httpClient.getResponseString(response)
assertEquals(responseString, "{}")

every { response.entity } returns StringEntity("")
responseString = httpClient.getResponseString(response)
assertEquals(responseString, "{}")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ internal class SlackDestinationTests {
@Test
fun `test Slack message empty entity response`() {
val mockHttpClient: CloseableHttpClient = EasyMock.createMock(CloseableHttpClient::class.java)
val expectedWebhookResponse = DestinationMessageResponse(RestStatus.OK.status, "")
val expectedWebhookResponse = DestinationMessageResponse(RestStatus.OK.status, "{}")

val httpResponse = mockk<CloseableHttpResponse>()
EasyMock.expect(mockHttpClient.execute(EasyMock.anyObject(HttpPost::class.java))).andReturn(httpResponse)
Expand Down