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.HashMap;
31 import java.util.List;
33 import java.util.stream.Collectors;
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;
64 import com.aventstack.extentreports.Status;
65 import com.clearspring.analytics.util.Pair;
67 public class Onboard extends SetupCDTest {
70 protected String makeDistributionValue;
72 @Parameters({ "makeDistribution" })
74 public void beforeTestReadParams(@Optional("true") String makeDistributionReadValue) {
75 makeDistributionValue = makeDistributionReadValue;
78 public static Object[][] provideData(Object[] fileNamesFromFolder, String filepath) {
79 Object[][] arObject = new Object[fileNamesFromFolder.length][];
82 for (Object obj : fileNamesFromFolder) {
83 arObject[index++] = new Object[] { filepath, obj };
88 @DataProvider(name = "VNF_List" , parallel = true)
89 private static final Object[][] VnfList() throws Exception {
90 String filepath = getFilePath();
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);
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";
103 else if(filepath.isEmpty() && !System.getProperty("os.name").contains("Windows")){
104 filepath = FileHandling.getBasePath() + File.separator + "Files" + File.separator +"VNFs";
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);
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;
123 DeploymentArtifactPage.getLeftPanel().moveToCompositionScreen();
124 ExtentTestActions.addScreenshot(Status.INFO, "TopologyTemplate_" + vnfFile ,"The topology template for " + vnfFile + " is as follows : ");
126 DeploymentArtifactPage.clickSubmitForTestingButton(vspName);
128 reloginWithNewRole(UserRoleEnum.TESTER);
129 GeneralUIUtils.findComponentAndClick(vspName);
130 TesterOperationPage.certifyComponent(vspName);
132 reloginWithNewRole(UserRoleEnum.DESIGNER);
134 ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
135 ServiceUIUtils.createService(serviceMetadata, getUser());
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);
143 assertNotNull(vfElement);
144 ServiceVerificator.verifyNumOfComponentInstances(serviceMetadata, "0.1", 1, getUser());
145 ExtentTestActions.addScreenshot(Status.INFO, "ServiceComposition_" + vnfFile ,"The service topology is as follows : ");
147 ServiceGeneralPage.clickSubmitForTestingButton(serviceMetadata.getName());
149 reloginWithNewRole(UserRoleEnum.TESTER);
150 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
151 TesterOperationPage.certifyComponent(serviceMetadata.getName());
153 reloginWithNewRole(UserRoleEnum.GOVERNOR);
154 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
155 GovernorOperationPage.approveSerivce(serviceMetadata.getName());
157 if (makeDistributionValue.equals("true")){
160 reloginWithNewRole(UserRoleEnum.OPS);
161 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
162 OpsOperationPage.distributeService();
163 OpsOperationPage.displayMonitor();
165 List<WebElement> rowsFromMonitorTable = OpsOperationPage.getRowsFromMonitorTable();
166 AssertJUnit.assertEquals(1, rowsFromMonitorTable.size());
168 OpsOperationPage.waitUntilArtifactsDistributed(0);
170 // validateInputArtsVSouput(serviceMetadata.getName());
174 getExtendTest().log(Status.INFO, String.format("The onboarding %s test is passed ! ", vnfFile));
177 // protected synchronized void validateInputArtsVSouput(String serviceName) {
180 // String filepath = System.getProperty("filepath");
181 // if (filepath == null && System.getProperty("os.name").contains("Windows")) {
182 // filepath = FileHandling.getResourcesFilesPath() + folder + File.separator;
185 // Set<Entry<String, Entry<String, LinkedList<HeatMetaFirstLevelDefinition>>>> serviceArtifactCorrelationMap = ArtifactsCorrelationManager.getServiceArtifactCorrelationMap(serviceName);
189 @Test(dataProvider = "VNF_List")
190 public void onboardVNFTest(String filepath, String vnfFile) throws Exception, Throwable {
192 System.out.println("printttttttttttttt - >" + makeDistributionValue);
193 runOnboardToDistributionFlow(filepath, vnfFile);
198 public void onboardUpdateVNFTest() throws Exception, Throwable {
199 String filepath = getFilePath();
200 Object[] fileNamesFromFolder = FileHandling.getZipFileNamesFromFolder(filepath);
201 String vnfFile = fileNamesFromFolder[0].toString();
203 Pair<String,Map<String,String>> vsp = OnboardingUtils.onboardAndValidate(filepath, vnfFile, getUser());
204 String vspName = vsp.left;
205 ResourceGeneralPage.clickSubmitForTestingButton(vspName);
207 reloginWithNewRole(UserRoleEnum.TESTER);
208 GeneralUIUtils.findComponentAndClick(vspName);
209 TesterOperationPage.certifyComponent(vspName);
211 reloginWithNewRole(UserRoleEnum.DESIGNER);
213 ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
214 ServiceUIUtils.createService(serviceMetadata, getUser());
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());
223 HomePage.navigateToHomePage();
226 String updatedVnfFile = fileNamesFromFolder[1].toString();
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());
232 ResourceGeneralPage.clickSubmitForTestingButton(vspName);
234 reloginWithNewRole(UserRoleEnum.TESTER);
235 GeneralUIUtils.findComponentAndClick(vspName);
236 TesterOperationPage.certifyComponent(vspName);
238 reloginWithNewRole(UserRoleEnum.DESIGNER);
240 // replace exiting VFI in service with new updated
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());
248 ServiceGeneralPage.clickSubmitForTestingButton(serviceMetadata.getName());
250 reloginWithNewRole(UserRoleEnum.TESTER);
251 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
252 TesterOperationPage.certifyComponent(serviceMetadata.getName());
254 reloginWithNewRole(UserRoleEnum.GOVERNOR);
255 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
256 GovernorOperationPage.approveSerivce(serviceMetadata.getName());
260 reloginWithNewRole(UserRoleEnum.OPS);
261 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
262 OpsOperationPage.distributeService();
263 OpsOperationPage.displayMonitor();
265 List<WebElement> rowsFromMonitorTable = OpsOperationPage.getRowsFromMonitorTable();
266 AssertJUnit.assertEquals(1, rowsFromMonitorTable.size());
268 OpsOperationPage.waitUntilArtifactsDistributed(0);
271 getExtendTest().log(Status.INFO, String.format("onboarding %s test is passed ! ", vnfFile));
277 public void threeVMMSCsInServiceTest() throws Exception{
278 String filepath = getFilePath();
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);
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));
290 OnboardingUtils.createVendorLicense(getUser());
291 Pair<String,Map<String,String>> createVendorSoftwareProduct = OnboardingUtils.createVendorSoftwareProduct(vnfFile, filepath, getUser());
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);
298 ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
299 DeploymentArtifactPage.verifyArtifactsExistInTable(filepath, vnfFile);
301 String vspName = createVendorSoftwareProduct.left;
302 DeploymentArtifactPage.clickSubmitForTestingButton(vspName);
304 vspNames.put(vnfFile, vspName);
307 reloginWithNewRole(UserRoleEnum.TESTER);
308 for (String vsp : vspNames.values()){
309 GeneralUIUtils.findComponentAndClick(vsp);
310 TesterOperationPage.certifyComponent(vsp);
313 reloginWithNewRole(UserRoleEnum.DESIGNER);
315 ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
316 ServiceUIUtils.createService(serviceMetadata, getUser());
317 ServiceGeneralPage.getLeftMenu().moveToCompositionScreen();
318 CanvasManager serviceCanvasManager = CanvasManager.getCanvasManager();
320 for (String vsp : vspNames.values()){
321 CompositionPage.searchForElement(vsp);
322 CanvasElement vfElement = serviceCanvasManager.createElementOnCanvas(vsp);
323 assertNotNull(vfElement);
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));
330 ServiceGeneralPage.clickSubmitForTestingButton(serviceMetadata.getName());
332 reloginWithNewRole(UserRoleEnum.TESTER);
333 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
334 TesterOperationPage.certifyComponent(serviceMetadata.getName());
336 reloginWithNewRole(UserRoleEnum.GOVERNOR);
337 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
338 GovernorOperationPage.approveSerivce(serviceMetadata.getName());
340 reloginWithNewRole(UserRoleEnum.OPS);
341 GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
342 OpsOperationPage.distributeService();
343 OpsOperationPage.displayMonitor();
345 List<WebElement> rowsFromMonitorTable = OpsOperationPage.getRowsFromMonitorTable();
346 AssertJUnit.assertEquals(1, rowsFromMonitorTable.size());
348 OpsOperationPage.waitUntilArtifactsDistributed(0);
367 protected UserRoleEnum getRole() {
368 return UserRoleEnum.DESIGNER;