Class ForwardChainExpectation
- Author:
- jamesdbloom
-
Method Summary
Modifier and TypeMethodDescriptionReturn error when expectation is matchedforward(ExpectationForwardCallback expectationForwardCallback) Call method on object locally or remotely (over web socket) to generate request to forward when expectation is matchedforward(ExpectationForwardCallback expectationForwardCallback, ExpectationForwardAndResponseCallback expectationForwardResponseCallback) Call method on object locally or remotely (over web socket) to generate request to forward when expectation is matchedforward(ExpectationForwardCallback expectationForwardCallback, ExpectationForwardAndResponseCallback expectationForwardResponseCallback, Delay delay) Call method on object locally or remotely (over web socket) to generate request to forward when expectation is matchedforward(ExpectationForwardCallback expectationForwardCallback, Delay delay) Call method on object locally or remotely (over web socket) to generate request to forward when expectation is matchedforward(HttpClassCallback httpClassCallback) Call method on local class in same JVM implementing ExpectationResponseCallback to generate request to forward when expectation is matchedforward(HttpForward httpForward) Forward request to the specified host and port when expectation is matchedforward(HttpOverrideForwardedRequest httpOverrideForwardedRequest) Override fields, headers, and cookies etc in request being forwarded with specified fields, headers and cookies, etc in the specified request when expectation is matchedforward(HttpTemplate httpTemplate) Evaluate Velocity or JavaScript template to generate request to forward when expectation is matchedforwardWithFallback(HttpForwardWithFallback httpForwardWithFallback) Forward request to the upstream host and return a fallback response when the upstream returns a configured status code (default 5xx) or times out.respond(List<HttpResponse> httpResponses) Set a list of responses to cycle through sequentially when expectation is matched.respond(ExpectationResponseCallback expectationResponseCallback) Call method on object locally or remotely (over web socket) to generate response to return when expectation is matchedrespond(ExpectationResponseCallback expectationResponseCallback, Delay delay) Call method on object locally or remotely (over web socket) to generate response to return when expectation is matchedrespond(HttpClassCallback httpClassCallback) Call method on local class in same JVM implementing ExpectationResponseCallback to generate response to return when expectation is matchedrespond(HttpResponse httpResponse) Return response when expectation is matchedrespond(HttpTemplate httpTemplate) Evaluate Velocity or JavaScript template to generate response to return when expectation is matchedrespondWithBinary(BinaryResponse binaryResponse) respondWithDns(DnsResponse dnsResponse) respondWithGrpcBidi(GrpcBidiResponse grpcBidiResponse) respondWithGrpcStream(GrpcStreamResponse grpcStreamResponse) respondWithLlm(HttpLlmResponse httpLlmResponse) respondWithSse(HttpSseResponse httpSseResponse) respondWithWebSocket(HttpWebSocketResponse httpWebSocketResponse) upsert()Submit the expectation to MockServer without setting any additional primary action.withAfterAction(AfterAction afterAction) Set a single after-action to execute after the primary action completeswithAfterActions(AfterAction... afterActions) withBeforeAction(AfterAction beforeAction) Set a single before-action to execute before the primary action.withBeforeActions(AfterAction... beforeActions) withChaos(HttpChaosProfile chaos) Set a declarative HTTP chaos/fault injection profile for this expectation.Set id of this expectation which can be used to update this expectation later or for clearing or verifying by expectation id.withNewScenarioState(String newScenarioState) withPercentage(Integer percentage) Set percentage of requests this expectation should match (0-100).withPriority(int priority) Set priority of this expectation which is used to determine the matching order of expectations when a request is received.withResponseMode(ResponseMode responseMode) withScenarioName(String scenarioName) Set the scenario name for stateful expectation matchingwithScenarioState(String scenarioState) withSteps(List<ExpectationStep> steps) Set an ordered list of steps for this expectation.withSteps(ExpectationStep... steps) Set an ordered list of steps for this expectation.
-
Method Details
-
withId
Set id of this expectation which can be used to update this expectation later or for clearing or verifying by expectation id.
Note: Each unique expectation must have a unique id otherwise this expectation will update a existing expectation with the same id.
- Parameters:
id- unique string for expectation's id
-
withPriority
Set priority of this expectation which is used to determine the matching order of expectations when a request is received.
Matching is ordered by priority (highest first) then creation (earliest first).
- Parameters:
priority- expectation's priority
-
withPercentage
Set percentage of requests this expectation should match (0-100).
When set, the expectation will only match the specified percentage of requests that structurally match, enabling probabilistic matching.
- Parameters:
percentage- percentage of requests to match (0-100), or null for all requests
-
withChaos
Set a declarative HTTP chaos/fault injection profile for this expectation.
When set, probabilistic error status injection and/or latency injection is applied to the response returned by the expectation's action.
- Parameters:
chaos- the chaos profile to apply, or null to disable chaos injection
-
withScenarioName
Set the scenario name for stateful expectation matching- Parameters:
scenarioName- the name of the scenario
-
withScenarioState
-
withNewScenarioState
-
withResponseMode
-
withBeforeActions
-
withBeforeAction
Set a single before-action to execute before the primary action. Blocking before-actions (the default) can gate the response via their failure policy and timeout.- Parameters:
beforeAction- the before-action to set
-
withAfterActions
-
withSteps
Set an ordered list of steps for this expectation. Steps provide a unified way to declare an ordered pipeline of side-effects and a single designated responder. Exactly one step must haveresponder = true. Steps that precede the responder run before the response; steps that follow run after.When steps are set, they supersede
beforeActions+ the primary response action for dispatch ordering. The primary action is still determined by the responder step's action type.- Parameters:
steps- the ordered steps
-
withSteps
Set an ordered list of steps for this expectation.- Parameters:
steps- the ordered steps- See Also:
-
withAfterAction
Set a single after-action to execute after the primary action completes- Parameters:
afterAction- the after-action to set
-
respond
Return response when expectation is matched- Parameters:
httpResponse- response to return- Returns:
- added or updated expectations
-
respond
Set a list of responses to cycle through sequentially when expectation is matched. Each match returns the next response in the list, cycling back to the first after the last.- Parameters:
httpResponses- list of responses to cycle through- Returns:
- added or updated expectations
-
respond
Evaluate Velocity or JavaScript template to generate response to return when expectation is matched- Parameters:
httpTemplate- Velocity or JavaScript template used to generate response- Returns:
- added or updated expectations
-
respond
Call method on local class in same JVM implementing ExpectationResponseCallback to generate response to return when expectation is matchedThe callback class must: - implement org.mockserver.mock.action.ExpectationResponseCallback - have a zero argument constructor - be available in the classpath of the MockServer
- Parameters:
httpClassCallback- class to callback as a fully qualified class name, i.e. "com.foo.MyExpectationResponseCallback"- Returns:
- added or updated expectations
-
respond
Call method on object locally or remotely (over web socket) to generate response to return when expectation is matched- Parameters:
expectationResponseCallback- object to call locally or remotely to generate response- Returns:
- added or updated expectations
-
respond
Call method on object locally or remotely (over web socket) to generate response to return when expectation is matched- Parameters:
expectationResponseCallback- object to call locally or remotely to generate response- Returns:
- added or updated expectations
-
forward
Forward request to the specified host and port when expectation is matched- Parameters:
httpForward- host and port to forward to- Returns:
- added or updated expectations
-
forward
Evaluate Velocity or JavaScript template to generate request to forward when expectation is matched- Parameters:
httpTemplate- Velocity or JavaScript template used to generate response- Returns:
- added or updated expectations
-
forward
Call method on local class in same JVM implementing ExpectationResponseCallback to generate request to forward when expectation is matchedThe callback class must: - implement org.mockserver.mock.action.ExpectationForwardCallback or org.mockserver.mock.action.ExpectationForwardAndResponseCallback - have a zero argument constructor - be available in the classpath of the MockServer
- Parameters:
httpClassCallback- class to callback as a fully qualified class name, i.e. "com.foo.MyExpectationResponseCallback"- Returns:
- added or updated expectations
-
forward
Call method on object locally or remotely (over web socket) to generate request to forward when expectation is matched- Parameters:
expectationForwardCallback- object to call locally or remotely to generate request- Returns:
- added or updated expectations
-
forward
public Expectation[] forward(ExpectationForwardCallback expectationForwardCallback, ExpectationForwardAndResponseCallback expectationForwardResponseCallback) Call method on object locally or remotely (over web socket) to generate request to forward when expectation is matched- Parameters:
expectationForwardCallback- object to call locally or remotely to generate request- Returns:
- added or updated expectations
-
forward
Call method on object locally or remotely (over web socket) to generate request to forward when expectation is matched- Parameters:
expectationForwardCallback- object to call locally or remotely to generate request- Returns:
- added or updated expectations
-
forward
public Expectation[] forward(ExpectationForwardCallback expectationForwardCallback, ExpectationForwardAndResponseCallback expectationForwardResponseCallback, Delay delay) Call method on object locally or remotely (over web socket) to generate request to forward when expectation is matched- Parameters:
expectationForwardCallback- object to call locally or remotely to generate request- Returns:
- added or updated expectations
-
forward
Override fields, headers, and cookies etc in request being forwarded with specified fields, headers and cookies, etc in the specified request when expectation is matched- Parameters:
httpOverrideForwardedRequest- contains request to override request being forwarded- Returns:
- added or updated expectations
-
forwardWithFallback
Forward request to the upstream host and return a fallback response when the upstream returns a configured status code (default 5xx) or times out.- Parameters:
httpForwardWithFallback- the forward-with-fallback action- Returns:
- added or updated expectations
-
error
Return error when expectation is matched- Parameters:
httpError- error to return- Returns:
- added or updated expectations
-
respondWithSse
-
respondWithLlm
-
respondWithWebSocket
-
respondWithGrpcStream
-
respondWithGrpcBidi
-
respondWithBinary
-
respondWithDns
-
upsert
Submit the expectation to MockServer without setting any additional primary action. This is the correct terminal call when the expectation's action is already fully defined by itssteps(the responder step defines the action). Using.respond()or.forward()would set a redundant top-level action that conflicts with the steps pipeline.- Returns:
- added or updated expectations
-