diff options
author | Brinda Santh <brindasanth@in.ibm.com> | 2018-08-26 16:20:04 -0400 |
---|---|---|
committer | Brinda Santh <brindasanth@in.ibm.com> | 2018-08-26 16:20:04 -0400 |
commit | 48c15ed0d02d98acac81773d84e928d0bd5ff07d (patch) | |
tree | 0a9e7bfad8689014e2e86984c1dc1d0dc7e4378f /ms/controllerblueprints/modules/resource-dict | |
parent | 7b23a92a3d079940193eaf141ff8494851b49d61 (diff) |
Controller Blueprints Microservice
Add Standardized resource definition in Initial data loading and Dictionary management services.
Change-Id: Ib33ba2ecf3cb1e1fb9b5dea71532e6bc8280bcbb
Issue-ID: CCSDK-487
Signed-off-by: Brinda Santh <brindasanth@in.ibm.com>
Diffstat (limited to 'ms/controllerblueprints/modules/resource-dict')
10 files changed, 154 insertions, 316 deletions
diff --git a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-db.json b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-db.json index 7ebeaa82c..661a9503b 100644 --- a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-db.json +++ b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-db.json @@ -7,7 +7,7 @@ "type": "string", "constraints": [ { - "validValues": [ + "valid_values": [ "SQL", "PLSQL" ] @@ -33,7 +33,7 @@ } }, "key-dependencies": { - "required": false, + "required": true, "type": "list", "entry_schema": { "type": "string" diff --git a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-default.json b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-default.json index dd0bffcc1..13e234e1b 100644 --- a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-default.json +++ b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-default.json @@ -7,7 +7,7 @@ "type": "string" }, "key-dependencies": { - "required": false, + "required": true, "type": "list", "entry_schema": { "type": "string" diff --git a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-input.json b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-input.json index 99c4691c4..126ea30bd 100644 --- a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-input.json +++ b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-input.json @@ -7,7 +7,7 @@ "type": "string" }, "key-dependencies": { - "required": false, + "required": true, "type": "list", "entry_schema": { "type": "string" diff --git a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-rest.json b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-rest.json index e77020ec9..f8dd8b6fc 100644 --- a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-rest.json +++ b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-rest.json @@ -8,8 +8,7 @@ "default": "JSON", "constraints": [ { - "validValues": [ - "XML", + "valid_values": [ "JSON" ] } @@ -29,7 +28,7 @@ "default": "JSON_PATH", "constraints": [ { - "validValues": [ + "valid_values": [ "JSON_PATH", "JSON_POINTER" ] @@ -51,7 +50,7 @@ } }, "key-dependencies": { - "required": false, + "required": true, "type": "list", "entry_schema": { "type": "string" diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java index 1af42c590..96ab1ee1a 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java @@ -1,5 +1,6 @@ /*
* Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,4 +22,8 @@ public class ResourceDictionaryConstants { public static final String SOURCE_DEFAULT = "default";
public static final String SOURCE_DB = "db";
public static final String SOURCE_MDSAL = "mdsal";
+
+ public static final String PROPERTY_INPUT_KEY_MAPPING = "input-key-mapping";
+ public static final String PROPERTY_OUTPUT_KEY_MAPPING = "output-key-mapping";
+ public static final String PROPERTY_KEY_DEPENDENCY = "key-dependency";
}
diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.java deleted file mode 100644 index 4f9467f05..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.java +++ /dev/null @@ -1,129 +0,0 @@ -/*
- * Copyright © 2017-2018 AT&T Intellectual Property.
- *
- * 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.ccsdk.apps.controllerblueprints.resource.dict.utils;
-
-import org.apache.commons.collections.MapUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.onap.ccsdk.apps.controllerblueprints.core.data.EntrySchema;
-import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition;
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment;
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants;
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.DictionaryDefinition;
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.DictionaryDependency;
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.ResourceSource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Map;
-import java.util.Optional;
-import java.util.function.Supplier;
-
-/**
- * ResourceDictionaryUtils.java Purpose to provide ResourceDictionaryUtils
- *
- * @author Brinda Santh
- * @version 1.0
- */
-public class ResourceDictionaryUtils {
-
- private ResourceDictionaryUtils() {
- // Do nothing
- }
-
- private static final Logger log = LoggerFactory.getLogger(ResourceDictionaryUtils.class);
-
- /**
- * This Method is to assign the source name to the Dictionary Definition Check to see if the source
- * definition is not present then assign, if more than one source then assign only one first source.
- *
- * @param resourceAssignment
- * @param dictionaryDefinition
- */
- @SuppressWarnings("squid:S3776")
- public static void populateSourceMapping(ResourceAssignment resourceAssignment,
- DictionaryDefinition dictionaryDefinition) {
-
- if (resourceAssignment != null && dictionaryDefinition != null
- && StringUtils.isBlank(resourceAssignment.getDictionarySource())) {
-
- // Overwrite the Property Definitions from Dictionary
- setProperty(resourceAssignment, dictionaryDefinition);
-
- Map<String, ResourceSource> dictionarySource = dictionaryDefinition.getSource();
- Map<String, DictionaryDependency> dictionaryDependencyMap = dictionaryDefinition.getDependency();
-
- if (MapUtils.isNotEmpty(dictionarySource)) {
- String source = findFirstSource(dictionarySource);
-
- // Populate and Assign First Source
- if (StringUtils.isNotBlank(source)) {
- // Set Dictionary Source
- resourceAssignment.setDictionarySource(source);
-
- if (MapUtils.isNotEmpty(dictionaryDependencyMap)) {
- // Set Dependencies
- DictionaryDependency dictionaryDependency = dictionaryDependencyMap.get(source);
- if (dictionaryDependency != null) {
- resourceAssignment.setDependencies(dictionaryDependency.getNames());
- }
- }
- } else {
- resourceAssignment.setDictionarySource(ResourceDictionaryConstants.SOURCE_INPUT);
- }
- log.info("auto map resourceAssignment : {}", resourceAssignment);
- }
- }
- }
-
- public static <T> Optional<T> resolve(Supplier<T> resolver) {
- try {
- T result = resolver.get();
- return Optional.ofNullable(result);
- } catch (NullPointerException e) {
- return Optional.empty();
- }
- }
-
- private static String findFirstSource(Map<String, ResourceSource> dictionarySource) {
- String source = null;
- if (MapUtils.isNotEmpty(dictionarySource)) {
- source = dictionarySource.keySet().stream().findFirst().get();
- }
- return source;
- }
-
- /**
- * Overriding ResourceAssignment Properties with properties defined in Dictionary
- */
- private static void setProperty(ResourceAssignment resourceAssignment, DictionaryDefinition dictionaryDefinition) {
- if (StringUtils.isNotBlank(dictionaryDefinition.getDataType())) {
- PropertyDefinition property = resourceAssignment.getProperty();
- if (property == null) {
- property = new PropertyDefinition();
- }
- property.setDefaultValue(dictionaryDefinition.getDefaultValue());
- property.setType(dictionaryDefinition.getDataType());
- if (StringUtils.isNotBlank(dictionaryDefinition.getEntrySchema())) {
- EntrySchema entrySchema = new EntrySchema();
- entrySchema.setType(dictionaryDefinition.getEntrySchema());
- property.setEntrySchema(entrySchema);
- }
- resourceAssignment.setProperty(property);
- }
- }
-
-}
diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt index c2c8094b9..525ed9a42 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt @@ -44,7 +44,7 @@ open class ResourceDefinition{ lateinit var resourcePath: String @JsonProperty(value = "sources", required = true) - var sources: MutableMap<String, NodeTemplate>? = null + lateinit var sources: MutableMap<String, NodeTemplate> @JsonProperty("decryption-rules") var decryptionRules: MutableList<DecryptionRule>? = null diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt new file mode 100644 index 000000000..e08c09c8e --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt @@ -0,0 +1,62 @@ +/* + * Copyright © 2018 IBM. + * + * 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.ccsdk.apps.controllerblueprints.resource.dict.utils + +import org.apache.commons.collections.MapUtils +import org.apache.commons.lang3.StringUtils +import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants +import org.slf4j.LoggerFactory + + +object ResourceDictionaryUtils { + private val log = LoggerFactory.getLogger(ResourceDictionaryUtils::class.java) + + @JvmStatic + fun populateSourceMapping(resourceAssignment: ResourceAssignment, + resourceDefinition: ResourceDefinition) { + + if (StringUtils.isBlank(resourceAssignment.dictionarySource)) { + + if (MapUtils.isNotEmpty(resourceDefinition.sources)) { + val source = findFirstSource(resourceDefinition.sources) + + // Populate and Assign First Source + if (StringUtils.isNotBlank(source)) { + // Set Dictionary Source + resourceAssignment.dictionarySource = source + } else { + resourceAssignment.dictionarySource = ResourceDictionaryConstants.SOURCE_INPUT + } + log.info("auto map resourceAssignment : {}", resourceAssignment) + }else { + resourceAssignment.dictionarySource = ResourceDictionaryConstants.SOURCE_INPUT + } + } + } + + @JvmStatic + fun findFirstSource(sources: Map<String, NodeTemplate>): String? { + var source: String? = null + if (MapUtils.isNotEmpty(sources)) { + source = sources.keys.stream().findFirst().get() + } + return source + } +}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDictionaryUtilsTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDictionaryUtilsTest.java deleted file mode 100644 index b6ac103ee..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDictionaryUtilsTest.java +++ /dev/null @@ -1,178 +0,0 @@ -/*
- * Copyright © 2017-2018 AT&T Intellectual Property.
- * Modifications Copyright © 2018 IBM.
- *
- * 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.ccsdk.apps.controllerblueprints.resource.dict.util;
-
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants;
-import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition;
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment;
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants;
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.*;
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-
-public class ResourceDictionaryUtilsTest {
- private static final Logger log = LoggerFactory.getLogger(ResourceDictionaryUtilsTest.class);
-
- @Test
- public void validateSingleInputSource() {
- try {
- ResourceAssignment resourceAssignment = new ResourceAssignment();
- resourceAssignment.setName("test-input-key");
- PropertyDefinition propertyDefinition = new PropertyDefinition();
- propertyDefinition.setType("string");
- resourceAssignment.setProperty(propertyDefinition);
- DictionaryDefinition dictionaryDefinition = new DictionaryDefinition();
- dictionaryDefinition.setDataType(BluePrintConstants.DATA_TYPE_STRING);
-
- Map<String, ResourceSource> source = new HashMap<>();
- SourceInput sourceInput = new SourceInput();
- source.put(ResourceDictionaryConstants.SOURCE_INPUT, sourceInput);
- dictionaryDefinition.setSource(source);
-
- ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition);
- Assert.assertNotNull("Resource assignment input source is missing ",
- resourceAssignment.getDictionarySource());
- Assert.assertNotNull("Resource assignment input source property is missing ",
- resourceAssignment.getProperty());
- Assert.assertNotNull("Resource assignment input source property type is missing ",
- resourceAssignment.getProperty().getType());
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @Test
- public void validateSingleDbSource() {
- try {
- ResourceAssignment resourceAssignment = new ResourceAssignment();
- resourceAssignment.setName("test-db-key");
- PropertyDefinition propertyDefinition = new PropertyDefinition();
- propertyDefinition.setType("string");
- resourceAssignment.setProperty(propertyDefinition);
-
- DictionaryDefinition dictionaryDefinition = new DictionaryDefinition();
- dictionaryDefinition.setDataType(BluePrintConstants.DATA_TYPE_STRING);
-
- Map<String, ResourceSource> source = new HashMap<>();
- SourceDb sourceDb = new SourceDb();
- sourceDb.setBase("sdnc_connection");
- source.put(ResourceDictionaryConstants.SOURCE_DB, sourceDb);
- dictionaryDefinition.setSource(source);
-
- Map<String, DictionaryDependency> dependency = new HashMap<>();
- DictionaryDependency dependencyDb = new DictionaryDependency();
- dependencyDb.setNames(Arrays.asList("vnf-id", "vnf-name"));
- dependency.put(ResourceDictionaryConstants.SOURCE_DB, dependencyDb);
- dictionaryDefinition.setDependency(dependency);
-
- DecryptionRule decryptionRule = new DecryptionRule();
- decryptionRule.setDecryptType("sample Type");
- decryptionRule.setPath("$.");
- decryptionRule.setRule("Sample Rule");
- decryptionRule.setSources(Arrays.asList("vnf-id"));
- dictionaryDefinition.setDecryptionRules(Arrays.asList(decryptionRule));
-
- ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition);
- Assert.assertNotNull("Resource assignment db source source is missing ",
- resourceAssignment.getDictionarySource());
- Assert.assertNotNull("Resource assignment db source source property is missing ",
- resourceAssignment.getProperty());
- Assert.assertNotNull("Resource assignment db source source property type is missing ",
- resourceAssignment.getProperty().getType());
-
- Assert.assertNotNull("Resource assignment db dependecy is missing ", resourceAssignment.getDependencies());
- Assert.assertEquals("Resource assignment db dependecy count mismatch ", 2,
- resourceAssignment.getDependencies().size());
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @Test
- public void testSourceDefault() {
- ResourceAssignment resourceAssignment = new ResourceAssignment();
- resourceAssignment.setName("test-input-key");
- PropertyDefinition propertyDefinition = new PropertyDefinition();
- propertyDefinition.setType("string");
- resourceAssignment.setProperty(propertyDefinition);
-
- DictionaryDefinition dictionaryDefinition = new DictionaryDefinition();
- dictionaryDefinition.setDataType(BluePrintConstants.DATA_TYPE_STRING);
-
- Map<String, ResourceSource> source = new HashMap<>();
- SourceDefault sourceDefault = new SourceDefault();
- source.put(ResourceDictionaryConstants.SOURCE_DEFAULT, sourceDefault);
- dictionaryDefinition.setSource(source);
-
- Map<String, DictionaryDependency> dependency = new HashMap<>();
- DictionaryDependency dependencyDefault = new DictionaryDependency();
- dependencyDefault.setNames(Arrays.asList(new String[]{"vnf-id", "vnf-name"}));
- dependency.put(ResourceDictionaryConstants.SOURCE_DEFAULT, dependencyDefault);
- dictionaryDefinition.setDependency(dependency);
-
- ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition);
-
- Assert.assertNotNull("Resource assignment default source is missing ",
- resourceAssignment.getDictionarySource());
- Assert.assertNotNull("Resource assignment default source property is missing ",
- resourceAssignment.getProperty());
- Assert.assertNotNull("Resource assignment default source property type is missing ",
- resourceAssignment.getProperty().getType());
- }
-
- @Test
- public void testSourceMdsal() {
- ResourceAssignment resourceAssignment = new ResourceAssignment();
- resourceAssignment.setName("test-input-key");
- PropertyDefinition propertyDefinition = new PropertyDefinition();
- propertyDefinition.setType("string");
- resourceAssignment.setProperty(propertyDefinition);
-
- DictionaryDefinition dictionaryDefinition = new DictionaryDefinition();
- dictionaryDefinition.setDataType(BluePrintConstants.DATA_TYPE_STRING);
-
- Map<String, ResourceSource> source = new HashMap<>();
- SourceMdsal sourceMdsal = new SourceMdsal();
- source.put(ResourceDictionaryConstants.SOURCE_MDSAL,sourceMdsal);
- dictionaryDefinition.setSource(source);
-
- Map<String, DictionaryDependency> dependency = new HashMap<>();
- DictionaryDependency dependencyMdsal = new DictionaryDependency();
- dependencyMdsal.setNames(Arrays.asList(new String[]{"vnf-id", "vnf-name"}));
- dependency.put(ResourceDictionaryConstants.SOURCE_MDSAL, dependencyMdsal);
- dictionaryDefinition.setDependency(dependency);
-
- ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition);
-
- Assert.assertNotNull("Resource assignment mdsal source is missing ", resourceAssignment.getDictionarySource());
- Assert.assertNotNull("Resource assignment mdsal source property is missing ", resourceAssignment.getProperty());
- Assert.assertNotNull("Resource assignment mdsal source property type is missing ",
- resourceAssignment.getProperty().getType());
- }
-
-}
diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java new file mode 100644 index 000000000..2a207e09b --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java @@ -0,0 +1,79 @@ +/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
+ *
+ * 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.ccsdk.apps.controllerblueprints.resource.dict.utils;
+
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate;
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment;
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition;
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class ResourceDictionaryUtilsTest {
+ private static final Logger log = LoggerFactory.getLogger(ResourceDictionaryUtilsTest.class);
+
+ @Test
+ public void testPopulateSourceMapping() {
+
+ ResourceAssignment resourceAssignment = new ResourceAssignment();
+ ResourceDefinition resourceDefinition = new ResourceDefinition();
+ Map<String, NodeTemplate> sources = new HashMap<>();
+ resourceDefinition.setSources(sources);
+ // To Check Empty Source
+ ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition);
+ Assert.assertEquals("Expected Empty source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, resourceAssignment.getDictionarySource());
+
+ // To Check First Source
+ resourceAssignment.setDictionarySource(null);
+ sources.put(ResourceDictionaryConstants.SOURCE_DEFAULT, new NodeTemplate());
+ ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition);
+ Assert.assertEquals("Expected First source Default, but.", ResourceDictionaryConstants.SOURCE_DEFAULT, resourceAssignment.getDictionarySource());
+
+ // To Check Assigned Source
+ resourceAssignment.setDictionarySource(ResourceDictionaryConstants.SOURCE_DB);
+ ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition);
+ Assert.assertEquals("Expected Assigned source DB, but.", ResourceDictionaryConstants.SOURCE_DB, resourceAssignment.getDictionarySource());
+
+ }
+
+ @Test
+ public void testFindFirstSource() {
+ //To check if Empty Source
+ Map<String, NodeTemplate> sources = new HashMap<>();
+ String firstSource = ResourceDictionaryUtils.findFirstSource(sources);
+ Assert.assertNull("Source populated, which is not expected.", firstSource);
+
+ // TO check the first Source
+ sources.put(ResourceDictionaryConstants.SOURCE_INPUT, new NodeTemplate());
+ String inputFirstSource = ResourceDictionaryUtils.findFirstSource(sources);
+ Assert.assertEquals("Expected source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, inputFirstSource);
+
+ // TO check the multiple Source
+ sources.put(ResourceDictionaryConstants.SOURCE_DB, new NodeTemplate());
+ String multipleFirstSource = ResourceDictionaryUtils.findFirstSource(sources);
+ Assert.assertEquals("Expected source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, multipleFirstSource);
+
+ }
+
+}
|