aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandlerTest.java
blob: 218e0267d21d188fd9ea9f2d599d50317ae56a9a (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
/*-
 * ============LICENSE_START===============================================
 * ONAP SDC
 * ========================================================================
 * Modifications Copyright (c) 2019 Samsung
 * ========================================================================
 * 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.openecomp.sdc.be.components.csar;

import mockit.Deencapsulation;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.assertj.core.util.Lists;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.openecomp.sdc.be.components.impl.AnnotationBusinessLogic;
import org.openecomp.sdc.be.components.impl.GroupTypeBusinessLogic;
import org.openecomp.sdc.be.components.impl.PolicyTypeBusinessLogic;
import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
import org.openecomp.sdc.be.components.validation.AnnotationValidator;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.model.CapabilityDefinition;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.GroupProperty;
import org.openecomp.sdc.be.model.GroupTypeDefinition;
import org.openecomp.sdc.be.model.ParsedToscaYamlInfo;
import org.openecomp.sdc.be.model.PolicyDefinition;
import org.openecomp.sdc.be.model.PolicyTypeDefinition;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.UploadArtifactInfo;
import org.openecomp.sdc.be.model.UploadComponentInstanceInfo;
import org.openecomp.sdc.be.model.UploadReqInfo;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.operations.impl.AnnotationTypeOperations;
import org.openecomp.sdc.be.ui.model.OperationUi;
import org.openecomp.sdc.common.zip.ZipUtils;
import org.openecomp.sdc.common.zip.exception.ZipException;
import org.springframework.test.util.ReflectionTestUtils;

import java.io.File;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.ARTIFACTS;

@ExtendWith(MockitoExtension.class)
public class YamlTemplateParsingHandlerTest {

    @Mock
    private GroupTypeBusinessLogic groupTypeBusinessLogic;
    @Mock
    private AnnotationTypeOperations annotationTypeOperations;
    @Mock
    private AnnotationValidator annotationValidator;
    @Mock
    private JanusGraphDao janusGraphDao;
    @Mock
    private User user;
    @Mock
    private PolicyTypeBusinessLogic policyTypeBusinessLogic;
    @Mock
    private ServiceBusinessLogic serviceBusinessLogic;
    @Mock
    private ToscaFunctionYamlParsingHandler toscaFunctionYamlParsingHandler;

    private YamlTemplateParsingHandler handler;

    private static Map<String, byte[]> csar;
    private static String resourceYml;

    private final static String VFC_GROUP_TYPE = "org.openecomp.groups.VfcInstanceGroup";
    private final static String HEAT_GROUP_TYPE = "org.openecomp.groups.heat.HeatStack";
    private final static String ROOT_GROUP_TYPE = "tosca.groups.Root";
    private final static String OPENECOMP_ANTILOCATE_POLICY_TYPE = "org.openecomp.policies.placement.Antilocate";
    private final static String ROOT_POLICIES_TYPE = "tosca.policies.Root";
    private final static GroupTypeDefinition VfcInstanceGroupType = buildVfcInstanceGroupType();
    private final static GroupTypeDefinition heatGroupType = buildHeatStackGroupType();
    private final static GroupTypeDefinition rootGroupType = buildRootGroupType();
    private static final PolicyTypeDefinition OPENECOMP_POLICY_TYPE = buildOpenecompPolicyType();
    private final static String OPENECOMP_POLICY_NAME = "vepdg_server_group_policy";
    private final static String CAPABILITY_TYPE = "org.openecomp.capabilities.VLANAssignment";
    private final static String CAPABILITY_NAME = "vlan_assignment";
    private static final String CSAR_FILE_PATH = "csars/with_groups.csar";
    private static final String FILE_NAME = "MainServiceTemplate.yaml";
    private static final String CSAR_UUID = "csarUUID";
    private static final String RESOURCE_NAME = "resourceName";
    private static final String MAIN_TEMPLATE_NAME = "Definitions/MainServiceTemplate.yaml";
    private static final String NODE_NAME = "org.openecomp.resource.abstract.nodes.heat.mg";
    private static final String MAIN_GROUP_NAME = "x_group";
    private static final String NESTED_GROUP_NAME = "nested_mg_vepdg_group";

    @InjectMocks
    private YamlTemplateParsingHandler testSubject;

    @BeforeAll
    public static void prepareData() throws URISyntaxException, ZipException {
        final File csarFile = new File(
            YamlTemplateParsingHandlerTest.class.getClassLoader().getResource(CSAR_FILE_PATH).toURI());
        csar = ZipUtils.readZip(csarFile, false);

        Optional<String> keyOp = csar.keySet().stream().filter(k -> k.endsWith(FILE_NAME)).findAny();
        byte[] mainTemplateService = keyOp.map(csar::get).orElse(null);
        assertNotNull(mainTemplateService);

        resourceYml = new String(mainTemplateService);
    }

    @BeforeEach
    public void setup() {
        final var annotationBusinessLogic = new AnnotationBusinessLogic(annotationTypeOperations, annotationValidator);
        handler = new YamlTemplateParsingHandler(janusGraphDao, groupTypeBusinessLogic, annotationBusinessLogic, policyTypeBusinessLogic,
            serviceBusinessLogic, toscaFunctionYamlParsingHandler);
        ReflectionTestUtils.setField(handler, "policyTypeBusinessLogic", policyTypeBusinessLogic);
    }

    @Test
    void parseResourceInfoFromOneNodeTest() {
        when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(HEAT_GROUP_TYPE), any())).thenReturn(heatGroupType);

        String main_template_content = new String(csar.get(MAIN_TEMPLATE_NAME));
        CsarInfo csarInfo = new OnboardedCsarInfo(user, CSAR_UUID, csar, RESOURCE_NAME,
            MAIN_TEMPLATE_NAME, main_template_content, true);

        Resource resource = new Resource();
        ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(),
            csarInfo.extractTypesInfo(), NODE_NAME, resource, getInterfaceTemplateYaml(csarInfo).get());

        validateParsedYaml(parsedYaml, NESTED_GROUP_NAME,
            Lists.newArrayList("heat_file", "description"));
    }

    @Test
    void parseServicePropertiesInfoFromYamlTest() {
        when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(HEAT_GROUP_TYPE), any())).thenReturn(heatGroupType);
        String main_template_content = new String(csar.get(MAIN_TEMPLATE_NAME));
        CsarInfo csarInfo = new OnboardedCsarInfo(user, CSAR_UUID, csar, RESOURCE_NAME,
            MAIN_TEMPLATE_NAME, main_template_content, true);

        Service service = new Service();
        ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(),
            csarInfo.extractTypesInfo(), NODE_NAME, service, getInterfaceTemplateYaml(csarInfo).get());

        assertThat(parsedYaml.getProperties()).isNotNull();
        assertEquals(5, parsedYaml.getProperties().size());
        assertTrue(parsedYaml.getProperties().containsKey("skip_post_instantiation_configuration"));
        assertTrue(parsedYaml.getProperties().containsKey("controller_actor"));
        assertTrue(parsedYaml.getProperties().containsKey("cds_model_version"));
        assertTrue(parsedYaml.getProperties().containsKey("cds_model_name"));
        assertTrue(parsedYaml.getProperties().containsKey("default_software_version"));
    }

    @Test
    void parseRelationshipTemplateInfoFromYamlTest() {
        when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(HEAT_GROUP_TYPE), any())).thenReturn(heatGroupType);
        String main_template_content = new String(csar.get(MAIN_TEMPLATE_NAME));
        CsarInfo csarInfo = new OnboardedCsarInfo(user, CSAR_UUID, csar, RESOURCE_NAME,
            MAIN_TEMPLATE_NAME, main_template_content, true);

        Service service = new Service();
        ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(),
            csarInfo.extractTypesInfo(), NODE_NAME, service, getInterfaceTemplateYaml(csarInfo).get());

        assertThat(parsedYaml.getInstances()).isNotNull();
        final Map<String, List<OperationUi>> operations = new HashMap<>();
        for (UploadComponentInstanceInfo instance : parsedYaml.getInstances().values()) {
            final Map<String, List<UploadReqInfo>> requirements = instance.getRequirements();
            if (MapUtils.isNotEmpty(requirements)) {
                requirements.values()
                    .forEach(requirementInfoList -> requirementInfoList.stream()
                        .filter(requirement -> StringUtils.isNotEmpty(requirement.getRelationshipTemplate()))
                        .forEach(requirement -> operations.putAll(instance.getOperations())));
            }
        }
        assertEquals(1, operations.size());
    }

    @Test
    void parseResourceInfoFromYAMLTest() {
        stubGetGroupType();
        stubGetPolicyType();

        Resource resource = new Resource();
        ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(),
            new HashMap<>(), "", resource, null);
        validateParsedYamlWithCapability(parsedYaml);
    }

    @Test
    void testSetArtifacts() {
        UploadComponentInstanceInfo nodeTemplateInfo = new UploadComponentInstanceInfo();
        Map<String, Object> nodeTemplateJsonMap = new HashMap<>();
        Map<String, String> nodeMap = new HashMap<>();
        nodeMap.put("name", "test_name");
        nodeMap.put("type", "test_type");
        nodeTemplateJsonMap.put(ARTIFACTS.getElementName(), nodeMap);
        Deencapsulation.invoke(testSubject, "setArtifacts", nodeTemplateInfo, nodeTemplateJsonMap);
        assertNotNull(nodeTemplateInfo.getArtifacts());
    }

    @Test
    void testCreateArtifactsModuleFromYaml() {
        Map<String, Map<String, Map<String, String>>> nodeTemplateJsonMap = new HashMap<>();
        Map<String, Map<String, String>> map0 = new HashMap<>();
        Map<String, String> map1 = new HashMap<>();
        map1.put("file", "test_file");
        map1.put("type", "test_type");
        map0.put("test_art", map1);
        nodeTemplateJsonMap.put(ARTIFACTS.getElementName(), map0);
        Map<String, Map<String, UploadArtifactInfo>> result;
        result = Deencapsulation.invoke(testSubject, "createArtifactsModuleFromYaml", nodeTemplateJsonMap);
        assertTrue(MapUtils.isNotEmpty(result));
        assertTrue(MapUtils.isNotEmpty(result.get(ARTIFACTS.getElementName())));
        assertEquals("test_file", result.get(ARTIFACTS.getElementName()).get("test_art").getFile());
        assertEquals("test_type", result.get(ARTIFACTS.getElementName()).get("test_art").getType());
    }

    @Test
    void testAddModuleNodeTemplateArtifacts() {
        Map<String, Map<String, UploadArtifactInfo>> result = new HashMap<>();
        Map<String, String> map1 = new HashMap<>();
        map1.put("file", "test_file");
        map1.put("type", "test_type");
        Deencapsulation.invoke(testSubject, "addModuleNodeTemplateArtifacts", result, map1, "test_art");
        assertTrue(MapUtils.isNotEmpty(result));
        assertTrue(MapUtils.isNotEmpty(result.get(ARTIFACTS.getElementName())));
        assertEquals("test_file", result.get(ARTIFACTS.getElementName()).get("test_art").getFile());
        assertEquals("test_type", result.get(ARTIFACTS.getElementName()).get("test_art").getType());
    }

    @Test
    void testBuildModuleNodeTemplateArtifact() {
        Map<String, String> map1 = new HashMap<>();
        map1.put("file", "test_file");
        map1.put("type", "test_type");
        UploadArtifactInfo result;
        result = Deencapsulation.invoke(testSubject, "buildModuleNodeTemplateArtifact", map1);
        assertNotNull(result);
        assertEquals("test_file", result.getFile());
        assertEquals("test_type", result.getType());
    }

    @Test
    void testFillArtifact() {
        Map<String, String> map1 = new HashMap<>();
        map1.put("file", "test_file");
        map1.put("type", "test_type");
        UploadArtifactInfo result = new UploadArtifactInfo();
        Deencapsulation.invoke(testSubject, "fillArtifact", result, map1);
        assertNotNull(result);
        assertEquals("test_file", result.getFile());
        assertEquals("test_type", result.getType());
    }

    @Test
    void parseResourceWithPoliciesDefined() {
        stubGetGroupType();
        stubGetPolicyType();
        Resource resource = new Resource();
        ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(),
            new HashMap<>(), "", resource, "");
        validateParsedYamlWithPolicies(parsedYaml);
    }

    @Test
    void parseResourceInstanceWithAttributesTest() {
        stubGetGroupType();
        stubGetPolicyType();
        Resource resource = new Resource();
        ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(),
                new HashMap<>(), "", resource, null);
        validateParsedYamlWithAttributes(parsedYaml);
    }

    private void validateParsedYamlWithAttributes(ParsedToscaYamlInfo parsedYaml) {
        ArrayList<String> expectedSubnetsShowList = new ArrayList<>();
        expectedSubnetsShowList.add("val1");
        expectedSubnetsShowList.add("val2");

        HashMap<String, String> expectedSubnetsNameMap = new HashMap<>();
        expectedSubnetsNameMap.put("name1", "name_val1");
        expectedSubnetsNameMap.put("name2", "name_val2");


        assertThat(parsedYaml.getInstances().get("resource_instance_with_attributes")).isNotNull();
        UploadComponentInstanceInfo resourceInstanceWithAttributes = parsedYaml.getInstances().get("resource_instance_with_attributes");
        assertEquals(5, resourceInstanceWithAttributes.getAttributes().size());

        assertTrue(resourceInstanceWithAttributes.getAttributes().containsKey("fq_name"));
        assertEquals("fq_name_value", resourceInstanceWithAttributes.getAttributes().get("fq_name").getValue());
        assertTrue(resourceInstanceWithAttributes.getAttributes().containsKey("tosca_name"));
        assertEquals("tosca_name_value", resourceInstanceWithAttributes.getAttributes().get("tosca_name").getValue());
        assertTrue(resourceInstanceWithAttributes.getAttributes().containsKey("subnets_show"));
        assertEquals(expectedSubnetsShowList, resourceInstanceWithAttributes.getAttributes().get("subnets_show").getValue());
        assertTrue(resourceInstanceWithAttributes.getAttributes().containsKey("subnets_name"));
        assertEquals(expectedSubnetsNameMap, resourceInstanceWithAttributes.getAttributes().get("subnets_name").getValue());
        assertTrue(resourceInstanceWithAttributes.getAttributes().containsKey("new_attribute"));
        assertEquals("new_attribute_value", resourceInstanceWithAttributes.getAttributes().get("new_attribute").getValue());
    }

    private void validateParsedYaml(ParsedToscaYamlInfo parsedYaml, String group, List<String> expectedProp) {
        assertThat(parsedYaml).isNotNull();
        assertThat(parsedYaml.getGroups()).isNotNull().containsKey(group);
        assertThat(parsedYaml.getGroups().get(group)).isNotNull();

        assertThat(parsedYaml.getGroups().get(group).getProperties()).isNotNull();
        assertThat(parsedYaml.getGroups().get(group).getProperties()
            .stream()
            .map(PropertyDataDefinition::getName)
            .collect(Collectors.toList()))
            .containsAll(expectedProp);

        assertThat(parsedYaml.getGroups().get(group).getMembers()).isNotNull();
    }

    private void validateParsedYamlWithCapability(ParsedToscaYamlInfo parsedYaml) {

        final List<String> expectedProp = Lists.newArrayList("vfc_parent_port_role",
            "network_collection_function", "vfc_instance_group_function", "subinterface_role");

        validateParsedYaml(parsedYaml, MAIN_GROUP_NAME, expectedProp);

        assertThat(parsedYaml.getGroups().get(MAIN_GROUP_NAME).getCapabilities()
            .get(CAPABILITY_TYPE)
            .get(0).getProperties().get(0).getValue()).isEqualTo("success");
        assertThat(parsedYaml.getGroups().get(MAIN_GROUP_NAME).getCapabilities()).isNotNull();
        assertThat(parsedYaml.getSubstitutionMappingNodeType()).isEqualTo("org.openecomp.resource.abstract.nodes.VF");
    }

    private void stubGetGroupType() {
        when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(VFC_GROUP_TYPE), any())).thenReturn(VfcInstanceGroupType);
        when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(HEAT_GROUP_TYPE), any())).thenReturn(heatGroupType);
        when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(ROOT_GROUP_TYPE), any())).thenReturn(rootGroupType);
    }

    private static GroupTypeDefinition buildRootGroupType() {
        return createGroupTypeDefinition(ROOT_GROUP_TYPE, null,
            "The TOSCA Group Type all other TOSCA Group Types derive from");
    }

    private static GroupTypeDefinition buildHeatStackGroupType() {
        GroupTypeDefinition groupType = createGroupTypeDefinition(HEAT_GROUP_TYPE, "tosca.groups.Root",
            "Grouped all heat resources which are in the same heat stack");

        GroupProperty property1 = createGroupProperty("heat_file",
            "Heat file which associate to this group/heat stack", "SUPPORTED");

        GroupProperty property2 = createGroupProperty("description",
            "Group description", "SUPPORTED");

        groupType.setProperties(Lists.newArrayList(property1, property2));
        return groupType;
    }

    private static GroupTypeDefinition buildVfcInstanceGroupType() {
        GroupTypeDefinition groupType = createGroupTypeDefinition(VFC_GROUP_TYPE, "tosca.groups.Root",
            "Groups of VFCs with same parent port role");

        GroupProperty property1 = createGroupProperty("vfc_instance_group_function",
            "Function of this VFC group", null);

        GroupProperty property2 = createGroupProperty("vfc_parent_port_role",
            "Common role of parent ports of VFCs in this group", null);

        GroupProperty property3 = createGroupProperty("network_collection_function",
            "Network collection function assigned to this group", null);

        GroupProperty property4 = createGroupProperty("subinterface_role",
            "Common role of subinterfaces of VFCs in this group, criteria the group is created", null);

        groupType.setProperties(Lists.newArrayList(property1, property2, property3, property4));

        CapabilityDefinition capability = new CapabilityDefinition();
        capability.setType(CAPABILITY_TYPE);
        capability.setName(CAPABILITY_NAME);
        ComponentInstanceProperty capabilityProperty = new ComponentInstanceProperty();
        capabilityProperty.setName("vfc_instance_group_reference");
        capabilityProperty.setType("string");
        capability.setProperties(Collections.singletonList(capabilityProperty));

        Map<String, CapabilityDefinition> capabilityMap = new HashMap<>();
        capabilityMap.put(CAPABILITY_NAME, capability);
        groupType.setCapabilities(capabilityMap);
        return groupType;
    }

    private static GroupTypeDefinition createGroupTypeDefinition(String type, String derivedFrom, String description) {
        GroupTypeDefinition property = new GroupTypeDefinition();

        if (type != null) {
            property.setType(type);
        }

        if (derivedFrom != null) {
            property.setDerivedFrom(derivedFrom);
        }

        if (description != null) {
            property.setDescription(description);
        }

        return property;
    }

    private static GroupProperty createGroupProperty(String name, String description,
                                                     String status) {
        GroupProperty property = new GroupProperty();
        if (name != null) {
            property.setName(name);
        }

        if (description != null) {
            property.setDescription(description);
        }

        if (status != null) {
            property.setStatus(status);
        }

        property.setType("string");
        property.setRequired(true);

        return property;
    }

    private void validateParsedYamlWithPolicies(ParsedToscaYamlInfo parsedYaml) {
        // validate  policies
        assertThat(parsedYaml.getPolicies()).isNotNull();
        assertThat(parsedYaml.getPolicies()).containsKey(OPENECOMP_POLICY_NAME);
        assertThat(parsedYaml.getPolicies().get(OPENECOMP_POLICY_NAME)).isInstanceOf(PolicyDefinition.class);
    }

    private void stubGetPolicyType() {
        when(policyTypeBusinessLogic.getLatestPolicyTypeByType(eq(OPENECOMP_ANTILOCATE_POLICY_TYPE), any()))
            .thenReturn(OPENECOMP_POLICY_TYPE);
    }

    private static PolicyTypeDefinition buildOpenecompPolicyType() {
        return createPolicyTypeDefinition(OPENECOMP_POLICY_NAME, OPENECOMP_ANTILOCATE_POLICY_TYPE, ROOT_POLICIES_TYPE,
            "The Openecomp Antilocate policy");
    }

    private static PolicyTypeDefinition createPolicyTypeDefinition(String policyName, String policyType, String derivedFrom, String description) {
        PolicyTypeDefinition policyTypeDefinition = new PolicyTypeDefinition();
        if (policyName != null && !policyName.isEmpty()) {
            policyTypeDefinition.setName(policyName);
        }
        if (policyType != null) {
            policyTypeDefinition.setType(policyType);
        }
        if (derivedFrom != null) {
            policyTypeDefinition.setDerivedFrom(derivedFrom);
        }
        if (description != null) {
            policyTypeDefinition.setDescription(description);
        }
        return policyTypeDefinition;
    }

    private Optional<String> getInterfaceTemplateYaml(CsarInfo csarInfo) {
        String[] yamlFile;
        String interfaceTemplateYaml = "";
        if (csarInfo.getMainTemplateName().contains(".yml")) {
            yamlFile = csarInfo.getMainTemplateName().split(".yml");
            interfaceTemplateYaml = yamlFile[0] + "-interface.yml";
        } else if (csarInfo.getMainTemplateName().contains(".yaml")) {
            yamlFile = csarInfo.getMainTemplateName().split(".yaml");
            interfaceTemplateYaml = yamlFile[0] + "-interface.yaml";
        }
        if (csarInfo.getCsar().containsKey(interfaceTemplateYaml)) {
            return Optional.of(new String(csarInfo.getCsar().get(interfaceTemplateYaml)));
        }
        return Optional.empty();
    }
}