[SDC] rebase 1710 code
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / execute / sanity / Onboard.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 static org.testng.AssertJUnit.assertNotNull;
24 import static org.testng.AssertJUnit.assertTrue;
25
26 import java.awt.AWTException;
27 import java.io.File;
28 import java.util.ArrayList;
29 import java.util.Arrays;
30 import java.util.Collections;
31 import java.util.HashMap;
32 import java.util.List;
33 import java.util.Map;
34 import java.util.Random;
35 import java.util.stream.Collectors;
36
37 import org.openecomp.sdc.ci.tests.datatypes.CanvasElement;
38 import org.openecomp.sdc.ci.tests.datatypes.CanvasManager;
39 import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
40 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
41 import org.openecomp.sdc.ci.tests.execute.setup.ArtifactsCorrelationManager;
42 import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;
43 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
44 import org.openecomp.sdc.ci.tests.pages.CompositionPage;
45 import org.openecomp.sdc.ci.tests.pages.DeploymentArtifactPage;
46 import org.openecomp.sdc.ci.tests.pages.GovernorOperationPage;
47 import org.openecomp.sdc.ci.tests.pages.HomePage;
48 import org.openecomp.sdc.ci.tests.pages.OpsOperationPage;
49 import org.openecomp.sdc.ci.tests.pages.ResourceGeneralPage;
50 import org.openecomp.sdc.ci.tests.pages.ServiceGeneralPage;
51 import org.openecomp.sdc.ci.tests.pages.TesterOperationPage;
52 import org.openecomp.sdc.ci.tests.utilities.FileHandling;
53 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
54 import org.openecomp.sdc.ci.tests.utilities.OnboardingUtils;
55 import org.openecomp.sdc.ci.tests.utilities.ServiceUIUtils;
56 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
57 import org.openecomp.sdc.ci.tests.verificator.ServiceVerificator;
58 import org.openqa.selenium.WebElement;
59 import org.testng.AssertJUnit;
60 import org.testng.annotations.BeforeMethod;
61 import org.testng.annotations.DataProvider;
62 import org.testng.annotations.Optional;
63 import org.testng.annotations.Parameters;
64 import org.testng.annotations.Test;
65
66 import com.aventstack.extentreports.Status;
67 import com.clearspring.analytics.util.Pair;
68
69 public class Onboard extends SetupCDTest {
70         
71         
72         protected String makeDistributionValue;
73         
74         @Parameters({ "makeDistribution" })
75         @BeforeMethod
76         public void beforeTestReadParams(@Optional("true") String makeDistributionReadValue) {
77                 makeDistributionValue = makeDistributionReadValue;                             
78         }
79         
80         public static Object[][] provideData(Object[] fileNamesFromFolder, String filepath) {
81                 Object[][] arObject = new Object[fileNamesFromFolder.length][];
82
83                 int index = 0;
84                 for (Object obj : fileNamesFromFolder) {
85                         arObject[index++] = new Object[] { filepath, obj };
86                 }
87                 return arObject;
88         }
89
90         @DataProvider(name = "VNF_List" , parallel = true)
91         private static final Object[][] VnfList() throws Exception {
92                 String filepath = getFilePath();
93                 
94                 Object[] fileNamesFromFolder = FileHandling.getZipFileNamesFromFolder(filepath);
95                 System.out.println(String.format("There are %s zip file(s) to test", fileNamesFromFolder.length));
96                 return provideData(fileNamesFromFolder, filepath);
97         }
98
99         
100         @DataProvider(name = "randomVNF_List", parallel = false)
101         private static final Object[][] randomVnfList() throws Exception {
102                 int randomElementNumber = 3; //how many VNFs to onboard randomly
103                 String filepath = getFilePath();
104                 Object[] fileNamesFromFolder = FileHandling.getZipFileNamesFromFolder(filepath);
105                 Object[] newRandomFileNamesFromFolder = getRandomElements(randomElementNumber, fileNamesFromFolder);
106                 System.out.println(String.format("There are %s zip file(s) to test", newRandomFileNamesFromFolder.length));
107                 return provideData(newRandomFileNamesFromFolder, filepath);
108         }
109         
110         
111         private static Object[] getRandomElements(int randomElementNumber, Object[] fileNamesFromFolder) {
112                 if(fileNamesFromFolder.length == 0 || fileNamesFromFolder.length < randomElementNumber){
113                         return null;
114                 }else{
115                         List<Integer> indexList = new ArrayList<>();
116                         Object[] newRandomFileNamesFromFolder = new Object[randomElementNumber]; 
117                         for(int i = 0; i < fileNamesFromFolder.length; i++){
118                                 indexList.add(i);
119                         }
120                         Collections.shuffle(indexList);
121                         Integer[] randomArray = indexList.subList(0, randomElementNumber).toArray(new Integer[randomElementNumber]);
122                         for(int i = 0; i < randomArray.length; i++){
123                                 newRandomFileNamesFromFolder[i] = fileNamesFromFolder[randomArray[i]];
124                         }
125                         return newRandomFileNamesFromFolder;
126                 }
127         }
128
129         public static String getFilePath() {
130                 String filepath = System.getProperty("filepath");
131                 if (filepath == null && System.getProperty("os.name").contains("Windows")) {
132                         filepath = FileHandling.getResourcesFilesPath() +"VNFs";
133                 }
134                 
135                 else if(filepath.isEmpty() && !System.getProperty("os.name").contains("Windows")){
136                                 filepath = FileHandling.getBasePath() + File.separator + "Files" + File.separator +"VNFs";
137                 }
138                 return filepath;
139         }
140         
141         @Test
142         public void onboardVNFTestSanity() throws Exception, Throwable {
143                 String filepath = getFilePath();
144 //              String vnfFile = "2016-012_vMX_AV_30_1072_e2e.zip";
145 //              String filepath = getFilePath();
146                 Object[] fileNamesFromFolder = FileHandling.getZipFileNamesFromFolder(filepath);
147                 String vnfFile = fileNamesFromFolder[0].toString();
148                 runOnboardToDistributionFlow(filepath, vnfFile);
149         }
150
151         
152         public void runOnboardToDistributionFlow(String filepath, String vnfFile) throws Exception, AWTException {
153                 Pair<String,Map<String,String>> onboardAndValidate = OnboardingUtils.onboardAndValidate(filepath, vnfFile, getUser());
154                 String vspName = onboardAndValidate.left;
155                 
156                 DeploymentArtifactPage.getLeftPanel().moveToCompositionScreen();
157                 ExtentTestActions.addScreenshot(Status.INFO, "TopologyTemplate_" + vnfFile ,"The topology template for " + vnfFile + " is as follows : ");
158                 
159                 DeploymentArtifactPage.clickSubmitForTestingButton(vspName);
160
161                 reloginWithNewRole(UserRoleEnum.TESTER);
162                 GeneralUIUtils.findComponentAndClick(vspName);
163                 TesterOperationPage.certifyComponent(vspName);
164
165                 reloginWithNewRole(UserRoleEnum.DESIGNER);
166                 // create service
167                 ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
168                 ServiceUIUtils.createService(serviceMetadata, getUser());
169
170                 ServiceGeneralPage.getLeftMenu().moveToCompositionScreen();
171                 CompositionPage.searchForElement(vspName);
172                 CanvasManager serviceCanvasManager = CanvasManager.getCanvasManager();
173                 CanvasElement vfElement = serviceCanvasManager.createElementOnCanvas(vspName);
174                 ArtifactsCorrelationManager.addVNFtoServiceArtifactCorrelation(serviceMetadata.getName(), vspName);
175                 
176                 assertNotNull(vfElement);
177                 ServiceVerificator.verifyNumOfComponentInstances(serviceMetadata, "0.1", 1, getUser());
178                 ExtentTestActions.addScreenshot(Status.INFO, "ServiceComposition_" + vnfFile ,"The service topology is as follows : ");
179
180                 ServiceGeneralPage.clickSubmitForTestingButton(serviceMetadata.getName());
181
182                 reloginWithNewRole(UserRoleEnum.TESTER);
183                 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
184                 TesterOperationPage.certifyComponent(serviceMetadata.getName());
185
186                 reloginWithNewRole(UserRoleEnum.GOVERNOR);
187                 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
188                 GovernorOperationPage.approveSerivce(serviceMetadata.getName());
189
190                 if (makeDistributionValue.equals("true")){
191                         
192                 
193                 reloginWithNewRole(UserRoleEnum.OPS);
194                 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
195                 OpsOperationPage.distributeService();
196                 OpsOperationPage.displayMonitor();
197
198                 List<WebElement> rowsFromMonitorTable = OpsOperationPage.getRowsFromMonitorTable();
199                 AssertJUnit.assertEquals(1, rowsFromMonitorTable.size());
200
201                 OpsOperationPage.waitUntilArtifactsDistributed(0);
202                 
203 //              validateInputArtsVSouput(serviceMetadata.getName());
204
205                 }
206                 
207                 getExtendTest().log(Status.INFO, String.format("The onboarding %s test is passed ! ", vnfFile));
208         }
209
210 //      protected synchronized void validateInputArtsVSouput(String serviceName) {
211 //              
212 //              
213 //              String filepath = System.getProperty("filepath");
214 //              if (filepath == null && System.getProperty("os.name").contains("Windows")) {
215 //                      filepath = FileHandling.getResourcesFilesPath() + folder + File.separator;
216 //              }
217 //              
218 //              Set<Entry<String, Entry<String, LinkedList<HeatMetaFirstLevelDefinition>>>> serviceArtifactCorrelationMap = ArtifactsCorrelationManager.getServiceArtifactCorrelationMap(serviceName);
219 //              
220 //      }
221
222         @Test(dataProvider = "VNF_List")
223         public void onboardVNFTest(String filepath, String vnfFile) throws Exception, Throwable {
224                 setLog(vnfFile);
225                 System.out.println("printttttttttttttt - >" + makeDistributionValue);
226                 runOnboardToDistributionFlow(filepath, vnfFile);
227         }
228
229         @Test(dataProvider = "randomVNF_List")
230         public void onboardRandomVNFsTest(String filepath, String vnfFile) throws Exception, Throwable {
231                 setLog(vnfFile);
232                 System.out.println("printttttttttttttt - >" + makeDistributionValue);
233                 System.out.println("vnf File name is: " + vnfFile);
234                 runOnboardToDistributionFlow(filepath, vnfFile);
235         }
236         
237         
238         @Test
239         public void onboardUpdateVNFTest() throws Exception, Throwable {
240                 String filepath = getFilePath();
241                 Object[] fileNamesFromFolder = FileHandling.getZipFileNamesFromFolder(filepath);
242                 String vnfFile = fileNamesFromFolder[0].toString();
243                 
244                 Pair<String,Map<String,String>> vsp = OnboardingUtils.onboardAndValidate(filepath, vnfFile, getUser());
245                 String vspName = vsp.left;
246                 ResourceGeneralPage.clickSubmitForTestingButton(vspName);
247
248                 reloginWithNewRole(UserRoleEnum.TESTER);
249                 GeneralUIUtils.findComponentAndClick(vspName);
250                 TesterOperationPage.certifyComponent(vspName);
251
252                 reloginWithNewRole(UserRoleEnum.DESIGNER);
253                 // create service
254                 ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
255                 ServiceUIUtils.createService(serviceMetadata, getUser());
256
257                 ServiceGeneralPage.getLeftMenu().moveToCompositionScreen();
258                 CompositionPage.searchForElement(vspName);
259                 CanvasManager serviceCanvasManager = CanvasManager.getCanvasManager();
260                 CanvasElement vfElement = serviceCanvasManager.createElementOnCanvas(vspName);
261                 assertNotNull(vfElement);
262                 ServiceVerificator.verifyNumOfComponentInstances(serviceMetadata, "0.1", 1, getUser());
263
264                 HomePage.navigateToHomePage();
265                 
266                 ///update flow
267                 String updatedVnfFile = fileNamesFromFolder[1].toString();
268
269                 getExtendTest().log(Status.INFO, String.format("Going to update the VNF with %s......", updatedVnfFile));
270                 // update VendorSoftwareProduct
271                 OnboardingUtils.updateVnfAndValidate(filepath, vsp, updatedVnfFile, getUser());
272                 
273                 ResourceGeneralPage.clickSubmitForTestingButton(vspName);
274
275                 reloginWithNewRole(UserRoleEnum.TESTER);
276                 GeneralUIUtils.findComponentAndClick(vspName);
277                 TesterOperationPage.certifyComponent(vspName);
278
279                 reloginWithNewRole(UserRoleEnum.DESIGNER);
280                 
281                 // replace exiting VFI in service with new updated
282                 
283                 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
284                 ServiceGeneralPage.getLeftMenu().moveToCompositionScreen();
285                 serviceCanvasManager = CanvasManager.getCanvasManager();
286                 CompositionPage.changeComponentVersion(serviceCanvasManager, vfElement, "2.0");
287                 ServiceVerificator.verifyNumOfComponentInstances(serviceMetadata, "0.1", 1, getUser());
288
289                 ServiceGeneralPage.clickSubmitForTestingButton(serviceMetadata.getName());
290
291                 reloginWithNewRole(UserRoleEnum.TESTER);
292                 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
293                 TesterOperationPage.certifyComponent(serviceMetadata.getName());
294
295                 reloginWithNewRole(UserRoleEnum.GOVERNOR);
296                 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
297                 GovernorOperationPage.approveSerivce(serviceMetadata.getName());
298                 
299
300                         
301                                 reloginWithNewRole(UserRoleEnum.OPS);
302                                 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
303                                 OpsOperationPage.distributeService();
304                                 OpsOperationPage.displayMonitor();
305                 
306                                 List<WebElement> rowsFromMonitorTable = OpsOperationPage.getRowsFromMonitorTable();
307                                 AssertJUnit.assertEquals(1, rowsFromMonitorTable.size());
308                 
309                                 OpsOperationPage.waitUntilArtifactsDistributed(0);
310                 
311                 
312                 getExtendTest().log(Status.INFO, String.format("onboarding %s test is passed ! ", vnfFile));
313                 
314                 
315         }
316
317         @Test
318         public void threeVMMSCsInServiceTest() throws Exception{
319                 String filepath = getFilePath();
320                 
321                 
322                 List<String> vmmscList = new ArrayList<String>();
323                 vmmscList = Arrays.asList(new File(filepath).list()).stream().filter(e -> e.contains("vmmsc") && e.endsWith(".zip")).collect(Collectors.toList());
324                 assertTrue("Did not find vMMSCs", vmmscList.size() > 0);
325                 
326                 Map<String, String> vspNames = new HashMap<String, String>(); 
327                 for (String vnfFile : vmmscList){
328                         getExtendTest().log(Status.INFO, String.format("going to onboard the VNF %s......", vnfFile));
329                         System.out.println(String.format("going to onboard the VNF %s......", vnfFile));
330
331                         OnboardingUtils.createVendorLicense(getUser());
332                         Pair<String,Map<String,String>> createVendorSoftwareProduct = OnboardingUtils.createVendorSoftwareProduct(vnfFile, filepath, getUser());
333
334                         getExtendTest().log(Status.INFO, String.format("searching for onboarded %s", vnfFile));
335                         HomePage.showVspRepository();
336                         getExtendTest().log(Status.INFO,String.format("going to import %s......", vnfFile.substring(0, vnfFile.indexOf("."))));
337                         OnboardingUtils.importVSP(createVendorSoftwareProduct);
338                         
339                         ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
340                         DeploymentArtifactPage.verifyArtifactsExistInTable(filepath, vnfFile);
341                         
342                         String vspName = createVendorSoftwareProduct.left;
343                         DeploymentArtifactPage.clickSubmitForTestingButton(vspName);
344                         
345                         vspNames.put(vnfFile, vspName);
346                 }
347                 
348                 reloginWithNewRole(UserRoleEnum.TESTER);
349                 for (String vsp : vspNames.values()){
350                         GeneralUIUtils.findComponentAndClick(vsp);
351                         TesterOperationPage.certifyComponent(vsp);
352                 }
353                 
354                 reloginWithNewRole(UserRoleEnum.DESIGNER);
355                 // create service
356                 ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
357                 ServiceUIUtils.createService(serviceMetadata, getUser());
358                 ServiceGeneralPage.getLeftMenu().moveToCompositionScreen();
359                 CanvasManager serviceCanvasManager = CanvasManager.getCanvasManager();
360
361                 for (String vsp : vspNames.values()){
362                         CompositionPage.searchForElement(vsp);
363                         CanvasElement vfElement = serviceCanvasManager.createElementOnCanvas(vsp);
364                         assertNotNull(vfElement);
365                 }
366                 ServiceVerificator.verifyNumOfComponentInstances(serviceMetadata, "0.1", vspNames.values().size(), getUser());
367                 File imageFilePath = GeneralUIUtils.takeScreenshot(null, SetupCDTest.getScreenshotFolder(), "Info_" + getExtendTest().getModel().getName());
368                 final String absolutePath = new File(SetupCDTest.getReportFolder()).toURI().relativize(imageFilePath.toURI()).getPath();
369                 SetupCDTest.getExtendTest().log(Status.INFO, "Three kinds of vMMSC are in canvas now." + getExtendTest().addScreenCaptureFromPath(absolutePath));
370                 
371                 ServiceGeneralPage.clickSubmitForTestingButton(serviceMetadata.getName());
372
373                 reloginWithNewRole(UserRoleEnum.TESTER);
374                 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
375                 TesterOperationPage.certifyComponent(serviceMetadata.getName());
376
377                 reloginWithNewRole(UserRoleEnum.GOVERNOR);
378                 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
379                 GovernorOperationPage.approveSerivce(serviceMetadata.getName());
380
381                 reloginWithNewRole(UserRoleEnum.OPS);
382                 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
383                 OpsOperationPage.distributeService();
384                 OpsOperationPage.displayMonitor();
385
386                 List<WebElement> rowsFromMonitorTable = OpsOperationPage.getRowsFromMonitorTable();
387                 AssertJUnit.assertEquals(1, rowsFromMonitorTable.size());
388
389                 OpsOperationPage.waitUntilArtifactsDistributed(0);
390
391         }
392         
393         
394         
395         
396         
397         
398         
399         
400         
401         
402         
403         
404         
405         
406         
407         @Override
408         protected UserRoleEnum getRole() {
409                 return UserRoleEnum.DESIGNER;
410         }
411
412 }