From a5ad3c16b440feeabb1ac5dda39c0ca11d4b673a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D1=82=D0=BE=D0=BD?= Date: Sun, 24 Aug 2025 08:14:24 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BE=D0=BC=D0=BF=D0=B8=D0=BB=D1=8F?= =?UTF-8?q?=D1=86=D0=B8=D1=8F=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=D0=B4=D0=BD?= =?UTF-8?q?=D0=B5=D0=B3=D0=BE=20=D1=82=D0=B5=D1=81=D1=82=D0=B0=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BD=D1=82=D1=80=D0=BE=D0=BB=D0=BB=D0=B5=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/endpoints_handlers/Controller.h | 7 ++++ tests/endpoint_handlers/Controller_TEST.cpp | 38 +++++++++++++++++++-- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/endpoints_handlers/Controller.h b/src/endpoints_handlers/Controller.h index 619a381..9a80ae4 100644 --- a/src/endpoints_handlers/Controller.h +++ b/src/endpoints_handlers/Controller.h @@ -9,7 +9,14 @@ namespace uad template class Controller : IController { + using HTTPMethodsToExecutors = std::unordered_map>>; + + HTTPMethodsToExecutors executors_; public: + Controller() = default; + + explicit Controller(HTTPMethodsToExecutors&& executors) {} + std::optional>> FindExecutor( boost::beast::http::verb method ) const override diff --git a/tests/endpoint_handlers/Controller_TEST.cpp b/tests/endpoint_handlers/Controller_TEST.cpp index bede0b3..7f49394 100644 --- a/tests/endpoint_handlers/Controller_TEST.cpp +++ b/tests/endpoint_handlers/Controller_TEST.cpp @@ -15,11 +15,27 @@ using namespace boost; using namespace std; using namespace uad; +class MockExecutor : public IExecutor, + beast::http::string_body> +{ +public: + beast::http::response operator ()( + beast::http::request>>&& req + ) override + { + boost::beast::http::response res{ + boost::beast::http::status::not_found, req.version()}; + + return res; + } +}; + BOOST_AUTO_TEST_CASE(Should_Be_Initiated_With_No_Executors) { Controller, - beast::http::response> my_controller; + std::allocator, + beast::http::string_body> my_controller; BOOST_CHECK(!my_controller.FindExecutor(beast::http::verb::get).has_value()); BOOST_CHECK(!my_controller.FindExecutor(beast::http::verb::post).has_value()); @@ -28,3 +44,21 @@ BOOST_AUTO_TEST_CASE(Should_Be_Initiated_With_No_Executors) BOOST_CHECK(!my_controller.FindExecutor(beast::http::verb::head).has_value()); BOOST_CHECK(!my_controller.FindExecutor(beast::http::verb::options).has_value()); } + +BOOST_AUTO_TEST_CASE(Should_Be_Initiated_With_Unordered_Map_HTTP_Methods_To_Executors) +{ + std::unordered_map, beast::http::string_body>>> executors; + + executors[beast::http::verb::get] = make_unique(); + + Controller, + beast::http::string_body> my_controller(std::move(executors)); + + BOOST_CHECK(my_controller.FindExecutor(beast::http::verb::get).has_value()); + BOOST_CHECK(my_controller.FindExecutor(beast::http::verb::post).has_value()); + BOOST_CHECK(my_controller.FindExecutor(beast::http::verb::put).has_value()); + BOOST_CHECK(my_controller.FindExecutor(beast::http::verb::delete_).has_value()); + BOOST_CHECK(my_controller.FindExecutor(beast::http::verb::head).has_value()); + BOOST_CHECK(my_controller.FindExecutor(beast::http::verb::options).has_value()); +}