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.annotations.Test;
49 public class ImportUpdateInformationalDeploymentArtifacts extends SetupCDTest {
51 private String folder ="US747946";
53 // US747946 - Import artifacts to component instances
54 // TC1407822 - Import VFC Artifacts - Deployment Artifacts - Multiple Artifacts, Multiple Types
56 public void importVfvArtifactsDeploymentArtifactsMultipleArtifactsMultipleTypes() throws Exception {
58 String filePath = FileHandling.getFilePath(folder);
59 ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
61 String fileName = "TC1407822.csar";
63 ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, fileName, getUser());
65 Resource resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resourceMetaData.getName(), "0.1");
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());
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()))
85 .collect(Collectors.toList());
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));
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));
99 filteredArtifactNames.stream()
100 .map(e->e.getArtifactDisplayName())
101 .collect(Collectors.toList())
103 assertTrue("Wrong artifact appear on deployment artifact UI page.",
104 !GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.ArtifactPageEnum.UUID.getValue() + e));
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
113 public void importVfcArtifactsDeploymentAndInformationalArtifactsMultipleVfcs() throws Exception {
115 String filePath = FileHandling.getFilePath(folder);
116 String fileName = "TC1407998.csar";
118 ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
120 ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, fileName, getUser());
121 Resource resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resourceMetaData.getName(), "0.1");
123 resource.getComponentInstances().forEach(e -> {
125 if(e.getToscaComponentName().endsWith("heat.cm")) {
126 Map<String, List<String>> deployArtifactsMap = new HashMap<String, List<String>>() {
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"));
132 validateDeploymentArtifactOnComponetInstance(e, deployArtifactsMap, "heat.cm");
134 } else if (e.getToscaComponentName().endsWith("heat.sm")) {
135 Map<String, List<String>> deployArtifactsMap = new HashMap<String, List<String>>() {
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"));
141 validateDeploymentArtifactOnComponetInstance(e, deployArtifactsMap, "heat.sm");
147 // US747946 - Import artifacts to component instances
148 // TC1410352 - Import VFC Artifacts - Deployment Artifacts - Extra folder Under VFC-Identification
150 public void importVfcArtifactsDeploymentArtifactsExtraFolderUnderVfcIdentification() throws Exception {
152 String filePath = FileHandling.getFilePath(folder);
153 String fileName = "TC1410352.csar";
155 ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
157 ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, fileName, getUser());
158 Resource resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resourceMetaData.getName(), "0.1");
160 resource.getComponentInstances().forEach(e -> {
162 if(e.getToscaComponentName().endsWith("heat.ltm")) {
163 Map<String, List<String>> deployArtifactsMap = new HashMap<String, List<String>>() {
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"));
169 validateDeploymentArtifactOnComponetInstance(e, deployArtifactsMap, "heat.ltm");
175 // US747946 - Import artifacts to component instances
176 // TC1410352 - Import VFC Artifacts - Deployment Artifacts - Invalid Artifact Type
178 public void importVfcArtifactsDeploymentArtifactsInvalidArtifactType() throws Exception {
180 String filePath = FileHandling.getFilePath(folder);
181 String fileName = "TC1425032.csar";
183 ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
185 ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, fileName, getUser());
186 Resource resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resourceMetaData.getName(), "0.1");
188 resource.getComponentInstances().forEach(e -> {
190 if(e.getToscaComponentName().endsWith("heat.ltm")) {
191 Map<String, List<String>> deployArtifactsMap = new HashMap<String, List<String>>() {
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"));
197 validateDeploymentArtifactOnComponetInstance(e, deployArtifactsMap, "heat.ltm");
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();
206 Map<String, List<ArtifactDefinition>> collect = instance.getDeploymentArtifacts().values().stream()
207 .filter( a -> types.contains(a.getArtifactType()))
208 .collect(Collectors.groupingBy( e -> e.getArtifactType()));
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);
216 assertTrue("Contains deployment artifact which not in provided list", false);
223 protected UserRoleEnum getRole() {
224 return UserRoleEnum.DESIGNER;