public class Expectation extends ObjectWithJsonToString
Modifier and Type | Field and Description |
---|---|
static Comparator<Expectation> |
EXPECTATION_PRIORITY_COMPARATOR |
Constructor and Description |
---|
Expectation(RequestDefinition requestDefinition) |
Expectation(RequestDefinition requestDefinition,
Times times,
TimeToLive timeToLive,
Integer priority) |
Modifier and Type | Method and Description |
---|---|
Expectation |
clone() |
boolean |
contains(HttpRequest httpRequest) |
boolean |
decrementRemainingMatches() |
boolean |
equals(Object o) |
String[] |
fieldsExcludedFromEqualsAndHashCode() |
Action |
getAction() |
long |
getCreated() |
HttpError |
getHttpError() |
HttpForward |
getHttpForward() |
HttpClassCallback |
getHttpForwardClassCallback() |
HttpObjectCallback |
getHttpForwardObjectCallback() |
HttpTemplate |
getHttpForwardTemplate() |
HttpOverrideForwardedRequest |
getHttpOverrideForwardedRequest() |
RequestDefinition |
getHttpRequest() |
HttpResponse |
getHttpResponse() |
HttpClassCallback |
getHttpResponseClassCallback() |
HttpObjectCallback |
getHttpResponseObjectCallback() |
HttpTemplate |
getHttpResponseTemplate() |
String |
getId() |
Integer |
getPriority() |
Times |
getTimes() |
TimeToLive |
getTimeToLive() |
int |
hashCode() |
boolean |
isActive() |
Expectation |
thenError(HttpError httpError) |
Expectation |
thenForward(HttpClassCallback httpClassCallback) |
Expectation |
thenForward(HttpForward httpForward) |
Expectation |
thenForward(HttpObjectCallback httpObjectCallback) |
Expectation |
thenForward(HttpOverrideForwardedRequest httpOverrideForwardedRequest) |
Expectation |
thenForward(HttpTemplate httpTemplate) |
Expectation |
thenRespond(HttpClassCallback httpClassCallback) |
Expectation |
thenRespond(HttpObjectCallback httpObjectCallback) |
Expectation |
thenRespond(HttpResponse httpResponse) |
Expectation |
thenRespond(HttpTemplate httpTemplate) |
static Expectation |
when(HttpRequest httpRequest)
Specify the HttpRequest to match against as follows:
|
static Expectation |
when(HttpRequest httpRequest,
Integer priority)
Specify the HttpRequest to match against with a match priority as follows:
|
static Expectation |
when(HttpRequest httpRequest,
Times times,
TimeToLive timeToLive)
Specify the HttpRequest to match against for a limit number of times or time as follows:
|
static Expectation |
when(HttpRequest httpRequest,
Times times,
TimeToLive timeToLive,
Integer priority)
Specify the HttpRequest to match against for a limit number of times or time and a match priority as follows:
|
static Expectation |
when(String specUrlOrPayload,
String operationId)
Specify the OpenAPI and operationId to match against by URL or payload and string as follows:
|
static Expectation |
when(String specUrlOrPayload,
String operationId,
Integer priority)
Specify the OpenAPI and operationId to match against by URL or payload and string with a match priority as follows:
|
static Expectation |
when(String specUrlOrPayload,
String operationId,
Times times,
TimeToLive timeToLive)
Specify the OpenAPI and operationId to match against by URL or payload and string for a limit number of times or time as follows:
|
static Expectation |
when(String specUrlOrPayload,
String operationId,
Times times,
TimeToLive timeToLive,
Integer priority)
Specify the OpenAPI and operationId to match against by URL or payload and string for a limit number of times or time and a match priority as follows:
|
Expectation |
withCreated(long created) |
Expectation |
withId(String key) |
toString
public static final Comparator<Expectation> EXPECTATION_PRIORITY_COMPARATOR
public Expectation(RequestDefinition requestDefinition)
public Expectation(RequestDefinition requestDefinition, Times times, TimeToLive timeToLive, Integer priority)
public static Expectation when(String specUrlOrPayload, String operationId)
// Create from a publicly hosted HTTP location (json or yaml) when("https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore-expanded.yaml", "showPetById") // Create from a file on the local filesystem (json or yaml) when("file://Users/myuser/git/mockserver/mockserver-core/src/test/resources/org/mockserver/mock/openapi_petstore_example.json", "showPetById"); // Create from a classpath resource in the /api package (json or yaml) when("org/mockserver/mock/openapi_petstore_example.json", "showPetById"); // Create from an OpenAPI payload (json or yaml) when("{\"openapi\": \"3.0.0\", \"info\": { ...", "showPetById")
specUrlOrPayload
- the OpenAPI to match against by URL or payloadoperationId
- operationId from the OpenAPI to match against i.e. "showPetById"public static Expectation when(String specUrlOrPayload, String operationId, Integer priority)
// Create from a publicly hosted HTTP location (json or yaml) when("https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore-expanded.yaml", "showPetById", 10) // Create from a file on the local filesystem (json or yaml) when("file://Users/myuser/git/mockserver/mockserver-core/src/test/resources/org/mockserver/mock/openapi_petstore_example.json", "showPetById", 10); // Create from a classpath resource in the /api package (json or yaml) when("org/mockserver/mock/openapi_petstore_example.json", "showPetById", 10); // Create from an OpenAPI payload (json or yaml) when("{\"openapi\": \"3.0.0\", \"info\": { ...", "showPetById", 10)
specUrlOrPayload
- the OpenAPI to match against by URL or payloadoperationId
- operationId from the OpenAPI to match against i.e. "showPetById"priority
- the priority with which this expectation is used to match requests compared to other expectations (high first)public static Expectation when(String specUrlOrPayload, String operationId, Times times, TimeToLive timeToLive)
// Create from a publicly hosted HTTP location (json or yaml) when("https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore-expanded.yaml", "showPetById", 5, exactly(TimeUnit.SECONDS, 90)) // Create from a file on the local filesystem (json or yaml) when("file://Users/myuser/git/mockserver/mockserver-core/src/test/resources/org/mockserver/mock/openapi_petstore_example.json", "showPetById", 5, exactly(TimeUnit.SECONDS, 90)); // Create from a classpath resource in the /api package (json or yaml) when("org/mockserver/mock/openapi_petstore_example.json", "showPetById", 5, exactly(TimeUnit.SECONDS, 90)); // Create from an OpenAPI payload (json or yaml) when("{\"openapi\": \"3.0.0\", \"info\": { ...", "showPetById", 5, exactly(TimeUnit.SECONDS, 90))
specUrlOrPayload
- the OpenAPI to match against by URL or payloadoperationId
- operationId from the OpenAPI to match against i.e. "showPetById"times
- the number of times to use this expectation to match requeststimeToLive
- the time this expectation should be used to match requestspublic static Expectation when(String specUrlOrPayload, String operationId, Times times, TimeToLive timeToLive, Integer priority)
// Create from a publicly hosted HTTP location (json or yaml) when("https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore-expanded.yaml", "showPetById", 5, exactly(TimeUnit.SECONDS, 90)) // Create from a file on the local filesystem (json or yaml) when("file://Users/myuser/git/mockserver/mockserver-core/src/test/resources/org/mockserver/mock/openapi_petstore_example.json", "showPetById", 5, exactly(TimeUnit.SECONDS, 90)); // Create from a classpath resource in the /api package (json or yaml) when("org/mockserver/mock/openapi_petstore_example.json", "showPetById", 5, exactly(TimeUnit.SECONDS, 90)); // Create from an OpenAPI payload (json or yaml) when("{\"openapi\": \"3.0.0\", \"info\": { ...", "showPetById", 5, exactly(TimeUnit.SECONDS, 90))
specUrlOrPayload
- the OpenAPI to match against by URL or payloadoperationId
- operationId from the OpenAPI to match against i.e. "showPetById"times
- the number of times to use this expectation to match requeststimeToLive
- the time this expectation should be used to match requestspriority
- the priority with which this expectation is used to match requests compared to other expectations (high first)public static Expectation when(HttpRequest httpRequest)
when( request() .withMethod("GET") .withPath("/some/path") ).thenRespond( response() .withContentType(APPLICATION_JSON_UTF_8) .withBody("{\"some\": \"body\"}") );
httpRequest
- the HttpRequest to match againstpublic static Expectation when(HttpRequest httpRequest, Integer priority)
when( request() .withMethod("GET") .withPath("/some/path"), 10 ).thenRespond( response() .withContentType(APPLICATION_JSON_UTF_8) .withBody("{\"some\": \"body\"}") );
httpRequest
- the HttpRequest to match againstpriority
- the priority with which this expectation is used to match requests compared to other expectations (high first)public static Expectation when(HttpRequest httpRequest, Times times, TimeToLive timeToLive)
when( request() .withMethod("GET") .withPath("/some/path"), 5, exactly(TimeUnit.SECONDS, 90) ).thenRespond( response() .withContentType(APPLICATION_JSON_UTF_8) .withBody("{\"some\": \"body\"}") );
httpRequest
- the HttpRequest to match againsttimes
- the number of times to use this expectation to match requeststimeToLive
- the time this expectation should be used to match requestspublic static Expectation when(HttpRequest httpRequest, Times times, TimeToLive timeToLive, Integer priority)
when( request() .withMethod("GET") .withPath("/some/path"), 5, exactly(TimeUnit.SECONDS, 90), 10 ).thenRespond( response() .withContentType(APPLICATION_JSON_UTF_8) .withBody("{\"some\": \"body\"}") );
httpRequest
- the HttpRequest to match againsttimes
- the number of times to use this expectation to match requeststimeToLive
- the time this expectation should be used to match requestspriority
- the priority with which this expectation is used to match requests compared to other expectations (high first)public Expectation withId(String key)
public String getId()
public Integer getPriority()
public Expectation withCreated(long created)
public long getCreated()
public RequestDefinition getHttpRequest()
public HttpResponse getHttpResponse()
public HttpTemplate getHttpResponseTemplate()
public HttpClassCallback getHttpResponseClassCallback()
public HttpObjectCallback getHttpResponseObjectCallback()
public HttpForward getHttpForward()
public HttpTemplate getHttpForwardTemplate()
public HttpClassCallback getHttpForwardClassCallback()
public HttpObjectCallback getHttpForwardObjectCallback()
public HttpOverrideForwardedRequest getHttpOverrideForwardedRequest()
public HttpError getHttpError()
public Action getAction()
public Times getTimes()
public TimeToLive getTimeToLive()
public Expectation thenRespond(HttpResponse httpResponse)
public Expectation thenRespond(HttpTemplate httpTemplate)
public Expectation thenRespond(HttpClassCallback httpClassCallback)
public Expectation thenRespond(HttpObjectCallback httpObjectCallback)
public Expectation thenForward(HttpForward httpForward)
public Expectation thenForward(HttpTemplate httpTemplate)
public Expectation thenForward(HttpClassCallback httpClassCallback)
public Expectation thenForward(HttpObjectCallback httpObjectCallback)
public Expectation thenForward(HttpOverrideForwardedRequest httpOverrideForwardedRequest)
public Expectation thenError(HttpError httpError)
public boolean isActive()
public boolean decrementRemainingMatches()
public boolean contains(HttpRequest httpRequest)
public Expectation clone()
public String[] fieldsExcludedFromEqualsAndHashCode()
fieldsExcludedFromEqualsAndHashCode
in class ObjectWithReflectiveEqualsHashCodeToString
public boolean equals(Object o)
equals
in class ObjectWithReflectiveEqualsHashCodeToString
public int hashCode()
hashCode
in class ObjectWithReflectiveEqualsHashCodeToString
Copyright © 2020. All rights reserved.