3 * ============LICENSE_START=======================================================
4 * Copyright (C) 2022 Nordix Foundation.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.openecomp.sdc.be.components.csar;
24 import static org.junit.jupiter.api.Assertions.assertEquals;
25 import static org.junit.jupiter.api.Assertions.assertNotNull;
27 import java.net.URISyntaxException;
29 import org.junit.jupiter.api.BeforeEach;
30 import org.junit.jupiter.api.Test;
31 import org.junit.jupiter.api.extension.ExtendWith;
32 import org.mockito.Mock;
33 import org.mockito.junit.jupiter.MockitoExtension;
34 import org.openecomp.sdc.be.config.ConfigurationManager;
35 import org.openecomp.sdc.be.model.User;
36 import org.openecomp.sdc.common.impl.ExternalConfiguration;
37 import org.openecomp.sdc.common.impl.FSConfigurationSource;
38 import org.openecomp.sdc.common.zip.ZipUtils;
39 import org.openecomp.sdc.common.zip.exception.ZipException;
41 @ExtendWith(MockitoExtension.class)
42 class ServiceCsarInfoTest {
44 private ServiceCsarInfo csarInfo;
49 private static final String CSAR_UUID = "csarUUID";
50 private static final String PAYLOAD_NAME = "csars/serviceWithUnknownTypes.csar";
51 private static final String SERVICE_NAME = "serviceWithDataType";
52 private static final String MAIN_TEMPLATE_NAME = "Definitions/service-Servicewithdatatype-template.yml";
55 void setup() throws ZipException, URISyntaxException {
56 csarInfo = createCsarInfo(PAYLOAD_NAME, MAIN_TEMPLATE_NAME);
58 new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
61 private ServiceCsarInfo createCsarInfo(final String csarFileName, final String mainTemplateName) throws URISyntaxException, ZipException {
62 final File csarFile = new File(ServiceCsarInfoTest.class.getClassLoader().getResource(csarFileName).toURI());
63 final Map<String, byte[]> payload = ZipUtils.readZip(csarFile, false);
64 String mainTemplateContent = new String(payload.get(mainTemplateName));
65 return new ServiceCsarInfo(user, CSAR_UUID, payload, SERVICE_NAME, null, mainTemplateName, mainTemplateContent, true);
68 @SuppressWarnings("unchecked")
70 void testGetDataTypes() {
71 final Map<String, Object> dataTypes = csarInfo.getDataTypes();
72 assertEquals(184, dataTypes.size());
73 final Map<String, Object> dataTypeDefinition = (Map<String, Object>) dataTypes.get("tosca.datatypes.test_g");
74 assertNotNull(dataTypeDefinition);
75 assertEquals("tosca.datatypes.Root", dataTypeDefinition.get("derived_from"));
76 assertEquals("tosca.datatypes.test_h",
77 ((Map<String, Object>) ((Map<String, Object>) dataTypeDefinition.get("properties")).get("prop2")).get("type"));
80 @SuppressWarnings("unchecked")
82 void testGetInterfaceTypes() {
83 final Map<String, Object> interfaceTypes = csarInfo.getInterfaceTypes();
84 assertEquals(9, interfaceTypes.size());
85 final Map<String, Object> interfaceTypeDefinition = (Map<String, Object>) interfaceTypes.get(
86 "tosca.interfaces.test.node.lifecycle.Reconfigure");
87 assertNotNull(interfaceTypeDefinition);
88 assertEquals("tosca.interfaces.Root", interfaceTypeDefinition.get("derived_from"));
89 assertEquals("reconfigure", ((Map<String, Object>) interfaceTypeDefinition.get("Reconfigure")).get("description"));