1 package org.apache.archiva.web.test.parent;
4 import java.io.IOException;
6 import org.apache.archiva.web.test.XPathExpressionUtil;
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
17 * http://www.apache.org/licenses/LICENSE-2.0
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
27 public abstract class AbstractArchivaTest
28 extends AbstractSeleniumTest
30 protected String username;
32 protected String fullname;
34 public String getUserEmail()
36 String email = getProperty( "USERROLE_EMAIL" );
40 public String getUserRolePassword()
42 String password = getProperty( "USERROLE_PASSWORD" );
46 public String getUserRoleNewPassword()
48 String password_new = getProperty( "NEW_USERROLE_PASSWORD" );
52 public String getBasedir()
54 String basedir = System.getProperty( "basedir" );
56 if ( basedir == null )
58 basedir = new File( "" ).getAbsolutePath();
64 public String getAdminUsername()
66 String adminUsername = getProperty( "ADMIN_USERNAME" );
70 public String getAdminPassword()
72 String adminPassword = getProperty( "ADMIN_PASSWORD" );
76 public void assertCreateAdmin()
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" );
92 public void submitAdminData( String fullname, String email, String password )
94 setFieldValue( "user.fullName", fullname );
95 setFieldValue( "user.email", email );
96 setFieldValue( "user.password", password );
97 setFieldValue( "user.confirmPassword", password );
102 public void goToLoginPage()
104 getSelenium().open( baseUrl );
105 clickLinkWithText( "Login" );
109 public void submitUserData( String username, String password, boolean rememberme, boolean success )
112 setFieldValue( "username", username );
113 setFieldValue( "password", password );
116 checkField( "rememberMe" );
122 assertUserLoggedIn( username );
130 public void assertLoginPage()
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." );
148 public void goToUserManagementPage()
150 clickLinkWithText( "User Management" );
151 assertUserManagementPage();
154 public void assertUserManagementPage()
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" );
185 * //User Role public void goToUserRolesPage() { clickLinkWithText( "User Roles" ); assertUserRolesPage(); }
188 public void assertUserRolesPage()
190 assertPage( "Apache Archiva \\ [Admin] User Edit" );
191 assertTextPresent( "[Admin] User Roles" );
192 assertTextPresent( "Username" );
193 assertTextPresent( "Full Name" );
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 );
201 public void assertDeleteUserPage( String username )
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" );
210 public void createUser( String userName, String fullName, String email, String password, boolean valid )
212 createUser( userName, fullName, email, password, password, valid );
215 private void createUser( String userName, String fullName, String emailAd, String password, String confirmPassword,
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 );
229 assertUserRolesPage();
230 clickButtonWithValue( "Submit" );
234 String[] columnValues = { userName, fullName, emailAd };
235 assertElementPresent( XPathExpressionUtil.getTableRow( columnValues ) );
239 assertCreateUserPage();
243 public void deleteUser( String userName, String fullName, String emailAdd )
245 deleteUser( userName, fullName, emailAdd, false, false );
248 public void deleteUser( String userName, String fullName, String emailAd, boolean validated, boolean locked )
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 );
255 assertElementNotPresent( XPathExpressionUtil.getTableRow( columnValues ) );
258 public void login( String username, String password )
260 login( username, password, true, "Login Page" );
263 public void login( String username, String password, boolean valid, String assertReturnPage )
265 if ( isLinkPresent( "Login" ) )
269 submitLoginPage( username, password, false, valid, assertReturnPage );
273 assertUserLoggedIn( username );
277 public void submitLoginPage( String username, String password )
279 submitLoginPage( username, password, false, true, "Login Page" );
282 public void submitLoginPage( String username, String password, boolean validUsernamePassword )
284 submitLoginPage( username, password, false, validUsernamePassword, "Login Page" );
287 public void submitLoginPage( String username, String password, boolean rememberMe, boolean validUsernamePassword,
288 String assertReturnPage )
291 setFieldValue( "username", username );
292 setFieldValue( "password", password );
295 checkField( "rememberMe" );
297 clickButtonWithValue( "Login" );
299 if ( validUsernamePassword )
301 assertUserLoggedIn( username );
305 if ( "Login Page".equals( assertReturnPage ) )
311 assertPage( assertReturnPage );
316 protected void assertUserLoggedIn( String username )
318 assertTextPresent( "Current User:" );
319 assertTextPresent( username );
320 assertLinkPresent( "Edit Details" );
321 assertLinkPresent( "Logout" );
322 assertTextNotPresent( "Login" );
326 public void assertUserRoleCheckBoxPresent( String value )
328 getSelenium().isElementPresent(
329 "xpath=//input[@id='addRolesToUser_addNDSelectedRoles' and @name='addNDSelectedRoles' and @value='"
333 public void assertResourceRolesCheckBoxPresent( String value )
335 getSelenium().isElementPresent( "xpath=//input[@name='addDSelectedRoles' and @value='" + value + "']" );
338 public void checkUserRoleWithValue( String value )
340 assertUserRoleCheckBoxPresent( value );
342 "xpath=//input[@id='addRolesToUser_addNDSelectedRoles' and @name='addNDSelectedRoles' and @value='"
346 public void checkResourceRoleWithValue( String value )
348 assertResourceRolesCheckBoxPresent( value );
349 getSelenium().click( "xpath=//input[@name='addDSelectedRoles' and @value='" + value + "']" );
352 public void changePassword( String oldPassword, String newPassword )
354 assertPage( "Apache Archiva \\ Change Password" );
355 setFieldValue( "existingPassword", oldPassword );
356 setFieldValue( "newPassword", newPassword );
357 setFieldValue( "newPasswordConfirm", newPassword );
358 clickButtonWithValue( "Change Password" );
361 public void assertCreateUserPage()
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" );
378 public void assertLeftNavMenuWithRole( String role )
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" ) )
383 assertTextPresent( "Search" );
384 assertLinkPresent( "Find Artifact" );
385 assertLinkPresent( "Browse" );
386 assertLinkNotPresent( "Repositories" );
388 else if ( role.equals( "User Administrator" ) )
390 assertTextPresent( "Search" );
391 assertLinkPresent( "Find Artifact" );
392 assertLinkPresent( "Browse" );
393 assertLinkPresent( "User Management" );
394 assertLinkPresent( "User Roles" );
395 assertLinkNotPresent( "Repositories" );
397 else if ( role.equals( "Global Repository Manager" ) || role.equals( "Repository Manager - internal" )
398 || role.equals( "Repository Manager - snapshots" ) )
400 assertTextPresent( "Search" );
401 assertLinkPresent( "Find Artifact" );
402 assertLinkPresent( "Browse" );
403 assertLinkPresent( "Upload Artifact" );
404 assertLinkPresent( "Delete Artifact" );
405 assertLinkNotPresent( "Repositories" );
409 assertTextPresent( "Search" );
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 );
419 public void goToFindArtifactPage()
421 clickLinkWithText( "Find Artifact" );
422 assertFindArtifactPage();
425 public void assertFindArtifactPage()
427 assertPage( "Apache Archiva \\ Find Artifact" );
428 assertTextPresent( "Find Artifact" );
429 assertTextPresent( "Search for:" );
430 assertTextPresent( "Checksum:" );
431 assertElementPresent( "q" );
432 assertButtonWithValuePresent( "Search" );
436 public void goToAppearancePage()
438 clickLinkWithText( "Appearance" );
439 assertAppearancePage();
442 public void assertAppearancePage()
444 assertPage( "Apache Archiva \\ Configure 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" );
454 public void addEditAppearance( String name, String url, String logoUrl )
456 setFieldValue( "organisationName", name );
457 setFieldValue( "organisationUrl", url );
458 setFieldValue( "organisationLogo", logoUrl );
459 clickButtonWithValue( "Save" );
463 public void goToAddArtifactPage()
465 clickLinkWithText( "Upload Artifact" );
466 assertAddArtifactPage();
469 public void assertAddArtifactPage()
471 assertPage( "Apache Archiva \\ Upload Artifact" );
472 assertTextPresent( "Upload 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 );
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 );
487 public void addArtifact( String groupId, String artifactId, String version, String packaging,
488 String artifactFilePath, String repositoryId )
490 addArtifact( groupId, artifactId, version, packaging, true, artifactFilePath, repositoryId );
493 public void addArtifact( String groupId, String artifactId, String version, String packaging, boolean generatePom,
494 String artifactFilePath, String repositoryId )
496 goToAddArtifactPage();
497 setFieldValue( "groupId", groupId );
498 setFieldValue( "artifactId", artifactId );
499 setFieldValue( "version", version );
500 setFieldValue( "packaging", packaging );
504 checkField( "generatePom" );
508 if ( artifactFilePath != null && artifactFilePath.trim().length() > 0 )
510 File f = new File( artifactFilePath );
513 path = f.getCanonicalPath();
515 catch ( IOException e )
517 path = f.getAbsolutePath();
522 path = artifactFilePath;
525 setFieldValue( "artifact", path );
526 selectValue( "repositoryId", repositoryId );
528 clickButtonWithValue( "Submit" );
531 public void goToRepositoriesPage()
533 if ( !getTitle().equals( "Apache Archiva \\ Administration - Repositories" ) )
535 clickLinkWithText( "Repositories" );
537 assertRepositoriesPage();
540 public void assertRepositoriesPage()
542 assertPage( "Apache Archiva \\ Administration - Repositories" );
543 assertTextPresent( "Administration - Repositories" );
544 assertTextPresent( "Managed Repositories" );
545 assertTextPresent( "Remote Repositories" );
548 public void addManagedRepository( String identifier, String name, String directory, String indexDirectory,
549 String type, String cron, String daysOlder, String retentionCount )
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 );
562 clickButtonWithValue( "Add Repository" );
565 protected void logout()
567 clickLinkWithText( "Logout" );
568 assertTextNotPresent( "Current User:" );
569 assertLinkNotPresent( "Edit Details" );
570 assertLinkNotPresent( "Logout" );
571 assertLinkPresent( "Login" );