Fix checkstyle issues including javadoc
[aai/babel.git] / src / test / java / org / onap / aai / babel / csar / vnfcatalog / SdcToscaHelper.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2019 European Software Marketing Ltd.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.aai.babel.csar.vnfcatalog;
23
24 import java.util.ArrayList;
25 import java.util.LinkedHashMap;
26 import org.onap.sdc.toscaparser.api.NodeTemplate;
27 import org.onap.sdc.toscaparser.api.SubstitutionMappings;
28
29 public class SdcToscaHelper {
30
31     private ArrayList<NodeTemplate> smnodetemplates = new ArrayList<>();
32
33     /**
34      * Create the test SubstitutionMappings.
35      * 
36      * @return the new Substitution Mappings
37      */
38     public SubstitutionMappings buildMappings() {
39         LinkedHashMap<String, Object> defProps = getImagesDefProps();
40
41         LinkedHashMap<String, Object> defs = buildNodeTemplateTypeInfo(defProps);
42         LinkedHashMap<String, Object> caps = new LinkedHashMap<>();
43         LinkedHashMap<String, Object> reqs = new LinkedHashMap<>();
44
45         String type = "tosca.nodes.custom";
46
47         LinkedHashMap<String, Object> smsubMappingDef = new LinkedHashMap<>();
48         smsubMappingDef.put("node_type", type);
49         smsubMappingDef.put("capabilities", caps);
50         smsubMappingDef.put("requirements", reqs);
51
52         LinkedHashMap<String, Object> smcustomDefs = buildCustomTypeDefinitions(type, defs);
53
54         return new SubstitutionMappings(smsubMappingDef, smnodetemplates, null, null, null, null, smcustomDefs);
55     }
56
57     private LinkedHashMap<String, Object> getImagesDefProps() {
58         LinkedHashMap<String, Object> imagesDef = new LinkedHashMap<>();
59         imagesDef.put("type", "map");
60         imagesDef.put("required", false);
61         imagesDef.put("entry_schema", "{type=org.openecomp.datatypes.ImageInfo}");
62
63         LinkedHashMap<String, Object> defProps = new LinkedHashMap<>();
64         defProps.put("images", imagesDef);
65         return defProps;
66     }
67
68     private LinkedHashMap<String, Object> buildCustomTypeDefinitions(String type,
69             LinkedHashMap<String, Object> typeInfo) {
70         LinkedHashMap<String, Object> customDefs = new LinkedHashMap<>();
71         customDefs.put(type, typeInfo);
72         return customDefs;
73     }
74
75     private LinkedHashMap<String, Object> buildNodeTemplateTypeInfo(LinkedHashMap<String, Object> props) {
76         LinkedHashMap<String, Object> typeInfo = new LinkedHashMap<>();
77         typeInfo.put("derived_from", "tosca.nodes.Root");
78         typeInfo.put("properties", props);
79         return typeInfo;
80     }
81
82     /**
83      * Create a new NodeTemplate and add it to the list (for populating the Substitution Mappings).
84      */
85     public void addNodeTemplate() {
86         String name = "node name";
87         String type = "tosca.nodes.custom";
88
89         LinkedHashMap<String, Object> nodeTemplate = new LinkedHashMap<>();
90         nodeTemplate.put("type", type);
91         nodeTemplate.put("properties", null);
92
93         LinkedHashMap<String, Object> ntnodeTemplates = buildCustomTypeDefinitions(name, nodeTemplate);
94         ntnodeTemplates.put("derived_from", null);
95         ntnodeTemplates.put("properties", getImagesDefProps());
96
97         LinkedHashMap<String, Object> typeInfo = buildNodeTemplateTypeInfo(getImagesDefProps());
98         LinkedHashMap<String, Object> customDefs = buildCustomTypeDefinitions(type, typeInfo);
99         smnodetemplates.add(new NodeTemplate(name, ntnodeTemplates, customDefs, null, null));
100     }
101
102     /**
103      * Simulate the creation of a NodeTemplate by the SDC TOSCA parser. Populate the properties of the NodeTemplate with
104      * the supplied images.
105      * 
106      * @param images
107      *            the value of the images property
108      */
109     public void addNodeTemplate(Object images) {
110         LinkedHashMap<String, Object> properties = new LinkedHashMap<>();
111         properties.put("images", images);
112
113         String type = "tosca.nodes.custom";
114         LinkedHashMap<String, Object> nodeTemplate = new LinkedHashMap<>();
115         nodeTemplate.put("type", type);
116         nodeTemplate.put("properties", properties);
117
118         String name = "node name";
119         LinkedHashMap<String, Object> ntnodeTemplates = buildCustomTypeDefinitions(name, nodeTemplate);
120         ntnodeTemplates.put("derived_from", null);
121         ntnodeTemplates.put("properties", getImagesDefProps());
122
123         LinkedHashMap<String, Object> typeInfo = buildNodeTemplateTypeInfo(getImagesDefProps());
124         LinkedHashMap<String, Object> customDefs = buildCustomTypeDefinitions(type, typeInfo);
125
126         smnodetemplates.add(new NodeTemplate(name, ntnodeTemplates, customDefs, null, null));
127     }
128 }
129