diff options
author | 2020-03-03 12:04:15 +0000 | |
---|---|---|
committer | 2020-03-03 12:04:15 +0000 | |
commit | 47bd03a0353f37ce2c4f2749e40ebd6fd3e93363 (patch) | |
tree | 634d3fbef70b905d9f252f3611036e3390741570 /vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/CanvasManager.java | |
parent | 48781cf7a2ce980c75bb7844b90dbd8194f09989 (diff) | |
parent | 9cb90d378b4cc8cc81acdd85ea2534ae0a2ad392 (diff) |
Merge "Remove dead code in automation's utils"
Diffstat (limited to 'vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/CanvasManager.java')
-rw-r--r-- | vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/CanvasManager.java | 179 |
1 files changed, 0 insertions, 179 deletions
diff --git a/vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/CanvasManager.java b/vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/CanvasManager.java deleted file mode 100644 index 91011f333..000000000 --- a/vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/CanvasManager.java +++ /dev/null @@ -1,179 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.sdc.ci.tests.utilities; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.UUID; -import java.util.stream.Collectors; - -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.onap.sdc.ci.tests.datatypes.DataTestIdEnum; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.interactions.Actions; - -public final class CanvasManager { - private Map<String, CanvasElement> canvasElements; - private Actions actions; - private WebElement canvas; - private int reduceCanvasWidthFactor; - // Offsets Are used to find upper right corner of canvas element in order to - // connect links - private static final int CANVAS_ELEMENT_Y_OFFSET = 40; - private static final int CANVAS_ELEMENT_X_OFFSET = 21; // 14 - 27 - - private CanvasManager() { - canvasElements = new HashMap<>(); - actions = new Actions(GeneralUIUtils.getDriver()); - canvas = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralCanvasItems.CANVAS.getValue()); - try { - WebElement webElement = GeneralUIUtils - .getWebElementByTestID(DataTestIdEnum.GeneralCanvasItems.CANVAS_RIGHT_PANEL.getValue()); - reduceCanvasWidthFactor = webElement.getSize().width; - } catch (Exception e) { - reduceCanvasWidthFactor = 0; - } - } - - public static CanvasManager getCanvasManager() { - return new CanvasManager(); - } - - public List<CanvasElement> getCanvasElements() { - return canvasElements.values().stream().collect(Collectors.toList()); - } - - private void addCanvasElement(CanvasElement element) { - canvasElements.put(element.getUniqueId(), element); - } - - private void moveElementOnCanvas(CanvasElement canvasElement, ImmutablePair<Integer, Integer> newLocation) - throws Exception { - GeneralUIUtils.waitForLoader(); - Thread.sleep(500); - actions.moveToElement(canvas, canvasElement.getLocation().left, canvasElement.getLocation().right); - actions.clickAndHold(); - actions.moveToElement(canvas, newLocation.left, newLocation.right); - actions.release(); - actions.perform(); - canvasElement.setLocation(newLocation); - GeneralUIUtils.waitForLoader(); - - } - - public void moveElementOnCanvas(CanvasElement canvasElement) throws Exception { - moveElementOnCanvas(canvasElement, getFreePosition()); - } - - public void deleteElementFromCanvas(CanvasElement canvasElement) throws Exception { - GeneralUIUtils.waitForLoader(); - actions.moveToElement(canvas, canvasElement.getLocation().left, canvasElement.getLocation().right); - actions.click(); - actions.perform(); - GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralCanvasItems.DELETE_INSTANCE_BUTTON.getValue()) - .click(); - GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ModalItems.OK.getValue()).click(); - canvasElements.remove(canvasElement.getUniqueId()); - GeneralUIUtils.waitForLoader(); - } - - private String getItemName(WebElement canvasItem) { - String canvasItemName = canvasItem.getAttribute("data-tests-id"); - - return canvasItemName.substring(canvasItemName.lastIndexOf("-")); - } - - public CanvasElement createElementOnCanvas(WebElement canvasItem) throws Exception { - GeneralUIUtils.waitForLoader(); - ImmutablePair<Integer, Integer> freePosition = getFreePosition(); - actions.moveToElement(canvasItem, 0, 0); - actions.clickAndHold(); - actions.moveToElement(canvas, freePosition.left, freePosition.right); - actions.release(); - actions.perform(); - - String uniqueId = getItemName(canvasItem) + "_" + UUID.randomUUID().toString(); - CanvasElement canvasElement = new CanvasElement(uniqueId, freePosition, canvasItem); - addCanvasElement(canvasElement); - GeneralUIUtils.waitForLoader(); - return canvasElement; - } - - private ImmutablePair<Integer, Integer> getFreePosition() { - // TODO mshitrit use better method - ImmutablePair<Integer, Integer> randomPosition = null; - boolean freePosition = false; - int minSpace = 150; - while (!freePosition) { - ImmutablePair<Integer, Integer> tempRandomPosition = getRandomPosition(); - freePosition = !canvasElements.values().stream().map(e -> e.getLocation()) - .filter(e -> Math.abs(e.left - tempRandomPosition.left) < minSpace - && Math.abs(e.right - tempRandomPosition.right) < minSpace) - .findAny().isPresent(); - randomPosition = tempRandomPosition; - } - return randomPosition; - } - - private ImmutablePair<Integer, Integer> getRandomPosition() { - int edgeBuffer = 50; - Random random = new Random(); - int xElement = random.nextInt(canvas.getSize().width - 2 * edgeBuffer - reduceCanvasWidthFactor) + edgeBuffer; - int yElement = random.nextInt(canvas.getSize().height - 2 * edgeBuffer) + edgeBuffer; - return new ImmutablePair<Integer, Integer>(xElement, yElement); - } - - public void linkElements(CanvasElement firstElement, CanvasElement secondElement) throws Exception { - GeneralUIUtils.waitForLoader(); - drawSimpleLink(firstElement, secondElement); - - selectReqAndCapAndConnect(); - - GeneralUIUtils.waitForLoader(); - - } - - private void selectReqAndCapAndConnect() { - // Select First Cap - GeneralUIUtils.getWebElementsListByTestID(DataTestIdEnum.LinkMenuItems.LINK_ITEM_CAP.getValue()).get(0).click(); - // Select First Req - GeneralUIUtils.getWebElementsListByTestID(DataTestIdEnum.LinkMenuItems.LINK_ITEM_REQ.getValue()).get(0).click(); - // Connect - GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.LinkMenuItems.CONNECT_BUTTON.getValue()).click(); - } - - private void drawSimpleLink(CanvasElement firstElement, CanvasElement secondElement) { - - int yOffset = CANVAS_ELEMENT_Y_OFFSET; - int xOffset = CANVAS_ELEMENT_X_OFFSET; - - actions.moveToElement(canvas, firstElement.getLocation().left + xOffset, - firstElement.getLocation().right - yOffset); - - actions.clickAndHold(); - actions.moveToElement(canvas, secondElement.getLocation().left + xOffset, - secondElement.getLocation().right - yOffset); - actions.release(); - actions.perform(); - } -} |