-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathWireMockContainer.kt
36 lines (29 loc) · 1.15 KB
/
WireMockContainer.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
package io.dotanuki.platform.jvm.core.rest.util
import org.testcontainers.containers.GenericContainer
import org.testcontainers.containers.wait.strategy.Wait
import org.testcontainers.images.builder.Transferable
import org.testcontainers.utility.DockerImageName
class WireMockContainer(
imageName: DockerImageName,
) : GenericContainer<WireMockContainer>(imageName) {
private val stubs = mutableListOf<Pair<String, String>>()
private val customWaitStrategy by lazy {
Wait.forHttp("/__admin/mappings").withMethod("GET").forStatusCode(200)
}
fun withStubMapping(stubName: String, jsonContent: String): WireMockContainer {
stubs += Pair(stubName, jsonContent)
return this
}
override fun configure() {
super.configure()
withExposedPorts(DEFAULT_PORT)
waitingFor(customWaitStrategy)
stubs.forEach { (name, jsonContent) ->
withCopyToContainer(Transferable.of(jsonContent), "$WIREMOCK_STUBS_FOLDER$name.json")
}
}
companion object {
private const val DEFAULT_PORT = 8080
private const val WIREMOCK_STUBS_FOLDER = "/home/wiremock/mappings/"
}
}