2cea0f73e3be9ef27dcc245c9fdde2aa8e5230bf
[sdc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * Modifications copyright (c) 2021 Nokia
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremodule;
23
24 import org.junit.jupiter.api.Test;
25 import org.openecomp.sdc.heat.datatypes.manifest.FileData;
26 import org.openecomp.sdc.heat.datatypes.manifest.ManifestContent;
27 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
28 import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStructure;
29
30 import java.util.List;
31 import java.util.Optional;
32
33 import static org.junit.jupiter.api.Assertions.assertFalse;
34 import static org.junit.jupiter.api.Assertions.assertTrue;
35
36
37 public class ManifestCreatorNamingConventionImplTest extends ManifestCreatorNamingConventionImpl {
38
39     private static final String ARTIFACT_1 = "cloudtech_k8s_charts.zip";
40     private static final String ARTIFACT_2 = "cloudtech_azure_day0.zip";
41     private static final String ARTIFACT_3 = "cloudtech_aws_configtemplate.zip";
42     private static final String ARTIFACT_4 = "k8s_charts.zip";
43     private static final String ARTIFACT_5 = "cloudtech_openstack_configtemplate.zip";
44     private static final String PMDICT_YAML = "pmdict.yaml";
45
46
47     @Test
48     void testIsCloudSpecificArtifact() {
49         assertTrue(isCloudSpecificArtifact(ARTIFACT_1));
50         assertTrue(isCloudSpecificArtifact(ARTIFACT_2));
51         assertTrue(isCloudSpecificArtifact(ARTIFACT_3));
52         assertFalse(isCloudSpecificArtifact(ARTIFACT_4));
53         assertFalse(isCloudSpecificArtifact(ARTIFACT_5));
54     }
55
56     @Test
57     void shouldMapPmDictionaryTypeFromExistingManifestToPmDictionaryTypeInNewManifest() {
58         // given
59         VspDetails vspDetails = new VspDetails();
60         FilesDataStructure fileDataStructure = new FilesDataStructure();
61         fileDataStructure.setArtifacts(List.of(PMDICT_YAML));
62         ManifestContent existingManifest = prepareManifestWithPmDictFileWithType(FileData.Type.PM_DICTIONARY);
63
64         // when
65         Optional<ManifestContent> newManifest = new ManifestCreatorNamingConventionImpl()
66                 .createManifestFromExisting(vspDetails, fileDataStructure, existingManifest);
67
68         // then
69         assertTrue(newManifest.isPresent());
70         assertTrue(newManifest.get()
71                 .getData()
72                 .stream()
73                 .allMatch(fd -> fd.getType().equals(FileData.Type.PM_DICTIONARY) &&
74                         fd.getFile().equals(PMDICT_YAML)));
75     }
76
77     @Test
78     void shouldMapPmDictionaryWithOtherTypeFromExistingManifestToOtherTypeInNewManifest() {
79         // given
80         VspDetails vspDetails = new VspDetails();
81         FilesDataStructure fileDataStructure = new FilesDataStructure();
82         fileDataStructure.setArtifacts(List.of(PMDICT_YAML));
83         ManifestContent existingManifest = prepareManifestWithPmDictFileWithType(FileData.Type.OTHER);
84
85         // when
86         Optional<ManifestContent> newManifest = new ManifestCreatorNamingConventionImpl()
87                 .createManifestFromExisting(vspDetails, fileDataStructure, existingManifest);
88
89         // then
90         assertTrue(newManifest.isPresent());
91         assertTrue(newManifest.get()
92                 .getData()
93                 .stream()
94                 .allMatch(fd -> fd.getType().equals(FileData.Type.OTHER) &&
95                         fd.getFile().equals(PMDICT_YAML)));
96     }
97
98     private ManifestContent prepareManifestWithPmDictFileWithType(FileData.Type fileType) {
99         ManifestContent existingManifest = new ManifestContent();
100         FileData fileData = new FileData();
101         fileData.setFile(PMDICT_YAML);
102         fileData.setType(fileType);
103         existingManifest.setData(List.of(fileData));
104         return existingManifest;
105     }
106 }