Sync Integ to Master
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / execute / sanity / OnboardingFlowsUI.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.execute.sanity;
22
23 import com.aventstack.extentreports.Status;
24 import com.clearspring.analytics.util.Pair;
25 import org.openecomp.sdc.ci.tests.dataProvider.OnbordingDataProviders;
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.execute.setup.ArtifactsCorrelationManager;
29 import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;
30 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
31 import org.openecomp.sdc.ci.tests.pages.*;
32 import org.openecomp.sdc.ci.tests.utilities.FileHandling;
33 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
34 import org.openecomp.sdc.ci.tests.utilities.OnboardingUiUtils;
35 import org.openecomp.sdc.ci.tests.utilities.ServiceUIUtils;
36 import org.openecomp.sdc.ci.tests.utils.Utils;
37 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
38 import org.openecomp.sdc.ci.tests.utils.general.OnboardingUtils;
39 import org.openecomp.sdc.ci.tests.utils.general.VendorLicenseModelRestUtils;
40 import org.openecomp.sdc.ci.tests.utils.general.VendorSoftwareProductRestUtils;
41 import org.openecomp.sdc.ci.tests.verificator.ServiceVerificator;
42 import org.openqa.selenium.WebElement;
43 import org.testng.AssertJUnit;
44 import org.testng.annotations.BeforeMethod;
45 import org.testng.annotations.Optional;
46 import org.testng.annotations.Parameters;
47 import org.testng.annotations.Test;
48
49 import java.io.File;
50 import java.util.Arrays;
51 import java.util.HashMap;
52 import java.util.List;
53 import java.util.Map;
54 import java.util.stream.Collectors;
55
56 import static org.testng.AssertJUnit.assertNotNull;
57 import static org.testng.AssertJUnit.assertTrue;
58
59 public class OnboardingFlowsUI extends SetupCDTest {
60         
61         protected static String filePath = FileHandling.getVnfRepositoryPath();
62         protected String makeDistributionValue;
63         
64         @Parameters({ "makeDistribution" })
65         @BeforeMethod
66         public void beforeTestReadParams(@Optional("true") String makeDistributionReadValue) {
67                 makeDistributionValue = makeDistributionReadValue;                             
68         }
69         
70         @Test
71         public void onboardVNFTestSanityOneFile() throws Throwable {
72                 String vnfFile = "1-VF-vUSP-vCCF-DB_v11.1.zip";
73                 ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource();//getResourceReqDetails(ComponentConfigurationTypeEnum.DEFAULT);
74                 ServiceReqDetails serviceReqDetails = ElementFactory.getDefaultService();//getServiceReqDetails(ComponentConfigurationTypeEnum.DEFAULT);
75                 runOnboardToDistributionFlow(resourceReqDetails, serviceReqDetails, filePath, vnfFile);
76         }
77
78         @Test
79         public void performanceTest() throws Throwable {
80                 System.out.println("Start test");
81                 Long actualTestRunTime = Utils.getActionDuration(() -> {
82                         try {
83                                 onboardVNFTestSanityOneFile();
84                         } catch (Throwable throwable) {
85                                 throwable.printStackTrace();
86                         }
87                 });
88                 Long regularTestRunTime = 400L;
89                 double factor = 1.5;
90                 assertTrue("Expected test run time should be less from " + regularTestRunTime*factor + ", actual time is " + actualTestRunTime , regularTestRunTime*factor>actualTestRunTime);
91         }
92
93         @Test
94         public void onboardVNFTestSanity() throws Throwable {
95                 List<String> fileNamesFromFolder = OnboardingUtils.getVnfNamesFileList();
96                 String vnfFile = fileNamesFromFolder.get(0).toString();
97                 ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource();//getResourceReqDetails(ComponentConfigurationTypeEnum.DEFAULT);
98                 ServiceReqDetails serviceReqDetails = ElementFactory.getDefaultService();//getServiceReqDetails(ComponentConfigurationTypeEnum.DEFAULT);
99                 runOnboardToDistributionFlow(resourceReqDetails, serviceReqDetails, filePath, vnfFile);
100         }
101
102         
103         public void runOnboardToDistributionFlow(ResourceReqDetails resourceReqDetails, ServiceReqDetails serviceMetadata, String filePath, String vnfFile) throws Exception {
104                 getExtendTest().log(Status.INFO, "Going to create resource with category: " + resourceReqDetails.getCategories().get(0).getName()
105                                 + " subCategory: " +  resourceReqDetails.getCategories().get(0).getSubcategories().get(0).getName()
106                                 + " and service category: " + serviceMetadata.getCategory());
107                 String vspName = onboardAndCertify(resourceReqDetails, filePath, vnfFile);
108
109                 reloginWithNewRole(UserRoleEnum.DESIGNER);
110                 // create service
111 //              ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
112                 ServiceUIUtils.createService(serviceMetadata, getUser());
113
114                 ServiceGeneralPage.getLeftMenu().moveToCompositionScreen();
115                 CompositionPage.searchForElement(vspName);
116                 CanvasManager serviceCanvasManager = CanvasManager.getCanvasManager();
117                 CanvasElement vfElement = serviceCanvasManager.createElementOnCanvas(vspName);
118                 ArtifactsCorrelationManager.addVNFtoServiceArtifactCorrelation(serviceMetadata.getName(), vspName);
119                 
120                 assertNotNull(vfElement);
121                 ServiceVerificator.verifyNumOfComponentInstances(serviceMetadata, "0.1", 1, getUser());
122                 ExtentTestActions.addScreenshot(Status.INFO, "ServiceComposition_" + vnfFile ,"The service topology is as follows: ");
123
124                 ServiceGeneralPage.clickSubmitForTestingButton(serviceMetadata.getName());
125
126                 reloginWithNewRole(UserRoleEnum.TESTER);
127                 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
128                 TesterOperationPage.certifyComponent(serviceMetadata.getName());
129
130                 reloginWithNewRole(UserRoleEnum.GOVERNOR);
131                 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
132                 GovernorOperationPage.approveSerivce(serviceMetadata.getName());
133
134                 if (makeDistributionValue.equals("true")){
135                         
136                 
137                 reloginWithNewRole(UserRoleEnum.OPS);
138                 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
139                 OpsOperationPage.distributeService();
140                 OpsOperationPage.displayMonitor();
141
142                 List<WebElement> rowsFromMonitorTable = OpsOperationPage.getRowsFromMonitorTable();
143                 AssertJUnit.assertEquals(1, rowsFromMonitorTable.size());
144
145                 OpsOperationPage.waitUntilArtifactsDistributed(0);
146                 
147 //              validateInputArtsVSouput(serviceMetadata.getName());
148
149                 }
150                 
151                 getExtendTest().log(Status.INFO, String.format("The onboarding %s test is passed ! ", vnfFile));
152         }
153
154         public String onboardAndCertify(ResourceReqDetails resourceReqDetails, String filePath, String vnfFile) throws Exception {
155                 Pair<String, VendorSoftwareProductObject> onboardAndValidate = OnboardingUiUtils.onboardAndValidate(resourceReqDetails, filePath, vnfFile, getUser());
156                 String vspName = onboardAndValidate.left;
157                 
158                 DeploymentArtifactPage.getLeftPanel().moveToCompositionScreen();
159                 ExtentTestActions.addScreenshot(Status.INFO, "TopologyTemplate_" + vnfFile ,"The topology template for " + vnfFile + " is as follows : ");
160                 
161                 DeploymentArtifactPage.clickSubmitForTestingButton(vspName);
162
163                 reloginWithNewRole(UserRoleEnum.TESTER);
164                 GeneralUIUtils.findComponentAndClick(vspName);
165                 TesterOperationPage.certifyComponent(vspName);
166                 return vspName;
167         }
168         
169         
170         @Test(dataProviderClass = OnbordingDataProviders.class, dataProvider = "VNF_List")
171         public void onboardVNFTest(String filePath, String vnfFile) throws Throwable {
172                 setLog(vnfFile);
173                 System.out.println("printttttttttttttt - >" + makeDistributionValue);
174                 ResourceReqDetails resourceReqDetails = ElementFactory.getRandomCategoryResource();
175                 ServiceReqDetails serviceReqDetails = ElementFactory.getRandomCategoryService();
176                 runOnboardToDistributionFlow(resourceReqDetails, serviceReqDetails, filePath, vnfFile);
177         }
178         
179         @Test(dataProviderClass = OnbordingDataProviders.class, dataProvider = "VNF_List")
180         public void onboardVNFShotFlow(String filePath, String vnfFile) throws Throwable {
181                 setLog(vnfFile);
182                 System.out.println("printttttttttttttt - >" + makeDistributionValue);
183                 ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource();//getResourceReqDetails(ComponentConfigurationTypeEnum.DEFAULT);
184                 onboardAndCertify(resourceReqDetails, filePath, vnfFile);
185         }
186
187         @Test(dataProviderClass = OnbordingDataProviders.class, dataProvider = "randomVNF_List")
188         public void onboardRandomVNFsTest(String filePath, String vnfFile) throws Throwable {
189                 setLog(vnfFile);
190                 System.out.println("printttttttttttttt - >" + makeDistributionValue);
191                 System.out.println("Vnf File name is: " + vnfFile);
192                 ResourceReqDetails resourceReqDetails = ElementFactory.getRandomCategoryResource();
193                 ServiceReqDetails serviceReqDetails = ElementFactory.getRandomCategoryService();
194                 runOnboardToDistributionFlow(resourceReqDetails, serviceReqDetails, filePath, vnfFile);
195         }
196         
197         
198         @Test
199         public void onboardUpdateVNFTest() throws Throwable {
200 //              Object[] fileNamesFromFolder = FileHandling.getZipFileNamesFromFolder(filePath);
201                 List<String> fileNamesFromFolder = FileHandling.getZipFileNamesFromFolder(filePath);
202 //              String vnfFile = fileNamesFromFolder[0].toString();
203                 String vnfFile = fileNamesFromFolder.get(0);
204                 ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource();//getResourceReqDetails(ComponentConfigurationTypeEnum.DEFAULT);
205                 Pair<String, VendorSoftwareProductObject> vsp = OnboardingUiUtils.onboardAndValidate(resourceReqDetails, filePath, vnfFile, getUser());
206                 String vspName = vsp.left;
207                 ResourceGeneralPage.clickSubmitForTestingButton(vspName);
208
209                 reloginWithNewRole(UserRoleEnum.TESTER);
210                 GeneralUIUtils.findComponentAndClick(vspName);
211                 TesterOperationPage.certifyComponent(vspName);
212
213                 reloginWithNewRole(UserRoleEnum.DESIGNER);
214                 // create service
215                 ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
216                 ServiceUIUtils.createService(serviceMetadata, getUser());
217
218                 ServiceGeneralPage.getLeftMenu().moveToCompositionScreen();
219                 CompositionPage.searchForElement(vspName);
220                 CanvasManager serviceCanvasManager = CanvasManager.getCanvasManager();
221                 CanvasElement vfElement = serviceCanvasManager.createElementOnCanvas(vspName);
222                 assertNotNull(vfElement);
223                 ServiceVerificator.verifyNumOfComponentInstances(serviceMetadata, "0.1", 1, getUser());
224
225                 HomePage.navigateToHomePage();
226                 
227                 ///update flow
228 //              String updatedVnfFile = fileNamesFromFolder[1].toString();
229                 String updatedVnfFile = fileNamesFromFolder.get(1);
230
231                 getExtendTest().log(Status.INFO, String.format("Going to update the VNF with %s......", updatedVnfFile));
232                 // update VendorSoftwareProduct
233                 OnboardingUiUtils.updateVnfAndValidate(filePath, vsp, updatedVnfFile, getUser());
234                 
235                 ResourceGeneralPage.clickSubmitForTestingButton(vspName);
236
237                 reloginWithNewRole(UserRoleEnum.TESTER);
238                 GeneralUIUtils.findComponentAndClick(vspName);
239                 TesterOperationPage.certifyComponent(vspName);
240
241                 reloginWithNewRole(UserRoleEnum.DESIGNER);
242                 
243                 // replace exiting VFI in service with new updated
244                 
245                 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
246                 ServiceGeneralPage.getLeftMenu().moveToCompositionScreen();
247                 serviceCanvasManager = CanvasManager.getCanvasManager();
248                 CompositionPage.changeComponentVersion(serviceCanvasManager, vfElement, "2.0");
249                 ServiceVerificator.verifyNumOfComponentInstances(serviceMetadata, "0.1", 1, getUser());
250
251                 ServiceGeneralPage.clickSubmitForTestingButton(serviceMetadata.getName());
252
253                 reloginWithNewRole(UserRoleEnum.TESTER);
254                 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
255                 TesterOperationPage.certifyComponent(serviceMetadata.getName());
256
257                 reloginWithNewRole(UserRoleEnum.GOVERNOR);
258                 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
259                 GovernorOperationPage.approveSerivce(serviceMetadata.getName());
260                 
261
262                         
263                                 reloginWithNewRole(UserRoleEnum.OPS);
264                                 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
265                                 OpsOperationPage.distributeService();
266                                 OpsOperationPage.displayMonitor();
267                 
268                                 List<WebElement> rowsFromMonitorTable = OpsOperationPage.getRowsFromMonitorTable();
269                                 AssertJUnit.assertEquals(1, rowsFromMonitorTable.size());
270                 
271                                 OpsOperationPage.waitUntilArtifactsDistributed(0);
272                 
273                 
274                 getExtendTest().log(Status.INFO, String.format("Onboarding %s test is passed ! ", vnfFile));
275                 
276                 
277         }
278
279         @Test
280         public void threeVMMSCsInServiceTest() throws Exception{
281
282                 String pathFile = FileHandling.getFilePath("VmmscArtifacts");
283                 List<String> vmmscList = Arrays.asList(new File(pathFile).list()).stream().filter(e -> e.contains("vmmsc") && e.endsWith(".zip")).collect(Collectors.toList());
284                 assertTrue("Did not find vMMSCs", vmmscList.size() > 0);
285                 
286                 Map<String, String> vspNames = new HashMap<>();
287                 for (String vnfFile : vmmscList){
288                         getExtendTest().log(Status.INFO, String.format("Going to onboard the VNF %s......", vnfFile));
289                         System.out.println(String.format("Going to onboard the VNF %s......", vnfFile));
290
291                         AmdocsLicenseMembers amdocsLicenseMembers = VendorLicenseModelRestUtils.createVendorLicense(getUser());
292                         ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource();//getResourceReqDetails(ComponentConfigurationTypeEnum.DEFAULT);
293                         Pair<String, VendorSoftwareProductObject> createVendorSoftwareProduct = VendorSoftwareProductRestUtils.createVendorSoftwareProduct(resourceReqDetails, vnfFile, pathFile, getUser(), amdocsLicenseMembers);
294
295                         getExtendTest().log(Status.INFO, String.format("Searching for onboarded %s", vnfFile));
296                         HomePage.showVspRepository();
297                         getExtendTest().log(Status.INFO,String.format("Going to import %s......", vnfFile.substring(0, vnfFile.indexOf("."))));
298                         OnboardingUiUtils.importVSP(createVendorSoftwareProduct);
299                         
300                         ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
301                         DeploymentArtifactPage.verifyArtifactsExistInTable(pathFile, vnfFile);
302                         
303                         String vspName = createVendorSoftwareProduct.left;
304                         DeploymentArtifactPage.clickSubmitForTestingButton(vspName);
305                         
306                         vspNames.put(vnfFile, vspName);
307                 }
308                 
309                 reloginWithNewRole(UserRoleEnum.TESTER);
310                 for (String vsp : vspNames.values()){
311                         GeneralUIUtils.findComponentAndClick(vsp);
312                         TesterOperationPage.certifyComponent(vsp);
313                 }
314                 
315                 reloginWithNewRole(UserRoleEnum.DESIGNER);
316                 // create service
317                 ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
318                 ServiceUIUtils.createService(serviceMetadata, getUser());
319                 ServiceGeneralPage.getLeftMenu().moveToCompositionScreen();
320                 CanvasManager serviceCanvasManager = CanvasManager.getCanvasManager();
321
322                 for (String vsp : vspNames.values()){
323                         CompositionPage.searchForElement(vsp);
324                         CanvasElement vfElement = serviceCanvasManager.createElementOnCanvas(vsp);
325                         assertNotNull(vfElement);
326                 }
327                 ServiceVerificator.verifyNumOfComponentInstances(serviceMetadata, "0.1", vspNames.values().size(), getUser());
328                 File imageFilePath = GeneralUIUtils.takeScreenshot(null, SetupCDTest.getScreenshotFolder(), "Info_" + getExtendTest().getModel().getName());
329                 final String absolutePath = new File(SetupCDTest.getReportFolder()).toURI().relativize(imageFilePath.toURI()).getPath();
330                 SetupCDTest.getExtendTest().log(Status.INFO, "Three kinds of vMMSC are in canvas now." + getExtendTest().addScreenCaptureFromPath(absolutePath));
331                 
332                 ServiceGeneralPage.clickSubmitForTestingButton(serviceMetadata.getName());
333
334                 reloginWithNewRole(UserRoleEnum.TESTER);
335                 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
336                 TesterOperationPage.certifyComponent(serviceMetadata.getName());
337
338                 reloginWithNewRole(UserRoleEnum.GOVERNOR);
339                 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
340                 GovernorOperationPage.approveSerivce(serviceMetadata.getName());
341
342                 reloginWithNewRole(UserRoleEnum.OPS);
343                 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
344                 OpsOperationPage.distributeService();
345                 OpsOperationPage.displayMonitor();
346
347                 List<WebElement> rowsFromMonitorTable = OpsOperationPage.getRowsFromMonitorTable();
348                 AssertJUnit.assertEquals(1, rowsFromMonitorTable.size());
349
350                 OpsOperationPage.waitUntilArtifactsDistributed(0);
351
352         }
353         
354         
355         @Override
356         protected UserRoleEnum getRole() {
357                 return UserRoleEnum.DESIGNER;
358         }
359
360 }