diff options
Diffstat (limited to 'src/components/policy/test/policy_manager_impl_test.cc')
-rw-r--r-- | src/components/policy/test/policy_manager_impl_test.cc | 166 |
1 files changed, 94 insertions, 72 deletions
diff --git a/src/components/policy/test/policy_manager_impl_test.cc b/src/components/policy/test/policy_manager_impl_test.cc index 84fbcf1116..9bc30b3508 100644 --- a/src/components/policy/test/policy_manager_impl_test.cc +++ b/src/components/policy/test/policy_manager_impl_test.cc @@ -1,4 +1,5 @@ -/* Copyright (c) 2014, Ford Motor Company +/* + * Copyright (c) 2016, Ford Motor Company * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -64,11 +65,11 @@ namespace components { namespace policy { class PolicyManagerImplTest : public ::testing::Test { - protected: - PolicyManagerImpl* manager; - MockCacheManagerInterface* cache_manager; +protected: + PolicyManagerImpl *manager; + MockCacheManagerInterface *cache_manager; MockUpdateStatusManager update_manager; - MockPolicyListener* listener; + MockPolicyListener *listener; void SetUp() { manager = new PolicyManagerImpl(); @@ -85,7 +86,7 @@ class PolicyManagerImplTest : public ::testing::Test { delete listener; } - ::testing::AssertionResult IsValid(const policy_table::Table& table) { + ::testing::AssertionResult IsValid(const policy_table::Table &table) { if (table.is_valid()) { return ::testing::AssertionSuccess(); } else { @@ -96,23 +97,25 @@ class PolicyManagerImplTest : public ::testing::Test { } }; -TEST_F(PolicyManagerImplTest, RefreshRetrySequence_SetSecondsBetweenRetries_ExpectRetryTimeoutSequenceWithSameSeconds) { +TEST_F( + PolicyManagerImplTest, + RefreshRetrySequence_SetSecondsBetweenRetries_ExpectRetryTimeoutSequenceWithSameSeconds) { - //arrange + // arrange std::vector<int> seconds; seconds.push_back(50); seconds.push_back(100); seconds.push_back(200); - //assert + // assert EXPECT_CALL(*cache_manager, TimeoutResponse()).WillOnce(Return(60)); - EXPECT_CALL(*cache_manager, SecondsBetweenRetries(_)).WillOnce( - DoAll(SetArgReferee<0>(seconds), Return(true))); + EXPECT_CALL(*cache_manager, SecondsBetweenRetries(_)) + .WillOnce(DoAll(SetArgReferee<0>(seconds), Return(true))); - //act + // act manager->RefreshRetrySequence(); - //assert + // assert EXPECT_EQ(50, manager->NextRetryTimeout()); EXPECT_EQ(100, manager->NextRetryTimeout()); EXPECT_EQ(200, manager->NextRetryTimeout()); @@ -121,23 +124,22 @@ TEST_F(PolicyManagerImplTest, RefreshRetrySequence_SetSecondsBetweenRetries_Expe TEST_F(PolicyManagerImplTest, DISABLED_GetUpdateUrl) { - EXPECT_CALL(*cache_manager, GetServiceUrls("7",_)); - EXPECT_CALL(*cache_manager, GetServiceUrls("4",_)); + EXPECT_CALL(*cache_manager, GetServiceUrls("7", _)); + EXPECT_CALL(*cache_manager, GetServiceUrls("4", _)); EndpointUrls ep_7; manager->GetServiceUrls("7", ep_7); - EXPECT_EQ("http://policies.telematics.ford.com/api/policies", ep_7[0].url[0] ); + EXPECT_EQ("http://policies.telematics.ford.com/api/policies", ep_7[0].url[0]); EndpointUrls ep_4; manager->GetServiceUrls("4", ep_4); EXPECT_EQ("http://policies.ford.com/api/policies", ep_4[0].url[0]); - } - TEST_F(PolicyManagerImplTest, ResetPT) { - EXPECT_CALL(*cache_manager, ResetPT("filename")).WillOnce(Return(true)) + EXPECT_CALL(*cache_manager, ResetPT("filename")) + .WillOnce(Return(true)) .WillOnce(Return(false)); EXPECT_CALL(*cache_manager, TimeoutResponse()); EXPECT_CALL(*cache_manager, SecondsBetweenRetries(_)); @@ -146,24 +148,25 @@ TEST_F(PolicyManagerImplTest, ResetPT) { EXPECT_FALSE(manager->ResetPT("filename")); } -TEST_F(PolicyManagerImplTest, CheckPermissions_SetHmiLevelFullForAlert_ExpectAllowedPermissions) { +TEST_F(PolicyManagerImplTest, + CheckPermissions_SetHmiLevelFullForAlert_ExpectAllowedPermissions) { - //arrange + // arrange ::policy::CheckPermissionResult expected; expected.hmi_level_permitted = ::policy::kRpcAllowed; expected.list_of_allowed_params.push_back("speed"); expected.list_of_allowed_params.push_back("gps"); - //assert - EXPECT_CALL(*cache_manager, CheckPermissions("12345678", "FULL", "Alert", _)). - WillOnce(SetArgReferee<3>(expected)); + // assert + EXPECT_CALL(*cache_manager, CheckPermissions("12345678", "FULL", "Alert", _)) + .WillOnce(SetArgReferee<3>(expected)); - //act + // act ::policy::RPCParams input_params; ::policy::CheckPermissionResult output; manager->CheckPermissions("12345678", "FULL", "Alert", input_params, output); - //assert + // assert EXPECT_EQ(::policy::kRpcAllowed, output.hmi_level_permitted); ASSERT_TRUE(!output.list_of_allowed_params.empty()); @@ -174,17 +177,17 @@ TEST_F(PolicyManagerImplTest, CheckPermissions_SetHmiLevelFullForAlert_ExpectAll TEST_F(PolicyManagerImplTest, LoadPT_SetPT_PTIsLoaded) { - //arrange + // arrange Json::Value table(Json::objectValue); table["policy_table"] = Json::Value(Json::objectValue); - Json::Value& policy_table = table["policy_table"]; + Json::Value &policy_table = table["policy_table"]; policy_table["module_config"] = Json::Value(Json::objectValue); policy_table["functional_groupings"] = Json::Value(Json::objectValue); policy_table["consumer_friendly_messages"] = Json::Value(Json::objectValue); policy_table["app_policies"] = Json::Value(Json::objectValue); - Json::Value& module_config = policy_table["module_config"]; + Json::Value &module_config = policy_table["module_config"]; module_config["preloaded_pt"] = Json::Value(true); module_config["exchange_after_x_ignition_cycles"] = Json::Value(10); module_config["exchange_after_x_kilometers"] = Json::Value(100); @@ -197,10 +200,10 @@ TEST_F(PolicyManagerImplTest, LoadPT_SetPT_PTIsLoaded) { module_config["endpoints"] = Json::Value(Json::objectValue); module_config["endpoints"]["0x00"] = Json::Value(Json::objectValue); module_config["endpoints"]["0x00"]["default"] = Json::Value(Json::arrayValue); - module_config["endpoints"]["0x00"]["default"][0] = Json::Value( - "http://ford.com/cloud/default"); - module_config["notifications_per_minute_by_priority"] = Json::Value( - Json::objectValue); + module_config["endpoints"]["0x00"]["default"][0] = + Json::Value("http://ford.com/cloud/default"); + module_config["notifications_per_minute_by_priority"] = + Json::Value(Json::objectValue); module_config["notifications_per_minute_by_priority"]["emergency"] = Json::Value(1); module_config["notifications_per_minute_by_priority"]["navigation"] = @@ -209,17 +212,17 @@ TEST_F(PolicyManagerImplTest, LoadPT_SetPT_PTIsLoaded) { Json::Value(3); module_config["notifications_per_minute_by_priority"]["communication"] = Json::Value(4); - module_config["notifications_per_minute_by_priority"]["normal"] = Json::Value( - 5); - module_config["notifications_per_minute_by_priority"]["none"] = Json::Value( - 6); + module_config["notifications_per_minute_by_priority"]["normal"] = + Json::Value(5); + module_config["notifications_per_minute_by_priority"]["none"] = + Json::Value(6); module_config["vehicle_make"] = Json::Value("MakeT"); module_config["vehicle_model"] = Json::Value("ModelT"); module_config["vehicle_year"] = Json::Value("2014"); - Json::Value& functional_groupings = policy_table["functional_groupings"]; + Json::Value &functional_groupings = policy_table["functional_groupings"]; functional_groupings["default"] = Json::Value(Json::objectValue); - Json::Value& default_group = functional_groupings["default"]; + Json::Value &default_group = functional_groupings["default"]; default_group["rpcs"] = Json::Value(Json::objectValue); default_group["rpcs"]["Update"] = Json::Value(Json::objectValue); default_group["rpcs"]["Update"]["hmi_levels"] = Json::Value(Json::arrayValue); @@ -227,11 +230,11 @@ TEST_F(PolicyManagerImplTest, LoadPT_SetPT_PTIsLoaded) { default_group["rpcs"]["Update"]["parameters"] = Json::Value(Json::arrayValue); default_group["rpcs"]["Update"]["parameters"][0] = Json::Value("speed"); - Json::Value& consumer_friendly_messages = + Json::Value &consumer_friendly_messages = policy_table["consumer_friendly_messages"]; consumer_friendly_messages["version"] = Json::Value("1.2"); - Json::Value& app_policies = policy_table["app_policies"]; + Json::Value &app_policies = policy_table["app_policies"]; app_policies["default"] = Json::Value(Json::objectValue); app_policies["default"]["memory_kb"] = Json::Value(50); app_policies["default"]["heart_beat_timeout_ms"] = Json::Value(100); @@ -256,18 +259,17 @@ TEST_F(PolicyManagerImplTest, LoadPT_SetPT_PTIsLoaded) { policy_table::Table update(&table); update.SetPolicyTableType(rpc::policy_table_interface_base::PT_UPDATE); - //assert + // assert ASSERT_TRUE(IsValid(update)); - - //act + // act std::string json = table.toStyledString(); ::policy::BinaryMessage msg(json.begin(), json.end()); - utils::SharedPtr<policy_table::Table> snapshot = new policy_table::Table( - update.policy_table); + utils::SharedPtr<policy_table::Table> snapshot = + new policy_table::Table(update.policy_table); - //assert + // assert EXPECT_CALL(*cache_manager, GenerateSnapshot()).WillOnce(Return(snapshot)); EXPECT_CALL(*cache_manager, ApplyUpdate(_)).WillOnce(Return(true)); EXPECT_CALL(*listener, GetAppName("1234")).WillOnce(Return("")); @@ -276,36 +278,56 @@ TEST_F(PolicyManagerImplTest, LoadPT_SetPT_PTIsLoaded) { EXPECT_CALL(*cache_manager, TimeoutResponse()); EXPECT_CALL(*cache_manager, SecondsBetweenRetries(_)); - EXPECT_TRUE(manager->LoadPT("file_pt_update.json", msg)); -} - -TEST_F(PolicyManagerImplTest, RequestPTUpdate_SetPT_GeneratedSnapshotAndPTUpdate) { - - //arrange - ::utils::SharedPtr< ::policy_table::Table > p_table = - new ::policy_table::Table(); - - //assert - EXPECT_CALL(*cache_manager, GenerateSnapshot()).WillOnce(Return(p_table)); + TEST_F(PolicyManagerImplTest2, NextRetryTimeout_ExpectTimeoutsFromPT) { + // Arrange + std::ifstream ifile("sdl_preloaded_pt.json"); + Json::Reader reader; + Json::Value root(Json::objectValue); + if (ifile.is_open() && reader.parse(ifile, root, true)) { + Json::Value seconds_between_retries = Json::Value(Json::arrayValue); + seconds_between_retries = + root["policy_table"]["module_config"]["seconds_between_retries"]; + uint32_t size = seconds_between_retries.size(); + CreateLocalPT("sdl_preloaded_pt.json"); + + uint32_t waiting_timeout = 0u; + + for (uint32_t retry_number = 0u; retry_number < size; ++retry_number) { + waiting_timeout += seconds_between_retries[retry_number].asInt(); + waiting_timeout += manager->TimeoutExchange(); + + // it's in miliseconds + EXPECT_EQ(waiting_timeout * date_time::DateTime::MILLISECONDS_IN_SECOND, + manager->NextRetryTimeout()); + } + } + } - //act - manager->RequestPTUpdate(); -} + TEST_F(PolicyManagerImplTest, + RequestPTUpdate_SetPT_GeneratedSnapshotAndPTUpdate) { + // arrange + ::utils::SharedPtr<::policy_table::Table> p_table = + new ::policy_table::Table(); -TEST_F(PolicyManagerImplTest, DISABLED_AddApplication) { - // TODO(AOleynik): Implementation of method should be changed to avoid - // using of snapshot - //manager->AddApplication("12345678"); -} + // assert + EXPECT_CALL(*cache_manager, GenerateSnapshot()).WillOnce(Return(p_table)); -TEST_F(PolicyManagerImplTest, DISABLED_GetPolicyTableStatus) { - // TODO(AOleynik): Test is not finished, to be continued - //manager->GetPolicyTableStatus(); -} + // act + manager->RequestPTUpdate(); + } + TEST_F(PolicyManagerImplTest, DISABLED_AddApplication) { + // TODO(AOleynik): Implementation of method should be changed to avoid + // using of snapshot + // manager->AddApplication("12345678"); + } + TEST_F(PolicyManagerImplTest, DISABLED_GetPolicyTableStatus) { + // TODO(AOleynik): Test is not finished, to be continued + // manager->GetPolicyTableStatus(); + } } // namespace policy -}// namespace components -} // namespace test +} // namespace components +} // namespace test |