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