aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/ToscaModelTest.java
blob: 4ad4d2b53ed1d16e7897bdad021d59786eb8409f (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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
/*
 * Copyright © 2016-2018 European Support Limited
 *
 * 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.
 */

package org.openecomp.sdc.tosca.datatypes;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.junit.Assert;
import org.junit.Test;
import org.onap.sdc.tosca.datatypes.model.ArtifactType;
import org.onap.sdc.tosca.datatypes.model.AttributeDefinition;
import org.onap.sdc.tosca.datatypes.model.CapabilityAssignment;
import org.onap.sdc.tosca.datatypes.model.CapabilityDefinition;
import org.onap.sdc.tosca.datatypes.model.CapabilityFilter;
import org.onap.sdc.tosca.datatypes.model.Constraint;
import org.onap.sdc.tosca.datatypes.model.Directive;
import org.onap.sdc.tosca.datatypes.model.Implementation;
import org.onap.sdc.tosca.datatypes.model.Import;
import org.onap.sdc.tosca.datatypes.model.InterfaceDefinitionTemplate;
import org.onap.sdc.tosca.datatypes.model.InterfaceDefinitionType;
import org.onap.sdc.tosca.datatypes.model.InterfaceType;
import org.onap.sdc.tosca.datatypes.model.NodeFilter;
import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
import org.onap.sdc.tosca.datatypes.model.NodeType;
import org.onap.sdc.tosca.datatypes.model.OperationDefinition;
import org.onap.sdc.tosca.datatypes.model.OperationDefinitionTemplate;
import org.onap.sdc.tosca.datatypes.model.OperationDefinitionType;
import org.onap.sdc.tosca.datatypes.model.ParameterDefinition;
import org.onap.sdc.tosca.datatypes.model.PropertyDefinition;
import org.onap.sdc.tosca.datatypes.model.PropertyType;
import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
import org.onap.sdc.tosca.datatypes.model.SubstitutionMapping;
import org.onap.sdc.tosca.datatypes.model.TopologyTemplate;
import org.onap.sdc.tosca.datatypes.model.extension.RequirementAssignmentExt;
import org.onap.sdc.tosca.datatypes.model.heatextend.ParameterDefinitionExt;
import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
import org.onap.sdc.tosca.services.YamlUtil;
import org.openecomp.sdc.tosca.services.DataModelUtil;
import org.openecomp.sdc.tosca.services.ToscaConstants;


public class ToscaModelTest {

    public static final String FIRST_NODE_TEMPLATE = "firstNodeTemplate";
    public static final String REQ1 = "req1";
    public static final String REQ2 = "req2";
    public static final String SERVICE_FILTER_TOSCA_ID = "{get_input=inParam1}";
    public static final String VMD_NAME = "vmdName";
    public static final String DIRECTOR = "director";
    private YamlUtil yamlUtil = new YamlUtil();
    private ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
    private static final String INTERFACE_ID = "inter_1";
    private static final String NODE_TEMPLATE_ID = "firstNodeTemplate";
    private static final String NODE_TYPE_ID = "compute_node_type";
    private static final String BASE_DIR = "/mock/model";
    private static final String ST = "/serviceTemplate.yaml";
    private static final String ST_WITH_INTERFACE = "/serviceTemplateWithInterface.yaml";
    private static final String ST_WITH_OPERATIONS = "/serviceTemplateWithInterfaceAndOperation.yaml";
    private static final String ST_WITH_INTERFACE_DEF = "/serviceTemplateWithNodeTemplateInterface.yaml";
    private static final String ST_WITH_NODE_INTERFACE_DEF = "/serviceTemplateWithNodeTypeInterface.yaml";
    private static final String INTERFACE_TYPE_VALUE = "tosca.interfaces.node.lifecycle.Standard";
    private static final String OPERATION_START = "start";
    private static final String OPERATION_DESC = "start operation";
    private static final String IMPLEMENTATION_NAME = "startWorkFlow.json";
    private static final String PRIMARY_IMPL = "myImpl.yaml";
    private static final String DEPENDENCY_NAME = "script1.sh";
    private static final String STRING_TYPE = "string";
    private static final String ST_WITH_SERVICE_FILTER = "/serviceTemplateWithServiceFilter.yaml";
    private static final String SUBSTITUTION_MAPPING = "/serviceTemplateWithSubstitutionMapping.yaml";
    private static final String SUBSTITUTION_MAPPING_WITH_FILTER = "/substitutionMappingWithFilter.yaml";

    @Test
    public void testServiceTemplateJavaToYaml() {
        ServiceTemplate serviceTemplate = new ServiceTemplate();
        Map<String, String> metadata = new HashMap<>();
        metadata.put("Template_author", "OPENECOMP");
        metadata.put(ToscaConstants.ST_METADATA_TEMPLATE_NAME, "Test");
        metadata.put("Template_version", "1.0.0");
        serviceTemplate.setMetadata(metadata);
        serviceTemplate.setTosca_definitions_version("tosca_simple_yaml_1_0_0");
        serviceTemplate.setDescription("testing desc tosca service template");

        Import fileImport1 = new Import();
        fileImport1.setFile("path1/path2/file1.yaml");
        Import fileImport2 = new Import();
        fileImport2.setFile("path1/path2/file2.yaml");
        List<Map<String, Import>> imports = new ArrayList<>();
        Map<String, Import> importsMap = new HashMap<>();
        importsMap.put("myfile1", fileImport1);
        imports.add(importsMap);
        importsMap = new HashMap<>();
        importsMap.put("myfile2", fileImport2);
        imports.add(importsMap);
        serviceTemplate.setImports(imports);

        OperationDefinition operationDefinition = new OperationDefinition();
        operationDefinition.setDescription("test operation");
        InterfaceType interfaceType = new InterfaceType();
        interfaceType.setDerived_from("derived_from");
        interfaceType.setDescription("desc");
        interfaceType.addOperation("test", operationDefinition);
        serviceTemplate.addInterfaceType("test_interface", interfaceType);

        ArtifactType artifact = new ArtifactType();
        artifact.setMime_type("application/java-archive");
        ArrayList<String> ext = new ArrayList<>();
        ext.add("yaml");
        ext.add("xml");
        artifact.setFile_ext(ext);
        Map<String, ArtifactType> artifactTypes = new HashMap<>();
        artifactTypes.put("one_artifact", artifact);
        serviceTemplate.setArtifact_types(artifactTypes);

        NodeType nodeType = new NodeType();
        nodeType.setDerived_from("tosca.nodes.Root");
        nodeType.setVersion("1.0.0");
        nodeType.setDescription("tosca compute test");

        PropertyDefinition propDef1 = new PropertyDefinition();
        propDef1.setType("integer");
        propDef1.setDescription("Number of CPUs requested for a software node instance");
        propDef1.setRequired(true);
        propDef1.set_default(1);

        Constraint graterOrEqual = new Constraint();
        graterOrEqual.setGreater_or_equal((float) 5.0);
        Constraint constraintEqual = new Constraint();
        constraintEqual.setEqual(5);
        Constraint greater_than = new Constraint();
        greater_than.setGreater_than(6.02);
        Constraint inRange = new Constraint();
        inRange.setIn_range(new Object[2]);
        inRange.getIn_range()[0] = 0;
        inRange.getIn_range()[1] = ToscaConstants.UNBOUNDED;

        List<Constraint> constraints = new ArrayList<>();
        constraints.add(graterOrEqual);
        constraints.add(constraintEqual);
        constraints.add(greater_than);
        constraints.add(inRange);
        propDef1.setConstraints(constraints);

        Map<String, PropertyDefinition> properties = new HashMap<>();
        properties.put("cpu_num", propDef1);
        nodeType.setProperties(properties);

        Map<String, AttributeDefinition> attributesDef = new HashMap<>();
        AttributeDefinition attDef = new AttributeDefinition();
        attDef.setType(PropertyType.STRING.getDisplayName());
        attDef.set_default("hi");
        attributesDef.put("attDef1", attDef);
        nodeType.setAttributes(attributesDef);

        Map<String, RequirementDefinition> reqsDef = new HashMap<>();
        RequirementDefinition reqDef = new RequirementDefinition();
        reqDef.setCapability("tosca.cap1");
        reqDef.getOccurrences()[0] = 5;
        reqsDef.put("re1", reqDef);
        List<Map<String, RequirementDefinition>> reqList = new ArrayList<>();
        reqList.add(reqsDef);
        nodeType.setRequirements(reqList);


        CapabilityDefinition capdef = new CapabilityDefinition();
        capdef.setType("tosca.cap");
        List<String> vvSource = new ArrayList<>();
        vvSource.add("node1");
        vvSource.add("node2");
        capdef.setValid_source_types(vvSource);
        Map<String, CapabilityDefinition> capsDef = new HashMap<>();
        capsDef.put("cap1", capdef);
        nodeType.setCapabilities(capsDef);

        Map<String, NodeType> nodeTypes = new HashMap<>();
        nodeTypes.put("compute_node_type", nodeType);
        serviceTemplate.setNode_types(nodeTypes);

        TopologyTemplate topologyTemplate = new TopologyTemplate();
        topologyTemplate.setDescription("topologi template descroption");
        ParameterDefinition paramDef = new ParameterDefinition();
        paramDef.setType(PropertyType.STRING.getDisplayName());
        paramDef.setDescription("desc");
        paramDef.set_default("my default val");
        paramDef.setRequired(false);
        paramDef.setEntry_schema(DataModelUtil.createEntrySchema("tosca.myType", null, null));
        List<Constraint> paramConstraint = new ArrayList<>();
        Constraint paramConst1 = new Constraint();
        paramConst1.setGreater_than(6);
        Constraint paramConst2 = new Constraint();
        paramConst2.setGreater_or_equal(9);
        paramConstraint.add(paramConst1);
        paramConstraint.add(paramConst2);
        paramDef.setConstraints(paramConstraint);
        Map<String, ParameterDefinition> inputs = new HashMap<>();
        inputs.put("inParam1", paramDef);
        topologyTemplate.setInputs(inputs);

        NodeTemplate nodeTemplate = new NodeTemplate();
        nodeTemplate.setType("nodeTypeRef");
        List<String> directives = new ArrayList<>();
        directives.add(Directive.SELECTABLE.getDisplayName());
        directives.add(Directive.SUBSTITUTABLE.getDisplayName());
        nodeTemplate.setDirectives(directives);
        Map<String, Object> nodeTemplateProperties = new HashMap<>();
        nodeTemplateProperties.put("prop1", "abcd");
        nodeTemplateProperties.put("prop2", "{ get_input: my_mysql_rootpw }");
        nodeTemplate.setProperties(nodeTemplateProperties);
        Map<String, Object> nodeTemplateAtts = new HashMap<>();
        nodeTemplateAtts.put("att1", "att1Val");
        nodeTemplateAtts.put("att2", "{ get_input: my_mysql_rootpw }");
        Map<String, NodeTemplate> nodeTemplates = new HashMap<>();
        nodeTemplate.setAttributes(nodeTemplateAtts);


        RequirementAssignment reqAssignment1 = new RequirementAssignment();
        reqAssignment1.setNode("nodeA");
        reqAssignment1.setCapability("capA");
        reqAssignment1.setRelationship("relationB");
        Object[] reqAssOccurrences = new Object[2];
        reqAssOccurrences[0] = 1;
        reqAssOccurrences[1] = 2;
        reqAssignment1.setOccurrences(reqAssOccurrences);
        List<Constraint> propConstraint1 = new ArrayList<>();
        Constraint propConst1 = new Constraint();
        propConst1.setGreater_or_equal(9);
        propConstraint1.add(propConst1);
        List<Constraint> propConstraint2 = new ArrayList<>();
        Constraint propConst2 = new Constraint();
        propConst2.setMin_length(1);
        propConstraint2.add(propConst2);
        Constraint propConst3 = new Constraint();
        propConst3.setMax_length(2);
        propConstraint2.add(propConst3);
        List<Map<String, List<Constraint>>> nodeFilterProp = new ArrayList<>();
        Map<String, List<Constraint>> propsMap = new HashMap<>();
        propsMap.put("propName1", propConstraint1);
        propsMap.put("propName2", propConstraint2);
        nodeFilterProp.add(propsMap);
        NodeFilter reqNodeFilter = new NodeFilter();
        reqNodeFilter.setProperties(nodeFilterProp);
        reqAssignment1.setNode_filter(reqNodeFilter);

        RequirementAssignment reqAssignment2 = new RequirementAssignment();
        reqAssignment2.setNode("nodeA");
        reqAssignment2.setCapability("capA");
        reqAssignment2.setRelationship("relationB");
        Map<String, RequirementAssignment> nodeTemplateRequirement1 = new HashMap<>();
        Map<String, RequirementAssignment> nodeTemplateRequirement2 = new HashMap<>();
        nodeTemplateRequirement1.put(REQ1, reqAssignment1);
        nodeTemplateRequirement2.put(REQ2, reqAssignment2);
        nodeTemplate.setRequirements(new ArrayList<>());
        nodeTemplate.getRequirements().add(nodeTemplateRequirement1);
        nodeTemplate.getRequirements().add(nodeTemplateRequirement2);

        CapabilityAssignment capAss = new CapabilityAssignment();
        Map<String, Object> capProps = new HashMap<>();
        capProps.put("num_cpus", "{ get_input: cpus }");
        capAss.setProperties(capProps);
        Map<String, Object> capAtts = new HashMap<>();
        capAtts.put("num_cpus", "66");
        capAss.setAttributes(capAtts);
        Map<String, CapabilityAssignment> nodeTemplateCapability = new HashMap<>();
        nodeTemplateCapability.put("cap1", capAss);
        nodeTemplate.setCapabilities(nodeTemplateCapability);

        List<Map<String, List<Constraint>>> nodeFilterProp2 = new ArrayList<>();
        Map<String, List<Constraint>> propsMap2 = new HashMap<>();
        Constraint c1 = new Constraint();
        c1.setEqual("1 MB");
        List<Constraint> consList = new ArrayList<>();
        consList.add(c1);
        propsMap2.put("test1", consList);
        nodeFilterProp2.add(propsMap2);
        NodeFilter nodeTemplateNodeFilter = new NodeFilter();
        nodeTemplateNodeFilter.setProperties(nodeFilterProp2);
        nodeTemplate.setNode_filter(nodeTemplateNodeFilter);
        nodeTemplates.put("firatNodeTemplate", nodeTemplate);
        topologyTemplate.setNode_templates(nodeTemplates);

        SubstitutionMapping subMap = new SubstitutionMapping();
        subMap.setNode_type("myNodeType.node");
        Map<String, List<String>> mapCapabilities = new HashMap<>();
        List<String> nodeCap = new ArrayList<>();
        nodeCap.add("database");
        nodeCap.add("database_endpoint");
        mapCapabilities.put("database_endpoint", nodeCap);
        subMap.setCapabilities(mapCapabilities);
        topologyTemplate.setSubstitution_mappings(subMap);
        serviceTemplate.setTopology_template(topologyTemplate);

        String yaml = new YamlUtil().objectToYaml(serviceTemplate);
        ServiceTemplate serviceTemplateFromYaml = new YamlUtil().yamlToObject(yaml, ServiceTemplate.class);
        Assert.assertNotNull(serviceTemplateFromYaml);
    }


  @Test
  public void testYamlToServiceTemplateObj() throws IOException {
    ServiceTemplate serviceTemplateFromYaml = getServiceTemplate(BASE_DIR + ST);
    Assert.assertNotNull(serviceTemplateFromYaml);
  }

    @Test
    public void testYamlWithInterfaceToServiceTemplateObj() throws IOException {
        ServiceTemplate serviceTemplateWithOperation = getServiceTemplate(BASE_DIR + ST_WITH_OPERATIONS);
        Assert.assertNotNull(serviceTemplateWithOperation);

        InterfaceType expectedInterfaceType = createInterfaceType();

        Map<String, InterfaceType> interfaceTypes = serviceTemplateWithOperation.getNormalizeInterfaceTypes();
        Assert.assertEquals(1, interfaceTypes.size());
        InterfaceType actualInterfaceType = interfaceTypes.get(INTERFACE_ID);
        Assert.assertEquals(expectedInterfaceType, actualInterfaceType);
    }

    @Test
    public void testAddOperationToInterface() throws IOException {
        YamlUtil yamlUtil = new YamlUtil();
        ServiceTemplate serviceTemplateWithInterface = getServiceTemplate(BASE_DIR + ST_WITH_INTERFACE);
        ServiceTemplate serviceTemplateWithOperation = getServiceTemplate(BASE_DIR + ST_WITH_OPERATIONS);

        OperationDefinition operationDefinition = createOperationDefinition();
        InterfaceType normalizeInterfaceType =
                serviceTemplateWithInterface.getNormalizeInterfaceTypes().get(INTERFACE_ID);
        normalizeInterfaceType.addOperation(OPERATION_START, operationDefinition);
        serviceTemplateWithInterface.addInterfaceType(INTERFACE_ID, normalizeInterfaceType);
        String expectedServiceTemplate = yamlUtil.objectToYaml(serviceTemplateWithOperation);
        String actualServiceTemplate = yamlUtil.objectToYaml(serviceTemplateWithInterface);
        Assert.assertEquals(expectedServiceTemplate, actualServiceTemplate);
    }

    @Test
    public void testInterfaceTypeToObjConversion() throws IOException {
        ServiceTemplate serviceTemplateWithInterface = getServiceTemplate(BASE_DIR + ST_WITH_INTERFACE);
        ServiceTemplate serviceTemplateWithOperation = getServiceTemplate(BASE_DIR + ST_WITH_OPERATIONS);
        InterfaceType interfaceType = createInterfaceType();

        Optional<Object> interfaceAsObj = interfaceType.convertInterfaceTypeToToscaObj();
        Assert.assertTrue(interfaceAsObj.isPresent());

        Map<String, Object> interfaceTypes = new HashMap<>();
        interfaceTypes.put(INTERFACE_ID, interfaceAsObj.get());
        serviceTemplateWithInterface.setInterface_types(interfaceTypes);

        String expectedServiceTemplate = yamlUtil.objectToYaml(serviceTemplateWithOperation);
        String actualServiceTemplate = yamlUtil.objectToYaml(serviceTemplateWithInterface);
        Assert.assertEquals(expectedServiceTemplate, actualServiceTemplate);
    }

    @Test
    public void testObjToInterfaceTypeConversion() throws IOException, ReflectiveOperationException {
        ServiceTemplate serviceTemplateWithOperation = getServiceTemplate(BASE_DIR + ST_WITH_OPERATIONS);
        Map<String, InterfaceType> interfaceTypes = serviceTemplateWithOperation.getNormalizeInterfaceTypes();
        InterfaceType actualInterfaceType = interfaceTypes.get(INTERFACE_ID);
        InterfaceType expectedInterfaceType = createInterfaceType();
        Assert.assertEquals(expectedInterfaceType, actualInterfaceType);
    }

    @Test
    public void testObjToInterfaceDefinitionTypeConversion() throws IOException, ReflectiveOperationException {
        ServiceTemplate serviceTemplateWithInterfaceDef = getServiceTemplate(BASE_DIR + ST_WITH_NODE_INTERFACE_DEF);
        NodeType nodeTypeWithInterface = DataModelUtil.getNodeType(serviceTemplateWithInterfaceDef, NODE_TYPE_ID);
        Map<String, Object> interfaces = nodeTypeWithInterface.getInterfaces();
        Object interfaceObj = interfaces.get(INTERFACE_ID);

        InterfaceDefinitionType actualInterfaceDefinition = new InterfaceDefinitionType(interfaceObj);
        InterfaceDefinitionType expectedInterfaceDefinitionType = createInterfaceDefinitionType();
        Assert.assertEquals(expectedInterfaceDefinitionType, actualInterfaceDefinition);
    }

    @Test
    public void testObjToInterfaceDefinitionTemplateConversion() throws IOException {
        ServiceTemplate serviceTemplateWithInterfaceDef = getServiceTemplate(BASE_DIR + ST_WITH_INTERFACE_DEF);
        NodeTemplate nodeTemplateWithInterface =
                DataModelUtil.getNodeTemplate(serviceTemplateWithInterfaceDef, NODE_TEMPLATE_ID);
        Map<String, Object> interfaces = nodeTemplateWithInterface.getInterfaces();
        Object interfaceObj = interfaces.get(INTERFACE_ID);

        InterfaceDefinitionTemplate actualInterfaceDefinition = new InterfaceDefinitionTemplate(interfaceObj);
        InterfaceDefinitionTemplate expectedInterfaceDefinitionTemplate = createInterfaceDefinitionTemplate();
        Assert.assertEquals(expectedInterfaceDefinitionTemplate, actualInterfaceDefinition);
    }

    @Test
    public void testYamlToServiceTemplateIncludingHeatExtend() throws IOException {
        ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
        try (InputStream yamlFile = toscaExtensionYamlUtil
                                            .loadYamlFileIs(BASE_DIR + "/serviceTemplateHeatExtend.yaml")) {
            ServiceTemplate serviceTemplateFromYaml =
                    toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
            ParameterDefinitionExt parameterDefinitionExt =
                    (ParameterDefinitionExt) serviceTemplateFromYaml.getTopology_template().getInputs().get("inParam1");
            Assert.assertNotNull(parameterDefinitionExt.getLabel());
            String backToYamlString = toscaExtensionYamlUtil.objectToYaml(serviceTemplateFromYaml);
            Assert.assertNotNull(backToYamlString);
        }
    }

    @Test
    public void testServiceFilter() throws IOException {
        ServiceTemplate serviceTemplateWithServiceFilter = getServiceTemplateExt(BASE_DIR + ST_WITH_SERVICE_FILTER);

        NodeTemplate firstNodeTemplate =
                DataModelUtil.getNodeTemplate(serviceTemplateWithServiceFilter, FIRST_NODE_TEMPLATE);
        Map<String, RequirementAssignment> nodeTemplateRequirements =
                DataModelUtil.getNodeTemplateRequirements(firstNodeTemplate);

        Object req1 = nodeTemplateRequirements.get(REQ1);
        Assert.assertTrue(req1 instanceof RequirementAssignmentExt);
        Assert.assertNotNull(((RequirementAssignmentExt) req1).getService_filter());
        List<Map<String, List<Constraint>>> properties =
                ((RequirementAssignmentExt) req1).getService_filter().getProperties();
        Assert.assertNotNull(properties);
        List<Constraint> vmdNameConstrain = properties.get(0).get(VMD_NAME);
        Assert.assertNotNull(vmdNameConstrain);
        Assert.assertNotNull(vmdNameConstrain.get(0).getEqual());

        List<Map<String, CapabilityFilter>> capabilities =
                ((RequirementAssignmentExt) req1).getService_filter().getCapabilities();
        Assert.assertNotNull(capabilities);
        CapabilityFilter capabilityFilter = capabilities.get(0).get(DIRECTOR);
        Assert.assertNotNull(capabilityFilter);
        Assert.assertNotNull(capabilityFilter.getProperties());


        Object req2 = nodeTemplateRequirements.get(REQ2);
        Assert.assertTrue(req2 instanceof RequirementAssignmentExt);
        Assert.assertNotNull(((RequirementAssignmentExt) req2).getService_filter());
        Object toscaId = ((RequirementAssignmentExt) req2).getService_filter().getTosca_id();
        Assert.assertNotNull(toscaId);
        Assert.assertEquals(SERVICE_FILTER_TOSCA_ID, toscaId.toString());


        String serviceTemplateYaml = toscaExtensionYamlUtil.objectToYaml(serviceTemplateWithServiceFilter);
        Assert.assertNotNull(serviceTemplateYaml);

    }

    @Test
    public void testSubstitutionMapping() throws IOException {
        final ServiceTemplate serviceTemplate = getServiceTemplateExt(BASE_DIR + SUBSTITUTION_MAPPING);
        final SubstitutionMapping substitutionMappings = DataModelUtil.getSubstitutionMappings(serviceTemplate);
        Assert.assertEquals("myNodeType.node", substitutionMappings.getNode_type());
        Assert.assertNotNull(substitutionMappings.getCapabilities());
        Assert.assertEquals(1,substitutionMappings.getCapabilities().size());
        Assert.assertNotNull(substitutionMappings.getRequirements());
        Assert.assertEquals(1,substitutionMappings.getRequirements().size());
        Assert.assertNull(substitutionMappings.getSubstitution_filter());
    }

    @Test
    public void testSubstitutionMappingWithFilter() throws IOException {
        final ServiceTemplate serviceTemplate = getServiceTemplateExt(BASE_DIR + SUBSTITUTION_MAPPING_WITH_FILTER);

        final SubstitutionMapping substitutionMappings = DataModelUtil.getSubstitutionMappings(serviceTemplate);
        Assert.assertEquals("myNodeType.node", substitutionMappings.getNode_type());
        Assert.assertNotNull(substitutionMappings.getCapabilities());
        Assert.assertEquals(1,substitutionMappings.getCapabilities().size());
        Assert.assertNotNull(substitutionMappings.getRequirements());
        Assert.assertEquals(1,substitutionMappings.getRequirements().size());
        final NodeFilter substitutionFilter = substitutionMappings.getSubstitution_filter();
        Assert.assertNotNull(substitutionFilter);
        Assert.assertNotNull(substitutionFilter.getProperties());
        Assert.assertEquals(2,substitutionFilter.getProperties().size());
        final List<Constraint> vendorFilter = substitutionFilter.getProperties().get(0).get("vendor");
        Assert.assertNotNull(vendorFilter);
        Assert.assertNotNull(vendorFilter.get(0).getEqual());
    }

    private ServiceTemplate getServiceTemplate(String inputPath) throws IOException {
        try (InputStream yamlFile = yamlUtil.loadYamlFileIs(inputPath)) {
            return yamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
        }
    }

    private ServiceTemplate getServiceTemplateExt(String inputPath) throws IOException {
        try (InputStream yamlFile = toscaExtensionYamlUtil.loadYamlFileIs(inputPath)) {
            return toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
        }
    }

    private InterfaceType createInterfaceType() {
        OperationDefinition operationDefinition = createOperationDefinition();
        InterfaceType interfaceType = new InterfaceType();
        interfaceType.setDescription("test interface");
        interfaceType.addOperation(OPERATION_START, operationDefinition);
        return interfaceType;
    }

    private OperationDefinition createOperationDefinition() {
        OperationDefinition operationDefinition = new OperationDefinition();
        operationDefinition.setDescription(OPERATION_DESC);
        return operationDefinition;
    }

    private InterfaceDefinitionType createInterfaceDefinitionType() {
        OperationDefinitionType operationDefinitionType = createOperationDefinitionType();
        InterfaceDefinitionType interfaceDefinitionType = new InterfaceDefinitionType();
        interfaceDefinitionType.setType(INTERFACE_TYPE_VALUE);
        interfaceDefinitionType.addOperation(OPERATION_START, operationDefinitionType);
        return interfaceDefinitionType;
    }

    private InterfaceDefinitionTemplate createInterfaceDefinitionTemplate() {
        OperationDefinitionTemplate operationDefinitionTemplate = createOperationDefinitionTemplate();
        InterfaceDefinitionTemplate interfaceDefinitionTemplate = new InterfaceDefinitionTemplate();
        interfaceDefinitionTemplate.addOperation(OPERATION_START, operationDefinitionTemplate);
        return interfaceDefinitionTemplate;
    }

    private OperationDefinitionTemplate createOperationDefinitionTemplate() {
        OperationDefinitionTemplate operationDefinitionTemplate = new OperationDefinitionTemplate();
        operationDefinitionTemplate.setDescription(OPERATION_DESC);
        Implementation implementation = new Implementation();
        implementation.setPrimary(PRIMARY_IMPL);
        List<String> dependencies = new ArrayList<>();
        dependencies.add(DEPENDENCY_NAME);
        implementation.setDependencies(dependencies);
        operationDefinitionTemplate.setImplementation(implementation);
        return operationDefinitionTemplate;
    }

    private OperationDefinitionType createOperationDefinitionType() {
        OperationDefinitionType operationDefinitionType = new OperationDefinitionType();
        operationDefinitionType.setDescription(OPERATION_DESC);
        operationDefinitionType.setImplementation(IMPLEMENTATION_NAME);
        PropertyDefinition propertyDefinition = new PropertyDefinition();
        propertyDefinition.setType(STRING_TYPE);
        return operationDefinitionType;
    }
}