Sync Integ to Master
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / execute / sanity / CatalogLeftPanelTest.java
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.openecomp.sdc.ci.tests.execute.sanity;
22
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;
37
38 import java.util.Arrays;
39 import java.util.List;
40
41 import static org.testng.AssertJUnit.assertTrue;
42
43 @Test(singleThreaded = true)
44 public class CatalogLeftPanelTest extends  SetupCDTest{
45         
46         private String filePath;
47         @BeforeMethod
48         public void beforeTest(){
49                 filePath = FileHandling.getFilePath("");
50         }
51         
52         public static String[] resourceTypes = Arrays.stream(ResourceTypeEnum.class.getEnumConstants()).
53                         map(ResourceTypeEnum::name).toArray(String[]::new);
54         
55         public static String[] catalogTypes = {"RESOURCE", "SERVICE"};  
56         
57         public static Object[][] provideData(String[] arObj) {
58             Object[][] arObject = new Object[arObj.length][];
59
60             int index = 0;
61             for (Object obj : arObj) {
62                 arObject[index++] = new Object[]{obj};
63             }
64             return arObject;
65         }
66         
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); 
73         }
74         
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][];
79                 int index = 0;
80         for (String catalogType : catalogTypes) {
81                 if (catalogType.equals("RESOURCE")){
82                         arObject[index++] = new Object[]{catalogType, resourceTypes};
83                 } else {
84                         arObject[index++] = new Object[]{catalogType, new String[] {catalogType}};
85                 }
86                 }
87                 return arObject; 
88         }
89         
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][];
98                 int index = 0;
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)};
110                         }
111                 }
112                 return arObject;
113         }
114         
115         // filter by Type Resource in catalog
116         @Test(dataProvider = "Type_List")
117         public void filterByType(String catalogType, String[] classValues ) throws Exception {
118         setLog(catalogType);            
119 //              getExtendTest().setDescription(catalogType);
120                 
121                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
122                 CatalogUIUtilitis.catalogFilterTypeChecBox(TypesEnum.valueOf(catalogType));
123                 
124                 CatalogVerificator.validateType(TypesEnum.valueOf(catalogType));                                
125         }
126         
127         @Test(dataProvider = "Resource_Type_List")
128         public void filterByResourceType(String resourceType) throws Exception {
129                 setLog(resourceType);           
130 //              getExtendTest().setDescription(resourceType);                   
131                 
132                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
133                 CatalogUIUtilitis.catalogFilterTypeChecBox(TypesEnum.valueOf(resourceType));
134                 
135                 CatalogVerificator.validateType(TypesEnum.valueOf(resourceType));       
136         }
137         
138         @Test(dataProvider = "Status_List")
139         public void filterByStatus(CheckBoxStatusEnum statusCheckbox, List<LifeCycleStateEnum> lifecycleStates) throws Exception{
140                 setLog(statusCheckbox.name());          
141 //              getExtendTest().setDescription(statusCheckbox.name());
142                 
143                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
144                 CatalogUIUtilitis.clickOnLeftPanelElement(DataTestIdEnum.CatalogPageLeftPanelFilterTitle.CATEGORIES);
145                 CatalogUIUtilitis.catalogFilterStatusChecBox(statusCheckbox);
146                 
147                 CatalogVerificator.validateStatus(lifecycleStates, statusCheckbox.name());
148         }
149
150         @Test
151         public void filterByUpperCategory() throws Exception{           
152                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
153                 CatalogUIUtilitis.clickOnLeftPanelElement(DataTestIdEnum.CatalogPageLeftPanelFilterTitle.TYPE);
154                 
155                 WebElement categorieCheckbox = CatalogUIUtilitis.clickOnUpperCategoryCheckbox();
156                 
157                 CatalogVerificator.validateCategory(categorieCheckbox.getAttribute("textContent").trim());
158         }
159
160         @Test
161         public void filterByGenericDtabaseSubCategory() throws Exception{               
162                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
163                 CatalogUIUtilitis.clickOnLeftPanelElement(DataTestIdEnum.CatalogPageLeftPanelFilterTitle.TYPE);
164
165                 WebElement checkboxElement = GeneralUIUtils.getElementsByCSS(CatalogPageLeftPanelSubCategoryCheckbox.DATABASE.getValue()).get(0);
166                 String checkboxElementName = checkboxElement.getAttribute("textContent").trim();
167                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on %s subcategory ...", checkboxElementName));
168                 GeneralUIUtils.clickOnAreaJS(checkboxElement);
169                 CatalogVerificator.validateSubCategory("Generic", checkboxElementName);
170         }
171         
172         @Test(priority = 1)
173         public void lastUpdatedService() throws Exception{
174                 // create service 
175                 ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
176                 ServiceUIUtils.createService(serviceMetadata, getUser());
177                 
178                 ResourceGeneralPage.clickCheckinButton(serviceMetadata.getName());
179                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
180                 List<WebElement> cardElements = GeneralUIUtils.getElementsByCSS(DataTestIdEnum.DashboardCardEnum.INFO_NAME.getValue());
181                 String firstElementName = cardElements.get(0).getAttribute("textContent").trim();
182                 assertTrue(String.format("Wrong element name, Exepected : %s , Actual: %s", serviceMetadata.getName(), firstElementName), serviceMetadata.getName().equals(firstElementName));                  
183         }
184         
185         @Test(priority = 17)
186         public void lastUpdatedResource() throws Exception{
187                 // create resource 
188                 ResourceReqDetails vfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
189                 ResourceUIUtils.createVF(vfMetaData, getUser());
190                 
191                 ResourceGeneralPage.clickCheckinButton(vfMetaData.getName());
192                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
193                 List<WebElement> cardElements = GeneralUIUtils.getElementsByCSS(DataTestIdEnum.DashboardCardEnum.INFO_NAME.getValue());
194                 String firstElementName = cardElements.get(0).getAttribute("textContent").trim();
195                 assertTrue(String.format("Wrong element name, Exepected : %s , Actual: %s", vfMetaData.getName(), firstElementName), vfMetaData.getName().equals(firstElementName));                    
196         }
197         
198         @Test(priority = 5)
199         public void fromCatalogCheckout() throws Exception{
200                 // create resource 
201                 ResourceReqDetails vfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
202                 ResourceUIUtils.createVF(vfMetaData, getUser());
203                 
204                 ResourceGeneralPage.clickCheckinButton(vfMetaData.getName());
205                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
206                 GeneralUIUtils.findComponentAndClickInCatalog(vfMetaData.getName());
207                 ResourceGeneralPage.clickCheckoutButton();
208                 ResourceGeneralPage.clickCheckinButton(vfMetaData.getName());           
209         }
210         
211         @Override
212         protected UserRoleEnum getRole() {
213                 return UserRoleEnum.DESIGNER;
214         }
215
216 }