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.onap.sdc.frontend.ci.tests.verificator;
23 import com.aventstack.extentreports.Status;
24 import org.apache.commons.text.WordUtils;
25 import org.onap.sdc.backend.ci.tests.datatypes.http.RestResponse;
26 import org.onap.sdc.frontend.ci.tests.pages.AdminGeneralPage;
27 import org.onap.sdc.backend.ci.tests.utils.validation.ErrorValidationUtils;
28 import org.openecomp.sdc.be.dao.api.ActionStatus;
29 import org.openecomp.sdc.be.model.User;
30 import org.onap.sdc.backend.ci.tests.datatypes.enums.UserRoleEnum;
31 import org.onap.sdc.frontend.ci.tests.execute.setup.ExtentTestActions;
32 import org.onap.sdc.frontend.ci.tests.utilities.RestCDUtils;
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 {
41 private 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.");
86 } catch (Exception e) {
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());
96 } catch (Exception e) {
97 Assert.fail("The response message does not describe the user is not found.");
101 public static void validateUserIdNotFound(String userId) {
102 ExtentTestActions.log(Status.INFO, "Validating that user " + userId + " is not found.");
103 AdminGeneralPage.getUserManagementTab().searchUser(userId);
104 List<WebElement> rows = AdminGeneralPage.getUserManagementTab().getAllRowsDisplayed();
105 Assert.assertEquals(rows.size(), 0, String.format("There are %s rows instead of none.", rows.size()));
108 public static void validateOnlySingleRowDisplayed() {
109 ExtentTestActions.log(Status.INFO, "Validating that only a single row is displayed in table.");
110 List<WebElement> rows = AdminGeneralPage.getUserManagementTab().getAllRowsDisplayed();
111 Assert.assertEquals(rows.size(), 1, String.format("There are %s rows instead of %s.", rows.size(), 1));
114 public static void validateRowDisplayedCorrectly(User user, int rowindex) {
115 String role = user.getRole();
116 String userId = user.getUserId();
117 String firstName = user.getFirstName();
118 String lastName = user.getLastName();
119 String email = user.getEmail();
121 ExtentTestActions.log(Status.INFO, "Validating that the row is properly displayed.");
123 WebElement actualFirstName = AdminGeneralPage.getUserManagementTab().getFirstName(rowindex);
124 WebElement actualLastName = AdminGeneralPage.getUserManagementTab().getLastName(rowindex);
125 WebElement actualUserId = AdminGeneralPage.getUserManagementTab().getUserId(rowindex);
126 WebElement actualEmail = AdminGeneralPage.getUserManagementTab().getEmail(rowindex);
127 WebElement actualRole = AdminGeneralPage.getUserManagementTab().getRole(rowindex);
130 String actualFirstNameText = actualFirstName.getText();
131 String actualLastNameText = actualLastName.getText();
132 String actualUserIdText = actualUserId.getText();
133 String actualEmailText = actualEmail.getText();
134 String actualRoleText = actualRole.getText();
136 Assert.assertTrue(actualFirstNameText.equals(firstName), "Actual first name is not " + firstName);
137 Assert.assertTrue(actualLastNameText.equals(lastName), "Actual last name is not " + lastName);
138 Assert.assertTrue(actualUserIdText.equals(userId), "Actual user id is not " + userId);
139 Assert.assertTrue(actualEmailText.contains(email), "Actual email does not contain " + email);
140 Assert.assertTrue(actualRoleText.equals(WordUtils.capitalize(role.toLowerCase())), "Actual role is not " + role);
143 public static void validateFirstRowDisplayedCorrectly(User user) {
144 validateRowDisplayedCorrectly(user, 0);