Clearing & Resetting
MockServer has internal state:
- recorded requests
- active expectations
- recorded expectations
- logs
State can be cleared from MockServer selectively:
- use type to select with type of state to clear
- use a request matcher to clear matching items
new MockServerClient("localhost", 1080).clear(
request()
.withPath("/some/path")
.withMethod("POST")
);
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
.clear({
'path': '/some/path'
})
.then(
function () {
console.log("cleared state that matches request matcher");
},
function (error) {
console.log(error);
}
);
curl -v -X PUT "http://localhost:1080/clear" -d '{
"path": "/some/path"
}'
new MockServerClient("localhost", 1080).clear(
request()
.withPath("/some/path")
.withMethod("POST"),
ClearType.LOG
);
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
.clear({
'path': '/some/path'
}, 'LOG')
.then(
function () {
console.log("cleared recorded requests and logs that matches request matcher");
},
function (error) {
console.log(error);
}
);
curl -v -X PUT "http://localhost:1080/clear?type=LOGS" -d '{
"path": "/some/path"
}'
new MockServerClient("localhost", 1080).clear(
request()
.withPath("/some/path")
.withMethod("POST"),
ClearType.EXPECTATIONS
);
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
.clear({
'path': '/some/path'
}, 'EXPECTATIONS')
.then(
function () {
console.log("cleared expectations that matches request matcher");
},
function (error) {
console.log(error);
}
);
curl -v -X PUT "http://localhost:1080/clear?type=EXPECTATIONS" -d '{
"path": "/some/path"
}'
MockServer can be reset completely, as follows:
new MockServerClient("localhost", 1080).reset();
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
.reset()
.then(
function () {
console.log("reset all state");
},
function (error) {
console.log(error);
}
);
curl -v -X PUT "http://localhost:1080/reset