-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.kt
55 lines (48 loc) · 1.66 KB
/
App.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package de.beiertu.wiremock.docker
import com.github.tomakehurst.wiremock.client.WireMock.aResponse
import com.github.tomakehurst.wiremock.client.WireMock.equalTo
import com.github.tomakehurst.wiremock.client.WireMock.get
import com.github.tomakehurst.wiremock.client.WireMockBuilder
import io.github.oshai.kotlinlogging.KotlinLogging
import org.http4k.client.ApacheClient
import org.http4k.core.Method
import org.http4k.core.Request
import java.net.URI
/*
* A simple example on how to register requests in WireMock.
* See https://wiremock.org/docs/request-matching/ for more information.
*/
fun main() {
val logger = KotlinLogging.logger {}
// Wiremock url, which is available after it is started with the provided docker-compose file.
// Adjust the scheme and port if needed.
val wireMockUri = URI("http://localhost:8080")
val wireMockClient =
WireMockBuilder()
.scheme(wireMockUri.scheme)
.host(wireMockUri.host)
.port(wireMockUri.port)
.build()
// Register a new GET request
wireMockClient.register(
get("/v2/hello")
.withHeader("accept", equalTo("text/plain"))
.willReturn(
aResponse().withStatus(200).withBody("Hello from v2"),
),
)
// Verify that registered request is working as expected.
val httpClient = ApacheClient()
val wireMockResponse =
httpClient(
Request(Method.GET, "$wireMockUri/v2/hello")
.header("accept", "text/plain"),
)
logger.info {
"""
|WireMock responds with:
|
|$wireMockResponse
""".trimMargin()
}
}