Package org.opentestfactory.test.harness
Class ExpectedOutputReceiver
java.lang.Object
org.opentestfactory.test.harness.ExpectedOutputReceiver
This class may be used to define expectations on output messages from a given service. When
expectations are setup, call the system under test THEN call
waitAndVerifyExpectedCall(Duration) on your ExpectedOutputReceiver instance to check
if the expected messages where received (and optionally, check that no unwanted message was
received).-
Constructor Summary
ConstructorsConstructorDescriptionExpectedOutputReceiver(org.mockserver.integration.ClientAndServer mockServer) Create an original receiver instance based on a given mock server.ExpectedOutputReceiver(org.mockserver.integration.ClientAndServer mockServer, List<org.mockserver.model.HttpRequest> expectedRequests, List<org.mockserver.model.HttpRequest> unwantedRequests, JsonVariableMappings variableMappings, boolean ignoreArrayOrder) Create a complete expectation definition. -
Method Summary
Modifier and TypeMethodDescriptionstatic ExpectedOutputReceiverbasedOnMock(org.mockserver.integration.ClientAndServer mockServer) Static factory method to create an initial based on the given mock server.mappings()Wait some time to give time for callbacks, then verify if expected requests were received, and check that no unwanted request came.withExpectedRequests(org.mockserver.model.HttpRequest... expectedRequests) withExpectedRequestTemplate(String path, InputStream bodyStream) Create a receiver that ignores array element order.withMockAttachment(String attachmentResourceName) Tells the mockserver to serve said resource.withUnwantedRequests(org.mockserver.model.HttpRequest... unwantedRequests) withVariableMapping(String key, String value) Add variable mappings to build expected requests. the variable must be inserted on its own line as #{key} as the value of a json property.
-
Constructor Details
-
ExpectedOutputReceiver
public ExpectedOutputReceiver(org.mockserver.integration.ClientAndServer mockServer) Create an original receiver instance based on a given mock server.- Parameters:
mockServer- the server object to use.
-
ExpectedOutputReceiver
public ExpectedOutputReceiver(org.mockserver.integration.ClientAndServer mockServer, List<org.mockserver.model.HttpRequest> expectedRequests, List<org.mockserver.model.HttpRequest> unwantedRequests, JsonVariableMappings variableMappings, boolean ignoreArrayOrder) Create a complete expectation definition.- Parameters:
mockServer- the mock server instance to use.expectedRequests- aListof expectedHttpRequests : the receiver will verify that it got each request at least once after the wait delay.unwantedRequests- aListof unwantedHttpRequests : the receiver will chaque that it was sent NONE of these requests after the wait delay.variableMappings- aJsonVariableMappingsdescribing key-value variableMappings to replace in JSON request templates.- See Also:
-
-
Method Details
-
basedOnMock
public static ExpectedOutputReceiver basedOnMock(org.mockserver.integration.ClientAndServer mockServer) Static factory method to create an initial based on the given mock server. This is for use in combination with thewithExpectedRequests(HttpRequest...)andwithUnwantedRequests(HttpRequest...)to build a configured receiver instance.- Parameters:
mockServer- the mock server to use.- Returns:
- the instance.
-
withVariableMapping
Add variable mappings to build expected requests. the variable must be inserted on its own line as #{key} as the value of a json property. The mapping must appear on its own line in the template, like this (if there is no other property after it):"property": #{key}or like this (if there is a property after it):"property": #{key},- Parameters:
key- the key to replace. This must be an az-AZ-09+ string.value- the textual value by which to replace the variable construct.- Returns:
- the new
ExpectedOutputReceiverinstance.
-
withMockAttachment
public ExpectedOutputReceiver withMockAttachment(String attachmentResourceName) throws IOException, URISyntaxException Tells the mockserver to serve said resource. A mapping will be added for envelope substitution (the mappng key will be base on the resource name with slashes replaced by underscores, the value the exposed URL).- Parameters:
attachmentResourceName- the resource name. If this matchs no known resource, anUnknownTestResourceexception will be thrown.- Returns:
- the new receiver with a mapping for the resource URL.
- Throws:
IOException- if resource access fails (may happen)URISyntaxException- if the computed attachemnt URI is invalid (should NEVER happen)
-
withExpectedRequestTemplate
public ExpectedOutputReceiver withExpectedRequestTemplate(String path, InputStream bodyStream) throws IOException - Throws:
IOException
-
withExpectedRequests
public ExpectedOutputReceiver withExpectedRequests(org.mockserver.model.HttpRequest... expectedRequests) -
withUnwantedRequests
public ExpectedOutputReceiver withUnwantedRequests(org.mockserver.model.HttpRequest... unwantedRequests) -
waitAndVerifyExpectedCall
Wait some time to give time for callbacks, then verify if expected requests were received, and check that no unwanted request came.- Parameters:
delay- the base delay. A duration factor is applied based onTestConfiguration.getDurationFactorPercent().- Returns:
- Throws:
InterruptedException- See Also:
-
withIgnoreArrayElementOrder
Create a receiver that ignores array element order. The default behavior is to check for array element order.- Returns:
-
mappings
-