summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormked-luxoft <mked@luxoft.com>2019-08-23 14:42:15 +0300
committermked-luxoft <mked@luxoft.com>2019-08-29 17:56:41 +0300
commit2d53a14e603cce00709307797725c3cc595129d3 (patch)
tree87ae9bd406be0fad5e02d40e1ed2e4aa18f94a36
parent3f86f3864ae18515c5d1a9ddaf9f7fcaf4d59c62 (diff)
downloadsdl_core-2d53a14e603cce00709307797725c3cc595129d3.tar.gz
Remove notification builder
-rw-r--r--src/components/application_manager/include/application_manager/message_helper.h62
-rw-r--r--src/components/application_manager/src/application_manager_impl.cc18
-rw-r--r--src/components/application_manager/src/message_helper/message_helper.cc51
-rw-r--r--src/components/application_manager/test/application_manager_impl_test.cc15
-rw-r--r--src/components/application_manager/test/include/application_manager/mock_message_helper.h43
-rw-r--r--src/components/application_manager/test/message_helper/message_helper_test.cc94
-rwxr-xr-xsrc/components/application_manager/test/mock_message_helper.cc46
7 files changed, 53 insertions, 276 deletions
diff --git a/src/components/application_manager/include/application_manager/message_helper.h b/src/components/application_manager/include/application_manager/message_helper.h
index ddb6fb71f2..3a0055871b 100644
--- a/src/components/application_manager/include/application_manager/message_helper.h
+++ b/src/components/application_manager/include/application_manager/message_helper.h
@@ -89,63 +89,11 @@ class MessageHelper {
static smart_objects::SmartObjectSPtr CreateHMINotification(
hmi_apis::FunctionID::eType function_id);
- /**
- * @brief ServiceStatusUpdateNotificationBuilder small utility class used for
- * more flexible construction of OnServiceUpdateNotification
- */
- class ServiceStatusUpdateNotificationBuilder {
- public:
- typedef hmi_apis::Common_ServiceType::eType ServiceType;
- typedef hmi_apis::Common_ServiceEvent::eType ServiceEvent;
- typedef hmi_apis::Common_ServiceStatusUpdateReason::eType
- ServiceStatusUpdateReason;
-
- /**
- * @brief CreateBuilder creates builder instance
- * @param service_type - enum value containing service type
- * @param service_event - enum value containing service event
- * @returns builder instance
- */
- static ServiceStatusUpdateNotificationBuilder CreateBuilder(
- const ServiceType service_type, const ServiceEvent service_event);
-
- /**
- * @brief AddAppID adds app id to notification
- * @param app_id application id to add
- * @returns ref to builder instance
- */
- ServiceStatusUpdateNotificationBuilder& AddAppID(const uint32_t app_id);
-
- /**
- * @brief AddServiceUpdateReason adds service update reason to notification
- * @param service_update_reason enum value containing update reason
- * @returns ref to builder instance
- */
- ServiceStatusUpdateNotificationBuilder& AddServiceUpdateReason(
- const ServiceStatusUpdateReason service_update_reason);
-
- /**
- * @brief notification gets notification SO
- * @returns shared ptr to notification SO
- */
- smart_objects::SmartObjectSPtr notification() const;
-
- protected:
- smart_objects::SmartObjectSPtr notification_;
-
- /**
- * @brief class constructor
- * @param service_type - enum value containing service type
- * @param service_event - enum value containing service event
- */
- ServiceStatusUpdateNotificationBuilder(const ServiceType service_type,
- const ServiceEvent service_event);
-
- /**
- * @brief class constructor
- */
- ServiceStatusUpdateNotificationBuilder(){};
- };
+ static smart_objects::SmartObjectSPtr CreateOnServiceUpdateNotification(
+ const hmi_apis::Common_ServiceType::eType type,
+ const hmi_apis::Common_ServiceEvent::eType event,
+ const hmi_apis::Common_ServiceStatusUpdateReason::eType reason,
+ const uint32_t app_id);
/**
* @brief Creates request for different interfaces(JSON)
diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc
index b737e452a2..94e67a0c80 100644
--- a/src/components/application_manager/src/application_manager_impl.cc
+++ b/src/components/application_manager/src/application_manager_impl.cc
@@ -2042,19 +2042,17 @@ void ApplicationManagerImpl::ProcessServiceStatusUpdate(
<< " service_update_reason " << service_update_reason);
const auto app = application(connection_key);
- auto notification_builder =
- MessageHelper::ServiceStatusUpdateNotificationBuilder::CreateBuilder(
- service_type, service_event);
- if (app) {
- notification_builder.AddAppID(app->app_id());
- }
+ const uint32_t app_id = app ? app->app_id() : 0u;
- if (service_update_reason) {
- notification_builder.AddServiceUpdateReason(*service_update_reason);
- }
+ auto reason = service_update_reason
+ ? *service_update_reason
+ : hmi_apis::Common_ServiceStatusUpdateReason::INVALID_ENUM;
+
+ auto notification = MessageHelper::CreateOnServiceUpdateNotification(
+ service_type, service_event, reason, app_id);
- rpc_service_->ManageHMICommand(notification_builder.notification());
+ rpc_service_->ManageHMICommand(notification);
}
void ApplicationManagerImpl::OnSecondaryTransportStartedCallback(
diff --git a/src/components/application_manager/src/message_helper/message_helper.cc b/src/components/application_manager/src/message_helper/message_helper.cc
index 5c9e0e80b1..31eaa54e5d 100644
--- a/src/components/application_manager/src/message_helper/message_helper.cc
+++ b/src/components/application_manager/src/message_helper/message_helper.cc
@@ -2234,45 +2234,32 @@ smart_objects::SmartObjectSPtr MessageHelper::CreateNegativeResponse(
return std::make_shared<smart_objects::SmartObject>(response_data);
}
-MessageHelper::ServiceStatusUpdateNotificationBuilder::
- ServiceStatusUpdateNotificationBuilder(const ServiceType service_type,
- const ServiceEvent service_event) {
- notification_ = MessageHelper::CreateHMINotification(
+smart_objects::SmartObjectSPtr MessageHelper::CreateOnServiceUpdateNotification(
+ const hmi_apis::Common_ServiceType::eType service_type,
+ const hmi_apis::Common_ServiceEvent::eType service_event,
+ const hmi_apis::Common_ServiceStatusUpdateReason::eType
+ service_update_reason,
+ const uint32_t app_id) {
+ LOG4CXX_AUTO_TRACE(logger_);
+ auto notification = MessageHelper::CreateHMINotification(
hmi_apis::FunctionID::BasicCommunication_OnServiceUpdate);
- (*notification_)[strings::msg_params][hmi_notification::service_type] =
+ (*notification)[strings::msg_params][hmi_notification::service_type] =
service_type;
- (*notification_)[strings::msg_params][hmi_notification::service_event] =
+ (*notification)[strings::msg_params][hmi_notification::service_event] =
service_event;
-}
-
-MessageHelper::ServiceStatusUpdateNotificationBuilder
-MessageHelper::ServiceStatusUpdateNotificationBuilder::CreateBuilder(
- const ServiceType service_type, const ServiceEvent service_event) {
- MessageHelper::ServiceStatusUpdateNotificationBuilder builder{service_type,
- service_event};
- return builder;
-}
-
-MessageHelper::ServiceStatusUpdateNotificationBuilder&
-MessageHelper::ServiceStatusUpdateNotificationBuilder::AddAppID(
- const uint32_t app_id) {
- (*notification_)[strings::msg_params][strings::app_id] = app_id;
- return *this;
-}
+ if (0 != app_id) {
+ (*notification)[strings::msg_params][strings::app_id] = app_id;
+ }
-MessageHelper::ServiceStatusUpdateNotificationBuilder&
-MessageHelper::ServiceStatusUpdateNotificationBuilder::AddServiceUpdateReason(
- const ServiceStatusUpdateReason service_update_reason) {
- (*notification_)[strings::msg_params][hmi_notification::reason] =
- service_update_reason;
+ if (hmi_apis::Common_ServiceStatusUpdateReason::INVALID_ENUM !=
+ service_update_reason) {
+ (*notification)[strings::msg_params][hmi_notification::reason] =
+ service_update_reason;
+ }
- return *this;
-}
-smart_objects::SmartObjectSPtr
-MessageHelper::ServiceStatusUpdateNotificationBuilder::notification() const {
- return notification_;
+ return notification;
}
void MessageHelper::SendNaviSetVideoConfig(
diff --git a/src/components/application_manager/test/application_manager_impl_test.cc b/src/components/application_manager/test/application_manager_impl_test.cc
index f3297388ff..bb87d71a48 100644
--- a/src/components/application_manager/test/application_manager_impl_test.cc
+++ b/src/components/application_manager/test/application_manager_impl_test.cc
@@ -105,8 +105,6 @@ const std::string kAppName = "appName";
const WindowID kDefaultWindowId =
mobile_apis::PredefinedWindows::DEFAULT_WINDOW;
-typedef MockMessageHelper::MockServiceStatusUpdateNotificationBuilder*
- MockServiceStatusUpdatePtr;
typedef hmi_apis::Common_ServiceStatusUpdateReason::eType
ServiceStatusUpdateReason;
typedef hmi_apis::Common_ServiceType::eType ServiceType;
@@ -154,8 +152,6 @@ class ApplicationManagerImplTest
new MockAppServiceManager(mock_app_mngr_, mock_last_state_))
, mock_message_helper_(
application_manager::MockMessageHelper::message_helper_mock())
- , mock_service_status_update_(application_manager::MockMessageHelper::
- on_service_update_builder_mock())
{
#ifdef ENABLE_LOG
@@ -276,7 +272,6 @@ class ApplicationManagerImplTest
std::unique_ptr<am::ApplicationManagerImpl> app_manager_impl_;
MockAppServiceManager* mock_app_service_manager_;
application_manager::MockMessageHelper* mock_message_helper_;
- MockServiceStatusUpdatePtr mock_service_status_update_;
std::shared_ptr<MockApplication> mock_app_ptr_;
NiceMock<protocol_handler_test::MockProtocolHandler> mock_protocol_handler_;
@@ -335,14 +330,8 @@ TEST_P(ApplicationManagerImplTest,
AddMockApplication();
ON_CALL(*mock_app_ptr_, app_id()).WillByDefault(Return(kConnectionKey));
- ON_CALL(*mock_service_status_update_,
- CreateBuilder(GetParam().service_type_, GetParam().service_event_))
- .WillByDefault(Return(*mock_service_status_update_));
- ON_CALL(*mock_service_status_update_, AddAppID(kConnectionKey))
- .WillByDefault(ReturnRef(*mock_service_status_update_));
- ON_CALL(*mock_service_status_update_, AddServiceUpdateReason(_))
- .WillByDefault(ReturnRef(*mock_service_status_update_));
- ON_CALL(*mock_service_status_update_, notification())
+
+ ON_CALL(*mock_message_helper_, CreateOnServiceUpdateNotification(_, _, _, _))
.WillByDefault(Return(notification_));
EXPECT_CALL(*mock_rpc_service_, ManageHMICommand(notification_, _))
diff --git a/src/components/application_manager/test/include/application_manager/mock_message_helper.h b/src/components/application_manager/test/include/application_manager/mock_message_helper.h
index a164265ab0..072199082e 100644
--- a/src/components/application_manager/test/include/application_manager/mock_message_helper.h
+++ b/src/components/application_manager/test/include/application_manager/mock_message_helper.h
@@ -341,42 +341,15 @@ class MockMessageHelper {
CreateDisplayCapabilityUpdateToMobile,
smart_objects::SmartObjectSPtr(const smart_objects::SmartObject&,
application_manager::Application&));
- MOCK_METHOD3(CreateOnServiceUpdateNotification, smart_objects::SmartObject(
- const uint32_t app_id,
- const hmi_apis::Common_ServiceType::eType service_type,
- const hmi_apis::Common_ServiceEvent::eType service_event));
- MOCK_METHOD4(CreateOnServiceUpdateNotification, smart_objects::SmartObject(
- const uint32_t app_id,
- const hmi_apis::Common_ServiceType::eType service_type,
- const hmi_apis::Common_ServiceEvent::eType service_event,
- const hmi_apis::Common_ServiceStatusUpdateReason::eType
- service_update_reason));
-
-class MockServiceStatusUpdateNotificationBuilder
- : public MessageHelper::ServiceStatusUpdateNotificationBuilder {
- public:
- MockServiceStatusUpdateNotificationBuilder(
- const MockServiceStatusUpdateNotificationBuilder& obj){};
- MockServiceStatusUpdateNotificationBuilder(){};
- MOCK_METHOD2(CreateBuilder,
- MessageHelper::ServiceStatusUpdateNotificationBuilder(
- hmi_apis::Common_ServiceType::eType,
- hmi_apis::Common_ServiceEvent::eType));
-
- MOCK_METHOD1(AddAppID,
- MessageHelper::ServiceStatusUpdateNotificationBuilder &
- (const uint32_t app_id));
-
- MOCK_METHOD1(AddServiceUpdateReason,
- MessageHelper::ServiceStatusUpdateNotificationBuilder &
- (const hmi_apis::Common_ServiceStatusUpdateReason::eType));
-
- MOCK_CONST_METHOD0(notification, smart_objects::SmartObjectSPtr());
-};
+ MOCK_METHOD4(CreateOnServiceUpdateNotification,
+ smart_objects::SmartObjectSPtr(
+ const hmi_apis::Common_ServiceType::eType service_type,
+ const hmi_apis::Common_ServiceEvent::eType service_event,
+ const hmi_apis::Common_ServiceStatusUpdateReason::eType
+ service_update_reason,
+ const uint32_t app_id));
-static MockMessageHelper* message_helper_mock();
-static MockServiceStatusUpdateNotificationBuilder*
-on_service_update_builder_mock();
+ static MockMessageHelper* message_helper_mock();
};
} // namespace application_manager
diff --git a/src/components/application_manager/test/message_helper/message_helper_test.cc b/src/components/application_manager/test/message_helper/message_helper_test.cc
index 8d75cacdf3..a174d74d5d 100644
--- a/src/components/application_manager/test/message_helper/message_helper_test.cc
+++ b/src/components/application_manager/test/message_helper/message_helper_test.cc
@@ -69,14 +69,6 @@ using namespace application_manager;
typedef std::shared_ptr<MockApplication> MockApplicationSharedPtr;
typedef std::vector<std::string> StringArray;
typedef std::shared_ptr<application_manager::Application> ApplicationSharedPtr;
-typedef MessageHelper::ServiceStatusUpdateNotificationBuilder::ServiceType
- ServiceType;
-typedef MessageHelper::ServiceStatusUpdateNotificationBuilder::ServiceEvent
- ServiceEvent;
-typedef MessageHelper::ServiceStatusUpdateNotificationBuilder::
- ServiceStatusUpdateReason UpdateReason;
-typedef MessageHelper::ServiceStatusUpdateNotificationBuilder
- ServiceStatusUpdateBuilder;
using testing::_;
using testing::AtLeast;
@@ -1113,92 +1105,6 @@ TEST_F(MessageHelperTest, ExtractWindowIdFromSmartObject_FromWrongType) {
MessageHelper::ExtractWindowIdFromSmartObject(message));
}
-TEST(ServiceStatusUpdateNotificationBuilderTest, CreateBuilderIsCorrect) {
- auto service_status_update_builder_ =
- ServiceStatusUpdateBuilder::CreateBuilder(ServiceType::AUDIO,
- ServiceEvent::REQUEST_ACCEPTED);
- auto notification_ = service_status_update_builder_.notification();
-
- auto message_type_exist_ =
- (*notification_)[strings::params].keyExists(strings::message_type);
- auto message_type_ =
- (*notification_)[strings::params][strings::message_type].asInt();
- auto function_id_exist_ =
- (*notification_)[strings::params].keyExists(strings::function_id);
- auto function_id_ =
- (*notification_)[strings::params][strings::function_id].asInt();
- auto protocol_version_exist_ =
- (*notification_)[strings::params].keyExists(strings::protocol_version);
- auto protocol_version_ =
- (*notification_)[strings::params][strings::protocol_version].asInt();
- auto protocol_type_exist_ =
- (*notification_)[strings::params].keyExists(strings::protocol_type);
- auto protocol_type_ =
- (*notification_)[strings::params][strings::protocol_type].asInt();
- auto service_type_exist_ = (*notification_)[strings::msg_params].keyExists(
- hmi_notification::service_type);
- auto service_type_ =
- (*notification_)[strings::msg_params][hmi_notification::service_type]
- .asInt();
- auto service_event_exist_ = (*notification_)[strings::msg_params].keyExists(
- hmi_notification::service_event);
- auto service_event_ =
- (*notification_)[strings::msg_params][hmi_notification::service_event]
- .asInt();
-
- EXPECT_TRUE(message_type_exist_);
- EXPECT_EQ(static_cast<int64_t>(kNotification), message_type_);
- EXPECT_TRUE(function_id_exist_);
- EXPECT_EQ(static_cast<int64_t>(
- hmi_apis::FunctionID::BasicCommunication_OnServiceUpdate),
- function_id_);
- EXPECT_TRUE(protocol_version_exist_);
- EXPECT_EQ(static_cast<int64_t>(commands::CommandImpl::protocol_version_),
- protocol_version_);
- EXPECT_TRUE(protocol_type_exist_);
- EXPECT_EQ(static_cast<int64_t>(commands::CommandImpl::hmi_protocol_type_),
- protocol_type_);
- EXPECT_TRUE(service_type_exist_);
- EXPECT_EQ(static_cast<int64_t>(ServiceType::AUDIO), service_type_);
- EXPECT_TRUE(service_event_exist_);
- EXPECT_EQ(static_cast<int64_t>(ServiceEvent::REQUEST_ACCEPTED),
- service_event_);
-}
-
-TEST(ServiceStatusUpdateNotificationBuilderTest, AddAppID) {
- auto service_status_update_builder_ =
- ServiceStatusUpdateBuilder::CreateBuilder(ServiceType::RPC,
- ServiceEvent::REQUEST_RECEIVED);
- const uint32_t kAppId = 1234u;
-
- service_status_update_builder_.AddAppID(kAppId);
- auto notification_ = service_status_update_builder_.notification();
-
- auto app_id_exist_ =
- (*notification_)[strings::msg_params].keyExists(strings::app_id);
- auto app_id_ = (*notification_)[strings::msg_params][strings::app_id].asInt();
-
- EXPECT_TRUE(app_id_exist_);
- EXPECT_EQ(kAppId, app_id_);
-}
-
-TEST(ServiceStatusUpdateNotificationBuilderTest, AddServiceUpdateReason) {
- auto service_status_update_builder_ =
- ServiceStatusUpdateBuilder::CreateBuilder(ServiceType::VIDEO,
- ServiceEvent::REQUEST_REJECTED);
-
- service_status_update_builder_.AddServiceUpdateReason(
- UpdateReason::INVALID_CERT);
- auto notification_ = service_status_update_builder_.notification();
- auto reason_exist_ =
- (*notification_)[strings::msg_params].keyExists(hmi_notification::reason);
- auto reason_ =
- (*notification_)[strings::msg_params][hmi_notification::reason].asInt();
-
- EXPECT_TRUE(reason_exist_);
- EXPECT_EQ(static_cast<int64_t>(UpdateReason::INVALID_CERT), reason_);
-}
-
} // namespace application_manager_test
} // namespace components
} // namespace test
diff --git a/src/components/application_manager/test/mock_message_helper.cc b/src/components/application_manager/test/mock_message_helper.cc
index b2c932a981..628fd97ae8 100755
--- a/src/components/application_manager/test/mock_message_helper.cc
+++ b/src/components/application_manager/test/mock_message_helper.cc
@@ -601,41 +601,6 @@ void MessageHelper::SendUnsubscribeButtonNotification(
->SendUnsubscribeButtonNotification(button, application, app_mngr);
}
-MockMessageHelper::MockServiceStatusUpdateNotificationBuilder*
-MockMessageHelper::on_service_update_builder_mock() {
- static ::testing::NiceMock<
- MockMessageHelper::MockServiceStatusUpdateNotificationBuilder>
- on_service_update_builder_mock;
- return &on_service_update_builder_mock;
-}
-
-MessageHelper::ServiceStatusUpdateNotificationBuilder
-MessageHelper::ServiceStatusUpdateNotificationBuilder::CreateBuilder(
- hmi_apis::Common_ServiceType::eType service_type,
- hmi_apis::Common_ServiceEvent::eType service_event) {
- return MockMessageHelper::on_service_update_builder_mock()->CreateBuilder(
- service_type, service_event);
-}
-
-MessageHelper::ServiceStatusUpdateNotificationBuilder&
-MessageHelper::ServiceStatusUpdateNotificationBuilder::AddAppID(
- const uint32_t app_id) {
- return MockMessageHelper::on_service_update_builder_mock()->AddAppID(app_id);
-}
-
-MessageHelper::ServiceStatusUpdateNotificationBuilder&
-MessageHelper::ServiceStatusUpdateNotificationBuilder::AddServiceUpdateReason(
- const hmi_apis::Common_ServiceStatusUpdateReason::eType
- service_update_reason) {
- return MockMessageHelper::on_service_update_builder_mock()
- ->AddServiceUpdateReason(service_update_reason);
-}
-
-smart_objects::SmartObjectSPtr
-MessageHelper::ServiceStatusUpdateNotificationBuilder::notification() const {
- return MockMessageHelper::on_service_update_builder_mock()->notification();
-}
-
smart_objects::SmartObject MessageHelper::CreateAppServiceCapabilities(
std::vector<smart_objects::SmartObject>& all_services) {
return MockMessageHelper::message_helper_mock()->CreateAppServiceCapabilities(
@@ -662,4 +627,15 @@ MessageHelper::CreateDisplayCapabilityUpdateToMobile(
return MockMessageHelper::message_helper_mock()
->CreateDisplayCapabilityUpdateToMobile(system_capabilities, app);
}
+
+smart_objects::SmartObjectSPtr MessageHelper::CreateOnServiceUpdateNotification(
+ const hmi_apis::Common_ServiceType::eType service_type,
+ const hmi_apis::Common_ServiceEvent::eType service_event,
+ const hmi_apis::Common_ServiceStatusUpdateReason::eType
+ service_update_reason,
+ const uint32_t app_id) {
+ return MockMessageHelper::message_helper_mock()
+ ->CreateOnServiceUpdateNotification(
+ service_type, service_event, service_update_reason, app_id);
+}
} // namespace application_manager