mock-server / mockserver

MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Ruby. MockServer also includes a proxy that introspects all proxied traffic including encrypted SSL traffic and supports Port Forwarding, Web Proxying (i.e. HTTP proxy), HTTPS Tunneling Proxying (using HTTP CONNECT) and SOCKS Proxying (i.e. dynamic port forwarding).
http://mock-server.com
Apache License 2.0
4.57k stars 1.07k forks source link

Request verification fails with incorrect error message. #73

Closed hydra closed 9 years ago

hydra commented 9 years ago

When the mock server is called with a bad request it responds with 404. Later in the test where the interactions with mock server are verified the expected request is shown via the AssertionError but it incorrectly states: ... but found no requests

This is not true as the mock server responded with 404 so there must have been a request.

This is a problem because it's then impossible to see the difference between the request that should have been made and what was made.

I'm not sure if this is by design, or if i'm not enabling a mock server feature but it's certainly not helpful when the assertion is raised.

From the logs:

2014-10-03 10:53:06,169 DEBUG [main] o.s.web.client.RestTemplate Created GET request for "http://phlmac-0180.mfuse.net:56283/gpapi?loginname=loginname1&password=password1&apiversion=1.2&clienttype=html5&gpid=1234&request=getbalance&opid&sessionid=AAD8EE30-8C43-11DC-9755-668156D89593&accountid=playerAccountId"
2014-10-03 10:53:06,192 WARN [main] o.s.web.client.RestTemplate GET request for "http://phlmac-0180.mfuse.net:56283/gpapi?loginname=loginname1&password=password1&apiversion=1.2&clienttype=html5&gpid=1234&request=getbalance&opid&sessionid=AAD8EE30-8C43-11DC-9755-668156D89593&accountid=playerAccountId" resulted in 404 (Not Found); invoking error handler

the assertion is:

java.lang.AssertionError: Expected {
  "method" : "GET",
  "path" : "/gpapi",
  "queryStringParameters" : [ {
    "name" : "request",
    "values" : [ "getbalance" ]
  }, {
    "name" : "sessionid",
    "values" : [ "AAD8EE30-8C43-11DC-9755-668156D89593" ]
  }, {
    "name" : "loginname",
    "values" : [ "loginname1" ]
  }, {
    "name" : "password",
    "values" : [ "password1" ]
  }, {
    "name" : "apiversion",
    "values" : [ "1.2" ]
  }, {
    "name" : "gpid",
    "values" : [ "1234" ]
  }, {
    "name" : "clienttype",
    "values" : [ "html5" ]
  }, {
    "name" : "opid",
    "values" : [ "opid" ]
  }, {
    "name" : "accountid",
    "values" : [ "playerAccountId" ]
  }, {
    "name" : "currency",
    "values" : [ "currencyCode" ]
  } ]
} but found no requests
    at org.mockserver.client.server.MockServerClient.verify(MockServerClient.java:254)
    at org.mockserver.client.server.MockServerClient.verify(MockServerClient.java:211)
    at org.mockserver.client.server.MockServerClient.verify(MockServerClient.java:184)
...

In this case, the currencyCode was missing from the request, but it's impossible to know that from the assertion.

I upgraded the project to the latest version of mock server.

The assertion report printed by http imposter - https://github.com/xelnaga/http-imposter - is much better in this regard because it allows you to see the difference between ALL the requests that were expected and ALL the requests that actually made, side-by-side, in the IDE using the assertion format that intellij can detect.

See also:

http://stackoverflow.com/questions/10934743/formatting-output-so-that-intellij-idea-shows-diffs-for-two-texts

hydra commented 9 years ago

Here's an example of the HttpImposterVerifier that I used, for reference:

https://gist.github.com/hydra/993530d78ad0c3901082

specifically, see line 47.

jamesdbloom commented 9 years ago

To improve this requires some refactoring and to remove verification logic from the client and put it (where it belongs) in the server side. This is the current bug / improvement I am now working on.

jamesdbloom commented 9 years ago

done - will be released once #74 is also completed as these both significantly improve the verification logic