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.openecomp.sdc.ci.tests.execute.sanity;
23 import com.aventstack.extentreports.Status;
24 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
25 import org.openecomp.sdc.ci.tests.datatypes.*;
26 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.CatalogPageLeftPanelSubCategoryCheckbox;
27 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
28 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
29 import org.openecomp.sdc.ci.tests.pages.ResourceGeneralPage;
30 import org.openecomp.sdc.ci.tests.utilities.*;
31 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
32 import org.openecomp.sdc.ci.tests.verificator.CatalogVerificator;
33 import org.openqa.selenium.WebElement;
34 import org.testng.annotations.BeforeMethod;
35 import org.testng.annotations.DataProvider;
36 import org.testng.annotations.Test;
38 import java.util.Arrays;
39 import java.util.List;
41 import static org.testng.AssertJUnit.assertTrue;
43 @Test(singleThreaded = true)
44 public class CatalogLeftPanelTest extends SetupCDTest{
46 private String filePath;
48 public void beforeTest(){
49 filePath = FileHandling.getFilePath("");
52 public static String[] resourceTypes = Arrays.stream(ResourceTypeEnum.class.getEnumConstants()).
53 map(ResourceTypeEnum::name).toArray(String[]::new);
55 public static String[] catalogTypes = {"RESOURCE", "SERVICE"};
57 public static Object[][] provideData(String[] arObj) {
58 Object[][] arObject = new Object[arObj.length][];
61 for (Object obj : arObj) {
62 arObject[index++] = new Object[]{obj};
67 @DataProvider(name = "Resource_Type_List")
68 private static final Object[][] resourceTypeList(){
69 // Extract names of constants from enum as array of Strings
70 ResourceTypeEnum[] resourceEnums = {ResourceTypeEnum.CP, ResourceTypeEnum.VF, ResourceTypeEnum.VFC, ResourceTypeEnum.VL};
71 String[] resourcesForTest = Arrays.stream(resourceEnums).map(ResourceTypeEnum::name).toArray(String[]::new);
72 return provideData(resourcesForTest);
75 @DataProvider(name = "Type_List")
76 private static final Object[][] typeList(){
77 // Extract names of constants from enum as array of Strings
78 Object[][] arObject = new Object[catalogTypes.length][];
80 for (String catalogType : catalogTypes) {
81 if (catalogType.equals("RESOURCE")){
82 arObject[index++] = new Object[]{catalogType, resourceTypes};
84 arObject[index++] = new Object[]{catalogType, new String[] {catalogType}};
90 @DataProvider(name = "Status_List")
91 private static final Object[][] statusList(){
92 CheckBoxStatusEnum[] checkboxes = {CheckBoxStatusEnum.CERTIFIED,
93 CheckBoxStatusEnum.IN_DESIGN,
94 CheckBoxStatusEnum.DISTRIBUTED,
95 CheckBoxStatusEnum.IN_TESTING,
96 CheckBoxStatusEnum.READY_FOR_TESTING};
97 Object[][] arObject = new Object[checkboxes.length][];
99 for (CheckBoxStatusEnum checkbox: checkboxes) {
100 if (checkbox.equals(CheckBoxStatusEnum.CERTIFIED)){
101 arObject[index++] = new Object[]{checkbox, Arrays.asList(LifeCycleStateEnum.CERTIFIED, LifeCycleStateEnum.DISTRIBUTED, LifeCycleStateEnum.WAITING_FOR_DISTRIBUTION) };
102 } else if (checkbox.equals(CheckBoxStatusEnum.IN_DESIGN)) {
103 arObject[index++] = new Object[]{checkbox, Arrays.asList(LifeCycleStateEnum.CHECKIN, LifeCycleStateEnum.CHECKOUT)};
104 } else if (checkbox.equals(CheckBoxStatusEnum.DISTRIBUTED)) {
105 arObject[index++] = new Object[]{checkbox, Arrays.asList(LifeCycleStateEnum.DISTRIBUTED)};
106 } else if (checkbox.equals(CheckBoxStatusEnum.IN_TESTING)) {
107 arObject[index++] = new Object[]{checkbox, Arrays.asList(LifeCycleStateEnum.IN_TESTING)};
108 } else if (checkbox.equals(CheckBoxStatusEnum.READY_FOR_TESTING)) {
109 arObject[index++] = new Object[]{checkbox, Arrays.asList(LifeCycleStateEnum.READY_FOR_TESTING)};
115 // filter by Type Resource in catalog
116 @Test(dataProvider = "Type_List")
117 public void filterByType(String catalogType, String[] classValues ) throws Exception {
119 // getExtendTest().setDescription(catalogType);
121 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
122 CatalogUIUtilitis.catalogFilterTypeChecBox(TypesEnum.valueOf(catalogType));
123 CatalogVerificator.validateType(TypesEnum.valueOf(catalogType));
126 @Test(dataProvider = "Resource_Type_List")
127 public void filterByResourceType(String resourceType) throws Exception {
128 setLog(resourceType);
129 // getExtendTest().setDescription(resourceType);
131 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
132 CatalogUIUtilitis.catalogFilterTypeChecBox(TypesEnum.valueOf(resourceType));
134 CatalogVerificator.validateType(TypesEnum.valueOf(resourceType));
137 @Test(dataProvider = "Status_List")
138 public void filterByStatus(CheckBoxStatusEnum statusCheckbox, List<LifeCycleStateEnum> lifecycleStates) throws Exception{
139 setLog(statusCheckbox.name());
140 // getExtendTest().setDescription(statusCheckbox.name());
142 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
143 CatalogUIUtilitis.clickOnLeftPanelElement(DataTestIdEnum.CatalogPageLeftPanelFilterTitle.CATEGORIES);
144 CatalogUIUtilitis.catalogFilterStatusChecBox(statusCheckbox);
145 //TODO check the test after removing lifecycle steps for resource
146 CatalogVerificator.validateStatus(lifecycleStates, statusCheckbox.name());
150 public void filterByUpperCategory() throws Exception{
151 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
152 CatalogUIUtilitis.clickOnLeftPanelElement(DataTestIdEnum.CatalogPageLeftPanelFilterTitle.TYPE);
154 WebElement categoryCheckbox = CatalogUIUtilitis.clickOnUpperCategoryCheckbox();
156 CatalogVerificator.validateCategory(categoryCheckbox.getAttribute("textContent").trim());
160 public void filterByGenericDatabaseSubCategory() throws Exception{
161 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
162 CatalogUIUtilitis.clickOnLeftPanelElement(DataTestIdEnum.CatalogPageLeftPanelFilterTitle.TYPE);
164 WebElement checkboxElement = GeneralUIUtils.getElementsByCSS(CatalogPageLeftPanelSubCategoryCheckbox.DATABASE.getValue()).get(0);
165 String checkboxElementName = checkboxElement.getAttribute("textContent").trim();
166 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on %s subcategory ...", checkboxElementName));
167 GeneralUIUtils.clickOnAreaJS(checkboxElement);
168 CatalogVerificator.validateSubCategory("Generic", checkboxElementName);
172 public void lastUpdatedService() throws Exception{
174 ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
175 ServiceUIUtils.createService(serviceMetadata, getUser());
177 ResourceGeneralPage.clickCheckinButton(serviceMetadata.getName());
178 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
179 List<WebElement> cardElements = GeneralUIUtils.getElementsByCSS(DataTestIdEnum.DashboardCardEnum.INFO_NAME.getValue());
180 String firstElementName = cardElements.get(0).getAttribute("textContent").trim();
181 assertTrue(String.format("Wrong element name, Expected : %s , Actual: %s", serviceMetadata.getName(), firstElementName), serviceMetadata.getName().equals(firstElementName));
185 public void lastUpdatedResource() throws Exception{
187 ResourceReqDetails vfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
188 ResourceUIUtils.createVF(vfMetaData, getUser());
190 ResourceGeneralPage.clickCheckinButton(vfMetaData.getName());
191 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
192 List<WebElement> cardElements = GeneralUIUtils.getElementsByCSS(DataTestIdEnum.DashboardCardEnum.INFO_NAME.getValue());
193 String firstElementName = cardElements.get(0).getAttribute("textContent").trim();
194 assertTrue(String.format("Wrong element name, Expected : %s , Actual: %s", vfMetaData.getName(), firstElementName), vfMetaData.getName().equals(firstElementName));
198 public void fromCatalogCheckout() throws Exception{
200 ResourceReqDetails vfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
201 ResourceUIUtils.createVF(vfMetaData, getUser());
202 ResourceGeneralPage.clickCheckinButton(vfMetaData.getName());
204 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
205 GeneralUIUtils.findComponentAndClick(vfMetaData.getName());
206 ResourceGeneralPage.clickCheckoutButton();
207 ResourceGeneralPage.clickCheckinButton(vfMetaData.getName());
211 public void keepSearchResultsInCatalogAfterBrowserBack() throws Exception{
212 ResourceReqDetails resourceMetadata = ElementFactory.getDefaultResource();
213 ResourceUIUtils.createVF(resourceMetadata, getUser());
214 ResourceGeneralPage.clickCheckinButton(resourceMetadata.getName());
215 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
216 CatalogUIUtilitis.catalogSearchBox(resourceMetadata.getName());
217 GeneralUIUtils.findComponentAndClick(resourceMetadata.getName());
219 GeneralUIUtils.clickOnBrowserBackButton();
221 int numOfElementsInFilteredCatalog = CatalogVerificator.getNumberOfElementsFromCatalogHeader();
222 assertTrue(String.format("Wrong number fo elements, Expected : %s , Actual: %s", 1, numOfElementsInFilteredCatalog), numOfElementsInFilteredCatalog == 1 );
224 List<WebElement> cardElements = GeneralUIUtils.getElementsByCSS(DataTestIdEnum.DashboardCardEnum.INFO_NAME.getValue());
225 String firstElementName = cardElements.get(0).getAttribute("textContent").trim();
226 assertTrue(String.format("Wrong element name, Expected : %s , Actual: %s", resourceMetadata.getName(), firstElementName), resourceMetadata.getName().equals(firstElementName));
230 protected UserRoleEnum getRole() {
231 return UserRoleEnum.DESIGNER;