7

Wiremock 记录以下请求不匹配:

    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]*$"
    }
  }
}

问题是因为 url 和 urlPath 的不同吗?我还尝试在合同中指定 absoluteUrl。但它被忽略了。我猜是因为它没有在合同 DSL 中定义。

合约的请求方如下所示:

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')))
        }
    }
4

2 回答 2

7

原来是合同/存根中 URL 末尾缺少 /

于 2017-07-22T13:59:11.847 回答
1

与问题没有直接关系,但对于所有从谷歌来到这里的人:

就我而言,我处于错误的场景状态。

更多关于场景状态的信息:http ://wiremock.org/docs/stateful-behaviour/

于 2019-10-29T18:00:27.073 回答