MockServer has the following 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

When logLevel is set to DEBUG using clear does not delete logs from the event log, instead they are marked as deleted to ensure verification continues to work correctly. This allows the UI to continue to display logs that would have otherwise been deleted to improve the ability to debug issues.

new MockServerClient("localhost", 1080).clear(
    request()
        .withPath("/some/path")
);
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);
    }
  );

See REST API for full JSON specification

curl -v -X PUT "http://localhost:1080/mockserver/clear" -d '{
    "path": "/some/path"
}'

See REST API for full JSON specification

new MockServerClient("localhost", 1080).clear(
    openAPI(
        "https://raw.githubusercontent.com/mock-server/mockserver/master/mockserver-integration-testing/src/main/resources/org/mockserver/mock/openapi_petstore_example.json",
        "showPetById"
    )
);
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
    .clear({
        "specUrlOrPayload": "https://raw.githubusercontent.com/mock-server/mockserver/master/mockserver-integration-testing/src/main/resources/org/mockserver/mock/openapi_petstore_example.json",
        "operationId": "showPetById"
    })
    .then(
        function () {
            console.log("cleared state that matches request matcher");
        },
        function (error) {
            console.log(error);
        }
    );

See REST API for full JSON specification

curl -v -X PUT "http://localhost:1080/mockserver/clear" -d '{
        "specUrlOrPayload": "https://raw.githubusercontent.com/mock-server/mockserver/master/mockserver-integration-testing/src/main/resources/org/mockserver/mock/openapi_petstore_example.json",
        "operationId": "showPetById"
    }'

See REST API for full JSON specification

new MockServerClient("localhost", 1080).clear(
    request()
        .withPath("/some/path"),
    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);
    }
  );

See REST API for full JSON specification

curl -v -X PUT "http://localhost:1080/mockserver/clear?type=LOGS" -d '{
    "path": "/some/path"
}'

See REST API for full JSON specification

new MockServerClient("localhost", 1080).clear(
    openAPI(
        "https://raw.githubusercontent.com/mock-server/mockserver/master/mockserver-integration-testing/src/main/resources/org/mockserver/mock/openapi_petstore_example.json",
        "showPetById"
    ),
    ClearType.LOG
);
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
    .clear({
        "specUrlOrPayload": "https://raw.githubusercontent.com/mock-server/mockserver/master/mockserver-integration-testing/src/main/resources/org/mockserver/mock/openapi_petstore_example.json",
        "operationId": "showPetById"
    }, 'LOG')
    .then(
        function () {
            console.log("cleared state that matches request matcher");
        },
        function (error) {
            console.log(error);
        }
    );

See REST API for full JSON specification

curl -v -X PUT "http://localhost:1080/mockserver/clear?type=LOGS" -d '{
        "specUrlOrPayload": "https://raw.githubusercontent.com/mock-server/mockserver/master/mockserver-integration-testing/src/main/resources/org/mockserver/mock/openapi_petstore_example.json",
        "operationId": "showPetById"
    }'

See REST API for full JSON specification

new MockServerClient("localhost", 1080).clear(
    request()
        .withPath("/some/path"),
    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);
    }
  );

See REST API for full JSON specification

curl -v -X PUT "http://localhost:1080/mockserver/clear?type=EXPECTATIONS" -d '{
    "path": "/some/path"
}'

See REST API for full JSON specification

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);
    }
  );

See REST API for full JSON specification

curl -v -X PUT "http://localhost:1080/mockserver/reset

See REST API for full JSON specification