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 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;
40 import java.util.stream.Collectors;
41 import java.util.stream.Stream;
43 import static org.testng.AssertJUnit.assertTrue;
45 public class ImportUpdateInformationalDeploymentArtifacts extends SetupCDTest {
47 private String folder ="US747946";
49 // US747946 - Import artifacts to component instances
50 // TC1407822 - Import VFC Artifacts - Deployment Artifacts - Multiple Artifacts, Multiple Types
52 public void importVfvArtifactsDeploymentArtifactsMultipleArtifactsMultipleTypes() throws Exception {
54 String filePath = FileHandling.getFilePath(folder);
55 ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
57 String fileName = "TC1407822.csar";
59 ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, fileName, getUser());
61 Resource resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resourceMetaData.getName(), "0.1");
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());
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()))
81 .collect(Collectors.toList());
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));
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));
95 filteredArtifactNames.stream()
96 .map(e->e.getArtifactDisplayName())
97 .collect(Collectors.toList())
99 assertTrue("Wrong artifact appear on deployment artifact UI page.",
100 !GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.ArtifactPageEnum.UUID.getValue() + e));
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
109 public void importVfcArtifactsDeploymentAndInformationalArtifactsMultipleVfcs() throws Exception {
111 String filePath = FileHandling.getFilePath(folder);
112 String fileName = "TC1407998.csar";
114 ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
116 ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, fileName, getUser());
117 Resource resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resourceMetaData.getName(), "0.1");
119 resource.getComponentInstances().forEach(e -> {
121 if(e.getToscaComponentName().endsWith("heat.cm")) {
122 Map<String, List<String>> deployArtifactsMap = new HashMap<String, List<String>>() {
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"));
128 validateDeploymentArtifactOnComponetInstance(e, deployArtifactsMap, "heat.cm");
130 } else if (e.getToscaComponentName().endsWith("heat.sm")) {
131 Map<String, List<String>> deployArtifactsMap = new HashMap<String, List<String>>() {
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"));
137 validateDeploymentArtifactOnComponetInstance(e, deployArtifactsMap, "heat.sm");
143 // US747946 - Import artifacts to component instances
144 // TC1410352 - Import VFC Artifacts - Deployment Artifacts - Extra folder Under VFC-Identification
146 public void importVfcArtifactsDeploymentArtifactsExtraFolderUnderVfcIdentification() throws Exception {
148 String filePath = FileHandling.getFilePath(folder);
149 String fileName = "TC1410352.csar";
151 ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
153 ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, fileName, getUser());
154 Resource resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resourceMetaData.getName(), "0.1");
156 resource.getComponentInstances().forEach(e -> {
158 if(e.getToscaComponentName().endsWith("heat.ltm")) {
159 Map<String, List<String>> deployArtifactsMap = new HashMap<String, List<String>>() {
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"));
165 validateDeploymentArtifactOnComponetInstance(e, deployArtifactsMap, "heat.ltm");
171 // US747946 - Import artifacts to component instances
172 // TC1410352 - Import VFC Artifacts - Deployment Artifacts - Invalid Artifact Type
174 public void importVfcArtifactsDeploymentArtifactsInvalidArtifactType() throws Exception {
176 String filePath = FileHandling.getFilePath(folder);
177 String fileName = "TC1425032.csar";
179 ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
181 ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, fileName, getUser());
182 Resource resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resourceMetaData.getName(), "0.1");
184 resource.getComponentInstances().forEach(e -> {
186 if(e.getToscaComponentName().endsWith("heat.ltm")) {
187 Map<String, List<String>> deployArtifactsMap = new HashMap<String, List<String>>() {
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"));
193 validateDeploymentArtifactOnComponetInstance(e, deployArtifactsMap, "heat.ltm");
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();
202 Map<String, List<ArtifactDefinition>> collect = instance.getDeploymentArtifacts().values().stream()
203 .filter( a -> types.contains(a.getArtifactType()))
204 .collect(Collectors.groupingBy( e -> e.getArtifactType()));
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);
212 assertTrue("Contains deployment artifact which not in provided list", false);
219 protected UserRoleEnum getRole() {
220 return UserRoleEnum.DESIGNER;