diff options
Diffstat (limited to 'vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities')
7 files changed, 1 insertions, 526 deletions
diff --git a/vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/CanvasElement.java b/vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/CanvasElement.java deleted file mode 100644 index 2ff28dabd..000000000 --- a/vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/CanvasElement.java +++ /dev/null @@ -1,53 +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 org.apache.commons.lang3.tuple.ImmutablePair; -import org.openqa.selenium.WebElement; - -public final class CanvasElement { - private final String uniqueId; - private ImmutablePair<Integer, Integer> location; - private WebElement elementType; - - CanvasElement(String name, ImmutablePair<Integer, Integer> location, WebElement canvasItem) { - super(); - this.uniqueId = name; - this.location = location; - elementType = canvasItem; - } - - public String getUniqueId() { - return uniqueId; - } - - public ImmutablePair<Integer, Integer> getLocation() { - return location; - } - - public void setLocation(ImmutablePair<Integer, Integer> location) { - this.location = location; - } - - public WebElement getElementType() { - return elementType; - } -} 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(); - } -} diff --git a/vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/Decoder.java b/vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/Decoder.java deleted file mode 100644 index 049302e54..000000000 --- a/vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/Decoder.java +++ /dev/null @@ -1,62 +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.io.BufferedReader; -import java.io.FileReader; -import java.io.IOException; - -import org.apache.commons.codec.binary.Base64; - -public class Decoder { - - public static String encode(byte[] byteArrayToEncode) { - - byte[] bytesEncoded = Base64.encodeBase64(byteArrayToEncode); - String strEncoded = new String(bytesEncoded); - return strEncoded; - } - - public static String decode(String strEncoded) throws IOException { - - byte[] byteDecoded = Base64.decodeBase64(strEncoded); - String decoded = new String(byteDecoded); - - return decoded; - - } - - public static String readFileToString(String file) throws IOException { - - BufferedReader reader = new BufferedReader(new FileReader(file)); - String line = null; - StringBuilder stringBuilder = new StringBuilder(); - String ls = System.getProperty("line.separator"); - - while ((line = reader.readLine()) != null) { - stringBuilder.append(line); - stringBuilder.append(ls); - } - reader.close(); - return stringBuilder.toString(); - } - -} diff --git a/vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/EcompPortalUtilities.java b/vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/EcompPortalUtilities.java deleted file mode 100644 index 97938c741..000000000 --- a/vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/EcompPortalUtilities.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.onap.sdc.ci.tests.utilities; - -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; - -public class EcompPortalUtilities { - - public static void swichFrames(By by){ - WebElement appImage = GeneralUIUtils.getClickableButtonBy(by, 3 * 60); - appImage.click(); - GeneralUIUtils.getDriver().switchTo().frame(1); - GeneralUIUtils.waitForAngular(); - GeneralUIUtils.getWebElementByClassName("applicationWindow"); - } - -} diff --git a/vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/FileHandling.java b/vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/FileHandling.java index 029555a91..71e9b1c86 100644 --- a/vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/FileHandling.java +++ b/vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/FileHandling.java @@ -22,6 +22,7 @@ package org.onap.sdc.ci.tests.utilities; import static org.testng.AssertJUnit.assertTrue; +import com.aventstack.extentreports.Status; import java.io.BufferedOutputStream; import java.io.BufferedWriter; import java.io.File; @@ -43,14 +44,11 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipException; import java.util.zip.ZipFile; import java.util.zip.ZipInputStream; - import org.apache.commons.io.FileUtils; import org.onap.sdc.ci.tests.execute.setup.ExtentTestActions; import org.onap.sdc.ci.tests.execute.setup.SetupCDTest; import org.yaml.snakeyaml.Yaml; -import com.aventstack.extentreports.Status; - public class FileHandling { // ------------------yaml parser methods---------------------------- @@ -312,12 +310,6 @@ public class FileHandling { return flag; } - public static String getMD5OfFile(File file) throws IOException { - String content = FileUtils.readFileToString(file); - String md5 = GeneralUtility.calculateMD5ByString(content); - return md5; - } - public static File createEmptyFile(String fileToCreate) { File file= new File(fileToCreate); try { diff --git a/vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/FindUtils.java b/vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/FindUtils.java deleted file mode 100644 index 2b0ca66da..000000000 --- a/vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/FindUtils.java +++ /dev/null @@ -1,52 +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 org.onap.sdc.ci.tests.datatypes.DataTestIdEnum; -import org.onap.sdc.ci.tests.execute.setup.SetupCDTest; -import org.openqa.selenium.WebElement; -import org.testng.Assert; - -import com.aventstack.extentreports.Status; - -public final class FindUtils { - - - public static void findComponentAndClick(String componentName) throws Exception { - SetupCDTest.getExtendTest().log(Status.INFO, "finding component " + componentName); - GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtons.SEARCH_BOX.getValue()).sendKeys(componentName); - WebElement foundComp = null; - try { - foundComp = GeneralUIUtils.getWebElementByTestID(componentName); - foundComp.click(); - GeneralUIUtils.waitForLoader(); - GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.LIFECYCLE_STATE.getValue()); - } catch (Exception e) { - String msg = String.format("DID NOT FIND A COMPONENT NAMED %s", componentName); - SetupCDTest.getExtendTest().log(Status.FAIL, msg); - System.out.println(msg); - Assert.fail(msg); - } - } - - - -} diff --git a/vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/GeneralUtility.java b/vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/GeneralUtility.java deleted file mode 100644 index f2e834e03..000000000 --- a/vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/GeneralUtility.java +++ /dev/null @@ -1,155 +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.io.File; -import java.io.IOException; -import java.util.List; -import java.util.regex.Pattern; - -import org.apache.commons.codec.binary.Base64; -import org.apache.commons.io.FileUtils; - -public class GeneralUtility { - - public static boolean generateTextFile(String fileName, String fileData) { - boolean isSuccessfull = true; - try { - FileUtils.writeStringToFile(new File(fileName), fileData); - } catch (IOException e) { - isSuccessfull = false; - } - return isSuccessfull; - } - - /** - * Use with care, usage is not advised!!! - * The method only checks if String does not contain special characters + length divided by 4 with no remainder. - * The methods contained in other common libraries do the same. - */ - public static boolean isBase64Encoded(byte[] data) { - return Base64.isBase64(data); - } - - /** - *Use with care, usage is not advised!!! - * The method only checks if String does not contain special characters + length divided by 4 with no remainder. - * The methods contained in other common libraries do the same. - */ - public static boolean isBase64Encoded(String str) { - boolean isEncoded = false; - try { - // checks if the string was properly padded to the - isEncoded = ((str.length() % 4 == 0) && (Pattern.matches("\\A[a-zA-Z0-9/+]+={0,2}\\z", str))); - if (isEncoded) { - // If no exception is caught, then it is possibly a base64 - // encoded string - byte[] data = Base64.decodeBase64(str); - } - - } catch (Exception e) { - // If exception is caught, then it is not a base64 encoded string - isEncoded = false; - } - return isEncoded; - } - - /** - * Checks whether the passed string exceeds a limit of number of characters. - * - * @param str - * @param limit - * @return the result of comparison, or false if str is null. - */ - public static boolean isExceedingLimit(String str, int limit) { - if (str == null) { - return false; - } - return str.length() > limit; - } - - /** - * Checks the passed string list whether the cumulative length of strings and delimiters between them exceeds a limit of number of characters. For example for list ("one","two","three") with delimiter "," the length of list is calculated - * 3+1+3+1+5=13 - * - * @param strList - * @param limit - * @param delimiterLength - * - 0 if there is no delimeter. - * @return the result of comparison, or false if strList is null. - */ - public static boolean isExceedingLimit(List<String> strList, int limit, int delimiterLength) { - if (strList == null || strList.isEmpty()) { - return false; - } - int sum = 0; - int size = strList.size(); - for (int i = 0; i < size - 1; i++) { - String str = strList.get(i); - if (str != null) { - sum += str.length(); - } - sum += delimiterLength; - } - String str = strList.get(size - 1); - if (str != null) { - sum += str.length(); - } - return sum > limit; - } - - /** - * Return the extension as the substring from the last dot. For input "kuku.txt", "txt" will be returned. If no dot is found or input is null, empty string is returned. - * - * @param fileName - * @return extension - */ - public static String getFilenameExtension(String fileName) { - String res = Constants.EMPTY_STRING; - if (fileName != null) { - int indexOf = fileName.lastIndexOf('.'); - if (indexOf != -1 && indexOf < (fileName.length() - 1)) { - res = fileName.substring(indexOf + 1); - } - } - return res; - } - - public static String calculateMD5ByByteArray(byte[] payload) { - String decodedMd5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(payload); - byte[] encodeMd5 = Base64.encodeBase64(decodedMd5.getBytes()); - return new String(encodeMd5); - - } - - /** - * - * @param data - * @return - */ - public static String calculateMD5ByString(String data) { - String calculatedMd5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(data); - - // encode base-64 result - byte[] encodeBase64 = Base64.encodeBase64(calculatedMd5.getBytes()); - return new String(encodeBase64); - } -} |