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