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