1 package org.openecomp.core.converter.impl;
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;
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.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
26 public class ToscaConvertorDefinitionsTest {
30 public void loadCsar() throws Exception {
31 URL resource = ToscaConvertorDefinitionsTest.class.getResource("/csar/vCSCF.csar");
32 byte[] bytes = IOUtils.toByteArray(resource);
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);
41 assertNotNull(serviceTemplate);
42 assertTrue(serviceTemplate instanceof GlobalSubstitutionServiceTemplate);
44 assertNotNull(serviceTemplate.getMetadata());
45 assertFalse(serviceTemplate.getMetadata().isEmpty());
46 assertTrue(serviceTemplate.getMetadata().containsKey(TEMPLATE_NAME_PROPERTY));
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));
54 assertEquals(DEFININTION_VERSION, serviceTemplate.getTosca_definitions_version());
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"));