3

I've just started using Wiremock and I have a question about stubbing.

From the docs, it seems to be that you can use either a JSON file under mappings OR the code stubFor(get(urlEqualTo(... in your Java code. However, I'm finding that using stubFor(get(urlEqualTo( results in 'Request was not matched' messages appearing in the Wiremock console.

Is this correct behaviour? Does stubbing need both the code and the json file?

Thanks.

Paul D. Waite
  • 96,640
  • 56
  • 199
  • 270
angusrose
  • 143
  • 1
  • 3
  • 13
  • Behavior sounds correct to me. Request not matched just means you made a request but it does not match the request you mocked-up. – djangofan Feb 04 '19 at 23:00

3 Answers3

1

No, wiremock can work only with .json Files or only with java code. You can combine it if you want.

When the request is not matched, then the url is not correctly stubbed. If you are using the standalone process you can start it with --verbose to find detailed information why the request was not matched.

Daniel P.
  • 369
  • 3
  • 12
0

WireMock can work with just JSON payloads in mappings. Sounds like there's something else going on with your configuration, but I'd need more details to diagnose.

suite22
  • 476
  • 3
  • 16
-8

Not necessary. I have tried below code and it worked for me:

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import com.github.tomakehurst.wiremock.WireMockServer;

public class WireMockTest {
    public static void main(String[] args) throws InterruptedException {
        WireMockServer wireMockServer1 = new WireMockServer();  
        wireMockServer1.start();
        wireMockServer1.stubFor(get(urlEqualTo("/testWireMock"))
                       .willReturn(aResponse().withHeader("Content-Type", "text/plain")
                       .withStatus(200).withBody("Welcome to WireMock!")));
        System.out.println("Server started");
        Thread.sleep(1000);
        wireMockServer1.stop();
    }
}
Cà phê đen
  • 1,883
  • 2
  • 21
  • 20
  • This doesn't prove anything. This example stubs response but never actually calls it to prove it's working. – djangofan Feb 03 '19 at 21:15