From 50193ed8c59a99fe64fe814fc4678a3c0e84b503 Mon Sep 17 00:00:00 2001 From: Wendy Smoak Date: Sat, 16 May 2009 04:00:46 +0000 Subject: [PATCH] [MRM-1164] Improve the Selenium tests * added tests for archiva user roles * added tests for upload artifact * modified scripts from Search and Browse Submitted by: Marecor Baclay git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@775412 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/test/resources/testng.properties | 57 +++- .../src/test/testng/config/testng.xml | 2 + .../archiva/web/test/ArchivaAdminTest.java | 170 ++++++++++ .../web/test/ArtifactManagementTest.java | 63 ++++ .../apache/archiva/web/test/ReportsTest.java | 28 +- .../apache/archiva/web/test/SearchTest.java | 2 + .../archiva/web/test/UserRolesTest.java | 280 ++++++++++++++++ .../archiva/web/test/XPathExpressionUtil.java | 245 ++++++++++++++ .../web/test/parent/AbstractArchivaTest.java | 306 ++++++++++++++++-- .../AbstractArtifactManagementTest.java | 119 +++++++ .../web/test/parent/AbstractSeleniumTest.java | 2 +- 11 files changed, 1220 insertions(+), 54 deletions(-) create mode 100644 archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/ArtifactManagementTest.java create mode 100644 archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/UserRolesTest.java create mode 100644 archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/XPathExpressionUtil.java create mode 100644 archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractArtifactManagementTest.java diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/resources/testng.properties b/archiva-modules/archiva-web/archiva-webapp-test/src/test/resources/testng.properties index 82e90928e..0b2680028 100644 --- a/archiva-modules/archiva-web/archiva-webapp-test/src/test/resources/testng.properties +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/resources/testng.properties @@ -6,28 +6,67 @@ MAX_WAIT_TIME_IN_MS=60000 ADMIN_USERNAME=admin ADMIN_FULLNAME=Administrator ADMIN_EMAIL=admin@localhost -ADMIN_PASSWORD=admin123 +ADMIN_PASSWORD=admin1 SELENIUM_HOST=localhost SELENIUM_PORT=4444 SELENIUM_BROWSER=*firefox -# Search +# Search, Artifact Management SEARCH_BAD_ARTIFACT=asdf # Existing Artifact -ARTIFACT_GROUPID=org.apache.maven.archiva.web.test -ARTIFACT_ARTIFACTID=artifact-a +ARTIFACT_GROUPID=test +ARTIFACT_ARTIFACTID=test ARTIFACT_VERSION=1.0 ARTIFACT_PACKAGING=jar - # Reports REPOSITORY_NAME=internal START_DATE=04/01/2009 END_DATE=04/30/2009 +# Add Valid Artifact + # User Management +# For password and new password +USERROLE_EMAIL=admin@localhost +USERROLE_PASSWORD=password1 +NEW_USERROLE_PASSWORD=password123 + +# Guest Role GUEST_USERNAME=guest_user -GUEST_FULLNAME=Guest User -GUEST_EMAIL=guest_user@localhost.localdomain -GUEST_PASSWORD=guest12 -GUEST_PASSWORD1=guest123 \ No newline at end of file +GUEST_FULLNAME=Guest +# Registered User Role +REGISTERED_USERNAME=reg_user +REGISTERED_FULLNAME=Registered User +# System Administrator +SYSAD_USERNAME=sys_admin +SYSAD_FULLNAME=System Administrator +# User Administrator +USERADMIN_USERNAME=user_admin +USERADMIN_FULLNAME=User Administrator +# Global Repository Manager +GLOBALREPOMANAGER_USERNAME=globalrepo_manager +GLOBALREPOMANAGER_FULLNAME=Global Repository Manager +# Global Repository Observer +GLOBALREPOOBSERVER_USERNAME=globalrepo_observer +GLOBALREPOOBSERVER_FULLNAME=Global Repository Observer +# Repository Manager - internal +REPOMANAGER_INTERNAL_USERNAME=repomanager_internal +REPOMANAGER_INTERNAL_FULLNAME=Repository Manager - internal +# Repository Manager - snapshots +REPOMANAGER_SNAPSHOTS_USERNAME=repomanager_snapshots +REPOMANAGER_SNAPSHOTS_FULLNAME=Repository Manager - snapshots +# Repository Observer - internal +REPOOBSERVER_INTERNAL_USERNAME=repoobserver_internal +REPOOBSERVER_INTERNAL_FULLNAME=Repository Observer - internal +# Repository Observer - snapshots +REPOOBSERVER_SNAPSHOTS_USERNAME=repoobserver_snapshots +REPOOBSERVER_SNAPSHOTS_FULLNAME=Repository Observer - snapshots + +# Add Artifact +GROUPID=test +ARTIFACTID=test +VERSION=1.0 +PACKAGING=jar +ARTIFACTFILEPATH=/path/to/artifact/file +REPOSITORYID=internal diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/config/testng.xml b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/config/testng.xml index 7d56abb98..f8bf37259 100644 --- a/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/config/testng.xml +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/config/testng.xml @@ -34,6 +34,8 @@ under the License. + + diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/ArchivaAdminTest.java b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/ArchivaAdminTest.java index 1ae6345f8..0c357a4f3 100644 --- a/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/ArchivaAdminTest.java +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/ArchivaAdminTest.java @@ -19,16 +19,42 @@ package org.apache.archiva.web.test; * under the License. */ +import java.io.File; +import java.io.Writer; +import java.io.FileWriter; +import java.io.FileReader; +import java.io.BufferedReader; +import java.util.List; +import java.util.Collections; + import org.apache.archiva.web.test.parent.AbstractArchivaTest; +import org.testng.Assert; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeSuite; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; +import org.jdom.Document; +import org.jdom.Element; +import org.jdom.input.SAXBuilder; +import org.jdom.output.XMLOutputter; +import org.jdom.xpath.XPath; +import org.codehaus.plexus.commandline.ExecutableResolver; +import org.codehaus.plexus.commandline.DefaultExecutableResolver; +import org.codehaus.plexus.util.cli.CommandLineUtils; +import org.codehaus.plexus.util.cli.Commandline; +import org.codehaus.plexus.util.cli.StreamConsumer; +import org.codehaus.plexus.util.cli.WriterStreamConsumer; @Test( groups = { "about" }, alwaysRun = true ) public class ArchivaAdminTest extends AbstractArchivaTest { + public static final String PATH_TO_ARCHIVA_XML = "/target/appserver-base/conf/archiva.xml"; + + public static final String PATH_TO_SETTINGS_XML = "/target/local-repo/settings.xml"; + + public static final String NEW_LOCAL_REPO_VALUE = "/target/local-repo"; + @BeforeSuite public void initializeContinuum() throws Exception @@ -56,9 +82,153 @@ public class ArchivaAdminTest throws Exception { super.open(); + String newValue = getBasedir() + NEW_LOCAL_REPO_VALUE; + updateXml( new File( getBasedir(), PATH_TO_ARCHIVA_XML ), newValue ); + updateXml( new File( getBasedir(), PATH_TO_SETTINGS_XML ), newValue ); } + /** + * Update localRepository element value + * + * @param f + * @param newValue + * @throws Exception + */ + private void updateXml( File f, String newValue ) + throws Exception + { + SAXBuilder builder = new SAXBuilder(); + FileReader reader = new FileReader( f ); + Document document = builder.build( reader ); + + Element localRepository = + (Element) XPath.newInstance( "./" + "localRepository" ).selectSingleNode( document.getRootElement() ); + localRepository.setText( newValue ); + + // re-write xml file + FileWriter writer = new FileWriter( f ); + XMLOutputter output = new XMLOutputter(); + output.output( document, writer ); + } + + /*private void clickRepositories() + { + goToLoginPage(); + submitLoginPage( getAdminUsername() , getAdminPassword() ); + clickLinkWithText( "Repositories" ); + assertPage( "Apache Archiva \\ Administration" ); + assertTextPresent( "Administration - Repositories" ); + } + + private void removedManagedRepository( String id) + { + clickRepositories(); + clickLinkWithLocator( "//a[contains(@href, '/admin/confirmDeleteRepository.action?repoid=" + id + "')]" ); + clickButtonWithValue( "Delete Configuration and Contents" ); + }*/ + + private int executeMaven( String workingDir, File outputFile ) + throws Exception + { + + ExecutableResolver executableResolver = new DefaultExecutableResolver(); + + String actualExecutable = "mvn"; + File workingDirectory = new File( workingDir ); + + List path = executableResolver.getDefaultPath(); + + if ( path == null ) + { + path = Collections.EMPTY_LIST; + } + + File e = executableResolver.findExecutable( "mvn", path ); + + if ( e != null ) + { + actualExecutable = e.getAbsolutePath(); + } + + File actualExecutableFile = new File( actualExecutable ); + + if ( !actualExecutableFile.exists() ) + { + actualExecutable = "mvn"; + } + + // Set command line + Commandline cmd = new Commandline(); + + cmd.addSystemEnvironment(); + + cmd.addEnvironment( "MAVEN_TERMINATE_CMD", "on" ); + + cmd.setExecutable( actualExecutable ); + + cmd.setWorkingDirectory( workingDirectory.getAbsolutePath() ); + + cmd.createArgument().setValue( "clean" ); + + cmd.createArgument().setValue( "install" ); + + cmd.createArgument().setValue( "-s" ); + + cmd.createArgument().setValue( getBasedir() + "/target/local-repo/settings.xml" ); + + // Excute command + + Writer writer = new FileWriter( outputFile ); + + StreamConsumer consumer = new WriterStreamConsumer( writer ); + + int exitCode = CommandLineUtils.executeCommandLine( cmd, consumer, consumer ); + + writer.flush(); + + writer.close(); + + return exitCode; + } +/* public void testBadDependency() + throws Exception + { + File outputFile = new File( getBasedir(), "/target/projects/bad-dependency/bad-dependency.log" ); + int exitCode = executeMaven( getBasedir() + "/target/projects/bad-dependency", outputFile ); + + Assert.assertEquals( 1, exitCode ); + + File f = new File( getBasedir(), + "/target/local-repo/org/apache/maven/archiva/web/test/foo-bar/1.0-SNAPSHOT/foo-bar-1.0-SNAPSHOT.jar" ); + Assert.assertTrue( !f.exists() ); + + BufferedReader reader = new BufferedReader( new FileReader( outputFile ) ); + String str; + boolean foundSnapshot = false, foundBadDep = false; + + while ( ( str = reader.readLine() ) != null ) + { + //System.out.println( str ); + if ( str.indexOf( + "mvn install:install-file -DgroupId=org.apache.maven.archiva.web.test -DartifactId=foo-bar" ) != -1 ) + { + foundSnapshot = true; + } + else if ( str.indexOf( + "mvn install:install-file -DgroupId=org.apache.maven.archiva.web.test -DartifactId=bad-dependency" ) != + -1 ) + { + foundBadDep = true; + } + } + + reader.close(); + + Assert.assertTrue( foundSnapshot ); + Assert.assertTrue( foundBadDep ); + }*/ + public void displayLandingPage() { getSelenium().open( baseUrl ); diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/ArtifactManagementTest.java b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/ArtifactManagementTest.java new file mode 100644 index 000000000..21a42b283 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/ArtifactManagementTest.java @@ -0,0 +1,63 @@ +package org.apache.archiva.web.test; + +import org.apache.archiva.web.test.parent.AbstractArtifactManagementTest; +import org.testng.annotations.Test; + +@Test( groups = { "userroles" }, dependsOnMethods = { "testWithCorrectUsernamePassword" } ) +public class ArtifactManagementTest + extends AbstractArtifactManagementTest +{ + + public void testAddArtifactNullValues() + { + goToAddArtifactPage(); + clickButtonWithValue( "Submit" ); + assertTextPresent( "Please add a file to upload." ); + assertTextPresent( "Invalid version." ); + assertTextPresent( "You must enter a groupId." ); + assertTextPresent( "You must enter an artifactId." ); + assertTextPresent( "You must enter a version" ); + assertTextPresent( "You must enter a packaging" ); + } + + @Test(dependsOnMethods = { "testAddArtifactNullValues" } ) + public void testAddArtifactNoGroupId() + { + addArtifact( " " , getArtifactId(), getVersion(), getPackaging() , getArtifactFilePath(), getRepositoryId() ); + assertTextPresent( "You must enter a groupId." ); + } + + @Test(dependsOnMethods = { "testAddArtifactNoGroupId" } ) + public void testAddArtifactNoArtifactId() + { + addArtifact( getGroupId() , " ", getVersion(), getPackaging() , getArtifactFilePath(), getRepositoryId() ); + assertTextPresent( "You must enter an artifactId." ); + } + + @Test(dependsOnMethods = { "testAddArtifactNoGroupId" } ) + public void testAddArtifactNoVersion() + { + addArtifact( getGroupId() , getArtifactId(), " ", getPackaging() , getArtifactFilePath(), getRepositoryId() ); + assertTextPresent( "You must enter a version." ); + } + + @Test(dependsOnMethods = { "testAddArtifactNoGroupId" } ) + public void testAddArtifactNoPackaging() + { + addArtifact( getGroupId() , getArtifactId(), getVersion(), " " , getArtifactFilePath(), getRepositoryId() ); + assertTextPresent( "You must enter a packaging." ); + } + + @Test(dependsOnMethods = { "testAddArtifactNoGroupId" } ) + public void testAddArtifactNoFilePath() + { + addArtifact( getGroupId() , getArtifactId(), getVersion(), getPackaging() , " ", getRepositoryId() ); + assertTextPresent( "Please add a file to upload." ); + } + + public void testAddArtifactValidValues() + { + addArtifact( getGroupId() , getArtifactId(), getVersion(), getPackaging() , getArtifactFilePath(), getRepositoryId() ); + assertTextPresent( "Artifact 'test:test:1.0' was successfully deployed to repository 'internal'" ); + } +} diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/ReportsTest.java b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/ReportsTest.java index 704086f9b..e3b34589c 100644 --- a/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/ReportsTest.java +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/ReportsTest.java @@ -22,13 +22,13 @@ package org.apache.archiva.web.test; import org.apache.archiva.web.test.parent.AbstractArtifactReportsTest; import org.testng.annotations.Test; -@Test( groups = { "reports" }, dependsOnMethods = { "testWithCorrectUsernamePassword" } ) +@Test( groups = { "reports" }, dependsOnMethods = { "testAddArtifactValidValues" } ) public class ReportsTest extends AbstractArtifactReportsTest { //TODO Tests for repository with defects - @Test(dependsOnMethods = { "testWithCorrectUsernamePassword" } ) +// @Test(dependsOnMethods = { "testAddArtifactValidValues" } ) public void testRepoStatisticsWithoutRepoCompared() { goToReportsPage(); @@ -36,16 +36,16 @@ public class ReportsTest assertTextPresent( "Please select a repository (or repositories) from the list." ); } - @Test(dependsOnMethods = { "testWithCorrectUsernamePassword" } ) +/* @Test(dependsOnMethods = { "testRepoStatisticsWithoutRepoCompared" } ) public void testRepositoryStatisticsWithoutDate() { String repositoryName = p.getProperty( "REPOSITORY_NAME" ) ; compareRepositories( "label=" + repositoryName, "", "" ); //TODO assertTextPresent( "Statistics Report" ); - } + }*/ - @Test(dependsOnMethods = { "testWithCorrectUsernamePassword" } ) + @Test(dependsOnMethods = { "testRepoStatisticsWithoutRepoCompared" } ) public void testRepositoryStatisticsEndEarlierThanStart() { String repositoryName = p.getProperty( "REPOSITORY_NAME" ) ; @@ -57,7 +57,7 @@ public class ReportsTest assertTextPresent( "Start Date must be earlier than the End Date" ); } - @Test(dependsOnMethods = { "testWithCorrectUsernamePassword" } ) +/* @Test(dependsOnMethods = { "testAddArtifactValidValues" } ) public void testRepositoryStatistics() { String repositoryName = p.getProperty( "REPOSITORY_NAME" ) ; @@ -67,9 +67,9 @@ public class ReportsTest //assertTextPresent( "Statistics for Repository '" + repositoryName + "'" ); assertPage( "Apache Archiva \\ Reports" ); assertTextPresent( "Statistics Report" ); - } + }*/ - @Test(dependsOnMethods = { "testWithCorrectUsernamePassword" } ) +/* @Test(dependsOnMethods = { "testAddArtifactValidValues" } ) public void testRepositoriesStatisticComparisonReport() { goToReportsPage(); @@ -77,8 +77,8 @@ public class ReportsTest clickButtonWithValue( "View Statistics" ); assertTextPresent( "Statistics Report" ); } - - @Test(dependsOnMethods = { "testWithCorrectUsernamePassword" } ) + */ + @Test(dependsOnMethods = { "testAddArtifactValidValues" } ) public void testRepositoryHealthWithoutDefect() { goToReportsPage(); @@ -89,15 +89,17 @@ public class ReportsTest assertTextPresent( "The operation generated an empty report." ); } - @Test(dependsOnMethods = { "testWithCorrectUsernamePassword" } ) +/* @Test(dependsOnMethods = { "testAddArtifactValidValues" } ) public void testRepositoryHealthWithoutGroupId() { - goToReportsPage(); + //goToReportsPage(); clickButtonWithValue( "Show Report" ); assertPage( "Apache Archiva \\ Reports" ); assertTextPresent( "The operation generated an empty report." ); //TODO As of the creation of the tests, GroupId is not a required field in showing the reports of repository health. GroupId should be required I think. - } + }*/ + + } \ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/SearchTest.java b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/SearchTest.java index fc0973bbd..7333acf18 100644 --- a/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/SearchTest.java +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/SearchTest.java @@ -34,6 +34,7 @@ public class SearchTest assertTextPresent( "No results found" ); } + @Test (dependsOnMethods = { "testAddArtifactValidValues" } ) public void testSearchExistingArtifact() { searchForArtifact( p.getProperty( "ARTIFACT_ARTIFACTID" ) ); @@ -42,6 +43,7 @@ public class SearchTest assertLinkPresent( "test" ); } + @Test (dependsOnMethods = { "testAddArtifactValidValues" } ) public void testViewSearchedArtifact() { searchForArtifact( p.getProperty( "ARTIFACT_ARTIFACTID" ) ); diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/UserRolesTest.java b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/UserRolesTest.java new file mode 100644 index 000000000..e0225de0e --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/UserRolesTest.java @@ -0,0 +1,280 @@ +package org.apache.archiva.web.test; + +import org.apache.archiva.web.test.parent.AbstractArchivaTest; +import org.testng.annotations.Test; + +@Test( groups = { "userroles" }, dependsOnMethods = { "testWithCorrectUsernamePassword" } ) +public class UserRolesTest + extends AbstractArchivaTest +{ + + public void testBasicAddDeleteUser() + { + username = p.getProperty( "GUEST_USERNAME" ); + fullname = p.getProperty( "GUEST_FULLNAME" ); + + createUser( username, fullname, getUserEmail(), getUserRolePassword(), true); + deleteUser( username, fullname, getUserEmail() ); + clickLinkWithText( "Logout" ); + } + + @Test (dependsOnMethods = { "testBasicAddDeleteUser" } ) + public void testUserWithGuestRole() + { + username = p.getProperty("GUEST_USERNAME"); + fullname = p.getProperty("GUEST_FULLNAME"); + + createUser(username, fullname, getUserEmail(), getUserRolePassword(), true); + clickLinkWithText( username ); + clickLinkWithText( "Edit Roles" ); + checkUserRoleWithValue( fullname ); + clickButtonWithValue( "Submit" ); + + clickLinkWithText("Logout"); + login(username, getUserRolePassword()); + changePassword( getUserRolePassword(), getUserRoleNewPassword()); + + // this section will be removed if issue from redback after changing password will be fixed. + getSelenium().goBack(); + clickLinkWithText("Logout"); + //assertTextPresent("You are already logged in."); + + login(username, getUserRoleNewPassword()); + assertLeftNavMenuWithRole( fullname ); + clickLinkWithText("Logout"); + } + + @Test (dependsOnMethods = { "testUserWithGuestRole" } ) + public void testUserWithRegisteredUserRole() + { + username = p.getProperty("REGISTERED_USERNAME"); + fullname = p.getProperty("REGISTERED_FULLNAME"); + + createUser(username, fullname, getUserEmail(), getUserRolePassword(), true); + clickLinkWithText( username ); + clickLinkWithText( "Edit Roles" ); + checkUserRoleWithValue( fullname ); + clickButtonWithValue( "Submit" ); + + clickLinkWithText("Logout"); + login(username, getUserRolePassword()); + changePassword( getUserRolePassword(), getUserRoleNewPassword()); + + // this section will be removed if issue from redback after changing password will be fixed. + getSelenium().goBack(); + clickLinkWithText("Logout"); + //assertTextPresent("You are already logged in."); + + login(username, getUserRoleNewPassword()); + assertLeftNavMenuWithRole( fullname ); + clickLinkWithText("Logout"); + } + + @Test (dependsOnMethods = { "testUserWithRegisteredUserRole" } ) + public void testUserWithSysAdminUserRole() + { + username = p.getProperty("SYSAD_USERNAME"); + fullname = p.getProperty("SYSAD_FULLNAME"); + + createUser(username, fullname, getUserEmail(), getUserRolePassword(), true); + clickLinkWithText( username ); + clickLinkWithText( "Edit Roles" ); + checkUserRoleWithValue( fullname ); + clickButtonWithValue( "Submit" ); + + clickLinkWithText("Logout"); + login(username, getUserRolePassword()); + changePassword( getUserRolePassword(), getUserRoleNewPassword()); + + // this section will be removed if issue from redback after changing password will be fixed. + getSelenium().goBack(); + clickLinkWithText("Logout"); + //assertTextPresent("You are already logged in."); + + login(username, getUserRoleNewPassword()); + assertLeftNavMenuWithRole( fullname ); + clickLinkWithText("Logout"); + } + + @Test (dependsOnMethods = { "testUserWithSysAdminUserRole" } ) + public void testUserWithUserAdminUserRole() + { + username = p.getProperty("USERADMIN_USERNAME"); + fullname = p.getProperty("USERADMIN_FULLNAME"); + + createUser(username, fullname, getUserEmail(), getUserRolePassword(), true); + clickLinkWithText( username ); + clickLinkWithText( "Edit Roles" ); + checkUserRoleWithValue( fullname ); + clickButtonWithValue( "Submit" ); + + clickLinkWithText("Logout"); + login(username, getUserRolePassword()); + changePassword( getUserRolePassword(), getUserRoleNewPassword()); + + // this section will be removed if issue from redback after changing password will be fixed. + getSelenium().goBack(); + clickLinkWithText("Logout"); + //assertTextPresent("You are already logged in."); + + login(username, getUserRoleNewPassword()); + assertLeftNavMenuWithRole( fullname ); + clickLinkWithText("Logout"); + } + + @Test (dependsOnMethods = { "testUserWithUserAdminUserRole" } ) + public void testUserWithGlobalRepoManagerRole() + { + username = p.getProperty("GLOBALREPOMANAGER_USERNAME"); + fullname = p.getProperty("GLOBALREPOMANAGER_FULLNAME"); + + createUser(username, fullname, getUserEmail(), getUserRolePassword(), true); + clickLinkWithText( username ); + clickLinkWithText( "Edit Roles" ); + checkUserRoleWithValue( fullname ); + clickButtonWithValue( "Submit" ); + + clickLinkWithText("Logout"); + login(username, getUserRolePassword()); + changePassword( getUserRolePassword(), getUserRoleNewPassword()); + + // this section will be removed if issue from redback after changing password will be fixed. + getSelenium().goBack(); + clickLinkWithText("Logout"); + //assertTextPresent("You are already logged in."); + + login(username, getUserRoleNewPassword()); + assertLeftNavMenuWithRole( fullname ); + clickLinkWithText("Logout"); + } + + @Test (dependsOnMethods = { "testUserWithUserAdminUserRole" } ) + public void testUserWithGlobalRepoObserverRole() + { + username = p.getProperty("GLOBALREPOOBSERVER_USERNAME"); + fullname = p.getProperty("GLOBALREPOOBSERVER_FULLNAME"); + + createUser(username, fullname, getUserEmail(), getUserRolePassword(), true); + clickLinkWithText( username ); + clickLinkWithText( "Edit Roles" ); + checkUserRoleWithValue( fullname ); + clickButtonWithValue( "Submit" ); + + clickLinkWithText("Logout"); + login(username, getUserRolePassword()); + changePassword( getUserRolePassword(), getUserRoleNewPassword()); + + // this section will be removed if issue from redback after changing password will be fixed. + getSelenium().goBack(); + clickLinkWithText("Logout"); + //assertTextPresent("You are already logged in."); + + login(username, getUserRoleNewPassword()); + assertLeftNavMenuWithRole( fullname ); + clickLinkWithText("Logout"); + } + + @Test (dependsOnMethods = { "testUserWithGlobalRepoManagerRole" } ) + public void testUserWithRepoManagerInternalRole() + { + username = p.getProperty("REPOMANAGER_INTERNAL_USERNAME"); + fullname = p.getProperty("REPOMANAGER_INTERNAL_FULLNAME"); + + createUser(username, fullname, getUserEmail(), getUserRolePassword(), true); + clickLinkWithText( username ); + clickLinkWithText( "Edit Roles" ); + checkResourceRoleWithValue( fullname ); + clickButtonWithValue( "Submit" ); + + clickLinkWithText("Logout"); + login(username, getUserRolePassword()); + changePassword( getUserRolePassword(), getUserRoleNewPassword()); + + // this section will be removed if issue from redback after changing password will be fixed. + getSelenium().goBack(); + clickLinkWithText("Logout"); + //assertTextPresent("You are already logged in."); + + login(username, getUserRoleNewPassword()); + assertLeftNavMenuWithRole( fullname ); + clickLinkWithText("Logout"); + } + + @Test (dependsOnMethods = { "testUserWithGlobalRepoManagerRole" } ) + public void testUserWithRepoManagerSnapshotsRole() + { + username = p.getProperty("REPOMANAGER_SNAPSHOTS_USERNAME"); + fullname = p.getProperty("REPOMANAGER_SNAPSHOTS_FULLNAME"); + + createUser(username, fullname, getUserEmail(), getUserRolePassword(), true); + clickLinkWithText( username ); + clickLinkWithText( "Edit Roles" ); + checkResourceRoleWithValue( fullname ); + clickButtonWithValue( "Submit" ); + + clickLinkWithText("Logout"); + login(username, getUserRolePassword()); + changePassword( getUserRolePassword(), getUserRoleNewPassword()); + + // this section will be removed if issue from redback after changing password will be fixed. + getSelenium().goBack(); + clickLinkWithText("Logout"); + //assertTextPresent("You are already logged in."); + + login(username, getUserRoleNewPassword()); + assertLeftNavMenuWithRole( fullname ); + clickLinkWithText("Logout"); + } + + @Test (dependsOnMethods = { "testUserWithGlobalRepoObserverRole" } ) + public void testUserWithRepoObserverInternalRole() + { + username = p.getProperty( "REPOOBSERVER_INTERNAL_USERNAME" ); + fullname = p.getProperty( "REPOOBSERVER_INTERNAL_FULLNAME" ); + + createUser(username, fullname, getUserEmail(), getUserRolePassword(), true); + clickLinkWithText( username ); + clickLinkWithText( "Edit Roles" ); + checkResourceRoleWithValue( fullname ); + clickButtonWithValue( "Submit" ); + + clickLinkWithText("Logout"); + login(username, getUserRolePassword()); + changePassword( getUserRolePassword(), getUserRoleNewPassword()); + + // this section will be removed if issue from redback after changing password will be fixed. + getSelenium().goBack(); + clickLinkWithText("Logout"); + //assertTextPresent("You are already logged in."); + + login(username, getUserRoleNewPassword()); + assertLeftNavMenuWithRole( fullname ); + clickLinkWithText("Logout"); + } + + @Test (dependsOnMethods = { "testUserWithGlobalRepoObserverRole" } ) + public void testUserWithRepoObserverSnapshotsRole() + { + username = p.getProperty( "REPOOBSERVER_SNAPSHOTS_USERNAME" ); + fullname = p.getProperty( "REPOOBSERVER_SNAPSHOTS_FULLNAME" ); + + createUser(username, fullname, getUserEmail(), getUserRolePassword(), true); + clickLinkWithText( username ); + clickLinkWithText( "Edit Roles" ); + checkResourceRoleWithValue( fullname ); + clickButtonWithValue( "Submit" ); + + clickLinkWithText("Logout"); + login(username, getUserRolePassword()); + changePassword( getUserRolePassword(), getUserRoleNewPassword()); + + // this section will be removed if issue from redback after changing password will be fixed. + getSelenium().goBack(); + clickLinkWithText("Logout"); + //assertTextPresent("You are already logged in."); + + login(username, getUserRoleNewPassword()); + assertLeftNavMenuWithRole( fullname ); + clickLinkWithText("Logout"); + } +} diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/XPathExpressionUtil.java b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/XPathExpressionUtil.java new file mode 100644 index 000000000..8802512ad --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/XPathExpressionUtil.java @@ -0,0 +1,245 @@ +package org.apache.archiva.web.test; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * Utility class for creating xpath expressions + */ +public class XPathExpressionUtil +{ + public static final String CONTAINS = "contains"; + + public static final String AND = " and "; + + public static final String CURRENT_NODE = "./"; + + public static final String PARENT_NODE = "../"; + + public static final String GRANDPARENT_NODE = "../../"; + + public static final String ELEMENT_ANY_LEVEL = "//"; + + public static final String TABLE_COLUMN = "td"; + + public static final String TABLE_ROW = "tr"; + + public static final String START_NODE_TEST = "["; + + public static final String END_NODE_TEST = "]"; + + public static final String ANCHOR = "a"; + + public static final String IMG = "img"; + + public static final String LIST = "ul"; + + public static final String LINE = "li"; + + public static String getList( String[] values ) + { + String xpathExpression = ""; + + if ( values.length > 0 ) + { + xpathExpression += ELEMENT_ANY_LEVEL; + xpathExpression += LIST; + xpathExpression += START_NODE_TEST; + + for (int nIndex = 0; nIndex < values.length; nIndex++ ) + { + xpathExpression += ( ( nIndex > 0 ) ? AND : "" ); + xpathExpression += contains( LINE + position( nIndex + 1 ), values[nIndex] ); + } + + xpathExpression += END_NODE_TEST; + } + + return xpathExpression; + } + + /** + * expression for acquiring an element in one of the table columns + * + * @param element the node element + * @param elementIndex column index of the element, used for skipping + * @param columnValues the values to be matched in each column, element column is included + * @return + */ + public static String getColumnElement( String element, int elementIndex, String[] columnValues ) + { + return getColumnElement( element, elementIndex, null, columnValues ); + } + + /** + * expression for acquiring an element in one of the table columns + * + * @param element the node element + * @param elementIndex column index of the element, used for skipping + * @param elementValue the matched element value + * @param columnValues the values to be matched in each column, element column is included + * @return + */ + public static String getColumnElement( String element, int elementIndex, String elementValue, + String[] columnValues ) + { + return getColumnElement( element, elementIndex, elementValue, "TEXT", columnValues ); + } + + /** + * expression for acquiring an element in one of the table columns + * + * @param element the node element + * @param elementIndex column index of the element, used for skipping + * @param imageName the matched image name + * @param columnValues the values to be matched in each column, element column is included + * @return + */ + public static String getImgColumnElement( String element, int elementIndex, String imageName, + String[] columnValues ) + { + return getColumnElement( element, elementIndex, imageName, IMG, columnValues ); + } + + /** + * expression for acquiring an element in one of the table columns + * + * @param element the node element + * @param elementIndex column index of the element, used for skipping + * @param imageName the matched image name + * @param columnValues the values to be matched in each column, element column is included + * @return + */ + private static String getColumnElement( String element, int elementIndex, String elementValue, + String elementValueType, String[] columnValues ) + { + String xpathExpression = null; + + if ( ( columnValues != null ) && ( columnValues.length > 0 ) ) + { + xpathExpression = ELEMENT_ANY_LEVEL + element; + xpathExpression += START_NODE_TEST; + + if ( elementValue != null ) + { + if ( "TEXT".equals( elementValueType ) ) + { + xpathExpression += contains( elementValue ); + xpathExpression += ( columnValues.length > 0 ) ? AND : ""; + } + } + + // we are two levels below the table row element ( tr/td/ ) + xpathExpression += matchColumns( GRANDPARENT_NODE, columnValues, elementIndex ); + + xpathExpression += END_NODE_TEST; + } + + if ( IMG.equals( elementValueType ) ) + { + xpathExpression += "/img[contains(@src, '" + elementValue + "')]"; + } + + return xpathExpression; + } + + /** + * expression for acquiring the table row that matches all column values with the same order + * as the list + * + * @param columnValues the matched list of columnValues + * @return + */ + public static String getTableRow( String[] columnValues ) + { + String xpathExpression = null; + + if ( ( columnValues != null ) && ( columnValues.length > 0 ) ) + { + xpathExpression = new String( ELEMENT_ANY_LEVEL + TABLE_ROW + START_NODE_TEST ); + xpathExpression += matchColumns( columnValues ); + xpathExpression += END_NODE_TEST; + } + + return xpathExpression; + } + + private static String matchColumns( String[] columnValues ) + { + return matchColumns( columnValues, -1 ); + } + + private static String matchColumns( String[] columnValues, int skipIndex ) + { + return matchColumns( null, columnValues, skipIndex ); + } + + private static String matchColumns( String parent, String[] columnValues, int skipIndex ) + { + String xpathExpression = ""; + + for ( int nIndex = 0; nIndex < columnValues.length; nIndex++ ) + { + if ( ( skipIndex != nIndex ) || ( skipIndex == -1 ) ) + { + // prepend "and" if index > 0 + xpathExpression += ( ( nIndex > 0 ) ? AND : "" ); + xpathExpression += contains( parent, TABLE_COLUMN + position( nIndex + 1 ), columnValues[nIndex] ); + } + } + + return xpathExpression; + } + + private static String position( int nIndex ) + { + return new String( "[" + nIndex + "]" ); + } + + private static String contains( String parent, String element, String matchedString ) + { + String finalElement = ( parent != null ) ? parent : ""; + finalElement += element; + + return contains( finalElement, matchedString ); + } + + private static String contains( String matchedString ) + { + return contains( ".", matchedString ); + } + + private static String contains( String axis, String matchedString ) + { + return new String( CONTAINS + "(" + axis + "," + "'" + matchedString + "')" ); + } + + private static String equals( String parent, String element, String matchedString ) + { + String finalElement = ( parent != null ) ? parent : ""; + finalElement += element; + + return equals( finalElement, matchedString ); + } + + private static String equals( String axis, String matchedString ) + { + return new String( axis + "==" + "'" + matchedString + "'" ); + } +} \ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractArchivaTest.java b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractArchivaTest.java index ea4359ae0..c36512a56 100644 --- a/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractArchivaTest.java +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractArchivaTest.java @@ -1,5 +1,9 @@ package org.apache.archiva.web.test.parent; +import java.io.File; + +import org.apache.archiva.web.test.XPathExpressionUtil; + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -22,7 +26,51 @@ package org.apache.archiva.web.test.parent; public abstract class AbstractArchivaTest extends AbstractSeleniumTest { + protected String username; + protected String fullname; + + public String getUserEmail() + { + String email = p.getProperty("USERROLE_EMAIL"); + return email; + } + + public String getUserRolePassword() + { + String password = p.getProperty("USERROLE_PASSWORD"); + return password; + } + + public String getUserRoleNewPassword() + { + String password_new = p.getProperty( "NEW_USERROLE_PASSWORD" ); + return password_new; + } + + public String getBasedir() + { + String basedir = System.getProperty( "basedir" ); + + if ( basedir == null ) + { + basedir = new File( "" ).getAbsolutePath(); + } + return basedir; + } + + public String getAdminUsername() + { + String adminUsername = p.getProperty( "ADMIN_USERNAME" ); + return adminUsername; + } + + public String getAdminPassword() + { + String adminPassword = p.getProperty( "ADMIN_PASSWORD" ); + return adminPassword; + } + public void assertCreateAdmin() { assertPage( "Apache Archiva \\ Create Admin User" ); @@ -104,27 +152,6 @@ public abstract class AbstractArchivaTest } -/* //Find Artifact - public void goToFindArtifactPage() - { - clickLinkWithText( "Find Artifact" ); - assertFindArtifactPage(); - } - - public void assertFindArtifactPage() - { - //assertPage( "Apache Archiva \\ Find Artifact" ); - assertTextPresent( "Find Artifact" ); - assertTextPresent( "Search For" ); - assertElementPresent( "f" ); - assertTextPresent( "Checksum" ); - assertElementPresent( "q" ); - assertButtonWithValuePresent( "Search" ); - 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. " ); - assertTextPresent( "Tï scan a local file, select the file you would like to locate in the remote repository. Ôhe entire file will not be uploaded$to the server. See the progress bar below for progress of locally creating a checksum that is uploaded to the server ifter you hit "); - } - - //User Management public void goToUserManagementPage() { @@ -134,7 +161,7 @@ public abstract class AbstractArchivaTest public void assertUserManagementPage() { - //assertPage( "Apache Archiva \\ [Admin] User List" ); + assertPage( "Apache Archiva \\ [Admin] User List" ); assertTextPresent( "[Admin] List of Users in Role: Any" ); assertTextPresent( "Navigation" ); assertImgWithAlt( "First" ); @@ -162,23 +189,240 @@ public abstract class AbstractArchivaTest assertTextPresent( "Roles Matrix" ); } - //User Role +/* //User Role public void goToUserRolesPage() { clickLinkWithText( "User Roles" ); assertUserRolesPage(); - } + }*/ public void assertUserRolesPage() { - //assertPage( "Apache Archiva \\ [Admin] Role List" ); - assertTextPresent( "[Admin] Role List" ); - assertTextPresent( "Role Name" ); - assertTextPresent( "Role Description" ); - String userRoles = "Guest,Registered User,System Administrator,User Administrator,Global Repository Observer,Archiva Guest,Archiva System Administrator,Global Repository Manager,Archiva User Administrator,Repository Observer - internal,Repository Manager - internal,Repository Observer - snapshots,Repository Manager - snapshots"; + assertPage( "Apache Archiva \\ [Admin] User Edit" ); + assertTextPresent( "[Admin] User Roles" ); + assertTextPresent( "Username" ); + assertTextPresent( "Full Name" ); + String userRoles = "Guest,Registered User,System Administrator,User Administrator,Global Repository Observer,Global Repository Manager,Repository Observer,Repository Manager,internal,snapshots"; String[] arrayRole = userRoles.split( "," ); for ( String userroles : arrayRole ) - assertLinkPresent( userroles ); + assertTextPresent( userroles ); + } + + public void assertDeleteUserPage( String username ) + { + assertPage( "Apache Archiva \\ [Admin] User Delete" ); //TODO + assertTextPresent( "[Admin] User Delete" ); + assertTextPresent( "The following user will be deleted:" ); + assertTextPresent( "Username: " + username ); + assertButtonWithValuePresent( "Delete User" ); + } + + public void createUser( String userName, String fullName, String email, String password, boolean valid ) + { + createUser( userName, fullName, email, password, password, valid ); + } + + private void createUser( String userName, String fullName, String emailAd, String password, String confirmPassword, boolean valid ) + { + login( getAdminUsername() , getAdminPassword() ); + clickLinkWithText( "User Management" ); + clickButtonWithValue( "Create New User" ); + assertCreateUserPage(); + setFieldValue( "user.username", userName ); + setFieldValue( "user.fullName", fullName ); + setFieldValue( "user.email", emailAd ); + setFieldValue( "user.password", password ); + setFieldValue( "user.confirmPassword", confirmPassword ); + submit(); + + assertUserRolesPage( ); + clickButtonWithValue( "Submit" ); + + if (valid ) + { + String[] columnValues = {userName, fullName, emailAd}; + assertElementPresent( XPathExpressionUtil.getTableRow( columnValues ) ); + } + else + { + assertCreateUserPage(); + } + } + + public void deleteUser( String userName, String fullName, String emailAdd ) + { + deleteUser( userName, fullName, emailAdd, false, false ); + } + + public void deleteUser(String userName, String fullName, String emailAd, boolean validated, boolean locked) + { + String[] columnValues = {userName, fullName, emailAd}; + //clickLinkWithText( "userlist" ); + clickLinkWithXPath( "//table[@id='ec_table']/tbody[2]/tr[3]/td[7]/a/img" ); + assertDeleteUserPage( userName ); + submit(); + assertElementNotPresent( XPathExpressionUtil.getTableRow( columnValues ) ); + } + + public void login( String username, String password ) + { + login( username, password, true, "Login Page" ); + } + + public void login( String username, String password, boolean valid, String assertReturnPage ) + { + if ( isLinkPresent( "Login" ) ) + { + goToLoginPage(); + + submitLoginPage( username, password, false, valid, assertReturnPage ); + } + } + + public void submitLoginPage( String username, String password ) + { + submitLoginPage( username, password, false, true, "Login Page" ); + } + + public void submitLoginPage( String username, String password, boolean validUsernamePassword ) + { + submitLoginPage( username, password, false, validUsernamePassword, "Login Page" ); + } + + public void submitLoginPage( String username, String password, boolean rememberMe, boolean validUsernamePassword, + String assertReturnPage ) + { + assertLoginPage(); + setFieldValue( "username", username ); + setFieldValue( "password", password ); + if ( rememberMe ) + { + checkField( "rememberMe" ); + } + clickButtonWithValue( "Login" ); + + if ( validUsernamePassword ) + { + assertTextPresent( "Current User:" ); + assertTextPresent( username ); + assertLinkPresent( "Edit Details" ); + assertLinkPresent( "Logout" ); + } + else + { + if ( "Login Page".equals( assertReturnPage ) ) + { + assertLoginPage(); + } + else + { + assertPage( assertReturnPage ); + } + } + } + + // User Roles + public void assertUserRoleCheckBoxPresent(String value) + { + getSelenium() .isElementPresent("xpath=//input[@id='addRolesToUser_addNDSelectedRoles' and @name='addNDSelectedRoles' and @value='" + value + "']"); + } + + public void assertResourceRolesCheckBoxPresent(String value) { + getSelenium().isElementPresent("xpath=//input[@name='addDSelectedRoles' and @value='" + value + "']"); + } + + public void checkUserRoleWithValue(String value) + { + assertUserRoleCheckBoxPresent(value); + getSelenium().click( "xpath=//input[@id='addRolesToUser_addNDSelectedRoles' and @name='addNDSelectedRoles' and @value='" + value + "']"); + } + + public void checkResourceRoleWithValue(String value) + { + assertResourceRolesCheckBoxPresent(value); + getSelenium().click( "xpath=//input[@name='addDSelectedRoles' and @value='" + value + "']" ); + } + + + public void changePassword(String oldPassword, String newPassword) { + assertPage("Apache Archiva \\ Change Password"); + setFieldValue("existingPassword", oldPassword); + setFieldValue("newPassword", newPassword); + setFieldValue("newPasswordConfirm", newPassword); + clickButtonWithValue("Change Password"); + } + + public void assertCreateUserPage() + { + assertPage( "Apache Archiva \\ [Admin] User Create" ); + assertTextPresent( "[Admin] User Create" ); + assertTextPresent( "Username*:" ); + assertElementPresent( "user.username" ); + assertTextPresent( "Full Name*:"); + assertElementPresent( "user.fullName" ); + assertTextPresent( "Email Address*:" ); + assertElementPresent( "user.email" ); + assertTextPresent( "Password*:" ); + assertElementPresent( "user.password" ); + assertTextPresent( "Confirm Password*:" ); + assertElementPresent( "user.confirmPassword" ); + assertButtonWithValuePresent( "Create User" ); + } + + public void assertLeftNavMenuWithRole( String role ) + { + if ( role.equals( "Guest" ) || role.equals( "Registered User" ) || role.equals( "Global Repository Observer" ) || role.equals( "Repository Observer - internal" ) || role.equals( "Repository Observer - snapshots" ) ) + { + assertTextPresent( "Search" ); + assertLinkPresent( "Find Artifact" ); + assertLinkPresent( "Browse" ); + assertLinkNotPresent( "Repositories" ); + } + else if ( role.equals( "User Administrator" ) ) + { + assertTextPresent( "Search" ); + assertLinkPresent( "Find Artifact" ); + assertLinkPresent( "Browse" ); + assertLinkPresent( "User Management" ); + assertLinkPresent( "User Roles" ); + assertLinkNotPresent( "Repositories" ); + } + else if ( role.equals( "Global Repository Manager" ) || role.equals( "Repository Manager - internal" ) || role.equals( "Repository Manager - snapshots" ) ) + { + assertTextPresent( "Search" ); + assertLinkPresent( "Find Artifact" ); + assertLinkPresent( "Browse" ); + assertLinkPresent( "Upload Artifact" ); + assertLinkPresent( "Delete Artifact" ); + assertLinkNotPresent( "Repositories" ); + } + else + { + assertTextPresent( "Search" ); + 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,Database"; + String[] arrayMenu = navMenu.split( "," ); + for (String navmenu : arrayMenu ) + assertLinkPresent( navmenu ); + } + } +/* //Find Artifact + public void goToFindArtifactPage() + { + clickLinkWithText( "Find Artifact" ); + assertFindArtifactPage(); + } + + public void assertFindArtifactPage() + { + //assertPage( "Apache Archiva \\ Find Artifact" ); + assertTextPresent( "Find Artifact" ); + assertTextPresent( "Search For" ); + assertElementPresent( "f" ); + assertTextPresent( "Checksum" ); + assertElementPresent( "q" ); + assertButtonWithValuePresent( "Search" ); + 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. " ); + assertTextPresent( "Tï scan a local file, select the file you would like to locate in the remote repository. Ôhe entire file will not be uploaded$to the server. See the progress bar below for progress of locally creating a checksum that is uploaded to the server ifter you hit "); } //Appearance @@ -219,4 +463,4 @@ public abstract class AbstractArchivaTest assertElementPresent( uploadelements ); assertButtonWithValuePresent( "Submit" ); } */ -} +} \ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractArtifactManagementTest.java b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractArtifactManagementTest.java new file mode 100644 index 000000000..64f95ea10 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractArtifactManagementTest.java @@ -0,0 +1,119 @@ +package org.apache.archiva.web.test.parent; + +public abstract class AbstractArtifactManagementTest + extends AbstractArchivaTest +{ + + public String getGroupId() + { + String groupId = p.getProperty( "GROUPID" ) ; + return groupId; + } + + public String getArtifactId() + { + String artifactId = p.getProperty( "GROUPID" ) ; + return artifactId; + } + + public String getVersion() + { + String version = p.getProperty( "VERSION" ) ; + return version; + } + + public String getPackaging() + { + String packaging = p.getProperty( "PACKAGING" ) ; + return packaging; + } + + public String getArtifactFilePath() + { + String artifactFilePath = p.getProperty( "ARTIFACTFILEPATH" ) ; + return artifactFilePath; + } + + public String getRepositoryId() + { + String repositoryId = p.getProperty( "REPOSITORYID" ) ; + return repositoryId; + } + + public void goToAddArtifactPage() + { + clickLinkWithText( "Upload Artifact" ); + assertAddArtifactPage(); + } + + public void goToDeleteArtifactPage() + { + clickLinkWithText( "Delete Artifact" ); + assertDeleteArtifactPage(); + } + + public void addArtifact( String groupId, String artifactId, String version, String packaging, String artifactFilePath, String repositoryId ) + { + addArtifact(groupId, artifactId, version, packaging, true, artifactFilePath, repositoryId); + } + + public void addArtifact( String groupId, String artifactId, String version, String packaging, boolean generatePom, String artifactFilePath, String repositoryId) + { + goToAddArtifactPage(); + setFieldValue( "groupId" , groupId ); + setFieldValue( "artifactId" , artifactId ); + setFieldValue( "version" , version ); + setFieldValue( "packaging" , packaging ); + + if ( generatePom ) + { + checkField( "generatePom" ); + } + + setFieldValue( "artifact" , artifactFilePath ); + setFieldValue( "repositoryId" , repositoryId ); + + clickButtonWithValue( "Submit" ); + } + + public void deleteArtifact( String groupId, String artifactId, String version, String repositoryId ) + { + goToAddArtifactPage(); + setFieldValue( "groupId" , groupId ); + setFieldValue( "artifactId" , artifactId ); + setFieldValue( "version" , version ); + selectValue( "repositoryId" , repositoryId ); + clickButtonWithValue( "Submit" ) ; + } + + public void assertAddArtifactPage() + { + assertPage( "Apache Archiva \\ Upload Artifact" ); + assertTextPresent( "Upload Artifact" ); + + String artifact = "Upload Artifact,Group Id*:,Artifact Id*:,Version*:,Packaging*:,Classifier:,Generate Maven 2 POM,Artifact File*:,POM File:,Repository Id:"; + String[] arrayArtifact = artifact.split( "," ); + for ( String arrayartifact : arrayArtifact ) + assertTextPresent( arrayartifact ); + + String artifactElements = "upload_groupId,upload_artifactId,upload_version,upload_packaging,upload_classifier,upload_generatePom,upload_artifact,upload_pom,upload_repositoryId,upload_0"; + String[] arrayArtifactElements = artifactElements.split( "," ); + for ( String artifactelements : arrayArtifactElements ) + assertElementPresent( artifactelements ); + } + + public void assertDeleteArtifactPage() + { + assertPage( "Apache Archiva \\ Delete Artifact" ); + assertTextPresent( "Delete Artifact" ); + assertTextPresent( "Group Id*:" ); + assertTextPresent( "Artifact Id*:" ); + assertTextPresent( "Version*:" ); + assertTextPresent( "Repository Id:" ); + assertElementPresent( "groupId" ); + assertElementPresent( "artifactId" ); + assertElementPresent( "version" ); + assertElementPresent( "repositoryId" ); + assertButtonWithValuePresent( "Submit" ); + } +} diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java index 2e79ad91b..f08b7428d 100644 --- a/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java @@ -137,7 +137,7 @@ public abstract class AbstractSeleniumTest { Assert.assertTrue( isElementPresent( "link=" + text ), "The link '" + text + "' isî't present." ); } - public void assertLinkNotPresenu( String text ) + public void assertLinkNotPresent( String text ) { Assert.assertFalse( isElementPresent( "link=" + text ), "The link('" + text + "' is present." ); } -- 2.39.5