Class TestingFramework
- java.lang.Object
-
- org.apache.hc.core5.testing.framework.TestingFramework
-
public class TestingFramework extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description private ClientTestingAdapter
adapter
static java.util.List<java.lang.String>
ALL_METHODS
Use the ALL_METHODS list to conveniently cycle through all HTTP methods.static java.lang.Object
ALREADY_CHECKED
If anClassicTestClientTestingAdapter
is 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 java.lang.String
DEFAULT_REQUEST_BODY
If a test does not specify a body, this one is used.static java.lang.String
DEFAULT_REQUEST_CONTENT_TYPE
If a test does not specify a request contentType, this one is used.static java.util.Map<java.lang.String,java.lang.String>
DEFAULT_REQUEST_HEADERS
If a test does not specify a request headers, these are used.static java.lang.String
DEFAULT_REQUEST_PATH
If a test does not specify a path, this one is used.static ProtocolVersion
DEFAULT_REQUEST_PROTOCOL_VERSION
If a test does not specify a protocol version, this one is used.static java.util.Map<java.lang.String,java.lang.String>
DEFAULT_REQUEST_QUERY
If a test does not specify query parameters, these are used.static java.lang.String
DEFAULT_RESPONSE_BODY
If a test does not specify an expected response body, this one is used.static java.lang.String
DEFAULT_RESPONSE_CONTENT_TYPE
If a test does not specify an expected response contentType, this one is used.static java.util.Map<java.lang.String,java.lang.String>
DEFAULT_RESPONSE_HEADERS
If a test does not specify expected response headers, these are used.static int
DEFAULT_RESPONSE_STATUS
If a test does not specify an expected response status, this one is used.private int
port
private TestingFrameworkRequestHandler
requestHandler
private HttpServer
server
private java.util.List<FrameworkTest>
tests
-
Constructor Summary
Constructors Constructor Description TestingFramework()
TestingFramework(ClientTestingAdapter adapter)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addTest()
Call to add a test with defaults.void
addTest(java.util.Map<java.lang.String,java.lang.Object> test)
Call to add a test.private void
assertBodyMatchesExpectation(java.lang.Object actualBody, java.lang.Object expectedBody)
private void
assertContentTypeMatchesExpectation(java.lang.Object actualContentType, java.lang.Object expectedContentType)
private void
assertHeadersMatchExpectation(java.util.Map<java.lang.String,java.lang.String> actualHeaders, java.util.Map<java.lang.String,java.lang.String> expectedHeaders)
private void
assertResponseMatchesExpectation(java.lang.Object method, java.util.Map<java.lang.String,java.lang.Object> actualResponse, java.util.Map<java.lang.String,java.lang.Object> expectedResponse)
private void
assertStatusMatchesExpectation(java.lang.Object actualStatus, java.lang.Object expectedStatus)
private void
callAdapter(FrameworkTest test)
static java.lang.Object
deepcopy(java.lang.Object orig)
Used to make a "deep" copy of an object.void
deleteTests()
Deletes all tests.private java.lang.String
getDefaultURI()
private void
processThrowable(java.lang.Throwable t, FrameworkTest test)
void
runTests()
Run the tests that have been previously added.void
setAdapter(ClientTestingAdapter adapter)
Sets theClientTestingAdapter
.void
setRequestHandler(TestingFrameworkRequestHandler requestHandler)
This is not likely to be used except during the testing of this class.private void
startServer()
private void
stopServer()
-
-
-
Field Detail
-
ALL_METHODS
public static final java.util.List<java.lang.String> ALL_METHODS
Use the ALL_METHODS list to conveniently cycle through all HTTP methods.
-
ALREADY_CHECKED
public static final java.lang.Object ALREADY_CHECKED
If anClassicTestClientTestingAdapter
is 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
public static final java.lang.String DEFAULT_REQUEST_PATH
If a test does not specify a path, this one is used.- See Also:
- Constant Field Values
-
DEFAULT_REQUEST_BODY
public static final java.lang.String DEFAULT_REQUEST_BODY
If a test does not specify a body, this one is used.- See Also:
- Constant Field Values
-
DEFAULT_REQUEST_CONTENT_TYPE
public static final java.lang.String DEFAULT_REQUEST_CONTENT_TYPE
If a test does not specify a request contentType, this one is used.- See Also:
- Constant Field Values
-
DEFAULT_REQUEST_QUERY
public static final java.util.Map<java.lang.String,java.lang.String> DEFAULT_REQUEST_QUERY
If a test does not specify query parameters, these are used.
-
DEFAULT_REQUEST_HEADERS
public static final java.util.Map<java.lang.String,java.lang.String> DEFAULT_REQUEST_HEADERS
If a test does not specify a request headers, these are used.
-
DEFAULT_REQUEST_PROTOCOL_VERSION
public static final ProtocolVersion 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_STATUS
If a test does not specify an expected response status, this one is used.- See Also:
- Constant Field Values
-
DEFAULT_RESPONSE_BODY
public static final java.lang.String DEFAULT_RESPONSE_BODY
If a test does not specify an expected response body, this one is used.- See Also:
- Constant Field Values
-
DEFAULT_RESPONSE_CONTENT_TYPE
public static final java.lang.String DEFAULT_RESPONSE_CONTENT_TYPE
If a test does not specify an expected response contentType, this one is used.- See Also:
- Constant Field Values
-
DEFAULT_RESPONSE_HEADERS
public static final java.util.Map<java.lang.String,java.lang.String> DEFAULT_RESPONSE_HEADERS
If a test does not specify expected response headers, these are used.
-
adapter
private ClientTestingAdapter adapter
-
requestHandler
private TestingFrameworkRequestHandler requestHandler
-
tests
private java.util.List<FrameworkTest> tests
-
server
private HttpServer server
-
port
private int port
-
-
Constructor Detail
-
TestingFramework
public TestingFramework() throws TestingFrameworkException
- Throws:
TestingFrameworkException
-
TestingFramework
public TestingFramework(ClientTestingAdapter adapter) throws TestingFrameworkException
- Throws:
TestingFrameworkException
-
-
Method Detail
-
setRequestHandler
public void setRequestHandler(TestingFrameworkRequestHandler requestHandler)
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
public void runTests() throws TestingFrameworkException
Run the tests that have been previously added. First, an in-processHttpServer
is 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
private void processThrowable(java.lang.Throwable t, FrameworkTest test) throws TestingFrameworkException
- Throws:
TestingFrameworkException
-
startServer
private void startServer() throws TestingFrameworkException
- Throws:
TestingFrameworkException
-
stopServer
private void stopServer()
-
callAdapter
private void callAdapter(FrameworkTest test) throws TestingFrameworkException
- Throws:
TestingFrameworkException
-
assertResponseMatchesExpectation
private void assertResponseMatchesExpectation(java.lang.Object method, java.util.Map<java.lang.String,java.lang.Object> actualResponse, java.util.Map<java.lang.String,java.lang.Object> expectedResponse) throws TestingFrameworkException
- Throws:
TestingFrameworkException
-
assertStatusMatchesExpectation
private void assertStatusMatchesExpectation(java.lang.Object actualStatus, java.lang.Object expectedStatus) throws TestingFrameworkException
- Throws:
TestingFrameworkException
-
assertBodyMatchesExpectation
private void assertBodyMatchesExpectation(java.lang.Object actualBody, java.lang.Object expectedBody) throws TestingFrameworkException
- Throws:
TestingFrameworkException
-
assertContentTypeMatchesExpectation
private void assertContentTypeMatchesExpectation(java.lang.Object actualContentType, java.lang.Object expectedContentType) throws TestingFrameworkException
- Throws:
TestingFrameworkException
-
assertHeadersMatchExpectation
private void assertHeadersMatchExpectation(java.util.Map<java.lang.String,java.lang.String> actualHeaders, java.util.Map<java.lang.String,java.lang.String> expectedHeaders) throws TestingFrameworkException
- Throws:
TestingFrameworkException
-
getDefaultURI
private java.lang.String getDefaultURI()
-
setAdapter
public void setAdapter(ClientTestingAdapter adapter)
Sets theClientTestingAdapter
.- Parameters:
adapter
-
-
deleteTests
public void deleteTests()
Deletes all tests.
-
addTest
public void addTest() throws TestingFrameworkException
Call to add a test with defaults.- Throws:
TestingFrameworkException
-
addTest
public void addTest(java.util.Map<java.lang.String,java.lang.Object> test) throws TestingFrameworkException
Call to add a test. The test is a map with a REQUEST and a RESPONSE key. SeeClientPOJOAdapter
for details on the format of the request and response.- Parameters:
test
- Map with a REQUEST and a RESPONSE key.- Throws:
TestingFrameworkException
-
deepcopy
public static java.lang.Object deepcopy(java.lang.Object orig) throws TestingFrameworkException
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
-
-