summaryrefslogtreecommitdiffstats
path: root/common/onap-common-configuration-management
diff options
context:
space:
mode:
authork.kedron <k.kedron@partner.samsung.com>2019-05-28 11:40:36 +0200
committerOfir Sonsino <ofir.sonsino@intl.att.com>2019-06-02 11:00:44 +0000
commitb3126da0e7011d263cb19c317aef59f6ec68d844 (patch)
treec8f5e6895142f98e3867538d2c7f7489545763be /common/onap-common-configuration-management
parent72a7b3c2a2f056f38dc100c7407662ee3aeb0edc (diff)
Add new unit test for ConfigurationImpl.
Issue-ID: SDC-2327 Signed-off-by: Krystian Kedron <k.kedron@partner.samsung.com> Change-Id: I96269b0bcdf3c1254052d057b8c4ad2d7a48c89d
Diffstat (limited to 'common/onap-common-configuration-management')
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/CliConfigurtationImpTest.java92
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/util/ConfigTestConstant.java34
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/util/TestImplementationConfiguration.java52
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/CLIConfiguration/config.json23
4 files changed, 185 insertions, 16 deletions
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/CliConfigurtationImpTest.java b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/CliConfigurtationImpTest.java
new file mode 100644
index 0000000000..0d460a2bb1
--- /dev/null
+++ b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/CliConfigurtationImpTest.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2019 Samsung. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.config;
+
+import org.junit.Test;
+import org.onap.config.api.ConfigurationManager;
+import org.onap.config.impl.CliConfigurationImpl;
+import org.onap.config.util.ConfigTestConstant;
+import org.onap.config.util.TestImplementationConfiguration;
+
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class CliConfigurtationImpTest {
+
+ private static final String NAMESPACE = "CLIConfiguration";
+ private static final String TENANT = "OPENECOMP";
+ private static final String IMPL_KEY = "CLIImpl";
+ private static final String SERVICE_CONF = "testService";
+
+ @Test
+ public void testGenerateAndPopulateMap() throws Exception {
+
+ // given
+ ConfigurationManager conf = new CliConfigurationImpl();
+ // when
+ Map outputMap = conf.generateMap(TENANT, NAMESPACE, ConfigTestConstant.ARTIFACT);
+ TestImplementationConfiguration testServiceImpl = conf.populateMap(TENANT, NAMESPACE, IMPL_KEY,
+ TestImplementationConfiguration.class).get(SERVICE_CONF);
+
+ // then
+ validateCliMapConfig(outputMap);
+ assertTrue(testServiceImpl.isEnable());
+ assertEquals("org.junit.Test", testServiceImpl.getImplementationClass());
+ }
+
+ private void validateCliMapConfig(Map outputMap){
+ assertEquals("appc", outputMap.get(
+ withoutArtifactPrefix(ConfigTestConstant.ARTIFACT_CONSUMER)));
+ assertEquals("6", extract(outputMap,
+ withoutArtifactPrefix(ConfigTestConstant.ARTIFACT_NAME_MINLENGTH)));
+ assertEquals("true", outputMap.get(
+ withoutArtifactPrefix(ConfigTestConstant.ARTIFACT_ENCODED)));
+ assertEquals("14", extract(outputMap,
+ withoutArtifactPrefix(ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH)));
+ assertEquals("pdf", outputMap.get(
+ withoutArtifactPrefix(ConfigTestConstant.ARTIFACT_EXT)));
+ assertEquals("Base64", outputMap.get(
+ withoutArtifactPrefix(ConfigTestConstant.ARTIFACT_ENC)));
+ assertEquals("a-zA-Z_0-9", extract(outputMap,
+ withoutArtifactPrefix(ConfigTestConstant.ARTIFACT_NAME_UPPER)));
+ assertEquals("deleted", outputMap.get(
+ withoutArtifactPrefix(ConfigTestConstant.ARTIFACT_STATUS)));
+
+ }
+
+ public String withoutArtifactPrefix(String key){
+ return key.replace(ConfigTestConstant.ARTIFACT + ".", "");
+ }
+
+ public String extract(Map map, String keys) {
+
+ String[] keysList = keys.split("\\.");
+ Map recursive = (Map) map.get(keysList[0]);
+
+ for (int i = 1; i < keysList.length; i++) {
+ if (i == keysList.length - 1) {
+ return (String) recursive.get(keysList[i]);
+ }
+ recursive = (Map) recursive.get(keysList[i]);
+ }
+ return null;
+ }
+
+
+}
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/util/ConfigTestConstant.java b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/util/ConfigTestConstant.java
index 434c7d3fbd..b7bea4ca69 100644
--- a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/util/ConfigTestConstant.java
+++ b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/util/ConfigTestConstant.java
@@ -1,6 +1,8 @@
/*
* Copyright © 2016-2018 European Support Limited
*
+ * Modifications Copyright (c) 2019 Samsung
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -18,24 +20,24 @@ package org.onap.config.util;
public class ConfigTestConstant {
- public static final String ARTIFACT_NAME_MAXLENGTH = "artifact.name.maxlength";
- public static final String ARTIFACT_MAXSIZE = "artifact.maxsize";
- public static final String ARTIFACT_EXT = "artifact.extension";
- public static final String ARTIFACT_ENC = "artifact.supportedEncryption";
- public static final String ARTIFACT_NAME_UPPER = "artifact.name.allowedChar";
- public static final String ARTIFACT_NAME_LOWER = "artifact.name.allowedchar";
- public static final String ARTIFACT_STATUS = "artifact.status";
- public static final String ARTIFACT_LOC = "artifact.persistLocation";
- public static final String ARTIFACT_JSON_SCHEMA = "artifact.jsonSchema";
- public static final String ARTIFACT_XML_SCHEMA = "artifact.xmlSchema";
- public static final String ARTIFACT_CONSUMER_APPC = "artifact.consumerAPPC";
- public static final String ARTIFACT_CONSUMER = "artifact.consumer";
- public static final String ARTIFACT_MANDATORY_NAME = "artifact.mandatory.name";
- public static final String ARTIFACT_NAME_MINLENGTH = "artifact.name.minlength";
- public static final String ARTIFACT_ENCODED = "artifact.encoded";
+ public static final String ARTIFACT = "artifact";
+ public static final String ARTIFACT_NAME_MAXLENGTH = ARTIFACT + ".name.maxlength";
+ public static final String ARTIFACT_MAXSIZE = ARTIFACT + ".maxsize";
+ public static final String ARTIFACT_EXT = ARTIFACT + ".extension";
+ public static final String ARTIFACT_ENC = ARTIFACT + ".supportedEncryption";
+ public static final String ARTIFACT_NAME_UPPER = ARTIFACT + ".name.allowedChar";
+ public static final String ARTIFACT_NAME_LOWER = ARTIFACT + ".name.allowedchar";
+ public static final String ARTIFACT_STATUS = ARTIFACT + ".status";
+ public static final String ARTIFACT_LOC = ARTIFACT + ".persistLocation";
+ public static final String ARTIFACT_JSON_SCHEMA = ARTIFACT + ".jsonSchema";
+ public static final String ARTIFACT_XML_SCHEMA = ARTIFACT + ".xmlSchema";
+ public static final String ARTIFACT_CONSUMER_APPC = ARTIFACT + ".consumerAPPC";
+ public static final String ARTIFACT_CONSUMER = ARTIFACT + ".consumer";
+ public static final String ARTIFACT_MANDATORY_NAME = ARTIFACT + ".mandatory.name";
+ public static final String ARTIFACT_NAME_MINLENGTH = ARTIFACT + ".name.minlength";
+ public static final String ARTIFACT_ENCODED = ARTIFACT + ".encoded";
public static final String PATH = "PATH";
- public static final String ONBOARDING_NAMESPACE = "onboarding";
private ConfigTestConstant() {
// prevent instantiation
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/util/TestImplementationConfiguration.java b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/util/TestImplementationConfiguration.java
new file mode 100644
index 0000000000..8d79dea932
--- /dev/null
+++ b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/util/TestImplementationConfiguration.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2019 Samsung. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.config.util;
+
+import org.onap.config.api.Config;
+
+import java.util.Map;
+
+@Config(key = "")
+public class TestImplementationConfiguration {
+ @Config(key = "enable")
+ Boolean enable = true;
+ @Config(key = "implementationClass")
+ String implementationClass;
+ @Config(key = "properties")
+ Map<String, Object> properties;
+
+ public void setEnable(Boolean enable) {
+ this.enable = enable;
+ }
+
+ public Boolean isEnable() {
+ return enable;
+ }
+
+ public String getImplementationClass() {
+ return implementationClass;
+ }
+
+ public Map<String, Object> getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Map<String, Object> properties) {
+ this.properties = properties;
+ }
+
+}
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/CLIConfiguration/config.json b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/CLIConfiguration/config.json
new file mode 100644
index 0000000000..7809146439
--- /dev/null
+++ b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/resources/CLIConfiguration/config.json
@@ -0,0 +1,23 @@
+{
+ "artifact": {
+ "name": {
+ "minlength": "6",
+ "maxlength": "14",
+ "allowedChar": "a-zA-Z_0-9"
+ },
+ "consumer": "appc",
+ "encoded": "true",
+ "extension": "pdf",
+ "supportedEncryption": "Base64",
+ "status": "deleted"
+ },
+ "CLIImpl": {
+ "testService": {
+ "enable": "true",
+ "implementationClass": "org.junit.Test"
+ }
+ },
+ "_config": {
+ "namespace": "OPENECOMP:CLIConfiguration"
+ }
+} \ No newline at end of file