1 package org.openecomp.core.converter.impl;
3 import org.apache.commons.io.IOUtils;
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;
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 {
29 public void loadCsar() throws Exception {
30 URL resource = ToscaConvertorDefinitionsTest.class.getResource("/csar/vCSCF.csar");
31 byte[] bytes = IOUtils.toByteArray(resource);
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);
40 assertNotNull(serviceTemplate);
41 assertTrue(serviceTemplate instanceof GlobalSubstitutionServiceTemplate);
43 assertNotNull(serviceTemplate.getMetadata());
44 assertFalse(serviceTemplate.getMetadata().isEmpty());
45 assertTrue(serviceTemplate.getMetadata().containsKey(TEMPLATE_NAME_PROPERTY));
47 assertNotNull(serviceTemplate.getImports());
48 assertFalse(serviceTemplate.getImports().isEmpty());
49 assertEquals(1 ,serviceTemplate.getImports().size());
50 assertTrue(serviceTemplate.getImports().get(0).containsKey(HEAT_INDEX));
52 assertEquals(DEFININTION_VERSION, serviceTemplate.getTosca_definitions_version());
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"));