2 * Copyright © 2017-2018 AT&T Intellectual Property.
3 * Modifications Copyright © 2018 IBM.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org.onap.ccsdk.cds.controllerblueprints.resource.dict.utils;
21 import com.fasterxml.jackson.databind.JsonNode;
22 import org.junit.Assert;
23 import org.junit.Test;
24 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants;
25 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate;
26 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils;
27 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment;
28 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition;
29 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDictionaryConstants;
31 import java.util.HashMap;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
37 * ResourceDictionaryUtilsTest.
39 * @author Brinda Santh
41 public class ResourceDictionaryUtilsTest {
42 private static final Logger log = LoggerFactory.getLogger(ResourceDictionaryUtilsTest.class);
45 public void testPopulateSourceMapping() {
47 ResourceAssignment resourceAssignment = new ResourceAssignment();
48 resourceAssignment.setName("sample-assignment");
49 ResourceDefinition resourceDefinition = new ResourceDefinition();
50 Map<String, NodeTemplate> sources = new HashMap<>();
51 resourceDefinition.setSources(sources);
52 // To Check Empty Source
53 ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition);
54 Assert.assertEquals("Expected Empty source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, resourceAssignment.getDictionarySource());
56 // To Check First Source
57 resourceAssignment.setDictionarySource(null);
58 sources.put(ResourceDictionaryConstants.SOURCE_DEFAULT, new NodeTemplate());
59 ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition);
60 Assert.assertEquals("Expected First source Default, but.", ResourceDictionaryConstants.SOURCE_DEFAULT, resourceAssignment.getDictionarySource());
62 // To Check Assigned Source
63 resourceAssignment.setDictionarySource(ResourceDictionaryConstants.PROCESSOR_DB);
64 ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition);
65 Assert.assertEquals("Expected Assigned source DB, but.", ResourceDictionaryConstants.PROCESSOR_DB, resourceAssignment.getDictionarySource());
70 public void testFindFirstSource() {
71 //To check if Empty Source
72 Map<String, NodeTemplate> sources = new HashMap<>();
73 String firstSource = ResourceDictionaryUtils.findFirstSource(sources);
74 Assert.assertNull("Source populated, which is not expected.", firstSource);
76 // TO check the first Source
77 sources.put(ResourceDictionaryConstants.SOURCE_INPUT, new NodeTemplate());
78 String inputFirstSource = ResourceDictionaryUtils.findFirstSource(sources);
79 Assert.assertEquals("Expected source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, inputFirstSource);
81 // TO check the multiple Source
82 sources.put(ResourceDictionaryConstants.PROCESSOR_DB, new NodeTemplate());
83 String multipleFirstSource = ResourceDictionaryUtils.findFirstSource(sources);
84 Assert.assertEquals("Expected source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, multipleFirstSource);
89 public void testAssignInputs() {
90 JsonNode data = JacksonUtils.Companion.jsonNodeFromClassPathFile("data/resource-assignment-input.json");
91 Map<String, Object> context = new HashMap<>();
92 ResourceDictionaryUtils.assignInputs(data, context);
93 String path = BluePrintConstants.PATH_INPUTS.concat(BluePrintConstants.PATH_DIVIDER).concat("mapValue");
94 log.info("populated context {}", context);
95 Assert.assertTrue(String.format("failed to get variable : %s",path),context.containsKey(path));