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