Package org.opentestfactory.test.harness
Class AbstractMicroServiceTestBase
java.lang.Object
org.opentestfactory.test.harness.AbstractMicroServiceTestBase
- Direct Known Subclasses:
AbstractMicroserviceIntegrationTest
This class offers base microservice test primitives. It also automatically starts the mock before
each test, and stops it after each test.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enumIt so happens that YAML is not a supported content type for org.apache.http.entity.ContentType so we need to have our content type model here :/ -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionAbstractMicroServiceTestBase(int receiverPort, URL sutBaseUrl, AuthToken serviceAuthToken) -
Method Summary
Modifier and TypeMethodDescriptionprotected ExpectedOutputReceiverCreate anExpectedOutputReceiverinstance with the base setup from this test class.protected SUTSenderjsonRESTPost(String testMessageResourceName, URI sutURI, JsonVariableMappings variableMappings, AuthToken sutAuthToken) Send a JSON test input message to the SUT.static voidprotected SUTSenderpostJSONToSUTendPoint(String messageName, String sutEndpointPath, JsonVariableMappings variables) Post a JSON test input to the specified endpoint.protected SUTSenderpostYAMLToSUTendPoint(String messageName, String sutEndpointPath) Post a YAML test input to the specified endpoint.protected org.mockserver.model.HttpRequestrequestMatcher(String pathOfMock, String expectedPayloadName) Build a request matcher for theExpectedOutputReceiverinstance.protected SUTSendersendTemplatedTestMessage(String testMessageResourceName, JsonVariableMappings variableMappings) Send a test input message built from template to the SUT bus.protected SUTSendersendTestMessage(String testMessageResourceName) Send a test input message to the SUT bus.voidvoidprotected JsonVariableMappingssubscriptionMappings(String subscriptionName) protected StringsubscriptionPath(String subscriptionName) protected InputStreamuseTestResource(String resourceName)
-
Field Details
-
DELAY_BEFORE_ASYNC_REQUEST_VERIFY
-
DELAY_BEFORE_ASYNC_REQUEST_SEQUENCE_VERIFY
-
DELAY_FOR_SSH
-
AUTH_TOKEN_KEY_SUFFIX
- See Also:
-
URL_KEY_SUFFIX
- See Also:
-
EVENTBUS_BASE_KEY
- See Also:
-
SUBSCRIPTIONS_PATH
- See Also:
-
BUS_BASE_URL
-
BUS_AUTH_TOKEN
-
serviceAuthToken
-
mockServer
protected org.mockserver.integration.ClientAndServer mockServer
-
-
Constructor Details
-
AbstractMicroServiceTestBase
- Parameters:
receiverPort- TCP port on which the test receiver will listen to expected (or unwanted) messages. Try to use different ones across tests, to isolate tests and make results easier to read.sutBaseUrl- base URL from which the system under test will receive test inputs.
-
-
Method Details
-
mockServerWarmUp
- Throws:
InterruptedException
-
startClientAndServer
- Throws:
InterruptedException
-
stopClientAndServer
- Throws:
InterruptedException
-
sendTemplatedTestMessage
protected SUTSender sendTemplatedTestMessage(String testMessageResourceName, JsonVariableMappings variableMappings) throws URISyntaxException, IOException Send a test input message built from template to the SUT bus.- Parameters:
testMessageResourceName- the template with value placeholders as defined byJsonVariableMappings.variableMappings- the mappings to apply.- Returns:
- SUTSender object to test response code.
- Throws:
URISyntaxExceptionIOException
-
sendTestMessage
protected SUTSender sendTestMessage(String testMessageResourceName) throws IOException, URISyntaxException Send a test input message to the SUT bus.- Parameters:
testMessageResourceName- message content to send.- Returns:
- reference to the SUTSender object for further actions like checking HTTP return codes.
- Throws:
IOExceptionURISyntaxException
-
jsonRESTPost
protected SUTSender jsonRESTPost(String testMessageResourceName, URI sutURI, JsonVariableMappings variableMappings, AuthToken sutAuthToken) throws IOException Send a JSON test input message to the SUT.- Parameters:
testMessageResourceName- message content to sendsutURI- URI of the destination endpointvariableMappings-- Returns:
- reference to the SUTSender object for further actions like checking HTTP return codes.
- Throws:
IOException
-
requestMatcher
protected org.mockserver.model.HttpRequest requestMatcher(String pathOfMock, String expectedPayloadName) throws IOException Build a request matcher for theExpectedOutputReceiverinstance.- Parameters:
pathOfMock-expectedPayloadName-- Returns:
- Throws:
IOException
-
useTestResource
-
getExpectedOutputReceiver
Create anExpectedOutputReceiverinstance with the base setup from this test class.- Returns:
-
postJSONToSUTendPoint
protected SUTSender postJSONToSUTendPoint(String messageName, String sutEndpointPath, JsonVariableMappings variables) throws URISyntaxException, IOException Post a JSON test input to the specified endpoint.- Parameters:
messageName- name of the test resource to send, as foruseTestResource(String)sutEndpointPath- end point to post the json to.- Returns:
- reference to the
SUTSenderobject for further actions like checking HTTP return codes. - Throws:
URISyntaxExceptionIOException
-
postYAMLToSUTendPoint
protected SUTSender postYAMLToSUTendPoint(String messageName, String sutEndpointPath) throws URISyntaxException, IOException Post a YAML test input to the specified endpoint.- Parameters:
messageName- name of the test resource to send, as foruseTestResource(String)sutEndpointPath- end point to post the json to.- Returns:
- reference to the
SUTSenderobject for further actions like checking HTTP return codes. - Throws:
URISyntaxExceptionIOException
-
subscriptionMappings
- Throws:
IOException
-
subscriptionPath
- Throws:
IOException
-