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