Service Import - Node Template Relationship Template
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / csar / YamlTemplateParsingHandlerTest.java
1 /*-
2  * ============LICENSE_START===============================================
3  * ONAP SDC
4  * ========================================================================
5  * Modifications Copyright (c) 2019 Samsung
6  * ========================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=================================================
19  */
20
21 package org.openecomp.sdc.be.components.csar;
22
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.junit.jupiter.api.Assertions.assertEquals;
25 import static org.junit.jupiter.api.Assertions.assertNotNull;
26 import static org.junit.jupiter.api.Assertions.assertTrue;
27 import static org.mockito.ArgumentMatchers.any;
28 import static org.mockito.ArgumentMatchers.eq;
29 import static org.mockito.Mockito.when;
30 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.ARTIFACTS;
31
32 import java.io.File;
33 import java.net.URISyntaxException;
34 import java.util.ArrayList;
35 import java.util.Collection;
36 import java.util.Collections;
37 import java.util.HashMap;
38 import java.util.List;
39 import java.util.Map;
40 import java.util.Optional;
41 import java.util.stream.Collectors;
42 import mockit.Deencapsulation;
43 import org.apache.commons.collections.MapUtils;
44 import org.apache.commons.lang3.StringUtils;
45 import org.assertj.core.util.Lists;
46 import org.junit.jupiter.api.BeforeAll;
47 import org.junit.jupiter.api.BeforeEach;
48 import org.junit.jupiter.api.Test;
49 import org.junit.jupiter.api.extension.ExtendWith;
50 import org.mockito.InjectMocks;
51 import org.mockito.Mock;
52 import org.mockito.junit.jupiter.MockitoExtension;
53 import org.openecomp.sdc.be.components.impl.AnnotationBusinessLogic;
54 import org.openecomp.sdc.be.components.impl.GroupTypeBusinessLogic;
55 import org.openecomp.sdc.be.components.impl.PolicyTypeBusinessLogic;
56 import org.openecomp.sdc.be.components.validation.AnnotationValidator;
57 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
58 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
59 import org.openecomp.sdc.be.model.CapabilityDefinition;
60 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
61 import org.openecomp.sdc.be.model.GroupProperty;
62 import org.openecomp.sdc.be.model.GroupTypeDefinition;
63 import org.openecomp.sdc.be.model.ParsedToscaYamlInfo;
64 import org.openecomp.sdc.be.model.PolicyDefinition;
65 import org.openecomp.sdc.be.model.PolicyTypeDefinition;
66 import org.openecomp.sdc.be.model.Resource;
67 import org.openecomp.sdc.be.model.Service;
68 import org.openecomp.sdc.be.model.UploadArtifactInfo;
69 import org.openecomp.sdc.be.model.UploadComponentInstanceInfo;
70 import org.openecomp.sdc.be.model.UploadReqInfo;
71 import org.openecomp.sdc.be.model.User;
72 import org.openecomp.sdc.be.model.operations.impl.AnnotationTypeOperations;
73 import org.openecomp.sdc.be.ui.model.OperationUi;
74 import org.openecomp.sdc.common.zip.ZipUtils;
75 import org.openecomp.sdc.common.zip.exception.ZipException;
76 import org.springframework.test.util.ReflectionTestUtils;
77
78 @ExtendWith(MockitoExtension.class)
79 public class YamlTemplateParsingHandlerTest {
80
81     @Mock
82     private GroupTypeBusinessLogic groupTypeBusinessLogic;
83     @Mock
84     private AnnotationTypeOperations annotationTypeOperations;
85     @Mock
86     private AnnotationValidator annotationValidator;
87     @Mock
88     private JanusGraphDao janusGraphDao;
89     @Mock
90     private User user;
91     @Mock
92     private PolicyTypeBusinessLogic policyTypeBusinessLogic;
93
94     private YamlTemplateParsingHandler handler;
95
96     private static Map<String, byte[]> csar;
97     private static String resourceYml;
98
99     private final static String VFC_GROUP_TYPE = "org.openecomp.groups.VfcInstanceGroup";
100     private final static String HEAT_GROUP_TYPE = "org.openecomp.groups.heat.HeatStack";
101     private final static String ROOT_GROUP_TYPE = "tosca.groups.Root";
102     private final static String OPENECOMP_ANTILOCATE_POLICY_TYPE = "org.openecomp.policies.placement.Antilocate";
103     private final static String ROOT_POLICIES_TYPE = "tosca.policies.Root";
104     private final static GroupTypeDefinition VfcInstanceGroupType = buildVfcInstanceGroupType();
105     private final static GroupTypeDefinition heatGroupType = buildHeatStackGroupType();
106     private final static GroupTypeDefinition rootGroupType = buildRootGroupType();
107     private static final PolicyTypeDefinition OPENECOMP_POLICY_TYPE = buildOpenecompPolicyType();
108     private final static String OPENECOMP_POLICY_NAME = "vepdg_server_group_policy";
109     private final static String CAPABILITY_TYPE = "org.openecomp.capabilities.VLANAssignment";
110     private final static String CAPABILITY_NAME = "vlan_assignment";
111     private static final String CSAR_FILE_PATH = "csars/with_groups.csar";
112     private static final String FILE_NAME = "MainServiceTemplate.yaml";
113     private static final String CSAR_UUID = "csarUUID";
114     private static final String RESOURCE_NAME = "resourceName";
115     private static final String MAIN_TEMPLATE_NAME = "Definitions/MainServiceTemplate.yaml";
116     private static final String NODE_NAME = "org.openecomp.resource.abstract.nodes.heat.mg";
117     private static final String MAIN_GROUP_NAME = "x_group";
118     private static final String NESTED_GROUP_NAME = "nested_mg_vepdg_group";
119
120     @InjectMocks
121     private YamlTemplateParsingHandler testSubject;
122
123     @BeforeAll
124     public static void prepareData() throws URISyntaxException, ZipException {
125         final File csarFile = new File(
126             YamlTemplateParsingHandlerTest.class.getClassLoader().getResource(CSAR_FILE_PATH).toURI());
127         csar = ZipUtils.readZip(csarFile, false);
128
129         Optional<String> keyOp = csar.keySet().stream().filter(k -> k.endsWith(FILE_NAME)).findAny();
130         byte[] mainTemplateService = keyOp.map(csar::get).orElse(null);
131         assertNotNull(mainTemplateService);
132
133         resourceYml = new String(mainTemplateService);
134     }
135
136     @BeforeEach
137     public void setup() {
138
139         AnnotationBusinessLogic annotationBusinessLogic = new AnnotationBusinessLogic(annotationTypeOperations,
140             annotationValidator);
141         handler = new YamlTemplateParsingHandler(janusGraphDao, groupTypeBusinessLogic, annotationBusinessLogic, policyTypeBusinessLogic);
142         ReflectionTestUtils.setField(handler, "policyTypeBusinessLogic", policyTypeBusinessLogic);
143     }
144
145     @Test
146     void parseResourceInfoFromOneNodeTest() {
147         when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(HEAT_GROUP_TYPE), any())).thenReturn(heatGroupType);
148
149         String main_template_content = new String(csar.get(MAIN_TEMPLATE_NAME));
150         CsarInfo csarInfo = new CsarInfo(user, CSAR_UUID, csar, RESOURCE_NAME,
151             MAIN_TEMPLATE_NAME, main_template_content, true);
152
153         Resource resource = new Resource();
154         ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(),
155             csarInfo.extractTypesInfo(), NODE_NAME, resource, getInterfaceTemplateYaml(csarInfo).get());
156
157         validateParsedYaml(parsedYaml, NESTED_GROUP_NAME,
158             Lists.newArrayList("heat_file", "description"));
159     }
160
161     @Test
162     void parseServicePropertiesInfoFromYamlTest() {
163         when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(HEAT_GROUP_TYPE), any())).thenReturn(heatGroupType);
164         String main_template_content = new String(csar.get(MAIN_TEMPLATE_NAME));
165         CsarInfo csarInfo = new CsarInfo(user, CSAR_UUID, csar, RESOURCE_NAME,
166             MAIN_TEMPLATE_NAME, main_template_content, true);
167
168         Service service = new Service();
169         ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(),
170             csarInfo.extractTypesInfo(), NODE_NAME, service, getInterfaceTemplateYaml(csarInfo).get());
171
172         assertThat(parsedYaml.getProperties()).isNotNull();
173         assertEquals(5, parsedYaml.getProperties().size());
174         assertTrue(parsedYaml.getProperties().containsKey("skip_post_instantiation_configuration"));
175         assertTrue(parsedYaml.getProperties().containsKey("controller_actor"));
176         assertTrue(parsedYaml.getProperties().containsKey("cds_model_version"));
177         assertTrue(parsedYaml.getProperties().containsKey("cds_model_name"));
178         assertTrue(parsedYaml.getProperties().containsKey("default_software_version"));
179     }
180
181     @Test
182     void parseRelationshipTemplateInfoFromYamlTest() {
183         when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(HEAT_GROUP_TYPE), any())).thenReturn(heatGroupType);
184         String main_template_content = new String(csar.get(MAIN_TEMPLATE_NAME));
185         CsarInfo csarInfo = new CsarInfo(user, CSAR_UUID, csar, RESOURCE_NAME,
186             MAIN_TEMPLATE_NAME, main_template_content, true);
187
188         Service service = new Service();
189         ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(),
190             csarInfo.extractTypesInfo(), NODE_NAME, service, getInterfaceTemplateYaml(csarInfo).get());
191
192         assertThat(parsedYaml.getInstances()).isNotNull();
193         final Map<String, List<OperationUi>> operations = new HashMap<>();
194         for (UploadComponentInstanceInfo instance : parsedYaml.getInstances().values()) {
195             final Map<String, List<UploadReqInfo>> requirements = instance.getRequirements();
196             if (MapUtils.isNotEmpty(requirements)) {
197                 requirements.values()
198                     .forEach(requirementInfoList -> requirementInfoList.stream()
199                         .filter(requirement -> StringUtils.isNotEmpty(requirement.getRelationshipTemplate()))
200                         .forEach(requirement -> operations.putAll(instance.getOperations())));
201             }
202         }
203         assertEquals(1, operations.size());
204     }
205
206     @Test
207     void parseResourceInfoFromYAMLTest() {
208         stubGetGroupType();
209         stubGetPolicyType();
210
211         Resource resource = new Resource();
212         ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(),
213             new HashMap<>(), "", resource, null);
214         validateParsedYamlWithCapability(parsedYaml);
215     }
216
217     @Test
218     void testSetArtifacts() {
219         UploadComponentInstanceInfo nodeTemplateInfo = new UploadComponentInstanceInfo();
220         Map<String, Object> nodeTemplateJsonMap = new HashMap<>();
221         Map<String, String> nodeMap = new HashMap<>();
222         nodeMap.put("name", "test_name");
223         nodeMap.put("type", "test_type");
224         nodeTemplateJsonMap.put(ARTIFACTS.getElementName(), nodeMap);
225         Deencapsulation.invoke(testSubject, "setArtifacts", nodeTemplateInfo, nodeTemplateJsonMap);
226         assertNotNull(nodeTemplateInfo.getArtifacts());
227     }
228
229     @Test
230     void testCreateArtifactsModuleFromYaml() {
231         Map<String, Map<String, Map<String, String>>> nodeTemplateJsonMap = new HashMap<>();
232         Map<String, Map<String, String>> map0 = new HashMap<>();
233         Map<String, String> map1 = new HashMap<>();
234         map1.put("file", "test_file");
235         map1.put("type", "test_type");
236         map0.put("test_art", map1);
237         nodeTemplateJsonMap.put(ARTIFACTS.getElementName(), map0);
238         Map<String, Map<String, UploadArtifactInfo>> result;
239         result = Deencapsulation.invoke(testSubject, "createArtifactsModuleFromYaml", nodeTemplateJsonMap);
240         assertTrue(MapUtils.isNotEmpty(result));
241         assertTrue(MapUtils.isNotEmpty(result.get(ARTIFACTS.getElementName())));
242         assertEquals("test_file", result.get(ARTIFACTS.getElementName()).get("test_art").getFile());
243         assertEquals("test_type", result.get(ARTIFACTS.getElementName()).get("test_art").getType());
244     }
245
246     @Test
247     void testAddModuleNodeTemplateArtifacts() {
248         Map<String, Map<String, UploadArtifactInfo>> result = new HashMap<>();
249         Map<String, String> map1 = new HashMap<>();
250         map1.put("file", "test_file");
251         map1.put("type", "test_type");
252         Deencapsulation.invoke(testSubject, "addModuleNodeTemplateArtifacts", result, map1, "test_art");
253         assertTrue(MapUtils.isNotEmpty(result));
254         assertTrue(MapUtils.isNotEmpty(result.get(ARTIFACTS.getElementName())));
255         assertEquals("test_file", result.get(ARTIFACTS.getElementName()).get("test_art").getFile());
256         assertEquals("test_type", result.get(ARTIFACTS.getElementName()).get("test_art").getType());
257     }
258
259     @Test
260     void testBuildModuleNodeTemplateArtifact() {
261         Map<String, String> map1 = new HashMap<>();
262         map1.put("file", "test_file");
263         map1.put("type", "test_type");
264         UploadArtifactInfo result;
265         result = Deencapsulation.invoke(testSubject, "buildModuleNodeTemplateArtifact", map1);
266         assertNotNull(result);
267         assertEquals("test_file", result.getFile());
268         assertEquals("test_type", result.getType());
269     }
270
271     @Test
272     void testFillArtifact() {
273         Map<String, String> map1 = new HashMap<>();
274         map1.put("file", "test_file");
275         map1.put("type", "test_type");
276         UploadArtifactInfo result = new UploadArtifactInfo();
277         Deencapsulation.invoke(testSubject, "fillArtifact", result, map1);
278         assertNotNull(result);
279         assertEquals("test_file", result.getFile());
280         assertEquals("test_type", result.getType());
281     }
282
283     @Test
284     void parseResourceWithPoliciesDefined() {
285         stubGetGroupType();
286         stubGetPolicyType();
287         Resource resource = new Resource();
288         ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(),
289             new HashMap<>(), "", resource, "");
290         validateParsedYamlWithPolicies(parsedYaml);
291     }
292
293     @Test
294     void parseResourceInstanceWithAttributesTest() {
295         stubGetGroupType();
296         stubGetPolicyType();
297         Resource resource = new Resource();
298         ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(),
299                 new HashMap<>(), "", resource, null);
300         validateParsedYamlWithAttributes(parsedYaml);
301     }
302
303     private void validateParsedYamlWithAttributes(ParsedToscaYamlInfo parsedYaml) {
304         ArrayList<String> expectedSubnetsShowList = new ArrayList<>();
305         expectedSubnetsShowList.add("val1");
306         expectedSubnetsShowList.add("val2");
307
308         HashMap<String, String> expectedSubnetsNameMap = new HashMap<>();
309         expectedSubnetsNameMap.put("name1", "name_val1");
310         expectedSubnetsNameMap.put("name2", "name_val2");
311
312
313         assertThat(parsedYaml.getInstances().get("resource_instance_with_attributes")).isNotNull();
314         UploadComponentInstanceInfo resourceInstanceWithAttributes = parsedYaml.getInstances().get("resource_instance_with_attributes");
315         assertEquals(5, resourceInstanceWithAttributes.getAttributes().size());
316
317         assertTrue(resourceInstanceWithAttributes.getAttributes().containsKey("fq_name"));
318         assertEquals(resourceInstanceWithAttributes.getAttributes().get("fq_name").getValue(), "fq_name_value");
319         assertTrue(resourceInstanceWithAttributes.getAttributes().containsKey("tosca_name"));
320         assertEquals(resourceInstanceWithAttributes.getAttributes().get("tosca_name").getValue(), "tosca_name_value");
321         assertTrue(resourceInstanceWithAttributes.getAttributes().containsKey("subnets_show"));
322         assertEquals(resourceInstanceWithAttributes.getAttributes().get("subnets_show").getValue(), expectedSubnetsShowList);
323         assertTrue(resourceInstanceWithAttributes.getAttributes().containsKey("subnets_name"));
324         assertEquals(resourceInstanceWithAttributes.getAttributes().get("subnets_name").getValue(), expectedSubnetsNameMap);
325         assertTrue(resourceInstanceWithAttributes.getAttributes().containsKey("new_attribute"));
326         assertEquals(resourceInstanceWithAttributes.getAttributes().get("new_attribute").getValue(), "new_attribute_value");
327     }
328
329     private void validateParsedYaml(ParsedToscaYamlInfo parsedYaml, String group, List<String> expectedProp) {
330         assertThat(parsedYaml).isNotNull();
331         assertThat(parsedYaml.getGroups()).isNotNull().containsKey(group);
332         assertThat(parsedYaml.getGroups().get(group)).isNotNull();
333
334         assertThat(parsedYaml.getGroups().get(group).getProperties()).isNotNull();
335         assertThat(parsedYaml.getGroups().get(group).getProperties()
336             .stream()
337             .map(PropertyDataDefinition::getName)
338             .collect(Collectors.toList()))
339             .containsAll(expectedProp);
340
341         assertThat(parsedYaml.getGroups().get(group).getMembers()).isNotNull();
342     }
343
344     private void validateParsedYamlWithCapability(ParsedToscaYamlInfo parsedYaml) {
345
346         final List<String> expectedProp = Lists.newArrayList("vfc_parent_port_role",
347             "network_collection_function", "vfc_instance_group_function", "subinterface_role");
348
349         validateParsedYaml(parsedYaml, MAIN_GROUP_NAME, expectedProp);
350
351         assertThat(parsedYaml.getGroups().get(MAIN_GROUP_NAME).getCapabilities()
352             .get(CAPABILITY_TYPE)
353             .get(0).getProperties().get(0).getValue()).isEqualTo("success");
354         assertThat(parsedYaml.getGroups().get(MAIN_GROUP_NAME).getCapabilities()).isNotNull();
355         assertThat(parsedYaml.getSubstitutionMappingNodeType()).isEqualTo("org.openecomp.resource.abstract.nodes.VF");
356     }
357
358     private void stubGetGroupType() {
359         when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(VFC_GROUP_TYPE), any())).thenReturn(VfcInstanceGroupType);
360         when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(HEAT_GROUP_TYPE), any())).thenReturn(heatGroupType);
361         when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(ROOT_GROUP_TYPE), any())).thenReturn(rootGroupType);
362     }
363
364     private static GroupTypeDefinition buildRootGroupType() {
365         return createGroupTypeDefinition(ROOT_GROUP_TYPE, null,
366             "The TOSCA Group Type all other TOSCA Group Types derive from");
367     }
368
369     private static GroupTypeDefinition buildHeatStackGroupType() {
370         GroupTypeDefinition groupType = createGroupTypeDefinition(HEAT_GROUP_TYPE, "tosca.groups.Root",
371             "Grouped all heat resources which are in the same heat stack");
372
373         GroupProperty property1 = createGroupProperty("heat_file",
374             "Heat file which associate to this group/heat stack", "SUPPORTED");
375
376         GroupProperty property2 = createGroupProperty("description",
377             "Group description", "SUPPORTED");
378
379         groupType.setProperties(Lists.newArrayList(property1, property2));
380         return groupType;
381     }
382
383     private static GroupTypeDefinition buildVfcInstanceGroupType() {
384         GroupTypeDefinition groupType = createGroupTypeDefinition(VFC_GROUP_TYPE, "tosca.groups.Root",
385             "Groups of VFCs with same parent port role");
386
387         GroupProperty property1 = createGroupProperty("vfc_instance_group_function",
388             "Function of this VFC group", null);
389
390         GroupProperty property2 = createGroupProperty("vfc_parent_port_role",
391             "Common role of parent ports of VFCs in this group", null);
392
393         GroupProperty property3 = createGroupProperty("network_collection_function",
394             "Network collection function assigned to this group", null);
395
396         GroupProperty property4 = createGroupProperty("subinterface_role",
397             "Common role of subinterfaces of VFCs in this group, criteria the group is created", null);
398
399         groupType.setProperties(Lists.newArrayList(property1, property2, property3, property4));
400
401         CapabilityDefinition capability = new CapabilityDefinition();
402         capability.setType(CAPABILITY_TYPE);
403         capability.setName(CAPABILITY_NAME);
404         ComponentInstanceProperty capabilityProperty = new ComponentInstanceProperty();
405         capabilityProperty.setName("vfc_instance_group_reference");
406         capabilityProperty.setType("string");
407         capability.setProperties(Collections.singletonList(capabilityProperty));
408
409         Map<String, CapabilityDefinition> capabilityMap = new HashMap<>();
410         capabilityMap.put(CAPABILITY_NAME, capability);
411         groupType.setCapabilities(capabilityMap);
412         return groupType;
413     }
414
415     private static GroupTypeDefinition createGroupTypeDefinition(String type, String derivedFrom, String description) {
416         GroupTypeDefinition property = new GroupTypeDefinition();
417
418         if (type != null) {
419             property.setType(type);
420         }
421
422         if (derivedFrom != null) {
423             property.setDerivedFrom(derivedFrom);
424         }
425
426         if (description != null) {
427             property.setDescription(description);
428         }
429
430         return property;
431     }
432
433     private static GroupProperty createGroupProperty(String name, String description,
434                                                      String status) {
435         GroupProperty property = new GroupProperty();
436         if (name != null) {
437             property.setName(name);
438         }
439
440         if (description != null) {
441             property.setDescription(description);
442         }
443
444         if (status != null) {
445             property.setStatus(status);
446         }
447
448         property.setType("string");
449         property.setRequired(true);
450
451         return property;
452     }
453
454     private void validateParsedYamlWithPolicies(ParsedToscaYamlInfo parsedYaml) {
455         // validate  policies
456         assertThat(parsedYaml.getPolicies()).isNotNull();
457         assertThat(parsedYaml.getPolicies()).containsKey(OPENECOMP_POLICY_NAME);
458         assertThat(parsedYaml.getPolicies().get(OPENECOMP_POLICY_NAME)).isInstanceOf(PolicyDefinition.class);
459     }
460
461     private void stubGetPolicyType() {
462         when(policyTypeBusinessLogic.getLatestPolicyTypeByType(eq(OPENECOMP_ANTILOCATE_POLICY_TYPE), any()))
463             .thenReturn(OPENECOMP_POLICY_TYPE);
464     }
465
466     private static PolicyTypeDefinition buildOpenecompPolicyType() {
467         return createPolicyTypeDefinition(OPENECOMP_POLICY_NAME, OPENECOMP_ANTILOCATE_POLICY_TYPE, ROOT_POLICIES_TYPE,
468             "The Openecomp Antilocate policy");
469     }
470
471     private static PolicyTypeDefinition createPolicyTypeDefinition(String policyName, String policyType, String derivedFrom, String description) {
472         PolicyTypeDefinition policyTypeDefinition = new PolicyTypeDefinition();
473         if (policyName != null && !policyName.isEmpty()) {
474             policyTypeDefinition.setName(policyName);
475         }
476         if (policyType != null) {
477             policyTypeDefinition.setType(policyType);
478         }
479         if (derivedFrom != null) {
480             policyTypeDefinition.setDerivedFrom(derivedFrom);
481         }
482         if (description != null) {
483             policyTypeDefinition.setDescription(description);
484         }
485         return policyTypeDefinition;
486     }
487
488     private Optional<String> getInterfaceTemplateYaml(CsarInfo csarInfo) {
489         String[] yamlFile;
490         String interfaceTemplateYaml = "";
491         if (csarInfo.getMainTemplateName().contains(".yml")) {
492             yamlFile = csarInfo.getMainTemplateName().split(".yml");
493             interfaceTemplateYaml = yamlFile[0] + "-interface.yml";
494         } else if (csarInfo.getMainTemplateName().contains(".yaml")) {
495             yamlFile = csarInfo.getMainTemplateName().split(".yaml");
496             interfaceTemplateYaml = yamlFile[0] + "-interface.yaml";
497         }
498         if (csarInfo.getCsar().containsKey(interfaceTemplateYaml)) {
499             return Optional.of(new String(csarInfo.getCsar().get(interfaceTemplateYaml)));
500         }
501         return Optional.empty();
502     }
503 }