]> source.dussan.org Git - archiva.git/blob
815895875203342f0d99da89f6acca672925816a
[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
32     protected String fullname;
33
34     public String getUserEmail()
35     {
36         String email = getProperty( "USERROLE_EMAIL" );
37         return email;
38     }
39
40     public String getUserRolePassword()
41     {
42         String password = getProperty( "USERROLE_PASSWORD" );
43         return password;
44     }
45
46     public String getUserRoleNewPassword()
47     {
48         String password_new = getProperty( "NEW_USERROLE_PASSWORD" );
49         return password_new;
50     }
51
52     public String getBasedir()
53     {
54         String basedir = System.getProperty( "basedir" );
55
56         if ( basedir == null )
57         {
58             basedir = new File( "" ).getAbsolutePath();
59         }
60
61         return basedir;
62     }
63
64     public String getAdminUsername()
65     {
66         String adminUsername = getProperty( "ADMIN_USERNAME" );
67         return adminUsername;
68     }
69
70     public String getAdminPassword()
71     {
72         String adminPassword = getProperty( "ADMIN_PASSWORD" );
73         return adminPassword;
74     }
75
76     public void assertCreateAdmin()
77     {
78         assertPage( "Apache Archiva \\ Create Admin User" );
79         assertTextPresent( "Username" );
80         assertFieldValue( "admin", "user.username" );
81         assertTextPresent( "Full Name*" );
82         assertElementPresent( "user.fullName" );
83         assertTextPresent( "Email Address*" );
84         assertElementPresent( "user.email" );
85         assertTextPresent( "Password*" );
86         assertElementPresent( "user.password" );
87         assertTextPresent( "Confirm Password*" );
88         assertElementPresent( "user.confirmPassword" );
89         assertButtonWithValuePresent( "Create Admin" );
90     }
91
92     public void submitAdminData( String fullname, String email, String password )
93     {
94         setFieldValue( "user.fullName", fullname );
95         setFieldValue( "user.email", email );
96         setFieldValue( "user.password", password );
97         setFieldValue( "user.confirmPassword", password );
98         submit();
99     }
100
101     // Go to Login Page
102     public void goToLoginPage()
103     {
104         getSelenium().open( baseUrl );
105         clickLinkWithText( "Login" );
106         assertLoginPage();
107     }
108
109     public void submitUserData( String username, String password, boolean rememberme, boolean success )
110     {
111
112         setFieldValue( "username", username );
113         setFieldValue( "password", password );
114         if ( rememberme )
115         {
116             checkField( "rememberMe" );
117         }
118
119         submit();
120         if ( success )
121         {
122             assertUserLoggedIn( username );
123         }
124         else
125         {
126             assertLoginPage();
127         }
128     }
129
130     public void assertLoginPage()
131     {
132         assertPage( "Apache Archiva \\ Login Page" );
133         assertTextPresent( "Login" );
134         assertTextPresent( "Register" );
135         assertTextPresent( "Username" );
136         assertElementPresent( "username" );
137         assertTextPresent( "Password" );
138         assertElementPresent( "password" );
139         assertTextPresent( "Remember Me" );
140         assertElementPresent( "rememberMe" );
141         assertButtonWithValuePresent( "Login" );
142         assertButtonWithValuePresent( "Cancel" );
143         assertTextPresent( "Need an Account? Register!" );
144         assertTextPresent( "Forgot your Password? Request a password reset." );
145     }
146
147     // User Management
148     public void goToUserManagementPage()
149     {
150         getSelenium().open( "/archiva/security/userlist.action" );
151         assertUserManagementPage();
152     }
153
154     public void assertUserManagementPage()
155     {
156         assertPage( "Apache Archiva \\ [Admin] User List" );
157         assertTextPresent( "[Admin] List of Users in Role: Any" );
158         assertTextPresent( "Navigation" );
159         assertImgWithAlt( "First" );
160         assertImgWithAlt( "Prev" );
161         assertImgWithAlt( "Next" );
162         assertImgWithAlt( "Last" );
163         assertTextPresent( "Display Rows" );
164         assertTextPresent( "Username" );
165         assertTextPresent( "Full Name" );
166         assertTextPresent( "Email" );
167         assertTextPresent( "Permanent" );
168         assertTextPresent( "Validated" );
169         assertTextPresent( "Locked" );
170         assertTextPresent( "Tasks" );
171         assertTextPresent( "Tools" );
172         assertTextPresent( "Tasks" );
173         assertTextPresent( "The following tools are available for administrators to manipulate the user list." );
174         assertButtonWithValuePresent( "Create New User" );
175         assertButtonWithValuePresent( "Show Users In Role" );
176         assertElementPresent( "roleName" );
177         assertTextPresent( "Reports" );
178         assertTextPresent( "Name" );
179         assertTextPresent( "Types" );
180         assertTextPresent( "User List" );
181         assertTextPresent( "Roles Matrix" );
182     }
183
184     /*
185      * //User Role public void goToUserRolesPage() { clickLinkWithText( "User Roles" ); assertUserRolesPage(); }
186      */
187
188     public void assertUserRolesPage()
189     {
190         assertPage( "Apache Archiva \\ [Admin] User Edit" );
191         assertTextPresent( "[Admin] User Roles" );
192         assertTextPresent( "Username" );
193         assertTextPresent( "Full Name" );
194         String userRoles =
195             "Guest,Registered User,System Administrator,User Administrator,Global Repository Observer,Global Repository Manager,Repository Observer,Repository Manager,internal";
196         String[] arrayRole = userRoles.split( "," );
197         for ( String userroles : arrayRole )
198             assertTextPresent( userroles );
199     }
200
201     public void assertDeleteUserPage( String username )
202     {
203         assertPage( "Apache Archiva \\ [Admin] User Delete" ); // TODO
204         assertTextPresent( "[Admin] User Delete" );
205         assertTextPresent( "The following user will be deleted:" );
206         assertTextPresent( "Username: " + username );
207         assertButtonWithValuePresent( "Delete User" );
208     }
209
210     public void createUser( String userName, String fullName, String email, String password, boolean valid )
211     {
212         createUser( userName, fullName, email, password, password, valid );
213     }
214
215     private void createUser( String userName, String fullName, String emailAd, String password, String confirmPassword,
216                              boolean valid )
217     {
218         // login( getAdminUsername() , getAdminPassword() );
219         getSelenium().open( "/archiva/security/userlist.action" );
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(
329                                         "xpath=//input[@id='addRolesToUser_addNDSelectedRoles' and @name='addNDSelectedRoles' and @value='"
330                                             + value + "']" );
331     }
332
333     public void assertResourceRolesCheckBoxPresent( String value )
334     {
335         getSelenium().isElementPresent( "xpath=//input[@name='addDSelectedRoles' and @value='" + value + "']" );
336     }
337
338     public void checkUserRoleWithValue( String value )
339     {
340         assertUserRoleCheckBoxPresent( value );
341         getSelenium().click(
342                              "xpath=//input[@id='addRolesToUser_addNDSelectedRoles' and @name='addNDSelectedRoles' and @value='"
343                                  + value + "']" );
344     }
345
346     public void checkResourceRoleWithValue( String value )
347     {
348         assertResourceRolesCheckBoxPresent( value );
349         getSelenium().click( "xpath=//input[@name='addDSelectedRoles' and @value='" + value + "']" );
350     }
351
352     public void changePassword( String oldPassword, String newPassword )
353     {
354         assertPage( "Apache Archiva \\ Change Password" );
355         setFieldValue( "existingPassword", oldPassword );
356         setFieldValue( "newPassword", newPassword );
357         setFieldValue( "newPasswordConfirm", newPassword );
358         clickButtonWithValue( "Change Password" );
359     }
360
361     public void assertCreateUserPage()
362     {
363         assertPage( "Apache Archiva \\ [Admin] User Create" );
364         assertTextPresent( "[Admin] User Create" );
365         assertTextPresent( "Username*:" );
366         assertElementPresent( "user.username" );
367         assertTextPresent( "Full Name*:" );
368         assertElementPresent( "user.fullName" );
369         assertTextPresent( "Email Address*:" );
370         assertElementPresent( "user.email" );
371         assertTextPresent( "Password*:" );
372         assertElementPresent( "user.password" );
373         assertTextPresent( "Confirm Password*:" );
374         assertElementPresent( "user.confirmPassword" );
375         assertButtonWithValuePresent( "Create User" );
376     }
377
378     public void assertLeftNavMenuWithRole( String role )
379     {
380         if ( role.equals( "Guest" ) || role.equals( "Registered User" ) || role.equals( "Global Repository Observer" )
381             || role.equals( "Repository Observer - internal" ) || role.equals( "Repository Observer - snapshots" ) )
382         {
383             assertTextPresent( "Search" );
384             assertLinkPresent( "Find Artifact" );
385             assertLinkPresent( "Browse" );
386             assertLinkNotPresent( "Repositories" );
387         }
388         else if ( role.equals( "User Administrator" ) )
389         {
390             assertTextPresent( "Search" );
391             assertLinkPresent( "Find Artifact" );
392             assertLinkPresent( "Browse" );
393             assertLinkPresent( "User Management" );
394             assertLinkPresent( "User Roles" );
395             assertLinkNotPresent( "Repositories" );
396         }
397         else if ( role.equals( "Global Repository Manager" ) || role.equals( "Repository Manager - internal" )
398             || role.equals( "Repository Manager - snapshots" ) )
399         {
400             assertTextPresent( "Search" );
401             assertLinkPresent( "Find Artifact" );
402             assertLinkPresent( "Browse" );
403             assertLinkPresent( "Upload Artifact" );
404             assertLinkPresent( "Delete Artifact" );
405             assertLinkNotPresent( "Repositories" );
406         }
407         else
408         {
409             assertTextPresent( "Search" );
410             String navMenu =
411                 "Find Artifact,Browse,Reports,User Management,User Roles,Appearance,Upload Artifact,Delete Artifact,Repository Groups,Repositories,Proxy Connectors,Legacy Support,Network Proxies,Repository Scanning";
412             String[] arrayMenu = navMenu.split( "," );
413             for ( String navmenu : arrayMenu )
414                 assertLinkPresent( navmenu );
415         }
416     }
417
418     // Find Artifact
419     public void goToFindArtifactPage()
420     {
421         getSelenium().open( "/archiva/findArtifact.action" );
422         assertFindArtifactPage();
423     }
424
425     public void assertFindArtifactPage()
426     {
427         assertPage( "Apache Archiva \\ Find Artifact" );
428         assertTextPresent( "Find Artifact" );
429         assertTextPresent( "Search for:" );
430         assertTextPresent( "Checksum:" );
431         assertElementPresent( "q" );
432         assertButtonWithValuePresent( "Search" );
433     }
434
435     // Appearance
436     public void goToAppearancePage()
437     {
438         getSelenium().open( "/archiva/admin/configureAppearance.action" );
439         assertAppearancePage();
440     }
441
442     public void assertAppearancePage()
443     {
444         assertPage( "Apache Archiva \\ Configure Appearance" );
445         String appearance =
446             "Appearance,Organization Details,The logo in the top right of the screen is controlled by the following settings.,Organization Information,Name,URL,Logo URL";
447         String[] arrayAppearance = appearance.split( "," );
448         for ( String appear : arrayAppearance )
449             assertTextPresent( appear );
450         assertLinkPresent( "Edit" );
451         assertLinkPresent( "Change your appearance" );
452     }
453
454     public void addEditAppearance( String name, String url, String logoUrl )
455     {
456         setFieldValue( "organisationName", name );
457         setFieldValue( "organisationUrl", url );
458         setFieldValue( "organisationLogo", logoUrl );
459         clickButtonWithValue( "Save" );
460     }
461
462     // Upload Artifact
463     public void goToAddArtifactPage()
464     {
465         getSelenium().open( "/archiva/upload.action" );
466         assertAddArtifactPage();
467     }
468
469     public void assertAddArtifactPage()
470     {
471         assertPage( "Apache Archiva \\ Upload Artifact" );
472         assertTextPresent( "Upload Artifact" );
473
474         String artifact =
475             "Upload Artifact,Group Id*:,Artifact Id*:,Version*:,Packaging*:,Classifier:,Generate Maven 2 POM,Artifact File*:,POM File:,Repository Id:";
476         String[] arrayArtifact = artifact.split( "," );
477         for ( String arrayartifact : arrayArtifact )
478             assertTextPresent( arrayartifact );
479
480         String artifactElements =
481             "upload_groupId,upload_artifactId,upload_version,upload_packaging,upload_classifier,upload_generatePom,upload_artifact,upload_pom,upload_repositoryId,upload_0";
482         String[] arrayArtifactElements = artifactElements.split( "," );
483         for ( String artifactelements : arrayArtifactElements )
484             assertElementPresent( artifactelements );
485     }
486
487     public void addArtifact( String groupId, String artifactId, String version, String packaging,
488                              String artifactFilePath, String repositoryId )
489     {
490         addArtifact( groupId, artifactId, version, packaging, true, artifactFilePath, repositoryId );
491     }
492
493     public void addArtifact( String groupId, String artifactId, String version, String packaging, boolean generatePom,
494                              String artifactFilePath, String repositoryId )
495     {
496         goToAddArtifactPage();
497         setFieldValue( "groupId", groupId );
498         setFieldValue( "artifactId", artifactId );
499         setFieldValue( "version", version );
500         setFieldValue( "packaging", packaging );
501
502         if ( generatePom )
503         {
504             checkField( "generatePom" );
505         }
506
507         String path;
508         if ( artifactFilePath != null && artifactFilePath.trim().length() > 0 )
509         {
510             File f = new File( artifactFilePath );
511             try
512             {
513                 path = f.getCanonicalPath();
514             }
515             catch ( IOException e )
516             {
517                 path = f.getAbsolutePath();
518             }
519         }
520         else
521         {
522             path = artifactFilePath;
523         }
524
525         setFieldValue( "artifact", path );
526         selectValue( "repositoryId", repositoryId );
527
528         clickButtonWithValue( "Submit" );
529     }
530
531     public void goToRepositoriesPage()
532     {
533         if ( !getTitle().equals( "Apache Archiva \\ Administration - Repositories" ) )
534         {
535             getSelenium().open( "/archiva/admin/repositories.action" );
536         }
537         assertRepositoriesPage();
538     }
539
540     public void assertRepositoriesPage()
541     {
542         assertPage( "Apache Archiva \\ Administration - Repositories" );
543         assertTextPresent( "Administration - Repositories" );
544         assertTextPresent( "Managed Repositories" );
545         assertTextPresent( "Remote Repositories" );
546     }
547
548     public void addManagedRepository( String identifier, String name, String directory, String indexDirectory,
549                                       String type, String cron, String daysOlder, String retentionCount )
550     {
551         // goToRepositoriesPage();
552         // clickLinkWithText( "Add" );
553         setFieldValue( "repository.id", identifier );
554         setFieldValue( "repository.name", name );
555         setFieldValue( "repository.location", directory );
556         setFieldValue( "repository.indexDir", indexDirectory );
557         selectValue( "repository.layout", type );
558         setFieldValue( "repository.refreshCronExpression", cron );
559         setFieldValue( "repository.daysOlder", daysOlder );
560         setFieldValue( "repository.retentionCount", retentionCount );
561         // TODO
562         clickButtonWithValue( "Add Repository" );
563     }
564
565     protected void logout()
566     {
567         clickLinkWithText( "Logout" );
568         assertTextNotPresent( "Current User:" );
569         assertLinkNotPresent( "Edit Details" );
570         assertLinkNotPresent( "Logout" );
571         assertLinkPresent( "Login" );
572     }
573 }