Verifying Requests

MockServer supports verification of requests is has received, including both proxied requests and requests that have matched an expectation.

Verification can be specified as follows:

Verifying Repeating Requests

Verify that a request has been received by MockServer a specific number of times using a Verification

new MockServerClient("localhost", 1080)
 .verify(
 request()
 .withPath("/some/path"),
 VerificationTimes.atLeast(2)
 );
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
 .verify(
 {
 'path': '/some/path'
 }, 2)
 .then(
 function () {
 console.log("request found exactly 2 times");
 },
 function (error) {
 console.log(error);
 }
 );

See REST API for full JSON specification

curl -v -X PUT "http://localhost:1080/mockserver/verify" -d '{
 "httpRequest": {
 "path": "/simple"
 },
 "times": {
 "atLeast": 2
 }
}'

See REST API for full JSON specification

new MockServerClient("localhost", 1080)
.verify(
 request()
 .withPath("/some/path"),
 VerificationTimes.atMost(2)
);
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
.verify(
{
 'path': '/some/path'
}, 0, 2)
.then(
function () {
 console.log("request found exactly 2 times");
},
function (error) {
 console.log(error);
}
);

See REST API for full JSON specification

curl -v -X PUT "http://localhost:1080/mockserver/verify" -d '{
 "httpRequest": {
 "path": "/simple"
 },
 "times": {
 "atMost": 2
 }
}'

See REST API for full JSON specification

new MockServerClient("localhost", 1080)
 .verify(
 request()
 .withPath("/some/path"),
 VerificationTimes.exactly(2)
 );
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
 .verify(
 {
 'path': '/some/path'
 }, 2, 2)
 .then(
 function () {
 console.log("request found exactly 1 times");
 },
 function (error) {
 console.log(error);
 }
 );

See REST API for full JSON specification

curl -v -X PUT "http://localhost:1080/mockserver/verify" -d '{
 "httpRequest": {
 "path": "/simple"
 },
 "times": {
 "atLeast": 2,
 "atMost": 2
 }
}'

See REST API for full JSON specification

new MockServerClient("localhost", 1080)
 .verify(
 openAPI(
 "https://raw.githubusercontent.com/mock-server/mockserver/master/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json"
 ),
 VerificationTimes.atLeast(2)
 );
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
 .verify(
 {
 'specUrlOrPayload': 'https://raw.githubusercontent.com/mock-server/mockserver/master/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json'
 }, 2)
 .then(
 function () {
 console.log("request found exactly 2 times");
 },
 function (error) {
 console.log(error);
 }
 );

See REST API for full JSON specification

curl -v -X PUT "http://localhost:1080/mockserver/verify" -d '{
 "httpRequest": {
 "specUrlOrPayload": "https://raw.githubusercontent.com/mock-server/mockserver/master/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json"
 },
 "times": {
 "atLeast": 2
 }
}'

See REST API for full JSON specification

new MockServerClient("localhost", 1080)
 .verify(
 openAPI(
 "org/mockserver/openapi/openapi_petstore_example.json",
 "showPetById"
 ),
 VerificationTimes.once()
 );
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
 .verify(
 {
 'specUrlOrPayload': 'org/mockserver/openapi/openapi_petstore_example.json',
 'operationId': 'showPetById'
 }, 1, 1)
 .then(
 function () {
 console.log("request found exactly 2 times");
 },
 function (error) {
 console.log(error);
 }
 );

See REST API for full JSON specification

curl -v -X PUT "http://localhost:1080/mockserver/verify" -d '{
 "httpRequest": {
 "specUrlOrPayload": "org/mockserver/openapi/openapi_petstore_example.json",
 "operationId": "showPetById"
 },
 "times": {
 "atLeast": 1,
 "atMost": 1
 }
}'

See REST API for full JSON specification

new MockServerClient("localhost", 1080)
 .verify(
 "31e4ca35-66c6-4645-afeb-6e66c4ca0559",
 VerificationTimes.once()
 );
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
 .verifyById(
 {
 'id': '31e4ca35-66c6-4645-afeb-6e66c4ca0559'
 }, 1, 1)
 .then(
 function () {
 console.log("request found exactly 2 times");
 },
 function (error) {
 console.log(error);
 }
 );

See REST API for full JSON specification

curl -v -X PUT "http://localhost:1080/mockserver/verify" -d '{
 "id": "31e4ca35-66c6-4645-afeb-6e66c4ca0559"
 }'

