d604d1e75743a65c3779be6837a27813d609f8a3
[sdc.git] / common / onap-common-configuration-management / onap-configuration-management-core / src / test / java / org / onap / config / impl / ConfigurationRepositoryTest.java
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.assertNotNull;
26 import static org.junit.Assert.assertTrue;
27
28 import java.util.Set;
29
30 import org.apache.commons.configuration2.BaseConfiguration;
31 import org.apache.commons.configuration2.Configuration;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.onap.config.Constants;
35
36 public class ConfigurationRepositoryTest {
37
38     private static final String[] EMPTY_ARRAY_OF_STRING = new String[0];
39     private static final String TEST_NAME_SPACE = "testNameSpace";
40
41     private ConfigurationRepository repository;
42
43     @Before
44     public void init() {
45         repository = ConfigurationRepository.lookup();
46     }
47
48     @Test
49     public void testFreshCreatedOne() {
50         // when - then
51         assertTrue(repository.isValidTenant(Constants.DEFAULT_TENANT));
52         assertTrue(repository.isValidNamespace(Constants.DEFAULT_NAMESPACE));
53     }
54
55     @Test
56     public void testFreshCreatedTwo() {
57         // when
58         final Set<String> tenants = repository.getTenants();
59         final Set<String> namespaces = repository.getNamespaces();
60
61         // then
62         assertTrue(tenants.size() > 0);
63         assertTrue(namespaces.size() > 0);
64
65         assertNotNull(tenants.toArray(EMPTY_ARRAY_OF_STRING)[0]);
66         assertNotNull(namespaces.toArray(EMPTY_ARRAY_OF_STRING)[0]);
67     }
68
69     @Test
70     public void testConfigurationPopulated() throws Exception {
71         // given
72         BaseConfiguration inputConfig = new BaseConfiguration();
73
74         // when
75         repository.populateConfiguration(Constants.DEFAULT_TENANT + Constants.KEY_ELEMENTS_DELIMITER
76             + TEST_NAME_SPACE, inputConfig);
77         final Configuration outputConfig =
78             repository.getConfigurationFor(Constants.DEFAULT_TENANT, TEST_NAME_SPACE);
79
80         // then
81         assertEquals(inputConfig, outputConfig);
82     }
83 }