1 package org.apache.archiva.web.test.parent;
5 import org.apache.archiva.web.test.XPathExpressionUtil;
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
16 * http://www.apache.org/licenses/LICENSE-2.0
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
26 public abstract class AbstractArchivaTest
27 extends AbstractSeleniumTest
29 protected String username;
30 protected String fullname;
32 public String getUserEmail()
34 String email = getProperty("USERROLE_EMAIL");
38 public String getUserRolePassword()
40 String password = getProperty("USERROLE_PASSWORD");
44 public String getUserRoleNewPassword()
46 String password_new = getProperty( "NEW_USERROLE_PASSWORD" );
50 public String getBasedir()
52 String basedir = System.getProperty( "basedir" );
54 if ( basedir == null )
56 basedir = new File( "" ).getAbsolutePath();
62 public String getAdminUsername()
64 String adminUsername = getProperty( "ADMIN_USERNAME" );
68 public String getAdminPassword()
70 String adminPassword = getProperty( "ADMIN_PASSWORD" );
74 public void assertCreateAdmin()
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" );
90 public void submitAdminData( String fullname, String email, String password )
92 setFieldValue( "user.fullName", fullname );
93 setFieldValue( "user.email", email );
94 setFieldValue( "user.password", password );
95 setFieldValue( "user.confirmPassword", password );
100 public void goToLoginPage()
102 getSelenium().open( baseUrl );
103 clickLinkWithText( "Login");
107 public void submitUserData( String username, String password, boolean rememberme, boolean success )
110 setFieldValue( "username", username );
111 setFieldValue( "password", password );
114 checkField( "rememberMe" );
120 assertAuthenticatedPage( username );
128 public void assertLoginPage()
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." );
145 public void assertAuthenticatedPage( String username )
147 assertTextPresent( "Current User" );
148 assertTextPresent( "Edit Details" );
149 assertTextPresent( "Logout" );
150 assertTextNotPresent( "Login" );
151 assertTextPresent( username );
156 public void goToUserManagementPage()
158 clickLinkWithText( "User Management" );
159 assertUserManagementPage();
162 public void assertUserManagementPage()
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" );
193 public void goToUserRolesPage()
195 clickLinkWithText( "User Roles" );
196 assertUserRolesPage();
199 public void assertUserRolesPage()
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 );
211 public void assertDeleteUserPage( String username )
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" );
220 public void createUser( String userName, String fullName, String email, String password, boolean valid )
222 createUser( userName, fullName, email, password, password, valid );
225 private void createUser( String userName, String fullName, String emailAd, String password, String confirmPassword, boolean valid )
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 );
238 assertUserRolesPage( );
239 clickButtonWithValue( "Submit" );
243 String[] columnValues = {userName, fullName, emailAd};
244 assertElementPresent( XPathExpressionUtil.getTableRow( columnValues ) );
248 assertCreateUserPage();
252 public void deleteUser( String userName, String fullName, String emailAdd )
254 deleteUser( userName, fullName, emailAdd, false, false );
257 public void deleteUser(String userName, String fullName, String emailAd, boolean validated, boolean locked)
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 );
264 assertElementNotPresent( XPathExpressionUtil.getTableRow( columnValues ) );
267 public void login( String username, String password )
269 login( username, password, true, "Login Page" );
272 public void login( String username, String password, boolean valid, String assertReturnPage )
274 if ( isLinkPresent( "Login" ) )
278 submitLoginPage( username, password, false, valid, assertReturnPage );
282 public void submitLoginPage( String username, String password )
284 submitLoginPage( username, password, false, true, "Login Page" );
287 public void submitLoginPage( String username, String password, boolean validUsernamePassword )
289 submitLoginPage( username, password, false, validUsernamePassword, "Login Page" );
292 public void submitLoginPage( String username, String password, boolean rememberMe, boolean validUsernamePassword,
293 String assertReturnPage )
296 setFieldValue( "username", username );
297 setFieldValue( "password", password );
300 checkField( "rememberMe" );
302 clickButtonWithValue( "Login" );
304 if ( validUsernamePassword )
306 assertTextPresent( "Current User:" );
307 assertTextPresent( username );
308 assertLinkPresent( "Edit Details" );
309 assertLinkPresent( "Logout" );
313 if ( "Login Page".equals( assertReturnPage ) )
319 assertPage( assertReturnPage );
325 public void assertUserRoleCheckBoxPresent(String value)
327 getSelenium() .isElementPresent("xpath=//input[@id='addRolesToUser_addNDSelectedRoles' and @name='addNDSelectedRoles' and @value='" + value + "']");
330 public void assertResourceRolesCheckBoxPresent(String value) {
331 getSelenium().isElementPresent("xpath=//input[@name='addDSelectedRoles' and @value='" + value + "']");
334 public void checkUserRoleWithValue(String value)
336 assertUserRoleCheckBoxPresent(value);
337 getSelenium().click( "xpath=//input[@id='addRolesToUser_addNDSelectedRoles' and @name='addNDSelectedRoles' and @value='" + value + "']");
340 public void checkResourceRoleWithValue(String value)
342 assertResourceRolesCheckBoxPresent(value);
343 getSelenium().click( "xpath=//input[@name='addDSelectedRoles' and @value='" + value + "']" );
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");
355 public void assertCreateUserPage()
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" );
372 public void assertLeftNavMenuWithRole( String role )
374 if ( role.equals( "Guest" ) || role.equals( "Registered User" ) || role.equals( "Global Repository Observer" ) || role.equals( "Repository Observer - internal" ) || role.equals( "Repository Observer - snapshots" ) )
376 assertTextPresent( "Search" );
377 assertLinkPresent( "Find Artifact" );
378 assertLinkPresent( "Browse" );
379 assertLinkNotPresent( "Repositories" );
381 else if ( role.equals( "User Administrator" ) )
383 assertTextPresent( "Search" );
384 assertLinkPresent( "Find Artifact" );
385 assertLinkPresent( "Browse" );
386 assertLinkPresent( "User Management" );
387 assertLinkPresent( "User Roles" );
388 assertLinkNotPresent( "Repositories" );
390 else if ( role.equals( "Global Repository Manager" ) || role.equals( "Repository Manager - internal" ) || role.equals( "Repository Manager - snapshots" ) )
392 assertTextPresent( "Search" );
393 assertLinkPresent( "Find Artifact" );
394 assertLinkPresent( "Browse" );
395 assertLinkPresent( "Upload Artifact" );
396 assertLinkPresent( "Delete Artifact" );
397 assertLinkNotPresent( "Repositories" );
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";
403 String[] arrayMenu = navMenu.split( "," );
404 for (String navmenu : arrayMenu )
405 assertLinkPresent( navmenu );
409 public void goToFindArtifactPage()
411 clickLinkWithText( "Find Artifact" );
412 assertFindArtifactPage();
415 public void assertFindArtifactPage()
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." );
428 public void goToAppearancePage()
430 clickLinkWithText( "Appearance" );
431 assertAppearancePage();
434 public void assertAppearancePage()
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" );
445 public void addEditAppearance( String name, String url, String logoUrl )
447 setFieldValue( "organisationName" , name );
448 setFieldValue( "organisationUrl" , url );
449 setFieldValue( "organisationLogo" , logoUrl );
450 clickButtonWithValue( "Save" );
454 public void goToAddArtifactPage()
456 clickLinkWithText( "Upload Artifact" );
457 assertAddArtifactPage();
460 public void assertAddArtifactPage()
462 assertPage( "Apache Archiva \\ Upload Artifact" );
463 assertTextPresent( "Upload 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 );
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 );
478 public void addArtifact( String groupId, String artifactId, String version, String packaging,
479 String artifactFilePath, String repositoryId )
481 addArtifact( groupId, artifactId, version, packaging, true, artifactFilePath, repositoryId );
484 public void addArtifact( String groupId, String artifactId, String version, String packaging, boolean generatePom,
485 String artifactFilePath, String repositoryId )
487 goToAddArtifactPage();
488 setFieldValue( "groupId", groupId );
489 setFieldValue( "artifactId", artifactId );
490 setFieldValue( "version", version );
491 setFieldValue( "packaging", packaging );
495 checkField( "generatePom" );
498 setFieldValue( "artifact", artifactFilePath );
499 setFieldValue( "repositoryId", repositoryId );
501 clickButtonWithValue( "Submit" );
504 public void goToRepositoriesPage()
506 if( !getTitle().equals( "Apache Archiva \\ Administration - Repositories" ) )
508 clickLinkWithText( "Repositories" );
510 assertRepositoriesPage();
513 public void assertRepositoriesPage()
515 assertPage( "Apache Archiva \\ Administration - Repositories" );
516 assertTextPresent( "Administration - Repositories" );
517 assertTextPresent( "Managed Repositories" );
518 assertTextPresent( "Remote Repositories" );
521 public void addManagedRepository( String identifier, String name, String directory, String indexDirectory, String type, String cron,
522 String daysOlder, String retentionCount )
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 );
535 clickButtonWithValue( "Add Repository" );