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