8a39d1bff0c0b565a1d55195e98df585a18ffab4
[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.onap.config.Constants;
34
35 public class ConfigurationRepositoryTest {
36
37     private static final String[] EMPTY_ARRAY_OF_STRING = new String[0];
38
39     private ConfigurationRepository repository;
40
41     @Before
42     public void init() {
43         repository = ConfigurationRepository.lookup();
44     }
45
46     @Test
47     public void testFreshCreatedOne() {
48         // when - then
49         assertTrue(repository.isValidTenant(Constants.DEFAULT_TENANT));
50         assertTrue(repository.isValidNamespace(Constants.DEFAULT_NAMESPACE));
51     }
52
53     @Test
54     public void testFreshCreatedTwo() {
55         // when
56         final Set<String> tenants = repository.getTenants();
57         final Set<String> namespaces = repository.getNamespaces();
58
59         // then
60         assertEquals(1, tenants.size());
61         assertEquals(1, namespaces.size());
62
63         assertEquals(Constants.DEFAULT_TENANT, tenants.toArray(EMPTY_ARRAY_OF_STRING)[0]);
64         assertEquals(Constants.DEFAULT_NAMESPACE, namespaces.toArray(EMPTY_ARRAY_OF_STRING)[0]);
65     }
66
67     @Test
68     public void testConfigurationPopulated() throws Exception {
69         // given
70         BaseConfiguration inputConfig = new BaseConfiguration();
71
72         // when
73         repository.populateConfiguration(Constants.DEFAULT_TENANT + Constants.KEY_ELEMENTS_DELIMITER
74                 + Constants.DEFAULT_NAMESPACE, inputConfig);
75         final Configuration outputConfig = repository.getConfigurationFor(Constants.DEFAULT_TENANT,
76                 Constants.DEFAULT_NAMESPACE);
77
78         // then
79         assertEquals(inputConfig, outputConfig);
80     }
81 }