aboutsummaryrefslogtreecommitdiffstats
path: root/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/utilities/OnboardingUiUtils.java
blob: 020c41607a382e33efe960e863ae91bbed0d0648 (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
/*-
 * ============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.utilities;

import com.aventstack.extentreports.Status;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
import org.openecomp.sdc.ci.tests.datatypes.HeatMetaFirstLevelDefinition;
import org.openecomp.sdc.ci.tests.datatypes.LifeCycleStateEnum;
import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
import org.openecomp.sdc.ci.tests.datatypes.VendorLicenseModel;
import org.openecomp.sdc.ci.tests.datatypes.VendorSoftwareProductObject;
import org.openecomp.sdc.ci.tests.execute.devCI.ArtifactFromCsar;
import org.openecomp.sdc.ci.tests.execute.setup.ArtifactsCorrelationManager;
import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;
import org.openecomp.sdc.ci.tests.pages.DeploymentArtifactPage;
import org.openecomp.sdc.ci.tests.pages.GeneralPageElements;
import org.openecomp.sdc.ci.tests.pages.HomePage;
import org.openecomp.sdc.ci.tests.pages.ResourceGeneralPage;
import org.openecomp.sdc.ci.tests.utils.general.OnboardingUtils;
import org.openecomp.sdc.ci.tests.utils.general.VendorLicenseModelRestUtils;
import org.openecomp.sdc.ci.tests.utils.general.VendorSoftwareProductRestUtils;
import org.openecomp.sdc.ci.tests.verificator.VfVerificator;
import org.openqa.selenium.WebElement;
import org.testng.Assert;

import java.io.File;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


public class OnboardingUiUtils {

    private static final int WAITING_FOR_LOADER_TIME_OUT = 60 * 10;

    private static void importUpdateVSP(VendorSoftwareProductObject vsp, boolean isUpdate, boolean restore) throws Exception {
        String vspName = vsp.getName();
        boolean vspFound = HomePage.searchForVSP(vspName);

        if (vspFound) {
            List<WebElement> elementsFromTable = GeneralPageElements.getElementsFromTable();
            elementsFromTable.get(0).click();
            elementsFromTable.get(0).click();
            GeneralUIUtils.waitForLoader();

            if (isUpdate) {
                GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ImportVfRepository.UPDATE_VSP.getValue());
            } else {
                GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ImportVfRepository.IMPORT_VSP.getValue());
            }
            if (restore) {
                GeneralPageElements.restoreComponentFromElementPage(vspName);
            }
            doCheckOut();
            //Metadata verification
            onboardedVnfMetadataVerification(vsp, isUpdate);
            String duration = GeneralUIUtils.getActionDuration(OnboardingUiUtils::waitUntilVnfCreated);
            ExtentTestActions.log(Status.INFO, "Succeeded in importing/updating " + vspName, duration);
        } else {
            Assert.fail("Did not find VSP named " + vspName);
        }
    }

    private static void onboardedVnfMetadataVerification(VendorSoftwareProductObject vsp, boolean isUpdate) {
        if (isUpdate) {
            VfVerificator.verifyOnboardedVnfMetadataAfterUpdateVNF(vsp.getName(), vsp);
        } else {
            VfVerificator.verifyOnboardedVnfMetadata(vsp.getName(), vsp);
        }
    }

    public static boolean getVspValidationCongiguration() throws Exception {
        return Boolean.parseBoolean(OnboardingUtils.getVspValidationConfiguration());
    }

    public static boolean putVspValidationCongiguration(boolean value) throws Exception {
        return Boolean.parseBoolean(OnboardingUtils.putVspValidationConfiguration(value));
    }

    public static void doCheckOut() {
        String lifeCycleState = ResourceGeneralPage.getLifeCycleState();
        boolean needCheckout = lifeCycleState.equals(LifeCycleStateEnum.CHECKIN.getValue()) || lifeCycleState.equals(LifeCycleStateEnum.CERTIFIED.getValue());
        if (needCheckout) {
            try {
                ResourceGeneralPage.clickCheckoutButton();
                Assert.assertTrue(ResourceGeneralPage.getLifeCycleState().equals(LifeCycleStateEnum.CHECKOUT.getValue()), "Did not succeed to checkout");
            } catch (Exception e) {
                ExtentTestActions.log(Status.ERROR, "Did not succeed to checkout");
                e.printStackTrace();
            }
            GeneralUIUtils.waitForLoader();
        }
    }

    private static void waitUntilVnfCreated() {
        ExtentTestActions.log(Status.INFO, "Clicking create/update VNF");
        GeneralUIUtils.ultimateWait();
        GeneralUIUtils.clickOnAreaJS(DataTestIdEnum.GeneralElementsEnum.CREATE_BUTTON.getValue());
        GeneralUIUtils.waitForLoader(WAITING_FOR_LOADER_TIME_OUT);
        GeneralUIUtils.ultimateWait();
        GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.CHECKIN_BUTTON.getValue());
    }

    public static void updateVSP(VendorSoftwareProductObject vsp, boolean restore) throws Exception {
        ExtentTestActions.log(Status.INFO, "Updating VSP " + vsp.getName());
        importUpdateVSP(vsp, true, restore);
    }

    public static void updateVSP(VendorSoftwareProductObject vsp) throws Exception {
        ExtentTestActions.log(Status.INFO, "Updating VSP " + vsp.getName());
        importUpdateVSP(vsp, true, false);
    }

    public static void importVSP(VendorSoftwareProductObject vsp) throws Exception {
        ExtentTestActions.log(Status.INFO, "Importing VSP " + vsp.getName());
        importUpdateVSP(vsp, false, false);
    }

    public static void updateVnfAndValidate(String filePath, VendorSoftwareProductObject vsp, String updatedVnfFile, User user) throws Exception {
        ExtentTestActions.log(Status.INFO, String.format("Going to update the VNF with %s......", updatedVnfFile));
        System.out.println(String.format("Going to update the VNF with %s......", updatedVnfFile));

        VendorSoftwareProductRestUtils.updateVendorSoftwareProductToNextVersion(vsp, user, filePath, updatedVnfFile);
        HomePage.showVspRepository();
        updateVSP(vsp);
        ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
        DeploymentArtifactPage.verifyArtifactsExistInTable(filePath, updatedVnfFile);
    }

    public static VendorSoftwareProductObject createVSP(ResourceReqDetails resourceReqDetails, String vnfFile, String filepath, User user) throws Exception {
        ExtentTestActions.log(Status.INFO, String.format("Creating VSP from package '%s'", vnfFile));
        final VendorLicenseModel vendorLicenseModel = VendorLicenseModelRestUtils.createVendorLicense(user);
        return VendorSoftwareProductRestUtils.createVSP(resourceReqDetails, vnfFile, filepath, user, vendorLicenseModel);
    }


    public static VendorSoftwareProductObject onboardAndValidate(ResourceReqDetails resourceReqDetails, String filepath, String vnfFile, User user) throws Exception {
        ExtentTestActions.log(Status.INFO, String.format("Going to onboard the VNF %s", vnfFile));
        System.out.println(String.format("Going to onboard the VNF %s", vnfFile));

        VendorLicenseModel vendorLicenseModel = VendorLicenseModelRestUtils.createVendorLicense(user);
        VendorSoftwareProductObject createVendorSoftwareProduct = VendorSoftwareProductRestUtils.createVendorSoftwareProduct(resourceReqDetails, vnfFile, filepath, user,
            vendorLicenseModel);
        String vspName = createVendorSoftwareProduct.getName();

        DownloadManager.downloadCsarByNameFromVSPRepository(vspName, createVendorSoftwareProduct.getVspId());
        File latestFilefromDir = FileHandling.getLastModifiedFileNameFromDir();

        ExtentTestActions.log(Status.INFO, String.format("Going to import %s", vnfFile.substring(0, vnfFile.indexOf("."))));
        importVSP(createVendorSoftwareProduct);

        ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();

        // Verify deployment artifacts
        Map<String, Object> combinedMap = ArtifactFromCsar.combineHeatArtifacstWithFolderArtifacsToMap(latestFilefromDir.getAbsolutePath());

        LinkedList<HeatMetaFirstLevelDefinition> deploymentArtifacts = ((LinkedList<HeatMetaFirstLevelDefinition>) combinedMap.get("Deployment"));
        ArtifactsCorrelationManager.addVNFartifactDetails(vspName, deploymentArtifacts);

        List<String> heatEnvFilesFromCSAR = deploymentArtifacts.stream().filter(e -> e.getType().equals("HEAT_ENV")).
                map(e -> e.getFileName()).
                collect(Collectors.toList());

        validateDeploymentArtifactsVersion(deploymentArtifacts, heatEnvFilesFromCSAR);

//        DeploymentArtifactPage.verifyArtifactsExistInTable(filepath, vnfFile);
        return createVendorSoftwareProduct;
    }

    public static void validateDeploymentArtifactsVersion(LinkedList<HeatMetaFirstLevelDefinition> deploymentArtifacts,
                                                          List<String> heatEnvFilesFromCSAR) {
        String artifactVersion;
        String artifactName;

        for (HeatMetaFirstLevelDefinition deploymentArtifact : deploymentArtifacts) {
            artifactVersion = "1";

            if (deploymentArtifact.getType().equals("HEAT_ENV")) {
                continue;
            } else if (deploymentArtifact.getFileName().contains(".")) {
                artifactName = deploymentArtifact.getFileName().trim().substring(0, deploymentArtifact.getFileName().lastIndexOf("."));
            } else {
                artifactName = deploymentArtifact.getFileName().trim();
            }

            ArtifactUIUtils.validateArtifactNameVersionType(artifactName, artifactVersion, deploymentArtifact.getType());
        }
    }

}