@@ -41,80 +41,106 @@ const auto kTimeout = std::chrono::seconds{10};
4141
4242class Client {
4343 public:
44- explicit Client (olp::client::OlpClientSettings settings) {
45- http_client_ = olp::client::OlpClientFactory::Create (settings);
46- http_client_->SetBaseUrl (kBaseUrl );
47- }
44+ explicit Client (olp::client::OlpClientSettings settings);
4845
4946 void MockResponse (const std::string& method_matcher,
5047 const std::string& path_matcher,
51- const std::string& response_body) {
52- auto expectation = Expectation{};
53- expectation.request .path = path_matcher;
54- expectation.request .method = method_matcher;
55-
56- boost::optional<Expectation::ResponseAction> action =
57- Expectation::ResponseAction{};
58- action->body = response_body;
59- expectation.action = action;
60-
61- CreateExpectation (expectation);
62- }
48+ const std::string& response_body);
6349
6450 void MockBinaryResponse (const std::string& method_matcher,
6551 const std::string& path_matcher,
66- const std::string& response_body) {
67- auto expectation = Expectation{};
68- expectation.request .path = path_matcher;
69- expectation.request .method = method_matcher;
52+ const std::string& response_body);
7053
71- auto binary_response = Expectation::BinaryResponse{};
72- binary_response.base64_string = response_body;
54+ Status::Ports Ports () const ;
7355
74- boost::optional<Expectation::ResponseAction> action =
75- Expectation::ResponseAction{};
76- action->body = binary_response;
77- expectation.action = action;
56+ void Reset ();
7857
79- CreateExpectation (expectation);
80- }
81-
82- std::vector<int32_t > Ports () const {
83- auto response =
84- http_client_->CallApi (kStatusPath , " PUT" , {}, {}, {}, nullptr , " " ,
85- olp::client::CancellationContext{});
86-
87- if (response.status != olp::http::HttpStatusCode::OK) {
88- return {};
89- }
58+ private:
59+ void CreateExpectation (const Expectation& expectation);
9060
91- const auto status = olp::parser::parse<Status>(response.response );
61+ private:
62+ std::shared_ptr<olp::client::OlpClient> http_client_;
63+ };
9264
93- return status.ports ;
65+ inline Client::Client (olp::client::OlpClientSettings settings) {
66+ http_client_ = olp::client::OlpClientFactory::Create (settings);
67+ http_client_->SetBaseUrl (kBaseUrl );
68+ }
69+
70+ inline void Client::MockResponse (const std::string& method_matcher,
71+ const std::string& path_matcher,
72+ const std::string& response_body) {
73+ auto expectation = Expectation{};
74+ expectation.request .path = path_matcher;
75+ expectation.request .method = method_matcher;
76+
77+ boost::optional<Expectation::ResponseAction> action =
78+ Expectation::ResponseAction{};
79+ action->body = response_body;
80+ expectation.action = action;
81+
82+ boost::optional<Expectation::ResponseTimes> times =
83+ Expectation::ResponseTimes{};
84+ times->remaining_times = 1 ;
85+ times->unlimited = false ;
86+ expectation.times = times;
87+
88+ CreateExpectation (expectation);
89+ }
90+
91+ inline void Client::MockBinaryResponse (const std::string& method_matcher,
92+ const std::string& path_matcher,
93+ const std::string& response_body) {
94+ auto expectation = Expectation{};
95+ expectation.request .path = path_matcher;
96+ expectation.request .method = method_matcher;
97+
98+ auto binary_response = Expectation::BinaryResponse{};
99+ binary_response.base64_string = response_body;
100+
101+ boost::optional<Expectation::ResponseAction> action =
102+ Expectation::ResponseAction{};
103+ action->body = binary_response;
104+ expectation.action = action;
105+
106+ boost::optional<Expectation::ResponseTimes> times =
107+ Expectation::ResponseTimes{};
108+ times->remaining_times = 1 ;
109+ times->unlimited = false ;
110+ expectation.times = times;
111+
112+ CreateExpectation (expectation);
113+ }
114+
115+ inline Status::Ports Client::Ports () const {
116+ auto response = http_client_->CallApi (kStatusPath , " PUT" , {}, {}, {}, nullptr ,
117+ " " , olp::client::CancellationContext{});
118+
119+ if (response.status != olp::http::HttpStatusCode::OK) {
120+ return {};
94121 }
95122
96- void Reset () {
97- auto response =
98- http_client_->CallApi (kResetPath , " PUT" , {}, {}, {}, nullptr , " " ,
99- olp::client::CancellationContext{});
123+ const auto status = olp::parser::parse<Status>(response.response );
124+ return status.ports ;
125+ }
100126
101- return ;
102- }
127+ inline void Client::Reset () {
128+ auto response = http_client_->CallApi (kResetPath , " PUT" , {}, {}, {}, nullptr ,
129+ " " , olp::client::CancellationContext{});
103130
104- private:
105- void CreateExpectation (const Expectation& expectation) {
106- const auto data = serialize (expectation);
107- const std::shared_ptr<std::vector<unsigned char >> request_body =
108- std::make_shared<std::vector<unsigned char >>(data.begin (), data.end ());
131+ return ;
132+ }
109133
110- auto response =
111- http_client_->CallApi (kExpectationPath , " PUT" , {}, {}, {}, request_body,
112- " " , olp::client::CancellationContext{});
134+ inline void Client::CreateExpectation (const Expectation& expectation) {
135+ const auto data = serialize (expectation);
136+ const std::shared_ptr<std::vector<unsigned char >> request_body =
137+ std::make_shared<std::vector<unsigned char >>(data.begin (), data.end ());
113138
114- return ;
115- }
139+ auto response =
140+ http_client_->CallApi (kExpectationPath , " PUT" , {}, {}, {}, request_body,
141+ " " , olp::client::CancellationContext{});
142+
143+ return ;
144+ }
116145
117- private:
118- std::shared_ptr<olp::client::OlpClient> http_client_;
119- };
120146} // namespace mockserver
0 commit comments