-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
143 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.vonage.client.kt | ||
|
||
import com.github.tomakehurst.wiremock.WireMockServer | ||
import com.github.tomakehurst.wiremock.common.ConsoleNotifier | ||
import com.github.tomakehurst.wiremock.core.WireMockConfiguration.options | ||
import org.junit.jupiter.api.AfterEach | ||
import org.junit.jupiter.api.BeforeEach | ||
|
||
abstract class AbstractTest { | ||
val port = 8081 | ||
val wiremock: WireMockServer = WireMockServer( | ||
options().port(port).notifier(ConsoleNotifier(true)) | ||
) | ||
|
||
val vonageClient = Vonage { | ||
apiKey("a1b2c3d4") | ||
apiSecret("1234567890abcdef") | ||
applicationId("00000000-0000-4000-8000-000000000000") | ||
privateKeyPath("src/test/resources/com/vonage/client/kt/application_key") | ||
httpConfig { | ||
baseUri("http://localhost:$port") | ||
} | ||
} | ||
|
||
@BeforeEach | ||
fun setUp() { | ||
wiremock.start() | ||
} | ||
|
||
@AfterEach | ||
fun afterEach() { | ||
wiremock.resetAll() | ||
wiremock.stop() | ||
} | ||
} |
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,50 @@ | ||
package com.vonage.client.kt | ||
|
||
import com.marcinziolo.kotlin.wiremock.* | ||
import org.junit.jupiter.api.Test | ||
|
||
class MessagesTest : AbstractTest() { | ||
val messagesClient = vonageClient.messages | ||
val fromNumber = "447700900001" | ||
val toNumber = "447712345689" | ||
val text = "Hello, World!" | ||
|
||
fun expectedTextBody(channel: String): Map<String, String> = mapOf( | ||
"message_type" to "text", | ||
"text" to text, | ||
"to" to toNumber, | ||
"from" to fromNumber, | ||
"channel" to channel | ||
) | ||
|
||
fun mockResponse(expectedBodyParams: Map<String, String>) { | ||
wiremock.post { | ||
url equalTo "/v1/messages" | ||
headers contains "User-Agent" like "vonage-java-sdk.*" | ||
headers contains "Authorization" like "Bearer eyJ.+" | ||
headers contains "Content-Type" equalTo "application/json" | ||
headers contains "Accept" equalTo "application/json" | ||
for (entry in expectedBodyParams.entries) { | ||
body contains entry.key equalTo entry.value | ||
} | ||
} returns { | ||
header = "Content-Type" to "application/json" | ||
statusCode = 202 | ||
body = """ | ||
{ | ||
"message_uuid": "aaaaaaaa-bbbb-4ccc-8ddd-0123456789ab" | ||
} | ||
""" | ||
} | ||
} | ||
|
||
@Test | ||
fun `send SMS`() { | ||
mockResponse(expectedTextBody("sms")) | ||
messagesClient.send(smsText { | ||
from(fromNumber) | ||
to(toNumber) | ||
text(text) | ||
}) | ||
} | ||
} |
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,4 @@ | ||
package com.vonage.client.kt | ||
|
||
class VonageTest { | ||
} |
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,28 @@ | ||
-----BEGIN PRIVATE KEY----- | ||
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDqSe/genQY2KUz | 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