A mock implementation of the networking::ReplyResponse interface for testing purposes. It is specifically designed to facilitate testing by simulating the behavior of a network response. It enables controlled testing of network interactions without requiring actual network calls. It provides the mechanisms to mock common methods of a network reply, such as retrieving attributes, errors, URLs, error strings, and data content. Additionally, it includes functionality to simulate multiple consecutive network replies over a defined interval using timers.
More...
#include <RequestSender.hpp>
|
| ReplyResponseMock (const foundation::QtPtr< QObject > &parent) |
| Full initialisation constructor that initializes the object by assigning a parent and setting up internal components required for simulating mocked network replies.
|
|
| QMOCK (::QByteArray, readAll,(),()) |
|
| QMOCK (::QNetworkReply::NetworkError, error,(),(const, noexcept)) |
|
| QMOCK (::QString, errorString,(),(const, noexcept)) |
|
| QMOCK (::QUrl, url,(),(const, noexcept)) |
|
| QMOCK (::QVariant, attribute,(const ::QNetworkRequest::Attribute),(const, noexcept)) |
|
void | startReplies (const ::quint32 times=1, const std::chrono::milliseconds &triggerEvery=std::chrono::milliseconds{50}) |
| Triggers a sequence of mock network replies for testing purposes. This method enables the simulation of multiple consecutive network reply events over a specified time interval. It facilitates automated testing of scenarios that depend on repetitive network responses, such as polling mechanisms or batch data processing pipelines.
|
|
| ReplyResponse (const foundation::QtPtr< QObject > &parent) |
| Fully initialises the object with a specified parent.
|
|
virtual::QVariant | attribute (const QNetworkRequest::Attribute code) const noexcept=0 |
| When implemented, retrieves the specified attribute from the network request. This is used to obtain various attributes associated with a network request, such as HTTP status codes, redirection targets, etc. It is essential for handling different aspects of the response beyond the raw data.
|
|
virtual::QNetworkReply::NetworkError | error () const noexcept=0 |
| When implemented, provides the current error state of the network reply. This is used to retrieve the error status of a network operation. This information is crucial for handling any issues in network communication, allowing the application to react accordingly.
|
|
virtual::QString | errorString () const noexcept=0 |
| When implemented, provides a human-readable description of any network error that has occurred during a request-response cycle. Useful for logging or displaying error messages to users.
|
|
virtual::QByteArray | readAll ()=0 |
| When implemented, reads and retrieves all remaining data from the reply. This will extract all data that has been buffered into the reply object from a network operation. Typical usage involves calling this method after a network request has completed to obtain the full response payload for further processing. Use this method to read the entirety of the data content in one go.
|
|
virtual::QUrl | url () const noexcept=0 |
| When implemented, gives the URL to which the network request was made.
|
|
|
void | ready () |
| Triggered when a response from a network request is ready for processing. This signal is meant to be connected to a slot or lambda function that handles the response once a network request completes. It indicates that the reply object contains data that is ready to be processed, or is in an error state.
|
|
A mock implementation of the networking::ReplyResponse interface for testing purposes. It is specifically designed to facilitate testing by simulating the behavior of a network response. It enables controlled testing of network interactions without requiring actual network calls. It provides the mechanisms to mock common methods of a network reply, such as retrieving attributes, errors, URLs, error strings, and data content. Additionally, it includes functionality to simulate multiple consecutive network replies over a defined interval using timers.
Usage:
- Instantiate the class and use the provided QMOCK methods to mock the desired behavior.
- Call
startReplies
to simulate a sequence of network replies. You can define how many replies should be sent and the interval between them.
◆ ReplyResponseMock()
drn::networking::testing::ReplyResponseMock::ReplyResponseMock |
( |
const foundation::QtPtr< QObject > & | parent | ) |
|
|
explicit |
Full initialisation constructor that initializes the object by assigning a parent and setting up internal components required for simulating mocked network replies.
- Parameters
-
parent | The parent QObject that manages the lifetime of this mock object. Pass a parent when you need to manage the instance through Qt's object tree-based memory management. |
◆ QMOCK() [1/5]
drn::networking::testing::ReplyResponseMock::QMOCK |
( |
::QByteArray | , |
|
|
readAll | , |
|
|
() | , |
|
|
() | ) |
◆ QMOCK() [2/5]
drn::networking::testing::ReplyResponseMock::QMOCK |
( |
::QNetworkReply::NetworkError | , |
|
|
error | , |
|
|
() | , |
|
|
(const, noexcept) | ) |
◆ QMOCK() [3/5]
drn::networking::testing::ReplyResponseMock::QMOCK |
( |
::QString | , |
|
|
errorString | , |
|
|
() | , |
|
|
(const, noexcept) | ) |
◆ QMOCK() [4/5]
drn::networking::testing::ReplyResponseMock::QMOCK |
( |
::QUrl | , |
|
|
url | , |
|
|
() | , |
|
|
(const, noexcept) | ) |
◆ QMOCK() [5/5]
drn::networking::testing::ReplyResponseMock::QMOCK |
( |
::QVariant | , |
|
|
attribute | , |
|
|
(const ::QNetworkRequest::Attribute) | , |
|
|
(const, noexcept) | ) |
◆ startReplies()
void drn::networking::testing::ReplyResponseMock::startReplies |
( |
const ::quint32 | times = 1, |
|
|
const std::chrono::milliseconds & | triggerEvery = std::chrono::milliseconds{50} ) |
Triggers a sequence of mock network replies for testing purposes. This method enables the simulation of multiple consecutive network reply events over a specified time interval. It facilitates automated testing of scenarios that depend on repetitive network responses, such as polling mechanisms or batch data processing pipelines.
When called, it initializes the specified number of mock reply events, which are triggered at regular intervals. This is particularly useful for testing how a system handles successive network replies within a predefined time duration.
Usage:
- Call this method within test scenarios where consecutive mock network responses need to be simulated.
- Use it in conjunction with other QMOCK bindings to configure desired mock behavior for attributes, errors, URLs, or response contents.
- Parameters
-
times | The total number of mock replies to simulate. This defines how many times the reply events will be triggered consecutively. |
triggerEvery | The time interval between each simulated reply. This duration dictates the frequency of triggering the replies. |