2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.sdc.frontend.ci.tests.execute.sanity;
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;
47 import java.util.Arrays;
48 import java.util.List;
50 import static org.testng.AssertJUnit.assertTrue;
52 @Test(singleThreaded = true)
53 public class CatalogLeftPanelTest extends SetupCDTest {
55 private String filePath;
58 public void beforeTest() {
59 filePath = FileHandling.getFilePath("");
62 private static String[] resourceTypes = Arrays.stream(ResourceTypeEnum.class.getEnumConstants()).
63 map(ResourceTypeEnum::name).toArray(String[]::new);
65 private static String[] catalogTypes = {"RESOURCE", "SERVICE"};
67 private static Object[][] provideData(String[] arObj) {
68 Object[][] arObject = new Object[arObj.length][];
71 for (Object obj : arObj) {
72 arObject[index++] = new Object[]{obj};
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);
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][];
90 for (String catalogType : catalogTypes) {
91 if (catalogType.equals("RESOURCE")) {
92 arObject[index++] = new Object[]{catalogType, resourceTypes};
94 arObject[index++] = new Object[]{catalogType, new String[]{catalogType}};
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][];
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)};
125 // filter by Type Resource in catalog
126 @Test(dataProvider = "Type_List")
127 public void filterByType(String catalogType, String[] classValues) throws Exception {
129 // getExtendTest().setDescription(catalogType);
131 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
132 CatalogUIUtilitis.catalogFilterTypeChecBox(TypesEnum.valueOf(catalogType));
133 CatalogVerificator.validateType(TypesEnum.valueOf(catalogType));
136 @Test(dataProvider = "Resource_Type_List")
137 public void filterByResourceType(String resourceType) throws Exception {
138 setLog(resourceType);
139 // getExtendTest().setDescription(resourceType);
141 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
142 CatalogUIUtilitis.catalogFilterTypeChecBox(TypesEnum.valueOf(resourceType));
144 CatalogVerificator.validateType(TypesEnum.valueOf(resourceType));
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());
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());
160 public void filterByUpperCategory() throws Exception {
161 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
162 CatalogUIUtilitis.clickOnLeftPanelElement(DataTestIdEnum.CatalogPageLeftPanelFilterTitle.TYPE);
164 WebElement categoryCheckbox = CatalogUIUtilitis.clickOnUpperCategoryCheckbox();
166 CatalogVerificator.validateCategory(categoryCheckbox.getAttribute("textContent").trim());
170 public void filterByGenericDatabaseSubCategory() throws Exception {
171 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
172 CatalogUIUtilitis.clickOnLeftPanelElement(DataTestIdEnum.CatalogPageLeftPanelFilterTitle.TYPE);
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);
182 public void lastUpdatedService() throws Exception {
184 ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
185 ServiceUIUtils.createService(serviceMetadata);
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));
195 public void lastUpdatedResource() throws Exception {
197 ResourceReqDetails vfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
198 ResourceUIUtils.createVF(vfMetaData, getUser());
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));
208 public void fromCatalogCheckout() throws Exception {
210 ResourceReqDetails vfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
211 ResourceUIUtils.createVF(vfMetaData, getUser());
212 ResourceGeneralPage.clickCheckinButton(vfMetaData.getName());
214 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
215 GeneralUIUtils.findComponentAndClick(vfMetaData.getName());
216 ResourceGeneralPage.clickCheckoutButton();
217 ResourceGeneralPage.clickCheckinButton(vfMetaData.getName());
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());
229 GeneralUIUtils.clickOnBrowserBackButton();
231 int numOfElementsInFilteredCatalog = CatalogVerificator.getNumberOfElementsFromCatalogHeader();
232 assertTrue(String.format("Wrong number fo elements, Expected : %s , Actual: %s", 1, numOfElementsInFilteredCatalog), numOfElementsInFilteredCatalog == 1);
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));
240 protected UserRoleEnum getRole() {
241 return UserRoleEnum.DESIGNER;