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;
31 protected String fullname;
33 public String getUserEmail()
35 String email = getProperty("USERROLE_EMAIL");
39 public String getUserRolePassword()
41 String password = getProperty("USERROLE_PASSWORD");
45 public String getUserRoleNewPassword()
47 String password_new = getProperty( "NEW_USERROLE_PASSWORD" );
51 public String getBasedir()
53 String basedir = System.getProperty( "basedir" );
55 if ( basedir == null )
57 basedir = new File( "" ).getAbsolutePath();
63 public String getAdminUsername()
65 String adminUsername = getProperty( "ADMIN_USERNAME" );
69 public String getAdminPassword()
71 String adminPassword = getProperty( "ADMIN_PASSWORD" );
75 public void assertCreateAdmin()
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" );
91 public void submitAdminData( String fullname, String email, String password )
93 setFieldValue( "user.fullName", fullname );
94 setFieldValue( "user.email", email );
95 setFieldValue( "user.password", password );
96 setFieldValue( "user.confirmPassword", password );
101 public void goToLoginPage()
103 getSelenium().open( baseUrl );
104 clickLinkWithText( "Login");
108 public void submitUserData( String username, String password, boolean rememberme, boolean success )
111 setFieldValue( "username", username );
112 setFieldValue( "password", password );
115 checkField( "rememberMe" );
121 assertUserLoggedIn( username );
129 public void assertLoginPage()
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." );
147 public void goToUserManagementPage()
149 clickLinkWithText( "User Management" );
150 assertUserManagementPage();
153 public void assertUserManagementPage()
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" );
184 public void goToUserRolesPage()
186 clickLinkWithText( "User Roles" );
187 assertUserRolesPage();
190 public void assertUserRolesPage()
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 );
202 public void assertDeleteUserPage( String username )
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" );
211 public void createUser( String userName, String fullName, String email, String password, boolean valid )
213 createUser( userName, fullName, email, password, password, valid );
216 private void createUser( String userName, String fullName, String emailAd, String password, String confirmPassword, boolean valid )
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("xpath=//input[@id='addRolesToUser_addNDSelectedRoles' and @name='addNDSelectedRoles' and @value='" + value + "']");
331 public void assertResourceRolesCheckBoxPresent(String value) {
332 getSelenium().isElementPresent("xpath=//input[@name='addDSelectedRoles' and @value='" + value + "']");
335 public void checkUserRoleWithValue(String value)
337 assertUserRoleCheckBoxPresent(value);
338 getSelenium().click( "xpath=//input[@id='addRolesToUser_addNDSelectedRoles' and @name='addNDSelectedRoles' and @value='" + value + "']");
341 public void checkResourceRoleWithValue(String value)
343 assertResourceRolesCheckBoxPresent(value);
344 getSelenium().click( "xpath=//input[@name='addDSelectedRoles' and @value='" + value + "']" );
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");
356 public void assertCreateUserPage()
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" );
373 public void assertLeftNavMenuWithRole( String role )
375 if ( role.equals( "Guest" ) || role.equals( "Registered User" ) || role.equals( "Global Repository Observer" ) || role.equals( "Repository Observer - internal" ) || role.equals( "Repository Observer - snapshots" ) )
377 assertTextPresent( "Search" );
378 assertLinkPresent( "Find Artifact" );
379 assertLinkPresent( "Browse" );
380 assertLinkNotPresent( "Repositories" );
382 else if ( role.equals( "User Administrator" ) )
384 assertTextPresent( "Search" );
385 assertLinkPresent( "Find Artifact" );
386 assertLinkPresent( "Browse" );
387 assertLinkPresent( "User Management" );
388 assertLinkPresent( "User Roles" );
389 assertLinkNotPresent( "Repositories" );
391 else if ( role.equals( "Global Repository Manager" ) || role.equals( "Repository Manager - internal" ) || role.equals( "Repository Manager - snapshots" ) )
393 assertTextPresent( "Search" );
394 assertLinkPresent( "Find Artifact" );
395 assertLinkPresent( "Browse" );
396 assertLinkPresent( "Upload Artifact" );
397 assertLinkPresent( "Delete Artifact" );
398 assertLinkNotPresent( "Repositories" );
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 );
410 public void goToFindArtifactPage()
412 clickLinkWithText( "Find Artifact" );
413 assertFindArtifactPage();
416 public void assertFindArtifactPage()
418 assertPage( "Apache Archiva \\ Find Artifact" );
419 assertTextPresent( "Find Artifact" );
420 assertTextPresent( "Search for:" );
421 assertTextPresent( "Checksum:" );
422 assertElementPresent( "q" );
423 assertButtonWithValuePresent( "Search" );
427 public void goToAppearancePage()
429 clickLinkWithText( "Appearance" );
430 assertAppearancePage();
433 public void assertAppearancePage()
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" );
444 public void addEditAppearance( String name, String url, String logoUrl )
446 setFieldValue( "organisationName" , name );
447 setFieldValue( "organisationUrl" , url );
448 setFieldValue( "organisationLogo" , logoUrl );
449 clickButtonWithValue( "Save" );
453 public void goToAddArtifactPage()
455 clickLinkWithText( "Upload Artifact" );
456 assertAddArtifactPage();
459 public void assertAddArtifactPage()
461 assertPage( "Apache Archiva \\ Upload Artifact" );
462 assertTextPresent( "Upload 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 );
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 );
477 public void addArtifact( String groupId, String artifactId, String version, String packaging,
478 String artifactFilePath, String repositoryId )
480 addArtifact( groupId, artifactId, version, packaging, true, artifactFilePath, repositoryId );
483 public void addArtifact( String groupId, String artifactId, String version, String packaging, boolean generatePom,
484 String artifactFilePath, String repositoryId )
486 goToAddArtifactPage();
487 setFieldValue( "groupId", groupId );
488 setFieldValue( "artifactId", artifactId );
489 setFieldValue( "version", version );
490 setFieldValue( "packaging", packaging );
494 checkField( "generatePom" );
498 if ( artifactFilePath != null && artifactFilePath.trim().length() > 0 )
500 File f = new File( artifactFilePath );
503 path = f.getCanonicalPath();
505 catch ( IOException e )
507 path = f.getAbsolutePath();
512 path = artifactFilePath;
515 setFieldValue( "artifact", path );
516 selectValue( "repositoryId", repositoryId );
518 clickButtonWithValue( "Submit" );
521 public void goToRepositoriesPage()
523 if( !getTitle().equals( "Apache Archiva \\ Administration - Repositories" ) )
525 clickLinkWithText( "Repositories" );
527 assertRepositoriesPage();
530 public void assertRepositoriesPage()
532 assertPage( "Apache Archiva \\ Administration - Repositories" );
533 assertTextPresent( "Administration - Repositories" );
534 assertTextPresent( "Managed Repositories" );
535 assertTextPresent( "Remote Repositories" );
538 public void addManagedRepository( String identifier, String name, String directory, String indexDirectory, String type, String cron,
539 String daysOlder, String retentionCount )
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 );
552 clickButtonWithValue( "Add Repository" );
555 protected void logout()
557 clickLinkWithText("Logout");
558 assertTextNotPresent( "Current User:" );
559 assertLinkNotPresent( "Edit Details" );
560 assertLinkNotPresent( "Logout" );
561 assertLinkPresent( "Login" );