Onboard PNF software version Ui test case
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / flow / ImportVspFlow.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 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.openecomp.sdc.ci.tests.flow;
21
22 import com.aventstack.extentreports.Status;
23 import java.util.Optional;
24 import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;
25 import org.openecomp.sdc.ci.tests.pages.PageObject;
26 import org.openecomp.sdc.ci.tests.pages.ResourceCreatePage;
27 import org.openecomp.sdc.ci.tests.pages.TopNavComponent;
28 import org.openecomp.sdc.ci.tests.pages.VspRepositoryModalComponent;
29 import org.openqa.selenium.WebDriver;
30
31 /**
32  * UI Flow for importing a VSP
33  */
34 public class ImportVspFlow extends AbstractUiTestFlow {
35
36     private final String resourceName;
37
38     public ImportVspFlow(final WebDriver webDriver, final String resourceName) {
39         super(webDriver);
40         this.resourceName = resourceName;
41     }
42
43     @Override
44     public Optional<PageObject> run(final PageObject... pageObjects) {
45         final VspRepositoryModalComponent vspRepositoryModalComponent = openVspRepository();
46         searchForVsp(vspRepositoryModalComponent);
47         return Optional.of(importVsp(vspRepositoryModalComponent));
48     }
49
50     /**
51      * Opens the VSP repository modal by clicking in its icon from the top nav menu.
52      *
53      * @return the VSP repository modal
54      */
55     private VspRepositoryModalComponent openVspRepository() {
56         extendTest.log(Status.INFO, "Opening the VSP repository");
57         final TopNavComponent topNavComponent = new TopNavComponent(webDriver);
58         topNavComponent.isLoaded();
59         final VspRepositoryModalComponent vspRepositoryModalComponent = topNavComponent.clickOnRepositoryIcon();
60         vspRepositoryModalComponent.isLoaded();
61         return vspRepositoryModalComponent;
62     }
63
64     /**
65      * Searches for a VSP in the repository modal.
66      *
67      * @param vspRepositoryModalComponent the repository modal component
68      */
69     private void searchForVsp(final VspRepositoryModalComponent vspRepositoryModalComponent) {
70         extendTest.log(Status.INFO, String.format("Searching for VSP '%s' in the repository", resourceName));
71         vspRepositoryModalComponent.searchForVSP(resourceName);
72         ExtentTestActions.takeScreenshot(Status.INFO, "vsp-found-repository",
73             String.format("Searching for VSP '%s' found in the repository", resourceName));
74     }
75
76     /**
77      * Imports the first VSP in the repository list.
78      *
79      * @param vspRepositoryModalComponent the repository modal component that contains the VSP list
80      * @return the resource creation page that the import action redirects
81      */
82     private ResourceCreatePage importVsp(final VspRepositoryModalComponent vspRepositoryModalComponent) {
83         extendTest.log(Status.INFO, String.format("Importing VSP '%s'", resourceName));
84         final ResourceCreatePage resourceCreatePage = vspRepositoryModalComponent.clickOnImportVsp(1);
85         resourceCreatePage.isLoaded();
86         ExtentTestActions.takeScreenshot(Status.INFO, "vsp-imported",
87             String.format("VSP '%s' was imported", resourceName));
88         return resourceCreatePage;
89     }
90 }