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.TopMenuButtonsEnum;
34 import org.openecomp.sdc.ci.tests.datatypes.CanvasElement;
35 import org.openecomp.sdc.ci.tests.datatypes.CanvasManager;
36 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
37 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
38 import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
39 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
40 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
41 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
42 import org.openecomp.sdc.ci.tests.pages.CompositionPage;
43 import org.openecomp.sdc.ci.tests.pages.DeploymentArtifactPage;
44 import org.openecomp.sdc.ci.tests.pages.ResourceGeneralPage;
45 import org.openecomp.sdc.ci.tests.pages.UploadArtifactPopup;
46 import org.openecomp.sdc.ci.tests.utilities.ArtifactUIUtils;
47 import org.openecomp.sdc.ci.tests.utilities.FileHandling;
48 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
49 import org.openecomp.sdc.ci.tests.utilities.ResourceUIUtils;
50 import org.openecomp.sdc.ci.tests.utilities.ServiceUIUtils;
51 import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
52 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
53 import org.openecomp.sdc.ci.tests.utils.rest.ArtifactRestUtils;
54 import org.testng.Assert;
55 import org.testng.SkipException;
56 import org.testng.annotations.DataProvider;
57 import org.testng.annotations.Test;
60 public class MIBsArtifactsOnResourceInstance extends SetupCDTest {
62 private String folder ="";
64 @DataProvider(name="mibsArtifactCRUDUi")
65 public static Object[][] dataProviderMibsArtifactCRUDUi() {
66 return new Object[][] {
67 {"mibsvFW_VFC.yml", ResourceTypeEnum.VFC},
68 {"mibsVL.yml", ResourceTypeEnum.VL},
69 {"mibsCP.yml", ResourceTypeEnum.CP}
74 // Artifact UI CRUD on VFC/VL/CP
75 // TODO: Change download validation from download artifact via external API to UI
76 @Test(dataProvider="mibsArtifactCRUDUi")
77 public void mibsArtifactCRUDUi(String fileName, ResourceTypeEnum resourceTypeEnum) throws Exception {
78 setLog("mibsArtifactCRUDUi");
79 String filePath = FileHandling.getFilePath(folder);
82 throw new SkipException("Open bug 197101");
86 ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(resourceTypeEnum, getUser());
87 ResourceUIUtils.importVfc(resourceMetaData, filePath, fileName, getUser());
89 // get resourceUUID from BE
90 String resourceUUID = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resourceMetaData.getName(), "0.1").getUUID();
92 // 2. Upload MIBs artifacts - SNMP_TRAP & SNMP_POLL.
93 ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
95 List<ArtifactInfo> deploymentArtifactList = new ArrayList<ArtifactInfo>();
96 deploymentArtifactList.add(new ArtifactInfo(filePath, "asc_heat 0 2.yaml", "kuku", "artifact1", "SNMP_TRAP"));
97 deploymentArtifactList.add(new ArtifactInfo(filePath, "sample-xml-alldata-1-1.xml", "cuku", "artifact2", "SNMP_POLL"));
98 for (ArtifactInfo deploymentArtifact : deploymentArtifactList) {
99 DeploymentArtifactPage.clickAddNewArtifact();
100 ArtifactUIUtils.fillAndAddNewArtifactParameters(deploymentArtifact, new UploadArtifactPopup(true));
102 assertTrue("Only created artifact need to be exist", DeploymentArtifactPage.checkElementsCountInTable(1));
104 String artifactUUID = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.UUID.getValue() + deploymentArtifact.getArtifactLabel()).getText();
105 ArtifactUIUtils.validateExistArtifactOnDeploymentInformationPage(deploymentArtifact.getArtifactLabel(), null, "1", deploymentArtifact.getArtifactType(), true, true, true, false);
107 // Verify that uploaded correct file by download artifact via external api
108 RestResponse restResponse = ArtifactRestUtils.getResourceDeploymentArtifactExternalAPI(resourceUUID, artifactUUID, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER), ComponentTypeEnum.RESOURCE.toString());
109 File file = new File(deploymentArtifact.getFilepath() + deploymentArtifact.getFilename());
110 String readFileToString = FileUtils.readFileToString(file);
111 Assert.assertEquals(restResponse.getResponse(), readFileToString);
113 DeploymentArtifactPage.clickEditArtifact(deploymentArtifact.getArtifactLabel());
114 UploadArtifactPopup artifactPopup = new UploadArtifactPopup(true);
115 artifactPopup.loadFile(filePath, "CP.yml");
116 artifactPopup.clickDoneButton();
118 assertTrue("Only updated artifact need to be exist", DeploymentArtifactPage.checkElementsCountInTable(1));
119 Assert.assertNotEquals(GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.UUID.getValue() + deploymentArtifact.getArtifactLabel()).getText(), artifactUUID);
120 ArtifactUIUtils.validateExistArtifactOnDeploymentInformationPage(deploymentArtifact.getArtifactLabel(), null, "2", deploymentArtifact.getArtifactType(), true, true, true, false);
122 // Verify that updated correct file by download artifact via external api
123 artifactUUID = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.UUID.getValue() + deploymentArtifact.getArtifactLabel()).getText();
124 restResponse = ArtifactRestUtils.getResourceDeploymentArtifactExternalAPI(resourceUUID, artifactUUID, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER), ComponentTypeEnum.RESOURCE.toString());
125 file = new File(deploymentArtifact.getFilepath() + "CP.yml");
126 readFileToString = FileUtils.readFileToString(file);
127 Assert.assertEquals(restResponse.getResponse(), readFileToString);
129 DeploymentArtifactPage.clickDeleteArtifact(deploymentArtifact.getArtifactLabel());
130 DeploymentArtifactPage.clickOK();
132 assertTrue("No artifact need to be exist", DeploymentArtifactPage.checkElementsCountInTable(0));
137 @DataProvider(name="mibsArtifacsOnResourceInstanceShouldOnlyHaveDownloadOption")
138 public static Object[][] dataProviderMibsArtifacsOnResourceInstanceShouldOnlyHaveDownloadOption() {
139 return new Object[][] {
140 {"mibs1vFW_VFC.yml", ResourceTypeEnum.VFC},
141 // TODO: delete comment below when we will have support for VL on canvas
142 // {"mibs1VL.yml", ResourceTypeEnum.VL},
143 {"mibs1CP.yml", ResourceTypeEnum.CP}
148 // Import VFC/VL/CP, upload MIBs artifacts then drag it on VF & verify that deployment artifact have only download option
149 @Test(dataProvider="mibsArtifacsOnResourceInstanceShouldOnlyHaveDownloadOption")
150 public void mibsArtifacsOnResourceInstanceShouldOnlyHaveDownloadOption(String fileName, ResourceTypeEnum resourceTypeEnum) throws Exception {
152 setLog("mibsArtifacsOnResourceInstanceShouldOnlyHaveDownloadOption");
154 String filePath = FileHandling.getFilePath(folder);
157 ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(resourceTypeEnum, getUser());
158 ResourceUIUtils.importVfc(resourceMetaData, filePath, fileName, getUser());
160 // 2. Upload MIBs artifacts - SNMP_TRAP & SNMP_POLL.
161 ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
163 List<ArtifactInfo> deploymentArtifactList = new ArrayList<ArtifactInfo>();
164 deploymentArtifactList.add(new ArtifactInfo(filePath, "asc_heat 0 2.yaml", "kuku", "artifact1", "SNMP_TRAP"));
165 deploymentArtifactList.add(new ArtifactInfo(filePath, "sample-xml-alldata-1-1.xml", "cuku", "artifact2", "SNMP_POLL"));
166 for (ArtifactInfo deploymentArtifact : deploymentArtifactList) {
167 DeploymentArtifactPage.clickAddNewArtifact();
168 ArtifactUIUtils.fillAndAddNewArtifactParameters(deploymentArtifact, new UploadArtifactPopup(true));
170 assertTrue("artifact table does not contain artifacts uploaded", DeploymentArtifactPage.checkElementsCountInTable(deploymentArtifactList.size()));
172 // 3. Check-in DataProvider resource.
173 ResourceGeneralPage.clickCheckinButton(resourceMetaData.getName());
176 ResourceReqDetails vfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
177 ResourceUIUtils.createResource(vfMetaData, getUser());
179 // 5. Click on composition.
180 ResourceGeneralPage.getLeftMenu().moveToCompositionScreen();
182 // 6. Drag created DataProvider resource to canvas.
183 CanvasManager vfCanvasManager = CanvasManager.getCanvasManager();
184 CompositionPage.searchForElement(resourceMetaData.getName());
185 CanvasElement resourceInstance = vfCanvasManager.createElementOnCanvas(resourceMetaData.getName());
187 // 7. Click on DataProvider resource.
188 vfCanvasManager.clickOnCanvaElement(resourceInstance);
190 // 8. Click on deployment artifacts in right menu.
191 CompositionPage.showDeploymentArtifactTab();
193 // 9. Verify that each uploaded MIBs artifacts shows in deployment artifacts.
194 // 10. Verify that only have download option.
195 for (ArtifactInfo deploymentArtifact : deploymentArtifactList) {
196 // Hover over webelement -> check that only dowload button displayed
197 GeneralUIUtils.hoverOnAreaByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_DISPLAY_NAME.getValue() + deploymentArtifact.getArtifactLabel());
198 Assert.assertEquals(GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.DOWNLOAD.getValue() + deploymentArtifact.getArtifactLabel()).isDisplayed(), true);
199 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.DELETE.getValue() + deploymentArtifact.getArtifactLabel()), false);
200 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_DISPLAY_NAME.getValue() + deploymentArtifact.getArtifactLabel());
201 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.ArtifactPopup.MODAL_WINDOW.getValue()), false);
208 // Create VF, upload MIBs artifacts then drag it on service & verify that deployment artifact have only download option
210 public void mibsArtifacsOnVFInstanceShouldOnlyHaveDownloadOption() throws Exception {
211 String filePath = FileHandling.getFilePath(folder);
214 ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
215 ResourceUIUtils.createResource(resourceMetaData, getUser());
217 // 2. Upload MIBs artifacts - SNMP_TRAP & SNMP_POLL.
218 ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
220 List<ArtifactInfo> deploymentArtifactList = new ArrayList<ArtifactInfo>();
221 deploymentArtifactList.add(new ArtifactInfo(filePath, "asc_heat 0 2.yaml", "kuku", "artifact1", "SNMP_TRAP"));
222 deploymentArtifactList.add(new ArtifactInfo(filePath, "sample-xml-alldata-1-1.xml", "cuku", "artifact2", "SNMP_POLL"));
223 for (ArtifactInfo deploymentArtifact : deploymentArtifactList) {
224 DeploymentArtifactPage.clickAddNewArtifact();
225 ArtifactUIUtils.fillAndAddNewArtifactParameters(deploymentArtifact, new UploadArtifactPopup(true));
227 assertTrue("artifact table does not contain artifacts uploaded", DeploymentArtifactPage.checkElementsCountInTable(deploymentArtifactList.size()));
230 ResourceGeneralPage.clickCheckinButton(resourceMetaData.getName());
232 // 4. Create service.
233 ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
234 ServiceUIUtils.createService(serviceMetadata, getUser());
236 // 5. Click on composition.
237 ResourceGeneralPage.getLeftMenu().moveToCompositionScreen();
239 // 6. Drag created DataProvider s to canvas.
240 CanvasManager canvasManager = CanvasManager.getCanvasManager();
241 CompositionPage.searchForElement(resourceMetaData.getName());
242 CanvasElement resourceInstance = canvasManager.createElementOnCanvas(resourceMetaData.getName());
244 // 7. Click on DataProvider resource.
245 canvasManager.clickOnCanvaElement(resourceInstance);
247 // 8. Click on deployment artifacts in right menu.
248 CompositionPage.showDeploymentArtifactTab();
250 // 9. Verify that each uploaded MIBs artifacts shows in deployment artifacts.
251 // 10. Verify that only have download option.
252 for (ArtifactInfo deploymentArtifact : deploymentArtifactList) {
253 // Hover over webelement -> check that only dowload button displayed
254 GeneralUIUtils.hoverOnAreaByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_DISPLAY_NAME.getValue() + deploymentArtifact.getArtifactLabel());
255 Assert.assertEquals(GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.DOWNLOAD.getValue() + deploymentArtifact.getArtifactLabel()).isDisplayed(), true);
256 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.DELETE.getValue() + deploymentArtifact.getArtifactLabel()), false);
257 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_DISPLAY_NAME.getValue() + deploymentArtifact.getArtifactLabel());
258 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.ArtifactPopup.MODAL_WINDOW.getValue()), false);
265 protected UserRoleEnum getRole() {
266 return UserRoleEnum.DESIGNER;