aboutsummaryrefslogtreecommitdiffstats
path: root/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/pages/DeploymentArtifactPage.java
blob: 669a79ac39ab530462fad409f4a6b449c16d6752 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/*-
 * ============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.openecomp.sdc.ci.tests.pages;

import com.aventstack.extentreports.Status;
import org.apache.commons.lang.WordUtils;
import org.openecomp.sdc.ci.tests.datatypes.ArtifactInfo;
import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
import org.openecomp.sdc.ci.tests.datatypes.enums.ArtifactTypeEnum;
import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;
import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
import org.openecomp.sdc.ci.tests.utilities.FileHandling;
import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.collections.Lists;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class DeploymentArtifactPage extends GeneralPageElements {

    protected DeploymentArtifactPage() {
        super();
    }

    public static ResourceLeftMenu getLeftPanel() {
        return new ResourceLeftMenu();
    }

    public static UploadArtifactPopup artifactPopup() {
        return new UploadArtifactPopup();
    }

    protected static void addNewArtifact(ArtifactGroupTypeEnum artifactGroupType) {
        switch (artifactGroupType) {
            case DEPLOYMENT:
                GeneralUIUtils.getInputElement(DataTestIdEnum.ArtifactPageEnum.ADD_DEPLOYMENT_ARTIFACT.getValue()).click();
                break;
            case INFORMATIONAL:
                GeneralUIUtils.getInputElement(DataTestIdEnum.ArtifactPageEnum.ADD_INFORMATIONAL_ARTIFACT.getValue()).click();
                break;
            default:
                break;
        }
    }

    public static void clickAddNewArtifact() {
        addNewArtifact(ArtifactGroupTypeEnum.DEPLOYMENT);
    }

    public static void clickAddAnotherArtifact() {
        GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.ADD_ANOTHER_ARTIFACT.getValue()).click();
    }

    public static void clickEditArtifact(String artifactLabel) {
        GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.EDIT_ARTIFACT.getValue() + artifactLabel).click();
    }

    public static void clickEditEnvArtifact(String artifactLabel) {
        GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.EDIT_PARAMETERS_OF_ARTIFACT.getValue() + artifactLabel).click();
    }

    public static void hoverArtifact(String artifactLabel) {
        GeneralUIUtils.hoverOnAreaByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_NAME.getValue() + artifactLabel);
    }

    public static void clickDeleteArtifact(String artifactLabel) {
        SetupCDTest.getExtendTest().log(Status.INFO, String.format("Deleting %s Artefact ", artifactLabel));
        GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.DELETE_ARTIFACT.getValue() + artifactLabel).click();
    }

    public static WebElement clickDownloadArtifact(String artifactLabel) {
        WebElement downloadButton = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.DOWNLOAD_ARTIFACT.getValue() + artifactLabel);

        return downloadButton;
    }

    public static void clickDownloadEnvArtifact(String envFileNameToDownload) {
        ExtentTestActions.log(Status.INFO, String.format("Downloading the updated  %s artifact for validate parameters with the response after the update...", envFileNameToDownload));
        GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ArtifactPageEnum.DOWNLOAD_ARTIFACT_ENV.getValue() + envFileNameToDownload);
        ExtentTestActions.log(Status.INFO, String.format("%s Envartifact was downloaded successfully!", envFileNameToDownload));
    }

    public static void clickSaveEnvParameters() {
        GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPopup.SAVE.getValue()).click();
        GeneralUIUtils.ultimateWait();
    }

    public static void clickCloseEnvParameters() {
        GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPopup.CANCEL_BUTTON.getValue()).click();
        GeneralUIUtils.ultimateWait();
    }

    public static WebElement getAddOtherArtifactButton() {
        return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.ADD_ANOTHER_ARTIFACT.getValue());
    }

    public static void clickOK() {
        SetupCDTest.getExtendTest().log(Status.INFO, "Artifact Page, Clicking OK");
        GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.OK.getValue()).click();
        GeneralUIUtils.getWebElementBy(By.className("flex-container"));
        GeneralUIUtils.waitForAngular();
    }

    public static String getArtifactDescription(String artifactLabel) throws Exception {
        clickOnArtifactDescription(artifactLabel); // open artifact
        WebElement artifactDescriptionElement = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.GET_DEPLOYMENT_ARTIFACT_DESCRIPTION.getValue());
        String artifactDesc = artifactDescriptionElement.getAttribute("value");
        closeArtifactDescription(artifactLabel); // close artifact
        return artifactDesc;
    }

    public static void closeArtifactDescription(String artifactLabel) {
        GeneralUIUtils.clickOnElementByTestId("popover-x-button");
    }

    public static WebElement clickOnArtifactDescription(String artifactLabel) throws Exception {
        try {
            WebElement artifact = GeneralUIUtils.getWebElementByTestID("descriptionIcon_" + artifactLabel);
            artifact.click();
            GeneralUIUtils.waitForLoader();
            return artifact;
        } catch (Exception e) {
            throw new Exception("Artifact " + artifactLabel + "is not found");
        }
    }

    public static boolean checkElementsCountInTable(int expectedElementsCount) {
        return GeneralPageElements.checkElementsCountInTable(expectedElementsCount + 1);
    }

    public static String[] verifyArtifactsExistInTable(String filepath, String vnfFile) throws Exception {
        String[] artifactNamesFromZipFile = FileHandling.getArtifactsFromZip(filepath, vnfFile);
        return verifyArtifactsExistInTable(artifactNamesFromZipFile);
    }

    public static String[] verifyArtifactsExistInTable(String[] artifactNamesFromZipFile) throws Exception {
        if (artifactNamesFromZipFile != null) {
            checkArtifactsDisplayed(artifactNamesFromZipFile);
            checkEnvArtifactsDisplayed();
        }

        return artifactNamesFromZipFile;
    }

    public static void checkArtifactsDisplayed(String[] artifactsFromZipFile) throws Exception {
        SetupCDTest.getExtendTest().log(Status.INFO, "Verifying the artifacts in the table");
        List<String> artifactList = Lists.newArrayList(artifactsFromZipFile).stream().filter(p -> !p.contains(".env")).map(p -> getVisualArtifactName(p)).collect(Collectors.toList());
        try {
            List<WebElement> rows = GeneralUIUtils.getElementsByCSS("div div[data-tests-id^='artifact-item'] span[data-tests-id^='artifactDisplayName']");
            for (WebElement r : rows) {
                String artifactDisplayed = r.getAttribute("textContent").trim();
                if (artifactList.contains(artifactDisplayed)) {
                    artifactList.remove(artifactDisplayed);
                } else if (artifactDisplayed.toLowerCase().contains("license")) {
                    artifactList.add(artifactDisplayed);
                }
            }
            checkLicenseArtifactsDisplayed(artifactList);
        } catch (Exception e) {
            throw new Exception("Table problem");
        }


        if (!artifactList.isEmpty()) {
            throw new Exception(String.format("missing the following artifact(s) : %s", artifactList.toString()));
        }
    }

    public static void checkEnvArtifactsDisplayed() throws Exception {
        List<WebElement> envRows;
        List<WebElement> heatRows;
        List<WebElement> heatNetRows;
        List<WebElement> heatVolRows;
        int envArtifactsSize = 0;

        SetupCDTest.getExtendTest().log(Status.INFO, "Verifying the HEAT_ENV artifacts in the table");

        try {
            envRows = GeneralUIUtils.getElementsByCSS("div div[data-tests-id='HEAT_ENV']");

            heatRows = GeneralUIUtils.getElementsByCSS("div div[tooltip-content='HEAT']");
            heatNetRows = GeneralUIUtils.getElementsByCSS("div div[tooltip-content='HEAT_NET']");
            heatVolRows = GeneralUIUtils.getElementsByCSS("div div[tooltip-content='HEAT_VOL']");

            envArtifactsSize = heatRows.size() + heatNetRows.size() + heatVolRows.size();
        } catch (Exception e) {
            throw new Exception("Table problem");
        }

        if (envArtifactsSize != envRows.size()) {
            throw new Exception(String.format("some env artifacts are missing... there is %s instead of %s", envRows.size(), envArtifactsSize));
        }

    }

    public static void checkLicenseArtifactsDisplayed(List<String> rowsFromTable) throws Exception {
        SetupCDTest.getExtendTest().log(Status.INFO, "Verifying the license artifacts in the table");
        String vfLicense = getPreparedLicense(ArtifactTypeEnum.VF_LICENSE.getType());
        String[] split = vfLicense.split(" ");
        vfLicense = vfLicense.replaceAll(split[0], split[0].toUpperCase());
        if (rowsFromTable.contains(vfLicense)) {
            rowsFromTable.remove(vfLicense);
        }

        String vendorLicense = getPreparedLicense(ArtifactTypeEnum.VENDOR_LICENSE.getType());
        if (rowsFromTable.contains(vendorLicense)) {
            rowsFromTable.remove(vendorLicense);
        }

    }

    public static String getPreparedLicense(String license) {
        return WordUtils.capitalizeFully(license.replaceAll("_", " "));
    }


    private static String getVisualArtifactName(String artifactName) {
        if (artifactName.contains(".")) {
            return artifactName.substring(0, artifactName.lastIndexOf("."));
        }
        return artifactName;
    }

    public static void updateDescription(String newDescription, ArtifactInfo artefact) throws Exception {
        UploadArtifactPopup artifactPopup = new UploadArtifactPopup(true);
        DeploymentArtifactPage.clickEditArtifact(artefact.getArtifactLabel());
        artifactPopup.insertDescription(newDescription);
        artifactPopup.clickDoneButton();
    }

    public static List<String> getDeploymentArtifactsNamesWorkSpace() {
        return GeneralUIUtils.getWebElementListText(GeneralUIUtils.getWebElementsListByContainTestID(DataTestIdEnum.ArtifactPageEnum.ARTIFACT_NAME.getValue()));
    }

    //Get Artifact Type by Artifact Name.
    public static String getArtifactType(String artifactName) {
        return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.TYPE.getValue() + artifactName).getText();
    }

    public static List<String> getHeatParametersInUI(String dataTestId) {
        List<WebElement> elements;
        List<String> Names = new ArrayList<>();
        elements = GeneralUIUtils.getWebElementsListByContainTestID(dataTestId);
        for (WebElement webElement : elements) {
            String attributevalue = webElement.getAttribute("data-tests-id");
            Names.add(attributevalue.replace("heatParameterName_", ""));
        }
        return Names;
    }

    public static void searchBoxEnv(String parameterName) {
        GeneralUIUtils.getWebElementByContainsClassName("w-sdc-env-search-input").sendKeys(parameterName);
    }

    public static void clearSearchBoxEnv() {
        GeneralUIUtils.getWebElementByContainsClassName("w-sdc-env-search-input").clear();
    }

    public static void editHeatParamValue(String paramName, String value) throws Exception {
        SetupCDTest.getExtendTest().log(Status.INFO, "Searching for " + paramName + " parameter on Heat Params modal screen");
        WebElement valueTextbox = GeneralUIUtils.getWebElementByTestID(paramName);

        clickOnHeatParam(paramName);
        valueTextbox.clear();
        SetupCDTest.getExtendTest().log(Status.INFO, "Editing " + paramName + " value on Heat Params modal screen");
        valueTextbox.sendKeys(value);
        GeneralUIUtils.ultimateWait();

    }

    public static void clickOnDeleteHeatParamValue(String paramName) throws Exception {
        SetupCDTest.getExtendTest().log(Status.INFO, "Searching for " + paramName + " parameter on Properties screen");
        String value = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.EnvParameterView.ENV_CURRENT_VALUE.getValue() + paramName).getAttribute("value");
        if (value != null) {
            GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ArtifactPageEnum.DELETE_PARAMETER_OF_ARTIFACT.getValue() + paramName);
            GeneralUIUtils.ultimateWait();
            SetupCDTest.getExtendTest().log(Status.INFO, "Value of " + paramName + " is deleted");
        }
        SetupCDTest.getExtendTest().log(Status.INFO, "Value of " + paramName + " is empty and cannot be deleted");
    }

    public static void clickOnHeatParam(String paramName) throws Exception {

        SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on the %s component in Properties", paramName));
        GeneralUIUtils.clickOnElementByTestId(paramName);
        GeneralUIUtils.ultimateWait();
        GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.LIFECYCLE_STATE.getValue());
    }

}