summaryrefslogtreecommitdiffstats
path: root/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/execute/sanity/EtsiOnboardVnfCnfUiTests.java
blob: c149b24907eae01fcdd99da63d0de9211d1ad4bc (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
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2021 Nordix Foundation
 *  ================================================================================
 *  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.
 *
 *  SPDX-License-Identifier: Apache-2.0
 *  ============LICENSE_END=========================================================
 */

package org.onap.sdc.frontend.ci.tests.execute.sanity;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.fail;

import com.aventstack.extentreports.Status;
import java.util.Map;
import java.util.Optional;
import org.junit.jupiter.api.Assertions;
import org.onap.sdc.backend.ci.tests.data.providers.OnboardingDataProviders;
import org.onap.sdc.backend.ci.tests.datatypes.enums.ComponentType;
import org.onap.sdc.backend.ci.tests.datatypes.enums.ServiceCategoriesEnum;
import org.onap.sdc.backend.ci.tests.utils.general.ElementFactory;
import org.onap.sdc.frontend.ci.tests.datatypes.ComponentData;
import org.onap.sdc.frontend.ci.tests.datatypes.ServiceCreateData;
import org.onap.sdc.frontend.ci.tests.exception.UnzipException;
import org.onap.sdc.frontend.ci.tests.execute.setup.DriverFactory;
import org.onap.sdc.frontend.ci.tests.execute.setup.ExtentTestActions;
import org.onap.sdc.frontend.ci.tests.execute.setup.SetupCDTest;
import org.onap.sdc.frontend.ci.tests.flow.AddNodeToCompositionFlow;
import org.onap.sdc.frontend.ci.tests.flow.CreateResourceFromVspFlow;
import org.onap.sdc.frontend.ci.tests.flow.CreateServiceFlow;
import org.onap.sdc.frontend.ci.tests.flow.CreateVlmFlow;
import org.onap.sdc.frontend.ci.tests.flow.CreateVspFlow;
import org.onap.sdc.frontend.ci.tests.flow.DownloadCsarArtifactFlow;
import org.onap.sdc.frontend.ci.tests.flow.ImportVspFlow;
import org.onap.sdc.frontend.ci.tests.flow.exception.UiTestFlowRuntimeException;
import org.onap.sdc.frontend.ci.tests.pages.ComponentPage;
import org.onap.sdc.frontend.ci.tests.pages.ResourceCreatePage;
import org.onap.sdc.frontend.ci.tests.pages.ServiceCreatePage;
import org.onap.sdc.frontend.ci.tests.pages.TopNavComponent;
import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionPage;
import org.onap.sdc.frontend.ci.tests.pages.component.workspace.ToscaArtifactsPage;
import org.onap.sdc.frontend.ci.tests.pages.home.HomePage;
import org.onap.sdc.frontend.ci.tests.utilities.FileHandling;
import org.openqa.selenium.WebDriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class EtsiOnboardVnfCnfUiTests extends SetupCDTest {

    private static final Logger LOGGER = LoggerFactory.getLogger(EtsiOnboardVnfCnfUiTests.class);

    private WebDriver webDriver;
    private TopNavComponent topNavComponent;
    private HomePage homePage;

    @BeforeMethod
    public void init() {
        webDriver = DriverFactory.getDriver();
        topNavComponent = new TopNavComponent(webDriver);
    }

    @Test
    public void createVlm() {
        final CreateVlmFlow createVlmFlow = new CreateVlmFlow(webDriver);
        createVlmFlow.run();
    }

    @Test(dataProviderClass = OnboardingDataProviders.class, dataProvider = "etsiVnfCnfOnboardPackages", dependsOnMethods = "createVlm")
    public void onboardEtsiVnfCnfFlow(final String rootFolder, final String vnfFile) {
        setLog(vnfFile);
        final String resourceName = ElementFactory.addRandomSuffixToName(ElementFactory.getResourcePrefix());
        runOnboardEtsiVnfCnf(resourceName, rootFolder, vnfFile);
        runDistribution(resourceName);
    }

    /**
     * Runs ETSI onboarding VNF/CNF UI flow
     *
     * @param resourceName VSP name
     * @param rootFolder VNF/CNF package location
     * @param vnfCnfFile file to be onboarded
     */
    private void runOnboardEtsiVnfCnf(final String resourceName, final String rootFolder, final String vnfCnfFile) {
        final CreateVspFlow createVspFlow = new CreateVspFlow(webDriver, resourceName, vnfCnfFile, rootFolder);
        createVspFlow.run(topNavComponent);
        final ImportVspFlow importVspFlow = new ImportVspFlow(webDriver, resourceName);
        ResourceCreatePage resourceCreatePage = importVspFlow.run()
            .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected return ResourceCreatePage"));
        final CreateResourceFromVspFlow createResourceFlow = new CreateResourceFromVspFlow(webDriver, resourceName);
        resourceCreatePage = createResourceFlow.run(resourceCreatePage)
            .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected return ResourceCreatePage"));
        resourceCreatePage.isLoaded();
        resourceCreatePage.certifyComponent();
        ExtentTestActions.takeScreenshot(Status.INFO, "resource-certified",
            String.format("Resource '%s' was certified", resourceName));
        downloadAndVerifyOnboardedPackage(loadComponentPage());
    }

    private void runDistribution(final String resourceName) {
        final ServiceCreateData serviceCreateData = createServiceFormData();
        final ServiceCreatePage serviceCreatePage = createService(goToHomePage(topNavComponent), serviceCreateData);
        final ComponentData parentComponent = new ComponentData();
        parentComponent.setName(serviceCreateData.getName());
        parentComponent.setVersion("0.1");
        parentComponent.setComponentType(ComponentType.SERVICE);
        final ComponentData componentToAdd = new ComponentData();
        componentToAdd.setName(resourceName);
        componentToAdd.setVersion("1.0");
        componentToAdd.setComponentType(ComponentType.RESOURCE);
        final AddNodeToCompositionFlow addNodeToCompositionFlow = new AddNodeToCompositionFlow(webDriver, parentComponent, componentToAdd);
        ComponentPage componentPage = loadComponentPage();
        final CompositionPage compositionPage = (CompositionPage) addNodeToCompositionFlow.run(componentPage.goToComposition())
            .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected return CompositionPage"));
        compositionPage.isLoaded();
        ExtentTestActions.takeScreenshot(Status.INFO, "node-added-to-composition",
            String.format("Resource '%s' was added to composition", serviceCreateData.getName()));
        componentPage = compositionPage.goToGeneral();
        componentPage.isLoaded();
        componentPage.certifyComponent();
        componentPage.isLoaded();
        ExtentTestActions.takeScreenshot(Status.INFO, "service-certified",
            String.format("Service '%s' was certified", serviceCreateData.getName()));

        downloadAndVerifyOnboardedPackage(componentPage);
    }

    private void downloadAndVerifyOnboardedPackage(final ComponentPage componentPage) {
        final DownloadCsarArtifactFlow downloadCsarArtifactFlow = downloadToscaCsar(componentPage);
        final ToscaArtifactsPage toscaArtifactsPage = downloadCsarArtifactFlow.getLandedPage()
            .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected ToscaArtifactsPage"));
        assertThat("No artifact download was found", toscaArtifactsPage.getDownloadedArtifactList(), not(empty()));
        final String downloadedCsarName = toscaArtifactsPage.getDownloadedArtifactList().get(0);
        verifyOnboardedPackage(downloadedCsarName);
    }

    private ServiceCreatePage createService(final HomePage homePage, final ServiceCreateData serviceCreateData) {
        final CreateServiceFlow createServiceFlow = new CreateServiceFlow(webDriver, serviceCreateData);
        return createServiceFlow.run(homePage)
            .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected return ServiceCreatePage"));
    }

    private ServiceCreateData createServiceFormData() {
        final ServiceCreateData serviceCreateData = new ServiceCreateData();
        serviceCreateData.setRandomName(ElementFactory.addRandomSuffixToName(ElementFactory.getServicePrefix()));
        serviceCreateData.setCategory(ServiceCategoriesEnum.E2E_SERVICE.getValue());
        serviceCreateData.setDescription("aDescription");
        return serviceCreateData;
    }

    /**
     * Go to the system home page through the top nav menu.
     *
     * @param topNavComponent the top nav component
     */
    private HomePage goToHomePage(final TopNavComponent topNavComponent) {
        topNavComponent.isLoaded();
        homePage = topNavComponent.clickOnHome();
        homePage.isLoaded();
        ExtentTestActions.takeScreenshot(Status.INFO, "home-is-loaded", "The Home page is loaded.");
        return homePage;
    }

    /**
     * Loads Component Page
     *
     * @return ComponentPage
     */
    private ComponentPage loadComponentPage() {
        final ComponentPage componentPage = Optional.of(new ComponentPage(webDriver))
            .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected ComponentPage"));
        componentPage.isLoaded();
        return componentPage;
    }

    /**
     * Download the generated package
     *
     * @return DownloadCsarArtifactFlow
     */
    private DownloadCsarArtifactFlow downloadToscaCsar(final ComponentPage componentPage) {
        final DownloadCsarArtifactFlow downloadCsarArtifactFlow = new DownloadCsarArtifactFlow(webDriver);
        downloadCsarArtifactFlow.run(componentPage);
        return downloadCsarArtifactFlow;
    }

    /**
     * Verifies if the onboarded package is included in the downloaded csar
     *
     * @param downloadedCsarName downloaded csar package name
     */
    private void verifyOnboardedPackage(final String downloadedCsarName) {
        final String downloadFolderPath = getConfig().getDownloadAutomationFolder();
        final Map<String, byte[]> filesFromZip;
        try {
            filesFromZip = FileHandling.getFilesFromZip(downloadFolderPath, downloadedCsarName);
            final java.util.Optional<String> etsiPackageEntryOpt =
                filesFromZip.keySet().stream().filter(s -> s.startsWith("Artifacts/Deployment/ETSI_PACKAGE"))
                    .findFirst();
            if (etsiPackageEntryOpt.isEmpty()) {
                Assertions.fail("Could not find the  Onboarded Package in Artifacts/Deployment/ETSI_PACKAGE");
            }
        } catch (final UnzipException e) {
            final String errorMsg = "Could not unzip the downloaded csar package";
            LOGGER.info(errorMsg, e);
            fail(String.format("%s Error: %s", errorMsg, e.getMessage()));
        }
    }
}