aboutsummaryrefslogtreecommitdiffstats
path: root/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/flow/CreateVlmFlow.java
blob: 8b6a39117866ecea69cdf2ce1cca59fcae714278 (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
/*
 * ============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.flow;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;

import com.aventstack.extentreports.Status;
import java.util.Optional;
import org.apache.commons.lang.RandomStringUtils;
import org.onap.sdc.frontend.ci.tests.execute.setup.ExtentTestActions;
import org.onap.sdc.frontend.ci.tests.pages.OnboardHomePage;
import org.onap.sdc.frontend.ci.tests.pages.PageObject;
import org.onap.sdc.frontend.ci.tests.pages.TopNavComponent;
import org.onap.sdc.frontend.ci.tests.pages.VlmCreationModal;
import org.onap.sdc.frontend.ci.tests.pages.VlmOverviewPage;
import org.onap.sdc.frontend.ci.tests.pages.home.HomePage;
import org.openqa.selenium.WebDriver;

public class CreateVlmFlow extends AbstractUiTestFlow {

    private HomePage homePage;

    public CreateVlmFlow(WebDriver webDriver) {
        super(webDriver);
    }

    @Override
    public Optional<? extends PageObject> run(PageObject... pageObjects) {
        extendTest.log(Status.INFO, String.format("Starting flow to create a VLM"));
        final TopNavComponent topNavComponent = getParameter(pageObjects, TopNavComponent.class)
            .orElse(new TopNavComponent(webDriver));
        extendTest.log(Status.INFO, "Accessing the Onboard Home Page to create a VLM");
        topNavComponent.isLoaded();
        final OnboardHomePage onboardHomePage = goToOnboardHomePage(topNavComponent);
        final VlmOverviewPage vlmOverviewPage = createNewVlm(onboardHomePage);
        submitVlm(vlmOverviewPage);
        goToHomePage(topNavComponent);
        return Optional.empty();
    }

    @Override
    public Optional<HomePage> getLandedPage() {
        return Optional.ofNullable(homePage);
    }

    /**
     * Goes to the onboard home page by clicking in the onboard tab in the top nav component.
     *
     * @param topNavComponent the top nav component
     * @return the onboard home page
     */
    private OnboardHomePage goToOnboardHomePage(final TopNavComponent topNavComponent) {
        final OnboardHomePage onboardHomePage = topNavComponent.clickOnOnboard();
        onboardHomePage.isLoaded();
        ExtentTestActions.takeScreenshot(Status.INFO, "onboard-homepage", "Onboard homepage is loaded");
        return onboardHomePage;
    }

    /**
     * Creates a new VLM in the onboard home page.
     *
     * @param onboardHomePage the onboard home page representation
     * @return the Vendor License Model Overview page
     */
    private VlmOverviewPage createNewVlm(final OnboardHomePage onboardHomePage) {
        final String vendorName = new StringBuilder("CiVlm").append(RandomStringUtils.randomAlphabetic(5)).toString();
        extendTest.log(Status.INFO, "Creating a new VLM");
        final VlmCreationModal vlmCreationModal = onboardHomePage.clickOnCreateNewVlm();
        vlmCreationModal.isLoaded();
        vlmCreationModal.fillCreationForm(vendorName, "My New VLM");
        ExtentTestActions.takeScreenshot(Status.INFO, "vlm-creation-form",
            "Creating VLM with given information");
        final VlmOverviewPage vlmOverviewPage = vlmCreationModal.clickOnCreate();
        vlmOverviewPage.isLoaded();
        extendTest.log(Status.INFO, String.format("VLM with vendor name '%s' created", vendorName));
        final String actualVendorName = vlmOverviewPage.getVendorName();
        assertThat(String.format("Should be in the Vendor License Model '%s' page", vendorName),
            actualVendorName, is(vendorName));
        return vlmOverviewPage;
    }

    /**
     * Submits the VLM through the software product view.
     *
     * @param vlmOverviewPage the Vendor Licence Overview page
     */
    private void submitVlm(final VlmOverviewPage vlmOverviewPage) {
        extendTest.log(Status.INFO, "Checking if the VLM Overview page is loaded.");
        ExtentTestActions.takeScreenshot(Status.INFO, "vlm-overview-page-loaded", "The first VLM version was submitted");
        vlmOverviewPage.overviewScreenIsLoaded();
        extendTest.log(Status.INFO, "Submitting the first VLM version.");
        vlmOverviewPage.submit();
        ExtentTestActions.takeScreenshot(Status.INFO, "vlm-submitted", "The first VLM version was submitted");
    }

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

}