See REST API for full JSON specification

new MockServerClient("localhost", 1080)
 .verify(
 request()
 .withPath("/some/path"),
 VerificationTimes.exactly(0)
 );
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
 .verify(
 {
 'path': '/some/path'
 }, 0, true)
 .then(
 function () {
 console.log("request found zero times");
 },
 function (error) {
 console.log(error);
 }
 );

See REST API for full JSON specification

curl -v -X PUT "http://localhost:1080/mockserver/verify" -d '{
 "httpRequest": {
 "path": "/simple"
 },
 "times": {
 "atMost": 0
 }
}'

See REST API for full JSON specification

Verifying Request Sequences

Verify that a sequence of requests has been received by MockServer in the specified order using a VerificationSequence

The each request in the sequence will be verified to have been received at least once, in the exact order specified.

new MockServerClient("localhost", 1080)
 .verify(
 request()
 .withPath("/some/path/one"),
 request()
 .withPath("/some/path/two"),
 request()
 .withPath("/some/path/three")
 );
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
 .verifySequence(
 {
 'path': '/some/path/one'
 },
 {
 'path': '/some/path/two'
 },
 {
 'path': '/some/path/three'
 }
 )
 .then(
 function () {
 console.log("request sequence found in the order specified");
 },
 function (error) {
 console.log(error);
 }
 );

See REST API for full JSON specification

curl -v -X PUT "http://localhost:1080/mockserver/verifySequence" -d '{
 "httpRequests":[
 {
 "path":"/some/path/one"
 },
 {
 "path":"/some/path/two"
 },
 {
 "path":"/some/path/three"
 }
 ]
}'

See REST API for full JSON specification

new MockServerClient("localhost", 1080)
 .verify(
 request()
 .withPath("/status"),
 openAPI(
 "org/mockserver/openapi/openapi_petstore_example.json",
 "listPets"
 ),
 openAPI(
 "org/mockserver/openapi/openapi_petstore_example.json",
 "showPetById"
 )
 );
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
 .verifySequence(
 {
 'path': '/status'
 },
 {
 'specUrlOrPayload': 'org/mockserver/openapi/openapi_petstore_example.json',
 'operationId': 'listPets'
 },
 {
 'specUrlOrPayload': 'org/mockserver/openapi/openapi_petstore_example.json',
 'operationId': 'showPetById'
 }
 )
 .then(
 function () {
 console.log("request sequence found in the order specified");
 },
 function (error) {
 console.log(error);
 }
 );

See REST API for full JSON specification

curl -v -X PUT "http://localhost:1080/mockserver/verifySequence" -d '{
 "httpRequests":[
 {
 "path": "/status"
 },
 {
 "specUrlOrPayload": "org/mockserver/openapi/openapi_petstore_example.json",
 "operationId": "listPets"
 },
 {
 "specUrlOrPayload": "org/mockserver/openapi/openapi_petstore_example.json",
 "operationId": "showPetById"
 }
 ]
}'

See REST API for full JSON specification

new MockServerClient("localhost", 1080)
 .verify(
 "31e4ca35-66c6-4645-afeb-6e66c4ca0559",
 "66c6ca35-ca35-66f5-8feb-5e6ac7ca0559",
 "ca3531e4-23c8-ff45-88f5-4ca0c7ca0559"
 );
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
 .verifySequenceById(
 {
 'id': '31e4ca35-66c6-4645-afeb-6e66c4ca0559'
 },
 {
 'id': '66c6ca35-ca35-66f5-8feb-5e6ac7ca0559'
 },
 {
 'id': 'ca3531e4-23c8-ff45-88f5-4ca0c7ca0559'
 }
 )
 .then(
 function () {
 console.log("request sequence found in the order specified");
 },
 function (error) {
 console.log(error);
 }
 );

See REST API for full JSON specification

curl -v -X PUT "http://localhost:1080/mockserver/verifySequence" -d '{
 "id": "31e4ca35-66c6-4645-afeb-6e66c4ca0559"
 },
 {
 "id": "66c6ca35-ca35-66f5-8feb-5e6ac7ca0559"
 },
 {
 "id": "ca3531e4-23c8-ff45-88f5-4ca0c7ca0559"
 }'

See REST API for full JSON specification

AltStyle によって変換されたページ (->オリジナル) /