wiremock | A tool for mocking HTTP services | Mock library

 by   wiremock Java Version: 3.3.1 License: Apache-2.0

kandi X-RAY | wiremock Summary

kandi X-RAY | wiremock Summary

wiremock is a Java library typically used in Testing, Mock applications. wiremock has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has medium support. You can download it from GitHub, Maven.

WireMock only uses log4j in its test dependencies. Neither the thin nor standalone JAR depends on or embeds log4j, so you can continue to use WireMock 2.32.0 without any risk of exposue to the recently discovered vulnerability.

            kandi-support Support

              wiremock has a medium active ecosystem.
              It has 5594 star(s) with 1333 fork(s). There are 137 watchers for this library.
              There were 10 major release(s) in the last 12 months.
              There are 284 open issues and 991 have been closed. On average issues are closed in 553 days. There are 35 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of wiremock is 3.3.1

            kandi-Quality Quality

              wiremock has 0 bugs and 0 code smells.

            kandi-Security Security

              wiremock has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              wiremock code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              wiremock is licensed under the Apache-2.0 License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              wiremock releases are available to install and integrate.
              Deployable package is available in Maven.
              Build file is available. You can build the component from source.
              Installation instructions are not available. Examples and code snippets are available.
              It has 68112 lines of code, 5958 functions and 887 files.
              It has medium code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed wiremock and discovered the below as its top functions. This is intended to give you an instant insight into wiremock implemented functionality, and help decide if they suit your requirements.
            • Applies the given parameters to the response .
            • Add mock service context handler .
            • Add default routes .
            • Main method .
            • Adds body section to the builder .
            • Deserialize a date - time value pattern .
            • Handle webhook event .
            • Renders a single event .
            • Chunks the given number of chunks into a byte array .
            • Apply additional additional configuration if enabled .
            Get all kandi verified functions for this library.

            wiremock Key Features

            No Key Features are available at this moment for wiremock.

            wiremock Examples and Code Snippets

            Change spring cloud loadbalancer default RoundRobin Algorithm
            Lines of Code : 28dot img1License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            public class LoadBalancingConfiguration {
                public ReactorLoadBalancer reactorServiceInstanceLoadBalancer(Environment environment,
                    LoadBalancerClientFactory loadBalancerClientFactory) {
                  String name
            Android Gradle declare a Variant Build Flavor dependency using API and Exclude in KTS
            Lines of Code : 13dot img2License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            // WireMock - Do not put in release builds bc of large size, restrict to mock flavors
            "mockImplementation"(mockApi("com.github.tomakehurst:wiremock:2.18.0") {
                // Using Android Version Instead
                exclude("org.apache.httpcomponents", "h
            Best practice how to manage a lot of wiremock stubs?
            Javadot img3Lines of Code : 30dot img3License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            // Set the root of the filesystem WireMock will look under for files and mappings
            // Set a path within the classpath as the filesystem root
            Run WireMock Server as a SpringBoot application
            Javadot img4Lines of Code : 83dot img4License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            import org.springframework.context.annotation.ComponentScan;
            import org.springframework.contex
            Can't turn off debug logging for Wiremock
            Lines of Code : 7dot img5License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            Vertx HttpClientRequest handler behavior test
            Javadot img6Lines of Code : 44dot img6License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            public class MyTestClass {
                private static WireMockServer wiremock;
                private Vertx vertx;
                public static void init() {
                    wiremock = new WireMockServer(host, port); //configu
            VDM works for one Odata service, doesn't work for another
            Lines of Code : 45dot img7License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            public interface PhysicalInventoryDocumentService
                // ...
                String DEFAULT_SERVICE_PATH = "/sap/opu/odata/sap/API_PHYSICAL_INVE
            Resolve dynamic path in wireMock
            Javadot img8Lines of Code : 27dot img8License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            public static class DynamicTransformer extends ResponseDefinitionTransformer {
                public ResponseDefinition transform(Request request, ResponseDefinition responseDefinition, FileSource files, Parameters parameters) {

            Community Discussions


            How to write response in wiremock as a template with list?
            Asked 2022-Mar-18 at 20:10

            I want to use template response in wiremock and set list as a parameter. How to do that?

            I set up wiremock in Java:



            Answered 2022-Mar-18 at 20:10

            The easiest solution would be to use Jackson2 Helper or any other helper that can serialize to jsons.

            1. Add Handlebars jackson2 dependency to your project:
            • Gradle

            Source https://stackoverflow.com/questions/71529928


            Docker Container with Wiremock could not find stub mappings
            Asked 2022-Feb-02 at 20:49

            Link to the Repo:https://github.com/wiremock/wiremock-docker

            I'm getting an error when I try to access stubs, not sure if I'm missing anything here. Can I know if the below command is correct ?



            Answered 2022-Feb-02 at 20:49

            The mapping should be made to $PWD:/home/wiremock/mappings where PWD has the json files.

            Also json files should look like this:

            Source https://stackoverflow.com/questions/70961765


            Unable to run JUnit5 tests with Maven
            Asked 2022-Jan-15 at 16:05

            I'm running into an issue where I can't run JUnit5 tests using Maven. Running them in the IDE works just fine but using "mvn test" produces the following output:



            Answered 2022-Jan-15 at 15:48

            The Junit4 is available because of Testcontainer dependency. Testcontainers have a dependency on Junit4 and have it available by default. You might also encounter the following issue in few cases:

            • IDE's detects the test cases written in Junit4 format but in sometime in case you make the test classes and methods package-private, they don't detect it.

            I am not sure if they would be removing it in further releases but they do have Junit5 support which should resolve the issue

            Source https://stackoverflow.com/questions/70722701


            how to setup Wiremock dynamic port
            Asked 2021-Nov-16 at 02:13

            I am working on integration test written in Spring boot 5 and I am trying to stub downstream services. I have several clients and 3 integration test classes. In my resources folder I have .yml file with following configs:



            Answered 2021-Nov-16 at 02:13

            Lower port ranges are sometimes not allowed. Can you try higher port ranges ?

            Source https://stackoverflow.com/questions/69981011


            Implement different response with WireMock when no request(s) match
            Asked 2021-Sep-22 at 14:27

            I'm trying to stub a RESTful API. One of the resources return the details when the resource is (indeed) found, or an HTTP 404 (Not Found) when, eventually, there is no resource for the given URL.

            This is my simplified stub/mapping:



            Answered 2021-Sep-21 at 12:42

            Currently you would need to write a ResponseDefinitionTransformer to get the behaviour you're looking for.

            It would need to check whether the ResponseDefinition passed in the parameter required a file, then if so check whether the file exists by doing something like:

            Source https://stackoverflow.com/questions/69236509


            Wiremock stubs for an API client that has hardcoded urls
            Asked 2021-Sep-22 at 12:41

            I am trying to test a small service with wiremock tests.

            I am fine with stubbing out most of the third party service URLs however I run into problems when using client libraries that have their sanbox URL hardcoded.

            The current example is for Braintree.
            I want to stub a return for a call to "https://api.sandbox.braintreegateway.com:443" I cannot override that value in the test properties.

            (Ref for the hardcoding https://github.com/braintree/braintree_java/blob/9f619bb0dd019921caed1f344046078469fbf1f8/src/main/java/com/braintreegateway/Environment.java)

            Is there a way I can configure wiremock to be aware of calls to https://api.sandbox.braintreegateway.com: and return a stubbed response?



            Answered 2021-Sep-22 at 12:01

            I have never used Braintree SDK, but from what I see you use it by providing the Environment to the BraintreeGateway object: https://github.com/braintree/braintree_java/tree/master#quick-start-example

            I would create a dedicated test Environment instance containing Wiremock URLs and provide it to the BraintreeGateway in my integration tests.

            Source https://stackoverflow.com/questions/69283422


            SpringBoot2 Configuration JOOQ MariaDB: "required a bean of type 'javax.sql.DataSource' that could not be found"
            Asked 2021-Sep-13 at 13:20

            it's not the first time this question was asked and i read a lot of article about this topic, but I can't solve this problem:

            Field dataSource in de.foo.MariaDbConfig required a bean of type 'javax.sql.DataSource' that could not be found.

            All my configurations are like in this articles. Code generation worked properly with a given ddl sql file. The database is a MariaDB. Why does this error keep appearing?




            Answered 2021-Sep-13 at 13:20

            So Simon Martinelli helped me by finding the solution inside stackoverflow. After removing the hole config class, i got this "DSLContext that could not be found" error. Then i found this question:

            How to fix "Consider defining a bean of type 'org.jooq.DSLContext' in your configuration." after update to jOOQ 3.15.0

            Which solved my problem completly. Sorry for asking a question that has already been solved, but nothing pointed into the direction of R2dbcAutoConfiguration.

            So, as Simon already said, removing the config class and, as the answer in this question already pointed out, adding @SpringBootApplication(exclude = { R2dbcAutoConfiguration.class }) solved the problem.

            Source https://stackoverflow.com/questions/69162928


            Trying to update embedded database when mocked http response is returned using Wiremock of MockServer
            Asked 2021-Sep-09 at 20:15

            Working in a Spring Boot context, I am testing a service that queries a db, then makes a remote call that updates the db, then requeries the db to get the updated data.

            I am trying to use Wiremock or MockServer to mock the remote call, but can't figure out how to update the embedded database as part of the mock server response generation process.

            For example, using MockServer, I tried creating a callback class that had an autowired JdbcTemplate instance, but in the context of the callback that JdbcTemplate variable is null.



            Answered 2021-Sep-09 at 20:15

            There were two issues causing problems: making sure the jdbcTemplate used in the callback method was configured with the correct DataSource, and making sure that the data in the embedded in memory DB was accessible from the MockServer response generation thread.

            I solved the first problem by using a lambda or closure for the MockServer callback in which I use the JdbcTemplate instance created in the test class with the autowired DataSource (though solutions exist for the callback class approach as well).

            The second problem was the result of the fact that the test method was within a transaction and so inserts to the DB made at the beginning of the test were not committed when the MockServer thread (note that the MockServer response generation happens in a different thread than the main thread where the test method is running) was executing the callback. Thus those inserts were not accessible to the callback.

            The solution was to annotate the test method with @Transactional(propagation = Propagation.NOT_SUPPORTED) See h2 database access to test data from separate threads

            Source https://stackoverflow.com/questions/69111134


            Wiremock does not receive any requests
            Asked 2021-Sep-09 at 12:04

            I am writing an integrationtest for a resource (Jax-rs with resteasy) which invokes a thirdparty request to the Trustpilot Api to get a review link for a product. In my tests I wanted to mock this call by using Wiremock and invoke the request by using resteasy Dispatcher. The code below shows my Setup (names etc are changed).



            Answered 2021-Sep-09 at 12:04

            There are a couple of reasons why this isn't sending anything to WireMock at the moment:

            1. WireMock only accepts relative URLs when stubbing so passing the full URL including protocol and domain won't work. Try something equivalent to stubFor(post(urlPathEqualTo("/v1/private/product-reviews/business-units//invitation-links") instead.
            2. There doesn't seem to be any way for your class under test to know which host/port WireMock is running on and no forward proxying set up so the code is presumably still trying to call the real Trustpilot API.

            To solve 2. you have a couple of options:

            1. Set up your class/code under test to use localhost as the destination host and the result of wireMockRule.port() as the port number, or wireMockRule.httpsPort() if you're on HTTPS.
            2. Use the new auto JVM proxy setup feature to proxy your app's calls through WireMock. This assumes you're on WireMock 2.31.0+ and that your app's HTTP client respects the JVM proxy system properties.

            Source https://stackoverflow.com/questions/69116881


            With wiremock how can I match against the wiremock server URL in the body of a POST?
            Asked 2021-Sep-02 at 19:54

            I'm using Wiremock with a client calling the OSISoft PI Web API and I'm having issues matching against the POST body to the request defined here as with Wiremock the POST body will have a URL containing the randomly generated port. e.g.



            Answered 2021-Sep-02 at 19:54

            From wiremock-user Google Group

            If you don't need to match anything in particular for that element you could use a JSON placeholder e.g. "Resource": "${json-unit.any-string}".

            If you do need to match the part after the port number then you can use the regex form e.g.: "Resource": "${json-unit.regex}.*/piwebapi/assetdatabases/D0NxzXSxtlKkGzAaZhKOB-KABJ2buwfWrkye3YhdL2FOUAUEhMQUZTMDRcQgYUUEVSRk9STUFOQ0UgVEVTVElORw/elements"}"

            Source https://stackoverflow.com/questions/68957750

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network


            No vulnerabilities reported

            Install wiremock

            You can download it from GitHub, Maven.
            You can use wiremock like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the wiremock component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .


            If you have a question about WireMock, or are experiencing a problem you’re not sure is a bug please post a message to the [WireMock mailing list](https://groups.google.com/forum/#!forum/wiremock-user). On the other hand if you’re pretty certain you’ve found a bug please open an issue.
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
          • HTTPS


          • CLI

            gh repo clone wiremock/wiremock

          • sshUrl


          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link