2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ===================================================================
22 package org.onap.config.impl;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertTrue;
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;
36 public class ConfigurationRepositoryTest {
38 private static final String[] EMPTY_ARRAY_OF_STRING = new String[0];
39 private static final String TEST_NAME_SPACE = "testNameSpace";
41 private ConfigurationRepository repository;
45 repository = ConfigurationRepository.lookup();
49 public void testFreshCreatedOne() {
51 assertTrue(repository.isValidTenant(Constants.DEFAULT_TENANT));
52 assertTrue(repository.isValidNamespace(Constants.DEFAULT_NAMESPACE));
56 public void testFreshCreatedTwo() {
58 final Set<String> tenants = repository.getTenants();
59 final Set<String> namespaces = repository.getNamespaces();
62 assertTrue(tenants.size() > 0);
63 assertTrue(namespaces.size() > 0);
65 assertNotNull(tenants.toArray(EMPTY_ARRAY_OF_STRING)[0]);
66 assertNotNull(namespaces.toArray(EMPTY_ARRAY_OF_STRING)[0]);
70 public void testConfigurationPopulated() throws Exception {
72 BaseConfiguration inputConfig = new BaseConfiguration();
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);
81 assertEquals(inputConfig, outputConfig);