Skip to content

Commit 41cc48c

Browse files
committed
WireMock test sendSMS
1 parent 5747500 commit 41cc48c

File tree

6 files changed

+143
-15
lines changed

6 files changed

+143
-15
lines changed

pom.xml

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,9 @@
4444
<nexusUrl>https://oss.sonatype.org</nexusUrl>
4545
<project.scm.connection>scm:[email protected]:Vonage/vonage-kotlin-sdk</project.scm.connection>
4646
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
47-
<java.version>1.8</java.version>
4847
<kotlin.compiler.languageVersion>2.0</kotlin.compiler.languageVersion>
4948
<kotlin.compiler.apiVersion>2.0</kotlin.compiler.apiVersion>
50-
<kotlin.compiler.jvmTarget>${java.version}</kotlin.compiler.jvmTarget>
51-
<maven.compiler.release>${java.version}</maven.compiler.release>
49+
<kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget>
5250
</properties>
5351

5452
<dependencies>
@@ -64,10 +62,16 @@
6462
</dependency>
6563
<dependency>
6664
<groupId>org.jetbrains.kotlin</groupId>
67-
<artifactId>kotlin-test-junit</artifactId>
65+
<artifactId>kotlin-test-junit5</artifactId>
6866
<version>2.0.0</version>
6967
<scope>test</scope>
7068
</dependency>
69+
<dependency>
70+
<groupId>com.marcinziolo</groupId>
71+
<artifactId>kotlin-wiremock</artifactId>
72+
<version>2.1.1</version>
73+
<scope>test</scope>
74+
</dependency>
7175
</dependencies>
7276

7377
<distributionManagement>
@@ -101,7 +105,7 @@
101105
<version>3.6.3</version>
102106
</requireMavenVersion>
103107
<requireJavaVersion>
104-
<version>${java.version}</version>
108+
<version>1.8</version>
105109
</requireJavaVersion>
106110
</rules>
107111
</configuration>
@@ -122,7 +126,7 @@
122126
</plugin>
123127
<plugin>
124128
<artifactId>maven-javadoc-plugin</artifactId>
125-
<version>3.6.2</version>
129+
<version>3.7.0</version>
126130
<executions>
127131
<execution>
128132
<id>dokka-jar</id>
@@ -132,8 +136,8 @@
132136
</goals>
133137
<configuration>
134138
<classifier>dokka</classifier>
135-
<classesDirectory>${project.build.directory}/dokka</classesDirectory>
136-
<skipIfEmpty>true</skipIfEmpty>
139+
<!--classesDirectory>${project.build.directory}/dokka</classesDirectory>
140+
<skipIfEmpty>true</skipIfEmpty-->
137141
</configuration>
138142
</execution>
139143
</executions>
@@ -153,6 +157,16 @@
153157
</archive>
154158
</configuration>
155159
</plugin>
160+
<plugin>
161+
<groupId>org.apache.maven.plugins</groupId>
162+
<artifactId>maven-compiler-plugin</artifactId>
163+
<version>3.13.0</version>
164+
<configuration>
165+
<source>8</source>
166+
<target>8</target>
167+
<release>8</release>
168+
</configuration>
169+
</plugin>
156170
<plugin>
157171
<artifactId>maven-assembly-plugin</artifactId>
158172
<version>3.7.1</version>
@@ -186,6 +200,7 @@
186200
<plugin>
187201
<artifactId>kotlin-maven-plugin</artifactId>
188202
<groupId>org.jetbrains.kotlin</groupId>
203+
<version>2.0.0</version>
189204
<extensions>true</extensions>
190205
</plugin>
191206
</plugins>

src/main/kotlin/com/vonage/client/kt/Vonage.kt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Vonage constructor(init: VonageClient.Builder.() -> Unit) {
1515

1616
}
1717

