2 * Copyright (C) 2019 Samsung. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.config;
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertTrue;
24 import org.junit.Test;
25 import org.onap.config.api.ConfigurationManager;
26 import org.onap.config.impl.CliConfigurationImpl;
27 import org.onap.config.util.ConfigTestConstant;
28 import org.onap.config.util.TestImplementationConfiguration;
30 public class CliConfigurationImpTest {
32 private static final String NAMESPACE = "CLIConfiguration";
33 private static final String TENANT = "OPENECOMP";
34 private static final String IMPL_KEY = "CLIImpl";
35 private static final String SERVICE_CONF = "testService";
38 public void testGenerateAndPopulateMap() {
41 ConfigurationManager conf = new CliConfigurationImpl();
43 Map outputMap = conf.generateMap(TENANT, NAMESPACE, ConfigTestConstant.ARTIFACT);
44 TestImplementationConfiguration testServiceImpl =
45 conf.populateMap(TENANT, NAMESPACE, IMPL_KEY, TestImplementationConfiguration.class)
49 validateCliMapConfig(outputMap);
50 assertTrue(testServiceImpl.isEnable());
51 assertEquals("org.junit.Test", testServiceImpl.getImplementationClass());
54 private void validateCliMapConfig(Map outputMap) {
56 outputMap.get(withoutArtifactPrefix(ConfigTestConstant.ARTIFACT_CONSUMER)));
58 extract(outputMap, withoutArtifactPrefix(ConfigTestConstant.ARTIFACT_NAME_MINLENGTH)));
60 outputMap.get(withoutArtifactPrefix(ConfigTestConstant.ARTIFACT_ENCODED)));
62 extract(outputMap, withoutArtifactPrefix(ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH)));
63 assertEquals("pdf", outputMap.get(withoutArtifactPrefix(ConfigTestConstant.ARTIFACT_EXT)));
64 assertEquals("Base64",
65 outputMap.get(withoutArtifactPrefix(ConfigTestConstant.ARTIFACT_ENC)));
66 assertEquals("a-zA-Z_0-9",
67 extract(outputMap, withoutArtifactPrefix(ConfigTestConstant.ARTIFACT_NAME_UPPER)));
68 assertEquals("deleted",
69 outputMap.get(withoutArtifactPrefix(ConfigTestConstant.ARTIFACT_STATUS)));
73 private String withoutArtifactPrefix(String key) {
74 return key.replace(ConfigTestConstant.ARTIFACT + ".", "");
77 private String extract(Map map, String keys) {
79 String[] keysList = keys.split("\\.");
80 Map recursive = (Map) map.get(keysList[0]);
82 for (int i = 1; i < keysList.length; i++) {
83 if (i == keysList.length - 1) {
84 return (String) recursive.get(keysList[i]);
86 recursive = (Map) recursive.get(keysList[i]);