aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/aai/babel/csar/vnfcatalog/SdcToscaHelper.java
blob: 6fbb1f109e5598f74e7de1318e638e6685e6b309 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/**
 * ============LICENSE_START=======================================================
 * org.onap.aai
 * ================================================================================
 * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
 * Copyright © 2017-2019 European Software Marketing Ltd.
 * ================================================================================
 * 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.
 * ============LICENSE_END=========================================================
 */

package org.onap.aai.babel.csar.vnfcatalog;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import org.onap.sdc.toscaparser.api.NodeTemplate;
import org.onap.sdc.toscaparser.api.SubstitutionMappings;

public class SdcToscaHelper {

    private ArrayList<NodeTemplate> smnodetemplates = new ArrayList<>();

    /**
     * Create the test SubstitutionMappings.
     * 
     * @return the new Substitution Mappings
     */
    public SubstitutionMappings buildMappings() {
        LinkedHashMap<String, Object> defProps = getImagesDefProps();

        LinkedHashMap<String, Object> defs = buildNodeTemplateTypeInfo(defProps);
        LinkedHashMap<String, Object> caps = new LinkedHashMap<>();
        LinkedHashMap<String, Object> reqs = new LinkedHashMap<>();

        String type = "tosca.nodes.custom";

        LinkedHashMap<String, Object> smsubMappingDef = new LinkedHashMap<>();
        smsubMappingDef.put("node_type", type);
        smsubMappingDef.put("capabilities", caps);
        smsubMappingDef.put("requirements", reqs);

        LinkedHashMap<String, Object> smcustomDefs = buildCustomTypeDefinitions(type, defs);

        return new SubstitutionMappings(smsubMappingDef, smnodetemplates, null, null, null, null, smcustomDefs);
    }

    private LinkedHashMap<String, Object> getImagesDefProps() {
        LinkedHashMap<String, Object> imagesDef = new LinkedHashMap<>();
        imagesDef.put("type", "map");
        imagesDef.put("required", false);
        imagesDef.put("entry_schema", "{type=org.openecomp.datatypes.ImageInfo}");

        LinkedHashMap<String, Object> defProps = new LinkedHashMap<>();
        defProps.put("images", imagesDef);
        return defProps;
    }

    private LinkedHashMap<String, Object> buildCustomTypeDefinitions(String type,
            LinkedHashMap<String, Object> typeInfo) {
        LinkedHashMap<String, Object> customDefs = new LinkedHashMap<>();
        customDefs.put(type, typeInfo);
        return customDefs;
    }

    private LinkedHashMap<String, Object> buildNodeTemplateTypeInfo(LinkedHashMap<String, Object> props) {
        LinkedHashMap<String, Object> typeInfo = new LinkedHashMap<>();
        typeInfo.put("derived_from", "tosca.nodes.Root");
        typeInfo.put("properties", props);
        return typeInfo;
    }

    /**
     * Create a new NodeTemplate and add it to the list (for populating the Substitution Mappings).
     */
    public void addNodeTemplate() {
        String name = "node name";
        String type = "tosca.nodes.custom";

        LinkedHashMap<String, Object> nodeTemplate = new LinkedHashMap<>();
        nodeTemplate.put("type", type);
        nodeTemplate.put("properties", null);

        LinkedHashMap<String, Object> ntnodeTemplates = buildCustomTypeDefinitions(name, nodeTemplate);
        ntnodeTemplates.put("derived_from", null);
        ntnodeTemplates.put("properties", getImagesDefProps());

        LinkedHashMap<String, Object> typeInfo = buildNodeTemplateTypeInfo(getImagesDefProps());
        LinkedHashMap<String, Object> customDefs = buildCustomTypeDefinitions(type, typeInfo);
        smnodetemplates.add(new NodeTemplate(name, ntnodeTemplates, customDefs, null, null));
    }

    /**
     * Simulate the creation of a NodeTemplate by the SDC TOSCA parser. Populate the properties of the NodeTemplate with
     * the supplied images.
     * 
     * @param images
     *            the value of the images property
     */
    public void addNodeTemplate(Object images) {
        LinkedHashMap<String, Object> properties = new LinkedHashMap<>();
        properties.put("images", images);

        String type = "tosca.nodes.custom";
        LinkedHashMap<String, Object> nodeTemplate = new LinkedHashMap<>();
        nodeTemplate.put("type", type);
        nodeTemplate.put("properties", properties);

        String name = "node name";
        LinkedHashMap<String, Object> ntnodeTemplates = buildCustomTypeDefinitions(name, nodeTemplate);
        ntnodeTemplates.put("derived_from", null);
        ntnodeTemplates.put("properties", getImagesDefProps());

        LinkedHashMap<String, Object> typeInfo = buildNodeTemplateTypeInfo(getImagesDefProps());
        LinkedHashMap<String, Object> customDefs = buildCustomTypeDefinitions(type, typeInfo);

        smnodetemplates.add(new NodeTemplate(name, ntnodeTemplates, customDefs, null, null));
    }
}