]> source.dussan.org Git - archiva.git/blob
44907ab2e176a29cdbdb5bf05412298d2b65a723
[archiva.git] /
1 package org.apache.archiva.web.test.parent;
2
3 import org.junit.runner.RunWith;
4 import org.junit.runners.BlockJUnit4ClassRunner;
5 import org.openqa.selenium.By;
6 import org.openqa.selenium.WebElement;
7 import org.openqa.selenium.support.ui.ExpectedConditions;
8 import org.openqa.selenium.support.ui.WebDriverWait;
9
10 import java.io.File;
11 import java.io.IOException;
12
13 /*
14  * Licensed to the Apache Software Foundation (ASF) under one
15  * or more contributor license agreements.  See the NOTICE file
16  * distributed with this work for additional information
17  * regarding copyright ownership.  The ASF licenses this file
18  * to you under the Apache License, Version 2.0 (the
19  * "License"); you may not use this file except in compliance
20  * with the License.  You may obtain a copy of the License at
21  *
22  *   http://www.apache.org/licenses/LICENSE-2.0
23  *
24  * Unless required by applicable law or agreed to in writing,
25  * software distributed under the License is distributed on an
26  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
27  * KIND, either express or implied.  See the License for the
28  * specific language governing permissions and limitations
29  * under the License.
30  */
31
32 @RunWith( BlockJUnit4ClassRunner.class )
33 public abstract class AbstractArchivaTest
34     extends AbstractSeleniumTest
35 {
36
37     protected String username;
38
39     protected String fullname;
40
41     public String getUserEmail()
42     {
43         String email = getProperty( "USERROLE_EMAIL" );
44         return email;
45     }
46
47     public String getUserRolePassword()
48     {
49         String password = getProperty( "USERROLE_PASSWORD" );
50         return password;
51     }
52
53     public String getUserRoleNewPassword()
54     {
55         String password_new = getProperty( "NEW_USERROLE_PASSWORD" );
56         return password_new;
57     }
58
59     public String getBasedir()
60     {
61         String basedir = System.getProperty( "basedir" );
62
63         if ( basedir == null )
64         {
65             basedir = new File( "" ).getAbsolutePath();
66         }
67
68         return basedir;
69     }
70
71
72     public void submitUserData( String username, String password, boolean rememberme, boolean success )
73     {
74
75         setFieldValue( "username", username );
76         setFieldValue( "password", password );
77         if ( rememberme )
78         {
79             checkField( "rememberMe" );
80         }
81
82         submit();
83         if ( success )
84         {
85             assertUserLoggedIn( username );
86         }
87         else
88         {
89             assertLoginModal();
90         }
91     }
92
93     // User Management
94
95     public void createUser( String userName, String fullName, String email, String password, boolean valid )
96     {
97         createUser( userName, fullName, email, password, password, valid );
98     }
99
100     private void createUser( String userName, String fullName, String emailAd, String password, String confirmPassword,
101                              boolean valid )
102     {
103         login( getAdminUsername(), getAdminPassword() );
104         WebDriverWait wait = new WebDriverWait(getWebDriver(), 10);
105         WebElement el = wait.until(ExpectedConditions.elementToBeClickable( By.id("menu-users-list-a") ));
106         el = tryClick(el, ExpectedConditions.elementToBeClickable(By.id("users-view-tabs-li-user-edit-a")), "User List not available");
107         el = tryClick(el, ExpectedConditions.elementToBeClickable(By.id("users-view-tabs-li-user-edit-a")),"User Edit View not available");
108         el = tryClick(el, ExpectedConditions.elementToBeClickable(By.id("user-create-form-register-button")),
109             "Register Form not available");
110         assertCreateUserPage();
111         setFieldValue( "username", userName );
112         setFieldValue( "fullname", fullName );
113         setFieldValue( "email", emailAd );
114         setFieldValue( "password", password );
115         setFieldValue( "confirmPassword", confirmPassword );
116
117         el.click();
118
119         wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("user-messages"),"User " + userName + " created." ));
120         assertElementPresent( "users-grid-user-id-" + userName );
121
122         if ( valid )
123         {
124             //String[] columnValues = { userName, fullName, emailAd };
125             //assertElementPresent( XPathExpressionUtil.getTableRow( columnValues ) );
126
127         }
128         else
129         {
130             assertCreateUserPage();
131         }
132     }
133
134     public void deleteUser( String userName, String fullName, String emailAdd )
135     {
136         deleteUser( userName, fullName, emailAdd, false, false );
137     }
138
139     public void deleteUser( String userName, String fullName, String emailAd, boolean validated, boolean locked )
140     {
141         clickLinkWithLocator( "menu-users-list-a");
142         WebDriverWait wait = new WebDriverWait(getWebDriver(),10);
143         wait.until(ExpectedConditions.elementToBeClickable(By.id("users-grid-delete-" + userName)));
144         assertTextPresent( userName );
145         assertTextPresent( fullName );
146
147         clickLinkWithLocator( "users-grid-delete-" + userName );
148         wait.until(ExpectedConditions.elementToBeClickable(By.id("dialog-confirm-modal-ok")));
149
150         clickLinkWithLocator( "dialog-confirm-modal-ok" );
151         wait.until(ExpectedConditions.elementToBeClickable(By.id("alert-message-success-close-a" )));
152         assertTextPresent( "User " + userName + " deleted." );
153
154         clickLinkWithLocator( "alert-message-success-close-a" );
155
156         assertElementNotPresent( "users-grid-user-id-" + userName );
157         assertTextNotPresent( fullName );
158
159
160     }
161
162     // User Roles
163
164
165     public void assertCreateUserPage()
166     {
167         assertTextPresent( "Username" );
168         assertElementPresent( "username" );
169         assertTextPresent( "Full Name" );
170         assertElementPresent( "fullname" );
171         assertTextPresent( "Email Address" );
172         assertElementPresent( "email" );
173         assertTextPresent( "Password" );
174         assertElementPresent( "password" );
175         assertTextPresent( "Confirm Password" );
176         assertElementPresent( "confirmPassword" );
177         assertButtonWithIdPresent( "user-create-form-register-button" );
178
179     }
180
181     public void goToHomePage()
182     {
183         getWebDriver().get( baseUrl );
184     }
185
186     protected void logout()
187     {
188         clickLinkWithLocator( "logout-link-a" );
189         WebDriverWait wait = new WebDriverWait(getWebDriver(), 10);
190         wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[text()='Login']//ancestor::a")));
191         assertTextNotPresent( "Current User:" );
192         assertLinkNotVisible( "Edit Details" );
193         assertLinkNotVisible( "Logout" );
194         assertLinkVisible( "Login" );
195     }
196
197     protected String getAdminUserName()
198     {
199         return getProperty( "ADMIN_FULLNAME" );
200     }
201 }