Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 1 | /* |
| 2 | Copyright (c) 2018-2019 Nokia. |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
Timo Tietavainen | a0745d2 | 2019-11-28 09:55:22 +0200 | [diff] [blame^] | 17 | /* |
| 18 | * This source code is part of the near-RT RIC (RAN Intelligent Controller) |
| 19 | * platform project (RICP). |
| 20 | */ |
| 21 | |
Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 22 | #include <gtest/gtest.h> |
| 23 | #include <gmock/gmock.h> |
| 24 | #include "private/namespaceconfigurationsimpl.hpp" |
| 25 | |
| 26 | using namespace shareddatalayer; |
| 27 | using namespace testing; |
| 28 | |
| 29 | namespace |
| 30 | { |
| 31 | class NamespaceConfigurationsImplTest: public testing::Test |
| 32 | { |
| 33 | public: |
| 34 | const std::string someKnownNamespace; |
| 35 | const std::string someKnownInputSource; |
| 36 | std::unique_ptr<NamespaceConfigurationsImpl> namespaceConfigurationsImpl; |
| 37 | |
| 38 | NamespaceConfigurationsImplTest(): |
| 39 | someKnownNamespace("someKnownPrefixValue123"), |
| 40 | someKnownInputSource("someKnownInputSource") |
| 41 | { |
| 42 | InSequence dummy; |
| 43 | namespaceConfigurationsImpl.reset(new NamespaceConfigurationsImpl()); |
| 44 | } |
| 45 | }; |
| 46 | } |
| 47 | |
| 48 | TEST_F(NamespaceConfigurationsImplTest, CanMatchToLongestNamespacePrefixAndReturnItsValues) |
| 49 | { |
| 50 | namespaceConfigurationsImpl->addNamespaceConfiguration({"some", true, false, someKnownInputSource}); |
| 51 | namespaceConfigurationsImpl->addNamespaceConfiguration({"someKnownPrefix", true, true, someKnownInputSource}); |
| 52 | namespaceConfigurationsImpl->addNamespaceConfiguration({"someKnownPrefixs", false, false, someKnownInputSource}); |
| 53 | EXPECT_TRUE(namespaceConfigurationsImpl->isDbBackendUseEnabled(someKnownNamespace)); |
| 54 | EXPECT_TRUE(namespaceConfigurationsImpl->areNotificationsEnabled(someKnownNamespace)); |
| 55 | } |
| 56 | |
| 57 | TEST_F(NamespaceConfigurationsImplTest, CanMatchToEmptyNamespacePrefixAndReturnItsValues) |
| 58 | { |
| 59 | namespaceConfigurationsImpl->addNamespaceConfiguration({"anotherKnownPrefix", true, true, someKnownInputSource}); |
| 60 | namespaceConfigurationsImpl->addNamespaceConfiguration({"", false, false, someKnownInputSource}); |
| 61 | EXPECT_FALSE(namespaceConfigurationsImpl->isDbBackendUseEnabled(someKnownNamespace)); |
| 62 | EXPECT_FALSE(namespaceConfigurationsImpl->areNotificationsEnabled(someKnownNamespace)); |
| 63 | } |
| 64 | |
| 65 | TEST_F(NamespaceConfigurationsImplTest, CanReturnDefaultValues) |
| 66 | { |
| 67 | EXPECT_TRUE(namespaceConfigurationsImpl->isDbBackendUseEnabled(someKnownNamespace)); |
| 68 | EXPECT_FALSE(namespaceConfigurationsImpl->areNotificationsEnabled(someKnownNamespace)); |
| 69 | } |
| 70 | |
| 71 | TEST_F(NamespaceConfigurationsImplTest, CanShowReadConfigurationDescription) |
| 72 | { |
| 73 | namespaceConfigurationsImpl->addNamespaceConfiguration({"someKnownPrefix", true, true, someKnownInputSource}); |
| 74 | EXPECT_EQ("someKnownInputSource prefix: someKnownPrefix, useDbBackend: true, enableNotifications: true", |
| 75 | namespaceConfigurationsImpl->getDescription(someKnownNamespace)); |
| 76 | |
| 77 | namespaceConfigurationsImpl.reset(new NamespaceConfigurationsImpl()); |
| 78 | namespaceConfigurationsImpl->addNamespaceConfiguration({"someKnownPrefix", true, false, someKnownInputSource}); |
| 79 | EXPECT_EQ("someKnownInputSource prefix: someKnownPrefix, useDbBackend: true, enableNotifications: false", |
| 80 | namespaceConfigurationsImpl->getDescription(someKnownNamespace)); |
| 81 | |
| 82 | namespaceConfigurationsImpl.reset(new NamespaceConfigurationsImpl()); |
| 83 | namespaceConfigurationsImpl->addNamespaceConfiguration({"someKnownPrefix", false, false, someKnownInputSource}); |
| 84 | EXPECT_EQ("someKnownInputSource prefix: someKnownPrefix, useDbBackend: false, enableNotifications: false", |
| 85 | namespaceConfigurationsImpl->getDescription(someKnownNamespace)); |
| 86 | } |
| 87 | |
| 88 | TEST_F(NamespaceConfigurationsImplTest, CanShowDefaultValuesDescription) |
| 89 | { |
| 90 | EXPECT_EQ("<default>, useDbBackend: true, enableNotifications: false", |
| 91 | namespaceConfigurationsImpl->getDescription(someKnownNamespace)); |
| 92 | } |
| 93 | |
| 94 | TEST_F(NamespaceConfigurationsImplTest, NamespaceIsAddedToLookupTableAfterFirstSearch) |
| 95 | { |
| 96 | EXPECT_FALSE(namespaceConfigurationsImpl->isNamespaceInLookupTable(someKnownNamespace)); |
| 97 | namespaceConfigurationsImpl->addNamespaceConfiguration({"someKnownPrefix", true, true, someKnownInputSource}); |
| 98 | EXPECT_EQ("someKnownInputSource prefix: someKnownPrefix, useDbBackend: true, enableNotifications: true", |
| 99 | namespaceConfigurationsImpl->getDescription(someKnownNamespace)); |
| 100 | EXPECT_TRUE(namespaceConfigurationsImpl->isNamespaceInLookupTable(someKnownNamespace)); |
| 101 | |
| 102 | //Check that data can be correctly read also when configuration is read through lookup table |
| 103 | EXPECT_EQ("someKnownInputSource prefix: someKnownPrefix, useDbBackend: true, enableNotifications: true", |
| 104 | namespaceConfigurationsImpl->getDescription(someKnownNamespace)); |
| 105 | } |
| 106 | |
| 107 | TEST_F(NamespaceConfigurationsImplTest, DoesNotAllowConfigurationAdditionsAfterLookupTableInitialization) |
| 108 | { |
| 109 | // All configurations must be added before configurations are read. |
| 110 | namespaceConfigurationsImpl->addNamespaceConfiguration({"someKnownPrefix", true, true, someKnownInputSource}); |
| 111 | EXPECT_TRUE(namespaceConfigurationsImpl->isDbBackendUseEnabled(someKnownNamespace)); |
| 112 | EXPECT_EXIT(namespaceConfigurationsImpl->addNamespaceConfiguration({"someKnownPrefix2", false, false, someKnownInputSource}), |
| 113 | KilledBySignal(SIGABRT), "ABORT.*namespaceconfigurationsimpl\\.cpp"); |
| 114 | } |
| 115 | |
| 116 | TEST_F(NamespaceConfigurationsImplTest, IsEmptyReturnsCorrectInformation) |
| 117 | { |
| 118 | EXPECT_TRUE(namespaceConfigurationsImpl->isEmpty()); |
| 119 | namespaceConfigurationsImpl->addNamespaceConfiguration({"someKnownPrefix", true, true, someKnownInputSource}); |
| 120 | EXPECT_FALSE(namespaceConfigurationsImpl->isEmpty()); |
| 121 | } |