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.AmdocsComplexService;
23 import com.aventstack.extentreports.Status;
24 import com.clearspring.analytics.util.Pair;
25 import org.apache.commons.lang.RandomStringUtils;
26 import org.json.JSONObject;
27 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
28 import org.openecomp.sdc.ci.tests.datatypes.HeatMetaFirstLevelDefinition;
29 import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
30 import org.openecomp.sdc.ci.tests.datatypes.VendorSoftwareProductObject;
31 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
32 import org.openecomp.sdc.ci.tests.execute.devCI.ArtifactFromCsar;
33 import org.openecomp.sdc.ci.tests.execute.setup.ArtifactsCorrelationManager;
34 import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;
35 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
36 import org.openecomp.sdc.ci.tests.pages.DeploymentArtifactPage;
37 import org.openecomp.sdc.ci.tests.pages.ResourceGeneralPage;
38 import org.openecomp.sdc.ci.tests.utilities.DownloadManager;
39 import org.openecomp.sdc.ci.tests.utilities.FileHandling;
40 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
41 import org.openecomp.sdc.ci.tests.utilities.OnboardingUiUtils;
42 import org.openqa.selenium.WebElement;
45 import java.util.LinkedList;
46 import java.util.List;
48 import java.util.Random;
49 import java.util.stream.Collectors;
51 import static org.testng.AssertJUnit.assertEquals;
52 import static org.testng.AssertJUnit.assertNotSame;
55 public class PathValidations {
57 public static String[] validateServiceExtendedPath(String vspName) throws Exception {
58 PathUtilities.linkVFs(vspName, 5);
59 PathUtilities.openCreatePath();
60 String pathName = "name1";
61 PathUtilities.insertValues(pathName, "pathProtocol1", "pathPortNumbers1");
62 PathUtilities.selectFirstLineParam();
63 PathValidations.extendPath(3);
65 PathUtilities.deleteLines(1, 3);
66 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.CREATE_BUTTON.getValue());
67 ExtentTestActions.log(Status.INFO, "path has been created");
68 PathValidations.checkPathFilter(pathName, true);
69 GeneralUIUtils.findElementsByXpath("//*[@data-tests-id='" + DataTestIdEnum.ComplexServiceAmdocs.PATH_MENU_BUTTON.getValue() + "']/parent::*").get(0).click();
70 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.PATH_LIST_BUTTON.getValue());
71 String PathListName1 = GeneralUIUtils.findByText(pathName).getText();
73 String newPathName = "name2";
74 PathUtilities.editPathName(pathName, newPathName);
76 GeneralUIUtils.findElementsByXpath("//*[@data-tests-id='" + DataTestIdEnum.ComplexServiceAmdocs.PATH_MENU_BUTTON.getValue() + "']/parent::*").get(0).click();
77 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.PATH_LIST_BUTTON.getValue());
78 String PathListName2 = GeneralUIUtils.findByText(newPathName).getText();
80 // assert names changed
81 assertNotSame("path name expected to change after edit but did not", PathListName1, PathListName2);
84 int paths_before_deletion = GeneralUIUtils.findElementsByXpath("//*[text()='" + newPathName + "']/parent::*//span").size();
85 GeneralUIUtils.findElementsByXpath(newPathName).get(1).click();
86 GeneralUIUtils.ultimateWait();
87 int paths_after_deletion = GeneralUIUtils.findElementsByXpath("//*[text()='" + newPathName + "']/parent::*//span").size();
88 assertNotSame("path expected to be deleted but did not", paths_after_deletion, paths_before_deletion);
90 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.PropertiesAssignmentScreen.INPUT_DELETE_DIALOG_CLOSE.getValue());
91 SetupCDTest.getExtendTest().log(Status.INFO, "Path has been created");
92 // check that path got deleted in the path filter list
93 PathValidations.checkPathFilter(newPathName, false);
94 return new String[] {pathName, newPathName};
97 public static String[] validateComplexExtendedPath(String[] services) throws Exception {
98 PathUtilities.linkServices(services[0], services[1], 5);
99 PathUtilities.openCreatePath();
100 String pathName = "name1";
101 PathUtilities.insertValues(pathName, "pathProtocol1", "pathPortNumbers");
102 PathUtilities.selectFirstLineParam();
104 PathValidations.extendPath(numOfLines);
106 PathUtilities.deleteLines(1, numOfLines);
107 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.CREATE_BUTTON.getValue());
108 ExtentTestActions.log(Status.INFO, "path has been created");
109 PathUtilities.openPathList();
110 String PathListName1 = GeneralUIUtils.findByText(pathName).getText();
111 String newPathName = "name2";
112 PathUtilities.editPathName(pathName, newPathName);
113 GeneralUIUtils.findElementsByXpath("//*[@data-tests-id='" + DataTestIdEnum.ComplexServiceAmdocs.PATH_MENU_BUTTON.getValue() + "']/parent::*").get(0).click();
114 GeneralUIUtils.ultimateWait();
115 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.PATH_LIST_BUTTON.getValue());
116 String PathListName2 = GeneralUIUtils.findByText(newPathName).getText();
118 // assert names changed
119 assertNotSame("path name expected to change after edit but did not", PathListName1, PathListName2);
122 int paths_before_deletion = GeneralUIUtils.findElementsByXpath("//*[text()='" + newPathName + "']/parent::*//span").size();
123 GeneralUIUtils.findElementsByXpath("//*[text()='" + newPathName + "']/parent::*//span").get(1).click();
124 GeneralUIUtils.ultimateWait();
126 int paths_after_deletion = GeneralUIUtils.findElementsByXpath("//*[text()='" + newPathName + "']/parent::*//span").size();
127 assertNotSame("path expected to be deleted but did not", paths_after_deletion, paths_before_deletion);
129 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.PropertiesAssignmentScreen.INPUT_DELETE_DIALOG_CLOSE.getValue());
130 PathValidations.validateServicePath(services[2], pathName);
131 PathValidations.validateServicePath(services[2], newPathName);
132 SetupCDTest.getExtendTest().log(Status.INFO, "Paths have been validated");
133 return new String[] {pathName, newPathName};
136 public static void createPathNumOfRows(int numOfPathRows)throws Exception{
137 PathUtilities.openCreatePath();
138 PathUtilities.insertValues("extended" + RandomStringUtils.randomAlphanumeric(8),"pathProtocol1", "pathPortNumbers1");
139 PathUtilities.selectFirstLineParam();
140 extendPath(numOfPathRows);
141 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.CREATE_BUTTON.getValue());
142 SetupCDTest.getExtendTest().log(Status.INFO, "Path with " + numOfPathRows + " rows has been created");
145 public static void extendPath(int numOfLines) throws Exception {
146 for (int i=0; i < numOfLines; i++) {
148 String index = Integer.toString(i + 2);
149 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.EXTEND_BUTTON.getValue());
151 List<WebElement> linkSrcs = GeneralUIUtils.findElementsByXpath("//*[@data-tests-id='"+DataTestIdEnum.ComplexServiceAmdocs.LINK_SOURCE.getValue()+"']//select");
152 List<WebElement> linkSrcCPs = GeneralUIUtils.findElementsByXpath("//*[@data-tests-id='"+DataTestIdEnum.ComplexServiceAmdocs.LINK_SOURCE_CP.getValue()+"']//select");
153 List<WebElement> linkTargets = GeneralUIUtils.findElementsByXpath("//*[@data-tests-id='"+DataTestIdEnum.ComplexServiceAmdocs.LINK_TARGET.getValue()+"']//select");
154 List<WebElement> linkTargetCPs = GeneralUIUtils.findElementsByXpath("//*[@data-tests-id='"+DataTestIdEnum.ComplexServiceAmdocs.LINK_TARGET_CP.getValue()+"']//select");
155 for (int j = 0; j < i + 2; j++) {
156 validateExtendedPathDisabledButtons(linkSrcs, j, "Source should be disabled. open bug to UI team");
157 check = linkSrcCPs.get(j).getAttribute("class");
158 validateElementDisabledAttribute(check, "Source connection point");
160 for (int j = 0; j < i + 1; j++) {
161 check = linkTargets.get(j).getAttribute("class");
162 validateElementDisabledAttribute(check, "Target");
163 check = linkTargetCPs.get(j).getAttribute("class");
164 validateElementDisabledAttribute(check, "Target connection point");
166 List <WebElement> choices = GeneralUIUtils.findElementsByXpath("//*[" + index + "]/*[@data-tests-id='"+DataTestIdEnum.ComplexServiceAmdocs.LINK_TARGET.getValue()+"']//option");
167 choices.get((new Random()).nextInt(choices.size())).click();
168 choices = GeneralUIUtils.findElementsByXpath("//*[" + index + "]/*[@data-tests-id='"+DataTestIdEnum.ComplexServiceAmdocs.LINK_TARGET_CP.getValue()+"']//option");
169 choices.get((new Random()).nextInt(choices.size())).click();
173 public static void validateElementDisabledAttribute(String check, String param) throws Exception{
174 assertEquals(param + " of last lines should be disabled", check.contains("disabled"), true);
177 public static void validateExtendedPathDisabledButtons(List<WebElement> linkSrcs, int i, String errMsg) throws Exception {
178 String check = linkSrcs.get(i).getAttribute("class");
179 assertEquals(errMsg, check.contains("disabled"), true);
182 public static void validatePathListIsEmpty() throws Exception {
183 PathUtilities.openPathList();
185 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.PATH_LIST_DELETE.getValue());
189 SetupCDTest.getExtendTest().log(Status.INFO, "path list is empty");
191 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.CLOSE.getValue());
194 public static void AssertNameChangeFromPathList(String PathListName1, String PathListName2) throws Exception {
195 assertNotSame("path name is expected to change after edit", PathListName1, PathListName2);
198 public static void ValidateAndDeletePathFromPathList(String pathName) throws Exception {
200 List<WebElement> path_list_name = GeneralUIUtils.getWebElementsListByTestID(DataTestIdEnum.ComplexServiceAmdocs.PATH_LIST_NAME.getValue());
202 List<WebElement> path_delete = GeneralUIUtils.getWebElementsListByTestID(DataTestIdEnum.ComplexServiceAmdocs.PATH_LIST_DELETE.getValue());
203 int paths_before_deletion = 0;
204 for (int i = 0; i < path_list_name.size(); i++) {
205 if (path_list_name.get(i).getText().equals(pathName)) {
206 paths_before_deletion++;
207 path_delete.get(i).click();
210 int paths_after_deletion = 0;
211 List<WebElement> path_list_name2;
213 path_list_name2 = GeneralUIUtils.getWebElementsListByTestID(DataTestIdEnum.ComplexServiceAmdocs.PATH_LIST_NAME.getValue());
214 for (WebElement path_list_element : path_list_name2) {
215 if (path_list_element.getText().equals(pathName)) {
216 paths_after_deletion++;
219 } catch (Exception ignore) {}
221 assertNotSame("path is expected to be deleted", paths_after_deletion, paths_before_deletion);
224 public static void checkPathFilter(String pathName, boolean isFound) throws Exception{
225 List<WebElement> pathFilterList = GeneralUIUtils.findElementsByXpath("//*[@data-tests-id='"+DataTestIdEnum.ComplexServiceAmdocs.SERVICE_PATH_SELECTOR.getValue()+"']//option");
226 GeneralUIUtils.ultimateWait();
227 if (isFound) for (int i = 0; i < pathFilterList.size(); i++) {
228 String element_text = pathFilterList.get(i).getText();
229 if (element_text.equals(pathName)) break;
230 assertNotSame("path filter list is missing a path", i, pathFilterList.size() - 1);
232 else for (WebElement aPathFilterList : pathFilterList) {
233 String element_text = aPathFilterList.getText();
234 assertNotSame("path filter list is has a path that should be deleted", element_text, pathName);
236 SetupCDTest.getExtendTest().log(Status.INFO, "path list filter check passed");
239 public static void AssertCreatePath() throws Exception {
240 String check = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ComplexServiceAmdocs.CREATE_BUTTON.getValue()).getAttribute("disabled");
241 assertEquals("create button path should be disabled", check, "true");
244 public static void AssertCreatedPathExistInCompositionPage(String pathName) throws Exception {
245 checkPathFilter(pathName, true);
246 PathUtilities.openPathList();
248 // assert path is in the list
249 GeneralUIUtils.findByText(pathName).getText();
250 GeneralUIUtils.ultimateWait();
251 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.PropertiesAssignmentScreen.INPUT_DELETE_DIALOG_CLOSE.getValue());
252 // GeneralUIUtils.ultimateWait();
253 SetupCDTest.getExtendTest().log(Status.INFO, "Path is in the path list");
254 // GeneralUIUtils.ultimateWait();
257 public static void AssertExtendPath() throws Exception {
258 String check = GeneralUIUtils.getWebElementsListByTestID(DataTestIdEnum.ComplexServiceAmdocs.EXTEND_BUTTON.getValue()).get(0).getAttribute("class");
259 assertEquals("Extend button should be disabled", check, "disabled");
262 public static Pair<RestResponse, ServiceReqDetails> validateServicePath(String serviceName, String name) throws Exception {
263 Pair<RestResponse, ServiceReqDetails> servicePaths = PathUtilities.getServicePathsAPI(serviceName);
264 String response = servicePaths.left.getResponse();
266 JSONObject jsonResponse = new JSONObject(response);
267 JSONObject forwardingPaths = jsonResponse.getJSONObject("forwardingPaths");
268 Boolean validation_complete = Boolean.FALSE;
269 for (Object key : forwardingPaths.keySet()){
270 String keyStr = (String)key;
271 JSONObject forwardingPath = forwardingPaths.getJSONObject(keyStr);
272 if (forwardingPath.getString("name").equals(name)) {
273 JSONObject pathElements = forwardingPath.getJSONObject("pathElements");
274 Boolean empty = pathElements.getBoolean("empty");
275 assertEquals("assert pathElements are not empty", empty, Boolean.FALSE);
276 validation_complete = Boolean.TRUE;
280 assertEquals("validation success", validation_complete, Boolean.TRUE);
284 public static void ValidateThereIsNoErrorMessage() throws Exception {
286 GeneralUIUtils.findElementsByXpath("//*[@data-tests-id='" + DataTestIdEnum.ComplexServiceAmdocs.OK.getValue() + "']");
287 throw new Exception("element should not be found");
288 } catch (Exception e) {
289 if (e.getMessage().equals("element should not be found")) {
295 public static void validateEditToExistingName(String firstPathName, String secondPathName)throws Exception {
296 PathUtilities.openPathList();
297 PathUtilities.editPathName(secondPathName, firstPathName);
299 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.OK.getValue());
300 } catch (Exception e) {
301 throw new Exception("when creating another path with duplicate name, expected error did not appear");
303 PathUtilities.openPathList();
304 PathUtilities.editPathName(secondPathName, firstPathName + " ");
306 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.OK.getValue());
307 } catch (Exception e) {
308 throw new Exception("space in beggining or end does not count. when creating another path with duplicate name, expected error did not appear");
310 PathUtilities.openPathList();
311 PathUtilities.editPathName(secondPathName," " + firstPathName);
313 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.OK.getValue());
314 } catch (Exception e) {
315 throw new Exception("space in beggining or end does not count. when creating another path with duplicate name, expected error did not appear");
317 PathUtilities.openPathList();
318 PathUtilities.editPathProtocol(secondPathName, "pathProtocol2");
321 public static void validateNameWithSpaces(String pathName, String vspName) throws Exception{
322 PathUtilities.createPath(pathName + " ", vspName);
323 PathUtilities.openPathList();
324 PathUtilities.editPathName(pathName, "newName");
325 PathUtilities.createPathWithoutLink(" " + pathName, vspName);
326 PathUtilities.openPathList();
327 PathUtilities.editPathName(pathName, "newName2");
330 public static void importAndVerifyVSP(VendorSoftwareProductObject createVendorSoftwareProduct, String filepath, String vnfFile) throws Exception {
331 DownloadManager.downloadCsarByNameFromVSPRepository(createVendorSoftwareProduct.getName(), createVendorSoftwareProduct.getVspId());
332 File latestFilefromDir = FileHandling.getLastModifiedFileNameFromDir();
334 OnboardingUiUtils.importVSP(createVendorSoftwareProduct);
336 ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
338 // Verify deployment artifacts
339 Map<String, Object> combinedMap = ArtifactFromCsar.combineHeatArtifacstWithFolderArtifacsToMap(latestFilefromDir.getAbsolutePath());
341 LinkedList<HeatMetaFirstLevelDefinition> deploymentArtifacts = ((LinkedList<HeatMetaFirstLevelDefinition>) combinedMap.get("Deployment"));
342 ArtifactsCorrelationManager.addVNFartifactDetails(vnfFile, deploymentArtifacts);
344 List<String> heatEnvFilesFromCSAR = deploymentArtifacts.stream().filter(e -> e.getType().equals("HEAT_ENV")).
345 map(e -> e.getFileName()).
346 collect(Collectors.toList());
348 OnboardingUiUtils.validateDeploymentArtifactsVersion(deploymentArtifacts, heatEnvFilesFromCSAR);
350 DeploymentArtifactPage.verifyArtifactsExistInTable(filepath, vnfFile);