FullTest.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. /***************************************************************************
  2. *
  3. * Project _____ __ ____ _ _
  4. * ( _ ) /__\ (_ _)_| |_ _| |_
  5. * )(_)( /(__)\ )( (_ _)(_ _)
  6. * (_____)(__)(__)(__) |_| |_|
  7. *
  8. *
  9. * Copyright 2018-present, Leonid Stryzhevskyi <lganzzzo@gmail.com>
  10. *
  11. * Licensed under the Apache License, Version 2.0 (the "License");
  12. * you may not use this file except in compliance with the License.
  13. * You may obtain a copy of the License at
  14. *
  15. * http://www.apache.org/licenses/LICENSE-2.0
  16. *
  17. * Unless required by applicable law or agreed to in writing, software
  18. * distributed under the License is distributed on an "AS IS" BASIS,
  19. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20. * See the License for the specific language governing permissions and
  21. * limitations under the License.
  22. *
  23. ***************************************************************************/
  24. #include "FullTest.hpp"
  25. #include "oatpp/web/app/Client.hpp"
  26. #include "oatpp/web/app/ControllerWithInterceptors.hpp"
  27. #include "oatpp/web/app/ControllerWithErrorHandler.hpp"
  28. #include "oatpp/web/app/Controller.hpp"
  29. #include "oatpp/web/app/BasicAuthorizationController.hpp"
  30. #include "oatpp/web/app/BearerAuthorizationController.hpp"
  31. #include "oatpp/web/client/HttpRequestExecutor.hpp"
  32. #include "oatpp/web/server/HttpConnectionHandler.hpp"
  33. #include "oatpp/web/server/HttpRouter.hpp"
  34. #include "oatpp/parser/json/mapping/ObjectMapper.hpp"
  35. #include "oatpp/network/tcp/server/ConnectionProvider.hpp"
  36. #include "oatpp/network/tcp/client/ConnectionProvider.hpp"
  37. #include "oatpp/network/virtual_/client/ConnectionProvider.hpp"
  38. #include "oatpp/network/virtual_/server/ConnectionProvider.hpp"
  39. #include "oatpp/network/virtual_/Interface.hpp"
  40. #include "oatpp/core/data/resource/InMemoryData.hpp"
  41. #include "oatpp/core/macro/component.hpp"
  42. #include "oatpp-test/web/ClientServerTestRunner.hpp"
  43. namespace oatpp { namespace test { namespace web {
  44. namespace {
  45. typedef oatpp::web::mime::multipart::PartList PartList;
  46. typedef oatpp::web::protocol::http::outgoing::MultipartBody MultipartBody;
  47. class TestComponent {
  48. private:
  49. v_uint16 m_port;
  50. public:
  51. TestComponent(v_uint16 port)
  52. : m_port(port)
  53. {}
  54. OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::virtual_::Interface>, virtualInterface)([] {
  55. return oatpp::network::virtual_::Interface::obtainShared("virtualhost");
  56. }());
  57. OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>, serverConnectionProvider)([this] {
  58. if(m_port == 0) { // Use oatpp virtual interface
  59. OATPP_COMPONENT(std::shared_ptr<oatpp::network::virtual_::Interface>, _interface);
  60. return std::static_pointer_cast<oatpp::network::ServerConnectionProvider>(
  61. oatpp::network::virtual_::server::ConnectionProvider::createShared(_interface)
  62. );
  63. }
  64. return std::static_pointer_cast<oatpp::network::ServerConnectionProvider>(
  65. oatpp::network::tcp::server::ConnectionProvider::createShared({"localhost", m_port})
  66. );
  67. }());
  68. OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, httpRouter)([] {
  69. return oatpp::web::server::HttpRouter::createShared();
  70. }());
  71. OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ConnectionHandler>, serverConnectionHandler)([] {
  72. OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router);
  73. return oatpp::web::server::HttpConnectionHandler::createShared(router);
  74. }());
  75. OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::data::mapping::ObjectMapper>, objectMapper)([] {
  76. return oatpp::parser::json::mapping::ObjectMapper::createShared();
  77. }());
  78. OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ClientConnectionProvider>, clientConnectionProvider)([this] {
  79. if(m_port == 0) {
  80. OATPP_COMPONENT(std::shared_ptr<oatpp::network::virtual_::Interface>, _interface);
  81. return std::static_pointer_cast<oatpp::network::ClientConnectionProvider>(
  82. oatpp::network::virtual_::client::ConnectionProvider::createShared(_interface)
  83. );
  84. }
  85. return std::static_pointer_cast<oatpp::network::ClientConnectionProvider>(
  86. oatpp::network::tcp::client::ConnectionProvider::createShared({"localhost", m_port})
  87. );
  88. }());
  89. };
  90. std::shared_ptr<PartList> createMultipart(const std::unordered_map<oatpp::String, oatpp::String>& map) {
  91. auto multipart = oatpp::web::mime::multipart::PartList::createSharedWithRandomBoundary();
  92. for(auto& pair : map) {
  93. oatpp::web::mime::multipart::Headers partHeaders;
  94. auto part = std::make_shared<oatpp::web::mime::multipart::Part>(partHeaders);
  95. multipart->writeNextPartSimple(part);
  96. part->putHeader("Content-Disposition", "form-data; name=\"" + pair.first + "\"");
  97. part->setPayload(std::make_shared<oatpp::data::resource::InMemoryData>(pair.second));
  98. }
  99. return multipart;
  100. }
  101. }
  102. void FullTest::onRun() {
  103. TestComponent component(m_port);
  104. oatpp::test::web::ClientServerTestRunner runner;
  105. runner.addController(app::Controller::createShared());
  106. runner.addController(app::ControllerWithInterceptors::createShared());
  107. runner.addController(app::ControllerWithErrorHandler::createShared());
  108. runner.addController(app::DefaultBasicAuthorizationController::createShared());
  109. runner.addController(app::BasicAuthorizationController::createShared());
  110. runner.addController(app::BearerAuthorizationController::createShared());
  111. runner.run([this, &runner] {
  112. OATPP_COMPONENT(std::shared_ptr<oatpp::network::ClientConnectionProvider>, clientConnectionProvider);
  113. OATPP_COMPONENT(std::shared_ptr<oatpp::data::mapping::ObjectMapper>, objectMapper);
  114. auto requestExecutor = oatpp::web::client::HttpRequestExecutor::createShared(clientConnectionProvider);
  115. auto client = app::Client::createShared(requestExecutor, objectMapper);
  116. auto connection = client->getConnection();
  117. OATPP_ASSERT(connection);
  118. v_int32 iterationsStep = m_iterationsPerStep;
  119. auto lastTick = oatpp::base::Environment::getMicroTickCount();
  120. for(v_int32 i = 0; i < iterationsStep * 10; i ++) {
  121. { // test simple GET
  122. auto response = client->getRoot(connection);
  123. OATPP_ASSERT(response->getStatusCode() == 200);
  124. auto value = response->readBodyToString();
  125. OATPP_ASSERT(value == "Hello World!!!");
  126. }
  127. { // test simple GET with CORS
  128. auto response = client->getCors(connection);
  129. OATPP_ASSERT(response->getStatusCode() == 200);
  130. auto value = response->readBodyToString();
  131. OATPP_ASSERT(value == "Ping");
  132. auto header = response->getHeader(oatpp::web::protocol::http::Header::CORS_ORIGIN);
  133. OATPP_ASSERT(header);
  134. OATPP_ASSERT(header == "*");
  135. header = response->getHeader(oatpp::web::protocol::http::Header::CORS_METHODS);
  136. OATPP_ASSERT(header);
  137. OATPP_ASSERT(header == "GET, POST, OPTIONS");
  138. header = response->getHeader(oatpp::web::protocol::http::Header::CORS_HEADERS);
  139. OATPP_ASSERT(header);
  140. OATPP_ASSERT(header == "DNT, User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type, Range, Authorization");
  141. }
  142. { // test simple OPTIONS with CORS
  143. auto response = client->optionsCors(connection);
  144. OATPP_ASSERT(response->getStatusCode() == 204);
  145. auto header = response->getHeader(oatpp::web::protocol::http::Header::CORS_ORIGIN);
  146. OATPP_ASSERT(header);
  147. OATPP_ASSERT(header == "*");
  148. header = response->getHeader(oatpp::web::protocol::http::Header::CORS_METHODS);
  149. OATPP_ASSERT(header);
  150. OATPP_ASSERT(header == "GET, POST, OPTIONS");
  151. header = response->getHeader(oatpp::web::protocol::http::Header::CORS_HEADERS);
  152. OATPP_ASSERT(header);
  153. OATPP_ASSERT(header == "DNT, User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type, Range, Authorization");
  154. }
  155. { // test simple GET with CORS
  156. auto response = client->getCorsOrigin(connection);
  157. OATPP_ASSERT(response->getStatusCode() == 200);
  158. auto value = response->readBodyToString();
  159. OATPP_ASSERT(value == "Pong");
  160. auto header = response->getHeader(oatpp::web::protocol::http::Header::CORS_ORIGIN);
  161. OATPP_ASSERT(header);
  162. OATPP_ASSERT(header == "127.0.0.1");
  163. header = response->getHeader(oatpp::web::protocol::http::Header::CORS_METHODS);
  164. OATPP_ASSERT(header);
  165. OATPP_ASSERT(header == "GET, POST, OPTIONS");
  166. header = response->getHeader(oatpp::web::protocol::http::Header::CORS_HEADERS);
  167. OATPP_ASSERT(header);
  168. OATPP_ASSERT(header == "DNT, User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type, Range, Authorization");
  169. }
  170. { // test simple GET with CORS
  171. auto response = client->getCorsOriginMethods(connection);
  172. OATPP_ASSERT(response->getStatusCode() == 200);
  173. auto value = response->readBodyToString();
  174. OATPP_ASSERT(value == "Ping");
  175. auto header = response->getHeader(oatpp::web::protocol::http::Header::CORS_ORIGIN);
  176. OATPP_ASSERT(header);
  177. OATPP_ASSERT(header == "127.0.0.1");
  178. header = response->getHeader(oatpp::web::protocol::http::Header::CORS_METHODS);
  179. OATPP_ASSERT(header);
  180. OATPP_ASSERT(header == "GET, OPTIONS");
  181. header = response->getHeader(oatpp::web::protocol::http::Header::CORS_HEADERS);
  182. OATPP_ASSERT(header);
  183. OATPP_ASSERT(header == "DNT, User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type, Range, Authorization");
  184. }
  185. { // test simple GET with CORS
  186. auto response = client->getCorsOriginMethodsHeader(connection);
  187. OATPP_ASSERT(response->getStatusCode() == 200);
  188. auto value = response->readBodyToString();
  189. OATPP_ASSERT(value == "Pong");
  190. auto header = response->getHeader(oatpp::web::protocol::http::Header::CORS_ORIGIN);
  191. OATPP_ASSERT(header);
  192. OATPP_ASSERT(header == "127.0.0.1");
  193. header = response->getHeader(oatpp::web::protocol::http::Header::CORS_METHODS);
  194. OATPP_ASSERT(header);
  195. OATPP_ASSERT(header == "GET, OPTIONS");
  196. header = response->getHeader(oatpp::web::protocol::http::Header::CORS_HEADERS);
  197. OATPP_ASSERT(header);
  198. OATPP_ASSERT(header == "X-PWNT");
  199. }
  200. { // test GET with path parameter
  201. auto response = client->getWithParams("my_test_param", connection);
  202. OATPP_ASSERT(response->getStatusCode() == 200);
  203. auto dto = response->readBodyToDto<oatpp::Object<app::TestDto>>(objectMapper.get());
  204. OATPP_ASSERT(dto);
  205. OATPP_ASSERT(dto->testValue == "my_test_param");
  206. }
  207. { // test GET with query parameters
  208. auto response = client->getWithQueries("oatpp", 1, connection);
  209. OATPP_ASSERT(response->getStatusCode() == 200);
  210. auto dto = response->readBodyToDto<oatpp::Object<app::TestDto>>(objectMapper.get());
  211. OATPP_ASSERT(dto);
  212. OATPP_ASSERT(dto->testValue == "name=oatpp&age=1");
  213. }
  214. { // test GET with optional query parameters
  215. auto response = client->getWithOptQueries("oatpp", connection);
  216. OATPP_ASSERT(response->getStatusCode() == 200);
  217. auto dto = response->readBodyToDto<oatpp::Object<app::TestDto>>(objectMapper.get());
  218. OATPP_ASSERT(dto);
  219. OATPP_ASSERT(dto->testValue == "name=oatpp&age=101");
  220. }
  221. { // test GET with query parameters
  222. auto response = client->getWithQueriesMap("value1", 32, 0.32f, connection);
  223. OATPP_ASSERT(response->getStatusCode() == 200);
  224. auto dto = response->readBodyToDto<oatpp::Object<app::TestDto>>(objectMapper.get());
  225. OATPP_ASSERT(dto);
  226. OATPP_ASSERT(dto->testMap);
  227. OATPP_ASSERT(dto->testMap->size() == 3);
  228. OATPP_ASSERT(dto->testMap["key1"] == "value1");
  229. OATPP_ASSERT(dto->testMap["key2"] == "32");
  230. OATPP_ASSERT(dto->testMap["key3"] == oatpp::utils::conversion::float32ToStr(0.32f));
  231. }
  232. { // test GET with header parameter
  233. auto response = client->getWithHeaders("my_test_header", connection);
  234. OATPP_ASSERT(response->getStatusCode() == 200);
  235. auto dto = response->readBodyToDto<oatpp::Object<app::TestDto>>(objectMapper.get());
  236. OATPP_ASSERT(dto);
  237. OATPP_ASSERT(dto->testValue == "my_test_header");
  238. }
  239. { // test POST with body
  240. auto response = client->postBody("my_test_body", connection);
  241. OATPP_ASSERT(response->getStatusCode() == 200);
  242. auto dto = response->readBodyToDto<oatpp::Object<app::TestDto>>(objectMapper.get());
  243. OATPP_ASSERT(dto);
  244. OATPP_ASSERT(dto->testValue == "my_test_body");
  245. }
  246. { // test POST with dto body
  247. auto dtoIn = app::TestDto::createShared();
  248. dtoIn->testValueInt = i;
  249. auto response = client->postBodyDto(dtoIn, connection);
  250. OATPP_ASSERT(response->getStatusCode() == 200);
  251. auto dtoOut = response->readBodyToDto<oatpp::Object<app::TestDto>>(objectMapper.get());
  252. OATPP_ASSERT(dtoOut);
  253. OATPP_ASSERT(dtoOut->testValueInt == i);
  254. }
  255. { // test Enum as String
  256. OATPP_ASSERT(oatpp::Enum<app::AllowedPathParams>::getEntries().size() == 2);
  257. oatpp::Enum<app::AllowedPathParams> v = app::AllowedPathParams::HELLO;
  258. auto response = client->getHeaderEnumAsString(v, connection);
  259. OATPP_ASSERT(response->getStatusCode() == 200);
  260. }
  261. { // test Enum as String
  262. oatpp::Enum<app::AllowedPathParams> v = app::AllowedPathParams::HELLO;
  263. auto response = client->getHeaderEnumAsNumber(v, connection);
  264. OATPP_ASSERT(response->getStatusCode() == 200);
  265. }
  266. { // test Big Echo with body
  267. oatpp::data::stream::BufferOutputStream stream;
  268. for(v_int32 i = 0; i < oatpp::data::buffer::IOBuffer::BUFFER_SIZE; i++) {
  269. stream.writeSimple("0123456789", 10);
  270. }
  271. auto data = stream.toString();
  272. auto response = client->echoBody(data, connection);
  273. OATPP_ASSERT(response->getStatusCode() == 200);
  274. auto returnedData = response->readBodyToString();
  275. OATPP_ASSERT(returnedData);
  276. OATPP_ASSERT(returnedData == data);
  277. }
  278. {
  279. auto response = client->headerValueSet(" VALUE_1, VALUE_2, VALUE_3", connection);
  280. OATPP_ASSERT(response->getStatusCode() == 200);
  281. }
  282. {
  283. auto response = client->getDefaultHeaders1(connection);
  284. OATPP_ASSERT(response->getStatusCode() == 200);
  285. }
  286. {
  287. auto response = client->getDefaultHeaders2("some param", connection);
  288. OATPP_ASSERT(response->getStatusCode() == 200);
  289. }
  290. { // test custom authorization handler with custom authorization object
  291. auto response = client->defaultBasicAuthorization("foo:bar", connection);
  292. OATPP_ASSERT(response->getStatusCode() == 200);
  293. }
  294. { // test call of an endpoint that requiers authorization headers, but we don't send one
  295. auto response = client->defaultBasicAuthorizationWithoutHeader();
  296. OATPP_ASSERT(response->getStatusCode() == 401);
  297. oatpp::String body = response->readBodyToString();
  298. OATPP_ASSERT(body == "server=oatpp/" OATPP_VERSION "\n"
  299. "code=401\n"
  300. "description=Unauthorized\n"
  301. "message=Authorization Required\n");
  302. // should also add the WWW-Authenticate header when Authorization is missing
  303. auto header = response->getHeader(oatpp::web::protocol::http::Header::WWW_AUTHENTICATE);
  304. OATPP_ASSERT(header);
  305. OATPP_ASSERT(header == "Basic realm=\"default-test-realm\"");
  306. }
  307. { // test custom authorization handler with custom authorization object
  308. auto response = client->customBasicAuthorization("foo:bar", connection);
  309. OATPP_ASSERT(response->getStatusCode() == 200);
  310. }
  311. { // test call of an endpoint that requiers authorization headers, but we don't send one
  312. auto response = client->customBasicAuthorizationWithoutHeader();
  313. OATPP_ASSERT(response->getStatusCode() == 401);
  314. oatpp::String body = response->readBodyToString();
  315. OATPP_ASSERT(body == "server=oatpp/" OATPP_VERSION "\n"
  316. "code=401\n"
  317. "description=Unauthorized\n"
  318. "message=Authorization Required\n");
  319. // should also add the WWW-Authenticate header when Authorization is missing
  320. auto header = response->getHeader(oatpp::web::protocol::http::Header::WWW_AUTHENTICATE);
  321. OATPP_ASSERT(header);
  322. OATPP_ASSERT(header == "Basic realm=\"custom-test-realm\"");
  323. }
  324. { // test custom authorization handler with custom authorization object with unknown credentials where the
  325. // handler returns nullptr
  326. auto response = client->customBasicAuthorization("john:doe");
  327. oatpp::String body = response->readBodyToString();
  328. OATPP_ASSERT(response->getStatusCode() == 401);
  329. OATPP_ASSERT(body == "server=oatpp/" OATPP_VERSION "\n"
  330. "code=401\n"
  331. "description=Unauthorized\n"
  332. "message=Unauthorized\n");
  333. // should also add the WWW-Authenticate header when Authorization is missing or wrong
  334. auto header = response->getHeader(oatpp::web::protocol::http::Header::WWW_AUTHENTICATE);
  335. OATPP_ASSERT(header);
  336. OATPP_ASSERT(header == "Basic realm=\"custom-test-realm\"");
  337. }
  338. { // test custom authorization handler with custom authorization method
  339. oatpp::String token = "4e99e8c12de7e01535248d2bac85e732";
  340. auto response = client->bearerAuthorization(token);
  341. oatpp::String body = response->readBodyToString();
  342. OATPP_ASSERT(response->getStatusCode() == 200);
  343. }
  344. { // test custom authorization handler with custom authorization object with unknown credentials where the
  345. // handler returns nullptr
  346. oatpp::String token = "900150983cd24fb0d6963f7d28e17f72";
  347. auto response = client->bearerAuthorization(token);
  348. oatpp::String body = response->readBodyToString();
  349. OATPP_ASSERT(response->getStatusCode() == 401);
  350. OATPP_ASSERT(body == "server=oatpp/" OATPP_VERSION "\n"
  351. "code=401\n"
  352. "description=Unauthorized\n"
  353. "message=Unauthorized\n");
  354. // should also add the WWW-Authenticate header when Authorization is missing or wrong
  355. auto header = response->getHeader(oatpp::web::protocol::http::Header::WWW_AUTHENTICATE);
  356. OATPP_ASSERT(header);
  357. OATPP_ASSERT(header == "Bearer realm=\"custom-bearer-realm\"");
  358. }
  359. { // test Chunked body
  360. oatpp::String sample = "__abcdefghijklmnopqrstuvwxyz-0123456789";
  361. v_int32 numIterations = 10;
  362. oatpp::data::stream::BufferOutputStream stream;
  363. for(v_int32 i = 0; i < numIterations; i++) {
  364. stream.writeSimple(sample->data(), sample->size());
  365. }
  366. auto data = stream.toString();
  367. auto response = client->getChunked(sample, numIterations, connection);
  368. OATPP_ASSERT(response->getStatusCode() == 200);
  369. auto returnedData = response->readBodyToString();
  370. OATPP_ASSERT(returnedData);
  371. OATPP_ASSERT(returnedData == data);
  372. }
  373. { // Multipart body
  374. std::unordered_map<oatpp::String, oatpp::String> map;
  375. map["value1"] = "Hello";
  376. map["value2"] = "World";
  377. auto multipart = createMultipart(map);
  378. auto body = std::make_shared<MultipartBody>(multipart);
  379. auto response = client->multipartTest(i + 1, body);
  380. OATPP_ASSERT(response->getStatusCode() == 200);
  381. multipart = std::make_shared<oatpp::web::mime::multipart::PartList>(response->getHeaders());
  382. oatpp::web::mime::multipart::Reader multipartReader(multipart.get());
  383. multipartReader.setPartReader("value1", oatpp::web::mime::multipart::createInMemoryPartReader(10));
  384. multipartReader.setPartReader("value2", oatpp::web::mime::multipart::createInMemoryPartReader(10));
  385. response->transferBody(&multipartReader);
  386. OATPP_ASSERT(multipart->getAllParts().size() == 2);
  387. auto part1 = multipart->getNamedPart("value1");
  388. auto part2 = multipart->getNamedPart("value2");
  389. OATPP_ASSERT(part1);
  390. OATPP_ASSERT(part1->getPayload());
  391. OATPP_ASSERT(part2);
  392. OATPP_ASSERT(part2->getPayload());
  393. OATPP_ASSERT(part1->getPayload()->getInMemoryData() == "Hello");
  394. OATPP_ASSERT(part2->getPayload()->getInMemoryData() == "World");
  395. }
  396. { // test interceptors
  397. auto response = client->getInterceptors(connection);
  398. OATPP_ASSERT(response->getStatusCode() == 200);
  399. auto value = response->readBodyToString();
  400. OATPP_ASSERT(value == "Hello World!!!");
  401. }
  402. { // test controller's error handler catches
  403. auto response = client->getCaughtError(connection);
  404. OATPP_ASSERT(response->getStatusCode() == 418);
  405. auto value = response->readBodyToString();
  406. OATPP_ASSERT(value == "Controller With Errors!");
  407. }
  408. { // test header replacement
  409. auto response = client->getInterceptors(connection);
  410. OATPP_ASSERT(response->getStatusCode() == 200);
  411. OATPP_ASSERT(response->getHeader("to-be-replaced") == "replaced_value");
  412. }
  413. if((i + 1) % iterationsStep == 0) {
  414. auto ticks = oatpp::base::Environment::getMicroTickCount() - lastTick;
  415. lastTick = oatpp::base::Environment::getMicroTickCount();
  416. OATPP_LOGV("i", "%d, tick=%d", i + 1, ticks);
  417. }
  418. { // test bundle
  419. auto response = client->getBundle(connection);
  420. OATPP_ASSERT(response->getStatusCode() == 200);
  421. auto dto = response->readBodyToDto<oatpp::Object<app::TestDto>>(objectMapper.get());
  422. OATPP_ASSERT(dto);
  423. OATPP_ASSERT(dto->testValue == "str-param");
  424. OATPP_ASSERT(dto->testValueInt == 32000);
  425. }
  426. { // test host header
  427. auto response = client->getHostHeader(connection);
  428. OATPP_ASSERT(response->getStatusCode() == 200);
  429. auto value = response->readBodyToString();
  430. auto host = clientConnectionProvider->getProperty("host");
  431. OATPP_ASSERT(host);
  432. OATPP_ASSERT(value == host.toString() + ":" + oatpp::utils::conversion::int32ToStr(m_port));
  433. }
  434. }
  435. }, std::chrono::minutes(10));
  436. std::this_thread::sleep_for(std::chrono::seconds(1));
  437. }
  438. }}}