2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2023 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
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
20 package org.onap.so.cnfm.lcm.bpmn.flows.extclients.sdc;
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertNotNull;
24 import static org.onap.so.cnfm.lcm.bpmn.flows.extclients.sdc.SdcCsarPropertiesConstants.APPLICATION_NAME_PARAM_NAME;
25 import static org.onap.so.cnfm.lcm.bpmn.flows.extclients.sdc.SdcCsarPropertiesConstants.DESCRIPTOR_ID_PARAM_NAME;
26 import static org.onap.so.cnfm.lcm.bpmn.flows.extclients.sdc.SdcCsarPropertiesConstants.DESCRIPTOR_INVARIANT_ID_PARAM_NAME;
28 import java.io.IOException;
29 import java.nio.file.Files;
30 import java.nio.file.Path;
31 import java.nio.file.Paths;
32 import java.util.List;
34 import org.junit.Test;
38 * @author Waqas Ikram (waqas.ikram@est.tech)
41 public class SdcCsarPackageParserTest {
43 private static final String RESOURCE_ASD_PACKAGE_CSAR_PATH =
44 "src/test/resources/resource-Generatedasdpackage-csar.csar";
47 public void testResourceAsdCsar() throws IOException {
48 final SdcCsarPackageParser objUnderTest = new SdcCsarPackageParser();
50 final byte[] content = getFileContent(Paths.get(getAbsolutePath(RESOURCE_ASD_PACKAGE_CSAR_PATH)));
52 final Map<String, Object> properties = objUnderTest.getAsdProperties(content);
53 assertEquals("123e4567-e89b-12d3-a456-426614174000", properties.get(DESCRIPTOR_ID_PARAM_NAME));
54 assertEquals("123e4yyy-e89b-12d3-a456-426614174abc", properties.get(DESCRIPTOR_INVARIANT_ID_PARAM_NAME));
55 assertEquals("SampleApp", properties.get(APPLICATION_NAME_PARAM_NAME));
56 assertEquals("2.3", properties.get(SdcCsarPropertiesConstants.APPLICATION_VERSION_PARAM_NAME));
57 assertEquals("MyCompany", properties.get(SdcCsarPropertiesConstants.PROVIDER_PARAM_NAME));
59 @SuppressWarnings("unchecked")
60 final List<DeploymentItem> items =
61 (List<DeploymentItem>) properties.get(SdcCsarPropertiesConstants.DEPLOYMENT_ITEMS_PARAM_NAME);
63 assertEquals(2, items.size());
65 final DeploymentItem deploymentItem = items.get(0);
66 assertEquals("sampleapp-db", deploymentItem.getName());
67 assertEquals("1", deploymentItem.getItemId());
68 assertEquals("1", deploymentItem.getDeploymentOrder());
69 assertEquals("Artifacts/Deployment/HELM/sampleapp-db-operator-helm.tgz", deploymentItem.getFile());
74 private String getAbsolutePath(final String path) {
75 final File file = new File(path);
76 return file.getAbsolutePath();
79 private byte[] getFileContent(final Path path) throws IOException {
80 return Files.readAllBytes(path);