2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.ci.tests.verificator;
23 import com.aventstack.extentreports.Status;
24 import org.apache.commons.lang3.text.WordUtils;
25 import org.openecomp.sdc.be.dao.api.ActionStatus;
26 import org.openecomp.sdc.be.model.User;
27 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
28 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
29 import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;
30 import org.openecomp.sdc.ci.tests.pages.AdminGeneralPage;
31 import org.openecomp.sdc.ci.tests.utilities.RestCDUtils;
32 import org.openecomp.sdc.ci.tests.utils.validation.ErrorValidationUtils;
33 import org.openqa.selenium.WebElement;
34 import org.testng.Assert;
36 import java.util.Arrays;
37 import java.util.List;
39 public class UserManagementVerificator {
43 public static void validateUserCreated(String userId, UserRoleEnum role){
45 ExtentTestActions.log(Status.INFO, "Validating that a new user is created and displayed in the first row in the table.");
47 final int firstRow = 0;
49 WebElement actualFirstName = AdminGeneralPage.getUserManagementTab().getFirstName(firstRow);
50 WebElement actualLastName = AdminGeneralPage.getUserManagementTab().getLastName(firstRow);
51 WebElement actualUserId = AdminGeneralPage.getUserManagementTab().getUserId(firstRow);
52 WebElement actualEmail = AdminGeneralPage.getUserManagementTab().getEmail(firstRow);
53 WebElement actualRole = AdminGeneralPage.getUserManagementTab().getRole(firstRow);
54 WebElement actualLastActive = AdminGeneralPage.getUserManagementTab().getLastActive(firstRow);
57 String actualFirstNameText = actualFirstName.getText();
58 String actualLastNameText = actualLastName.getText();
59 String actualUserIdText = actualUserId.getText();
60 String actualEmailText = actualEmail.getText();
61 String actualRoleText = actualRole.getText();
62 String actualLastActiveText = actualLastActive.getText();
64 Assert.assertTrue(actualFirstNameText.equals("---"), "Actual first name is not '---'.");
65 Assert.assertTrue(actualLastNameText.equals("---"), "Actual last name is not '---'.");
66 Assert.assertTrue(actualUserIdText.equals(userId), "Actual user id is not " + userId);
67 Assert.assertTrue(actualEmailText.equals("---"), "Actual email is not '---'.");
68 Assert.assertTrue(actualRoleText.equals(WordUtils.capitalize(role.name().toLowerCase())), "Actual role is not " + role.name());
69 Assert.assertTrue(actualLastActiveText.equals("Waiting"), "Actual role is not 'Waiting'.");
73 public static void validateUserRoleUpdated(int rowIndx, UserRoleEnum updatedRole){
74 ExtentTestActions.log(Status.INFO, "Validating role is updated to " + updatedRole.name() + " in UI.");
75 WebElement actualRole = AdminGeneralPage.getUserManagementTab().getRole(rowIndx);
76 String actualRoleText = actualRole.getText();
77 Assert.assertTrue(actualRoleText.equals(WordUtils.capitalize(updatedRole.name().toLowerCase())), "Actual role is not " + updatedRole.name());
80 public static void validateUserRoleUpdatedViaRest(User reqUser, User user, UserRoleEnum expectedUserRole){
82 ExtentTestActions.log(Status.INFO, "Validating role is updated to " + expectedUserRole.name() + " in BE.");
83 String actualUserRole = RestCDUtils.getUserRole(reqUser, user);
84 Assert.assertTrue(expectedUserRole.name().toLowerCase().equals(actualUserRole.toLowerCase()), "User role is not updated.");
87 Assert.fail("The actual user role is null");
91 public static void validateUserNotFoundViaRest(User reqUser, User user){
93 ExtentTestActions.log(Status.INFO, "Validating user " + reqUser.getUserId() + " is not found in BE.");
94 RestResponse getUserResp = RestCDUtils.getUser(reqUser, user);
95 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.USER_INACTIVE.name(), Arrays.asList(reqUser.getUserId()), getUserResp.getResponse());
98 Assert.fail("The response message does not describe the user is not found.");
102 public static void validateUserIdNotFound(String userId){
103 ExtentTestActions.log(Status.INFO, "Validating that user " + userId + " is not found.");
104 AdminGeneralPage.getUserManagementTab().searchUser(userId);
105 List<WebElement> rows = AdminGeneralPage.getUserManagementTab().getAllRowsDisplayed();
106 Assert.assertEquals(rows.size(), 0, String.format("There are %s rows instead of none.", rows.size()));
109 public static void validateOnlySingleRowDisplayed(){
110 ExtentTestActions.log(Status.INFO, "Validating that only a single row is displayed in table.");
111 List<WebElement> rows = AdminGeneralPage.getUserManagementTab().getAllRowsDisplayed();
112 Assert.assertEquals(rows.size(), 1, String.format("There are %s rows instead of %s.", rows.size(), 1));
115 public static void validateRowDisplayedCorrectly(User user, int rowindex){
116 String role = user.getRole();
117 String userId = user.getUserId();
118 String firstName = user.getFirstName();
119 String lastName = user.getLastName();
120 String email = user.getEmail();
122 ExtentTestActions.log(Status.INFO, "Validating that the row is properly displayed.");
124 WebElement actualFirstName = AdminGeneralPage.getUserManagementTab().getFirstName(rowindex);
125 WebElement actualLastName = AdminGeneralPage.getUserManagementTab().getLastName(rowindex);
126 WebElement actualUserId = AdminGeneralPage.getUserManagementTab().getUserId(rowindex);
127 WebElement actualEmail = AdminGeneralPage.getUserManagementTab().getEmail(rowindex);
128 WebElement actualRole = AdminGeneralPage.getUserManagementTab().getRole(rowindex);
131 String actualFirstNameText = actualFirstName.getText();
132 String actualLastNameText = actualLastName.getText();
133 String actualUserIdText = actualUserId.getText();
134 String actualEmailText = actualEmail.getText();
135 String actualRoleText = actualRole.getText();
137 Assert.assertTrue(actualFirstNameText.equals(firstName), "Actual first name is not " + firstName);
138 Assert.assertTrue(actualLastNameText.equals(lastName), "Actual last name is not " + lastName);
139 Assert.assertTrue(actualUserIdText.equals(userId), "Actual user id is not " + userId);
140 Assert.assertTrue(actualEmailText.contains(email), "Actual email does not contain " + email);
141 Assert.assertTrue(actualRoleText.equals(WordUtils.capitalize(role.toLowerCase())), "Actual role is not " + role);
144 public static void validateFirstRowDisplayedCorrectly(User user){
145 validateRowDisplayedCorrectly(user, 0);