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