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.assertTrue;
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;
35 public class ConfigurationRepositoryTest {
37 private static final String[] EMPTY_ARRAY_OF_STRING = new String[0];
39 private ConfigurationRepository repository;
43 repository = ConfigurationRepository.lookup();
47 public void testFreshCreatedOne() {
49 assertTrue(repository.isValidTenant(Constants.DEFAULT_TENANT));
50 assertTrue(repository.isValidNamespace(Constants.DEFAULT_NAMESPACE));
54 public void testFreshCreatedTwo() {
56 final Set<String> tenants = repository.getTenants();
57 final Set<String> namespaces = repository.getNamespaces();
60 assertEquals(1, tenants.size());
61 assertEquals(1, namespaces.size());
63 assertEquals(Constants.DEFAULT_TENANT, tenants.toArray(EMPTY_ARRAY_OF_STRING)[0]);
64 assertEquals(Constants.DEFAULT_NAMESPACE, namespaces.toArray(EMPTY_ARRAY_OF_STRING)[0]);
68 public void testConfigurationPopulated() throws Exception {
70 BaseConfiguration inputConfig = new BaseConfiguration();
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);
79 assertEquals(inputConfig, outputConfig);