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