Additional tests for VNF image extraction
[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-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 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      * @return
35      */
36     public SubstitutionMappings buildMappings() {
37         LinkedHashMap<String, Object> defProps = getImagesDefProps();
38
39         LinkedHashMap<String, Object> defs = buildNodeTemplateTypeInfo(defProps);
40         LinkedHashMap<String, Object> caps = new LinkedHashMap<>();
41         LinkedHashMap<String, Object> reqs = new LinkedHashMap<>();
42
43         String type = "tosca.nodes.custom";
44
45         LinkedHashMap<String, Object> smsubMappingDef = new LinkedHashMap<>();
46         smsubMappingDef.put("node_type", type);
47         smsubMappingDef.put("capabilities", caps);
48         smsubMappingDef.put("requirements", reqs);
49
50         LinkedHashMap<String, Object> smcustomDefs = buildCustomTypeDefinitions(type, defs);
51
52         return new SubstitutionMappings(smsubMappingDef, smnodetemplates, null, null, null, null, smcustomDefs);
53     }
54
55     private LinkedHashMap<String, Object> getImagesDefProps() {
56         LinkedHashMap<String, Object> imagesDef = new LinkedHashMap<>();
57         imagesDef.put("type", "map");
58         imagesDef.put("required", false);
59         imagesDef.put("entry_schema", "{type=org.openecomp.datatypes.ImageInfo}");
60
61         LinkedHashMap<String, Object> defProps = new LinkedHashMap<>();
62         defProps.put("images", imagesDef);
63         return defProps;
64     }
65
66     private LinkedHashMap<String, Object> buildCustomTypeDefinitions(String type,
67             LinkedHashMap<String, Object> typeInfo) {
68         LinkedHashMap<String, Object> customDefs = new LinkedHashMap<>();
69         customDefs.put(type, typeInfo);
70         return customDefs;
71     }
72
73     private LinkedHashMap<String, Object> buildNodeTemplateTypeInfo(LinkedHashMap<String, Object> props) {
74         LinkedHashMap<String, Object> typeInfo = new LinkedHashMap<>();
75         typeInfo.put("derived_from", "tosca.nodes.Root");
76         typeInfo.put("properties", props);
77         return typeInfo;
78     }
79
80     /**
81      *
82      */
83     public void addNodeTemplate() {
84         String name = "node name";
85         String type = "tosca.nodes.custom";
86
87         LinkedHashMap<String, Object> nodeTemplate = new LinkedHashMap<>();
88         nodeTemplate.put("type", type);
89         nodeTemplate.put("properties", null);
90
91         LinkedHashMap<String, Object> ntnodeTemplates = buildCustomTypeDefinitions(name, nodeTemplate);
92         ntnodeTemplates.put("derived_from", null);
93         ntnodeTemplates.put("properties", getImagesDefProps());
94
95         LinkedHashMap<String, Object> typeInfo = buildNodeTemplateTypeInfo(getImagesDefProps());
96         LinkedHashMap<String, Object> customDefs = buildCustomTypeDefinitions(type, typeInfo);
97         smnodetemplates.add(new NodeTemplate(name, ntnodeTemplates, customDefs, null, null));
98     }
99
100     /**
101      * @param images
102      */
103     public void addNodeTemplate(Object images) {
104         LinkedHashMap<String, Object> properties = new LinkedHashMap<>();
105         properties.put("images", images);
106
107         String type = "tosca.nodes.custom";
108         LinkedHashMap<String, Object> nodeTemplate = new LinkedHashMap<>();
109         nodeTemplate.put("type", type);
110         nodeTemplate.put("properties", properties);
111
112         String name = "node name";
113         LinkedHashMap<String, Object> ntnodeTemplates = buildCustomTypeDefinitions(name, nodeTemplate);
114         ntnodeTemplates.put("derived_from", null);
115         ntnodeTemplates.put("properties", getImagesDefProps());
116
117         LinkedHashMap<String, Object> typeInfo = buildNodeTemplateTypeInfo(getImagesDefProps());
118         LinkedHashMap<String, Object> customDefs = buildCustomTypeDefinitions(type, typeInfo);
119
120         smnodetemplates.add(new NodeTemplate(name, ntnodeTemplates, customDefs, null, null));
121     }
122 }
123