9a44156d1aec4db6da3b5f4b2ad547d17a025130
[sdc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.sdc.frontend.ci.tests.execute.sanity;
22
23 import com.aventstack.extentreports.Status;
24 import org.onap.sdc.backend.ci.tests.utils.Utils;
25 import org.onap.sdc.backend.ci.tests.utils.general.ElementFactory;
26 import org.onap.sdc.frontend.ci.tests.verificator.CatalogVerificator;
27 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
28 import org.onap.sdc.frontend.ci.tests.datatypes.CheckBoxStatusEnum;
29 import org.onap.sdc.frontend.ci.tests.datatypes.DataTestIdEnum;
30 import org.onap.sdc.frontend.ci.tests.datatypes.LifeCycleStateEnum;
31 import org.onap.sdc.backend.ci.tests.datatypes.ResourceReqDetails;
32 import org.onap.sdc.backend.ci.tests.datatypes.ServiceReqDetails;
33 import org.onap.sdc.frontend.ci.tests.datatypes.TopMenuButtonsEnum;
34 import org.onap.sdc.frontend.ci.tests.datatypes.TypesEnum;
35 import org.onap.sdc.backend.ci.tests.datatypes.enums.UserRoleEnum;
36 import org.onap.sdc.frontend.ci.tests.execute.setup.SetupCDTest;
37 import org.onap.sdc.frontend.ci.tests.pages.ResourceGeneralPage;
38 import org.onap.sdc.frontend.ci.tests.utilities.CatalogUIUtilitis;
39 import org.onap.sdc.frontend.ci.tests.utilities.FileHandling;
40 import org.onap.sdc.frontend.ci.tests.utilities.GeneralUIUtils;
41 import org.onap.sdc.frontend.ci.tests.utilities.ResourceUIUtils;
42 import org.onap.sdc.frontend.ci.tests.utilities.ServiceUIUtils;
43 import org.openqa.selenium.WebElement;
44 import org.testng.annotations.BeforeMethod;
45 import org.testng.annotations.DataProvider;
46 import org.testng.annotations.Test;
47
48 import java.util.Arrays;
49 import java.util.List;
50
51 import static org.testng.AssertJUnit.assertTrue;
52
53 @Test(singleThreaded = true)
54 public class CatalogLeftPanelTestWithTime extends SetupCDTest {
55
56     private static final int REGULAR_TEST_RUN_TIME = 400;
57     private String filePath;
58
59     @BeforeMethod
60     public void beforeTest() {
61         filePath = FileHandling.getFilePath("");
62     }
63
64     private static String[] resourceTypes = Arrays.stream(ResourceTypeEnum.class.getEnumConstants()).
65             map(ResourceTypeEnum::name).toArray(String[]::new);
66
67     private static String[] catalogTypes = {"RESOURCE", "SERVICE"};
68
69     private static Object[][] provideData(String[] arObj) {
70         Object[][] arObject = new Object[arObj.length][];
71
72         int index = 0;
73         for (Object obj : arObj) {
74             arObject[index++] = new Object[]{obj};
75         }
76         return arObject;
77     }
78
79     @DataProvider(name = "Resource_Type_List")
80     private static Object[][] resourceTypeList() {
81         // Extract names of constants from enum as array of Strings
82         ResourceTypeEnum[] resourceEnums = {ResourceTypeEnum.CP, ResourceTypeEnum.VF, ResourceTypeEnum.VFC, ResourceTypeEnum.VL};
83         String[] resourcesForTest = Arrays.stream(resourceEnums).map(ResourceTypeEnum::name).toArray(String[]::new);
84         return provideData(resourcesForTest);
85     }
86
87     @DataProvider(name = "Type_List")
88     private static Object[][] typeList() {
89         // Extract names of constants from enum as array of Strings
90         Object[][] arObject = new Object[catalogTypes.length][];
91         int index = 0;
92         for (String catalogType : catalogTypes) {
93             if (catalogType.equals("RESOURCE")) {
94                 arObject[index++] = new Object[]{catalogType, resourceTypes};
95             } else {
96                 arObject[index++] = new Object[]{catalogType, new String[]{catalogType}};
97             }
98         }
99         return arObject;
100     }
101
102     @DataProvider(name = "Status_List")
103     private static Object[][] statusList() {
104         CheckBoxStatusEnum[] checkboxes = {CheckBoxStatusEnum.CERTIFIED,
105                 CheckBoxStatusEnum.IN_DESIGN,
106                 CheckBoxStatusEnum.DISTRIBUTED,
107                 CheckBoxStatusEnum.IN_TESTING,
108                 CheckBoxStatusEnum.READY_FOR_TESTING};
109         Object[][] arObject = new Object[checkboxes.length][];
110         int index = 0;
111         for (CheckBoxStatusEnum checkbox : checkboxes) {
112             if (checkbox.equals(CheckBoxStatusEnum.CERTIFIED)) {
113                 arObject[index++] = new Object[]{checkbox, Arrays.asList(LifeCycleStateEnum.CERTIFIED, LifeCycleStateEnum.DISTRIBUTED, LifeCycleStateEnum.WAITING_FOR_DISTRIBUTION)};
114             } else if (checkbox.equals(CheckBoxStatusEnum.IN_DESIGN)) {
115                 arObject[index++] = new Object[]{checkbox, Arrays.asList(LifeCycleStateEnum.CHECKIN, LifeCycleStateEnum.CHECKOUT)};
116             } else if (checkbox.equals(CheckBoxStatusEnum.DISTRIBUTED)) {
117                 arObject[index++] = new Object[]{checkbox, Arrays.asList(LifeCycleStateEnum.DISTRIBUTED)};
118             } else if (checkbox.equals(CheckBoxStatusEnum.IN_TESTING)) {
119                 arObject[index++] = new Object[]{checkbox, Arrays.asList(LifeCycleStateEnum.IN_TESTING)};
120             } else if (checkbox.equals(CheckBoxStatusEnum.READY_FOR_TESTING)) {
121                 arObject[index++] = new Object[]{checkbox, Arrays.asList(LifeCycleStateEnum.READY_FOR_TESTING)};
122             }
123         }
124         return arObject;
125     }
126
127     // filter by Type Resource in catalog
128     @Test(dataProvider = "Type_List")
129     public void filterByTypeWithTime(String catalogType, String[] classValues) throws Exception {
130         setLog(catalogType);
131         //Load catalog
132         Long actualTestRunTime = GeneralUIUtils.getAndValidateActionDuration(() ->
133                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG), REGULAR_TEST_RUN_TIME);
134         SetupCDTest.getExtendTest().log(Status.INFO, "Actual catalog loading time is  "
135                 + actualTestRunTime + " seconds");
136         //Filter by type
137         actualTestRunTime = Utils.getAndValidateActionDuration(() -> {
138             try {
139                 CatalogUIUtilitis.catalogFilterTypeChecBox(TypesEnum.valueOf(catalogType));
140             } catch (Exception e) {
141                 e.printStackTrace();
142             }
143         }, REGULAR_TEST_RUN_TIME);
144         SetupCDTest.getExtendTest().log(Status.INFO, "Actual catalog filtering time is  "
145                 + actualTestRunTime + " seconds");
146         //Validate number of elements after filtering
147         CatalogVerificator.validateType(TypesEnum.valueOf(catalogType));
148     }
149
150     @Test(dataProvider = "Resource_Type_List")
151     public void filterByResourceTypeWithTime(String resourceType) throws Exception {
152         setLog(resourceType);
153         //Load catalog
154         Long actualTestRunTime = Utils.getAndValidateActionDuration(() ->
155                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG), REGULAR_TEST_RUN_TIME);
156         SetupCDTest.getExtendTest().log(Status.INFO, "Actual catalog loading time is  "
157                 + actualTestRunTime + " seconds");
158         //Filter by resource type
159         actualTestRunTime = Utils.getAndValidateActionDuration(() -> {
160             try {
161                 CatalogUIUtilitis.catalogFilterTypeChecBox(TypesEnum.valueOf(resourceType));
162             } catch (Exception e) {
163                 e.printStackTrace();
164             }
165         }, REGULAR_TEST_RUN_TIME);
166         SetupCDTest.getExtendTest().log(Status.INFO, "Actual catalog filtering time is  "
167                 + actualTestRunTime + " seconds");
168         //Validate number of elements after filtering
169         CatalogVerificator.validateType(TypesEnum.valueOf(resourceType));
170     }
171
172     @Test(dataProvider = "Status_List")
173     public void filterByStatus(CheckBoxStatusEnum statusCheckbox, List<LifeCycleStateEnum> lifecycleStates) throws Exception {
174         setLog(statusCheckbox.name());
175         //Load catalog
176         Long actualTestRunTime = Utils.getAndValidateActionDuration(() ->
177                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG), REGULAR_TEST_RUN_TIME);
178         SetupCDTest.getExtendTest().log(Status.INFO, "Actual catalog loading time is  "
179                 + actualTestRunTime + " seconds");
180         CatalogUIUtilitis.clickOnLeftPanelElement(DataTestIdEnum.CatalogPageLeftPanelFilterTitle.CATEGORIES);
181         //Filter by resource type
182         actualTestRunTime = Utils.getAndValidateActionDuration(() -> CatalogUIUtilitis.catalogFilterStatusChecBox(statusCheckbox), REGULAR_TEST_RUN_TIME);
183         SetupCDTest.getExtendTest().log(Status.INFO, "Actual catalog filtering time is  "
184                 + actualTestRunTime + " seconds");
185         //TODO check the test after removing lifecycle steps for resource
186         //Validate number of elements after filtering
187         CatalogVerificator.validateStatus(lifecycleStates, statusCheckbox.name());
188     }
189
190     @Test
191     public void filterByUpperCategory() throws Exception {
192         //Load catalog
193         Long actualTestRunTime = Utils.getAndValidateActionDuration(() ->
194                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG), REGULAR_TEST_RUN_TIME);
195         SetupCDTest.getExtendTest().log(Status.INFO, "Actual catalog loading time is  "
196                 + actualTestRunTime + " seconds");
197         //Filter by Upper Category
198         CatalogUIUtilitis.clickOnLeftPanelElement(DataTestIdEnum.CatalogPageLeftPanelFilterTitle.TYPE);
199         actualTestRunTime = Utils.getAndValidateActionDuration(() -> CatalogUIUtilitis.clickOnUpperCategoryCheckbox(), REGULAR_TEST_RUN_TIME);
200         SetupCDTest.getExtendTest().log(Status.INFO, "Actual catalog filtering time is  "
201                 + actualTestRunTime + " seconds");
202         WebElement categoryCheckbox = CatalogUIUtilitis.getCategoryCheckbox();
203         CatalogVerificator.validateCategory(categoryCheckbox.getAttribute("textContent").trim());
204     }
205
206     @Test
207     public void filterByGenericDatabaseSubCategory() throws Exception {
208         //Load catalog
209         Long actualTestRunTime = Utils.getAndValidateActionDuration(() ->
210                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG), REGULAR_TEST_RUN_TIME);
211         SetupCDTest.getExtendTest().log(Status.INFO, "Actual catalog loading time is  "
212                 + actualTestRunTime + " seconds");
213         CatalogUIUtilitis.clickOnLeftPanelElement(DataTestIdEnum.CatalogPageLeftPanelFilterTitle.TYPE);
214         WebElement checkboxElement = GeneralUIUtils.getElementsByCSS(DataTestIdEnum.CatalogPageLeftPanelSubCategoryCheckbox.DATABASE.getValue()).get(0);
215         String checkboxElementName = checkboxElement.getAttribute("textContent").trim();
216         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on %s subcategory ...", checkboxElementName));
217         //Filter by sub category
218         actualTestRunTime = Utils.getAndValidateActionDuration(() -> {
219             try {
220                 GeneralUIUtils.clickOnAreaJS(checkboxElement);
221             } catch (Exception e) {
222                 e.printStackTrace();
223             }
224         }, REGULAR_TEST_RUN_TIME);
225         SetupCDTest.getExtendTest().log(Status.INFO, "Actual catalog filtering time is  "
226                 + actualTestRunTime + " seconds");
227         //Validate filtering results
228         CatalogVerificator.validateSubCategory("Generic", checkboxElementName);
229     }
230
231     @Test(priority = 1)
232     public void lastUpdatedService() throws Exception {
233         // create service
234         ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
235         ServiceUIUtils.createService(serviceMetadata);
236
237         ResourceGeneralPage.clickCheckinButton(serviceMetadata.getName());
238         CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
239         List<WebElement> cardElements = GeneralUIUtils.getElementsByCSS(DataTestIdEnum.DashboardCardEnum.INFO_NAME.getValue());
240         String firstElementName = cardElements.get(0).getAttribute("textContent").trim();
241         assertTrue(String.format("Wrong element name, Expected : %s , Actual: %s", serviceMetadata.getName(), firstElementName), serviceMetadata.getName().equals(firstElementName));
242     }
243
244     @Test(priority = 17)
245     public void lastUpdatedResource() throws Exception {
246         // create resource
247         ResourceReqDetails vfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
248         ResourceUIUtils.createVF(vfMetaData, getUser());
249
250         ResourceGeneralPage.clickCheckinButton(vfMetaData.getName());
251         CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
252         List<WebElement> cardElements = GeneralUIUtils.getElementsByCSS(DataTestIdEnum.DashboardCardEnum.INFO_NAME.getValue());
253         String firstElementName = cardElements.get(0).getAttribute("textContent").trim();
254         assertTrue(String.format("Wrong element name, Expected : %s , Actual: %s", vfMetaData.getName(), firstElementName), vfMetaData.getName().equals(firstElementName));
255     }
256
257     @Test(priority = 5)
258     public void fromCatalogCheckout() throws Exception {
259         // create resource
260         ResourceReqDetails vfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
261         ResourceUIUtils.createVF(vfMetaData, getUser());
262         ResourceGeneralPage.clickCheckinButton(vfMetaData.getName());
263         CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
264         //Search in catalog
265         GeneralUIUtils.findComponentAndClick(vfMetaData.getName());
266         ResourceGeneralPage.clickCheckoutButton();
267         ResourceGeneralPage.clickCheckinButton(vfMetaData.getName());
268     }
269
270     @Test
271     public void keepSearchResultsInCatalogAfterBrowserBack() throws Exception {
272         ResourceReqDetails resourceMetadata = ElementFactory.getDefaultResource();
273         ResourceUIUtils.createVF(resourceMetadata, getUser());
274         ResourceGeneralPage.clickCheckinButton(resourceMetadata.getName());
275         CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
276         CatalogUIUtilitis.catalogSearchBox(resourceMetadata.getName());
277         GeneralUIUtils.findComponentAndClick(resourceMetadata.getName());
278
279         GeneralUIUtils.clickOnBrowserBackButton();
280
281         int numOfElementsInFilteredCatalog = CatalogVerificator.getNumberOfElementsFromCatalogHeader();
282         assertTrue(String.format("Wrong number fo elements, Expected : %s , Actual: %s", 1, numOfElementsInFilteredCatalog), numOfElementsInFilteredCatalog == 1);
283
284         List<WebElement> cardElements = GeneralUIUtils.getElementsByCSS(DataTestIdEnum.DashboardCardEnum.INFO_NAME.getValue());
285         String firstElementName = cardElements.get(0).getAttribute("textContent").trim();
286         assertTrue(String.format("Wrong element name, Expected : %s , Actual: %s", resourceMetadata.getName(), firstElementName), resourceMetadata.getName().equals(firstElementName));
287     }
288
289     @Override
290     protected UserRoleEnum getRole() {
291         return UserRoleEnum.DESIGNER;
292     }
293
294 }