8

Wiremock logs that the following request not matches:

    WireMock                                 : Request was not matched:
{
  "url" : "/api/accounts?username=defaultuser",
  "absoluteUrl" : "http://localhost:11651/api/accounts?username=defaultuser",
  "method" : "GET",
  "clientIp" : "127.0.0.1",
  "headers" : {
    "authorization" : "bearer test123",
    "accept" : "application/json, application/*+json",
    "user-agent" : "Java/1.8.0_121",
    "host" : "localhost:11651",
    "connection" : "keep-alive"
  },
  "cookies" : { },
  "browserProxyRequest" : false,
  "loggedDate" : 1500711718016,
  "bodyAsBase64" : "",
  "body" : "",
  "loggedDateString" : "2017-07-22T08:21:58Z"
}
Closest match:
{
  "urlPath" : "/api/accounts",
  "method" : "GET",
  "headers" : {
    "authorization" : {
      "matches" : "^bearer"
    },
    "accept" : {
      "equalTo" : "application/json, application/*+json"
    },
    "user-agent" : {
      "equalTo" : "Java/1.8.0_121"
    },
    "host" : {
      "matches" : "^localhost:[0-9]{5}"
    },
    "connection" : {
      "equalTo" : "keep-alive"
    }
  },
  "queryParameters" : {
    "username" : {
      "matches" : "^[a-zA-Z0-9]*$"
    }
  }
}

Is the problem because of the difference of url and urlPath? I also tried to specify absoluteUrl in the Contract. but it is ignored. I guess because it is not defined in Contract DSL.

The request side of the contract looks like this:

request{
        method 'GET'
        url('/api/accounts'){
            queryParameters {
                parameter('username', $(consumer(regex('^[a-zA-Z0-9]*$')), producer('defaultuser')))
            }
        }
        headers {
            header('authorization', $(consumer(regex('^bearer')), producer(execute('authClientBearer()'))))
            header('accept', $(consumer('application/json, application/*+json')))
            header('user-agent', $(consumer('Java/1.8.0_121')))
            header('host', $(consumer(regex('^localhost:[0-9]{5}'))))
            header('connection', $(consumer('keep-alive')))
        }
    }
Slava Semushin
  • 14,904
  • 7
  • 53
  • 69
Rocks360
  • 358
  • 1
  • 4
  • 14

3 Answers3

8

It turned out to be a missing / at the end of the URL in the contract/stub

Marcin Grzejszczak
  • 10,624
  • 1
  • 16
  • 32
3

Not directly related to the question but for all who came here from Google:

In my case I was in the wrong scenario state.

More about scenario states here: http://wiremock.org/docs/stateful-behaviour/

JoschJava
  • 1,152
  • 12
  • 20
1

If you have the same problem, maybe it's about your problem: JSON configuration for matching mvcMock example:

"request": {
"urlPath": "/hello?name=pavel",
"method": "GET",
 ..
           }

And you can see in log: "/hello?name=pavel" | "/hello?name=pavel" - URL does not match

This is correct. You have to change:

"request": {
    "urlPath": "/hello",
    "method": "GET",
"queryParameters": {
  "name": {
    "equalTo": "pavel"
  }
},
      .. 
      }