Add collaboration feature
[sdc.git] / openecomp-be / lib / openecomp-tosca-converter-lib / openecomp-tosca-converter-core / src / test / java / org / openecomp / core / converter / impl / ToscaConvertorDefinitionsTest.java
1 package org.openecomp.core.converter.impl;
2
3 import org.apache.commons.io.IOUtils;
4 import org.junit.Test;
5 import org.openecomp.core.impl.GlobalSubstitutionServiceTemplate;
6 import org.openecomp.core.impl.ToscaConverterImpl;
7 import org.openecomp.core.utilities.file.FileContentHandler;
8 import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
9 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
10 import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
11
12 import java.net.URL;
13 import java.util.Map;
14 import java.util.Set;
15
16 import static org.junit.Assert.assertEquals;
17 import static org.junit.Assert.assertFalse;
18 import static org.junit.Assert.assertNotNull;
19 import static org.junit.Assert.assertTrue;
20 import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.DEFININTION_VERSION;
21 import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME;
22 import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.HEAT_INDEX;
23 import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.TEMPLATE_NAME_PROPERTY;
24 import static org.openecomp.sdc.common.utils.CommonUtil.validateAndUploadFileContent;
25 public class ToscaConvertorDefinitionsTest {
26
27
28     @Test
29     public void loadCsar() throws Exception {
30         URL resource = ToscaConvertorDefinitionsTest.class.getResource("/csar/vCSCF.csar");
31         byte[] bytes = IOUtils.toByteArray(resource);
32         assertNotNull(bytes);
33         FileContentHandler contentMap = validateAndUploadFileContent(OnboardingTypesEnum.CSAR, bytes);
34         ToscaConverterImpl toscaConverter = new ToscaConverterImpl();
35         ToscaServiceModel convert = toscaConverter.convert(contentMap);
36         Map<String, ServiceTemplate> serviceTemplates = convert.getServiceTemplates();
37         assertTrue(serviceTemplates.containsKey(GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME));
38         ServiceTemplate serviceTemplate = serviceTemplates.get(GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME);
39
40         assertNotNull(serviceTemplate);
41         assertTrue(serviceTemplate instanceof GlobalSubstitutionServiceTemplate);
42
43         assertNotNull(serviceTemplate.getMetadata());
44         assertFalse(serviceTemplate.getMetadata().isEmpty());
45         assertTrue(serviceTemplate.getMetadata().containsKey(TEMPLATE_NAME_PROPERTY));
46
47         assertNotNull(serviceTemplate.getImports());
48         assertFalse(serviceTemplate.getImports().isEmpty());
49         assertEquals(1 ,serviceTemplate.getImports().size());
50         assertTrue(serviceTemplate.getImports().get(0).containsKey(HEAT_INDEX));
51
52         assertEquals(DEFININTION_VERSION, serviceTemplate.getTosca_definitions_version());
53
54
55         assertNotNull(serviceTemplate.getNode_types());
56         assertEquals(1, serviceTemplate.getNode_types().size());
57         Set<String> keys = serviceTemplate.getNode_types().keySet();
58         assertTrue(keys.contains("tosca.nodes.nfv.ext.zte.VNF.vCSCF"));
59     }
60
61
62 }