summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJackLivio <jack@livio.io>2019-03-17 15:19:48 -0400
committerGitHub <noreply@github.com>2019-03-17 15:19:48 -0400
commit79ce3c927bf6b1c661bfb8174031370694ea9ff6 (patch)
tree94a12f9a762b111ed3fec668bb6f0e2eb16b739d
parent6c6e363dc72338893dc8c577e9b59867a3215aa2 (diff)
parent36b383be1c8dd77218d0954e7851389c1de71f08 (diff)
downloadsdl_core-79ce3c927bf6b1c661bfb8174031370694ea9ff6.tar.gz
Merge pull request #2846 from smartdevicelink/tests/app_service_command_tests
App Service Command Unit Tests
-rw-r--r--src/components/application_manager/include/application_manager/commands/command_impl.h1
-rw-r--r--src/components/application_manager/rpc_plugins/app_service_rpc_plugin/test/CMakeLists.txt2
-rw-r--r--src/components/application_manager/rpc_plugins/app_service_rpc_plugin/test/commands/mobile/on_app_service_data_notification_test.cc217
-rw-r--r--src/components/application_manager/test/commands/CMakeLists.txt1
-rw-r--r--src/components/application_manager/test/commands/command_request_impl_test.cc86
-rw-r--r--src/components/application_manager/test/include/application_manager/mock_app_service_manager.h2
6 files changed, 309 insertions, 0 deletions
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/rpc_plugins/app_service_rpc_plugin/test/CMakeLists.txt b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/test/CMakeLists.txt
index 97d2efaf07..0b56ddb7e9 100644
--- 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
@@ -7,6 +7,7 @@ include_directories(
${COMPONENTS_DIR}/application_manager/test/include/
${POLICY_MOCK_INCLUDE_PATH}/
${CMAKE_SOURCE_DIR}/src
+ ${COMPONENTS_DIR}/resumption/include
)
@@ -33,6 +34,7 @@ set(LIBRARIES
sdl_rpc_plugin
jsoncpp
Policy
+ Resumption
)
create_cotired_test("app_services_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..47358ef631
--- /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/test/commands/CMakeLists.txt b/src/components/application_manager/test/commands/CMakeLists.txt
index 33258e60db..556f3a5032 100644
--- a/src/components/application_manager/test/commands/CMakeLists.txt
+++ b/src/components/application_manager/test/commands/CMakeLists.txt
@@ -59,6 +59,7 @@ set(LIBRARIES
ApplicationManager
jsoncpp
Policy
+ Resumption
)
create_test("commands_test" "${SOURCES}" "${LIBRARIES}")
diff --git a/src/components/application_manager/test/commands/command_request_impl_test.cc b/src/components/application_manager/test/commands/command_request_impl_test.cc
index d4a62d069f..6d80a11440 100644
--- a/src/components/application_manager/test/commands/command_request_impl_test.cc
+++ b/src/components/application_manager/test/commands/command_request_impl_test.cc
@@ -51,6 +51,9 @@
#include "application_manager/mock_hmi_interface.h"
#include "interfaces/MOBILE_API.h"
+#include "application_manager/mock_app_service_manager.h"
+#include "resumption/last_state_impl.h"
+
namespace test {
namespace components {
namespace commands_test {
@@ -64,6 +67,7 @@ using ::testing::_;
using ::testing::Return;
using ::testing::SaveArg;
using ::testing::DoAll;
+using ::testing::SetArgReferee;
using am::commands::MessageSharedPtr;
using am::CommandParametersPermissions;
@@ -74,6 +78,7 @@ using am::ApplicationManager;
using am::ApplicationSet;
using am::RPCParams;
using am::MockHmiInterfaces;
+using test::components::application_manager_test::MockAppServiceManager;
typedef am::commands::CommandRequestImpl::RequestState RequestState;
@@ -585,6 +590,87 @@ TEST_F(CommandRequestImplTest, AppNotFound_HashUpdateNotExpected) {
command.reset();
}
+TEST_F(CommandRequestImplTest, SendProviderRequest_ByServiceType) {
+ resumption::LastStateImpl last_state("app_storage_folder",
+ "app_info_storage");
+ MockAppServiceManager app_service_manager(app_mngr_, last_state);
+ MockAppPtr mock_app = CreateMockApp();
+ EXPECT_CALL(app_mngr_, GetAppServiceManager())
+ .WillRepeatedly(ReturnRef(app_service_manager));
+ EXPECT_CALL(app_service_manager, GetProviderByType("MEDIA", _, _, _))
+ .WillOnce(DoAll(SetArgReferee<2>(mock_app), SetArgReferee<3>(false)));
+
+ MessageSharedPtr result;
+ EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _))
+ .WillOnce(DoAll(SaveArg<0>(&result), Return(true)));
+
+ MessageSharedPtr msg = CreateMessage();
+ (*msg)[strings::params][strings::function_id] =
+ mobile_apis::FunctionID::GetAppServiceDataID;
+ (*msg)[strings::msg_params][strings::service_type] = "MEDIA";
+
+ CommandPtr command = CreateCommand<UCommandRequestImpl>(msg);
+ command->SendProviderRequest(
+ mobile_apis::FunctionID::GetAppServiceDataID,
+ hmi_apis::FunctionID::AppService_GetAppServiceData,
+ &(*msg),
+ true);
+}
+
+TEST_F(CommandRequestImplTest, SendProviderRequest_ByProviderID) {
+ resumption::LastStateImpl last_state("app_storage_folder",
+ "app_info_storage");
+ MockAppServiceManager app_service_manager(app_mngr_, last_state);
+ MockAppPtr mock_app = CreateMockApp();
+ EXPECT_CALL(app_mngr_, GetAppServiceManager())
+ .WillRepeatedly(ReturnRef(app_service_manager));
+ EXPECT_CALL(app_service_manager, GetProviderByID("serviceid12345", _, _, _))
+ .WillOnce(DoAll(SetArgReferee<2>(mock_app), SetArgReferee<3>(false)));
+
+ MessageSharedPtr result;
+ EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _))
+ .WillOnce(DoAll(SaveArg<0>(&result), Return(true)));
+
+ MessageSharedPtr msg = CreateMessage();
+ (*msg)[strings::params][strings::function_id] =
+ mobile_apis::FunctionID::GetAppServiceDataID;
+ (*msg)[strings::msg_params][strings::service_id] = "serviceid12345";
+
+ CommandPtr command = CreateCommand<UCommandRequestImpl>(msg);
+ command->SendProviderRequest(
+ mobile_apis::FunctionID::GetAppServiceDataID,
+ hmi_apis::FunctionID::AppService_GetAppServiceData,
+ &(*msg),
+ true);
+}
+
+TEST_F(CommandRequestImplTest, SendProviderRequestToHMI_ByProviderID) {
+ resumption::LastStateImpl last_state("app_storage_folder",
+ "app_info_storage");
+ MockAppServiceManager app_service_manager(app_mngr_, last_state);
+ MockAppPtr mock_app = CreateMockApp();
+ EXPECT_CALL(app_mngr_, GetAppServiceManager())
+ .WillRepeatedly(ReturnRef(app_service_manager));
+ EXPECT_CALL(app_service_manager, GetProviderByID("serviceid12345", _, _, _))
+ .WillOnce(DoAll(SetArgReferee<2>(mock_app), SetArgReferee<3>(true)));
+
+ MessageSharedPtr result;
+ EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _))
+ .WillOnce(DoAll(SaveArg<0>(&result), Return(true)));
+
+ MessageSharedPtr msg = CreateMessage();
+ (*msg)[strings::params][strings::function_id] =
+ mobile_apis::FunctionID::GetAppServiceDataID;
+ (*msg)[strings::msg_params][strings::service_id] = "serviceid12345";
+
+ CommandPtr command = CreateCommand<UCommandRequestImpl>(msg);
+ command->SendProviderRequest(
+ mobile_apis::FunctionID::GetAppServiceDataID,
+ hmi_apis::FunctionID::AppService_GetAppServiceData,
+ &(*msg),
+ true);
+}
+
} // namespace command_request_impl
} // namespace commands_test
} // namespace components
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 311268689a..f77b5685da 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 {