Debian Codegraph @

unittest/gunit/xplugin/xpl/admin_cmd_handler_t.h

raw symbols SCIP
1 /* Copyright (c) 2019, 2026, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24 #ifndef UNITTEST_GUNIT_XPLUGIN_XPL_ADMIN_CMD_HANDLER_T_H_
25 #define UNITTEST_GUNIT_XPLUGIN_XPL_ADMIN_CMD_HANDLER_T_H_
26
27 #include <gmock/gmock.h>
28 #include <gtest/gtest.h>
29 #include <memory>
30
31 #include "plugin/x/src/admin_cmd_arguments.h"
32 #include "plugin/x/src/admin_cmd_handler.h"
33 #include "unittest/gunit/xplugin/xpl/mock/protocol_encoder.h"
34 #include "unittest/gunit/xplugin/xpl/mock/session.h"
35 #include "unittest/gunit/xplugin/xpl/mock/sql_session.h"
36 #include "unittest/gunit/xplugin/xpl/mysqlx_pb_wrapper.h"
37
38 namespace xpl {
39 namespace test {
40
41 using ::testing::_;
42 using ::testing::Return;
43 using ::testing::StrictMock;
44
45 const Any::Object::Fld SCHEMA{"schema", "xtest"};
46 const Any::Object::Fld COLLECTION_NAME{"name", "test_coll"};
47
48 class Admin_command_handler_stub : public Admin_command_handler {
49 public:
50 explicit Admin_command_handler_stub(iface::Session *session)
51 : Admin_command_handler(session) {}
52
53 using Admin_command_handler::create_collection;
54 using Admin_command_handler::ensure_collection;
55 using Admin_command_handler::get_collection_options;
56 using Admin_command_handler::modify_collection_options;
57 };
58
59 class Admin_command_handler_test : public ::testing::Test {
60 public:
61 void SetUp() override {
62 command.reset(new Admin_command_handler_stub(&mock_session));
63
64 EXPECT_CALL(mock_session, data_context())
65 .WillRepeatedly(ReturnRef(mock_data_context));
66 EXPECT_CALL(mock_session, proto()).WillRepeatedly(ReturnRef(mock_encoder));
67 EXPECT_CALL(mock_encoder, send_exec_ok()).WillRepeatedly(Return(true));
68
69 EXPECT_CALL(mock_session, update_status(_));
70 }
71
72 void set_arguments(const Any &value) {
73 m_list.Add()->CopyFrom(value);
74 m_args.reset(new Admin_command_arguments_object(m_list));
75 }
76
77 void set_validation_details(const Any::Object &validation) {
78 set_arguments(
79 Any::Object{SCHEMA,
80 COLLECTION_NAME,
81 {"options", Any::Object{{"validation", validation}}}});
82 }
83
84 StrictMock<mock::Sql_session> mock_data_context;
85 StrictMock<mock::Protocol_encoder> mock_encoder;
86 StrictMock<mock::Session> mock_session;
87 std::unique_ptr<Admin_command_handler_stub> command;
88 Admin_command_arguments_object::List m_list;
89 std::unique_ptr<Admin_command_arguments_object> m_args;
90 };
91
92 } // namespace test
93 } // namespace xpl
94
95 #endif // UNITTEST_GUNIT_XPLUGIN_XPL_ADMIN_CMD_HANDLER_T_H_