1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "config_factory.h"
16
17 #include "gtest/gtest.h"
18 using namespace testing::ext;
19 using namespace OHOS::DistributedData;
20 class ConfigFactoryTest : public testing::Test {
21 public:
SetUpTestCase(void)22 static void SetUpTestCase(void) {}
TearDownTestCase(void)23 static void TearDownTestCase(void) {}
SetUp()24 void SetUp() {}
TearDown()25 void TearDown() {}
26 };
27
28 /**
29 * @tc.name: GlobalConfig
30 * @tc.desc: load the config.json global info.
31 * @tc.type: FUNC
32 * @tc.require:
33 * @tc.author: Sven Wang
34 */
HWTEST_F(ConfigFactoryTest, GlobalConfig, TestSize.Level0)35 HWTEST_F(ConfigFactoryTest, GlobalConfig, TestSize.Level0)
36 {
37 auto *global = ConfigFactory::GetInstance().GetGlobalConfig();
38 ASSERT_NE(global, nullptr);
39 ASSERT_EQ(global->processLabel, "distributeddata");
40 ASSERT_EQ(global->metaData, "service_meta");
41 ASSERT_EQ(global->version, "000.000.001");
42 std::vector<std::string> features{ "kvdb", "rdb", "object", "backup", "data_sync" };
43 ASSERT_EQ(global->features, features);
44 }
45
46 /**
47 * @tc.name: ComponentConfig
48 * @tc.desc: load the config.json component info.
49 * @tc.type: FUNC
50 * @tc.require:
51 * @tc.author: Sven Wang
52 */
HWTEST_F(ConfigFactoryTest, ComponentConfig, TestSize.Level0)53 HWTEST_F(ConfigFactoryTest, ComponentConfig, TestSize.Level0)
54 {
55 auto *components = ConfigFactory::GetInstance().GetComponentConfig();
56 ASSERT_NE(components, nullptr);
57 ASSERT_EQ(components->size(), 4);
58 const ComponentConfig &config = (*components)[0];
59 ASSERT_EQ(config.description, "3rd party adapter");
60 ASSERT_EQ(config.lib, "libconfigdemo.z.so");
61 ASSERT_EQ(config.constructor, "");
62 ASSERT_EQ(config.destructor, "");
63 ASSERT_EQ(config.params, "{\"count\":1,\"key\":\"value\"}");
64 }
65
66 /**
67 * @tc.name: CheckerConfig
68 * @tc.desc: load the config.json checkers info.
69 * @tc.type: FUNC
70 * @tc.require:
71 * @tc.author: Sven Wang
72 */
HWTEST_F(ConfigFactoryTest, CheckerConfig, TestSize.Level0)73 HWTEST_F(ConfigFactoryTest, CheckerConfig, TestSize.Level0)
74 {
75 auto *checker = ConfigFactory::GetInstance().GetCheckerConfig();
76 ASSERT_NE(checker, nullptr);
77 std::vector<std::string> checkers{"SystemChecker", "BundleChecker"};
78 ASSERT_EQ(checker->checkers, checkers);
79 ASSERT_EQ(checker->trusts[0].bundleName, "bundle_manager_service");
80 ASSERT_EQ(checker->trusts[0].appId, "bundle_manager_service");
81 ASSERT_EQ(checker->trusts[0].checker, "SystemChecker");
82 }
83
84 /**
85 * @tc.name: NetworkConfig
86 * @tc.desc: load the config.json networks info.
87 * @tc.type: FUNC
88 * @tc.require:
89 * @tc.author: Sven Wang
90 */
HWTEST_F(ConfigFactoryTest, NetworkConfig, TestSize.Level0)91 HWTEST_F(ConfigFactoryTest, NetworkConfig, TestSize.Level0)
92 {
93 auto *networks = ConfigFactory::GetInstance().GetNetworkConfig();
94 ASSERT_NE(networks, nullptr);
95 std::vector<std::string> chains{ "loadBalance", "authentication", "traffic-control", "router", "transport",
96 "fault-inject" };
97 ASSERT_EQ(networks->chains, chains);
98 std::vector<std::string> routers{ "OHOSRouter" };
99 ASSERT_EQ(networks->routers, routers);
100 std::vector<std::string> transports{ "softbus" };
101 ASSERT_EQ(networks->transports, transports);
102 ASSERT_EQ(networks->protocols[0].name, "OHOS softbus");
103 ASSERT_EQ(networks->protocols[0].address, "ohos.distributeddata");
104 ASSERT_EQ(networks->protocols[0].transport, "softbus");
105 }