| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 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 |
} |
| 93 |
} |
| 94 |
|
| 95 |
#endif |