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/serviceWithUnknownDataTypes.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));
66 return new ServiceCsarInfo(user, CSAR_UUID, payload, SERVICE_NAME, mainTemplateName, mainTemplateContent, true);
69 @SuppressWarnings("unchecked")
71 void testGetDataTypes() {
72 final Map<String, Object> dataTypes = csarInfo.getDataTypes();
73 assertEquals(184, dataTypes.size());
74 final Map<String, Object> dataTypeDefinition = (Map<String, Object>) dataTypes.get("tosca.datatypes.test_g");
75 assertNotNull(dataTypeDefinition);
76 assertEquals("tosca.datatypes.Root", dataTypeDefinition.get("derived_from"));
77 assertEquals("tosca.datatypes.test_h",
78 ((Map<String, Object>) ((Map<String, Object>) dataTypeDefinition.get("properties")).get("prop2")).get("type"));