mock-server / mockserver-client-node

MockServer javascript client for browsers, Node.js or any grunt build
http://mock-server.com
Apache License 2.0
72 stars 34 forks source link

retrieveActiveExpectations not matching all active expectations #20

Closed bulkan closed 6 years ago

bulkan commented 6 years ago

Hi there,

I'm setting up 18 expectations and when I try to use retrieveActiveExpectations it returns only 17 of them with one missing.

I've used this example and using mockserver-client@5.2.3

Checking the mockserver logs I see the following;

 did not match expectation:

        {
          "method" : "GET",
          "path" : "/app/web-api/projects/1879048400/users",
          "queryStringParameters" : {
            "query" : [ ".*" ]
          }
        }

 because:

        method matches = true
        path matches = true
        query string parameters match = false
        body matches = true
        headers match = true
        cookies match = true
        keep-alive matches = true
        ssl matches = true

The only difference I can see is that the other expectations don't set a queryStringParameter.

I would have thought all recorded expectations are sent back ?

jamesdbloom commented 6 years ago
        {
          "method" : "GET",
          "path" : "/app/web-api/projects/1879048400/users",
          "queryStringParameters" : {
            "query" : [ ".*" ]
          }
        }

matches a request with a query string containing a parameter called query, for example, one of the following:

/app/web-api/projects/1879048400/users?query=someRandomValue
/app/web-api/projects/1879048400/users?query=someRandomValue&someOtherQuery=someRandomValue
/app/web-api/projects/1879048400/users?query=

Is that what you expected?

Can you please provide details of the expectations you are creating and requests you sending then I can help you debug your issue.

JassiSaini commented 6 years ago

I'm also facing a similar issue, using (version 5.3.0) I'm trying to Retrieve Active Expectations using following code -

HttpRequest request = new HttpRequest (); Expectation[] activeExpectations = new MockServerClient("localhost",1080).retrieveActiveExpectations(request);

But this doesn't return Expectations with "Query Parameters". Log has following message -

2018-01-04 18:39:31,930 INFO [nioEventLoopGroup-3-1] o.mockserver.mock.HttpStateHandler [?:?] retrieving active_expectations in json that match: { } 2018-01-04 18:39:31,935 INFO [nioEventLoopGroup-3-1] o.mockserver.mock.HttpStateHandler [?:?] request: { } did not match expectation: { "method" : "POST", "path" : "/Jassi", "queryStringParameters" : { "user" : [ "12345" ] } }

because:

method matches = true path matches = true query string parameters match = false body matches = true headers match = true cookies match = true keep-alive matches = true ssl matches = true

Since am not specifying any criteria, I'm expecting it to return all the Expectations, including the ones with QueryParameters.

jamesdbloom commented 6 years ago

I'll look into this

jamesdbloom commented 6 years ago

I have found the issue and I am resolving it.

jamesdbloom commented 6 years ago

It turns out the fix was more complex then I had hoped. It is now fixed in the current snapshot version. I will release a new version in the next few weeks once I have completed work on a UI.