2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.ci.tests.US;
23 import static org.testng.AssertJUnit.assertTrue;
25 import java.util.Arrays;
26 import java.util.HashMap;
27 import java.util.List;
30 import java.util.stream.Collectors;
31 import java.util.stream.Stream;
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;
50 public class ImportUpdateInformationalDeploymentArtifacts extends SetupCDTest {
52 private String folder ="US747946";
54 // US747946 - Import artifacts to component instances
55 // TC1407822 - Import VFC Artifacts - Deployment Artifacts - Multiple Artifacts, Multiple Types
57 public void importVfvArtifactsDeploymentArtifactsMultipleArtifactsMultipleTypes() throws Exception {
60 throw new SkipException("Open bug 197126");
63 String filePath = FileHandling.getFilePath(folder);
64 ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
66 String fileName = "TC1407822.csar";
68 ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, fileName, getUser());
70 Resource resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resourceMetaData.getName(), "0.1");
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());
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()))
88 .collect(Collectors.toList());
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));
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));
103 filteredArtifactNames.stream()
104 .map(e->e.getArtifactDisplayName())
105 .collect(Collectors.toList())
107 assertTrue("Wrong artifact appear on deployment artifact UI page.",
108 !GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.ArtifactPageEnum.UUID.getValue() + e));
115 // US747946 - Import artifacts to component instances
116 // TC1408044 - Import VFC Artifacts - Informational Artifacts on Single VFC
118 public void importVfcArtifactsInformationalArtifactsOnSingleVfc() throws Exception {
121 throw new SkipException("Open bug 197126");
124 String filePath = FileHandling.getFilePath(folder);
125 String fileName = "TC1408044.csar";
127 ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
129 ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, fileName, getUser());
131 Resource resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resourceMetaData.getName(), "0.1");
133 resource.getComponentInstances().forEach(e -> {
135 if(e.getToscaComponentName().endsWith("heat.ltm")) {
136 Map<String, List<String>> artifactsMap = new HashMap<String, List<String>>() {
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"));
143 validateInformationalArtifactOnComponetInstance(e, artifactsMap, "heat.ltm");
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
152 public void importVfcArtifactsDeploymentAndInformationalArtifactsMultipleVfcs() throws Exception {
155 throw new SkipException("Open bug 197126");
158 String filePath = FileHandling.getFilePath(folder);
159 String fileName = "TC1407998.csar";
161 ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
163 ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, fileName, getUser());
165 // resourceMetaData.setName("TC1407998");
166 Resource resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resourceMetaData.getName(), "0.1");
168 resource.getComponentInstances().forEach(e -> {
170 if(e.getToscaComponentName().endsWith("heat.ps")) {
171 Map<String, List<String>> deployArtifactsMap = new HashMap<String, List<String>>() {
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"));
177 validateDeploymentArtifactOnComponetInstance(e, deployArtifactsMap, "heat.ps");
179 Map<String, List<String>> infoArtifactsMap = new HashMap<String, List<String>>() {
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"));
185 validateInformationalArtifactOnComponetInstance(e, infoArtifactsMap, "heat.ps");
188 } else if (e.getToscaComponentName().endsWith("heat.sm")) {
189 Map<String, List<String>> deployArtifactsMap = new HashMap<String, List<String>>() {
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"));
195 validateDeploymentArtifactOnComponetInstance(e, deployArtifactsMap, "heat.sm");
197 Map<String, List<String>> infoArtifactsMap = new HashMap<String, List<String>>() {
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"));
203 validateInformationalArtifactOnComponetInstance(e, infoArtifactsMap, "heat.sm");
209 // US747946 - Import artifacts to component instances
210 // TC1410352 - Import VFC Artifacts - Deployment Artifacts - Extra folder Under VFC-Identification
212 public void importVfcArtifactsDeploymentArtifactsExtraFolderUnderVfcIdentification() throws Exception {
215 throw new SkipException("Open bug 197126");
218 String filePath = FileHandling.getFilePath(folder);
219 String fileName = "TC1410352.csar";
221 ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
223 ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, fileName, getUser());
225 // resourceMetaData.setName("TC1410352");
226 Resource resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resourceMetaData.getName(), "0.1");
228 resource.getComponentInstances().forEach(e -> {
230 if(e.getToscaComponentName().endsWith("heat.ltm")) {
231 Map<String, List<String>> deployArtifactsMap = new HashMap<String, List<String>>() {
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"));
237 validateDeploymentArtifactOnComponetInstance(e, deployArtifactsMap, "heat.ltm");
239 Map<String, List<String>> infoArtifactsMap = new HashMap<String, List<String>>() {
241 put(ArtifactTypeEnum.GUIDE.getType(), Arrays.asList("GUIDE1.yaml", "GUIDE2.xml"));
242 put(ArtifactTypeEnum.OTHER.getType(), Arrays.asList("OTHER1.yaml", "OTHER2.xml"));
245 validateInformationalArtifactOnComponetInstance(e, infoArtifactsMap, "heat.ltm");
251 // US747946 - Import artifacts to component instances
252 // TC1410352 - Import VFC Artifacts - Deployment Artifacts - Invalid Artifact Type
254 public void importVfcArtifactsDeploymentArtifactsInvalidArtifactType() throws Exception {
257 throw new SkipException("Open bug 197126");
260 String filePath = FileHandling.getFilePath(folder);
261 String fileName = "TC1425032.csar";
263 ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
265 ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, fileName, getUser());
267 // resourceMetaData.setName("TC1425032");
268 Resource resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resourceMetaData.getName(), "0.1");
270 resource.getComponentInstances().forEach(e -> {
272 if(e.getToscaComponentName().endsWith("heat.ltm")) {
273 Map<String, List<String>> deployArtifactsMap = new HashMap<String, List<String>>() {
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"));
279 validateDeploymentArtifactOnComponetInstance(e, deployArtifactsMap, "heat.ltm");
281 Map<String, List<String>> infoArtifactsMap = new HashMap<String, List<String>>() {
283 put(ArtifactTypeEnum.GUIDE.getType(), Arrays.asList("InfoGuide1.yaml", "InfoGuide2.xml"));
284 put(ArtifactTypeEnum.OTHER.getType(), Arrays.asList("InfoOther1.yaml", "InfoOther2.xml", "InfoInvalid1.yaml"));
287 validateInformationalArtifactOnComponetInstance(e, infoArtifactsMap, "heat.ltm");
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();
297 Map<String, List<ArtifactDefinition>> collect = instacne.getArtifacts().values().stream()
298 .filter( a -> types.contains(a.getArtifactType()))
299 .collect(Collectors.groupingBy( e -> e.getArtifactType()));
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);
307 assertTrue("Contains informational artifact which not in provided list", false);
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();
317 Map<String, List<ArtifactDefinition>> collect = instacne.getDeploymentArtifacts().values().stream()
318 .filter( a -> types.contains(a.getArtifactType()))
319 .collect(Collectors.groupingBy( e -> e.getArtifactType()));
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);
327 assertTrue("Contains deployment artifact which not in provided list", false);
339 protected UserRoleEnum getRole() {
340 return UserRoleEnum.DESIGNER;