re base code
[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                 CatalogVerificator.validateType(TypesEnum.valueOf(catalogType));                                
124         }
125
126         @Test(dataProvider = "Resource_Type_List")
127         public void filterByResourceType(String resourceType) throws Exception {
128                 setLog(resourceType);           
129 //              getExtendTest().setDescription(resourceType);                   
130                 
131                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
132                 CatalogUIUtilitis.catalogFilterTypeChecBox(TypesEnum.valueOf(resourceType));
133                 
134                 CatalogVerificator.validateType(TypesEnum.valueOf(resourceType));       
135         }
136         
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());
141                 
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());
147         }
148
149         @Test
150         public void filterByUpperCategory() throws Exception{           
151                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
152                 CatalogUIUtilitis.clickOnLeftPanelElement(DataTestIdEnum.CatalogPageLeftPanelFilterTitle.TYPE);
153                 
154                 WebElement categoryCheckbox = CatalogUIUtilitis.clickOnUpperCategoryCheckbox();
155                 
156                 CatalogVerificator.validateCategory(categoryCheckbox.getAttribute("textContent").trim());
157         }
158
159         @Test
160         public void filterByGenericDatabaseSubCategory() throws Exception{
161                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
162                 CatalogUIUtilitis.clickOnLeftPanelElement(DataTestIdEnum.CatalogPageLeftPanelFilterTitle.TYPE);
163
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);
169         }
170         
171         @Test(priority = 1)
172         public void lastUpdatedService() throws Exception{
173                 // create service 
174                 ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
175                 ServiceUIUtils.createService(serviceMetadata, getUser());
176                 
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));
182         }
183         
184         @Test(priority = 17)
185         public void lastUpdatedResource() throws Exception{
186                 // create resource 
187                 ResourceReqDetails vfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
188                 ResourceUIUtils.createVF(vfMetaData, getUser());
189                 
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));
195         }
196         
197         @Test(priority = 5)
198         public void fromCatalogCheckout() throws Exception{
199                 // create resource 
200                 ResourceReqDetails vfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
201                 ResourceUIUtils.createVF(vfMetaData, getUser());
202                 ResourceGeneralPage.clickCheckinButton(vfMetaData.getName());
203
204                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
205                 GeneralUIUtils.findComponentAndClick(vfMetaData.getName());
206                 ResourceGeneralPage.clickCheckoutButton();
207                 ResourceGeneralPage.clickCheckinButton(vfMetaData.getName());           
208         }
209
210     @Test
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());
218
219                 GeneralUIUtils.clickOnBrowserBackButton();
220
221                 int numOfElementsInFilteredCatalog =  CatalogVerificator.getNumberOfElementsFromCatalogHeader();
222                 assertTrue(String.format("Wrong number fo elements, Expected : %s , Actual: %s", 1, numOfElementsInFilteredCatalog), numOfElementsInFilteredCatalog == 1 );
223
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));
227     }
228
229         @Override
230         protected UserRoleEnum getRole() {
231                 return UserRoleEnum.DESIGNER;
232         }
233
234 }