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

Removing specific expectations #42

Closed ninckblokje closed 10 years ago

ninckblokje commented 10 years ago

Hi,

I have a question concerning the removing of specific expectations. Is it possible to remove a single expectation for a specific path?

For example: I have set an expectation for path /test with an XPath body match on //test=1. I have set a second expectation for path /test with an XPath body match on //test=2. Is it possible to remove the first expectation without removing the second one, even if no message has been received by the mock server?

Jeroen

jamesdbloom commented 10 years ago

Yes it is possible, if you use the clear function it will only remove the expectations that exactly match the request you provide, i.e:

mockServerClient.clear(
        request()
                .withPath("/test")
                .withBody(xpath("//test=1"))
);
ninckblokje commented 10 years ago

Hi,

Thanks for the quick response! When I try that using JSON the expectations appears to remain.

My JSON for setting the expectation looks like this: httpRequest": { "method": "POST", "path": "/test", "body": { "type": "XPATH", "value": "//test=1" }, "headers": [ { "name": "SOAPAction", "values": ["\"\""] } ] }, "httpResponse": { "statusCode": 200, "headers": [ { "name": "Content-Type", "values": ["application/soap+xml; charset=utf-8"] } ], "body": "[SOME_SOAP_ENVELOPE]" }

My JSON for removing the expectation looks like this: { "method": "POST", "path": "/test", "body": { "type": "XPATH", "value": "//test=1" }, "headers": [ { "name": "SOAPAction", "values": ["\"\""] } ] }

When I ommit the body part the expectation is removed.

Jeroen

jamesdbloom commented 10 years ago

ok I'll take a look

jamesdbloom commented 10 years ago

I've been away this weekend but I'll take a look in the next couple of days and add extra tests to make sure there aren't any bugs (or fix them if there are).

jamesdbloom commented 10 years ago

I resolved the issue and added a test for this scenario