]> source.dussan.org Git - archiva.git/blob
b22264af8e024399b1e4150635fd332f9e485798
[archiva.git] /
1 package org.apache.archiva.web.test.parent;
2
3 import java.io.File;
4 import java.io.IOException;
5
6 import org.apache.archiva.web.test.XPathExpressionUtil;
7
8 /*
9  * Licensed to the Apache Software Foundation (ASF) under one
10  * or more contributor license agreements.  See the NOTICE file
11  * distributed with this work for additional information
12  * regarding copyright ownership.  The ASF licenses this file
13  * to you under the Apache License, Version 2.0 (the
14  * "License"); you may not use this file except in compliance
15  * with the License.  You may obtain a copy of the License at
16  *
17  *   http://www.apache.org/licenses/LICENSE-2.0
18  *
19  * Unless required by applicable law or agreed to in writing,
20  * software distributed under the License is distributed on an
21  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
22  * KIND, either express or implied.  See the License for the
23  * specific language governing permissions and limitations
24  * under the License.
25  */
26
27 public abstract class AbstractArchivaTest 
28         extends AbstractSeleniumTest
29 {
30         protected String username;
31         protected String fullname;
32         
33         public String getUserEmail()
34         {
35                 String email = getProperty("USERROLE_EMAIL");
36                 return email;
37         }
38         
39         public String getUserRolePassword() 
40         {
41                 String password = getProperty("USERROLE_PASSWORD");
42                 return password;
43         }
44
45         public String getUserRoleNewPassword() 
46         {
47                 String password_new = getProperty( "NEW_USERROLE_PASSWORD" );
48                 return password_new;
49         }
50
51         public String getBasedir()
52     {
53         String basedir = System.getProperty( "basedir" );
54
55         if ( basedir == null )
56         {
57             basedir = new File( "" ).getAbsolutePath();
58         }
59
60         return basedir;
61     }
62         
63         public String getAdminUsername()
64         {
65                 String adminUsername = getProperty( "ADMIN_USERNAME" );
66                 return adminUsername;
67         }
68         
69         public String getAdminPassword()
70         {
71                 String adminPassword = getProperty( "ADMIN_PASSWORD" );
72                 return adminPassword;
73         }
74         
75         public void assertCreateAdmin()
76         {
77                         assertPage( "Apache Archiva \\ Create Admin User" );
78                         assertTextPresent( "Username" );
79                 assertFieldValue( "admin", "user.username" );
80                 assertTextPresent( "Full Name*" );
81                 assertElementPresent( "user.fullName" );
82                 assertTextPresent( "Email Address*" );
83                 assertElementPresent( "user.email");
84                 assertTextPresent( "Password*" );
85                 assertElementPresent( "user.password" );
86                 assertTextPresent( "Confirm Password*"   );
87                 assertElementPresent( "user.confirmPassword" );
88                 assertButtonWithValuePresent( "Create Admin" );
89         }
90         
91         public void submitAdminData( String fullname, String email, String password )
92         {
93                 setFieldValue( "user.fullName", fullname );
94                 setFieldValue( "user.email", email );
95                 setFieldValue( "user.password", password );
96                 setFieldValue( "user.confirmPassword", password );
97                 submit();
98         }
99         
100         //Go to Login Page
101         public void goToLoginPage()
102         {
103                 getSelenium().open( baseUrl );
104                 clickLinkWithText( "Login");
105                 assertLoginPage();
106         }
107         
108         public void submitUserData( String username, String password, boolean rememberme, boolean success )
109         {
110
111                 setFieldValue( "username", username );
112                 setFieldValue( "password", password );
113                 if ( rememberme )
114                 {
115                         checkField( "rememberMe" );
116                 }
117                 
118                 submit();
119                 if ( success )
120                 {
121                 assertUserLoggedIn( username );
122             }
123                 else
124                 {
125                     assertLoginPage();
126                 }
127         }
128         
129         public void assertLoginPage()
130         {
131                         assertPage( "Apache Archiva \\ Login Page" );
132                 assertTextPresent( "Login" );
133                 assertTextPresent( "Register" );
134                 assertTextPresent( "Username" );
135                 assertElementPresent( "username" );
136                 assertTextPresent( "Password" );
137                 assertElementPresent( "password" );
138                 assertTextPresent( "Remember Me" );
139                 assertElementPresent( "rememberMe" );
140                 assertButtonWithValuePresent( "Login" );
141                 assertButtonWithValuePresent( "Cancel" );
142                 assertTextPresent( "Need an Account? Register!" );
143                 assertTextPresent( "Forgot your Password? Request a password reset." );
144         }
145
146     //User Management
147         public void goToUserManagementPage()
148         {
149                 clickLinkWithText( "User Management" );
150                 assertUserManagementPage();
151         }
152         
153         public void assertUserManagementPage()
154         {
155                 assertPage( "Apache Archiva \\ [Admin] User List" );
156                 assertTextPresent( "[Admin] List of Users in Role: Any" );
157                 assertTextPresent( "Navigation" );
158                 assertImgWithAlt( "First" );
159                 assertImgWithAlt( "Prev" );
160                 assertImgWithAlt( "Next" );
161                 assertImgWithAlt( "Last" );
162                 assertTextPresent( "Display Rows" );
163                 assertTextPresent( "Username" );
164                 assertTextPresent( "Full Name" );
165                 assertTextPresent( "Email" );
166                 assertTextPresent( "Permanent" );
167                 assertTextPresent( "Validated" );
168                 assertTextPresent( "Locked" );
169                 assertTextPresent( "Tasks" );
170                 assertTextPresent( "Tools" );
171                 assertTextPresent( "Tasks" );
172                 assertTextPresent( "The following tools are available for administrators to manipulate the user list." );
173                 assertButtonWithValuePresent( "Create New User" );
174                 assertButtonWithValuePresent( "Show Users In Role" );
175                 assertElementPresent( "roleName" );
176                 assertTextPresent( "Reports" );
177                 assertTextPresent( "Name" );
178                 assertTextPresent( "Types" );
179                 assertTextPresent( "User List" );
180                 assertTextPresent( "Roles Matrix" );
181         }
182         
183 /*      //User Role
184         public void goToUserRolesPage()
185         {
186                 clickLinkWithText( "User Roles" );
187                 assertUserRolesPage();
188         }*/
189         
190         public void assertUserRolesPage()
191         {
192                 assertPage( "Apache Archiva \\ [Admin] User Edit" );
193                 assertTextPresent( "[Admin] User Roles" );
194                 assertTextPresent( "Username" );
195                 assertTextPresent( "Full Name" );
196                 String userRoles = "Guest,Registered User,System Administrator,User Administrator,Global Repository Observer,Global Repository Manager,Repository Observer,Repository Manager,internal";
197                 String[] arrayRole = userRoles.split( "," );
198                 for ( String userroles : arrayRole )
199                         assertTextPresent( userroles );
200         }
201         
202         public void assertDeleteUserPage( String username )
203          {
204                 assertPage( "Apache Archiva \\ [Admin] User Delete" ); //TODO
205                 assertTextPresent( "[Admin] User Delete" );
206                 assertTextPresent( "The following user will be deleted:" );
207                 assertTextPresent( "Username: " + username );
208                 assertButtonWithValuePresent( "Delete User" );
209          }
210         
211         public void createUser( String userName, String fullName, String email, String password, boolean valid )
212         {
213                 createUser( userName, fullName, email, password, password, valid );
214         }
215         
216         private void createUser( String userName, String fullName, String emailAd, String password, String confirmPassword, boolean valid ) 
217         {
218                 //login( getAdminUsername() , getAdminPassword() );
219                 clickLinkWithText( "User Management" );
220                 clickButtonWithValue( "Create New User" );
221                 assertCreateUserPage();
222         setFieldValue( "user.username", userName );
223         setFieldValue( "user.fullName", fullName );
224         setFieldValue( "user.email", emailAd );
225         setFieldValue( "user.password", password );
226         setFieldValue( "user.confirmPassword", confirmPassword );
227         submit();
228         
229         assertUserRolesPage( );
230         clickButtonWithValue( "Submit" );
231         
232         if (valid )
233         {
234                 String[] columnValues = {userName, fullName, emailAd};
235             assertElementPresent( XPathExpressionUtil.getTableRow( columnValues ) );
236         }
237         else
238         {
239             assertCreateUserPage();
240         }
241         }
242         
243         public void deleteUser( String userName, String fullName, String emailAdd )
244     {
245         deleteUser( userName, fullName, emailAdd, false, false );
246     }
247         
248         public void deleteUser(String userName, String fullName, String emailAd, boolean validated, boolean locked)
249         {
250                 String[] columnValues = {userName, fullName, emailAd};
251                 //clickLinkWithText( "userlist" );
252                 clickLinkWithXPath( "//table[@id='ec_table']/tbody[2]/tr[3]/td[7]/a/img" );
253                 assertDeleteUserPage( userName );
254         submit();
255         assertElementNotPresent( XPathExpressionUtil.getTableRow( columnValues ) );
256         }
257
258     public void login( String username, String password )
259     {
260         login( username, password, true, "Login Page" );
261     }
262         
263         public void login( String username, String password, boolean valid, String assertReturnPage )
264     {
265         if ( isLinkPresent( "Login" ) )
266         {
267             goToLoginPage();
268
269             submitLoginPage( username, password, false, valid, assertReturnPage );
270         }
271         if ( valid )
272         {
273             assertUserLoggedIn( username );
274         }
275     }
276     
277     public void submitLoginPage( String username, String password )
278     {
279         submitLoginPage( username, password, false, true, "Login Page" );
280     }
281
282     public void submitLoginPage( String username, String password, boolean validUsernamePassword )
283     {
284         submitLoginPage( username, password, false, validUsernamePassword, "Login Page" );
285     }
286
287     public void submitLoginPage( String username, String password, boolean rememberMe, boolean validUsernamePassword,
288                                  String assertReturnPage )
289     {
290         assertLoginPage();
291         setFieldValue( "username", username );
292         setFieldValue( "password", password );
293         if ( rememberMe )
294         {
295             checkField( "rememberMe" );
296         }
297         clickButtonWithValue( "Login" );
298
299         if ( validUsernamePassword )
300         {
301             assertUserLoggedIn( username );
302         }
303         else
304         {
305             if ( "Login Page".equals( assertReturnPage ) )
306             {
307                 assertLoginPage();
308             }
309             else
310             {
311                 assertPage( assertReturnPage );
312             }
313         }
314     }
315
316     protected void assertUserLoggedIn( String username )
317     {
318         assertTextPresent( "Current User:" );
319         assertTextPresent( username );
320         assertLinkPresent( "Edit Details" );
321         assertLinkPresent( "Logout" );
322         assertTextNotPresent( "Login" );
323     }
324
325     // User Roles
326         public void assertUserRoleCheckBoxPresent(String value) 
327         {
328                 getSelenium()   .isElementPresent("xpath=//input[@id='addRolesToUser_addNDSelectedRoles' and @name='addNDSelectedRoles' and @value='"   + value + "']");
329         }
330
331         public void assertResourceRolesCheckBoxPresent(String value) {
332                 getSelenium().isElementPresent("xpath=//input[@name='addDSelectedRoles' and @value='" + value + "']");
333         }
334
335         public void checkUserRoleWithValue(String value) 
336         {
337                 assertUserRoleCheckBoxPresent(value);
338                 getSelenium().click( "xpath=//input[@id='addRolesToUser_addNDSelectedRoles' and @name='addNDSelectedRoles' and @value='" + value + "']");
339         }
340
341         public void checkResourceRoleWithValue(String value) 
342         {
343                 assertResourceRolesCheckBoxPresent(value);
344                 getSelenium().click( "xpath=//input[@name='addDSelectedRoles' and @value='" + value + "']" );
345         }
346         
347         
348          public void changePassword(String oldPassword, String newPassword) {
349                 assertPage("Apache Archiva \\ Change Password");
350                 setFieldValue("existingPassword", oldPassword);
351                 setFieldValue("newPassword", newPassword);
352                 setFieldValue("newPasswordConfirm", newPassword);
353                 clickButtonWithValue("Change Password");
354         }
355         
356          public void assertCreateUserPage() 
357          {
358                 assertPage( "Apache Archiva \\ [Admin] User Create" );
359                 assertTextPresent( "[Admin] User Create" );
360                 assertTextPresent( "Username*:" );
361                 assertElementPresent( "user.username" );
362                 assertTextPresent( "Full Name*:");
363                 assertElementPresent( "user.fullName" );
364                 assertTextPresent( "Email Address*:" );
365                 assertElementPresent( "user.email" );
366                 assertTextPresent( "Password*:" );
367                 assertElementPresent( "user.password" );
368                 assertTextPresent( "Confirm Password*:" );
369                 assertElementPresent( "user.confirmPassword" );
370                 assertButtonWithValuePresent( "Create User" );
371         }
372          
373         public void assertLeftNavMenuWithRole( String role )
374         {
375                 if ( role.equals( "Guest" ) || role.equals( "Registered User" )  || role.equals( "Global Repository Observer" ) || role.equals( "Repository Observer - internal" ) || role.equals( "Repository Observer - snapshots" ) )
376                 {
377                         assertTextPresent( "Search" );
378                         assertLinkPresent( "Find Artifact" );
379                         assertLinkPresent( "Browse" );
380                         assertLinkNotPresent( "Repositories" );
381                 }
382                 else if ( role.equals( "User Administrator" ) )
383                 {
384                         assertTextPresent( "Search" );
385                         assertLinkPresent( "Find Artifact" );
386                         assertLinkPresent( "Browse" );
387                         assertLinkPresent( "User Management" );
388                         assertLinkPresent( "User Roles" );
389                         assertLinkNotPresent( "Repositories" );
390                 }
391                 else if ( role.equals( "Global Repository Manager" ) || role.equals( "Repository Manager - internal" ) || role.equals( "Repository Manager - snapshots" ) )
392                 {
393                         assertTextPresent( "Search" );
394                         assertLinkPresent( "Find Artifact" );
395                         assertLinkPresent( "Browse" );
396                         assertLinkPresent( "Upload Artifact" );
397                         assertLinkPresent( "Delete Artifact" );
398                         assertLinkNotPresent( "Repositories" );
399                 }
400                 else 
401                 {
402                         assertTextPresent( "Search" );
403                         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";
404                         String[] arrayMenu = navMenu.split( "," );
405                         for (String navmenu : arrayMenu )
406                                 assertLinkPresent( navmenu );
407                 }
408         }
409         //Find Artifact
410         public void goToFindArtifactPage()
411         {
412                 clickLinkWithText( "Find Artifact" );
413                 assertFindArtifactPage();
414         }
415         
416         public void assertFindArtifactPage()
417         {
418                 assertPage( "Apache Archiva \\ Find Artifact" );
419                 assertTextPresent( "Find Artifact" );
420                 assertTextPresent( "Search for:" );
421                 assertTextPresent( "Checksum:" );
422                 assertElementPresent( "q" );
423                 assertButtonWithValuePresent( "Search" );
424         }
425         
426         //Appearance
427         public void goToAppearancePage()
428         {
429                 clickLinkWithText( "Appearance" );
430                 assertAppearancePage();
431         }
432         
433         public void assertAppearancePage()
434         {
435                 assertPage( "Apache Archiva \\ Configure Appearance" );
436                 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";
437                 String[] arrayAppearance = appearance.split( "," );
438                 for ( String appear : arrayAppearance )
439                         assertTextPresent( appear );
440                 assertLinkPresent( "Edit" );
441                 assertLinkPresent( "Change your appearance" );
442         }
443         
444         public void addEditAppearance( String name, String url, String logoUrl )
445         {
446                 setFieldValue( "organisationName" , name );
447                 setFieldValue( "organisationUrl" , url );
448                 setFieldValue( "organisationLogo" , logoUrl );
449                 clickButtonWithValue( "Save" );
450         }
451
452         // Upload Artifact
453     public void goToAddArtifactPage()
454     {
455         clickLinkWithText( "Upload Artifact" );
456         assertAddArtifactPage();
457     }
458
459     public void assertAddArtifactPage()
460     {
461         assertPage( "Apache Archiva \\ Upload Artifact" );
462         assertTextPresent( "Upload Artifact" );
463
464         String artifact =
465             "Upload Artifact,Group Id*:,Artifact Id*:,Version*:,Packaging*:,Classifier:,Generate Maven 2 POM,Artifact File*:,POM File:,Repository Id:";
466         String[] arrayArtifact = artifact.split( "," );
467         for ( String arrayartifact : arrayArtifact )
468             assertTextPresent( arrayartifact );
469
470         String artifactElements =
471             "upload_groupId,upload_artifactId,upload_version,upload_packaging,upload_classifier,upload_generatePom,upload_artifact,upload_pom,upload_repositoryId,upload_0";
472         String[] arrayArtifactElements = artifactElements.split( "," );
473         for ( String artifactelements : arrayArtifactElements )
474             assertElementPresent( artifactelements );
475     }
476
477     public void addArtifact( String groupId, String artifactId, String version, String packaging,
478                              String artifactFilePath, String repositoryId )
479     {
480         addArtifact( groupId, artifactId, version, packaging, true, artifactFilePath, repositoryId );
481     }
482
483     public void addArtifact( String groupId, String artifactId, String version, String packaging, boolean generatePom,
484                              String artifactFilePath, String repositoryId )
485     {
486         goToAddArtifactPage();
487         setFieldValue( "groupId", groupId );
488         setFieldValue( "artifactId", artifactId );
489         setFieldValue( "version", version );
490         setFieldValue( "packaging", packaging );
491
492         if ( generatePom )
493         {
494             checkField( "generatePom" );
495         }
496
497         String path;
498         if ( artifactFilePath != null && artifactFilePath.trim().length() > 0 )
499         {
500             File f = new File( artifactFilePath );
501             try
502             {
503                 path = f.getCanonicalPath();
504             }
505             catch ( IOException e )
506             {
507                 path = f.getAbsolutePath();
508             }
509         }
510         else
511         {
512             path = artifactFilePath;
513         }
514
515         setFieldValue( "artifact", path );
516         setFieldValue( "repositoryId", repositoryId );
517
518         clickButtonWithValue( "Submit" );
519     }
520
521     public void goToRepositoriesPage()
522     {
523         if( !getTitle().equals( "Apache Archiva \\ Administration - Repositories" ) )
524         {
525             clickLinkWithText( "Repositories" );
526         }
527         assertRepositoriesPage();
528     }
529
530     public void assertRepositoriesPage()
531     {
532         assertPage( "Apache Archiva \\ Administration - Repositories" );
533         assertTextPresent( "Administration - Repositories" );
534         assertTextPresent( "Managed Repositories" );
535         assertTextPresent( "Remote Repositories" );
536     }
537
538     public void addManagedRepository( String identifier, String name, String directory, String indexDirectory, String type, String cron,
539                                          String daysOlder, String retentionCount )
540     {
541         //goToRepositoriesPage();
542         //clickLinkWithText( "Add" );
543         setFieldValue( "repository.id" , identifier );
544         setFieldValue( "repository.name" , name );
545         setFieldValue( "repository.location" , directory );
546         setFieldValue( "repository.indexDir" , indexDirectory );
547         selectValue( "repository.layout", type );
548         setFieldValue( "repository.refreshCronExpression" , cron );
549         setFieldValue( "repository.daysOlder" , daysOlder );
550         setFieldValue( "repository.retentionCount" , retentionCount );
551         //TODO  
552         clickButtonWithValue( "Add Repository" );
553     }
554
555     protected void logout()
556     {
557         clickLinkWithText("Logout");
558         assertTextNotPresent( "Current User:" );
559         assertLinkNotPresent( "Edit Details" );
560         assertLinkNotPresent( "Logout" );
561         assertLinkPresent( "Login" );
562     }
563 }