Update vulnerable package dependencies
[sdc.git] / integration-tests / src / test / java / org / onap / sdc / frontend / ci / tests / flow / CreateVlmFlow.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 Nordix Foundation
4  *  ================================================================================
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  *
16  *  SPDX-License-Identifier: Apache-2.0
17  *  ============LICENSE_END=========================================================
18  */
19
20 package org.onap.sdc.frontend.ci.tests.flow;
21
22 import static org.hamcrest.MatcherAssert.assertThat;
23 import static org.hamcrest.core.Is.is;
24
25 import com.aventstack.extentreports.Status;
26 import java.util.Optional;
27 import org.apache.commons.lang3.RandomStringUtils;
28 import org.onap.sdc.frontend.ci.tests.execute.setup.ExtentTestActions;
29 import org.onap.sdc.frontend.ci.tests.pages.OnboardHomePage;
30 import org.onap.sdc.frontend.ci.tests.pages.PageObject;
31 import org.onap.sdc.frontend.ci.tests.pages.TopNavComponent;
32 import org.onap.sdc.frontend.ci.tests.pages.VlmCreationModal;
33 import org.onap.sdc.frontend.ci.tests.pages.VlmOverviewPage;
34 import org.onap.sdc.frontend.ci.tests.pages.home.HomePage;
35 import org.openqa.selenium.WebDriver;
36
37 public class CreateVlmFlow extends AbstractUiTestFlow {
38
39     private HomePage homePage;
40
41     public CreateVlmFlow(WebDriver webDriver) {
42         super(webDriver);
43     }
44
45     @Override
46     public Optional<? extends PageObject> run(final PageObject... pageObjects) {
47         extendTest.log(Status.INFO, "Starting flow to create a VLM");
48         final TopNavComponent topNavComponent = getParameter(pageObjects, TopNavComponent.class)
49             .orElse(new TopNavComponent(webDriver));
50         extendTest.log(Status.INFO, "Accessing the Onboard Home Page to create a VLM");
51         topNavComponent.isLoaded();
52         final OnboardHomePage onboardHomePage = goToOnboardHomePage(topNavComponent);
53         onboardHomePage.isLoaded();
54         final VlmOverviewPage vlmOverviewPage = createNewVlm(onboardHomePage);
55         submitVlm(vlmOverviewPage);
56         goToHomePage(topNavComponent);
57         return Optional.empty();
58     }
59
60     @Override
61     public Optional<HomePage> getLandedPage() {
62         return Optional.ofNullable(homePage);
63     }
64
65     /**
66      * Goes to the onboard home page by clicking in the onboard tab in the top nav component.
67      *
68      * @param topNavComponent the top nav component
69      * @return the onboard home page
70      */
71     private OnboardHomePage goToOnboardHomePage(final TopNavComponent topNavComponent) {
72         final OnboardHomePage onboardHomePage = topNavComponent.clickOnOnboard();
73         onboardHomePage.isLoaded();
74         ExtentTestActions.takeScreenshot(Status.INFO, "onboard-homepage", "Onboard homepage is loaded");
75         return onboardHomePage;
76     }
77
78     /**
79      * Creates a new VLM in the onboard home page.
80      *
81      * @param onboardHomePage the onboard home page representation
82      * @return the Vendor License Model Overview page
83      */
84     private VlmOverviewPage createNewVlm(final OnboardHomePage onboardHomePage) {
85         final String vendorName = new StringBuilder("CiVlm").append(RandomStringUtils.randomAlphabetic(5)).toString();
86         extendTest.log(Status.INFO, "Creating a new VLM");
87         final VlmCreationModal vlmCreationModal = onboardHomePage.clickOnCreateNewVlm();
88         vlmCreationModal.isLoaded();
89         vlmCreationModal.fillCreationForm(vendorName, "My New VLM");
90         ExtentTestActions.takeScreenshot(Status.INFO, "vlm-creation-form",
91             "Creating VLM with given information");
92         final VlmOverviewPage vlmOverviewPage = vlmCreationModal.clickOnCreate();
93         vlmOverviewPage.isLoaded();
94         extendTest.log(Status.INFO, String.format("VLM with vendor name '%s' created", vendorName));
95         final String actualVendorName = vlmOverviewPage.getVendorName();
96         assertThat(String.format("Should be in the Vendor License Model '%s' page", vendorName),
97             actualVendorName, is(vendorName));
98         return vlmOverviewPage;
99     }
100
101     /**
102      * Submits the VLM through the software product view.
103      *
104      * @param vlmOverviewPage the Vendor Licence Overview page
105      */
106     private void submitVlm(final VlmOverviewPage vlmOverviewPage) {
107         extendTest.log(Status.INFO, "Checking if the VLM Overview page is loaded.");
108         ExtentTestActions.takeScreenshot(Status.INFO, "vlm-overview-page-loaded", "The first VLM version was submitted");
109         vlmOverviewPage.overviewScreenIsLoaded();
110         extendTest.log(Status.INFO, "Submitting the first VLM version.");
111         vlmOverviewPage.submit();
112         ExtentTestActions.takeScreenshot(Status.INFO, "vlm-submitted", "The first VLM version was submitted");
113     }
114
115     /**
116      * Go to the system home page through the top nav menu.
117      *
118      * @param topNavComponent the top nav component
119      */
120     private void goToHomePage(final TopNavComponent topNavComponent) {
121         extendTest.log(Status.INFO, "Accessing the Home page");
122         topNavComponent.isLoaded();
123         homePage = topNavComponent.clickOnHome();
124         homePage.isLoaded();
125         ExtentTestActions.takeScreenshot(Status.INFO, "home-is-loaded", "The Home page is loaded.");
126     }
127
128 }