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