]> source.dussan.org Git - archiva.git/blob
6ea78711faf4f33e094d3455cec5f5ded068bc6b
[archiva.git] /
1 package org.apache.archiva.web.test.parent;
2
3 import java.io.File;
4
5 import org.apache.archiva.web.test.XPathExpressionUtil;
6
7 /*
8  * Licensed to the Apache Software Foundation (ASF) under one
9  * or more contributor license agreements.  See the NOTICE file
10  * distributed with this work for additional information
11  * regarding copyright ownership.  The ASF licenses this file
12  * to you under the Apache License, Version 2.0 (the
13  * "License"); you may not use this file except in compliance
14  * with the License.  You may obtain a copy of the License at
15  *
16  *   http://www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing,
19  * software distributed under the License is distributed on an
20  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21  * KIND, either express or implied.  See the License for the
22  * specific language governing permissions and limitations
23  * under the License.
24  */
25
26 public abstract class AbstractArchivaTest 
27         extends AbstractSeleniumTest
28 {
29         protected String username;
30         protected String fullname;
31         
32         public String getUserEmail()
33         {
34                 String email = p.getProperty("USERROLE_EMAIL");
35                 return email;
36         }
37         
38         public String getUserRolePassword() 
39         {
40                 String password = p.getProperty("USERROLE_PASSWORD");
41                 return password;
42         }
43
44         public String getUserRoleNewPassword() 
45         {
46                 String password_new = p.getProperty( "NEW_USERROLE_PASSWORD" );
47                 return password_new;
48         }
49
50         public String getBasedir()
51     {
52         String basedir = System.getProperty( "basedir" );
53
54         if ( basedir == null )
55         {
56             basedir = new File( "" ).getAbsolutePath();
57         }
58
59         return basedir;
60     }
61         
62         public String getAdminUsername()
63         {
64                 String adminUsername = p.getProperty( "ADMIN_USERNAME" );
65                 return adminUsername;
66         }
67         
68         public String getAdminPassword()
69         {
70                 String adminPassword = p.getProperty( "ADMIN_PASSWORD" );
71                 return adminPassword;
72         }
73         
74         public void assertCreateAdmin()
75         {
76                         assertPage( "Apache Archiva \\ Create Admin User" );
77                         assertTextPresent( "Username" );
78                 assertFieldValue( "admin", "user.username" );
79                 assertTextPresent( "Full Name*" );
80                 assertElementPresent( "user.fullName" );
81                 assertTextPresent( "Email Address*" );
82                 assertElementPresent( "user.email");
83                 assertTextPresent( "Password*" );
84                 assertElementPresent( "user.password" );
85                 assertTextPresent( "Confirm Password*"   );
86                 assertElementPresent( "user.confirmPassword" );
87                 assertButtonWithValuePresent( "Create Admin" );
88         }
89         
90         public void submitAdminData( String fullname, String email, String password )
91         {
92                 setFieldValue( "user.fullName", fullname );
93                 setFieldValue( "user.email", email );
94                 setFieldValue( "user.password", password );
95                 setFieldValue( "user.confirmPassword", password );
96                 submit();
97         }
98         
99         //Go to Login Page
100         public void goToLoginPage()
101         {
102                 getSelenium().open( baseUrl );
103                 clickLinkWithText( "Login");
104                 assertLoginPage();
105         }
106         
107         public void submitUserData( String username, String password, boolean rememberme, boolean success )
108         {
109
110                 setFieldValue( "username", username );
111                 setFieldValue( "password", password );
112                 if ( rememberme )
113                 {
114                         checkField( "rememberMe" );
115                 }
116                 
117                 submit();
118                 if ( success )
119                 {
120                         assertAuthenticatedPage( username );
121                 }
122                 else
123                 {
124                     assertLoginPage();
125                 }
126         }
127         
128         public void assertLoginPage()
129         {
130                         assertPage( "Apache Archiva \\ Login Page" );
131                 assertTextPresent( "Login" );
132                 assertTextPresent( "Register" );
133                 assertTextPresent( "Username" );
134                 assertElementPresent( "username" );
135                 assertTextPresent( "Password" );
136                 assertElementPresent( "password" );
137                 assertTextPresent( "Remember Me" );
138                 assertElementPresent( "rememberMe" );
139                 assertButtonWithValuePresent( "Login" );
140                 assertButtonWithValuePresent( "Cancel" );
141                 assertTextPresent( "Need an Account? Register!" );
142                 assertTextPresent( "Forgot your Password? Request a password reset." );
143         }
144         
145         public void assertAuthenticatedPage( String username )
146         {
147                 assertTextPresent( "Current User" );
148                 assertTextPresent( "Edit Details" );
149                 assertTextPresent( "Logout" );
150                 assertTextNotPresent( "Login" );
151                 assertTextPresent( username );
152         }
153         
154         
155         //User Management
156         public void goToUserManagementPage()
157         {
158                 clickLinkWithText( "User Management" );
159                 assertUserManagementPage();
160         }
161         
162         public void assertUserManagementPage()
163         {
164                 assertPage( "Apache Archiva \\ [Admin] User List" );
165                 assertTextPresent( "[Admin] List of Users in Role: Any" );
166                 assertTextPresent( "Navigation" );
167                 assertImgWithAlt( "First" );
168                 assertImgWithAlt( "Prev" );
169                 assertImgWithAlt( "Next" );
170                 assertImgWithAlt( "Last" );
171                 assertTextPresent( "Display Rows" );
172                 assertTextPresent( "Username" );
173                 assertTextPresent( "Full Name" );
174                 assertTextPresent( "Email" );
175                 assertTextPresent( "Permanent" );
176                 assertTextPresent( "Validated" );
177                 assertTextPresent( "Locked" );
178                 assertTextPresent( "Tasks" );
179                 assertTextPresent( "Tools" );
180                 assertTextPresent( "Tasks" );
181                 assertTextPresent( "The following tools are available for administrators to manipulate the user list." );
182                 assertButtonWithValuePresent( "Create New User" );
183                 assertButtonWithValuePresent( "Show Users In Role" );
184                 assertElementPresent( "roleName" );
185                 assertTextPresent( "Reports" );
186                 assertTextPresent( "Name" );
187                 assertTextPresent( "Types" );
188                 assertTextPresent( "User List" );
189                 assertTextPresent( "Roles Matrix" );
190         }
191         
192 /*      //User Role
193         public void goToUserRolesPage()
194         {
195                 clickLinkWithText( "User Roles" );
196                 assertUserRolesPage();
197         }*/
198         
199         public void assertUserRolesPage()
200         {
201                 assertPage( "Apache Archiva \\ [Admin] User Edit" );
202                 assertTextPresent( "[Admin] User Roles" );
203                 assertTextPresent( "Username" );
204                 assertTextPresent( "Full Name" );
205                 String userRoles = "Guest,Registered User,System Administrator,User Administrator,Global Repository Observer,Global Repository Manager,Repository Observer,Repository Manager,internal";
206                 String[] arrayRole = userRoles.split( "," );
207                 for ( String userroles : arrayRole )
208                         assertTextPresent( userroles );
209         }
210         
211         public void assertDeleteUserPage( String username )
212          {
213                 assertPage( "Apache Archiva \\ [Admin] User Delete" ); //TODO
214                 assertTextPresent( "[Admin] User Delete" );
215                 assertTextPresent( "The following user will be deleted:" );
216                 assertTextPresent( "Username: " + username );
217                 assertButtonWithValuePresent( "Delete User" );
218          }
219         
220         public void createUser( String userName, String fullName, String email, String password, boolean valid )
221         {
222                 createUser( userName, fullName, email, password, password, valid );
223         }
224         
225         private void createUser( String userName, String fullName, String emailAd, String password, String confirmPassword, boolean valid ) 
226         {
227                 //login( getAdminUsername() , getAdminPassword() );
228                 clickLinkWithText( "User Management" );
229                 clickButtonWithValue( "Create New User" );
230                 assertCreateUserPage();
231         setFieldValue( "user.username", userName );
232         setFieldValue( "user.fullName", fullName );
233         setFieldValue( "user.email", emailAd );
234         setFieldValue( "user.password", password );
235         setFieldValue( "user.confirmPassword", confirmPassword );
236         submit();
237         
238         assertUserRolesPage( );
239         clickButtonWithValue( "Submit" );
240         
241         if (valid )
242         {
243                 String[] columnValues = {userName, fullName, emailAd};
244             assertElementPresent( XPathExpressionUtil.getTableRow( columnValues ) );
245         }
246         else
247         {
248             assertCreateUserPage();
249         }
250         }
251         
252         public void deleteUser( String userName, String fullName, String emailAdd )
253     {
254         deleteUser( userName, fullName, emailAdd, false, false );
255     }
256         
257         public void deleteUser(String userName, String fullName, String emailAd, boolean validated, boolean locked)
258         {
259                 String[] columnValues = {userName, fullName, emailAd};
260                 //clickLinkWithText( "userlist" );
261                 clickLinkWithXPath( "//table[@id='ec_table']/tbody[2]/tr[3]/td[7]/a/img" );
262                 assertDeleteUserPage( userName );
263         submit();
264         assertElementNotPresent( XPathExpressionUtil.getTableRow( columnValues ) );
265         }
266
267     public void login( String username, String password )
268     {
269         login( username, password, true, "Login Page" );
270     }
271         
272         public void login( String username, String password, boolean valid, String assertReturnPage )
273     {
274         if ( isLinkPresent( "Login" ) )
275         {
276             goToLoginPage();
277
278             submitLoginPage( username, password, false, valid, assertReturnPage );
279         }
280     }
281     
282     public void submitLoginPage( String username, String password )
283     {
284         submitLoginPage( username, password, false, true, "Login Page" );
285     }
286
287     public void submitLoginPage( String username, String password, boolean validUsernamePassword )
288     {
289         submitLoginPage( username, password, false, validUsernamePassword, "Login Page" );
290     }
291
292     public void submitLoginPage( String username, String password, boolean rememberMe, boolean validUsernamePassword,
293                                  String assertReturnPage )
294     {
295         assertLoginPage();
296         setFieldValue( "username", username );
297         setFieldValue( "password", password );
298         if ( rememberMe )
299         {
300             checkField( "rememberMe" );
301         }
302         clickButtonWithValue( "Login" );
303
304         if ( validUsernamePassword )
305         {
306             assertTextPresent( "Current User:" );
307             assertTextPresent( username );
308             assertLinkPresent( "Edit Details" );
309             assertLinkPresent( "Logout" );
310         }
311         else
312         {
313             if ( "Login Page".equals( assertReturnPage ) )
314             {
315                 assertLoginPage();
316             }
317             else
318             {
319                 assertPage( assertReturnPage );
320             }
321         }
322     }
323     
324          // User Roles
325         public void assertUserRoleCheckBoxPresent(String value) 
326         {
327                 getSelenium()   .isElementPresent("xpath=//input[@id='addRolesToUser_addNDSelectedRoles' and @name='addNDSelectedRoles' and @value='"   + value + "']");
328         }
329
330         public void assertResourceRolesCheckBoxPresent(String value) {
331                 getSelenium().isElementPresent("xpath=//input[@name='addDSelectedRoles' and @value='" + value + "']");
332         }
333
334         public void checkUserRoleWithValue(String value) 
335         {
336                 assertUserRoleCheckBoxPresent(value);
337                 getSelenium().click( "xpath=//input[@id='addRolesToUser_addNDSelectedRoles' and @name='addNDSelectedRoles' and @value='" + value + "']");
338         }
339
340         public void checkResourceRoleWithValue(String value) 
341         {
342                 assertResourceRolesCheckBoxPresent(value);
343                 getSelenium().click( "xpath=//input[@name='addDSelectedRoles' and @value='" + value + "']" );
344         }
345         
346         
347          public void changePassword(String oldPassword, String newPassword) {
348                 assertPage("Apache Archiva \\ Change Password");
349                 setFieldValue("existingPassword", oldPassword);
350                 setFieldValue("newPassword", newPassword);
351                 setFieldValue("newPasswordConfirm", newPassword);
352                 clickButtonWithValue("Change Password");
353         }
354         
355          public void assertCreateUserPage() 
356          {
357                 assertPage( "Apache Archiva \\ [Admin] User Create" );
358                 assertTextPresent( "[Admin] User Create" );
359                 assertTextPresent( "Username*:" );
360                 assertElementPresent( "user.username" );
361                 assertTextPresent( "Full Name*:");
362                 assertElementPresent( "user.fullName" );
363                 assertTextPresent( "Email Address*:" );
364                 assertElementPresent( "user.email" );
365                 assertTextPresent( "Password*:" );
366                 assertElementPresent( "user.password" );
367                 assertTextPresent( "Confirm Password*:" );
368                 assertElementPresent( "user.confirmPassword" );
369                 assertButtonWithValuePresent( "Create User" );
370         }
371          
372         public void assertLeftNavMenuWithRole( String role )
373         {
374                 if ( role.equals( "Guest" ) || role.equals( "Registered User" )  || role.equals( "Global Repository Observer" ) || role.equals( "Repository Observer - internal" ) || role.equals( "Repository Observer - snapshots" ) )
375                 {
376                         assertTextPresent( "Search" );
377                         assertLinkPresent( "Find Artifact" );
378                         assertLinkPresent( "Browse" );
379                         assertLinkNotPresent( "Repositories" );
380                 }
381                 else if ( role.equals( "User Administrator" ) )
382                 {
383                         assertTextPresent( "Search" );
384                         assertLinkPresent( "Find Artifact" );
385                         assertLinkPresent( "Browse" );
386                         assertLinkPresent( "User Management" );
387                         assertLinkPresent( "User Roles" );
388                         assertLinkNotPresent( "Repositories" );
389                 }
390                 else if ( role.equals( "Global Repository Manager" ) || role.equals( "Repository Manager - internal" ) || role.equals( "Repository Manager - snapshots" ) )
391                 {
392                         assertTextPresent( "Search" );
393                         assertLinkPresent( "Find Artifact" );
394                         assertLinkPresent( "Browse" );
395                         assertLinkPresent( "Upload Artifact" );
396                         assertLinkPresent( "Delete Artifact" );
397                         assertLinkNotPresent( "Repositories" );
398                 }
399                 else 
400                 {
401                         assertTextPresent( "Search" );
402                         String navMenu = "Find Artifact,Browse,Reports,User Management,User Roles,Appearance,Upload Artifact,Delete Artifact,Repository Groups,Repositories,Proxy Connectors,Legacy Support,Network Proxies,Repository Scanning,Database";
403                         String[] arrayMenu = navMenu.split( "," );
404                         for (String navmenu : arrayMenu )
405                                 assertLinkPresent( navmenu );
406                 }
407         }
408 /*      //Find Artifact
409         public void goToFindArtifactPage()
410         {
411                 clickLinkWithText( "Find Artifact" );
412                 assertFindArtifactPage();
413         }
414         
415         public void assertFindArtifactPage()
416         {
417                 //assertPage( "Apache Archiva \\ Find Artifact" );
418                 assertTextPresent( "Find Artifact" );
419                 assertTextPresent( "Search For" );
420                 assertElementPresent( "f" );
421                 assertTextPresent( "Checksum" );
422                 assertElementPresent( "q" );
423                 assertButtonWithValuePresent( "Search" );
424                 assertTextPresent( "This allows you to search the repository using the checksum of an artifact that you are trying to identify. You can either specify the checksum to look for directly, or scan a local artifact file. " );
425                 assertTextPresent( "Tï scan a local file, select the file you would like to locate in the remote repository. Ôhe entire file will not  be uploaded$to the server. See the progress bar below for progress of locally creating a checksum that is uploaded to the server ifter you hit ");
426         }
427         
428         //Appearance
429         public void goToAppearancePage()
430         {
431                 clickLinkWithText( "Appearance" );
432                 assertAppearancePage();
433         }
434         
435         public void assertAppearancePage()
436         {
437                 //assertPage( "Apache Archiva \\ Configure Appearance" );
438                 String appearance = "Appearance,Organization Details,The logo in the top right of the screen is controlled by the following settings.,Organizations Information,Name,URL,Logo URL";
439                 String[] arrayAppearance = appearance.split( "," );
440                 for ( String appear : arrayAppearance )
441                         assertTextPresent( appear );
442                 assertLinkPresent( "Edit" );
443                 assertLinkPresent( "Change your appearance" );
444         }
445         
446         //Upload Artifact
447         public void goToUploadArtifactPage()
448         {
449                 clickLinkWithText( "Upload Artifact" );
450                 assertUploadArtifactPage();
451         }
452         
453         public void assertUploadArtifactPage()
454         {
455                 //assertPage( "Apache Archiva \\ Upload Artifact" );
456                 String uploadArtifact = "Upload Artifact,Group Id*,Artifact Id*,Version*,Packaging*,Classifier,Generate Maven 2 POM,Artifact File*,POM File,Repository Id";
457                 String[] arrayUploadArtifact = uploadArtifact.split( "," );
458                 for ( String uploadartifact : arrayUploadArtifact )
459                         assertTextPresent( uploadartifact );
460                 String uploadElements = "groupId,artifactId,version,packaging,classifier,generatePom,artifact,pom,repositoryId";
461                 String[] arrayUploadElements = uploadElements.split( "," );
462                 for ( String uploadelements : arrayUploadElements )
463                         assertElementPresent( uploadelements );
464                 assertButtonWithValuePresent( "Submit" );
465         } */
466 }