[SDC-29] rebase continue work to align source
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / verificator / UserManagementVerificator.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.verificator;
22
23 import java.util.Arrays;
24 import java.util.List;
25
26 import org.apache.commons.lang3.text.WordUtils;
27 import org.openecomp.sdc.be.dao.api.ActionStatus;
28 import org.openecomp.sdc.be.model.User;
29 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
30 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
31 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
32 import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;
33 import org.openecomp.sdc.ci.tests.pages.AdminGeneralPage;
34 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
35 import org.openecomp.sdc.ci.tests.utilities.RestCDUtils;
36 import org.openecomp.sdc.ci.tests.utils.validation.ErrorValidationUtils;
37 import org.openqa.selenium.WebElement;
38 import org.testng.Assert;
39
40 import com.aventstack.extentreports.Status;
41
42 public class UserManagementVerificator {
43
44
45         
46         public static void validateUserCreated(String userId, UserRoleEnum role){
47                 
48                 ExtentTestActions.log(Status.INFO, "Validating that a new user is created and displayed in the first row in the table.");
49                 
50                 final int firstRow = 0;
51                 
52                 WebElement actualFirstName = AdminGeneralPage.getUserManagementTab().getFirstName(firstRow);
53                 WebElement actualLastName = AdminGeneralPage.getUserManagementTab().getLastName(firstRow);
54                 WebElement actualUserId = AdminGeneralPage.getUserManagementTab().getUserId(firstRow);
55                 WebElement actualEmail = AdminGeneralPage.getUserManagementTab().getEmail(firstRow);
56                 WebElement actualRole = AdminGeneralPage.getUserManagementTab().getRole(firstRow);
57                 WebElement actualLastActive = AdminGeneralPage.getUserManagementTab().getLastActive(firstRow);
58                 
59                 
60                 String actualFirstNameText = actualFirstName.getText();
61                 String actualLastNameText = actualLastName.getText();
62                 String actualUserIdText = actualUserId.getText();
63                 String actualEmailText = actualEmail.getText();
64                 String actualRoleText = actualRole.getText();
65                 String actualLastActiveText = actualLastActive.getText();
66                 
67                 Assert.assertTrue(actualFirstNameText.equals("---"), "Actual first name is not '---'.");
68                 Assert.assertTrue(actualLastNameText.equals("---"), "Actual last name is not '---'.");
69                 Assert.assertTrue(actualUserIdText.equals(userId), "Actual user id is not  " + userId);
70                 Assert.assertTrue(actualEmailText.equals("---"), "Actual email is not '---'.");
71                 Assert.assertTrue(actualRoleText.equals(WordUtils.capitalize(role.name().toLowerCase())), "Actual role is not " + role.name());
72                 Assert.assertTrue(actualLastActiveText.equals("Waiting"), "Actual role is not 'Waiting'.");
73         }
74         
75         
76         public static void validateUserRoleUpdated(int rowIndx, UserRoleEnum updatedRole){
77                 ExtentTestActions.log(Status.INFO, "Validating role is updated to " + updatedRole.name() + " in UI.");
78                 WebElement actualRole = AdminGeneralPage.getUserManagementTab().getRole(rowIndx);
79                 String actualRoleText = actualRole.getText();
80                 Assert.assertTrue(actualRoleText.equals(WordUtils.capitalize(updatedRole.name().toLowerCase())), "Actual role is not " + updatedRole.name());
81         }
82         
83         public static void validateUserRoleUpdatedViaRest(User reqUser, User user, UserRoleEnum expectedUserRole){
84                 try{
85                         ExtentTestActions.log(Status.INFO, "Validating role is updated to " + expectedUserRole.name() + " in BE.");
86                         String actualUserRole = RestCDUtils.getUserRole(reqUser, user);
87                         Assert.assertTrue(expectedUserRole.name().toLowerCase().equals(actualUserRole.toLowerCase()), "User role is not updated.");
88                 }
89                 catch(Exception e){
90                         Assert.fail("The actual user role is null");
91                 }
92         }
93         
94         public static void validateUserNotFoundViaRest(User reqUser, User user){
95                 try{
96                         ExtentTestActions.log(Status.INFO, "Validating user " + reqUser.getUserId() + " is not found in BE.");
97                         RestResponse getUserResp = RestCDUtils.getUser(reqUser, user);
98                         ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.USER_INACTIVE.name(), Arrays.asList(reqUser.getUserId()), getUserResp.getResponse());
99                 }
100                 catch(Exception e){
101                         Assert.fail("The response message does not describe the user is not found.");
102                 }
103         }
104         
105         public static void validateUserIdNotFound(String userId){
106                 ExtentTestActions.log(Status.INFO, "Validating that user " + userId + " is not found.");
107                 AdminGeneralPage.getUserManagementTab().searchUser(userId);
108                 List<WebElement> rows = AdminGeneralPage.getUserManagementTab().getAllRowsDisplayed();
109                 Assert.assertEquals(rows.size(), 0, String.format("There are %s rows instead of none.", rows.size()));
110         }
111         
112         public static void validateOnlySingleRowDisplayed(){
113                 ExtentTestActions.log(Status.INFO, "Validating that only a single row is displayed in table.");
114                 List<WebElement> rows = AdminGeneralPage.getUserManagementTab().getAllRowsDisplayed();
115                 Assert.assertEquals(rows.size(), 1, String.format("There are %s rows instead of %s.", rows.size(), 1));
116         }
117         
118         public static void validateRowDisplayedCorrectly(User user, int rowindex){
119                 String role = user.getRole();
120                 String userId = user.getUserId();
121                 String firstName = user.getFirstName();
122                 String lastName = user.getLastName();
123                 String email = user.getEmail();
124                 
125                 ExtentTestActions.log(Status.INFO, "Validating that the row is properly displayed.");
126
127                 WebElement actualFirstName = AdminGeneralPage.getUserManagementTab().getFirstName(rowindex);
128                 WebElement actualLastName = AdminGeneralPage.getUserManagementTab().getLastName(rowindex);
129                 WebElement actualUserId = AdminGeneralPage.getUserManagementTab().getUserId(rowindex);
130                 WebElement actualEmail = AdminGeneralPage.getUserManagementTab().getEmail(rowindex);
131                 WebElement actualRole = AdminGeneralPage.getUserManagementTab().getRole(rowindex);
132                 
133                 
134                 String actualFirstNameText = actualFirstName.getText();
135                 String actualLastNameText = actualLastName.getText();
136                 String actualUserIdText = actualUserId.getText();
137                 String actualEmailText = actualEmail.getText();
138                 String actualRoleText = actualRole.getText();
139                 
140                 Assert.assertTrue(actualFirstNameText.equals(firstName), "Actual first name is not " + firstName);
141                 Assert.assertTrue(actualLastNameText.equals(lastName), "Actual last name is not " + lastName);
142                 Assert.assertTrue(actualUserIdText.equals(userId), "Actual user id is not  " + userId);
143                 Assert.assertTrue(actualEmailText.contains(email), "Actual email does not contain " + email);
144                 Assert.assertTrue(actualRoleText.equals(WordUtils.capitalize(role.toLowerCase())), "Actual role is not " + role);
145         }
146         
147         public static void validateFirstRowDisplayedCorrectly(User user){
148                 validateRowDisplayedCorrectly(user, 0);
149         }
150         
151         
152 }