8374faa279a921d89da2a1a6fcd85482a5ce9e3a
[so/adapters/so-cnf-adapter.git] /
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.so.cnfm.lcm.bpmn.flows.extclients.sdc;
21
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;
27 import java.io.File;
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;
33 import java.util.Map;
34 import org.junit.Test;
35
36 /**
37  *
38  * @author Waqas Ikram (waqas.ikram@est.tech)
39  *
40  */
41 public class SdcCsarPackageParserTest {
42
43     private static final String RESOURCE_ASD_PACKAGE_CSAR_PATH =
44             "src/test/resources/resource-Generatedasdpackage-csar.csar";
45
46     @Test
47     public void testResourceAsdCsar() throws IOException {
48         final SdcCsarPackageParser objUnderTest = new SdcCsarPackageParser();
49
50         final byte[] content = getFileContent(Paths.get(getAbsolutePath(RESOURCE_ASD_PACKAGE_CSAR_PATH)));
51
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));
58
59         @SuppressWarnings("unchecked")
60         final List<DeploymentItem> items =
61                 (List<DeploymentItem>) properties.get(SdcCsarPropertiesConstants.DEPLOYMENT_ITEMS_PARAM_NAME);
62         assertNotNull(items);
63         assertEquals(2, items.size());
64
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());
70
71
72     }
73
74     private String getAbsolutePath(final String path) {
75         final File file = new File(path);
76         return file.getAbsolutePath();
77     }
78
79     private byte[] getFileContent(final Path path) throws IOException {
80         return Files.readAllBytes(path);
81     }
82 }