Onboard PNF software version Ui test case
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / flow / CheckSoftwareVersionPropertyFlow.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 static org.hamcrest.Matchers.containsInAnyOrder;
23 import static org.hamcrest.Matchers.hasSize;
24 import static org.junit.Assert.assertThat;
25
26 import com.aventstack.extentreports.Status;
27 import java.util.List;
28 import java.util.Optional;
29 import org.openecomp.sdc.ci.tests.pages.PageObject;
30 import org.openecomp.sdc.ci.tests.pages.ResourceLeftSideMenu;
31 import org.openecomp.sdc.ci.tests.pages.ResourcePropertiesAssignmentPage;
32 import org.openqa.selenium.WebDriver;
33
34 /**
35  * UI Flow for checking the software version property in a resource
36  */
37 public class CheckSoftwareVersionPropertyFlow extends AbstractUiTestFlow {
38
39     private final List<String> expectedSoftwareVersionList;
40
41     public CheckSoftwareVersionPropertyFlow(final WebDriver webDriver, final List<String> expectedSoftwareVersionList) {
42         super(webDriver);
43         this.expectedSoftwareVersionList = expectedSoftwareVersionList;
44     }
45
46     @Override
47     public Optional<PageObject> run(final PageObject... pageObjects) {
48         final ResourceLeftSideMenu resourceLeftSideMenu = new ResourceLeftSideMenu(webDriver);
49         resourceLeftSideMenu.isLoaded();
50
51         final ResourcePropertiesAssignmentPage resourcePropertiesAssignmentPage = accessPropertiesAssignmentPage();
52
53         checkSoftwareVersionProperty(resourcePropertiesAssignmentPage);
54         return Optional.empty();
55     }
56
57     /**
58      * Checks if the software_version property values are as expected by the {@link #expectedSoftwareVersionList}.
59      *
60      * @param resourcePropertiesAssignmentPage the resource properties assignment page
61      */
62     private void checkSoftwareVersionProperty(final ResourcePropertiesAssignmentPage resourcePropertiesAssignmentPage) {
63         extendTest.log(Status.INFO,
64             String.format("Checking the presence of software versions '%s' in 'software_versions' property",
65                 getSoftwareVersionListAsString())
66         );
67         final List<String> actualSoftwareVersionList = resourcePropertiesAssignmentPage.getSoftwareVersionProperty();
68         assertThat("Software Version should have the expected size", actualSoftwareVersionList,
69             hasSize(expectedSoftwareVersionList.size()));
70         assertThat("Software Version should be as expected", actualSoftwareVersionList,
71             containsInAnyOrder(expectedSoftwareVersionList.toArray(new String[0])));
72     }
73
74     /**
75      * Accesses the properties assignment page by clicking in the resource left side menu.
76      *
77      * @return the resulting resource properties assignment page
78      */
79     private ResourcePropertiesAssignmentPage accessPropertiesAssignmentPage() {
80         final ResourceLeftSideMenu resourceLeftSideMenu = new ResourceLeftSideMenu(webDriver);
81         resourceLeftSideMenu.isLoaded();
82
83         extendTest.log(Status.INFO,
84             String.format("Accessing the Properties Assignment page to check the software versions '%s'",
85                 getSoftwareVersionListAsString())
86         );
87         final ResourcePropertiesAssignmentPage resourcePropertiesAssignmentPage =
88             resourceLeftSideMenu.clickOnPropertiesAssignmentMenuItem();
89         resourcePropertiesAssignmentPage.isLoaded();
90         return resourcePropertiesAssignmentPage;
91     }
92
93     /**
94      * Converts the {@link #expectedSoftwareVersionList} in a comma + space separated string.
95      *
96      * @return the software version list as a comma + space separated string
97      */
98     private String getSoftwareVersionListAsString() {
99         return String.join(", ", expectedSoftwareVersionList);
100     }
101 }