18-
fun VonageClient.Builder.authFromEnv() : VonageClient.Builder {
18+
fun VonageClient.Builder.authFromEnv(): VonageClient.Builder {
1919
apiKey(env("VONAGE_API_KEY"))
2020
apiSecret(env("VONAGE_API_SECRET"))
2121
signatureSecret(env("VONAGE_SIGNATURE_SECRET"))
@@ -24,14 +24,10 @@ fun VonageClient.Builder.authFromEnv() : VonageClient.Builder {
2424
return this
2525
}
2626

27-
fun httpConfig(init: HttpConfig.Builder.() -> Unit): HttpConfig {
28-
return HttpConfig.builder().apply(init).build()
27+
fun VonageClient.Builder.httpConfig(init: HttpConfig.Builder.() -> Unit): VonageClient.Builder {
28+
return this.httpConfig(HttpConfig.builder().apply(init).build())
2929
}
3030

3131
private fun env(variable: String) : String? {
3232
return System.getenv(variable)
33-
}
34-
35-
fun main() {
36-
val client = Vonage { authFromEnv() }
3733
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.vonage.client.kt
2+
3+
import com.github.tomakehurst.wiremock.WireMockServer
4+
import com.github.tomakehurst.wiremock.common.ConsoleNotifier
5+
import com.github.tomakehurst.wiremock.core.WireMockConfiguration.options
6+
import org.junit.jupiter.api.AfterEach
7+
import org.junit.jupiter.api.BeforeEach
8+
9+
abstract class AbstractTest {
10+
val port = 8081
11+
val wiremock: WireMockServer = WireMockServer(
12+
options().port(port).notifier(ConsoleNotifier(true))
13+
)
14+
15+
val vonageClient = Vonage {
16+
apiKey("a1b2c3d4")
17+
apiSecret("1234567890abcdef")
18+
applicationId("00000000-0000-4000-8000-000000000000")
19+
privateKeyPath("src/test/resources/com/vonage/client/kt/application_key")
20+
httpConfig {
21+
baseUri("http://localhost:$port")
22+
}
23+
}
24+
25+
@BeforeEach
26+
fun setUp() {
27+
wiremock.start()
28+
}
29+
30+
@AfterEach
31+
fun afterEach() {
32+
wiremock.resetAll()
33+
wiremock.stop()
34+
}
35+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.vonage.client.kt
2+
3+
import com.marcinziolo.kotlin.wiremock.*
4+
import org.junit.jupiter.api.Test
5+
6+
class MessagesTest : AbstractTest() {
7+
val messagesClient = vonageClient.messages
8+
val fromNumber = "447700900001"
9+
val toNumber = "447712345689"
10+
val text = "Hello, World!"
11+
12+
fun expectedTextBody(channel: String): Map<String, String> = mapOf(
13+
"message_type" to "text",
14+
"text" to text,
15+
"to" to toNumber,
16+
"from" to fromNumber,
17+
"channel" to channel
18+
)
19+
20+
fun mockResponse(expectedBodyParams: Map<String, String>) {
21+
wiremock.post {
22+
url equalTo "/v1/messages"
23+
headers contains "User-Agent" like "vonage-java-sdk.*"
24+
headers contains "Authorization" like "Bearer eyJ.+"
25+
headers contains "Content-Type" equalTo "application/json"
26+
headers contains "Accept" equalTo "application/json"
27+
for (entry in expectedBodyParams.entries) {
28+
body contains entry.key equalTo entry.value
29+
}
30+
} returns {
31+
header = "Content-Type" to "application/json"
32+
statusCode = 202
33+
body = """
34+
{
35+
"message_uuid": "aaaaaaaa-bbbb-4ccc-8ddd-0123456789ab"
36+
}
37+
"""
38+
}
39+
}
40+
41+
@Test
42+
fun `send SMS`() {
43+
mockResponse(expectedTextBody("sms"))
44+
messagesClient.send(smsText {
45+
from(fromNumber)
46+
to(toNumber)
47+
text(text)
48+
})
49+
}
50+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.vonage.client.kt
2+
3+
class VonageTest {
4+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-----BEGIN PRIVATE KEY-----
2+
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDqSe/genQY2KUz
3+
xc1iqj2pgeH1k2SKHpIK8L8JLwfEEskhG92Ch9euivu30roKHTVMI4lXRrOL0OyM
4+
uX0EZQGSuDvB8cZpOL+044oV3XInx/LwkEgHIsB7anv6rJ/fyxHTGvlc1c3DmQhl
5+
J5ToFtu2DL8dY/nmYvdpeo74+0iOyTODiGCNrB8Kqc7zrx/KQM732BBrLeRs6TwY
6+
+7lQYIebFQN5C9JvGWAlStw9IJO+dlJojMru9bz//B+rWe350m5WiVSFHnSP5K6o
7+
t1SBuraoJRsdORwVb9dp0gU3UDkGApYgmBFTt0MJoCZWNA3QNkJ8clpjh8JJtIcF
8+
dWFL2mvxAgMBAAECggEAZZd9/rbalNOMfzCsaLYtWs1JL/WjyQiMh1XxYIgWM/15
9+
XXP5z1ocOkFl+UXVCgG0VLmsGj48KMqFaFgeT8OEtRxSPT0brhC/gC6Sd/y4PWvE
10+
em/167I0CNAZxo8IHECwD/xIWOsU+FXpg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