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 java.util.Arrays;
24 import java.util.List;
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;
38 import com.aventstack.extentreports.Status;
40 public class UserManagementVerificator {
44 public static void validateUserCreated(String userId, UserRoleEnum role){
46 ExtentTestActions.log(Status.INFO, "Validating that a new user is created and displayed in the first row in the table.");
48 final int firstRow = 0;
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);
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();
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'.");
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());
81 public static void validateUserRoleUpdatedViaRest(User reqUser, User user, UserRoleEnum expectedUserRole){
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.");
88 Assert.fail("The actual user role is null");
92 public static void validateUserNotFoundViaRest(User reqUser, User user){
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());
99 Assert.fail("The response message does not describe the user is not found.");
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()));
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));
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();
123 ExtentTestActions.log(Status.INFO, "Validating that the row is properly displayed.");
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);
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();
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);
145 public static void validateFirstRowDisplayedCorrectly(User user){
146 validateRowDisplayedCorrectly(user, 0);