c293d1cc5fd402990c0bbaef807ef7390614a414
[sdc.git] /
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.junit.jupiter.api.Assertions.assertTrue;
23
24 import java.util.Optional;
25
26 import org.onap.sdc.frontend.ci.tests.datatypes.ServiceDependencyProperty;
27 import org.onap.sdc.frontend.ci.tests.pages.PageObject;
28 import org.onap.sdc.frontend.ci.tests.pages.ServiceDependenciesEditor;
29 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionDetailSideBarComponent;
30 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionDetailSideBarComponent.CompositionDetailTabName;
31 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionPage;
32 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionSubstitutionFilterTab;
33 import org.openqa.selenium.WebDriver;
34
35 import com.aventstack.extentreports.Status;
36
37 public class CreateSubtitutionFilterFlow extends AbstractUiTestFlow {
38
39     private CompositionPage compositionPage;
40     private final ServiceDependencyProperty substitutionFilterProperty;
41
42     public CreateSubtitutionFilterFlow(final WebDriver webDriver, final ServiceDependencyProperty substitutionFilterProperty) {
43         super(webDriver);
44         this.substitutionFilterProperty = substitutionFilterProperty;
45     }
46
47     @Override
48     public Optional<PageObject> run(final PageObject... pageObjects) {
49         extendTest.log(Status.INFO, "Creating substitution filter");
50
51         compositionPage = getCompositionPage(pageObjects);
52         compositionPage.isLoaded();
53
54         final CompositionDetailSideBarComponent sideBar = compositionPage.getDetailSideBar();
55         sideBar.isLoaded();
56
57         final CompositionSubstitutionFilterTab compositionSubstitutionFilterTab = (CompositionSubstitutionFilterTab) sideBar.selectTab(CompositionDetailTabName.SUBSTITUTION_FILTER);
58         compositionSubstitutionFilterTab.isLoaded();
59
60         final ServiceDependenciesEditor compositionSubstitutionDependenciesEditor = compositionSubstitutionFilterTab.clickAddSubstitutionFilter();
61         compositionSubstitutionDependenciesEditor.isLoaded();
62         compositionSubstitutionDependenciesEditor.addProperty(substitutionFilterProperty);
63
64         compositionSubstitutionFilterTab.isLoaded();
65         assertTrue(compositionSubstitutionFilterTab.isSubstitutionFilterPresent(substitutionFilterProperty.getName()), "Created substitution filter is not present");
66
67         return Optional.of(compositionPage);
68     }
69
70     @Override
71     public Optional<? extends PageObject> getLandedPage() {
72         return Optional.ofNullable(compositionPage);
73     }
74
75     private CompositionPage getCompositionPage(final PageObject... pageObjects) {
76         return getParameter(pageObjects, CompositionPage.class)
77         .orElseGet(() -> {
78             return new CompositionPage(webDriver);
79         });
80     }
81 }