1 package org.apache.archiva.web.test.parent;
3 import org.junit.runner.RunWith;
4 import org.junit.runners.BlockJUnit4ClassRunner;
7 import java.io.IOException;
10 * Licensed to the Apache Software Foundation (ASF) under one
11 * or more contributor license agreements. See the NOTICE file
12 * distributed with this work for additional information
13 * regarding copyright ownership. The ASF licenses this file
14 * to you under the Apache License, Version 2.0 (the
15 * "License"); you may not use this file except in compliance
16 * with the License. You may obtain a copy of the License at
18 * http://www.apache.org/licenses/LICENSE-2.0
20 * Unless required by applicable law or agreed to in writing,
21 * software distributed under the License is distributed on an
22 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
23 * KIND, either express or implied. See the License for the
24 * specific language governing permissions and limitations
28 @RunWith( BlockJUnit4ClassRunner.class )
29 public abstract class AbstractArchivaTest
30 extends AbstractSeleniumTest
33 protected String username;
35 protected String fullname;
37 public String getUserEmail()
39 String email = getProperty( "USERROLE_EMAIL" );
43 public String getUserRolePassword()
45 String password = getProperty( "USERROLE_PASSWORD" );
49 public String getUserRoleNewPassword()
51 String password_new = getProperty( "NEW_USERROLE_PASSWORD" );
55 public String getBasedir()
57 String basedir = System.getProperty( "basedir" );
59 if ( basedir == null )
61 basedir = new File( "" ).getAbsolutePath();
68 public void submitUserData( String username, String password, boolean rememberme, boolean success )
71 setFieldValue( "username", username );
72 setFieldValue( "password", password );
75 checkField( "rememberMe" );
81 assertUserLoggedIn( username );
90 public void goToUserManagementPage()
92 getSelenium().open( "/archiva/security/userlist.action" );
93 assertUserManagementPage();
96 public void assertUserManagementPage()
98 assertPage( "Apache Archiva \\ [Admin] User List" );
99 assertTextPresent( "[Admin] List of Users in Role: Any" );
100 assertTextPresent( "Navigation" );
101 assertImgWithAlt( "First" );
102 assertImgWithAlt( "Prev" );
103 assertImgWithAlt( "Next" );
104 assertImgWithAlt( "Last" );
105 assertTextPresent( "Display Rows" );
106 assertTextPresent( "Username" );
107 assertTextPresent( "Full Name" );
108 assertTextPresent( "Email" );
109 assertTextPresent( "Permanent" );
110 assertTextPresent( "Validated" );
111 assertTextPresent( "Locked" );
112 assertTextPresent( "Tasks" );
113 assertTextPresent( "Tools" );
114 assertTextPresent( "Tasks" );
115 assertTextPresent( "The following tools are available for administrators to manipulate the user list." );
116 assertButtonWithValuePresent( "Create New User" );
117 assertButtonWithValuePresent( "Show Users In Role" );
118 assertElementPresent( "roleName" );
119 assertTextPresent( "Reports" );
120 assertTextPresent( "Name" );
121 assertTextPresent( "Types" );
122 assertTextPresent( "User List" );
123 assertTextPresent( "Roles Matrix" );
127 * //User Role public void goToUserRolesPage() { clickLinkWithText( "User Roles" ); assertUserRolesPage(); }
130 public void assertUserRolesPage()
132 //assertPage( "Apache Archiva \\ [Admin] User Edit" );
133 //[Admin] RĂ´les de l'utilisateur
135 assertTextPresent( "[Admin] User Roles", "[Admin] R\u00F4les de l'utilisateur" );
136 assertTextPresent( "Username", "Nom d'utilisateur" );
137 assertTextPresent( "Full Name", "Nom complet" );
139 "Guest,Registered User,System Administrator,User Administrator,Global Repository Observer,Global Repository Manager,Repository Observer,Repository Manager,internal";
140 String[] arrayRole = userRoles.split( "," );
141 for ( String userroles : arrayRole )
143 assertTextPresent( userroles );
147 public void assertDeleteUserPage( String username )
149 assertTextPresent( "[Admin] User Delete", "[Admin] Suppression de l'utilisateur",
150 "L'utilisateur suivant va \u00EAtre supprim\u00E9:" );
151 assertTextPresent( "The following user will be deleted:" );
152 assertTextPresent( "Username: " + username, "Nom d'utilisateur:" + username );
153 assertButtonWithIdPresent( "userDeleteSubmit" );
156 public void createUser( String userName, String fullName, String email, String password, boolean valid )
158 createUser( userName, fullName, email, password, password, valid );
161 private void createUser( String userName, String fullName, String emailAd, String password, String confirmPassword,
165 clickLinkWithLocator( "menu-users-list-a", true );
166 clickLinkWithLocator( "users-view-tabs-li-user-edit-a", true );
168 assertCreateUserPage();
169 setFieldValue( "username", userName );
170 setFieldValue( "fullname", fullName );
171 setFieldValue( "email", emailAd );
172 setFieldValue( "password", password );
173 setFieldValue( "confirmPassword", confirmPassword );
175 clickLinkWithLocator( "user-create-form-register-button", true );
177 assertTextPresent( "User " + userName + " created." );
178 assertElementPresent( "users-grid-user-id-" + userName );
182 //String[] columnValues = { userName, fullName, emailAd };
183 //assertElementPresent( XPathExpressionUtil.getTableRow( columnValues ) );
188 assertCreateUserPage();
192 public void deleteUser( String userName, String fullName, String emailAdd )
194 deleteUser( userName, fullName, emailAdd, false, false );
197 public void deleteUser( String userName, String fullName, String emailAd, boolean validated, boolean locked )
199 clickLinkWithLocator( "menu-users-list-a", true );
200 assertTextPresent( userName );
201 assertTextPresent( fullName );
203 clickLinkWithLocator( "users-grid-delete-" + userName );
205 clickLinkWithLocator( "dialog-confirm-modal-ok" );
206 assertTextPresent( "User " + userName + " deleted." );
208 clickLinkWithLocator( "alert-message-success-close-a" );
210 assertElementNotPresent( "users-grid-user-id-" + userName );
211 assertTextNotPresent( fullName );
217 public void assertUserRoleCheckBoxPresent( String value )
219 getSelenium().isElementPresent(
220 "xpath=//input[@id='addRolesToUser_addNDSelectedRoles' and @name='addNDSelectedRoles' and @value='" + value
224 public void assertResourceRolesCheckBoxPresent( String value )
226 getSelenium().isElementPresent( "xpath=//input[@name='addDSelectedRoles' and @value='" + value + "']" );
229 public void checkUserRoleWithValue( String value )
231 assertUserRoleCheckBoxPresent( value );
233 "xpath=//input[@id='addRolesToUser_addNDSelectedRoles' and @name='addNDSelectedRoles' and @value='" + value
237 public void checkResourceRoleWithValue( String value )
239 assertResourceRolesCheckBoxPresent( value );
240 getSelenium().click( "xpath=//input[@name='addDSelectedRoles' and @value='" + value + "']" );
243 public void changePassword( String oldPassword, String newPassword )
245 assertPage( "Apache Archiva \\ Change Password" );
246 setFieldValue( "existingPassword", oldPassword );
247 setFieldValue( "newPassword", newPassword );
248 setFieldValue( "newPasswordConfirm", newPassword );
249 clickButtonWithValue( "Change Password" );
252 public void assertCreateUserPage()
254 assertTextPresent( "Username" );
255 assertElementPresent( "username" );
256 assertTextPresent( "Full Name" );
257 assertElementPresent( "fullname" );
258 assertTextPresent( "Email Address" );
259 assertElementPresent( "email" );
260 assertTextPresent( "Password" );
261 assertElementPresent( "password" );
262 assertTextPresent( "Confirm Password" );
263 assertElementPresent( "confirmPassword" );
264 assertButtonWithIdPresent( "user-create-form-register-button" );
268 public void assertLeftNavMenuWithRole( String role )
270 if ( role.equals( "Guest" ) || role.equals( "Registered User" ) || role.equals( "Global Repository Observer" )
271 || role.equals( "Repository Observer - internal" ) || role.equals( "Repository Observer - snapshots" ) )
273 assertTextPresent( "Search" );
274 assertLinkPresent( "Find Artifact" );
275 assertLinkPresent( "Browse" );
276 assertLinkNotPresent( "Repositories" );
278 else if ( role.equals( "User Administrator" ) )
280 assertTextPresent( "Search" );
281 assertLinkPresent( "Find Artifact" );
282 assertLinkPresent( "Browse" );
283 assertLinkPresent( "User Management" );
284 assertLinkPresent( "User Roles" );
285 assertLinkNotPresent( "Repositories" );
287 else if ( role.equals( "Global Repository Manager" ) || role.equals( "Repository Manager - internal" )
288 || role.equals( "Repository Manager - snapshots" ) )
290 assertTextPresent( "Search" );
291 assertLinkPresent( "Find Artifact" );
292 assertLinkPresent( "Browse" );
293 assertLinkPresent( "Upload Artifact" );
294 assertLinkPresent( "Delete Artifact" );
295 assertLinkNotPresent( "Repositories" );
299 assertTextPresent( "Search" );
301 "Find Artifact,Browse,Reports,User Management,User Roles,Appearance,Upload Artifact,Delete Artifact,Repository Groups,Repositories,Proxy Connectors,Legacy Support,Network Proxies,Repository Scanning";
302 String[] arrayMenu = navMenu.split( "," );
303 for ( String navmenu : arrayMenu )
305 assertLinkPresent( navmenu );
311 public void goToFindArtifactPage()
313 getSelenium().open( "/archiva/findArtifact.action" );
314 assertFindArtifactPage();
317 public void assertFindArtifactPage()
319 //assertPage( "Apache Archiva \\ Find Artifact" );
320 assertElementPresent( "searchBox" );
321 //assertTextPresent( "Find Artifact" );
322 //assertTextPresent( "Search for:" );
323 //assertTextPresent( "Checksum:" );
324 assertElementPresent( "quickSearchBox" );
325 assertElementPresent( "checksumSearch" );
326 //assertButtonWithValuePresent( "Search" );
327 assertElementPresent( "checksumSearch_0" );
331 public void goToAppearancePage()
333 getSelenium().open( "/archiva/admin/configureAppearance.action" );
334 assertAppearancePage();
337 public void assertAppearancePage()
339 assertPage( "Apache Archiva \\ Configure Appearance" );
341 "Appearance,Organization Details,The logo in the top right of the screen is controlled by the following settings.,Organization Information,Name,URL,Logo URL";
342 String[] arrayAppearance = appearance.split( "," );
343 for ( String appear : arrayAppearance )
345 assertTextPresent( appear );
347 assertLinkPresent( "Edit" );
348 assertLinkPresent( "Change your appearance" );
351 public void addEditAppearance( String name, String url, String logoUrl, boolean wait )
353 setFieldValue( "organisationName", name );
354 setFieldValue( "organisationUrl", url );
355 setFieldValue( "organisationLogo", logoUrl );
356 clickButtonWithValue( "Save", wait );
359 public void goToHomePage()
361 getSelenium().open( baseUrl );
365 public void goToAddArtifactPage()
367 // must be logged as admin
368 getSelenium().open( "/archiva/upload.action" );
369 assertAddArtifactPage();
372 public void assertAddArtifactPage()
374 assertPage( "Apache Archiva \\ Upload Artifact" );
375 assertTextPresent( "Upload Artifact" );
378 "Upload Artifact,Group Id*:,Artifact Id*:,Version*:,Packaging*:,Classifier:,Generate Maven 2 POM,Artifact File*:,POM File:,Repository Id:";
379 String[] arrayArtifact = artifact.split( "," );
380 for ( String arrayartifact : arrayArtifact )
382 assertTextPresent( arrayartifact );
385 String artifactElements =
386 "upload_groupId,upload_artifactId,upload_version,upload_packaging,upload_classifier,upload_generatePom,upload_artifact,upload_pom,upload_repositoryId,uploadSubmit";
387 String[] arrayArtifactElements = artifactElements.split( "," );
388 for ( String artifactelements : arrayArtifactElements )
390 assertElementPresent( artifactelements );
394 public void addArtifact( String groupId, String artifactId, String version, String packaging,
395 String artifactFilePath, String repositoryId, boolean wait )
397 addArtifact( groupId, artifactId, version, packaging, true, artifactFilePath, repositoryId, wait );
400 public void addArtifact( String groupId, String artifactId, String version, String packaging, boolean generatePom,
401 String artifactFilePath, String repositoryId, boolean wait )
403 login( getProperty( "ADMIN_USERNAME" ), getProperty( "ADMIN_PASSWORD" ) );
404 goToAddArtifactPage();
405 setFieldValue( "groupId", groupId );
406 setFieldValue( "artifactId", artifactId );
407 setFieldValue( "version", version );
408 setFieldValue( "packaging", packaging );
412 checkField( "generatePom" );
416 if ( artifactFilePath != null && artifactFilePath.trim().length() > 0 )
418 File f = new File( artifactFilePath );
421 path = f.getCanonicalPath();
423 catch ( IOException e )
425 path = f.getAbsolutePath();
430 path = artifactFilePath;
433 setFieldValue( "artifact", path );
434 selectValue( "upload_repositoryId", repositoryId );
436 //clickButtonWithValue( "Submit" );
437 clickButtonWithLocator( "uploadSubmit", wait );
440 public void goToRepositoriesPage()
442 if ( !getTitle().equals( "Apache Archiva \\ Administration - Repositories" ) )
444 getSelenium().open( "/archiva/admin/repositories.action" );
446 assertRepositoriesPage();
449 public void assertRepositoriesPage()
451 assertPage( "Apache Archiva \\ Administration - Repositories" );
452 assertTextPresent( "Administration - Repositories" );
453 assertTextPresent( "Managed Repositories" );
454 assertTextPresent( "Remote Repositories" );
457 public void addManagedRepository( String identifier, String name, String directory, String indexDirectory,
458 String type, String cron, String daysOlder, String retentionCount, boolean wait )
460 // goToRepositoriesPage();
461 // clickLinkWithText( "Add" );
462 setFieldValue( "repository.id", identifier );
463 setFieldValue( "repository.name", name );
464 setFieldValue( "repository.location", directory );
465 setFieldValue( "repository.indexDirectory", indexDirectory );
466 selectValue( "repository.layout", type );
467 setFieldValue( "repository.cronExpression", cron );
468 setFieldValue( "repository.daysOlder", daysOlder );
469 setFieldValue( "repository.retentionCount", retentionCount );
471 clickButtonWithValue( "Add Repository", wait );
474 // artifact management
475 public void assertDeleteArtifactPage()
477 assertPage( "Apache Archiva \\ Delete Artifact" );
478 assertTextPresent( "Delete Artifact" );
479 assertTextPresent( "Group Id*:" );
480 assertTextPresent( "Artifact Id*:" );
481 assertTextPresent( "Version*:" );
482 assertTextPresent( "Repository Id:" );
483 assertElementPresent( "groupId" );
484 assertElementPresent( "artifactId" );
485 assertElementPresent( "version" );
486 assertElementPresent( "repositoryId" );
487 assertButtonWithValuePresent( "Submit" );
491 public void goToNetworkProxiesPage()
493 clickLinkWithText( "Network Proxies" );
494 assertNetworkProxiesPage();
497 public void assertNetworkProxiesPage()
499 assertPage( "Apache Archiva \\ Administration - Network Proxies" );
500 assertTextPresent( "Administration - Network Proxies" );
501 assertTextPresent( "Network Proxies" );
502 assertLinkPresent( "Add Network Proxy" );
505 public void addNetworkProxy( String identifier, String protocol, String hostname, String port, String username,
508 //goToNetworkProxiesPage();
509 clickLinkWithText( "Add Network Proxy" );
510 assertAddNetworkProxy();
511 setFieldValue( "proxy.id", identifier );
512 setFieldValue( "proxy.protocol", protocol );
513 setFieldValue( "proxy.host", hostname );
514 setFieldValue( "proxy.port", port );
515 setFieldValue( "proxy.username", username );
516 setFieldValue( "proxy.password", password );
517 clickButtonWithValue( "Save Network Proxy" );
520 public void assertAddNetworkProxy()
522 assertPage( "Apache Archiva \\ Admin: Add Network Proxy" );
523 assertTextPresent( "Admin: Add Network Proxy" );
524 assertTextPresent( "Add network proxy:" );
525 assertTextPresent( "Identifier*:" );
526 assertTextPresent( "Protocol*:" );
527 assertTextPresent( "Hostname*:" );
528 assertTextPresent( "Port*:" );
529 assertTextPresent( "Username:" );
530 assertTextPresent( "Password:" );
531 assertButtonWithValuePresent( "Save Network Proxy" );
535 public void goToLegacySupportPage()
537 getSelenium().open( "/archiva/admin/legacyArtifactPath.action" );
538 assertLegacySupportPage();
541 public void assertLegacySupportPage()
543 assertPage( "Apache Archiva \\ Administration - Legacy Support" );
544 assertTextPresent( "Administration - Legacy Artifact Path Resolution" );
545 assertTextPresent( "Path Mappings" );
546 assertLinkPresent( "Add" );
549 public void addLegacyArtifactPath( String path, String groupId, String artifactId, String version,
550 String classifier, String type, boolean wait )
552 assertAddLegacyArtifactPathPage();
553 setFieldValue( "legacyArtifactPath.path", path );
554 setFieldValue( "groupId", groupId );
555 setFieldValue( "artifactId", artifactId );
556 setFieldValue( "version", version );
557 setFieldValue( "classifier", classifier );
558 setFieldValue( "type", type );
559 clickButtonWithValue( "Add Legacy Artifact Path", wait );
562 public void assertAddLegacyArtifactPathPage()
564 assertPage( "Apache Archiva \\ Admin: Add Legacy Artifact Path" );
565 assertTextPresent( "Admin: Add Legacy Artifact Path" );
567 "Enter the legacy path to map to a particular artifact reference, then adjust the fields as necessary." );
569 "addLegacyArtifactPath_legacyArtifactPath_path,addLegacyArtifactPath_groupId,addLegacyArtifactPath_artifactId,addLegacyArtifactPath_version,addLegacyArtifactPath_classifier,addLegacyArtifactPath_type";
570 String[] arrayElement = element.split( "," );
571 for ( String arrayelement : arrayElement )
573 assertElementPresent( arrayelement );
575 assertButtonWithValuePresent( "Add Legacy Artifact Path" );
578 // add managed repository and its staging repository
579 public void addStagingRepository( String identifier, String name, String directory, String indexDirectory,
580 String type, String cron, String daysOlder, String retentionCount )
582 setFieldValue( "repository.id", identifier );
583 setFieldValue( "repository.name", name );
584 setFieldValue( "repository.location", directory );
585 setFieldValue( "repository.indexDirectory", indexDirectory );
586 selectValue( "repository.layout", type );
587 setFieldValue( "repository.cronExpression", cron );
588 setFieldValue( "repository.daysOlder", daysOlder );
589 setFieldValue( "repository.retentionCount", retentionCount );
590 checkField( "stageNeeded" );
592 clickButtonWithValue( "Add Repository" );
595 protected void logout()
597 clickLinkWithText( "Logout" );
598 assertTextNotPresent( "Current User:" );
599 assertLinkNotVisible( "Edit Details" );
600 assertLinkNotVisible( "Logout" );
601 assertLinkVisible( "Login" );
604 protected String getAdminUserName()
606 return getProperty( "ADMIN_FULLNAME" );