summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndriy Byzhynar <abyzhynar@luxoft.com>2018-06-19 14:23:21 +0300
committerIra Lytvynenko (GitHub) <ILytvynenko@luxoft.com>2018-06-26 12:01:49 +0300
commita69f2dfe4aae58c61ea65ac3915a5dd7cb58e833 (patch)
tree395b55078513099f5bc030fd83db671e459135b9
parent86615e32b7f8e36bb74650ae8c3f6b5b7d880ca2 (diff)
downloadsdl_core-a69f2dfe4aae58c61ea65ac3915a5dd7cb58e833.tar.gz
Fix unsubscribe vehicle request unit test
Fixed/rewritten unit tests which were failed(die to code changes) after vehicle info plugin implementation
-rw-r--r--src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_app_extension.h4
-rw-r--r--src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_plugin.h3
-rw-r--r--src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/unsubscribe_vehicle_request_test.cc123
3 files changed, 74 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 f8e880d9f5..ee23c8f303 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 371ea98618..a8ef820905 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 {
@@ -65,9 +67,33 @@ const mobile_apis::VehicleDataType::eType kVehicleType =
class UnsubscribeVehicleRequestTest
: public CommandRequestTest<CommandsTestMocks::kIsNice> {
+ public:
+ UnsubscribeVehicleRequestTest()
+ : mock_app_(CreateMockApp())
+ , 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_;
sync_primitives::Lock app_set_lock_;
+ vehicle_info_plugin::VehicleInfoPlugin vi_plugin_;
};
TEST_F(UnsubscribeVehicleRequestTest, Run_AppNotRegistered_UNSUCCESS) {
@@ -95,9 +121,8 @@ TEST_F(UnsubscribeVehicleRequestTest,
EXPECT_CALL(mock_message_helper_, vehicle_data()).WillOnce(ReturnRef(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_,
@@ -107,109 +132,103 @@ 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_);
+ // 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();
}
-void UnsubscribeVehicleRequestTest::UnsubscribeSuccessfully() {
+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] = 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_);
-
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] =
@@ -218,9 +237,9 @@ 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));
@@ -243,20 +262,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);