7de9bdccb719be5f849e2d6c30e8d90b9cf1adf3
[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.junit.Assert.assertTrue;
25 import static org.onap.so.cnfm.lcm.bpmn.flows.extclients.sdc.SdcCsarPropertiesConstants.APPLICATION_NAME_PARAM_NAME;
26 import static org.onap.so.cnfm.lcm.bpmn.flows.extclients.sdc.SdcCsarPropertiesConstants.DESCRIPTOR_ID_PARAM_NAME;
27 import static org.onap.so.cnfm.lcm.bpmn.flows.extclients.sdc.SdcCsarPropertiesConstants.DESCRIPTOR_INVARIANT_ID_PARAM_NAME;
28 import java.io.File;
29 import java.io.IOException;
30 import java.nio.file.Files;
31 import java.nio.file.Path;
32 import java.nio.file.Paths;
33 import java.util.List;
34 import java.util.Map;
35 import org.junit.Test;
36
37 /**
38  *
39  * @author Waqas Ikram (waqas.ikram@est.tech)
40  *
41  */
42 public class SdcCsarPackageParserTest {
43
44     private static final String RESOURCE_ASD_PACKAGE_CSAR_PATH =
45             "src/test/resources/resource-Generatedasdpackage-csar.csar";
46
47     @Test
48     public void testResourceAsdCsar() throws IOException {
49         final SdcCsarPackageParser objUnderTest = new SdcCsarPackageParser();
50
51         final byte[] content = getFileContent(Paths.get(getAbsolutePath(RESOURCE_ASD_PACKAGE_CSAR_PATH)));
52
53         final Map<String, Object> properties = objUnderTest.getAsdProperties(content);
54         assertEquals("123e4567-e89b-12d3-a456-426614174000", properties.get(DESCRIPTOR_ID_PARAM_NAME));
55         assertEquals("123e4yyy-e89b-12d3-a456-426614174abc", properties.get(DESCRIPTOR_INVARIANT_ID_PARAM_NAME));
56         assertEquals("SampleApp", properties.get(APPLICATION_NAME_PARAM_NAME));
57         assertEquals("2.3", properties.get(SdcCsarPropertiesConstants.APPLICATION_VERSION_PARAM_NAME));
58         assertEquals("MyCompany", properties.get(SdcCsarPropertiesConstants.PROVIDER_PARAM_NAME));
59
60         @SuppressWarnings("unchecked")
61         final List<DeploymentItem> items =
62                 (List<DeploymentItem>) properties.get(SdcCsarPropertiesConstants.DEPLOYMENT_ITEMS_PARAM_NAME);
63         assertNotNull(items);
64         assertTrue(items.size() == 2);
65
66         DeploymentItem deploymentItem = items.get(0);
67         assertEquals("sampleapp-db", deploymentItem.getName());
68         assertEquals("1", deploymentItem.getItemId());
69         assertEquals("1", deploymentItem.getDeploymentOrder());
70         assertEquals("Artifacts/Deployment/HELM/sampleapp-db-operator-helm.tgz", deploymentItem.getFile());
71
72
73     }
74
75     private String getAbsolutePath(final String path) {
76         final File file = new File(path);
77         return file.getAbsolutePath();
78     }
79
80     private byte[] getFileContent(final Path path) throws IOException {
81         return Files.readAllBytes(path);
82     }
83 }