-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update the tests to use WireMock 3.0.0 release #72
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4c9b8a7
Update the tests to use WireMock 3.0.0 release
oleg-nenashev ac56651
Update WireMock Webhook Extension to 3.0.1
oleg-nenashev dd5d1cf
Apply suggestions from code review
oleg-nenashev 97b9b9b
Update src/main/java/org/wiremock/integrations/testcontainers/WireMoc…
oleg-nenashev 782356f
Apply suggestions from code review
oleg-nenashev eb7734e
Adapt to WireMock 3.1.0 with extension removal, split out WireMock 2 ITs
oleg-nenashev 65d737e
Adapt to Wiremock 3.5.4 and fix tests for version 2
graric 94ed862
Merge pull request #129 from graric/wiremock-3-fix-tests
oleg-nenashev d648624
Merge branch 'main' into wiremock-3-by-default
oleg-nenashev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
17 changes: 17 additions & 0 deletions
17
src/test/java/org/wiremock/integrations/testcontainers/TestConfig.java
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,17 @@ | ||
package org.wiremock.integrations.testcontainers; | ||
|
||
import org.testcontainers.utility.DockerImageName; | ||
|
||
public class TestConfig { | ||
|
||
private static final String DEFAULT_TEST_TAG = | ||
System.getProperty("wiremock.testcontainer.defaultTag", "3.5.4"); | ||
private static final String WIREMOCK_2_TEST_TAG = | ||
System.getProperty("wiremock.testcontainer.wiremock2Tag", "2.35.1-1"); | ||
|
||
public static final DockerImageName WIREMOCK_DEFAULT_IMAGE = | ||
DockerImageName.parse(WireMockContainer.OFFICIAL_IMAGE_NAME).withTag(DEFAULT_TEST_TAG); | ||
|
||
public static final DockerImageName WIREMOCK_2_IMAGE = | ||
DockerImageName.parse(WireMockContainer.OFFICIAL_IMAGE_NAME).withTag(WIREMOCK_2_TEST_TAG); | ||
} |
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
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
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
100 changes: 100 additions & 0 deletions
100
src/test/java/org/wiremock/integrations/testcontainers/wiremock2/WebhooksExtensionTest.java
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,100 @@ | ||
/* | ||
* Copyright (C) 2023 WireMock Inc, Oleg Nenashev and all project contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.wiremock.integrations.testcontainers.wiremock2; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.testcontainers.Testcontainers.exposeHostPorts; | ||
import static org.testcontainers.shaded.org.awaitility.Awaitility.await; | ||
|
||
import java.nio.file.Paths; | ||
import java.time.Duration; | ||
import java.util.Collections; | ||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.output.Slf4jLogConsumer; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
import org.wiremock.integrations.testcontainers.TestConfig; | ||
import org.wiremock.integrations.testcontainers.WireMockContainer; | ||
import org.wiremock.integrations.testcontainers.testsupport.http.HttpResponse; | ||
import org.wiremock.integrations.testcontainers.testsupport.http.TestHttpClient; | ||
import org.wiremock.integrations.testcontainers.testsupport.http.TestHttpServer; | ||
|
||
/** | ||
* Tests the WireMock Webhook extension and TestContainers Networking | ||
* For this type of tests we should use following steps: | ||
* <p> | ||
* Use {@link GenericContainer#withAccessToHost(boolean)} to force the host access mechanism | ||
* <p> | ||
* Use {@link org.testcontainers.Testcontainers#exposeHostPorts(int...)} to expose host machine ports to containers | ||
* <p> | ||
* Use {@link GenericContainer#INTERNAL_HOST_HOSTNAME} to calculate hostname for callback | ||
* | ||
* @see <a href="https://www.testcontainers.org/features/networking/">Testcontainers Networking</a> | ||
*/ | ||
@Testcontainers | ||
class WebhooksExtensionTest { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(WebhooksExtensionTest.class); | ||
private static final String WIREMOCK_PATH = "/wiremock/callback-trigger"; | ||
private static final String APPLICATION_PATH = "/application/callback-receiver"; | ||
|
||
|
||
TestHttpServer applicationServer = TestHttpServer.newInstance(); | ||
@Container | ||
WireMockContainer wiremockServer = new WireMockContainer(TestConfig.WIREMOCK_2_IMAGE) | ||
.withLogConsumer(new Slf4jLogConsumer(LOGGER)) | ||
.withCliArg("--global-response-templating") | ||
.withMapping("webhook-callback-template", WebhooksExtensionTest.class, "webhook-callback-template.json") | ||
.withExtensions("Webhooks", | ||
Collections.singleton("org.wiremock.webhooks.Webhooks"), | ||
Collections.singleton(Paths.get("target", "test-wiremock-extension", "wiremock-webhooks-extension-2.35.0.jar").toFile())) | ||
.withAccessToHost(true); // Force the host access mechanism | ||
|
||
@Test | ||
void callbackUsingJsonStub() throws Exception { | ||
// given | ||
exposeHostPorts(applicationServer.getPort()); // Exposing host ports to the container | ||
|
||
String wiremockUrl = wiremockServer.getUrl(WIREMOCK_PATH); | ||
String applicationCallbackUrl = String.format("http://%s:%d%s", GenericContainer.INTERNAL_HOST_HOSTNAME, applicationServer.getPort(), APPLICATION_PATH); | ||
|
||
// when | ||
HttpResponse response = new TestHttpClient().post( | ||
wiremockUrl, | ||
"{\"callbackMethod\": \"PUT\", \"callbackUrl\": \"" + applicationCallbackUrl + "\"}" | ||
); | ||
|
||
// then | ||
assertThat(response).as("Wiremock Response").isNotNull().satisfies(it -> { | ||
assertThat(it.getStatusCode()).as("Wiremock Response Status").isEqualTo(200); | ||
assertThat(it.getBody()).as("Wiremock Response Body") | ||
.contains("Please wait callback") | ||
.contains("PUT") | ||
.contains(applicationCallbackUrl); | ||
}); | ||
|
||
await().atMost(Duration.ofMillis(5000)).untilAsserted(() -> { | ||
assertThat(applicationServer.getRecordedRequests()).as("Received Callback") | ||
.hasSize(1) | ||
.first().usingRecursiveComparison() | ||
.isEqualTo(new TestHttpServer.RecordedRequest("PUT", APPLICATION_PATH, "Async processing Finished")); | ||
}); | ||
} | ||
|
||
} |
68 changes: 68 additions & 0 deletions
68
...ock/integrations/testcontainers/wiremock2/WireMockContainerExtensionsCombinationTest.java
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,68 @@ | ||
/* | ||
* Copyright (C) 2023 WireMock Inc, Oleg Nenashev and all project contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.wiremock.integrations.testcontainers.wiremock2; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.testcontainers.containers.output.Slf4jLogConsumer; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
import org.wiremock.integrations.testcontainers.TestConfig; | ||
import org.wiremock.integrations.testcontainers.WireMockContainer; | ||
import org.wiremock.integrations.testcontainers.testsupport.http.HttpResponse; | ||
import org.wiremock.integrations.testcontainers.testsupport.http.TestHttpClient; | ||
|
||
import java.nio.file.Paths; | ||
import java.util.Collections; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Tests the WireMock extension loading. | ||
* It uses multiple external Jars supplied by the Maven Dependency Plugin. | ||
*/ | ||
@Testcontainers | ||
class WireMockContainerExtensionsCombinationTest { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(WireMockContainerExtensionsCombinationTest.class); | ||
|
||
@Container | ||
WireMockContainer wiremockServer = new WireMockContainer(TestConfig.WIREMOCK_2_IMAGE) | ||
.withLogConsumer(new Slf4jLogConsumer(LOGGER)) | ||
.withMapping("json-body-transformer", WireMockContainerExtensionsCombinationTest.class, "json-body-transformer.json") | ||
.withExtensions("Webhook", | ||
Collections.singleton("org.wiremock.webhooks.Webhooks"), | ||
Collections.singleton(Paths.get("target", "test-wiremock-extension", "wiremock-webhooks-extension-2.35.0.jar").toFile())) | ||
.withExtensions("JSON Body Transformer", | ||
Collections.singleton("com.ninecookies.wiremock.extensions.JsonBodyTransformer"), | ||
Collections.singleton(Paths.get("target", "test-wiremock-extension", "wiremock-extensions-0.4.1-jar-with-dependencies.jar").toFile())); | ||
|
||
@Test | ||
void testJSONBodyTransformer() throws Exception { | ||
// given | ||
String url = wiremockServer.getUrl("/json-body-transformer"); | ||
String body = "{\"name\":\"John Doe\"}"; | ||
|
||
// when | ||
HttpResponse response = new TestHttpClient().post(url, body); | ||
|
||
// then | ||
assertThat(response.getBody()) | ||
.as("Wrong response body") | ||
.contains("Hello, John Doe!"); | ||
} | ||
} |
File renamed without changes.
31 changes: 31 additions & 0 deletions
31
...ntegrations/testcontainers/wiremock2/WebhooksExtensionTest/webhook-callback-template.json
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,31 @@ | ||
{ | ||
"request": { | ||
"method": "POST", | ||
"urlPath": "/wiremock/callback-trigger" | ||
}, | ||
"response": { | ||
"status": 200, | ||
"headers": { | ||
"Content-Type": "application/json" | ||
}, | ||
"jsonBody": { | ||
"message": "Please wait callback", | ||
"method": "{{jsonPath request.body '$.callbackMethod'}}", | ||
"url": "{{jsonPath request.body '$.callbackUrl'}}" | ||
} | ||
}, | ||
"postServeActions": [ | ||
{ | ||
"name": "webhook", | ||
"parameters": { | ||
"method": "{{jsonPath originalRequest.body '$.callbackMethod'}}", | ||
"url": "{{jsonPath originalRequest.body '$.callbackUrl'}}", | ||
"body": "Async processing Finished", | ||
"delay": { | ||
"type": "fixed", | ||
"milliseconds": 1000 | ||
} | ||
} | ||
} | ||
] | ||
} |
16 changes: 16 additions & 0 deletions
16
...ontainers/wiremock2/WireMockContainerExtensionsCombinationTest/json-body-transformer.json
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,16 @@ | ||
{ | ||
"request": { | ||
"method": "POST", | ||
"url": "/json-body-transformer" | ||
}, | ||
"response": { | ||
"status": 201, | ||
"headers": { | ||
"content-type": "application/json" | ||
}, | ||
"jsonBody": { | ||
"message": "Hello, $(name)!" | ||
}, | ||
"transformers" : ["json-body-transformer"] | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove it, since we haven't yet released - we could afford removing old code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed