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;
26 import java.util.ArrayList;
27 import java.util.List;
29 import org.apache.commons.io.FileUtils;
30 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
31 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
32 import org.openecomp.sdc.ci.tests.datatypes.ArtifactInfo;
33 import org.openecomp.sdc.ci.tests.datatypes.CanvasElement;
34 import org.openecomp.sdc.ci.tests.datatypes.CanvasManager;
35 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
36 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
37 import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
38 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
39 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
40 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
41 import org.openecomp.sdc.ci.tests.pages.CompositionPage;
42 import org.openecomp.sdc.ci.tests.pages.DeploymentArtifactPage;
43 import org.openecomp.sdc.ci.tests.pages.ResourceGeneralPage;
44 import org.openecomp.sdc.ci.tests.pages.UploadArtifactPopup;
45 import org.openecomp.sdc.ci.tests.utilities.ArtifactUIUtils;
46 import org.openecomp.sdc.ci.tests.utilities.FileHandling;
47 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
48 import org.openecomp.sdc.ci.tests.utilities.ResourceUIUtils;
49 import org.openecomp.sdc.ci.tests.utilities.ServiceUIUtils;
50 import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
51 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
52 import org.openecomp.sdc.ci.tests.utils.rest.ArtifactRestUtils;
53 import org.testng.Assert;
54 import org.testng.annotations.DataProvider;
55 import org.testng.annotations.Test;
58 public class MIBsArtifactsOnResourceInstance extends SetupCDTest {
60 private String folder ="";
62 @DataProvider(name="mibsArtifactCRUDUi")
63 public static Object[][] dataProviderMibsArtifactCRUDUi() {
64 return new Object[][] {
65 {"mibsvFW_VFC.yml", ResourceTypeEnum.VFC},
66 {"mibsVL.yml", ResourceTypeEnum.VL},
67 {"mibsCP.yml", ResourceTypeEnum.CP}
72 // Artifact UI CRUD on VFC/VL/CP
73 // TODO: Change download validation from download artifact via external API to UI
74 @Test(dataProvider="mibsArtifactCRUDUi")
75 public void mibsArtifactCRUDUi(String fileName, ResourceTypeEnum resourceTypeEnum) throws Exception {
77 String filePath = FileHandling.getFilePath(folder);
80 ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(resourceTypeEnum, getUser());
81 ResourceUIUtils.importVfc(resourceMetaData, filePath, fileName, getUser());
83 // get resourceUUID from BE
84 String resourceUUID = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resourceMetaData.getName(), "0.1").getUUID();
86 // 2. Upload MIBs artifacts - SNMP_TRAP & SNMP_POLL.
87 ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
89 List<ArtifactInfo> deploymentArtifactList = new ArrayList<>();
90 deploymentArtifactList.add(new ArtifactInfo(filePath, "asc_heat 0 2.yaml", "kuku", "artifact1", "SNMP_TRAP"));
91 deploymentArtifactList.add(new ArtifactInfo(filePath, "sample-xml-alldata-1-1.xml", "cuku", "artifact2", "SNMP_POLL"));
92 for (ArtifactInfo deploymentArtifact : deploymentArtifactList) {
93 DeploymentArtifactPage.clickAddNewArtifact();
94 ArtifactUIUtils.fillAndAddNewArtifactParameters(deploymentArtifact, new UploadArtifactPopup(true));
96 assertTrue("Only created artifact need to be exist", DeploymentArtifactPage.checkElementsCountInTable(1));
98 String artifactUUID = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.UUID.getValue() + deploymentArtifact.getArtifactLabel()).getText();
99 ArtifactUIUtils.validateExistArtifactOnDeploymentInformationPage(deploymentArtifact.getArtifactLabel(), null, "1", deploymentArtifact.getArtifactType(), true, true, true, false);
101 // Verify that uploaded correct file by download artifact via external api
102 RestResponse restResponse = ArtifactRestUtils.getResourceDeploymentArtifactExternalAPI(resourceUUID, artifactUUID, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER), ComponentTypeEnum.RESOURCE.toString());
103 File file = new File(deploymentArtifact.getFilepath() + deploymentArtifact.getFilename());
105 String readFileToString = FileUtils.readFileToString(file);
106 Assert.assertEquals(restResponse.getResponse(), readFileToString);
108 DeploymentArtifactPage.clickEditArtifact(deploymentArtifact.getArtifactLabel());
109 UploadArtifactPopup artifactPopup = new UploadArtifactPopup(true);
110 artifactPopup.loadFile(filePath, "CP.yml");
111 artifactPopup.clickDoneButton();
113 assertTrue("Only updated artifact need to be exist", DeploymentArtifactPage.checkElementsCountInTable(1));
114 Assert.assertNotEquals(GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.UUID.getValue() + deploymentArtifact.getArtifactLabel()).getText(), artifactUUID);
115 ArtifactUIUtils.validateExistArtifactOnDeploymentInformationPage(deploymentArtifact.getArtifactLabel(), null, "2", deploymentArtifact.getArtifactType(), true, true, true, false);
117 // Verify that updated correct file by download artifact via external api
118 artifactUUID = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.UUID.getValue() + deploymentArtifact.getArtifactLabel()).getText();
119 restResponse = ArtifactRestUtils.getResourceDeploymentArtifactExternalAPI(resourceUUID, artifactUUID, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER), ComponentTypeEnum.RESOURCE.toString());
120 file = new File(deploymentArtifact.getFilepath() + "CP.yml");
121 readFileToString = FileUtils.readFileToString(file);
122 Assert.assertEquals(restResponse.getResponse(), readFileToString);
124 DeploymentArtifactPage.clickDeleteArtifact(deploymentArtifact.getArtifactLabel());
125 DeploymentArtifactPage.clickOK();
127 assertTrue("No artifact need to be exist", DeploymentArtifactPage.checkElementsCountInTable(0));
132 @DataProvider(name="mibsArtifacsOnResourceInstanceShouldOnlyHaveDownloadOption")
133 public static Object[][] dataProviderMibsArtifacsOnResourceInstanceShouldOnlyHaveDownloadOption() {
134 return new Object[][] {
135 // {"mibs1vFW_VFC.yml", ResourceTypeEnum.VFC},
136 // TODO: delete comment below when we will have support for VL on canvas
137 // {"mibs1VL.yml", ResourceTypeEnum.VL},
138 {"mibs1CP.yml", ResourceTypeEnum.CP}
143 // Import VFC/VL/CP, upload MIBs artifacts then drag it on VF & verify that deployment artifact have only download option
144 @Test(dataProvider="mibsArtifacsOnResourceInstanceShouldOnlyHaveDownloadOption")
145 public void mibsArtifacsOnResourceInstanceShouldOnlyHaveDownloadOption(String fileName, ResourceTypeEnum resourceTypeEnum) throws Exception {
147 // if(resourceTypeEnum.equals(ResourceTypeEnum.CP)){
148 // throw new SkipException("Open bug 322930");
153 String filePath = FileHandling.getFilePath(folder);
156 ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(resourceTypeEnum, getUser());
157 ResourceUIUtils.importVfc(resourceMetaData, filePath, fileName, getUser());
159 // 2. Upload MIBs artifacts - SNMP_TRAP & SNMP_POLL.
160 ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
162 List<ArtifactInfo> deploymentArtifactList = new ArrayList<ArtifactInfo>();
163 deploymentArtifactList.add(new ArtifactInfo(filePath, "asc_heat 0 2.yaml", "kuku", "artifact1", "SNMP_TRAP"));
164 deploymentArtifactList.add(new ArtifactInfo(filePath, "sample-xml-alldata-1-1.xml", "cuku", "artifact2", "SNMP_POLL"));
165 for (ArtifactInfo deploymentArtifact : deploymentArtifactList) {
166 DeploymentArtifactPage.clickAddNewArtifact();
167 ArtifactUIUtils.fillAndAddNewArtifactParameters(deploymentArtifact, new UploadArtifactPopup(true));
169 assertTrue("artifact table does not contain artifacts uploaded", DeploymentArtifactPage.checkElementsCountInTable(deploymentArtifactList.size()));
171 // 3. Check-in DataProvider resource.
172 ResourceGeneralPage.clickCheckinButton(resourceMetaData.getName());
175 ResourceReqDetails vfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
176 ResourceUIUtils.createVF(vfMetaData, getUser());
178 // 5. Click on composition.
179 ResourceGeneralPage.getLeftMenu().moveToCompositionScreen();
181 // 6. Drag created DataProvider resource to canvas.
182 CanvasManager vfCanvasManager = CanvasManager.getCanvasManager();
183 CompositionPage.searchForElement(resourceMetaData.getName());
184 CanvasElement resourceInstance = vfCanvasManager.createElementOnCanvas(resourceMetaData.getName());
186 // 7. Click on DataProvider resource.
187 vfCanvasManager.clickOnCanvaElement(resourceInstance);
189 // 8. Click on deployment artifacts in right menu.
190 CompositionPage.showDeploymentArtifactTab();
192 // 9. Verify that each uploaded MIBs artifacts shows in deployment artifacts.
193 // 10. Verify that only have download option.
194 for (ArtifactInfo deploymentArtifact : deploymentArtifactList) {
195 // Hover over webelement -> check that only dowload button displayed
196 GeneralUIUtils.hoverOnAreaByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_DISPLAY_NAME.getValue() + deploymentArtifact.getArtifactLabel());
197 Assert.assertEquals(GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.DOWNLOAD.getValue() + deploymentArtifact.getArtifactLabel()).isDisplayed(), true);
198 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.DELETE.getValue() + deploymentArtifact.getArtifactLabel()), false);
199 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_DISPLAY_NAME.getValue() + deploymentArtifact.getArtifactLabel());
200 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.ArtifactPopup.MODAL_WINDOW.getValue()), false);
207 // Create VF, upload MIBs artifacts then drag it on service & verify that deployment artifact have only download option
209 public void mibsArtifacsOnVFInstanceShouldOnlyHaveDownloadOption() throws Exception {
210 String filePath = FileHandling.getFilePath(folder);
213 ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
214 ResourceUIUtils.createVF(resourceMetaData, getUser());
216 // 2. Upload MIBs artifacts - SNMP_TRAP & SNMP_POLL.
217 ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
219 List<ArtifactInfo> deploymentArtifactList = new ArrayList<ArtifactInfo>();
220 deploymentArtifactList.add(new ArtifactInfo(filePath, "asc_heat 0 2.yaml", "kuku", "artifact1", "SNMP_TRAP"));
221 deploymentArtifactList.add(new ArtifactInfo(filePath, "sample-xml-alldata-1-1.xml", "cuku", "artifact2", "SNMP_POLL"));
222 for (ArtifactInfo deploymentArtifact : deploymentArtifactList) {
223 DeploymentArtifactPage.clickAddNewArtifact();
224 ArtifactUIUtils.fillAndAddNewArtifactParameters(deploymentArtifact, new UploadArtifactPopup(true));
226 assertTrue("artifact table does not contain artifacts uploaded", DeploymentArtifactPage.checkElementsCountInTable(deploymentArtifactList.size()));
229 ResourceGeneralPage.clickCheckinButton(resourceMetaData.getName());
231 // 4. Create service.
232 ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
233 ServiceUIUtils.createService(serviceMetadata, getUser());
235 // 5. Click on composition.
236 ResourceGeneralPage.getLeftMenu().moveToCompositionScreen();
238 // 6. Drag created DataProvider s to canvas.
239 CanvasManager canvasManager = CanvasManager.getCanvasManager();
240 CompositionPage.searchForElement(resourceMetaData.getName());
241 CanvasElement resourceInstance = canvasManager.createElementOnCanvas(resourceMetaData.getName());
243 // 7. Click on DataProvider resource.
244 canvasManager.clickOnCanvaElement(resourceInstance);
246 // 8. Click on deployment artifacts in right menu.
247 CompositionPage.showDeploymentArtifactTab();
249 // 9. Verify that each uploaded MIBs artifacts shows in deployment artifacts.
250 // 10. Verify that only have download option.
251 for (ArtifactInfo deploymentArtifact : deploymentArtifactList) {
252 // Hover over webelement -> check that only dowload button displayed
253 GeneralUIUtils.hoverOnAreaByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_DISPLAY_NAME.getValue() + deploymentArtifact.getArtifactLabel());
254 Assert.assertEquals(GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.DOWNLOAD.getValue() + deploymentArtifact.getArtifactLabel()).isDisplayed(), true);
255 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.DELETE.getValue() + deploymentArtifact.getArtifactLabel()), false);
256 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_DISPLAY_NAME.getValue() + deploymentArtifact.getArtifactLabel());
257 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.ArtifactPopup.MODAL_WINDOW.getValue()), false);
264 protected UserRoleEnum getRole() {
265 return UserRoleEnum.DESIGNER;