diff options
author | Andriy Byzhynar <abyzhynar@luxoft.com> | 2018-06-19 14:23:21 +0300 |
---|---|---|
committer | Ira Lytvynenko (GitHub) <ILytvynenko@luxoft.com> | 2018-06-27 18:20:30 +0300 |
commit | 6f4122d154855242adb1e8503a48694441ba281d (patch) | |
tree | 7dcd22163053edbade8cff110c6d642e4edb6fc9 | |
parent | 73c5c7a8df81a7019f3a6b3c8ef659a60ec72aa7 (diff) | |
download | sdl_core-6f4122d154855242adb1e8503a48694441ba281d.tar.gz |
Fix unsubscribe vehicle request unit test
Fixed/rewritten unit tests which were failed(die to code changes) after
vehicle info plugin implementation
3 files changed, 70 insertions, 56 deletions
diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_app_extension.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_app_extension.h index 6b642c822a..f7e6ae7887 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_app_extension.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_app_extension.h @@ -56,8 +56,8 @@ class VehicleInfoAppExtension : public app_mngr::AppExtension { * @param plugin vehicle info plugin * @param app application that contains this plugin */ - explicit VehicleInfoAppExtension(VehicleInfoPlugin& plugin, - app_mngr::Application& app); + VehicleInfoAppExtension(VehicleInfoPlugin& plugin, + app_mngr::Application& app); virtual ~VehicleInfoAppExtension(); /** diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_plugin.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_plugin.h index 2e8d621593..b8e6f763e3 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_plugin.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_plugin.h @@ -38,7 +38,6 @@ namespace vehicle_info_plugin { class VehicleInfoAppExtension; namespace app_mngr = application_manager; -namespace commands = application_manager::commands; namespace plugins = application_manager::plugin_manager; class VehicleInfoPlugin : public plugins::RPCPlugin { @@ -51,7 +50,7 @@ class VehicleInfoPlugin : public plugins::RPCPlugin { policy::PolicyHandlerInterface& policy_handler) OVERRIDE; bool IsAbleToProcess(const int32_t function_id, - const commands::Command::CommandSource source) OVERRIDE; + const app_mngr::commands::Command::CommandSource source) OVERRIDE; std::string PluginName() OVERRIDE; app_mngr::CommandFactory& GetCommandFactory() OVERRIDE; diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/unsubscribe_vehicle_request_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/unsubscribe_vehicle_request_test.cc index a9a498d3c7..1afcf8d135 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/unsubscribe_vehicle_request_test.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/unsubscribe_vehicle_request_test.cc @@ -39,6 +39,8 @@ #include "application_manager/mock_application_manager.h" #include "application_manager/mock_message_helper.h" #include "mobile/unsubscribe_vehicle_data_request.h" +#include "vehicle_info_plugin/vehicle_info_plugin.h" +#include "vehicle_info_plugin/vehicle_info_app_extension.h" namespace test { namespace components { @@ -67,11 +69,32 @@ class UnsubscribeVehicleRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { public: UnsubscribeVehicleRequestTest() - : app_set_lock_ptr_(std::make_shared<sync_primitives::Lock>()) {} + : mock_app_(CreateMockApp()) + , app_set_lock_ptr_(std::make_shared<sync_primitives::Lock>()) + , vi_app_extension_ptr_( + utils::MakeShared<vehicle_info_plugin::VehicleInfoAppExtension>( + vi_plugin_, *mock_app_)) {} protected: - void UnsubscribeSuccessfully(); + void SetUp() OVERRIDE { + vi_plugin_.Init(app_mngr_, + mock_rpc_service_, + mock_hmi_capabilities_, + mock_policy_handler_); + ON_CALL(*mock_app_, AddExtension(vi_app_extension_ptr_)); + vi_plugin_.OnApplicationEvent(application_manager::plugin_manager:: + ApplicationEvent::kApplicationRegistered, + mock_app_); + ON_CALL(*mock_app_, + QueryInterface(vehicle_info_plugin::VehicleInfoAppExtension:: + VehicleInfoAppExtensionUID)) + .WillByDefault(Return(vi_app_extension_ptr_)); + } + + MockAppPtr mock_app_; + application_manager::AppExtensionPtr vi_app_extension_ptr_; std::shared_ptr<sync_primitives::Lock> app_set_lock_ptr_; + vehicle_info_plugin::VehicleInfoPlugin vi_plugin_; }; TEST_F(UnsubscribeVehicleRequestTest, Run_AppNotRegistered_UNSUCCESS) { @@ -101,7 +124,7 @@ TEST_F(UnsubscribeVehicleRequestTest, MockAppPtr mock_app(CreateMockApp()); EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); + .WillOnce(Return(mock_app_)); EXPECT_CALL( mock_rpc_service_, @@ -111,72 +134,78 @@ TEST_F(UnsubscribeVehicleRequestTest, } TEST_F(UnsubscribeVehicleRequestTest, - Run_UnsubscribeNotSubscribedBeforeData_IGNORED) { + Run_UnsubscribeFromSubscribedBeforeData_RequestSuccessfullySentToHmi) { MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); (*command_msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; - (*command_msg)[am::strings::msg_params][kMsgParamKey] = kVehicleType; + (*command_msg)[am::strings::msg_params][kMsgParamKey] = true; am::VehicleData vehicle_data; vehicle_data.insert(am::VehicleData::value_type(kMsgParamKey, kVehicleType)); EXPECT_CALL(mock_message_helper_, vehicle_data()) .WillOnce(ReturnRef(vehicle_data)); - CommandPtr command(CreateCommand<UnsubscribeVehicleDataRequest>(command_msg)); - MockAppPtr mock_app(CreateMockApp()); EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - - EXPECT_CALL( - mock_rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::IGNORED), _)); - + .WillOnce(Return(mock_app_)); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::VehicleInfo_UnsubscribeVehicleData))) + .WillOnce(Return(true)); + vehicle_info_plugin::VehicleInfoAppExtension* vi_app_extension = + dynamic_cast<vehicle_info_plugin::VehicleInfoAppExtension*>( + vi_app_extension_ptr_.get()); + ASSERT_TRUE(vi_app_extension->subscribeToVehicleInfo(kVehicleType)); + application_manager::ApplicationSet app_set = {mock_app_}; + DataAccessor<application_manager::ApplicationSet> accessor(app_set, + app_set_lock_ptr_); + // Expectations + EXPECT_CALL(app_mngr_, applications()).WillRepeatedly(Return(accessor)); + CommandPtr command(CreateCommand<UnsubscribeVehicleDataRequest>(command_msg)); command->Run(); } TEST_F(UnsubscribeVehicleRequestTest, - Run_UnsubscribeNotSubscribedBeforeData_UNSUCCESS) { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - (*command_msg)[am::strings::msg_params][kMsgParamKey] = true; - + Run_EmptyVehicleData_INVALID_DATA_SentToMobile) { am::VehicleData vehicle_data; - vehicle_data.insert(am::VehicleData::value_type(kMsgParamKey, kVehicleType)); EXPECT_CALL(mock_message_helper_, vehicle_data()) .WillOnce(ReturnRef(vehicle_data)); - CommandPtr command(CreateCommand<UnsubscribeVehicleDataRequest>(command_msg)); MockAppPtr mock_app(CreateMockApp()); EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); + .WillOnce(Return(mock_app_)); EXPECT_CALL( mock_rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::IGNORED), _)); - - command->Run(); -} + ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); -TEST_F(UnsubscribeVehicleRequestTest, Run_UnsubscribeDataDisabled_UNSUCCESS) { MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); (*command_msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*command_msg)[am::strings::msg_params][kMsgParamKey] = false; + CommandPtr command(CreateCommand<UnsubscribeVehicleDataRequest>(command_msg)); + command->Run(); +} +TEST_F(UnsubscribeVehicleRequestTest, + Run_UnsubscribeFromNotSubscribedBeforeData_UNSUCCESS) { am::VehicleData vehicle_data; vehicle_data.insert(am::VehicleData::value_type(kMsgParamKey, kVehicleType)); EXPECT_CALL(mock_message_helper_, vehicle_data()) .WillOnce(ReturnRef(vehicle_data)); - CommandPtr command(CreateCommand<UnsubscribeVehicleDataRequest>(command_msg)); - MockAppPtr mock_app(CreateMockApp()); EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); + .WillOnce(Return(mock_app_)); EXPECT_CALL( mock_rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); + ManageMobileCommand(MobileResultCodeIs(mobile_result::IGNORED), _)); + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*command_msg)[am::strings::msg_params][kMsgParamKey] = true; + CommandPtr command(CreateCommand<UnsubscribeVehicleDataRequest>(command_msg)); command->Run(); } @@ -184,37 +213,24 @@ void UnsubscribeVehicleRequestTest::UnsubscribeSuccessfully() { MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); (*command_msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; - (*command_msg)[am::strings::msg_params][kMsgParamKey] = true; am::VehicleData vehicle_data; vehicle_data.insert(am::VehicleData::value_type(kMsgParamKey, kVehicleType)); - EXPECT_CALL(mock_message_helper_, vehicle_data()) .WillOnce(ReturnRef(vehicle_data)); + CommandPtr command(CreateCommand<UnsubscribeVehicleDataRequest>(command_msg)); - am::ApplicationSet application_set_; MockAppPtr mock_app(CreateMockApp()); - application_set_.insert(mock_app); - DataAccessor<am::ApplicationSet> accessor(application_set_, - app_set_lock_ptr_); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillRepeatedly(Return(mock_app)); - - EXPECT_CALL(app_mngr_, applications()).WillRepeatedly(Return(accessor)); + .WillOnce(Return(mock_app)); EXPECT_CALL( mock_rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), _)); + ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); - CommandPtr command(CreateCommand<UnsubscribeVehicleDataRequest>(command_msg)); command->Run(); } -TEST_F(UnsubscribeVehicleRequestTest, Run_UnsubscribeData_SUCCESS) { - UnsubscribeSuccessfully(); -} - TEST_F(UnsubscribeVehicleRequestTest, OnEvent_DataNotSubscribed_IGNORED) { MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); (*command_msg)[am::strings::params][am::strings::connection_key] = @@ -223,9 +239,8 @@ TEST_F(UnsubscribeVehicleRequestTest, OnEvent_DataNotSubscribed_IGNORED) { CommandPtr command(CreateCommand<UnsubscribeVehicleDataRequest>(command_msg)); am::VehicleData vehicle_data; - MockAppPtr mock_app(CreateMockApp()); EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillRepeatedly(Return(mock_app)); + .WillRepeatedly(Return(mock_app_)); vehicle_data.insert(am::VehicleData::value_type(kMsgParamKey, kVehicleType)); EXPECT_CALL(mock_message_helper_, vehicle_data()) .WillOnce(ReturnRef(vehicle_data)); @@ -248,20 +263,20 @@ TEST_F(UnsubscribeVehicleRequestTest, OnEvent_DataNotSubscribed_IGNORED) { EXPECT_CALL( mock_rpc_service_, ManageMobileCommand(MobileResultCodeIs(mobile_result::IGNORED), _)); - EXPECT_CALL(*mock_app, UpdateHash()); + EXPECT_CALL(*mock_app_, UpdateHash()); command->on_event(test_event); } TEST_F(UnsubscribeVehicleRequestTest, OnEvent_DataUnsubscribed_SUCCESS) { - UnsubscribeSuccessfully(); MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); (*command_msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; (*command_msg)[am::strings::msg_params][kMsgParamKey] = true; CommandPtr command(CreateCommand<UnsubscribeVehicleDataRequest>(command_msg)); - MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillRepeatedly(Return(mock_app_)); am::event_engine::Event test_event( hmi_apis::FunctionID::VehicleInfo_UnsubscribeVehicleData); SmartObject message(smart_objects::SmartType_Map); |