{"id":18875807,"url":"https://github.com/wiremock/wiremock-testcontainers-java","last_synced_at":"2025-05-12T00:41:35.360Z","repository":{"id":153506554,"uuid":"628302383","full_name":"wiremock/wiremock-testcontainers-java","owner":"wiremock","description":"WireMock module for Testcontainers for Java","archived":false,"fork":false,"pushed_at":"2025-05-06T07:41:12.000Z","size":341,"stargazers_count":58,"open_issues_count":16,"forks_count":12,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-12T00:41:30.341Z","etag":null,"topics":["api","hacktoberfest","java","testcontainers","testcontainers-junit-jupiter","wiremock","wiremock-java"],"latest_commit_sha":null,"homepage":"https://wiremock.org/docs/solutions/testcontainers/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wiremock.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":"github:oleg-nenashev"},"created_at":"2023-04-15T14:26:05.000Z","updated_at":"2025-05-06T07:41:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"c907ae57-7b0a-45ee-81e4-cb0c1acf3bd8","html_url":"https://github.com/wiremock/wiremock-testcontainers-java","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wiremock%2Fwiremock-testcontainers-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wiremock%2Fwiremock-testcontainers-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wiremock%2Fwiremock-testcontainers-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wiremock%2Fwiremock-testcontainers-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wiremock","download_url":"https://codeload.github.com/wiremock/wiremock-testcontainers-java/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253655919,"owners_count":21943072,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","hacktoberfest","java","testcontainers","testcontainers-junit-jupiter","wiremock","wiremock-java"],"created_at":"2024-11-08T06:09:14.291Z","updated_at":"2025-05-12T00:41:35.345Z","avatar_url":"https://github.com/wiremock.png","language":"Java","readme":"# Testcontainers Java module for WireMock\n\n[![GitHub release (latest by date)](https://img.shields.io/github/v/release/wiremock/wiremock-testcontainers-java)](https://github.com/wiremock/wiremock-testcontainers-java/releases)\n[![Slack](https://img.shields.io/badge/slack-slack.wiremock.org-brightgreen?style=flat\u0026logo=slack)](https://slack.wiremock.org/)\n[![GitHub contributors](https://img.shields.io/github/contributors/wiremock/wiremock-testcontainers-java)](https://github.com/wiremock/wiremock-testcontainers-java/graphs/contributors)\n\n\u003e NOTE: This project is under development, the GitHub Packages release is coming soon.\n\u003e Not all WireMock features are supported at the moment,\n\u003e and there might be incompatible changes before the 1.0 release.\n\u003e Contributions are welcome!\n\nThis module allows provisioning the WireMock server\nas a standalone container\nwithin your unit tests, based on [WireMock Docker](https://github.com/wiremock/wiremock-docker).\n\nWhile you can run [WireMock Java](https://github.com/wiremock/wiremock)\nwith the same result for the most of the use-cases,\nit might be helpful to isolate JVMs or to run on\nJava versions and platforms not supported by WireMock.\nA common example is using Wiremock 3.x with Java 1.8.\n\n## Compatibility\n\nThe module is compatible with the following WireMock versions:\n\n- WireMock (aka WireMock Java) `2.0.0` and above\n- WireMock (aka WireMock Java) `3.x` versions.\n  Note that the official image for WireMock 3 is yet to be released and verified ([issue #59](https://github.com/wiremock/wiremock-testcontainers-java/issues/59))\n\nOther WireMock implementations may work but have not been tested yet.\nPlease feel free to contribute the integration tests and compatibility layers!\n\n## Usage\n\n### Importing the dependency\n\nThe module is published to Maven Central and GitHub Packages.\nYou can also use [JitPack](https://jitpack.io/) to add the dependency in your projects.\n\n#### Maven\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003eorg.wiremock.integrations.testcontainers\u003c/groupId\u003e\n  \u003cartifactId\u003ewiremock-testcontainers-module\u003c/artifactId\u003e\n  \u003cversion\u003e${see the releases}\u003c/version\u003e\n  \u003cscope\u003etest\u003c/scope\u003e\n\u003c/dependency\u003e\n```\n\n#### Gradle\n\n```gradle\ndependencies {\n  testImplementation 'org.wiremock.integrations.testcontainers:wiremock-testcontainers-module:${wiremock-testcontainers.version}'\n}\n```\n\n#### GitHub Packages\n\nGitHub Packages uses the official Maven coordinates (same as Maven Central above),\nbut you will need to configure the server and authentication.\n\n#### JitPack\n\n\u003cdetails\u003e\n\u003csummary\u003e\nJitPack / Maven\n\u003c/summary\u003e\n\n```xml\n  \u003cdependencies\u003e\n    \u003cdependency\u003e\n      \u003cgroupId\u003ecom.github.wiremock\u003c/groupId\u003e\n      \u003cartifactId\u003ewiremock-testcontainers-java\u003c/artifactId\u003e\n      \u003cversion\u003e${wiremock-testcontainers.version}\u003c/version\u003e\n      \u003cscope\u003etest\u003c/scope\u003e\n    \u003c/dependency\u003e\n    \u003c!-- .... Other Dependencies --\u003e\n  \u003c/dependencies\u003e\n\n  \u003crepositories\u003e\n    \u003crepository\u003e\n      \u003cid\u003ejitpack.io\u003c/id\u003e\n      \u003curl\u003ehttps://jitpack.io\u003c/url\u003e\n    \u003c/repository\u003e\n  \u003c/repositories\u003e\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\nJitPack / Gradle\n\u003c/summary\u003e\n\n```gradle\n  allprojects {\n\t\trepositories {\n\t\t\tmaven { url 'https://jitpack.io' }\n\t\t}\n\t}\n\n  dependencies {\n\t\ttestImplementation 'com.github.wiremock:wiremock-testcontainers-java:${wiremock-testcontainers.version}'\n\t}\n\n```\n\n\u003c/details\u003e\n\n### Using the test container in JUnit 4/5\n\nP.S: Javadoc is coming soon!\n\n#### Sample Code using JUnit 5\n\n```java\nimport org.junit.jupiter.api.*;\nimport org.testcontainers.junit.jupiter.*;\nimport org.wiremock.integrations.testcontainers.testsupport.http.*;\n\nimport static org.assertj.core.api.Assertions.assertThat;\n\n@Testcontainers\nclass WireMockContainerJunit5Test {\n\n    @Container\n    WireMockContainer wiremockServer = new WireMockContainer(\"wiremock/wiremock:2.35.0\")\n            .withMapping(\"hello\", WireMockContainerJunit5Test.class, \"hello-world.json\");\n\n    @Test\n    void helloWorld() throws Exception {\n        // given\n        String url = wiremockServer.getUrl(\"/hello\");\n\n        // when\n        HttpResponse response = new TestHttpClient().get(url);\n\n        // then\n        assertThat(response.getBody())\n                .as(\"Wrong response body\")\n                .contains(\"Hello, world!\");\n    }\n}\n```\n\n#### Sample Code using JUnit 4\n\n\u003cdetails\u003e\n\u003csummary\u003e\nShow Code\n\u003c/summary\u003e\n\n```java\nimport org.junit.*;\nimport org.wiremock.integrations.testcontainers.testsupport.http.*;\n\nimport static org.assertj.core.api.Assertions.assertThat;\n\npublic class WireMockContainerJunit4Test {\n\n    @Rule\n    public WireMockContainer wiremockServer = new WireMockContainer(\"wiremock/wiremock:2.35.0\")\n            .withMapping(\"hello\", WireMockContainerJunit4Test.class, \"hello-world.json\");\n\n    @Test\n    public void helloWorld() throws Exception {\n        // given\n        String url = wiremockServer.getUrl(\"/hello\");\n\n        // when\n        HttpResponse response = new TestHttpClient().get(url);\n\n        // then\n        assertThat(response.getBody())\n                .as(\"Wrong response body\")\n                .contains(\"Hello, world!\");\n    }\n}\n```\n\u003c/details\u003e    \n    \n### Using WireMock extensions\n\nThe API supports adding [WireMock extensions](https://wiremock.org/docs/extending-wiremock/)\nto the test container.\nThe extension can be sourced from the classpath for bundled extensions,\nor added from the JAR file in the initializer.\n\n#### Using external extensions\n\nFor the external extensions,\nan extension Jar should be pulled to the test directory before running the test.\n[Apache Maven Dependency Plugin](https://maven.apache.org/plugins/maven-dependency-plugin/) can be used for this purpose.\nMake sure that all dependencies of the extension JAR, if any,\nare also included.\n\nBelow you can see an examples of using the _JSON Body Transformer_ extension\nfrom the [9cookies/wiremock-extensions](https://github.com/9cookies/wiremock-extensions).\n\nCopying the dependency:\n\n```xml\n      \u003cplugin\u003e\n        \u003cgroupId\u003eorg.apache.maven.plugins\u003c/groupId\u003e\n        \u003cartifactId\u003emaven-dependency-plugin\u003c/artifactId\u003e\n        \u003cversion\u003e3.5.0\u003c/version\u003e\n        \u003cexecutions\u003e\n          \u003cexecution\u003e\n            \u003cid\u003ecopy\u003c/id\u003e\n            \u003cphase\u003epackage\u003c/phase\u003e\n            \u003cgoals\u003e\n              \u003cgoal\u003ecopy\u003c/goal\u003e\n            \u003c/goals\u003e\n            \u003cconfiguration\u003e\n              \u003cartifactItems\u003e\n                \u003cartifactItem\u003e\n                  \u003cgroupId\u003ecom.ninecookies.wiremock.extensions\u003c/groupId\u003e\n                  \u003cartifactId\u003ewiremock-extensions\u003c/artifactId\u003e\n                  \u003cversion\u003e0.4.1\u003c/version\u003e\n                  \u003cclassifier\u003ejar-with-dependencies\u003c/classifier\u003e\n                \u003c/artifactItem\u003e\n              \u003c/artifactItems\u003e\n              \u003coutputDirectory\u003e${project.build.directory}/test-wiremock-extension\u003c/outputDirectory\u003e\n            \u003c/configuration\u003e\n          \u003c/execution\u003e\n        \u003c/executions\u003e\n      \u003c/plugin\u003e\n```\n\nMapping definition:\n\n```json\n{\n  \"request\": {\n    \"method\": \"POST\",\n    \"url\": \"/json-body-transformer\"\n  },\n  \"response\": {\n    \"status\": 201,\n    \"headers\": {\n      \"content-type\": \"application/json\"\n    },\n    \"jsonBody\": {\n      \"message\": \"Hello, $(name)!\"\n    },\n    \"transformers\" : [\"json-body-transformer\"]\n  }\n}\n```\n\nTest sample:\n\n##### Sample code using JUnit 5\n\n```java\nimport org.junit.jupiter.api.*;\nimport org.testcontainers.junit.jupiter.*;\nimport org.wiremock.integrations.testcontainers.testsupport.http.*;\n\nimport java.nio.file.Paths;\nimport java.util.Collections;\n\nimport static org.assertj.core.api.Assertions.assertThat;\n\n@Testcontainers\nclass WireMockContainerExtensionJunit5Test {\n\n    @Container\n    WireMockContainer wiremockServer = new WireMockContainer(\"wiremock/wiremock:2.35.0\")\n            .withMapping(\"json-body-transformer\", WireMockContainerExtensionJunit5Test.class, \"json-body-transformer.json\")\n            .withExtension(\"JSON Body Transformer\",\n                    Collections.singleton(\"com.ninecookies.wiremock.extensions.JsonBodyTransformer\"),\n                    Collections.singleton(Paths.get(\"target\", \"test-wiremock-extension\", \"wiremock-extensions-0.4.1-jar-with-dependencies.jar\").toFile()));\n\n    @Test\n    void testJSONBodyTransformer() throws Exception {\n        // given\n        String url = wiremockServer.getUrl(\"/json-body-transformer\");\n        String body = \"{\\\"name\\\":\\\"John Doe\\\"}\";\n\n        // when\n        HttpResponse response = new TestHttpClient().post(url, body);\n\n        // then\n        assertThat(response.getBody()).as(\"Wrong response body\")\n                .contains(\"Hello, John Doe!\");\n    }\n}\n```\n\n##### Sample code using JUnit 4\n\n\u003cdetails\u003e\n\u003csummary\u003e\nShow Code\n\u003c/summary\u003e \n    \n```java\nimport org.junit.*;\nimport org.wiremock.integrations.testcontainers.testsupport.http.*;\n\nimport java.nio.file.Paths;\nimport java.util.Collections;\n\nimport static org.assertj.core.api.Assertions.assertThat;\n\npublic class WireMockContainerExtensionJunit4Test {\n\n    @Rule\n    public WireMockContainer wiremockServer = new WireMockContainer(\"wiremock/wiremock:2.35.0\")\n            .withMapping(\"json-body-transformer\", WireMockContainerExtensionJunit4Test.class, \"json-body-transformer.json\")\n            .withExtension(\"JSON Body Transformer\",\n                    Collections.singleton(\"com.ninecookies.wiremock.extensions.JsonBodyTransformer\"),\n                    Collections.singleton(Paths.get(\"target\", \"test-wiremock-extension\", \"wiremock-extensions-0.4.1-jar-with-dependencies.jar\").toFile()));\n\n    @Test\n    public void testJSONBodyTransformer() throws Exception {\n        // given\n        String url = wiremockServer.getUrl(\"/json-body-transformer\");\n        String body = \"{\\\"name\\\":\\\"John Doe\\\"}\";\n\n        // when\n        HttpResponse response = new TestHttpClient().post(url, body);\n\n        // then\n        assertThat(response.getBody()).as(\"Wrong response body\")\n                .contains(\"Hello, John Doe!\");\n    }\n}\n```  \n\u003c/details\u003e\n\n## Contributing\n\nSee the [Contributor Guide](./CONTRIBUTING.md).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwiremock%2Fwiremock-testcontainers-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwiremock%2Fwiremock-testcontainers-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwiremock%2Fwiremock-testcontainers-java/lists"}