Add validation of manifest for helm packages.
[sdc.git] / openecomp-be / backend / openecomp-sdc-vendor-software-product-manager / src / test / java / org / openecomp / sdc / vendorsoftwareproduct / impl / onboarding / OnboardingPackageProcessorUnitTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 Nokia
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  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  *
16  *  SPDX-License-Identifier: Apache-2.0
17  *  ============LICENSE_END=========================================================
18  */
19
20 package org.openecomp.sdc.vendorsoftwareproduct.impl.onboarding;
21
22 import java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.List;
25 import org.junit.Test;
26 import org.openecomp.sdc.heat.datatypes.manifest.FileData;
27 import org.openecomp.sdc.heat.datatypes.manifest.FileData.Type;
28 import org.openecomp.sdc.heat.datatypes.manifest.ManifestContent;
29
30 import static org.hamcrest.Matchers.is;
31 import static org.junit.Assert.assertThat;
32
33
34 public class OnboardingPackageProcessorUnitTest {
35
36     private OnboardingPackageProcessor processor = new OnboardingPackageProcessor("unitTestPackage", null);
37
38     @Test
39     public void shouldValidateZipPackage_helmWithoutHeat() {
40         assertThat(processor.validateZipPackage(manifest(withHelmWithoutHeat())).size(), is(0));
41     }
42
43     @Test
44     public void shouldValidateZipPackage_withHelmAndHeat() {
45         assertThat(processor.validateZipPackage(manifest(withHelmAndHeat())).size(), is(0));
46     }
47
48     @Test
49     public void shouldValidateZipPackage_withHelmWithoutHeat() {
50         assertThat(processor.validateZipPackage(manifest(withoutHelmWithoutHeat())).size(), is(0));
51     }
52
53     @Test
54     public void shouldValidateZipPackage_helmInvalid() {
55         assertThat(processor.validateZipPackage(manifest(withHelmInvalid())).size(), is(1));
56     }
57
58     @Test
59     public void shouldValidateHelmPackage() {
60         ManifestAnalyzer analyzer = new ManifestAnalyzer(manifest(withHelmWithoutHeat()));
61
62        assertThat(processor.shouldValidateHelmPackage(analyzer), is(true));
63     }
64
65     @Test
66     public void shouldNotValidateHelmPackage_emptyInput() {
67         ManifestAnalyzer analyzer = new ManifestAnalyzer(manifest(empty()));
68
69         assertThat(processor.shouldValidateHelmPackage(analyzer), is(false));
70     }
71
72     @Test
73     public void shouldNotValidateHelmPackage_containsHeatModule() {
74         ManifestAnalyzer analyzer = new ManifestAnalyzer(manifest(withHelmAndHeat()));
75
76         assertThat(processor.shouldValidateHelmPackage(analyzer), is(false));
77     }
78
79     @Test
80     public void shouldNotValidateHelmPackage_noHelmModule() {
81         ManifestAnalyzer analyzer = new ManifestAnalyzer(manifest(withoutHelmWithoutHeat()));
82
83         assertThat(processor.shouldValidateHelmPackage(analyzer), is(false));
84     }
85
86     private ManifestContent manifest(List<FileData> entries) {
87         ManifestContent manifest = new ManifestContent();
88         manifest.setData(entries);
89         return  manifest;
90     }
91
92     private List<FileData> empty() {
93         return Collections.emptyList();
94     }
95
96     private List<FileData> withHelmAndHeat() {
97         List<FileData> entries = new ArrayList<>();
98
99         entries.add(createFileData(Type.HEAT, true));
100         entries.add(createFileData(Type.HELM, false));
101         entries.add(createFileData(Type.PM_DICTIONARY, false));
102
103         return entries;
104     }
105
106     private List<FileData> withHelmWithoutHeat() {
107         List<FileData> entries = new ArrayList<>();
108
109         entries.add(createFileData(Type.HELM, true));
110         entries.add(createFileData(Type.CHEF, false));
111         entries.add(createFileData(Type.PM_DICTIONARY, false));
112
113         return entries;
114     }
115
116     private List<FileData> withHelmInvalid() {
117         List<FileData> entries = new ArrayList<>();
118
119         entries.add(createFileData(Type.HELM, false));
120         entries.add(createFileData(Type.CHEF, false));
121         entries.add(createFileData(Type.PM_DICTIONARY, false));
122
123         return entries;
124     }
125
126     private List<FileData> withoutHelmWithoutHeat() {
127         List<FileData> entries = new ArrayList<>();
128
129         entries.add(createFileData(Type.CHEF, false));
130         entries.add(createFileData(Type.PM_DICTIONARY, false));
131
132         return entries;
133     }
134
135
136     private FileData createFileData(Type type, Boolean base) {
137         FileData f = new FileData();
138         f.setType(type);
139         f.setBase(base);
140         return f;
141     }
142
143 }