c7cc96cfbe9bdfa088a42b53f12f206ca95f3ee6
[sdc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP SDC
4  * ================================================================================
5  * Copyright (C) 2019 Samsung. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END============================================
19  * ===================================================================
20  */
21
22 package org.onap.config.impl;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertTrue;
26
27 import java.util.Set;
28
29 import org.apache.commons.configuration2.BaseConfiguration;
30 import org.apache.commons.configuration2.Configuration;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.onap.config.Constants;
35 import org.powermock.core.classloader.annotations.PrepareForTest;
36 import org.powermock.modules.junit4.PowerMockRunner;
37
38 @RunWith(PowerMockRunner.class)
39 @PrepareForTest(ConfigurationRepository.class)
40 public class ConfigurationRepositoryTest {
41
42     private static final String[] EMPTY_ARRAY_OF_STRING = new String[0];
43
44     private ConfigurationRepository repository;
45
46     @Before
47     public void init() {
48         repository = ConfigurationRepository.lookup();
49     }
50
51     @Test
52     public void testFreshCreatedOne() {
53         // when - then
54         assertTrue(repository.isValidTenant(Constants.DEFAULT_TENANT));
55         assertTrue(repository.isValidNamespace(Constants.DEFAULT_NAMESPACE));
56     }
57
58     @Test
59     public void testFreshCreatedTwo() {
60         // when
61         final Set<String> tenants = repository.getTenants();
62         final Set<String> namespaces = repository.getNamespaces();
63
64         // then
65         assertEquals(1, tenants.size());
66         assertEquals(1, namespaces.size());
67
68         assertEquals(Constants.DEFAULT_TENANT, tenants.toArray(EMPTY_ARRAY_OF_STRING)[0]);
69         assertEquals(Constants.DEFAULT_NAMESPACE, namespaces.toArray(EMPTY_ARRAY_OF_STRING)[0]);
70     }
71
72     @Test
73     public void testConfigurationPopulated() throws Exception {
74         // given
75         BaseConfiguration inputConfig = new BaseConfiguration();
76
77         // when
78         repository.populateConfiguration(Constants.DEFAULT_TENANT + Constants.KEY_ELEMENTS_DELIMITER
79             + Constants.DEFAULT_NAMESPACE, inputConfig);
80         final Configuration outputConfig =
81             repository.getConfigurationFor(Constants.DEFAULT_TENANT, Constants.DEFAULT_NAMESPACE);
82
83         // then
84         assertEquals(inputConfig, outputConfig);
85     }
86 }