]> source.dussan.org Git - archiva.git/blob
9209d6f606f92b24d3324aa7e6e44aa402d2cda9
[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 = getProperty("USERROLE_EMAIL");
35                 return email;
36         }
37         
38         public String getUserRolePassword() 
39         {
40                 String password = getProperty("USERROLE_PASSWORD");
41                 return password;
42         }
43
44         public String getUserRoleNewPassword() 
45         {
46                 String password_new = 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 = getProperty( "ADMIN_USERNAME" );
65                 return adminUsername;
66         }
67         
68         public String getAdminPassword()
69         {
70                 String adminPassword = 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         }
426         
427         //Appearance
428         public void goToAppearancePage()
429         {
430                 clickLinkWithText( "Appearance" );
431                 assertAppearancePage();
432         }
433         
434         public void assertAppearancePage()
435         {
436                 assertPage( "Apache Archiva \\ Configure Appearance" );
437                 String appearance = "Appearance,Organization Details,The logo in the top right of the screen is controlled by the following settings.,Organization Information,Name,URL,Logo URL";
438                 String[] arrayAppearance = appearance.split( "," );
439                 for ( String appear : arrayAppearance )
440                         assertTextPresent( appear );
441                 assertLinkPresent( "Edit" );
442                 assertLinkPresent( "Change your appearance" );
443         }
444         
445         public void addEditAppearance( String name, String url, String logoUrl )
446         {
447                 setFieldValue( "organisationName" , name );
448                 setFieldValue( "organisationUrl" , url );
449                 setFieldValue( "organisationLogo" , logoUrl );
450                 clickButtonWithValue( "Save" );
451         }
452
453         // Upload Artifact
454     public void goToAddArtifactPage()
455     {
456         clickLinkWithText( "Upload Artifact" );
457         assertAddArtifactPage();
458     }
459
460     public void assertAddArtifactPage()
461     {
462         assertPage( "Apache Archiva \\ Upload Artifact" );
463         assertTextPresent( "Upload Artifact" );
464
465         String artifact =
466             "Upload Artifact,Group Id*:,Artifact Id*:,Version*:,Packaging*:,Classifier:,Generate Maven 2 POM,Artifact File*:,POM File:,Repository Id:";
467         String[] arrayArtifact = artifact.split( "," );
468         for ( String arrayartifact : arrayArtifact )
469             assertTextPresent( arrayartifact );
470
471         String artifactElements =
472             "upload_groupId,upload_artifactId,upload_version,upload_packaging,upload_classifier,upload_generatePom,upload_artifact,upload_pom,upload_repositoryId,upload_0";
473         String[] arrayArtifactElements = artifactElements.split( "," );
474         for ( String artifactelements : arrayArtifactElements )
475             assertElementPresent( artifactelements );
476     }
477
478     public void addArtifact( String groupId, String artifactId, String version, String packaging,
479                              String artifactFilePath, String repositoryId )
480     {
481         addArtifact( groupId, artifactId, version, packaging, true, artifactFilePath, repositoryId );
482     }
483
484     public void addArtifact( String groupId, String artifactId, String version, String packaging, boolean generatePom,
485                              String artifactFilePath, String repositoryId )
486     {
487         goToAddArtifactPage();
488         setFieldValue( "groupId", groupId );
489         setFieldValue( "artifactId", artifactId );
490         setFieldValue( "version", version );
491         setFieldValue( "packaging", packaging );
492
493         if ( generatePom )
494         {
495             checkField( "generatePom" );
496         }
497
498         setFieldValue( "artifact", artifactFilePath );
499         setFieldValue( "repositoryId", repositoryId );
500
501         clickButtonWithValue( "Submit" );
502     }
503
504     public void goToRepositoriesPage()
505     {
506         if( !getTitle().equals( "Apache Archiva \\ Administration - Repositories" ) )
507         {
508             clickLinkWithText( "Repositories" );
509         }
510         assertRepositoriesPage();
511     }
512
513     public void assertRepositoriesPage()
514     {
515         assertPage( "Apache Archiva \\ Administration - Repositories" );
516         assertTextPresent( "Administration - Repositories" );
517         assertTextPresent( "Managed Repositories" );
518         assertTextPresent( "Remote Repositories" );
519     }
520
521     public void addManagedRepository( String identifier, String name, String directory, String indexDirectory, String type, String cron,
522                                          String daysOlder, String retentionCount )
523     {
524         //goToRepositoriesPage();
525         //clickLinkWithText( "Add" );
526         setFieldValue( "repository.id" , identifier );
527         setFieldValue( "repository.name" , name );
528         setFieldValue( "repository.location" , directory );
529         setFieldValue( "repository.indexDir" , indexDirectory );
530         selectValue( "repository.layout", type );
531         setFieldValue( "repository.refreshCronExpression" , cron );
532         setFieldValue( "repository.daysOlder" , daysOlder );
533         setFieldValue( "repository.retentionCount" , retentionCount );
534         //TODO  
535         clickButtonWithValue( "Add Repository" );
536     }
537 }