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