2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
20 package org.openecomp.core.impl;
22 import org.apache.commons.io.IOUtils;
23 import org.junit.Ignore;
24 import org.junit.Test;
25 import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
26 import org.openecomp.core.utilities.file.FileContentHandler;
27 import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
28 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
34 import static org.junit.Assert.*;
35 import static org.openecomp.core.converter.datatypes.Constants.ONAP_INDEX;
36 import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.*;
37 import static org.openecomp.sdc.common.utils.CommonUtil.validateAndUploadFileContent;
38 public class ToscaConvertorDefinitionsTest {
43 public void loadCsar() throws Exception {
44 URL resource = ToscaConvertorDefinitionsTest.class.getResource("/csar/vCSCF.csar");
45 byte[] bytes = IOUtils.toByteArray(resource);
47 FileContentHandler contentMap = validateAndUploadFileContent(OnboardingTypesEnum.CSAR, bytes);
48 ToscaConverterImpl toscaConverter = new ToscaConverterImpl();
49 ToscaServiceModel convert = toscaConverter.convert(contentMap);
50 Map<String, ServiceTemplate> serviceTemplates = convert.getServiceTemplates();
51 assertTrue(serviceTemplates.containsKey(GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME));
52 ServiceTemplate serviceTemplate = serviceTemplates.get(GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME);
54 assertNotNull(serviceTemplate);
55 assertTrue(serviceTemplate instanceof GlobalSubstitutionServiceTemplate);
57 assertNotNull(serviceTemplate.getMetadata());
58 assertFalse(serviceTemplate.getMetadata().isEmpty());
59 assertTrue(serviceTemplate.getMetadata().containsKey(TEMPLATE_NAME_PROPERTY));
61 assertNotNull(serviceTemplate.getImports());
62 assertFalse(serviceTemplate.getImports().isEmpty());
63 assertEquals(1 ,serviceTemplate.getImports().size());
64 assertTrue(((Map) serviceTemplate.getImports().get(0)).containsKey(HEAT_INDEX));
65 assertTrue(((Map) serviceTemplate.getImports().get(0)).containsKey(ONAP_INDEX));
67 assertEquals(DEFININTION_VERSION, serviceTemplate.getTosca_definitions_version());
70 assertNotNull(serviceTemplate.getNode_types());
71 assertEquals(1, serviceTemplate.getNode_types().size());
72 Set<String> keys = serviceTemplate.getNode_types().keySet();
73 assertTrue(keys.contains("tosca.nodes.nfv.ext.zte.VNF.vCSCF"));