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.onap.sdc.frontend.ci.tests.execute.AmdocsComplexService;
23 import com.aventstack.extentreports.Status;
24 import com.clearspring.analytics.util.Pair;
25 import org.apache.commons.lang3.RandomStringUtils;
26 import org.json.JSONObject;
27 import org.onap.sdc.frontend.ci.tests.datatypes.DataTestIdEnum;
28 import org.onap.sdc.backend.ci.tests.datatypes.HeatMetaFirstLevelDefinition;
29 import org.onap.sdc.backend.ci.tests.datatypes.ServiceReqDetails;
30 import org.onap.sdc.backend.ci.tests.datatypes.VendorSoftwareProductObject;
31 import org.onap.sdc.backend.ci.tests.datatypes.http.RestResponse;
32 import org.onap.sdc.backend.ci.tests.execute.devCI.ArtifactFromCsar;
33 import org.onap.sdc.frontend.ci.tests.pages.DeploymentArtifactPage;
34 import org.onap.sdc.frontend.ci.tests.utilities.DownloadManager;
35 import org.onap.sdc.frontend.ci.tests.utilities.FileHandling;
36 import org.onap.sdc.frontend.ci.tests.utilities.GeneralUIUtils;
37 import org.onap.sdc.frontend.ci.tests.utilities.OnboardingUiUtils;
38 import org.onap.sdc.frontend.ci.tests.execute.setup.ArtifactsCorrelationManager;
39 import org.onap.sdc.frontend.ci.tests.execute.setup.ExtentTestActions;
40 import org.onap.sdc.frontend.ci.tests.execute.setup.SetupCDTest;
41 import org.onap.sdc.frontend.ci.tests.pages.ResourceGeneralPage;
42 import org.openqa.selenium.WebElement;
46 import java.util.stream.Collectors;
48 import static org.testng.AssertJUnit.assertEquals;
49 import static org.testng.AssertJUnit.assertNotSame;
52 public class PathValidations {
55 public static final int NUMBER_OF_LINKS = 5;
56 public static final int NUMBER_OF_LINES = 3;
57 public static final int NUMBER_OF_LINES_TO_DELETE = 1;
59 public static String[] validateServiceExtendedPath(String vspName) throws Exception {
60 PathUtilities.linkVFs(vspName, NUMBER_OF_LINKS);
61 PathUtilities.openCreatePath();
62 String pathName = "name1";
63 PathUtilities.insertValues(pathName, "pathProtocol1", "pathPortNumbers1");
64 PathUtilities.selectFirstLineParam();
65 PathValidations.extendPath(NUMBER_OF_LINES);
67 PathUtilities.deleteLines(NUMBER_OF_LINES_TO_DELETE, NUMBER_OF_LINES);
68 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.CREATE_BUTTON.getValue());
69 ExtentTestActions.log(Status.INFO, "path has been created");
70 PathValidations.checkPathFilter(pathName, true);
71 GeneralUIUtils.findElementsByXpath("//*[@data-tests-id='" + DataTestIdEnum.ComplexServiceAmdocs.PATH_MENU_BUTTON.getValue() + "']/parent::*").get(0).click();
72 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.PATH_LIST_BUTTON.getValue());
73 String PathListName1 = GeneralUIUtils.findByText(pathName).getText();
75 String newPathName = "name2";
76 PathUtilities.editPathName(pathName, newPathName);
78 GeneralUIUtils.findElementsByXpath("//*[@data-tests-id='" + DataTestIdEnum.ComplexServiceAmdocs.PATH_MENU_BUTTON.getValue() + "']/parent::*").get(0).click();
79 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.PATH_LIST_BUTTON.getValue());
80 String PathListName2 = GeneralUIUtils.findByText(newPathName).getText();
82 // assert names changed
83 assertNotSame("path name expected to change after edit but did not", PathListName1, PathListName2);
86 int paths_before_deletion = GeneralUIUtils.findElementsByXpath("//*[text()='" + newPathName + "']/parent::*//span").size();
87 GeneralUIUtils.findElementsByXpath(newPathName).get(1).click();
88 GeneralUIUtils.ultimateWait();
89 int paths_after_deletion = GeneralUIUtils.findElementsByXpath("//*[text()='" + newPathName + "']/parent::*//span").size();
90 assertNotSame("path expected to be deleted but did not", paths_after_deletion, paths_before_deletion);
92 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.PropertiesAssignmentScreen.INPUT_DELETE_DIALOG_CLOSE.getValue());
93 SetupCDTest.getExtendTest().log(Status.INFO, "Path has been created");
94 // check that path got deleted in the path filter list
95 PathValidations.checkPathFilter(newPathName, false);
96 return new String[]{pathName, newPathName};
99 public static String[] validateComplexExtendedPath(String[] services) throws Exception {
100 PathUtilities.linkServices(services[0], services[1], NUMBER_OF_LINKS);
101 PathUtilities.openCreatePath();
102 String pathName = "name1";
103 PathUtilities.insertValues(pathName, "pathProtocol1", "pathPortNumbers");
104 PathUtilities.selectFirstLineParam();
105 PathValidations.extendPath(NUMBER_OF_LINES);
107 PathUtilities.deleteLines(NUMBER_OF_LINES_TO_DELETE, NUMBER_OF_LINES);
108 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.CREATE_BUTTON.getValue());
109 ExtentTestActions.log(Status.INFO, "path has been created");
110 PathUtilities.openPathList();
111 String PathListName1 = GeneralUIUtils.findByText(pathName).getText();
112 String newPathName = "name2";
113 PathUtilities.editPathName(pathName, newPathName);
114 GeneralUIUtils.findElementsByXpath("//*[@data-tests-id='" + DataTestIdEnum.ComplexServiceAmdocs.PATH_MENU_BUTTON.getValue() + "']/parent::*").get(0).click();
115 GeneralUIUtils.ultimateWait();
116 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.PATH_LIST_BUTTON.getValue());
117 String PathListName2 = GeneralUIUtils.findByText(newPathName).getText();
119 // assert names changed
120 assertNotSame("path name expected to change after edit but did not", PathListName1, PathListName2);
123 int paths_before_deletion = GeneralUIUtils.findElementsByXpath("//*[text()='" + newPathName + "']/parent::*//span").size();
124 GeneralUIUtils.findElementsByXpath("//*[text()='" + newPathName + "']/parent::*//span").get(1).click();
125 GeneralUIUtils.ultimateWait();
127 int paths_after_deletion = GeneralUIUtils.findElementsByXpath("//*[text()='" + newPathName + "']/parent::*//span").size();
128 assertNotSame("path expected to be deleted but did not", paths_after_deletion, paths_before_deletion);
130 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.PropertiesAssignmentScreen.INPUT_DELETE_DIALOG_CLOSE.getValue());
131 PathValidations.validateServicePath(services[2], pathName);
132 PathValidations.validateServicePath(services[2], newPathName);
133 SetupCDTest.getExtendTest().log(Status.INFO, "Paths have been validated");
134 return new String[]{pathName, newPathName};
137 public static void createPathNumOfRows(int numOfPathRows) throws Exception {
138 final int numberOfRandomCharacters = 8;
139 PathUtilities.openCreatePath();
140 PathUtilities.insertValues("extended" + RandomStringUtils.randomAlphanumeric(numberOfRandomCharacters), "pathProtocol1", "pathPortNumbers1");
141 PathUtilities.selectFirstLineParam();
142 extendPath(numOfPathRows);
143 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.CREATE_BUTTON.getValue());
144 SetupCDTest.getExtendTest().log(Status.INFO, "Path with " + numOfPathRows + " rows has been created");
147 public static void extendPath(int numOfLines) throws Exception {
148 for (int i = 0; i < numOfLines; i++) {
150 String index = Integer.toString(i + 2);
151 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.EXTEND_BUTTON.getValue());
153 List<WebElement> linkSrcs = GeneralUIUtils.findElementsByXpath("//*[@data-tests-id='" + DataTestIdEnum.ComplexServiceAmdocs.LINK_SOURCE.getValue() + "']//select");
154 List<WebElement> linkSrcCPs = GeneralUIUtils.findElementsByXpath("//*[@data-tests-id='" + DataTestIdEnum.ComplexServiceAmdocs.LINK_SOURCE_CP.getValue() + "']//select");
155 List<WebElement> linkTargets = GeneralUIUtils.findElementsByXpath("//*[@data-tests-id='" + DataTestIdEnum.ComplexServiceAmdocs.LINK_TARGET.getValue() + "']//select");
156 List<WebElement> linkTargetCPs = GeneralUIUtils.findElementsByXpath("//*[@data-tests-id='" + DataTestIdEnum.ComplexServiceAmdocs.LINK_TARGET_CP.getValue() + "']//select");
157 for (int j = 0; j < i + 2; j++) {
158 validateExtendedPathDisabledButtons(linkSrcs, j, "Source should be disabled. open bug to UI team");
159 check = linkSrcCPs.get(j).getAttribute("class");
160 validateElementDisabledAttribute(check, "Source connection point");
162 for (int j = 0; j < i + 1; j++) {
163 check = linkTargets.get(j).getAttribute("class");
164 validateElementDisabledAttribute(check, "Target");
165 check = linkTargetCPs.get(j).getAttribute("class");
166 validateElementDisabledAttribute(check, "Target connection point");
168 List<WebElement> choices = GeneralUIUtils.findElementsByXpath("//*[" + index + "]/*[@data-tests-id='" + DataTestIdEnum.ComplexServiceAmdocs.LINK_TARGET.getValue() + "']//option");
169 choices.get((new Random()).nextInt(choices.size())).click();
170 choices = GeneralUIUtils.findElementsByXpath("//*[" + index + "]/*[@data-tests-id='" + DataTestIdEnum.ComplexServiceAmdocs.LINK_TARGET_CP.getValue() + "']//option");
171 choices.get((new Random()).nextInt(choices.size())).click();
175 public static void validateElementDisabledAttribute(String check, String param) throws Exception {
176 assertEquals(param + " of last lines should be disabled", check.contains("disabled"), true);
179 public static void validateExtendedPathDisabledButtons(List<WebElement> linkSrcs, int i, String errMsg) throws Exception {
180 String check = linkSrcs.get(i).getAttribute("class");
181 assertEquals(errMsg, check.contains("disabled"), true);
184 public static void validatePathListIsEmpty() throws Exception {
185 PathUtilities.openPathList();
187 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.PATH_LIST_DELETE.getValue());
188 } catch (Exception e) {
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) {
222 assertNotSame("path is expected to be deleted", paths_after_deletion, paths_before_deletion);
225 public static void checkPathFilter(String pathName, boolean isFound) throws Exception {
226 List<WebElement> pathFilterList = GeneralUIUtils.findElementsByXpath("//*[@data-tests-id='" + DataTestIdEnum.ComplexServiceAmdocs.SERVICE_PATH_SELECTOR.getValue() + "']//option");
227 GeneralUIUtils.ultimateWait();
229 for (int i = 0; i < pathFilterList.size(); i++) {
230 String element_text = pathFilterList.get(i).getText();
231 if (element_text.equals(pathName)) {
234 assertNotSame("path filter list is missing a path", i, pathFilterList.size() - 1);
237 for (WebElement aPathFilterList : pathFilterList) {
238 String element_text = aPathFilterList.getText();
239 assertNotSame("path filter list is has a path that should be deleted", element_text, pathName);
242 SetupCDTest.getExtendTest().log(Status.INFO, "path list filter check passed");
245 public static void AssertCreatePath() throws Exception {
246 String check = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ComplexServiceAmdocs.CREATE_BUTTON.getValue()).getAttribute("disabled");
247 assertEquals("create button path should be disabled", check, "true");
250 public static void AssertCreatedPathExistInCompositionPage(String pathName) throws Exception {
251 checkPathFilter(pathName, true);
252 PathUtilities.openPathList();
254 // assert path is in the list
255 GeneralUIUtils.findByText(pathName).getText();
256 GeneralUIUtils.ultimateWait();
257 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.PropertiesAssignmentScreen.INPUT_DELETE_DIALOG_CLOSE.getValue());
258 // GeneralUIUtils.ultimateWait();
259 SetupCDTest.getExtendTest().log(Status.INFO, "Path is in the path list");
260 // GeneralUIUtils.ultimateWait();
263 public static void AssertExtendPath() throws Exception {
264 String check = GeneralUIUtils.getWebElementsListByTestID(DataTestIdEnum.ComplexServiceAmdocs.EXTEND_BUTTON.getValue()).get(0).getAttribute("class");
265 assertEquals("Extend button should be disabled", check, "disabled");
268 public static Pair<RestResponse, ServiceReqDetails> validateServicePath(String serviceName, String name) throws Exception {
269 Pair<RestResponse, ServiceReqDetails> servicePaths = PathUtilities.getServicePathsAPI(serviceName);
270 String response = servicePaths.left.getResponse();
272 JSONObject jsonResponse = new JSONObject(response);
273 JSONObject forwardingPaths = jsonResponse.getJSONObject("forwardingPaths");
274 Boolean validation_complete = Boolean.FALSE;
275 for (Iterator it = forwardingPaths.keys(); it.hasNext(); ) {
276 Object key = it.next();
277 String keyStr = (String) key;
278 JSONObject forwardingPath = forwardingPaths.getJSONObject(keyStr);
279 if (forwardingPath.getString("name").equals(name)) {
280 JSONObject pathElements = forwardingPath.getJSONObject("pathElements");
281 Boolean empty = pathElements.getBoolean("empty");
282 assertEquals("assert pathElements are not empty", empty, Boolean.FALSE);
283 validation_complete = Boolean.TRUE;
287 assertEquals("validation success", validation_complete, Boolean.TRUE);
291 public static void ValidateThereIsNoErrorMessage() throws Exception {
293 GeneralUIUtils.findElementsByXpath("//*[@data-tests-id='" + DataTestIdEnum.ComplexServiceAmdocs.OK.getValue() + "']");
294 throw new Exception("element should not be found");
295 } catch (Exception e) {
296 if (e.getMessage().equals("element should not be found")) {
302 public static void validateEditToExistingName(String firstPathName, String secondPathName) throws Exception {
303 PathUtilities.openPathList();
304 PathUtilities.editPathName(secondPathName, firstPathName);
306 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.OK.getValue());
307 } catch (Exception e) {
308 throw new Exception("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.editPathName(secondPathName, " " + firstPathName);
320 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.OK.getValue());
321 } catch (Exception e) {
322 throw new Exception("space in beggining or end does not count. when creating another path with duplicate name, expected error did not appear");
324 PathUtilities.openPathList();
325 PathUtilities.editPathProtocol(secondPathName, "pathProtocol2");
328 public static void validateNameWithSpaces(String pathName, String vspName) throws Exception {
329 PathUtilities.createPath(pathName + " ", vspName);
330 PathUtilities.openPathList();
331 PathUtilities.editPathName(pathName, "newName");
332 PathUtilities.createPathWithoutLink(" " + pathName, vspName);
333 PathUtilities.openPathList();
334 PathUtilities.editPathName(pathName, "newName2");
337 public static void importAndVerifyVSP(VendorSoftwareProductObject createVendorSoftwareProduct, String filepath, String vnfFile) throws Exception {
338 DownloadManager.downloadCsarByNameFromVSPRepository(createVendorSoftwareProduct.getName(), createVendorSoftwareProduct.getVspId());
339 File latestFilefromDir = FileHandling.getLastModifiedFileNameFromDir();
341 OnboardingUiUtils.importVSP(createVendorSoftwareProduct);
343 ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
345 // Verify deployment artifacts
346 Map<String, Object> combinedMap = ArtifactFromCsar.combineHeatArtifacstWithFolderArtifacsToMap(latestFilefromDir.getAbsolutePath());
348 LinkedList<HeatMetaFirstLevelDefinition> deploymentArtifacts = ((LinkedList<HeatMetaFirstLevelDefinition>) combinedMap.get("Deployment"));
349 ArtifactsCorrelationManager.addVNFartifactDetails(vnfFile, deploymentArtifacts);
351 List<String> heatEnvFilesFromCSAR = deploymentArtifacts.stream().filter(e -> e.getType().equals("HEAT_ENV")).
352 map(e -> e.getFileName()).
353 collect(Collectors.toList());
355 OnboardingUiUtils.validateDeploymentArtifactsVersion(deploymentArtifacts, heatEnvFilesFromCSAR);
357 DeploymentArtifactPage.verifyArtifactsExistInTable(filepath, vnfFile);