diff options
9 files changed, 303 insertions, 9 deletions
diff --git a/src/components/application_manager/include/application_manager/app_service_manager.h b/src/components/application_manager/include/application_manager/app_service_manager.h index 7f8d305edd..973c5054b4 100644 --- a/src/components/application_manager/include/application_manager/app_service_manager.h +++ b/src/components/application_manager/include/application_manager/app_service_manager.h @@ -142,7 +142,7 @@ class AppServiceManager { AppService* FindServiceByName(const std::string name); - AppService* FindServiceByID(const std::string service_id); + virtual AppService* FindServiceByID(const std::string service_id); std::string DefaultServiceByType(const std::string service_type); diff --git a/src/components/application_manager/include/application_manager/application_manager_impl.h b/src/components/application_manager/include/application_manager/application_manager_impl.h index 2d2eff7bd3..f20ed982e9 100644 --- a/src/components/application_manager/include/application_manager/application_manager_impl.h +++ b/src/components/application_manager/include/application_manager/application_manager_impl.h @@ -1586,8 +1586,7 @@ class ApplicationManagerImpl plugin_manager_.reset(plugin_manager.release()); } - virtual void SetAppServiceManager( - AppServiceManager* app_service_manager) { + virtual void SetAppServiceManager(AppServiceManager* app_service_manager) { app_service_manager_.reset(app_service_manager); } diff --git a/src/components/application_manager/include/application_manager/commands/command_impl.h b/src/components/application_manager/include/application_manager/commands/command_impl.h index 4859f73a55..dd1592c4aa 100644 --- a/src/components/application_manager/include/application_manager/commands/command_impl.h +++ b/src/components/application_manager/include/application_manager/commands/command_impl.h @@ -37,6 +37,7 @@ #include "application_manager/event_engine/event_observer.h" #include "application_manager/application_manager.h" #include "application_manager/smart_object_keys.h" +#include "policy/policy_types.h" #include "utils/logger.h" namespace application_manager { diff --git a/src/components/application_manager/include/application_manager/rpc_passing_handler.h b/src/components/application_manager/include/application_manager/rpc_passing_handler.h index 3ed10ff1e6..ce41b5a597 100644 --- a/src/components/application_manager/include/application_manager/rpc_passing_handler.h +++ b/src/components/application_manager/include/application_manager/rpc_passing_handler.h @@ -39,6 +39,7 @@ #include "application_manager/app_service_manager.h" #include <deque> #include "utils/timer.h" +#include "application_manager/commands/command.h" namespace application_manager { diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/CMakeLists.txt b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/CMakeLists.txt index 2bdc150906..1e23aac8ee 100644 --- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/CMakeLists.txt +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/CMakeLists.txt @@ -80,5 +80,5 @@ install(TARGETS app_service_rpc_plugin ) if(BUILD_TESTS) - # add_subdirectory(test) + add_subdirectory(test) endif() diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/test/CMakeLists.txt b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/test/CMakeLists.txt new file mode 100644 index 0000000000..02fb4fe4ec --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/test/CMakeLists.txt @@ -0,0 +1,72 @@ +# Copyright (c) 2019, Livio +# All rights reserved. + +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: + +# Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. + +# Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following +# disclaimer in the documentation and/or other materials provided with the +# distribution. + +# Neither the name of the copyright holders nor the names of their contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. + +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +include(${CMAKE_SOURCE_DIR}/tools/cmake/helpers/sources.cmake) + +include_directories ( + ${GMOCK_INCLUDE_DIRECTORY} + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${COMPONENTS_DIR}/application_manager/test/include + ${COMPONENTS_DIR}/include/test/application_manager/ + ${COMPONENTS_DIR}/resumption/include + ) + +set(APP_SERVICE_COMMANDS_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/commands) + +file(GLOB SOURCES + ${COMPONENTS_DIR}/application_manager/test/mock_message_helper.cc + ${APP_SERVICE_COMMANDS_TEST_DIR}/* + ${APP_SERVICE_COMMANDS_TEST_DIR}/mobile/* +) + +set(LIBRARIES + AppServiceRpcPluginStaticLib + ApplicationManager + connectionHandler + SmartObjects + ProtocolHandler + MessageHelper + connectionHandler + Utils + jsoncpp + gmock_main + dl + Resumption +) + +if(ENABLE_LOG) + list(APPEND LIBRARIES log4cxx -L${LOG4CXX_LIBS_DIRECTORY}) + list(APPEND LIBRARIES apr-1 -L${APR_LIBS_DIRECTORY}) + list(APPEND LIBRARIES aprutil-1 -L${APR_UTIL_LIBS_DIRECTORY}) + list(APPEND LIBRARIES expat -L${EXPAT_LIBS_DIRECTORY}) +endif() + +create_test("app_service_commands_test" "${SOURCES}" "${LIBRARIES}" ) + diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/test/commands/mobile/on_app_service_data_notification_test.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/test/commands/mobile/on_app_service_data_notification_test.cc new file mode 100644 index 0000000000..d501ea08ea --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/test/commands/mobile/on_app_service_data_notification_test.cc @@ -0,0 +1,217 @@ +/* + * Copyright (c) 2018, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "application_manager/application.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_app_service_manager.h" +#include "application_manager/commands/commands_test.h" +#include "app_service_rpc_plugin/commands/mobile/on_app_service_data_notification.h" +#include "app_service_rpc_plugin/app_service_rpc_plugin.h" +#include "app_service_rpc_plugin/app_service_app_extension.h" +#include "gtest/gtest.h" +#include "interfaces/MOBILE_API.h" +#include "application_manager/commands/command_impl.h" +#include "resumption/last_state_impl.h" + +namespace am = application_manager; +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::ReturnNull; +using ::testing::NiceMock; +using ::testing::SaveArg; +using ::testing::Mock; +using am::ApplicationSet; +using am::commands::MessageSharedPtr; +using test::components::application_manager_test::MockApplication; +using test::components::application_manager_test::MockApplicationManager; +using test::components::application_manager_test::MockAppServiceManager; +using test::components::commands_test::CommandsTest; +using test::components::commands_test::CommandsTestMocks; +using app_service_rpc_plugin::commands::OnAppServiceDataNotification; + +namespace { +const uint32_t kAppId = 0u; +const uint32_t kConnectionKey = 1u; +const std::string kPolicyAppId = "Test"; +const int kModuleId = 153u; +} + +namespace app_service_plugin_test { +using namespace app_service_rpc_plugin; +using application_manager::ApplicationSet; + +class OnAppServiceDatanotificationTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + OnAppServiceDatanotificationTest() + : mock_app_(std::make_shared<NiceMock<MockApplication> >()) + , app_service_app_extension_( + std::make_shared<app_service_rpc_plugin::AppServiceAppExtension>( + app_service_plugin_, *mock_app_)) + , apps_lock_(std::make_shared<sync_primitives::Lock>()) + , apps_da_(apps_, apps_lock_) + , last_state_("app_storage_folder", "app_info_storage") + , app_service_manager_(app_mngr_, last_state_) { + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kAppId)); + ON_CALL(*mock_app_, is_remote_control_supported()) + .WillByDefault(Return(true)); + ON_CALL(*mock_app_, QueryInterface(_)) + .WillByDefault(Return(app_service_app_extension_)); + } + + MessageSharedPtr CreateBasicMessage() { + MessageSharedPtr message = CreateMessage(); + (*message)[application_manager::strings::params] + [application_manager::strings::function_id] = + mobile_apis::FunctionID::OnAppServiceDataID; + (*message)[application_manager::strings::params] + [application_manager::strings::connection_key] = kConnectionKey; + (*message)[application_manager::strings::params] + [application_manager::strings::app_id] = kAppId; + + return message; + } + + protected: + std::shared_ptr<MockApplication> mock_app_; + std::shared_ptr<AppServiceAppExtension> app_service_app_extension_; + app_service_rpc_plugin::AppServiceRpcPlugin app_service_plugin_; + application_manager::ApplicationSet apps_; + const std::shared_ptr<sync_primitives::Lock> apps_lock_; + DataAccessor<application_manager::ApplicationSet> apps_da_; + resumption::LastStateImpl last_state_; + MockAppServiceManager app_service_manager_; +}; + +TEST_F(OnAppServiceDatanotificationTest, Run_SendMessageToMobile_Notification) { + MessageSharedPtr mobile_message = CreateBasicMessage(); + + (*mobile_message)[am::strings::msg_params][am::strings::service_data] + [am::strings::service_type] = "MEDIA"; + (*mobile_message)[am::strings::msg_params][am::strings::service_data] + [am::strings::service_id] = "mediaid1234"; + (*mobile_message)[am::strings::msg_params][am::strings::service_data] + ["mediaServiceData"]["mediaTitle"] = "media title"; + + apps_.insert(mock_app_); + app_service_app_extension_->SubscribeToAppService("MEDIA"); + ON_CALL(app_mngr_, applications()).WillByDefault(Return(apps_da_)); + + am::AppService service; + service.connection_key = 1; + service.mobile_service = true; + service + .record[am::strings::service_manifest][am::strings::allow_app_consumers] = + true; + EXPECT_CALL(app_service_manager_, FindServiceByID(_)) + .WillOnce(Return(&service)); + + EXPECT_CALL(app_mngr_, GetAppServiceManager()) + .WillRepeatedly(ReturnRef(app_service_manager_)); + + std::shared_ptr<OnAppServiceDataNotification> command = + CreateCommand<OnAppServiceDataNotification>(mobile_message); + + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(_, false)) + .WillOnce(SaveArg<0>(&mobile_message)); + // Act + command->Run(); + + // Assertions + ASSERT_TRUE(mobile_message.get()); + Mock::VerifyAndClearExpectations(&app_mngr_); +} + +TEST_F(OnAppServiceDatanotificationTest, Run_NoService) { + MessageSharedPtr mobile_message = CreateBasicMessage(); + + (*mobile_message)[am::strings::msg_params][am::strings::service_data] + [am::strings::service_type] = "MEDIA"; + (*mobile_message)[am::strings::msg_params][am::strings::service_data] + [am::strings::service_id] = "mediaid1234"; + (*mobile_message)[am::strings::msg_params][am::strings::service_data] + ["mediaServiceData"]["mediaTitle"] = "media title"; + + apps_.insert(mock_app_); + app_service_app_extension_->SubscribeToAppService("MEDIA"); + ON_CALL(app_mngr_, applications()).WillByDefault(Return(apps_da_)); + + EXPECT_CALL(app_service_manager_, FindServiceByID(_)).WillOnce(ReturnNull()); + + EXPECT_CALL(app_mngr_, GetAppServiceManager()) + .WillRepeatedly(ReturnRef(app_service_manager_)); + + std::shared_ptr<OnAppServiceDataNotification> command = + CreateCommand<OnAppServiceDataNotification>(mobile_message); + + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(_, false)).Times(0); + command->Run(); + + Mock::VerifyAndClearExpectations(&app_mngr_); +} + +TEST_F(OnAppServiceDatanotificationTest, Run_NoSubscribedApps) { + MessageSharedPtr mobile_message = CreateBasicMessage(); + + (*mobile_message)[am::strings::msg_params][am::strings::service_data] + [am::strings::service_type] = "MEDIA"; + (*mobile_message)[am::strings::msg_params][am::strings::service_data] + [am::strings::service_id] = "mediaid1234"; + (*mobile_message)[am::strings::msg_params][am::strings::service_data] + ["mediaServiceData"]["mediaTitle"] = "media title"; + + apps_.insert(mock_app_); + ON_CALL(app_mngr_, applications()).WillByDefault(Return(apps_da_)); + + am::AppService service; + service.connection_key = 1; + service.mobile_service = true; + service + .record[am::strings::service_manifest][am::strings::allow_app_consumers] = + true; + EXPECT_CALL(app_service_manager_, FindServiceByID(_)) + .WillOnce(Return(&service)); + + EXPECT_CALL(app_mngr_, GetAppServiceManager()) + .WillRepeatedly(ReturnRef(app_service_manager_)); + + std::shared_ptr<OnAppServiceDataNotification> command = + CreateCommand<OnAppServiceDataNotification>(mobile_message); + + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(_, false)).Times(0); + command->Run(); + + Mock::VerifyAndClearExpectations(&app_mngr_); +} + +} // namespace rc_rpc_plugin_test diff --git a/src/components/application_manager/src/app_service_manager.cc b/src/components/application_manager/src/app_service_manager.cc index c2f647f567..36d5307a41 100644 --- a/src/components/application_manager/src/app_service_manager.cc +++ b/src/components/application_manager/src/app_service_manager.cc @@ -189,7 +189,8 @@ void AppServiceManager::OnAppActivated(ApplicationConstSharedPtr app) { } } -std::vector<smart_objects::SmartObject> AppServiceManager::GetAllServiceRecords() { +std::vector<smart_objects::SmartObject> +AppServiceManager::GetAllServiceRecords() { LOG4CXX_AUTO_TRACE(logger_); std::vector<smart_objects::SmartObject> services; sync_primitives::AutoLock lock(published_services_lock_); diff --git a/src/components/application_manager/test/include/application_manager/mock_app_service_manager.h b/src/components/application_manager/test/include/application_manager/mock_app_service_manager.h index 030c130cbc..cad71f98ab 100644 --- a/src/components/application_manager/test/include/application_manager/mock_app_service_manager.h +++ b/src/components/application_manager/test/include/application_manager/mock_app_service_manager.h @@ -35,6 +35,8 @@ #include <gmock/gmock.h> #include "application_manager/app_service_manager.h" +#include "application_manager/commands/command.h" +#include "application_manager/commands/command_impl.h" namespace test { namespace components { @@ -45,10 +47,11 @@ class MockAppServiceManager : public application_manager::AppServiceManager { MockAppServiceManager(application_manager::ApplicationManager& app_manager, resumption::LastState& last_state) : application_manager::AppServiceManager(app_manager, last_state) {} - MOCK_METHOD3(PublishAppService, smart_objects::SmartObject( - const smart_objects::SmartObject& manifest, - const bool mobile_service, - const uint32_t connection_key)); + MOCK_METHOD3( + PublishAppService, + smart_objects::SmartObject(const smart_objects::SmartObject& manifest, + const bool mobile_service, + const uint32_t connection_key)); MOCK_METHOD1(UnpublishAppService, bool(const std::string service_id)); MOCK_METHOD1(UnpublishServices, void(const uint32_t connection_key)); MOCK_METHOD1(OnAppActivated, |