Class TestingFramework
java.lang.Object
org.apache.hc.core5.testing.framework.TestingFramework
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ClientTestingAdapterUse the ALL_METHODS list to conveniently cycle through all HTTP methods.static final ObjectIf anClassicTestClientTestingAdapteris unable to return a response in the format this testing framework is needing, then it will need to check the item in the response (such as body, status, headers, or contentType) itself and set the returned value of the item as ALREADY_CHECKED.static final StringIf a test does not specify a body, this one is used.static final StringIf a test does not specify a request contentType, this one is used.If a test does not specify a request headers, these are used.static final StringIf a test does not specify a path, this one is used.static final ProtocolVersionIf a test does not specify a protocol version, this one is used.If a test does not specify query parameters, these are used.static final StringIf a test does not specify an expected response body, this one is used.static final StringIf a test does not specify an expected response contentType, this one is used.If a test does not specify expected response headers, these are used.static final intIf a test does not specify an expected response status, this one is used.private intprivate TestingFrameworkRequestHandlerprivate HttpServerprivate List<FrameworkTest> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddTest()Call to add a test with defaults.voidCall to add a test.private voidassertBodyMatchesExpectation(Object actualBody, Object expectedBody) private voidassertContentTypeMatchesExpectation(Object actualContentType, Object expectedContentType) private voidprivate voidassertResponseMatchesExpectation(Object method, Map<String, Object> actualResponse, Map<String, Object> expectedResponse) private voidassertStatusMatchesExpectation(Object actualStatus, Object expectedStatus) private voidcallAdapter(FrameworkTest test) static ObjectUsed to make a "deep" copy of an object.voidDeletes all tests.private Stringprivate voidprocessThrowable(Throwable t, FrameworkTest test) voidrunTests()Run the tests that have been previously added.voidsetAdapter(ClientTestingAdapter adapter) Sets theClientTestingAdapter.voidsetRequestHandler(TestingFrameworkRequestHandler requestHandler) This is not likely to be used except during the testing of this class.private voidprivate void
-
Field Details
-
ALL_METHODS
Use the ALL_METHODS list to conveniently cycle through all HTTP methods. -
ALREADY_CHECKED
If anClassicTestClientTestingAdapteris unable to return a response in the format this testing framework is needing, then it will need to check the item in the response (such as body, status, headers, or contentType) itself and set the returned value of the item as ALREADY_CHECKED. -
DEFAULT_REQUEST_PATH
If a test does not specify a path, this one is used.- See Also:
-
DEFAULT_REQUEST_BODY
If a test does not specify a body, this one is used.- See Also:
-
DEFAULT_REQUEST_CONTENT_TYPE
If a test does not specify a request contentType, this one is used.- See Also:
-
DEFAULT_REQUEST_QUERY
If a test does not specify query parameters, these are used. -
DEFAULT_REQUEST_HEADERS
If a test does not specify a request headers, these are used. -
DEFAULT_REQUEST_PROTOCOL_VERSION
If a test does not specify a protocol version, this one is used. -
DEFAULT_RESPONSE_STATUS
public static final int DEFAULT_RESPONSE_STATUSIf a test does not specify an expected response status, this one is used.- See Also:
-
DEFAULT_RESPONSE_BODY
If a test does not specify an expected response body, this one is used.- See Also:
-
DEFAULT_RESPONSE_CONTENT_TYPE
If a test does not specify an expected response contentType, this one is used.- See Also:
-
DEFAULT_RESPONSE_HEADERS
If a test does not specify expected response headers, these are used. -
adapter
-
requestHandler
-
tests
-
server
-
port
private int port
-
-
Constructor Details
-
TestingFramework
- Throws:
TestingFrameworkException
-
TestingFramework
- Throws:
TestingFrameworkException
-
-
Method Details
-
setRequestHandler
This is not likely to be used except during the testing of this class. It is used to inject a mocked request handler.- Parameters:
requestHandler-
-
runTests
Run the tests that have been previously added. First, an in-processHttpServeris started. Then, all the tests are completed by passing each test to the adapter which will make the HTTP request.- Throws:
TestingFrameworkException- if there is a test failure or unexpected problem.
-
processThrowable
- Throws:
TestingFrameworkException
-
startServer
- Throws:
TestingFrameworkException
-
stopServer
private void stopServer() -
callAdapter
- Throws:
TestingFrameworkException
-
assertResponseMatchesExpectation
private void assertResponseMatchesExpectation(Object method, Map<String, Object> actualResponse, Map<String, throws TestingFrameworkExceptionObject> expectedResponse) - Throws:
TestingFrameworkException
-
assertStatusMatchesExpectation
private void assertStatusMatchesExpectation(Object actualStatus, Object expectedStatus) throws TestingFrameworkException - Throws:
TestingFrameworkException
-
assertBodyMatchesExpectation
private void assertBodyMatchesExpectation(Object actualBody, Object expectedBody) throws TestingFrameworkException - Throws:
TestingFrameworkException
-
assertContentTypeMatchesExpectation
private void assertContentTypeMatchesExpectation(Object actualContentType, Object expectedContentType) throws TestingFrameworkException - Throws:
TestingFrameworkException
-
assertHeadersMatchExpectation
private void assertHeadersMatchExpectation(Map<String, String> actualHeaders, Map<String, throws TestingFrameworkExceptionString> expectedHeaders) - Throws:
TestingFrameworkException
-
getDefaultURI
-
setAdapter
Sets theClientTestingAdapter.- Parameters:
adapter-
-
deleteTests
public void deleteTests()Deletes all tests. -
addTest
Call to add a test with defaults.- Throws:
TestingFrameworkException
-
addTest
Call to add a test. The test is a map with a REQUEST and a RESPONSE key. SeeClientPOJOAdapterfor details on the format of the request and response.- Parameters:
test- Map with a REQUEST and a RESPONSE key.- Throws:
TestingFrameworkException
-
deepcopy
Used to make a "deep" copy of an object. This testing framework makes deep copies of tests that are added as well as requestExpectations Maps and response Maps.- Parameters:
orig- a serializable object.- Returns:
- a deep copy of the orig object.
- Throws:
TestingFrameworkException
-