-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update documentation * Fix text * Use numbered list * Fix image * Fix text * Fix link * Fix link * Fix code * Fix index * Fix links * Rename test * Use WireMockContainer * Update README * Fix headings
- Loading branch information
1 parent
e1473f7
commit c8a12cd
Showing
6 changed files
with
150 additions
and
22 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
80 changes: 80 additions & 0 deletions
80
src/test/kotlin/com/rogervinas/wiremock/AppShouldWithWireMockTestcontainers.kt
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,80 @@ | ||
package com.rogervinas.wiremock | ||
|
||
import com.github.tomakehurst.wiremock.client.WireMock | ||
import com.github.tomakehurst.wiremock.client.WireMock.get | ||
import com.github.tomakehurst.wiremock.client.WireMock.ok | ||
import com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo | ||
import com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.TestInstance | ||
import org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS | ||
import org.testcontainers.junit.jupiter.Container | ||
import org.testcontainers.junit.jupiter.Testcontainers | ||
import org.wiremock.integrations.testcontainers.WireMockContainer | ||
import java.io.File | ||
|
||
@Testcontainers | ||
@TestInstance(PER_CLASS) | ||
class AppShouldWithWireMockTestcontainers { | ||
|
||
companion object { | ||
private const val name = "Ivy" | ||
|
||
@Container | ||
@JvmStatic | ||
val containerFoo = WireMockContainer("wiremock/wiremock:3.2.0") | ||
.withMappingFromJSON(File("wiremock/foo-api/mappings/foo-get.json").readText()) | ||
.withCliArg("--global-response-templating") | ||
|
||
@Container | ||
@JvmStatic | ||
val containerBar = WireMockContainer("wiremock/wiremock:3.2.0") | ||
.withMappingFromJSON(File("wiremock/bar-api/mappings/bar-get.json").readText()) | ||
.withCliArg("--global-response-templating") | ||
} | ||
|
||
@Test | ||
fun `call foo and bar`() { | ||
val fooApiUrl = "http://${containerFoo.host}:${containerFoo.port}" | ||
val barApiUrl = "http://${containerBar.host}:${containerBar.port}" | ||
|
||
val app = App(name, fooApiUrl, barApiUrl) | ||
|
||
assertThat(app.execute()).isEqualTo( | ||
""" | ||
Hi! I am $name | ||
I called Foo and its response is Hello $name I am Foo! | ||
I called Bar and its response is Hello $name I am Bar! | ||
Bye! | ||
""".trimIndent() | ||
) | ||
} | ||
|
||
@Test | ||
fun `call foo an bar with dynamic stubs`() { | ||
val fooApiUrl = "http://${containerFoo.host}:${containerFoo.port}/dynamic" | ||
val barApiUrl = "http://${containerBar.host}:${containerBar.port}/dynamic" | ||
|
||
WireMock(containerFoo.host, containerFoo.port) | ||
.register(get(urlPathEqualTo("/dynamic/foo")) | ||
.withQueryParam("name", WireMock.equalTo(name)) | ||
.willReturn(ok().withBody("Hi $name I am Foo, how are you?")) | ||
) | ||
WireMock(containerBar.host, containerBar.port) | ||
.register(get(urlPathMatching("/dynamic/bar/$name")) | ||
.willReturn(ok().withBody("Hi $name I am Bar, nice to meet you!")) | ||
) | ||
|
||
val app = App(name, fooApiUrl, barApiUrl) | ||
|
||
assertThat(app.execute()).isEqualTo( | ||
""" | ||
Hi! I am $name | ||
I called Foo and its response is Hi $name I am Foo, how are you? | ||
I called Bar and its response is Hi $name I am Bar, nice to meet you! | ||
Bye! | ||
""".trimIndent() | ||
) | ||
} | ||
} |