re base code
[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 org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
24 import org.openecomp.sdc.be.model.ArtifactDefinition;
25 import org.openecomp.sdc.be.model.ComponentInstance;
26 import org.openecomp.sdc.be.model.Resource;
27 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
28 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
29 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
30 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
31 import org.openecomp.sdc.ci.tests.utilities.FileHandling;
32 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
33 import org.openecomp.sdc.ci.tests.utilities.ResourceUIUtils;
34 import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
35 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
36 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
37 import org.testng.annotations.Test;
38
39 import java.util.*;
40 import java.util.stream.Collectors;
41 import java.util.stream.Stream;
42
43 import static org.testng.AssertJUnit.assertTrue;
44
45 public class ImportUpdateInformationalDeploymentArtifacts extends SetupCDTest {
46         
47         private String folder ="US747946";
48
49         // US747946 - Import artifacts to component instances
50         // TC1407822 -  Import VFC Artifacts - Deployment Artifacts - Multiple Artifacts, Multiple Types
51         @Test
52         public void importVfvArtifactsDeploymentArtifactsMultipleArtifactsMultipleTypes() throws Exception {
53                 
54                 String filePath = FileHandling.getFilePath(folder);
55                 ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
56                 
57                 String fileName = "TC1407822.csar";
58                 
59                 ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, fileName, getUser());
60                 
61                 Resource resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resourceMetaData.getName(), "0.1");
62                 
63                 List<String> snmpPollArtifactList = Stream
64                                 .of("base_cgi_frwl.mib", "base_vIECCF_volume.yml", "node_userdata_script.sh", "vendor-license-model.xml")
65                                 .collect(Collectors.toList());
66                 List<String> snmpTrapArtifactList = Stream
67                                 .of("module_1_ixlt.mib", "module_1_ixlt.yaml")
68                                 .collect(Collectors.toList());
69                 
70         
71                 List<ArtifactDefinition> filteredArtifactNames = 
72                                 //Stream of component Instances
73                                 resource.getComponentInstances().stream()
74                                         //filter out all nulls
75                                         .filter( e -> e.getDeploymentArtifacts() != null )
76                                         //Stream of all the artifacts on all the component instances
77                                         .flatMap( e -> e.getDeploymentArtifacts().values().stream())
78                                         //filter relevant artifact types
79                                         .filter( e -> e.getArtifactType().equals(ArtifactTypeEnum.SNMP_TRAP.getType()) || e.getArtifactType().equals(ArtifactTypeEnum.SNMP_POLL.getType()))
80                                         //collect to list
81                                         .collect(Collectors.toList());
82
83                 assertTrue("Not contain all SNMP TRAP artifacts.", filteredArtifactNames.stream()
84                                 .filter(e -> e.getArtifactType().equals(ArtifactTypeEnum.SNMP_TRAP.getType()))
85                                 .map(e -> e.getArtifactName())
86                                 .collect(Collectors.toList())
87                                 .containsAll(snmpTrapArtifactList));
88                 
89                 assertTrue("Not contain all SNMP POLL artifacts.", filteredArtifactNames.stream()
90                                 .filter(e -> e.getArtifactType().equals(ArtifactTypeEnum.SNMP_POLL.getType()))
91                                 .map(e -> e.getArtifactName())
92                                 .collect(Collectors.toList())
93                                 .containsAll(snmpPollArtifactList));
94                 
95                 filteredArtifactNames.stream()
96                         .map(e->e.getArtifactDisplayName())
97                         .collect(Collectors.toList())
98                         .forEach(e -> {
99                                 assertTrue("Wrong artifact appear on deployment artifact UI page.", 
100                                                 !GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.ArtifactPageEnum.UUID.getValue() + e));
101                         });
102                 
103         }
104
105         // TODO: Note there is performance issue with this CSAR
106         // US747946 - Import artifacts to component instances
107         // TC1407998 - Import VFC Artifacts - Deployment & Informational Artifacts - Multiple VFCs
108         @Test
109         public void importVfcArtifactsDeploymentAndInformationalArtifactsMultipleVfcs() throws Exception {
110                 
111                 String filePath = FileHandling.getFilePath(folder);
112                 String fileName = "TC1407998.csar";
113                         
114                 ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
115                         
116                 ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, fileName, getUser());
117                 Resource resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resourceMetaData.getName(), "0.1");
118                         
119                 resource.getComponentInstances().forEach(e -> {
120                                 
121                         if(e.getToscaComponentName().endsWith("heat.cm")) {
122                                 Map<String, List<String>> deployArtifactsMap = new HashMap<String, List<String>>() {
123                                         {
124                                                 put(ArtifactTypeEnum.SNMP_POLL.getType(), Arrays.asList("PS_DEPL_Poll1.mib", "PS_DEPL_Poll2.xml", "PS_DEPL_Poll3.yaml"));
125                                                 put(ArtifactTypeEnum.SNMP_TRAP.getType(), Arrays.asList("PS_DEPL_Trap1.mib", "PS_DEPL_Trap2.xml", "PS_DEPL_Trap3.sh", "PS_DEPL_Trap4.yml"));
126                                         }
127                                 };
128                                 validateDeploymentArtifactOnComponetInstance(e, deployArtifactsMap, "heat.cm");
129                                 
130                         } else if (e.getToscaComponentName().endsWith("heat.sm")) {
131                                 Map<String, List<String>> deployArtifactsMap = new HashMap<String, List<String>>() {
132                                         {
133                                                 put(ArtifactTypeEnum.SNMP_POLL.getType(), Arrays.asList("SM_DEPL_Poll1.mib", "SM_DEPL_Poll2.mib", "SM_DEPL_Poll3.xml"));
134                                                 put(ArtifactTypeEnum.SNMP_TRAP.getType(), Arrays.asList("SM_DEPL_Trap1.mib", "SM_DEPL_Trap2.xml"));
135                                         }
136                                 };
137                                 validateDeploymentArtifactOnComponetInstance(e, deployArtifactsMap, "heat.sm");
138                         }
139                 });
140                         
141         }
142         
143         // US747946 - Import artifacts to component instances
144         // TC1410352 - Import VFC Artifacts - Deployment Artifacts - Extra folder Under VFC-Identification
145         @Test
146         public void importVfcArtifactsDeploymentArtifactsExtraFolderUnderVfcIdentification() throws Exception {
147                 
148                 String filePath = FileHandling.getFilePath(folder);
149                 String fileName = "TC1410352.csar";
150                         
151                 ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
152                         
153                 ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, fileName, getUser());
154                 Resource resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resourceMetaData.getName(), "0.1");
155                         
156                 resource.getComponentInstances().forEach(e -> {
157                                 
158                         if(e.getToscaComponentName().endsWith("heat.ltm")) {
159                                 Map<String, List<String>> deployArtifactsMap = new HashMap<String, List<String>>() {
160                                         {
161                                                 put(ArtifactTypeEnum.SNMP_POLL.getType(), Arrays.asList("Poll1.mib", "Poll2.xml", "Poll3.sh", "Poll4.yml"));
162                                                 put(ArtifactTypeEnum.SNMP_TRAP.getType(), Arrays.asList("Trap1.mib", "Trap2.yaml"));
163                                         }
164                                 };
165                                 validateDeploymentArtifactOnComponetInstance(e, deployArtifactsMap, "heat.ltm");
166                         }
167                 });
168         }
169         
170         
171         // US747946 - Import artifacts to component instances
172         // TC1410352 - Import VFC Artifacts - Deployment Artifacts - Invalid Artifact Type
173         @Test
174         public void importVfcArtifactsDeploymentArtifactsInvalidArtifactType() throws Exception {
175                 
176                 String filePath = FileHandling.getFilePath(folder);
177                 String fileName = "TC1425032.csar";
178                                 
179                 ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
180                                 
181                 ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, fileName, getUser());
182                 Resource resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resourceMetaData.getName(), "0.1");
183                                 
184                 resource.getComponentInstances().forEach(e -> {
185                                         
186                         if(e.getToscaComponentName().endsWith("heat.ltm")) {
187                                 Map<String, List<String>> deployArtifactsMap = new HashMap<String, List<String>>() {
188                                         {
189                                                 put(ArtifactTypeEnum.SNMP_POLL.getType(), Arrays.asList("DeploySNMPPoll1.mib", "DeploySNMPPoll2.yml", "DeploySNMPPoll3.sh", "DeploySNMPPoll4.xml"));
190                                                 put(ArtifactTypeEnum.OTHER.getType(), Arrays.asList("DeploySNMPTrapB1.mib", "DeploySNMPTrapB2.yaml"));
191                                         }
192                                 };
193                                 validateDeploymentArtifactOnComponetInstance(e, deployArtifactsMap, "heat.ltm");
194                         }
195                 });
196         }
197
198         private void validateDeploymentArtifactOnComponetInstance(ComponentInstance instance, Map<String, List<String>> artifactsMap, String endswith){
199                 if(instance.getToscaComponentName().endsWith(endswith) ){
200                         Set<String> types = artifactsMap.keySet();
201
202                         Map<String, List<ArtifactDefinition>> collect = instance.getDeploymentArtifacts().values().stream()
203                                         .filter( a -> types.contains(a.getArtifactType()))
204                                         .collect(Collectors.groupingBy( e -> e.getArtifactType()));
205                 
206                         types.forEach(m -> {
207                                 if(collect.containsKey(m)){
208                                         List<String> found = collect.get(m).stream().map(e -> e.getArtifactName()).collect(Collectors.toList());
209                                         boolean isValid = found.containsAll(artifactsMap.get(m)) && artifactsMap.get(m).containsAll(found);
210                                         assertTrue("Not contain all artifact of type: " + m, isValid);
211                                 } else{
212                                         assertTrue("Contains deployment artifact which not in provided list", false);
213                                 }
214                         });
215                 }
216         }
217         
218         @Override
219         protected UserRoleEnum getRole() {
220                 return UserRoleEnum.DESIGNER;
221         }
222
223 }