[SDC-29] rebase continue work to align source
[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 static org.testng.AssertJUnit.assertTrue;
24
25 import java.io.File;
26 import java.util.Arrays;
27 import java.util.List;
28
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;
52
53 import com.aventstack.extentreports.Status;
54
55 @Test(singleThreaded = true)
56 public class CatalogLeftPanelTest extends  SetupCDTest{
57         
58         private String filePath;
59         @BeforeMethod
60         public void beforeTest(){
61                 filePath = System.getProperty("filepath");
62         
63                 if (filePath == null && System.getProperty("os.name").contains("Windows")) {
64                         filePath = FileHandling.getResourcesFilesPath();
65                 }
66                 
67                 else if(filePath.isEmpty() && !System.getProperty("os.name").contains("Windows")){
68                         filePath = FileHandling.getBasePath() + File.separator + "Files" + File.separator;
69                 }
70         }
71         
72         public static String[] resourceTypes = Arrays.stream(ResourceTypeEnum.class.getEnumConstants()).
73                         map(ResourceTypeEnum::name).toArray(String[]::new);
74         
75         public static String[] catalogTypes = {"RESOURCE", "SERVICE", "PRODUCT"};       
76         
77         public static Object[][] provideData(String[] arObj) {
78             Object[][] arObject = new Object[arObj.length][];
79
80             int index = 0;
81             for (Object obj : arObj) {
82                 arObject[index++] = new Object[]{obj};
83             }
84             return arObject;
85         }
86         
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); 
93         }
94         
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][];
99                 int index = 0;
100         for (String catalogType : catalogTypes) {
101                 if (catalogType.equals("RESOURCE")){
102                         arObject[index++] = new Object[]{catalogType, resourceTypes};
103                 } else {
104                         arObject[index++] = new Object[]{catalogType, new String[] {catalogType}};
105                 }
106                 }
107                 return arObject; 
108         }
109         
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][];
118                 int index = 0;
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)};
130                         }
131                 }
132                 return arObject;
133         }
134         
135         // filter by Type Resource in catalog
136         @Test(dataProvider = "Type_List")
137         public void filterByType(String catalogType, String[] classValues ) throws Exception {
138         setLog(catalogType);            
139 //              getExtendTest().setDescription(catalogType);
140                 
141                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
142                 CatalogUIUtilitis.catalogFilterTypeChecBox(TypesEnum.valueOf(catalogType));
143                 
144                 CatalogVerificator.validateType(TypesEnum.valueOf(catalogType));                                
145         }
146         
147         @Test(dataProvider = "Resource_Type_List")
148         public void filterByResourceType(String resourceType) throws Exception {
149                 setLog(resourceType);           
150 //              getExtendTest().setDescription(resourceType);                   
151                 
152                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
153                 CatalogUIUtilitis.catalogFilterTypeChecBox(TypesEnum.valueOf(resourceType));
154                 
155                 CatalogVerificator.validateType(TypesEnum.valueOf(resourceType));       
156         }
157         
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());
162                 
163                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
164                 CatalogUIUtilitis.clickOnLeftPanelElement(DataTestIdEnum.CatalogPageLeftPanelFilterTitle.CATEGORIES);
165                 CatalogUIUtilitis.catalogFilterStatusChecBox(statusCheckbox);
166                 
167                 CatalogVerificator.validateStatus(lifecycleStates, statusCheckbox.name());
168         }
169
170         @Test
171         public void filterByUpperCategory() throws Exception{           
172                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
173                 CatalogUIUtilitis.clickOnLeftPanelElement(DataTestIdEnum.CatalogPageLeftPanelFilterTitle.TYPE);
174                 
175                 WebElement categorieCheckbox = CatalogUIUtilitis.clickOnUpperCategoryCheckbox();
176                 
177                 CatalogVerificator.validateCategory(categorieCheckbox.getAttribute("textContent").trim());
178         }
179
180         @Test
181         public void filterByGenericDtabaseSubCategory() throws Exception{               
182                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
183                 CatalogUIUtilitis.clickOnLeftPanelElement(DataTestIdEnum.CatalogPageLeftPanelFilterTitle.TYPE);
184
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);
190         }
191         
192         @Test(priority = 1)
193         public void lastUpdatedService() throws Exception{
194                 // create service 
195                 ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
196                 ServiceUIUtils.createService(serviceMetadata, getUser());
197                 
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));                  
203         }
204         
205         @Test(priority = 17)
206         public void lastUpdatedResource() throws Exception{
207                 // create resource 
208                 ResourceReqDetails vfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
209                 ResourceUIUtils.createResource(vfMetaData, getUser());
210                 
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));                    
216         }
217         
218         @Test(priority = 5)
219         public void fromCatalogCheckout() throws Exception{
220                 // create resource 
221                 ResourceReqDetails vfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
222                 ResourceUIUtils.createResource(vfMetaData, getUser());
223                 
224                 ResourceGeneralPage.clickCheckinButton(vfMetaData.getName());
225                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
226                 GeneralUIUtils.findComponentAndClickInCatalog(vfMetaData.getName());
227                 ResourceGeneralPage.clickCheckoutButton();
228                 ResourceGeneralPage.clickCheckinButton(vfMetaData.getName());           
229         }
230         
231         @Override
232         protected UserRoleEnum getRole() {
233                 return UserRoleEnum.DESIGNER;
234         }
235
236 }