Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wiremock error: Request was not matched as there were no stubs registered

@ClassRule
    public static WireMockRule wireMockRule = new WireMockRule(9898);

    @Test
    public void createXmlFile() {
        stubFor(get(urlPathEqualTo("/data/racing/"))
                .willReturn(aResponse()
                        .withBody(loadJSONFile("unibet-demo-input.json"))));

    }

I don't know what is going wrong here!

2019-01-16 15:54:05.810 [qtp1929284175-20] INFO  ROOT:2341 - RequestHandlerClass from context returned com.github.tomakehurst.wiremock.http.StubRequestHandler. Normalized mapped under returned 'null'
2019-01-16 15:54:05.822 [qtp1929284175-15] INFO  __admin:2341 - RequestHandlerClass from context returned com.github.tomakehurst.wiremock.http.AdminRequestHandler. Normalized mapped under returned 'null'
2019-01-16 15:54:05.925 [qtp1929284175-20] ERROR WireMock:40 - Request was not matched as there were no stubs registered:
{
      "url" : "/data/racing/",
      "absoluteUrl" : "http://localhost:9898/data/racing/",
      "method" : "GET",
      "clientIp" : "127.0.0.1",
      "headers" : {
        "User-Agent" : "Jakarta Commons-HttpClient/3.1",
        "Host" : "localhost:9898",
        "batchID" : "1056178410254123336",
        "breadcrumbId" : "ID-SBGML01938-1547654042343-0-1"
      },
      "cookies" : { },
      "browserProxyRequest" : false,
      "loggedDate" : 1547654045870,
      "bodyAsBase64" : "",
      "body" : "",
      "scheme" : "http",
      "host" : "localhost",
      "port" : 9898,
      "loggedDateString" : "2019-01-16T15:54:05Z",
      "queryParams" : { }
    }

Click to see the difference is stating Contents are identical.

com.github.tomakehurst.wiremock.client.VerificationException: A request was unmatched by any stub mapping. Closest stub mapping was:   <Click to see difference>


    at com.github.tomakehurst.wiremock.client.VerificationException.forSingleUnmatchedRequest(VerificationException.java:43)
    at com.github.tomakehurst.wiremock.client.VerificationException.forUnmatchedNearMisses(VerificationException.java:48)
    at com.github.tomakehurst.wiremock.junit.WireMockRule.checkForUnmatchedRequests(WireMockRule.java:92)
    at com.github.tomakehurst.wiremock.junit.WireMockRule.access$000(WireMockRule.java:34)
    at com.github.tomakehurst.wiremock.junit.WireMockRule$1.evaluate(WireMockRule.java:74)
    at org.junit.rules.RunRules.evaluate(RunRules.java:20)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
like image 337
krmanish007 Avatar asked Jan 16 '19 16:01

krmanish007


People also ask

What is stub in WireMock?

Stubbing is a technique that allows us to configure the HTTP response that is returned by our WireMock server when it receives a specific HTTP request. We can stub HTTP requests with WireMock by using the static givenThat() method of the WireMock class.

How do I reset my WireMock?

However you can do it yourself via a call to WireMock. reset() in Java or sending a POST request with an empty body to http://<host>:<port>/__admin/reset. To reset just the stub mappings leaving the request log intact send a DELETE to http://<host>:<port>/__admin/mappings. Hope this is useful.

What is the purpose of WireMock?

WireMock is a library for stubbing and mocking web services. It constructs an HTTP server that we can connect to as we would to an actual web service. When a WireMock server is in action, we can set up expectations, call the service and then verify its behaviors.


1 Answers

I had to add wireMockRule on stubFor to make it work.

@ClassRule
public static WireMockRule wireMockRule = new WireMockRule(9898);

@Test
public void createXmlFile() {
    wireMockRule.stubFor(get(urlPathEqualTo("/data/racing/"))
        .willReturn(aResponse()
            .withBody(loadJSONFile("unibet-demo-input.json"))));
}
like image 194
krmanish007 Avatar answered Oct 17 '22 07:10

krmanish007