[SDC-29] rebase continue work to align source
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / US / ImportUpdateInformationalDeploymentArtifacts.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.ci.tests.US;
22
23 import static org.testng.AssertJUnit.assertTrue;
24
25 import java.util.Arrays;
26 import java.util.HashMap;
27 import java.util.List;
28 import java.util.Map;
29 import java.util.Set;
30 import java.util.stream.Collectors;
31 import java.util.stream.Stream;
32
33 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
34 import org.openecomp.sdc.be.model.ArtifactDefinition;
35 import org.openecomp.sdc.be.model.ComponentInstance;
36 import org.openecomp.sdc.be.model.Resource;
37 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
38 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
39 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
40 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
41 import org.openecomp.sdc.ci.tests.utilities.FileHandling;
42 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
43 import org.openecomp.sdc.ci.tests.utilities.ResourceUIUtils;
44 import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
45 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
46 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
47 import org.testng.SkipException;
48 import org.testng.annotations.Test;
49
50 public class ImportUpdateInformationalDeploymentArtifacts extends SetupCDTest {
51         
52         private String folder ="US747946";
53
54         // US747946 - Import artifacts to component instances
55         // TC1407822 -  Import VFC Artifacts - Deployment Artifacts - Multiple Artifacts, Multiple Types
56         @Test
57         public void importVfvArtifactsDeploymentArtifactsMultipleArtifactsMultipleTypes() throws Exception {
58                 
59                 if(true){
60                         throw new SkipException("Open bug 197126");                     
61                 }
62                 
63                 String filePath = FileHandling.getFilePath(folder);
64                 ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
65                 
66                 String fileName = "TC1407822.csar";
67                 
68                 ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, fileName, getUser());
69                 
70                 Resource resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resourceMetaData.getName(), "0.1");
71                 
72                 List<String> snmpPollArtifactList = Stream
73                                 .of("base_cgi_frwl.mib", "base_vIECCF_volume.yml", "node_userdata_script.sh", "vendor-license-model.xml")
74                                 .collect(Collectors.toList());
75                 List<String> snmpTrapArtifactList = Stream
76                                 .of("module_1_ixlt.mib", "module_1_ixlt.yaml")
77                                 .collect(Collectors.toList());
78                 
79         
80                 List<ArtifactDefinition> filteredArtifactNames = 
81                                 //Stream of component Instances
82                                 resource.getComponentInstances().stream()
83                                         //Stream of all the artifacts on all the component instances
84                                         .flatMap( e -> e.getDeploymentArtifacts().values().stream())
85                                         //filter relevant artifact types
86                                         .filter( e -> e.getArtifactType().equals(ArtifactTypeEnum.SNMP_TRAP.getType()) || e.getArtifactType().equals(ArtifactTypeEnum.SNMP_POLL.getType()))
87                                         //collect to list
88                                         .collect(Collectors.toList());
89
90                 
91                 assertTrue("Not contain all SNMP TRAP artifacts.", filteredArtifactNames.stream()
92                                 .filter(e -> e.getArtifactType().equals(ArtifactTypeEnum.SNMP_TRAP.getType()))
93                                 .map(e -> e.getArtifactName())
94                                 .collect(Collectors.toList())
95                                 .containsAll(snmpTrapArtifactList));
96                 
97                 assertTrue("Not contain all SNMP POLL artifacts.", filteredArtifactNames.stream()
98                                 .filter(e -> e.getArtifactType().equals(ArtifactTypeEnum.SNMP_POLL.getType()))
99                                 .map(e -> e.getArtifactName())
100                                 .collect(Collectors.toList())
101                                 .containsAll(snmpPollArtifactList));
102                 
103                 filteredArtifactNames.stream()
104                         .map(e->e.getArtifactDisplayName())
105                         .collect(Collectors.toList())
106                         .forEach(e -> {
107                                 assertTrue("Wrong artifact appear on deployment artifact UI page.", 
108                                                 !GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.ArtifactPageEnum.UUID.getValue() + e));
109                         });
110                 
111         }
112         
113         
114         
115         // US747946 - Import artifacts to component instances
116         // TC1408044 - Import VFC Artifacts - Informational Artifacts on Single VFC
117         @Test
118         public void importVfcArtifactsInformationalArtifactsOnSingleVfc() throws Exception {
119                 
120                 if(true){
121                         throw new SkipException("Open bug 197126");                     
122                 }
123                 
124                 String filePath = FileHandling.getFilePath(folder);
125                 String fileName = "TC1408044.csar";
126                 
127                 ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
128                 
129                 ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, fileName, getUser());
130                 
131                 Resource resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resourceMetaData.getName(), "0.1");
132                 
133                 resource.getComponentInstances().forEach(e -> {
134                         
135                         if(e.getToscaComponentName().endsWith("heat.ltm")) {
136                                 Map<String, List<String>> artifactsMap = new HashMap<String, List<String>>() {
137                                         {
138                                                 put(ArtifactTypeEnum.GUIDE.getType(), Arrays.asList("module_1_ldsa.yaml", "vendor-license-model.xml"));
139                                                 put(ArtifactTypeEnum.OTHER.getType(), Arrays.asList("module_2_ldsa.yaml", "vf-license-model.xml"));
140                                         }
141                                 };
142                                         
143                                 validateInformationalArtifactOnComponetInstance(e, artifactsMap, "heat.ltm");
144                         }
145                 });
146         }
147         
148         // TODO: Note there is performance issue with this CSAR
149         // US747946 - Import artifacts to component instances
150         // TC1407998 - Import VFC Artifacts - Deployment & Informational Artifacts - Multiple VFCs
151         @Test
152         public void importVfcArtifactsDeploymentAndInformationalArtifactsMultipleVfcs() throws Exception {
153                 
154                 if(true){
155                         throw new SkipException("Open bug 197126");                     
156                 }
157                 
158                 String filePath = FileHandling.getFilePath(folder);
159                 String fileName = "TC1407998.csar";
160                         
161                 ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
162                         
163                 ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, fileName, getUser());
164                 
165 //              resourceMetaData.setName("TC1407998");
166                 Resource resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resourceMetaData.getName(), "0.1");
167                         
168                 resource.getComponentInstances().forEach(e -> {
169                                 
170                         if(e.getToscaComponentName().endsWith("heat.ps")) {
171                                 Map<String, List<String>> deployArtifactsMap = new HashMap<String, List<String>>() {
172                                         {
173                                                 put(ArtifactTypeEnum.SNMP_POLL.getType(), Arrays.asList("PS_DEPL_Poll1.mib", "PS_DEPL_Poll2.xml", "PS_DEPL_Poll3.yaml"));
174                                                 put(ArtifactTypeEnum.SNMP_TRAP.getType(), Arrays.asList("PS_DEPL_Trap1.mib", "PS_DEPL_Trap2.xml", "PS_DEPL_Trap3.sh", "PS_DEPL_Trap4.yml"));
175                                         }
176                                 };
177                                 validateDeploymentArtifactOnComponetInstance(e, deployArtifactsMap, "heat.ps");
178                                 
179                                 Map<String, List<String>> infoArtifactsMap = new HashMap<String, List<String>>() {
180                                         {
181                                                 put(ArtifactTypeEnum.GUIDE.getType(), Arrays.asList("PS_INFO_GUIDE1.yaml", "PS_INFO_GUIDE2.xml"));
182                                                 put(ArtifactTypeEnum.OTHER.getType(), Arrays.asList("PS_INFO_OTHER1.yaml", "PS_INFO_OTHER2.xml"));
183                                         }
184                                 };
185                                 validateInformationalArtifactOnComponetInstance(e, infoArtifactsMap, "heat.ps");
186                                 
187                                 
188                         } else if (e.getToscaComponentName().endsWith("heat.sm")) {
189                                 Map<String, List<String>> deployArtifactsMap = new HashMap<String, List<String>>() {
190                                         {
191                                                 put(ArtifactTypeEnum.SNMP_POLL.getType(), Arrays.asList("SM_DEPL_Poll1.mib", "SM_DEPL_Poll2.mib", "SM_DEPL_Poll3.xml"));
192                                                 put(ArtifactTypeEnum.SNMP_TRAP.getType(), Arrays.asList("SM_DEPL_Trap1.mib", "SM_DEPL_Trap2.xml"));
193                                         }
194                                 };
195                                 validateDeploymentArtifactOnComponetInstance(e, deployArtifactsMap, "heat.sm");
196                                 
197                                 Map<String, List<String>> infoArtifactsMap = new HashMap<String, List<String>>() {
198                                         {
199                                                 put(ArtifactTypeEnum.GUIDE.getType(), Arrays.asList("SM_INFO_GUIDE1.yaml", "SM_INFO_GUIDE2.xml"));
200                                                 put(ArtifactTypeEnum.OTHER.getType(), Arrays.asList("SM_INFO_OTHER1.yaml", "SM_INFO_OTHER2.xml"));
201                                         }
202                                 };
203                                 validateInformationalArtifactOnComponetInstance(e, infoArtifactsMap, "heat.sm");
204                         }
205                 });
206                         
207         }
208         
209         // US747946 - Import artifacts to component instances
210         // TC1410352 - Import VFC Artifacts - Deployment Artifacts - Extra folder Under VFC-Identification
211         @Test
212         public void importVfcArtifactsDeploymentArtifactsExtraFolderUnderVfcIdentification() throws Exception {
213                 
214                 if(true){
215                         throw new SkipException("Open bug 197126");                     
216                 }
217                 
218                 String filePath = FileHandling.getFilePath(folder);
219                 String fileName = "TC1410352.csar";
220                         
221                 ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
222                         
223                 ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, fileName, getUser());
224                 
225 //              resourceMetaData.setName("TC1410352");
226                 Resource resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resourceMetaData.getName(), "0.1");
227                         
228                 resource.getComponentInstances().forEach(e -> {
229                                 
230                         if(e.getToscaComponentName().endsWith("heat.ltm")) {
231                                 Map<String, List<String>> deployArtifactsMap = new HashMap<String, List<String>>() {
232                                         {
233                                                 put(ArtifactTypeEnum.SNMP_POLL.getType(), Arrays.asList("Poll1.mib", "Poll2.xml", "Poll3.sh", "Poll4.yml"));
234                                                 put(ArtifactTypeEnum.SNMP_TRAP.getType(), Arrays.asList("Trap1.mib", "Trap2.yaml"));
235                                         }
236                                 };
237                                 validateDeploymentArtifactOnComponetInstance(e, deployArtifactsMap, "heat.ltm");
238                                 
239                                 Map<String, List<String>> infoArtifactsMap = new HashMap<String, List<String>>() {
240                                         {
241                                                 put(ArtifactTypeEnum.GUIDE.getType(), Arrays.asList("GUIDE1.yaml", "GUIDE2.xml"));
242                                                 put(ArtifactTypeEnum.OTHER.getType(), Arrays.asList("OTHER1.yaml", "OTHER2.xml"));
243                                         }
244                                 };
245                                 validateInformationalArtifactOnComponetInstance(e, infoArtifactsMap, "heat.ltm");
246                         }
247                 });
248         }
249         
250         
251         // US747946 - Import artifacts to component instances
252         // TC1410352 - Import VFC Artifacts - Deployment Artifacts - Invalid Artifact Type
253         @Test
254         public void importVfcArtifactsDeploymentArtifactsInvalidArtifactType() throws Exception {
255                 
256                 if(true){
257                         throw new SkipException("Open bug 197126");                     
258                 }
259                 
260                 String filePath = FileHandling.getFilePath(folder);
261                 String fileName = "TC1425032.csar";
262                                 
263                 ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
264                                 
265                 ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, fileName, getUser());
266                         
267 //              resourceMetaData.setName("TC1425032");
268                 Resource resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resourceMetaData.getName(), "0.1");
269                                 
270                 resource.getComponentInstances().forEach(e -> {
271                                         
272                         if(e.getToscaComponentName().endsWith("heat.ltm")) {
273                                 Map<String, List<String>> deployArtifactsMap = new HashMap<String, List<String>>() {
274                                         {
275                                                 put(ArtifactTypeEnum.SNMP_POLL.getType(), Arrays.asList("DeploySNMPPoll1.mib", "DeploySNMPPoll2.yml", "DeploySNMPPoll3.sh", "DeploySNMPPoll4.xml"));
276                                                 put(ArtifactTypeEnum.OTHER.getType(), Arrays.asList("DeploySNMPTrapB1.mib", "DeploySNMPTrapB2.yaml"));
277                                         }
278                                 };
279                                 validateDeploymentArtifactOnComponetInstance(e, deployArtifactsMap, "heat.ltm");
280                                         
281                                 Map<String, List<String>> infoArtifactsMap = new HashMap<String, List<String>>() {
282                                         {
283                                                 put(ArtifactTypeEnum.GUIDE.getType(), Arrays.asList("InfoGuide1.yaml", "InfoGuide2.xml"));
284                                                 put(ArtifactTypeEnum.OTHER.getType(), Arrays.asList("InfoOther1.yaml", "InfoOther2.xml", "InfoInvalid1.yaml"));
285                                         }
286                                 };
287                                 validateInformationalArtifactOnComponetInstance(e, infoArtifactsMap, "heat.ltm");
288                         }
289                 });
290         }
291         
292         
293         private void validateInformationalArtifactOnComponetInstance(ComponentInstance instacne, Map<String, List<String>> artifactsMap, String endswith){
294                 if(instacne.getToscaComponentName().endsWith(endswith) ){
295                         Set<String> types = artifactsMap.keySet();
296
297                         Map<String, List<ArtifactDefinition>> collect = instacne.getArtifacts().values().stream()
298                                         .filter( a -> types.contains(a.getArtifactType()))
299                                         .collect(Collectors.groupingBy( e -> e.getArtifactType()));
300                                 
301                         types.forEach(m -> {
302                                 if(collect.containsKey(m)){
303                                         List<String> found = collect.get(m).stream().map(e -> e.getArtifactName()).collect(Collectors.toList());
304                                         boolean isValid = found.containsAll(artifactsMap.get(m)) && artifactsMap.get(m).containsAll(found);
305                                         assertTrue("Not contain all artifact of type: " + m, isValid);
306                                 } else{
307                                         assertTrue("Contains informational artifact which not in provided list", false);
308                                 }
309                         });
310                 }
311         }
312         
313         private void validateDeploymentArtifactOnComponetInstance(ComponentInstance instacne, Map<String, List<String>> artifactsMap, String endswith){
314                 if(instacne.getToscaComponentName().endsWith(endswith) ){
315                         Set<String> types = artifactsMap.keySet();
316
317                         Map<String, List<ArtifactDefinition>> collect = instacne.getDeploymentArtifacts().values().stream()
318                                         .filter( a -> types.contains(a.getArtifactType()))
319                                         .collect(Collectors.groupingBy( e -> e.getArtifactType()));
320                 
321                         types.forEach(m -> {
322                                 if(collect.containsKey(m)){
323                                         List<String> found = collect.get(m).stream().map(e -> e.getArtifactName()).collect(Collectors.toList());
324                                         boolean isValid = found.containsAll(artifactsMap.get(m)) && artifactsMap.get(m).containsAll(found);
325                                         assertTrue("Not contain all artifact of type: " + m, isValid);
326                                 } else{
327                                         assertTrue("Contains deployment artifact which not in provided list", false);
328                                 }
329                         });
330                 }
331         }
332         
333         
334
335         
336         
337         
338         @Override
339         protected UserRoleEnum getRole() {
340                 return UserRoleEnum.DESIGNER;
341         }
342
343 }