d4539b7f01d78bc852e2eb30183b90e4bfb1dc95
[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.general.ElementFactory;
25 import org.onap.sdc.frontend.ci.tests.verificator.CatalogVerificator;
26 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
27 import org.onap.sdc.frontend.ci.tests.datatypes.CheckBoxStatusEnum;
28 import org.onap.sdc.frontend.ci.tests.datatypes.DataTestIdEnum;
29 import org.onap.sdc.frontend.ci.tests.datatypes.LifeCycleStateEnum;
30 import org.onap.sdc.backend.ci.tests.datatypes.ResourceReqDetails;
31 import org.onap.sdc.backend.ci.tests.datatypes.ServiceReqDetails;
32 import org.onap.sdc.frontend.ci.tests.datatypes.TopMenuButtonsEnum;
33 import org.onap.sdc.frontend.ci.tests.datatypes.TypesEnum;
34 import org.onap.sdc.backend.ci.tests.datatypes.enums.UserRoleEnum;
35 import org.onap.sdc.frontend.ci.tests.execute.setup.SetupCDTest;
36 import org.onap.sdc.frontend.ci.tests.pages.ResourceGeneralPage;
37 import org.onap.sdc.frontend.ci.tests.utilities.CatalogUIUtilitis;
38 import org.onap.sdc.frontend.ci.tests.utilities.FileHandling;
39 import org.onap.sdc.frontend.ci.tests.utilities.GeneralUIUtils;
40 import org.onap.sdc.frontend.ci.tests.utilities.ResourceUIUtils;
41 import org.onap.sdc.frontend.ci.tests.utilities.ServiceUIUtils;
42 import org.openqa.selenium.WebElement;
43 import org.testng.annotations.BeforeMethod;
44 import org.testng.annotations.DataProvider;
45 import org.testng.annotations.Test;
46
47 import java.util.Arrays;
48 import java.util.List;
49
50 import static org.testng.AssertJUnit.assertTrue;
51
52 @Test(singleThreaded = true)
53 public class CatalogLeftPanelTest extends SetupCDTest {
54
55     private String filePath;
56
57     @BeforeMethod
58     public void beforeTest() {
59         filePath = FileHandling.getFilePath("");
60     }
61
62     private static String[] resourceTypes = Arrays.stream(ResourceTypeEnum.class.getEnumConstants()).
63             map(ResourceTypeEnum::name).toArray(String[]::new);
64
65     private static String[] catalogTypes = {"RESOURCE", "SERVICE"};
66
67     private static Object[][] provideData(String[] arObj) {
68         Object[][] arObject = new Object[arObj.length][];
69
70         int index = 0;
71         for (Object obj : arObj) {
72             arObject[index++] = new Object[]{obj};
73         }
74         return arObject;
75     }
76
77     @DataProvider(name = "Resource_Type_List")
78     private static Object[][] resourceTypeList() {
79         // Extract names of constants from enum as array of Strings
80         ResourceTypeEnum[] resourceEnums = {ResourceTypeEnum.CP, ResourceTypeEnum.VF, ResourceTypeEnum.VFC, ResourceTypeEnum.VL};
81         String[] resourcesForTest = Arrays.stream(resourceEnums).map(ResourceTypeEnum::name).toArray(String[]::new);
82         return provideData(resourcesForTest);
83     }
84
85     @DataProvider(name = "Type_List")
86     private static Object[][] typeList() {
87         // Extract names of constants from enum as array of Strings
88         Object[][] arObject = new Object[catalogTypes.length][];
89         int index = 0;
90         for (String catalogType : catalogTypes) {
91             if (catalogType.equals("RESOURCE")) {
92                 arObject[index++] = new Object[]{catalogType, resourceTypes};
93             } else {
94                 arObject[index++] = new Object[]{catalogType, new String[]{catalogType}};
95             }
96         }
97         return arObject;
98     }
99
100     @DataProvider(name = "Status_List")
101     private static Object[][] statusList() {
102         CheckBoxStatusEnum[] checkboxes = {CheckBoxStatusEnum.CERTIFIED,
103                 CheckBoxStatusEnum.IN_DESIGN,
104                 CheckBoxStatusEnum.DISTRIBUTED,
105                 CheckBoxStatusEnum.IN_TESTING,
106                 CheckBoxStatusEnum.READY_FOR_TESTING};
107         Object[][] arObject = new Object[checkboxes.length][];
108         int index = 0;
109         for (CheckBoxStatusEnum checkbox : checkboxes) {
110             if (checkbox.equals(CheckBoxStatusEnum.CERTIFIED)) {
111                 arObject[index++] = new Object[]{checkbox, Arrays.asList(LifeCycleStateEnum.CERTIFIED, LifeCycleStateEnum.DISTRIBUTED, LifeCycleStateEnum.WAITING_FOR_DISTRIBUTION)};
112             } else if (checkbox.equals(CheckBoxStatusEnum.IN_DESIGN)) {
113                 arObject[index++] = new Object[]{checkbox, Arrays.asList(LifeCycleStateEnum.CHECKIN, LifeCycleStateEnum.CHECKOUT)};
114             } else if (checkbox.equals(CheckBoxStatusEnum.DISTRIBUTED)) {
115                 arObject[index++] = new Object[]{checkbox, Arrays.asList(LifeCycleStateEnum.DISTRIBUTED)};
116             } else if (checkbox.equals(CheckBoxStatusEnum.IN_TESTING)) {
117                 arObject[index++] = new Object[]{checkbox, Arrays.asList(LifeCycleStateEnum.IN_TESTING)};
118             } else if (checkbox.equals(CheckBoxStatusEnum.READY_FOR_TESTING)) {
119                 arObject[index++] = new Object[]{checkbox, Arrays.asList(LifeCycleStateEnum.READY_FOR_TESTING)};
120             }
121         }
122         return arObject;
123     }
124
125     // filter by Type Resource in catalog
126     @Test(dataProvider = "Type_List")
127     public void filterByType(String catalogType, String[] classValues) throws Exception {
128         setLog(catalogType);
129 //              getExtendTest().setDescription(catalogType);
130
131         CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
132         CatalogUIUtilitis.catalogFilterTypeChecBox(TypesEnum.valueOf(catalogType));
133         CatalogVerificator.validateType(TypesEnum.valueOf(catalogType));
134     }
135
136     @Test(dataProvider = "Resource_Type_List")
137     public void filterByResourceType(String resourceType) throws Exception {
138         setLog(resourceType);
139 //              getExtendTest().setDescription(resourceType);                   
140
141         CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
142         CatalogUIUtilitis.catalogFilterTypeChecBox(TypesEnum.valueOf(resourceType));
143
144         CatalogVerificator.validateType(TypesEnum.valueOf(resourceType));
145     }
146
147     @Test(dataProvider = "Status_List")
148     public void filterByStatus(CheckBoxStatusEnum statusCheckbox, List<LifeCycleStateEnum> lifecycleStates) throws Exception {
149         setLog(statusCheckbox.name());
150 //              getExtendTest().setDescription(statusCheckbox.name());
151
152         CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
153         CatalogUIUtilitis.clickOnLeftPanelElement(DataTestIdEnum.CatalogPageLeftPanelFilterTitle.CATEGORIES);
154         CatalogUIUtilitis.catalogFilterStatusChecBox(statusCheckbox);
155         //TODO check the test after removing lifecycle steps for resource
156         CatalogVerificator.validateStatus(lifecycleStates, statusCheckbox.name());
157     }
158
159     @Test
160     public void filterByUpperCategory() throws Exception {
161         CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
162         CatalogUIUtilitis.clickOnLeftPanelElement(DataTestIdEnum.CatalogPageLeftPanelFilterTitle.TYPE);
163
164         WebElement categoryCheckbox = CatalogUIUtilitis.clickOnUpperCategoryCheckbox();
165
166         CatalogVerificator.validateCategory(categoryCheckbox.getAttribute("textContent").trim());
167     }
168
169     @Test
170     public void filterByGenericDatabaseSubCategory() throws Exception {
171         CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
172         CatalogUIUtilitis.clickOnLeftPanelElement(DataTestIdEnum.CatalogPageLeftPanelFilterTitle.TYPE);
173
174         WebElement checkboxElement = GeneralUIUtils.getElementsByCSS(DataTestIdEnum.CatalogPageLeftPanelSubCategoryCheckbox.DATABASE.getValue()).get(0);
175         String checkboxElementName = checkboxElement.getAttribute("textContent").trim();
176         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on %s subcategory ...", checkboxElementName));
177         GeneralUIUtils.clickOnAreaJS(checkboxElement);
178         CatalogVerificator.validateSubCategory("Generic", checkboxElementName);
179     }
180
181     @Test(priority = 1)
182     public void lastUpdatedService() throws Exception {
183         // create service
184         ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
185         ServiceUIUtils.createService(serviceMetadata);
186
187         ResourceGeneralPage.clickCheckinButton(serviceMetadata.getName());
188         CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
189         List<WebElement> cardElements = GeneralUIUtils.getElementsByCSS(DataTestIdEnum.DashboardCardEnum.INFO_NAME.getValue());
190         String firstElementName = cardElements.get(0).getAttribute("textContent").trim();
191         assertTrue(String.format("Wrong element name, Expected : %s , Actual: %s", serviceMetadata.getName(), firstElementName), serviceMetadata.getName().equals(firstElementName));
192     }
193
194     @Test(priority = 17)
195     public void lastUpdatedResource() throws Exception {
196         // create resource
197         ResourceReqDetails vfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
198         ResourceUIUtils.createVF(vfMetaData, getUser());
199
200         ResourceGeneralPage.clickCheckinButton(vfMetaData.getName());
201         CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
202         List<WebElement> cardElements = GeneralUIUtils.getElementsByCSS(DataTestIdEnum.DashboardCardEnum.INFO_NAME.getValue());
203         String firstElementName = cardElements.get(0).getAttribute("textContent").trim();
204         assertTrue(String.format("Wrong element name, Expected : %s , Actual: %s", vfMetaData.getName(), firstElementName), vfMetaData.getName().equals(firstElementName));
205     }
206
207     @Test(priority = 5)
208     public void fromCatalogCheckout() throws Exception {
209         // create resource
210         ResourceReqDetails vfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
211         ResourceUIUtils.createVF(vfMetaData, getUser());
212         ResourceGeneralPage.clickCheckinButton(vfMetaData.getName());
213
214         CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
215         GeneralUIUtils.findComponentAndClick(vfMetaData.getName());
216         ResourceGeneralPage.clickCheckoutButton();
217         ResourceGeneralPage.clickCheckinButton(vfMetaData.getName());
218     }
219
220     @Test
221     public void keepSearchResultsInCatalogAfterBrowserBack() throws Exception {
222         ResourceReqDetails resourceMetadata = ElementFactory.getDefaultResource();
223         ResourceUIUtils.createVF(resourceMetadata, getUser());
224         ResourceGeneralPage.clickCheckinButton(resourceMetadata.getName());
225         CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
226         CatalogUIUtilitis.catalogSearchBox(resourceMetadata.getName());
227         GeneralUIUtils.findComponentAndClick(resourceMetadata.getName());
228
229         GeneralUIUtils.clickOnBrowserBackButton();
230
231         int numOfElementsInFilteredCatalog = CatalogVerificator.getNumberOfElementsFromCatalogHeader();
232         assertTrue(String.format("Wrong number fo elements, Expected : %s , Actual: %s", 1, numOfElementsInFilteredCatalog), numOfElementsInFilteredCatalog == 1);
233
234         List<WebElement> cardElements = GeneralUIUtils.getElementsByCSS(DataTestIdEnum.DashboardCardEnum.INFO_NAME.getValue());
235         String firstElementName = cardElements.get(0).getAttribute("textContent").trim();
236         assertTrue(String.format("Wrong element name, Expected : %s , Actual: %s", resourceMetadata.getName(), firstElementName), resourceMetadata.getName().equals(firstElementName));
237     }
238
239     @Override
240     protected UserRoleEnum getRole() {
241         return UserRoleEnum.DESIGNER;
242     }
243
244 }