2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.ci.tests.execute.sanity;
23 import static org.testng.AssertJUnit.assertNotNull;
24 import static org.testng.AssertJUnit.assertTrue;
26 import java.awt.AWTException;
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;
34 import java.util.Random;
35 import java.util.stream.Collectors;
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;
66 import com.aventstack.extentreports.Status;
67 import com.clearspring.analytics.util.Pair;
69 public class Onboard extends SetupCDTest {
72 protected String makeDistributionValue;
74 @Parameters({ "makeDistribution" })
76 public void beforeTestReadParams(@Optional("true") String makeDistributionReadValue) {
77 makeDistributionValue = makeDistributionReadValue;
80 public static Object[][] provideData(Object[] fileNamesFromFolder, String filepath) {
81 Object[][] arObject = new Object[fileNamesFromFolder.length][];
84 for (Object obj : fileNamesFromFolder) {
85 arObject[index++] = new Object[] { filepath, obj };
90 @DataProvider(name = "VNF_List" , parallel = true)
91 private static final Object[][] VnfList() throws Exception {
92 String filepath = getFilePath();
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);
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);
111 private static Object[] getRandomElements(int randomElementNumber, Object[] fileNamesFromFolder) {
112 if(fileNamesFromFolder.length == 0 || fileNamesFromFolder.length < randomElementNumber){
115 List<Integer> indexList = new ArrayList<>();
116 Object[] newRandomFileNamesFromFolder = new Object[randomElementNumber];
117 for(int i = 0; i < fileNamesFromFolder.length; i++){
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]];
125 return newRandomFileNamesFromFolder;
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";
135 else if(filepath.isEmpty() && !System.getProperty("os.name").contains("Windows")){
136 filepath = FileHandling.getBasePath() + File.separator + "Files" + File.separator +"VNFs";
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);
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;
156 DeploymentArtifactPage.getLeftPanel().moveToCompositionScreen();
157 ExtentTestActions.addScreenshot(Status.INFO, "TopologyTemplate_" + vnfFile ,"The topology template for " + vnfFile + " is as follows : ");
159 DeploymentArtifactPage.clickSubmitForTestingButton(vspName);
161 reloginWithNewRole(UserRoleEnum.TESTER);
162 GeneralUIUtils.findComponentAndClick(vspName);
163 TesterOperationPage.certifyComponent(vspName);
165 reloginWithNewRole(UserRoleEnum.DESIGNER);
167 ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
168 ServiceUIUtils.createService(serviceMetadata, getUser());
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);
176 assertNotNull(vfElement);
177 ServiceVerificator.verifyNumOfComponentInstances(serviceMetadata, "0.1", 1, getUser());
178 ExtentTestActions.addScreenshot(Status.INFO, "ServiceComposition_" + vnfFile ,"The service topology is as follows : ");
180 ServiceGeneralPage.clickSubmitForTestingButton(serviceMetadata.getName());
182 reloginWithNewRole(UserRoleEnum.TESTER);
183 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
184 TesterOperationPage.certifyComponent(serviceMetadata.getName());
186 reloginWithNewRole(UserRoleEnum.GOVERNOR);
187 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
188 GovernorOperationPage.approveSerivce(serviceMetadata.getName());
190 if (makeDistributionValue.equals("true")){
193 reloginWithNewRole(UserRoleEnum.OPS);
194 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
195 OpsOperationPage.distributeService();
196 OpsOperationPage.displayMonitor();
198 List<WebElement> rowsFromMonitorTable = OpsOperationPage.getRowsFromMonitorTable();
199 AssertJUnit.assertEquals(1, rowsFromMonitorTable.size());
201 OpsOperationPage.waitUntilArtifactsDistributed(0);
203 // validateInputArtsVSouput(serviceMetadata.getName());
207 getExtendTest().log(Status.INFO, String.format("The onboarding %s test is passed ! ", vnfFile));
210 // protected synchronized void validateInputArtsVSouput(String serviceName) {
213 // String filepath = System.getProperty("filepath");
214 // if (filepath == null && System.getProperty("os.name").contains("Windows")) {
215 // filepath = FileHandling.getResourcesFilesPath() + folder + File.separator;
218 // Set<Entry<String, Entry<String, LinkedList<HeatMetaFirstLevelDefinition>>>> serviceArtifactCorrelationMap = ArtifactsCorrelationManager.getServiceArtifactCorrelationMap(serviceName);
222 @Test(dataProvider = "VNF_List")
223 public void onboardVNFTest(String filepath, String vnfFile) throws Exception, Throwable {
225 System.out.println("printttttttttttttt - >" + makeDistributionValue);
226 runOnboardToDistributionFlow(filepath, vnfFile);
229 @Test(dataProvider = "randomVNF_List")
230 public void onboardRandomVNFsTest(String filepath, String vnfFile) throws Exception, Throwable {
232 System.out.println("printttttttttttttt - >" + makeDistributionValue);
233 System.out.println("vnf File name is: " + vnfFile);
234 runOnboardToDistributionFlow(filepath, vnfFile);
239 public void onboardUpdateVNFTest() throws Exception, Throwable {
240 String filepath = getFilePath();
241 Object[] fileNamesFromFolder = FileHandling.getZipFileNamesFromFolder(filepath);
242 String vnfFile = fileNamesFromFolder[0].toString();
244 Pair<String,Map<String,String>> vsp = OnboardingUtils.onboardAndValidate(filepath, vnfFile, getUser());
245 String vspName = vsp.left;
246 ResourceGeneralPage.clickSubmitForTestingButton(vspName);
248 reloginWithNewRole(UserRoleEnum.TESTER);
249 GeneralUIUtils.findComponentAndClick(vspName);
250 TesterOperationPage.certifyComponent(vspName);
252 reloginWithNewRole(UserRoleEnum.DESIGNER);
254 ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
255 ServiceUIUtils.createService(serviceMetadata, getUser());
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());
264 HomePage.navigateToHomePage();
267 String updatedVnfFile = fileNamesFromFolder[1].toString();
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());
273 ResourceGeneralPage.clickSubmitForTestingButton(vspName);
275 reloginWithNewRole(UserRoleEnum.TESTER);
276 GeneralUIUtils.findComponentAndClick(vspName);
277 TesterOperationPage.certifyComponent(vspName);
279 reloginWithNewRole(UserRoleEnum.DESIGNER);
281 // replace exiting VFI in service with new updated
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());
289 ServiceGeneralPage.clickSubmitForTestingButton(serviceMetadata.getName());
291 reloginWithNewRole(UserRoleEnum.TESTER);
292 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
293 TesterOperationPage.certifyComponent(serviceMetadata.getName());
295 reloginWithNewRole(UserRoleEnum.GOVERNOR);
296 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
297 GovernorOperationPage.approveSerivce(serviceMetadata.getName());
301 reloginWithNewRole(UserRoleEnum.OPS);
302 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
303 OpsOperationPage.distributeService();
304 OpsOperationPage.displayMonitor();
306 List<WebElement> rowsFromMonitorTable = OpsOperationPage.getRowsFromMonitorTable();
307 AssertJUnit.assertEquals(1, rowsFromMonitorTable.size());
309 OpsOperationPage.waitUntilArtifactsDistributed(0);
312 getExtendTest().log(Status.INFO, String.format("onboarding %s test is passed ! ", vnfFile));
318 public void threeVMMSCsInServiceTest() throws Exception{
319 String filepath = getFilePath();
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);
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));
331 OnboardingUtils.createVendorLicense(getUser());
332 Pair<String,Map<String,String>> createVendorSoftwareProduct = OnboardingUtils.createVendorSoftwareProduct(vnfFile, filepath, getUser());
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);
339 ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
340 DeploymentArtifactPage.verifyArtifactsExistInTable(filepath, vnfFile);
342 String vspName = createVendorSoftwareProduct.left;
343 DeploymentArtifactPage.clickSubmitForTestingButton(vspName);
345 vspNames.put(vnfFile, vspName);
348 reloginWithNewRole(UserRoleEnum.TESTER);
349 for (String vsp : vspNames.values()){
350 GeneralUIUtils.findComponentAndClick(vsp);
351 TesterOperationPage.certifyComponent(vsp);
354 reloginWithNewRole(UserRoleEnum.DESIGNER);
356 ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
357 ServiceUIUtils.createService(serviceMetadata, getUser());
358 ServiceGeneralPage.getLeftMenu().moveToCompositionScreen();
359 CanvasManager serviceCanvasManager = CanvasManager.getCanvasManager();
361 for (String vsp : vspNames.values()){
362 CompositionPage.searchForElement(vsp);
363 CanvasElement vfElement = serviceCanvasManager.createElementOnCanvas(vsp);
364 assertNotNull(vfElement);
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));
371 ServiceGeneralPage.clickSubmitForTestingButton(serviceMetadata.getName());
373 reloginWithNewRole(UserRoleEnum.TESTER);
374 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
375 TesterOperationPage.certifyComponent(serviceMetadata.getName());
377 reloginWithNewRole(UserRoleEnum.GOVERNOR);
378 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
379 GovernorOperationPage.approveSerivce(serviceMetadata.getName());
381 reloginWithNewRole(UserRoleEnum.OPS);
382 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
383 OpsOperationPage.distributeService();
384 OpsOperationPage.displayMonitor();
386 List<WebElement> rowsFromMonitorTable = OpsOperationPage.getRowsFromMonitorTable();
387 AssertJUnit.assertEquals(1, rowsFromMonitorTable.size());
389 OpsOperationPage.waitUntilArtifactsDistributed(0);
408 protected UserRoleEnum getRole() {
409 return UserRoleEnum.DESIGNER;