Skip to content

Commit 9d61a18

Browse files
committed
Remove notification builder
1 parent 41e6f89 commit 9d61a18

File tree

7 files changed

+53
-276
lines changed

7 files changed

+53
-276
lines changed

src/components/application_manager/include/application_manager/message_helper.h

Lines changed: 5 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -88,63 +88,11 @@ class MessageHelper {
8888
static smart_objects::SmartObjectSPtr CreateHMINotification(
8989
hmi_apis::FunctionID::eType function_id);
9090

91-
/**
92-
* @brief ServiceStatusUpdateNotificationBuilder small utility class used for
93-
* more flexible construction of OnServiceUpdateNotification
94-
*/
95-
class ServiceStatusUpdateNotificationBuilder {
96-
public:
97-
typedef hmi_apis::Common_ServiceType::eType ServiceType;
98-
typedef hmi_apis::Common_ServiceEvent::eType ServiceEvent;
99-
typedef hmi_apis::Common_ServiceStatusUpdateReason::eType
100-
ServiceStatusUpdateReason;
101-
102-
/**
103-
* @brief CreateBuilder creates builder instance
104-
* @param service_type - enum value containing service type
105-
* @param service_event - enum value containing service event
106-
* @returns builder instance
107-
*/
108-
static ServiceStatusUpdateNotificationBuilder CreateBuilder(
109-
const ServiceType service_type, const ServiceEvent service_event);
110-
111-
/**
112-
* @brief AddAppID adds app id to notification
113-
* @param app_id application id to add
114-
* @returns ref to builder instance
115-
*/
116-
ServiceStatusUpdateNotificationBuilder& AddAppID(const uint32_t app_id);
117-
118-
/**
119-
* @brief AddServiceUpdateReason adds service update reason to notification
120-
* @param service_update_reason enum value containing update reason
121-
* @returns ref to builder instance
122-
*/
123-
ServiceStatusUpdateNotificationBuilder& AddServiceUpdateReason(
124-
const ServiceStatusUpdateReason service_update_reason);
125-
126-
/**
127-
* @brief notification gets notification SO
128-
* @returns shared ptr to notification SO
129-
*/
130-
smart_objects::SmartObjectSPtr notification() const;
131-
132-
protected:
133-
smart_objects::SmartObjectSPtr notification_;
134-
135-
/**
136-
* @brief class constructor
137-
* @param service_type - enum value containing service type
138-
* @param service_event - enum value containing service event
139-
*/
140-
ServiceStatusUpdateNotificationBuilder(const ServiceType service_type,
141-
const ServiceEvent service_event);
142-
143-
/**
144-
* @brief class constructor
145-
*/
146-
ServiceStatusUpdateNotificationBuilder(){};
147-
};
91+
static smart_objects::SmartObjectSPtr CreateOnServiceUpdateNotification(
92+
const hmi_apis::Common_ServiceType::eType type,
93+
const hmi_apis::Common_ServiceEvent::eType event,
94+
const hmi_apis::Common_ServiceStatusUpdateReason::eType reason,
95+
const uint32_t app_id);
14896

14997
/**
15098
* @brief Creates request for different interfaces(JSON)

src/components/application_manager/src/application_manager_impl.cc

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,19 +2029,17 @@ void ApplicationManagerImpl::ProcessServiceStatusUpdate(
20292029
<< " service_update_reason " << service_update_reason);
20302030

20312031
const auto app = application(connection_key);
2032-
auto notification_builder =
2033-
MessageHelper::ServiceStatusUpdateNotificationBuilder::CreateBuilder(
2034-
service_type, service_event);
20352032

2036-
if (app) {
2037-
notification_builder.AddAppID(app->app_id());
2038-
}
2033+
const uint32_t app_id = app ? app->app_id() : 0u;
20392034

2040-
if (service_update_reason) {
2041-
notification_builder.AddServiceUpdateReason(*service_update_reason);
2042-
}
2035+
auto reason = service_update_reason
2036+
? *service_update_reason
2037+
: hmi_apis::Common_ServiceStatusUpdateReason::INVALID_ENUM;
2038+
2039+
auto notification = MessageHelper::CreateOnServiceUpdateNotification(
2040+
service_type, service_event, reason, app_id);
20432041

2044-
rpc_service_->ManageHMICommand(notification_builder.notification());
2042+
rpc_service_->ManageHMICommand(notification);
20452043
}
20462044

20472045
void ApplicationManagerImpl::OnSecondaryTransportStartedCallback(

src/components/application_manager/src/message_helper/message_helper.cc

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,45 +2139,32 @@ smart_objects::SmartObjectSPtr MessageHelper::CreateNegativeResponse(
21392139
return std::make_shared<smart_objects::SmartObject>(response_data);
21402140
}
21412141

2142-
MessageHelper::ServiceStatusUpdateNotificationBuilder::
2143-
ServiceStatusUpdateNotificationBuilder(const ServiceType service_type,
2144-
const ServiceEvent service_event) {
2145-
notification_ = MessageHelper::CreateHMINotification(
2142+
smart_objects::SmartObjectSPtr MessageHelper::CreateOnServiceUpdateNotification(
2143+
const hmi_apis::Common_ServiceType::eType service_type,
2144+
const hmi_apis::Common_ServiceEvent::eType service_event,
2145+
const hmi_apis::Common_ServiceStatusUpdateReason::eType
2146+
service_update_reason,
2147+
const uint32_t app_id) {
2148+
LOG4CXX_AUTO_TRACE(logger_);
2149+
auto notification = MessageHelper::CreateHMINotification(
21462150
hmi_apis::FunctionID::BasicCommunication_OnServiceUpdate);
21472151

2148-
(*notification_)[strings::msg_params][hmi_notification::service_type] =
2152+
(*notification)[strings::msg_params][hmi_notification::service_type] =
21492153
service_type;
2150-
(*notification_)[strings::msg_params][hmi_notification::service_event] =
2154+
(*notification)[strings::msg_params][hmi_notification::service_event] =
21512155
service_event;
2152-
}
2153-
2154-
MessageHelper::ServiceStatusUpdateNotificationBuilder
2155-
MessageHelper::ServiceStatusUpdateNotificationBuilder::CreateBuilder(
2156-
const ServiceType service_type, const ServiceEvent service_event) {
2157-
MessageHelper::ServiceStatusUpdateNotificationBuilder builder{service_type,
2158-
service_event};
2159-
return builder;
2160-
}
2161-
2162-
MessageHelper::ServiceStatusUpdateNotificationBuilder&
2163-
MessageHelper::ServiceStatusUpdateNotificationBuilder::AddAppID(
2164-
const uint32_t app_id) {
2165-
(*notification_)[strings::msg_params][strings::app_id] = app_id;
21662156

2167-
return *this;
2168-
}
2157+
if (0 != app_id) {
2158+
(*notification)[strings::msg_params][strings::app_id] = app_id;
2159+
}
21692160

2170-
MessageHelper::ServiceStatusUpdateNotificationBuilder&
2171-
MessageHelper::ServiceStatusUpdateNotificationBuilder::AddServiceUpdateReason(
2172-
const ServiceStatusUpdateReason service_update_reason) {
2173-
(*notification_)[strings::msg_params][hmi_notification::reason] =
2174-
service_update_reason;
2161+
if (hmi_apis::Common_ServiceStatusUpdateReason::INVALID_ENUM !=
2162+
service_update_reason) {
2163+
(*notification)[strings::msg_params][hmi_notification::reason] =
2164+
service_update_reason;
2165+
}
21752166

2176-
return *this;
2177-
}
2178-
smart_objects::SmartObjectSPtr
2179-
MessageHelper::ServiceStatusUpdateNotificationBuilder::notification() const {
2180-
return notification_;
2167+
return notification;
21812168
}
21822169

21832170
void MessageHelper::SendNaviSetVideoConfig(

src/components/application_manager/test/application_manager_impl_test.cc

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ const std::string kAppId = "someID";
103103
const uint32_t kConnectionKey = 1232u;
104104
const std::string kAppName = "appName";
105105

106-
typedef MockMessageHelper::MockServiceStatusUpdateNotificationBuilder*
107-
MockServiceStatusUpdatePtr;
108106
typedef hmi_apis::Common_ServiceStatusUpdateReason::eType
109107
ServiceStatusUpdateReason;
110108
typedef hmi_apis::Common_ServiceType::eType ServiceType;
@@ -152,8 +150,6 @@ class ApplicationManagerImplTest
152150
new MockAppServiceManager(mock_app_mngr_, mock_last_state_))
153151
, mock_message_helper_(
154152
application_manager::MockMessageHelper::message_helper_mock())
155-
, mock_service_status_update_(application_manager::MockMessageHelper::
156-
on_service_update_builder_mock())
157153

158154
{
159155
#ifdef ENABLE_LOG
@@ -274,7 +270,6 @@ class ApplicationManagerImplTest
274270
std::unique_ptr<am::ApplicationManagerImpl> app_manager_impl_;
275271
MockAppServiceManager* mock_app_service_manager_;
276272
application_manager::MockMessageHelper* mock_message_helper_;
277-
MockServiceStatusUpdatePtr mock_service_status_update_;
278273

279274
std::shared_ptr<MockApplication> mock_app_ptr_;
280275
NiceMock<protocol_handler_test::MockProtocolHandler> mock_protocol_handler_;
@@ -333,14 +328,8 @@ TEST_P(ApplicationManagerImplTest,
333328
AddMockApplication();
334329

335330
ON_CALL(*mock_app_ptr_, app_id()).WillByDefault(Return(kConnectionKey));
336-
ON_CALL(*mock_service_status_update_,
337-
CreateBuilder(GetParam().service_type_, GetParam().service_event_))
338-
.WillByDefault(Return(*mock_service_status_update_));
339-
ON_CALL(*mock_service_status_update_, AddAppID(kConnectionKey))
340-
.WillByDefault(ReturnRef(*mock_service_status_update_));
341-
ON_CALL(*mock_service_status_update_, AddServiceUpdateReason(_))
342-
.WillByDefault(ReturnRef(*mock_service_status_update_));
343-
ON_CALL(*mock_service_status_update_, notification())
331+
332+
ON_CALL(*mock_message_helper_, CreateOnServiceUpdateNotification(_, _, _, _))
344333
.WillByDefault(Return(notification_));
345334

346335
EXPECT_CALL(*mock_rpc_service_, ManageHMICommand(notification_, _))

src/components/application_manager/test/include/application_manager/mock_message_helper.h

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -320,42 +320,15 @@ class MockMessageHelper {
320320
MOCK_METHOD2(BroadcastCapabilityUpdate,
321321
void(smart_objects::SmartObject& msg_params,
322322
ApplicationManager& app_mngr));
323-
MOCK_METHOD3(CreateOnServiceUpdateNotification, smart_objects::SmartObject(
324-
const uint32_t app_id,
325-
const hmi_apis::Common_ServiceType::eType service_type,
326-
const hmi_apis::Common_ServiceEvent::eType service_event));
327-
MOCK_METHOD4(CreateOnServiceUpdateNotification, smart_objects::SmartObject(
328-
const uint32_t app_id,
329-
const hmi_apis::Common_ServiceType::eType service_type,
330-
const hmi_apis::Common_ServiceEvent::eType service_event,
331-
const hmi_apis::Common_ServiceStatusUpdateReason::eType
332-
service_update_reason));
333-
334-
class MockServiceStatusUpdateNotificationBuilder
335-
: public MessageHelper::ServiceStatusUpdateNotificationBuilder {
336-
public:
337-
MockServiceStatusUpdateNotificationBuilder(
338-
const MockServiceStatusUpdateNotificationBuilder& obj){};
339-
MockServiceStatusUpdateNotificationBuilder(){};
340-
MOCK_METHOD2(CreateBuilder,
341-
MessageHelper::ServiceStatusUpdateNotificationBuilder(
342-
hmi_apis::Common_ServiceType::eType,
343-
hmi_apis::Common_ServiceEvent::eType));
344-
345-
MOCK_METHOD1(AddAppID,
346-
MessageHelper::ServiceStatusUpdateNotificationBuilder &
347-
(const uint32_t app_id));
348-
349-
MOCK_METHOD1(AddServiceUpdateReason,
350-
MessageHelper::ServiceStatusUpdateNotificationBuilder &
351-
(const hmi_apis::Common_ServiceStatusUpdateReason::eType));
352-
353-
MOCK_CONST_METHOD0(notification, smart_objects::SmartObjectSPtr());
354-
};
323+
MOCK_METHOD4(CreateOnServiceUpdateNotification,
324+
smart_objects::SmartObjectSPtr(
325+
const hmi_apis::Common_ServiceType::eType service_type,
326+
const hmi_apis::Common_ServiceEvent::eType service_event,
327+
const hmi_apis::Common_ServiceStatusUpdateReason::eType
328+
service_update_reason,
329+
const uint32_t app_id));
355330

356-
static MockMessageHelper* message_helper_mock();
357-
static MockServiceStatusUpdateNotificationBuilder*
358-
on_service_update_builder_mock();
331+
static MockMessageHelper* message_helper_mock();
359332
};
360333

361334
} // namespace application_manager

src/components/application_manager/test/message_helper/message_helper_test.cc

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,6 @@ using namespace application_manager;
6969
typedef std::shared_ptr<MockApplication> MockApplicationSharedPtr;
7070
typedef std::vector<std::string> StringArray;
7171
typedef std::shared_ptr<application_manager::Application> ApplicationSharedPtr;
72-
typedef MessageHelper::ServiceStatusUpdateNotificationBuilder::ServiceType
73-
ServiceType;
74-
typedef MessageHelper::ServiceStatusUpdateNotificationBuilder::ServiceEvent
75-
ServiceEvent;
76-
typedef MessageHelper::ServiceStatusUpdateNotificationBuilder::
77-
ServiceStatusUpdateReason UpdateReason;
78-
typedef MessageHelper::ServiceStatusUpdateNotificationBuilder
79-
ServiceStatusUpdateBuilder;
8072

8173
using testing::_;
8274
using testing::AtLeast;
@@ -1092,92 +1084,6 @@ TEST_F(MessageHelperTest, SendNaviSetVideoConfigRequest) {
10921084
EXPECT_EQ(480, msg_params[strings::config][strings::height].asInt());
10931085
}
10941086

1095-
TEST(ServiceStatusUpdateNotificationBuilderTest, CreateBuilderIsCorrect) {
1096-
auto service_status_update_builder_ =
1097-
ServiceStatusUpdateBuilder::CreateBuilder(ServiceType::AUDIO,
1098-
ServiceEvent::REQUEST_ACCEPTED);
1099-
auto notification_ = service_status_update_builder_.notification();
1100-
1101-
auto message_type_exist_ =
1102-
(*notification_)[strings::params].keyExists(strings::message_type);
1103-
auto message_type_ =
1104-
(*notification_)[strings::params][strings::message_type].asInt();
1105-
auto function_id_exist_ =
1106-
(*notification_)[strings::params].keyExists(strings::function_id);
1107-
auto function_id_ =
1108-
(*notification_)[strings::params][strings::function_id].asInt();
1109-
auto protocol_version_exist_ =
1110-
(*notification_)[strings::params].keyExists(strings::protocol_version);
1111-
auto protocol_version_ =
1112-
(*notification_)[strings::params][strings::protocol_version].asInt();
1113-
auto protocol_type_exist_ =
1114-
(*notification_)[strings::params].keyExists(strings::protocol_type);
1115-
auto protocol_type_ =
1116-
(*notification_)[strings::params][strings::protocol_type].asInt();
1117-
auto service_type_exist_ = (*notification_)[strings::msg_params].keyExists(
1118-
hmi_notification::service_type);
1119-
auto service_type_ =
1120-
(*notification_)[strings::msg_params][hmi_notification::service_type]
1121-
.asInt();
1122-
auto service_event_exist_ = (*notification_)[strings::msg_params].keyExists(
1123-
hmi_notification::service_event);
1124-
auto service_event_ =
1125-
(*notification_)[strings::msg_params][hmi_notification::service_event]
1126-
.asInt();
1127-
1128-
EXPECT_TRUE(message_type_exist_);
1129-
EXPECT_EQ(static_cast<int64_t>(kNotification), message_type_);
1130-
EXPECT_TRUE(function_id_exist_);
1131-
EXPECT_EQ(static_cast<int64_t>(
1132-
hmi_apis::FunctionID::BasicCommunication_OnServiceUpdate),
1133-
function_id_);
1134-
EXPECT_TRUE(protocol_version_exist_);
1135-
EXPECT_EQ(static_cast<int64_t>(commands::CommandImpl::protocol_version_),
1136-
protocol_version_);
1137-
EXPECT_TRUE(protocol_type_exist_);
1138-
EXPECT_EQ(static_cast<int64_t>(commands::CommandImpl::hmi_protocol_type_),
1139-
protocol_type_);
1140-
EXPECT_TRUE(service_type_exist_);
1141-
EXPECT_EQ(static_cast<int64_t>(ServiceType::AUDIO), service_type_);
1142-
EXPECT_TRUE(service_event_exist_);
1143-
EXPECT_EQ(static_cast<int64_t>(ServiceEvent::REQUEST_ACCEPTED),
1144-
service_event_);
1145-
}
1146-
1147-
TEST(ServiceStatusUpdateNotificationBuilderTest, AddAppID) {
1148-
auto service_status_update_builder_ =
1149-
ServiceStatusUpdateBuilder::CreateBuilder(ServiceType::RPC,
1150-
ServiceEvent::REQUEST_RECEIVED);
1151-
const uint32_t kAppId = 1234u;
1152-
1153-
service_status_update_builder_.AddAppID(kAppId);
1154-
auto notification_ = service_status_update_builder_.notification();
1155-
1156-
auto app_id_exist_ =
1157-
(*notification_)[strings::msg_params].keyExists(strings::app_id);
1158-
auto app_id_ = (*notification_)[strings::msg_params][strings::app_id].asInt();
1159-
1160-
EXPECT_TRUE(app_id_exist_);
1161-
EXPECT_EQ(kAppId, app_id_);
1162-
}
1163-
1164-
TEST(ServiceStatusUpdateNotificationBuilderTest, AddServiceUpdateReason) {
1165-
auto service_status_update_builder_ =
1166-
ServiceStatusUpdateBuilder::CreateBuilder(ServiceType::VIDEO,
1167-
ServiceEvent::REQUEST_REJECTED);
1168-
1169-
service_status_update_builder_.AddServiceUpdateReason(
1170-
UpdateReason::INVALID_CERT);
1171-
auto notification_ = service_status_update_builder_.notification();
1172-
auto reason_exist_ =
1173-
(*notification_)[strings::msg_params].keyExists(hmi_notification::reason);
1174-
auto reason_ =
1175-
(*notification_)[strings::msg_params][hmi_notification::reason].asInt();
1176-
1177-
EXPECT_TRUE(reason_exist_);
1178-
EXPECT_EQ(static_cast<int64_t>(UpdateReason::INVALID_CERT), reason_);
1179-
}
1180-
11811087
} // namespace application_manager_test
11821088
} // namespace components
11831089
} // namespace test

0 commit comments

Comments
 (0)