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.54k stars 1.06k forks source link

Java client v5.14 doesn't verify correct calls anymore? #1457

Closed mamuf closed 1 year ago

mamuf commented 1 year ago

Hi, I've updated the MockServer Java client to 5.14 and my tests suddenly fail? I use the Spring Boot Test integration and now I get this:

2022-08-29 17:19:33.255 DEBUG 19928 --- [           main] c.w.f.f.ExchangeRatesService   : HTTP GET with date='08.09.2021' to http://localhost:64605/rates

java.lang.AssertionError: Request not found exactly once, expected:<{
  "path" : "/rates"
}> but was:<{
  "headers" : {
    "content-length" : [ "0" ],
    "Accept" : [ "text/plain" ],
    "Cache-Control" : [ "no-store" ],
    "content-encoding" : [ ".*" ],
    "host" : [ "localhost:64605" ],
    "User-Agent" : [ "dummy" ],
    "Referer" : [ "http://localhost:64605/rates" ],
    "accept-encoding" : [ "gzip" ]
  },
  "keepAlive" : true,
  "method" : "GET",
  "path" : "/rates",
  "queryStringParameters" : {
    "date" : [ "08.09.2021" ]
  },
  "secure" : false
}>

Note that I'm using Maven and Kotlin, but that shouldn't really matter.

This is the verify call that fails:

mockServerClient.verify(
    request()
        .withPath(exchangeRatePath)
        .withPathParameter("date", "10.09.2021"),
    once()
)

Interesting fact is that when I comment out either the withPath, or withPathParameter, it works! So why doesn't it work with more specific verification?

jamesdbloom commented 1 year ago

The verification you have provided doesn't look correct. You are requesting path parameters but your expectation is setting query parameters. That is why it is not matching. A bug was fixed with path parameter matching during verifications in the latest version which explains why you bug in your verification request is not correctly not working.

Please change your verification requests to use query parameter instead of path parameter and your code should work as expected.

mamuf commented 1 year ago

Oh, that explains it, it works. Thanks!