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 org.junit.Test;
20 import org.onap.config.api.ConfigurationManager;
21 import org.onap.config.impl.CliConfigurationImpl;
22 import org.onap.config.util.ConfigTestConstant;
23 import org.onap.config.util.TestImplementationConfiguration;
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertTrue;
30 public class CliConfigurtationImpTest {
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() throws Exception {
41 ConfigurationManager conf = new CliConfigurationImpl();
43 Map outputMap = conf.generateMap(TENANT, NAMESPACE, ConfigTestConstant.ARTIFACT);
44 TestImplementationConfiguration testServiceImpl = conf.populateMap(TENANT, NAMESPACE, IMPL_KEY,
45 TestImplementationConfiguration.class).get(SERVICE_CONF);
48 validateCliMapConfig(outputMap);
49 assertTrue(testServiceImpl.isEnable());
50 assertEquals("org.junit.Test", testServiceImpl.getImplementationClass());
53 private void validateCliMapConfig(Map outputMap){
54 assertEquals("appc", outputMap.get(
55 withoutArtifactPrefix(ConfigTestConstant.ARTIFACT_CONSUMER)));
56 assertEquals("6", extract(outputMap,
57 withoutArtifactPrefix(ConfigTestConstant.ARTIFACT_NAME_MINLENGTH)));
58 assertEquals("true", outputMap.get(
59 withoutArtifactPrefix(ConfigTestConstant.ARTIFACT_ENCODED)));
60 assertEquals("14", extract(outputMap,
61 withoutArtifactPrefix(ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH)));
62 assertEquals("pdf", outputMap.get(
63 withoutArtifactPrefix(ConfigTestConstant.ARTIFACT_EXT)));
64 assertEquals("Base64", outputMap.get(
65 withoutArtifactPrefix(ConfigTestConstant.ARTIFACT_ENC)));
66 assertEquals("a-zA-Z_0-9", extract(outputMap,
67 withoutArtifactPrefix(ConfigTestConstant.ARTIFACT_NAME_UPPER)));
68 assertEquals("deleted", outputMap.get(
69 withoutArtifactPrefix(ConfigTestConstant.ARTIFACT_STATUS)));
73 public String withoutArtifactPrefix(String key){
74 return key.replace(ConfigTestConstant.ARTIFACT + ".", "");
77 public 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]);