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 static org.testng.AssertJUnit.assertTrue;
26 import java.util.Arrays;
27 import java.util.List;
29 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
30 import org.openecomp.sdc.ci.tests.datatypes.CheckBoxStatusEnum;
31 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
32 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.CatalogPageLeftPanelSubCategoryCheckbox;
33 import org.openecomp.sdc.ci.tests.datatypes.LifeCycleStateEnum;
34 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
35 import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
36 import org.openecomp.sdc.ci.tests.datatypes.TopMenuButtonsEnum;
37 import org.openecomp.sdc.ci.tests.datatypes.TypesEnum;
38 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
39 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
40 import org.openecomp.sdc.ci.tests.pages.ResourceGeneralPage;
41 import org.openecomp.sdc.ci.tests.utilities.CatalogUIUtilitis;
42 import org.openecomp.sdc.ci.tests.utilities.FileHandling;
43 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
44 import org.openecomp.sdc.ci.tests.utilities.ResourceUIUtils;
45 import org.openecomp.sdc.ci.tests.utilities.ServiceUIUtils;
46 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
47 import org.openecomp.sdc.ci.tests.verificator.CatalogVerificator;
48 import org.openqa.selenium.WebElement;
49 import org.testng.annotations.BeforeMethod;
50 import org.testng.annotations.DataProvider;
51 import org.testng.annotations.Test;
53 import com.aventstack.extentreports.Status;
55 @Test(singleThreaded = true)
56 public class CatalogLeftPanelTest extends SetupCDTest{
58 private String filePath;
60 public void beforeTest(){
61 filePath = System.getProperty("filepath");
63 if (filePath == null && System.getProperty("os.name").contains("Windows")) {
64 filePath = FileHandling.getResourcesFilesPath();
67 else if(filePath.isEmpty() && !System.getProperty("os.name").contains("Windows")){
68 filePath = FileHandling.getBasePath() + File.separator + "Files" + File.separator;
72 public static String[] resourceTypes = Arrays.stream(ResourceTypeEnum.class.getEnumConstants()).
73 map(ResourceTypeEnum::name).toArray(String[]::new);
75 public static String[] catalogTypes = {"RESOURCE", "SERVICE", "PRODUCT"};
77 public static Object[][] provideData(String[] arObj) {
78 Object[][] arObject = new Object[arObj.length][];
81 for (Object obj : arObj) {
82 arObject[index++] = new Object[]{obj};
87 @DataProvider(name = "Resource_Type_List")
88 private static final Object[][] resourceTypeList(){
89 // Extract names of constants from enum as array of Strings
90 ResourceTypeEnum[] resourceEnums = {ResourceTypeEnum.CP, ResourceTypeEnum.VF, ResourceTypeEnum.VFC, ResourceTypeEnum.VL};
91 String[] resourcesForTest = Arrays.stream(resourceEnums).map(ResourceTypeEnum::name).toArray(String[]::new);
92 return provideData(resourcesForTest);
95 @DataProvider(name = "Type_List")
96 private static final Object[][] typeList(){
97 // Extract names of constants from enum as array of Strings
98 Object[][] arObject = new Object[catalogTypes.length][];
100 for (String catalogType : catalogTypes) {
101 if (catalogType.equals("RESOURCE")){
102 arObject[index++] = new Object[]{catalogType, resourceTypes};
104 arObject[index++] = new Object[]{catalogType, new String[] {catalogType}};
110 @DataProvider(name = "Status_List")
111 private static final Object[][] statusList(){
112 CheckBoxStatusEnum[] checkboxes = {CheckBoxStatusEnum.CERTIFIED,
113 CheckBoxStatusEnum.IN_DESIGN,
114 CheckBoxStatusEnum.DISTRIBUTED,
115 CheckBoxStatusEnum.IN_TESTING,
116 CheckBoxStatusEnum.READY_FOR_TESTING};
117 Object[][] arObject = new Object[checkboxes.length][];
119 for (CheckBoxStatusEnum checkbox: checkboxes) {
120 if (checkbox.equals(CheckBoxStatusEnum.CERTIFIED)){
121 arObject[index++] = new Object[]{checkbox, Arrays.asList(LifeCycleStateEnum.CERTIFIED, LifeCycleStateEnum.DISTRIBUTED, LifeCycleStateEnum.WAITING_FOR_DISTRIBUTION) };
122 } else if (checkbox.equals(CheckBoxStatusEnum.IN_DESIGN)) {
123 arObject[index++] = new Object[]{checkbox, Arrays.asList(LifeCycleStateEnum.CHECKIN, LifeCycleStateEnum.CHECKOUT)};
124 } else if (checkbox.equals(CheckBoxStatusEnum.DISTRIBUTED)) {
125 arObject[index++] = new Object[]{checkbox, Arrays.asList(LifeCycleStateEnum.DISTRIBUTED)};
126 } else if (checkbox.equals(CheckBoxStatusEnum.IN_TESTING)) {
127 arObject[index++] = new Object[]{checkbox, Arrays.asList(LifeCycleStateEnum.IN_TESTING)};
128 } else if (checkbox.equals(CheckBoxStatusEnum.READY_FOR_TESTING)) {
129 arObject[index++] = new Object[]{checkbox, Arrays.asList(LifeCycleStateEnum.READY_FOR_TESTING)};
135 // filter by Type Resource in catalog
136 @Test(dataProvider = "Type_List")
137 public void filterByType(String catalogType, String[] classValues ) throws Exception {
139 // getExtendTest().setDescription(catalogType);
141 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
142 CatalogUIUtilitis.catalogFilterTypeChecBox(TypesEnum.valueOf(catalogType));
144 CatalogVerificator.validateType(TypesEnum.valueOf(catalogType));
147 @Test(dataProvider = "Resource_Type_List")
148 public void filterByResourceType(String resourceType) throws Exception {
149 setLog(resourceType);
150 // getExtendTest().setDescription(resourceType);
152 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
153 CatalogUIUtilitis.catalogFilterTypeChecBox(TypesEnum.valueOf(resourceType));
155 CatalogVerificator.validateType(TypesEnum.valueOf(resourceType));
158 @Test(dataProvider = "Status_List")
159 public void filterByStatus(CheckBoxStatusEnum statusCheckbox, List<LifeCycleStateEnum> lifecycleStates) throws Exception{
160 setLog(statusCheckbox.name());
161 // getExtendTest().setDescription(statusCheckbox.name());
163 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
164 CatalogUIUtilitis.clickOnLeftPanelElement(DataTestIdEnum.CatalogPageLeftPanelFilterTitle.CATEGORIES);
165 CatalogUIUtilitis.catalogFilterStatusChecBox(statusCheckbox);
167 CatalogVerificator.validateStatus(lifecycleStates, statusCheckbox.name());
171 public void filterByUpperCategory() throws Exception{
172 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
173 CatalogUIUtilitis.clickOnLeftPanelElement(DataTestIdEnum.CatalogPageLeftPanelFilterTitle.TYPE);
175 WebElement categorieCheckbox = CatalogUIUtilitis.clickOnUpperCategoryCheckbox();
177 CatalogVerificator.validateCategory(categorieCheckbox.getAttribute("textContent").trim());
181 public void filterByGenericDtabaseSubCategory() throws Exception{
182 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
183 CatalogUIUtilitis.clickOnLeftPanelElement(DataTestIdEnum.CatalogPageLeftPanelFilterTitle.TYPE);
185 WebElement checkboxElement = GeneralUIUtils.getElementsByCSS(CatalogPageLeftPanelSubCategoryCheckbox.DATABASE.getValue()).get(0);
186 String checkboxElementName = checkboxElement.getAttribute("textContent").trim();
187 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on %s subcategory ...", checkboxElementName));
188 GeneralUIUtils.clickOnAreaJS(checkboxElement);
189 CatalogVerificator.validateSubCategory("Generic", checkboxElementName);
193 public void lastUpdatedService() throws Exception{
195 ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
196 ServiceUIUtils.createService(serviceMetadata, getUser());
198 ResourceGeneralPage.clickCheckinButton(serviceMetadata.getName());
199 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
200 List<WebElement> cardElements = GeneralUIUtils.getElementsByCSS(DataTestIdEnum.DashboardCardEnum.INFO_NAME.getValue());
201 String firstElementName = cardElements.get(0).getAttribute("textContent").trim();
202 assertTrue(String.format("Wrong element name, Exepected : %s , Actual: %s", serviceMetadata.getName(), firstElementName), serviceMetadata.getName().equals(firstElementName));
206 public void lastUpdatedResource() throws Exception{
208 ResourceReqDetails vfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
209 ResourceUIUtils.createResource(vfMetaData, getUser());
211 ResourceGeneralPage.clickCheckinButton(vfMetaData.getName());
212 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
213 List<WebElement> cardElements = GeneralUIUtils.getElementsByCSS(DataTestIdEnum.DashboardCardEnum.INFO_NAME.getValue());
214 String firstElementName = cardElements.get(0).getAttribute("textContent").trim();
215 assertTrue(String.format("Wrong element name, Exepected : %s , Actual: %s", vfMetaData.getName(), firstElementName), vfMetaData.getName().equals(firstElementName));
219 public void fromCatalogCheckout() throws Exception{
221 ResourceReqDetails vfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
222 ResourceUIUtils.createResource(vfMetaData, getUser());
224 ResourceGeneralPage.clickCheckinButton(vfMetaData.getName());
225 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
226 GeneralUIUtils.findComponentAndClickInCatalog(vfMetaData.getName());
227 ResourceGeneralPage.clickCheckoutButton();
228 ResourceGeneralPage.clickCheckinButton(vfMetaData.getName());
232 protected UserRoleEnum getRole() {
233 return UserRoleEnum.DESIGNER;