Revert "Renaming Files having BluePrint to have Blueprint"
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / blueprints / resource-dict / src / test / java / org / onap / ccsdk / cds / controllerblueprints / resource / dict / utils / ResourceDictionaryUtilsTest.java
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  * Modifications Copyright © 2018 IBM.
4  *
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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17
18 package org.onap.ccsdk.cds.controllerblueprints.resource.dict.utils;
19
20 import com.fasterxml.jackson.databind.JsonNode;
21 import org.junit.Assert;
22 import org.junit.Test;
23 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants;
24 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate;
25 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils;
26 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment;
27 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition;
28 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDictionaryConstants;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 import java.util.HashMap;
33 import java.util.Map;
34
35 /**
36  * ResourceDictionaryUtilsTest.
37  *
38  * @author Brinda Santh
39  */
40 public class ResourceDictionaryUtilsTest {
41     private static final Logger log = LoggerFactory.getLogger(ResourceDictionaryUtilsTest.class);
42
43     @Test
44     public void testPopulateSourceMapping() {
45
46         ResourceAssignment resourceAssignment = new ResourceAssignment();
47         resourceAssignment.setName("sample-assignment");
48         ResourceDefinition resourceDefinition = new ResourceDefinition();
49         Map<String, NodeTemplate> sources = new HashMap<>();
50         resourceDefinition.setSources(sources);
51         // To Check Empty Source
52         ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition);
53         Assert.assertEquals("Expected Empty source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT,
54                 resourceAssignment.getDictionarySource());
55
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,
61                 resourceAssignment.getDictionarySource());
62
63         // To Check Assigned Source
64         resourceAssignment.setDictionarySource(ResourceDictionaryConstants.PROCESSOR_DB);
65         ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition);
66         Assert.assertEquals("Expected Assigned source DB, but.", ResourceDictionaryConstants.PROCESSOR_DB,
67                 resourceAssignment.getDictionarySource());
68
69     }
70
71     @Test
72     public void testFindFirstSource() {
73         // To check if Empty Source
74         Map<String, NodeTemplate> sources = new HashMap<>();
75         String firstSource = ResourceDictionaryUtils.findFirstSource(sources);
76         Assert.assertNull("Source populated, which is not expected.", firstSource);
77
78         // TO check the first Source
79         sources.put(ResourceDictionaryConstants.SOURCE_INPUT, new NodeTemplate());
80         String inputFirstSource = ResourceDictionaryUtils.findFirstSource(sources);
81         Assert.assertEquals("Expected source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, inputFirstSource);
82
83         // TO check the multiple Source
84         sources.put(ResourceDictionaryConstants.PROCESSOR_DB, new NodeTemplate());
85         String multipleFirstSource = ResourceDictionaryUtils.findFirstSource(sources);
86         Assert.assertEquals("Expected source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT,
87                 multipleFirstSource);
88
89     }
90
91     @Test
92     public void testAssignInputs() {
93         JsonNode data = JacksonUtils.Companion.jsonNodeFromClassPathFile("data/resource-assignment-input.json");
94         Map<String, Object> context = new HashMap<>();
95         ResourceDictionaryUtils.assignInputs(data, context);
96         String path = BluePrintConstants.PATH_INPUTS.concat(BluePrintConstants.PATH_DIVIDER).concat("mapValue");
97         log.info("populated context {}", context);
98         Assert.assertTrue(String.format("failed to get variable : %s", path), context.containsKey(path));
99
100     }
101
102 }