99fbc46ea2eb6937a38ecd2664eb49aef709519c
[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.composition;
21
22 import com.aventstack.extentreports.Status;
23 import java.util.Optional;
24 import org.onap.sdc.frontend.ci.tests.datatypes.composition.RelationshipInformation;
25 import org.onap.sdc.frontend.ci.tests.execute.setup.ExtentTestActions;
26 import org.onap.sdc.frontend.ci.tests.flow.AbstractUiTestFlow;
27 import org.onap.sdc.frontend.ci.tests.pages.PageObject;
28 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionPage;
29 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.RelationshipWizardComponent;
30 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.RelationshipWizardRequirementCapabilityComponent;
31 import org.openqa.selenium.WebDriver;
32
33 /**
34  * Creates a relationship between two nodes/component instances
35  */
36 public class CreateRelationshipFlow extends AbstractUiTestFlow {
37
38     private final RelationshipInformation relationshipInformation;
39     private CompositionPage compositionPage;
40
41     public CreateRelationshipFlow(final WebDriver webDriver, final RelationshipInformation relationshipInformation) {
42         super(webDriver);
43         this.relationshipInformation = relationshipInformation;
44     }
45
46     @Override
47     public Optional<? extends PageObject> run(final PageObject... pageObjects) {
48         compositionPage = findParameter(pageObjects, CompositionPage.class);
49         compositionPage.isLoaded();
50         final RelationshipWizardComponent relationshipWizardComponent = compositionPage
51             .createLink(relationshipInformation.getFromNode(), relationshipInformation.getToNode());
52         final RelationshipWizardRequirementCapabilityComponent requirementCapabilityComponent =
53             new RelationshipWizardRequirementCapabilityComponent(webDriver);
54         requirementCapabilityComponent.isLoaded();
55         requirementCapabilityComponent.selectRequirementOrCapability(relationshipInformation.getFromCapability());
56         ExtentTestActions.takeScreenshot(Status.INFO, "capability-selected",
57             String.format("Selected capability '%s'", relationshipInformation.getFromCapability()));
58         relationshipWizardComponent.clickOnNext();
59         requirementCapabilityComponent.isLoaded();
60         requirementCapabilityComponent.selectRequirementOrCapability(relationshipInformation.getToRequirement());
61         ExtentTestActions.takeScreenshot(Status.INFO, "requirement-selected",
62             String.format("Selected requirement '%s'", relationshipInformation.getToRequirement()));
63         relationshipWizardComponent.clickOnNext();
64         relationshipWizardComponent.clickOnNext();
65         relationshipWizardComponent.clickOnFinish();
66         compositionPage.isLoaded();
67         ExtentTestActions.takeScreenshot(Status.INFO, "relationship-created",
68             String.format("Relationship from '%s' to '%s' created", relationshipInformation.getFromNode(), relationshipInformation.getToNode()));
69         return Optional.of(compositionPage);
70     }
71
72     @Override
73     public Optional<CompositionPage> getLandedPage() {
74         return Optional.of(compositionPage);
75     }
76 }