* under the License.
*/
+import junit.framework.Assert;
import org.apache.archiva.web.test.parent.AbstractRepositoryTest;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
+import java.io.File;
+import java.io.IOException;
+
@Test( groups = { "repository" }, sequential = true )
public class RepositoryTest
extends AbstractRepositoryTest
public void tearDown()
{
goToRepositoriesPage();
- deleteManagedRepository( "managedrepo1", false );
- deleteManagedRepository( "managedrepo", false );
+ deleteManagedRepository( "managedrepo1", true, false );
+ deleteManagedRepository( "managedrepoedit", true, false );
deleteRemoteRepository( "remoterepo", false );
}
public void testAddManagedRepoValidValues()
- {
+ throws IOException
+ {
goToRepositoriesPage();
getSelenium().open( "/archiva/admin/addRepository.action" );
- addManagedRepository( "managedrepo1", "Managed Repository Sample 1" , getRepositoryDir() + "repository/" , "", "Maven 2.x Repository", "0 0 * * * ?", "", "" );
- clickButtonWithValue( "Save" );
- assertTextPresent( "Managed Repository Sample 1" );
+ File dir = new File( getRepositoryDir() + "repository/" );
+ if ( dir.exists() )
+ {
+ FileUtils.deleteDirectory( dir );
+ }
+ addManagedRepository( "managedrepo1", "Managed Repository Sample 1", dir.getAbsolutePath(), "",
+ "Maven 2.x Repository", "0 0 * * * ?", "", "" );
+ assertTextPresent( "Managed Repository Sample 1" );
assertRepositoriesPage();
- }
- @Test(dependsOnMethods = { "testAddManagedRepoValidValues" } )
+ Assert.assertTrue( dir.exists() && dir.isDirectory() );
+ }
+
public void testAddManagedRepoInvalidValues()
{
goToRepositoriesPage();
assertTextPresent( "Invalid cron expression." );
}
- @Test(dependsOnMethods = { "testAddManagedRepoInvalidValues" } )
public void testAddManagedRepoInvalidIdentifier()
{
addManagedRepository( "<> \\/~+[ ]'\"", "name" , "/home" , "/.index", "Maven 2.x Repository", "0 0 * * * ?", "1", "1" );
assertTextPresent( "Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-)." );
}
- @Test(dependsOnMethods = { "testAddManagedRepoInvalidIdentifier" } )
public void testAddManagedRepoInvalidRepoName()
{
addManagedRepository( "identifier", "<>\\~+[]'\"" , "/home" , "/.index", "Maven 2.x Repository", "0 0 * * * ?", "1", "1" );
assertTextPresent( "Repository Name must only contain alphanumeric characters, white-spaces(' '), forward-slashes(/), open-parenthesis('('), close-parenthesis(')'), underscores(_), dots(.), and dashes(-)." );
}
- @Test(dependsOnMethods = { "testAddManagedRepoInvalidRepoName" } )
public void testAddManagedRepoInvalidDirectory()
{
addManagedRepository( "identifier", "name" , "<> ~+[ ]'\"" , "/.index", "Maven 2.x Repository", "0 0 * * * ?", "1", "1" );
assertTextPresent( "Directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
}
- @Test(dependsOnMethods = { "testAddManagedRepoInvalidDirectory" } )
public void testAddManagedRepoInvalidIndexDir()
{
addManagedRepository( "identifier", "name" , "/home" , "<> ~+[ ]'\"", "Maven 2.x Repository", "0 0 * * * ?", "1", "1" );
assertTextPresent( "Index directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
}
- @Test(dependsOnMethods = { "testAddManagedRepoInvalidIndexDir" } )
public void testAddManagedRepoInvalidRetentionCount()
{
addManagedRepository( "identifier", "name" , "/home" , "/.index", "Maven 2.x Repository", "0 0 * * * ?", "1", "101" );
assertTextPresent( "Repository Purge By Retention Count needs to be between 1 and 100." );
}
- @Test(dependsOnMethods = { "testAddManagedRepoInvalidRetentionCount" } )
public void testAddManagedRepoInvalidDaysOlder()
{
addManagedRepository( "identifier", "name" , "/home" , "/.index", "Maven 2.x Repository", "0 0 * * * ?", "-1", "1" );
assertTextPresent( "Repository Purge By Days Older Than needs to be larger than 0." );
}
- @Test(dependsOnMethods = { "testAddManagedRepoInvalidDaysOlder" } )
public void testAddManagedRepoBlankValues()
{
goToRepositoriesPage();
assertTextPresent( "Invalid cron expression." );
}
- @Test(dependsOnMethods = { "testAddManagedRepoBlankValues" } )
public void testAddManagedRepoNoIdentifier()
{
- addManagedRepository( "", "name" , "/home" , "/.index", "Maven 2.x Repository", "0 0 * * * ?", "", "" );
+ addManagedRepository( "", "name", "/home", "/.index", "Maven 2.x Repository", "0 0 * * * ?", "", "" );
assertTextPresent( "You must enter a repository identifier." );
}
- @Test(dependsOnMethods = { "testAddManagedRepoNoIdentifier" } )
public void testAddManagedRepoNoRepoName()
{
addManagedRepository( "identifier", "" , "/home" , "/.index", "Maven 2.x Repository", "0 0 * * * ?", "", "" );
assertTextPresent( "You must enter a repository name." );
}
- @Test(dependsOnMethods = { "testAddManagedRepoNoRepoName" } )
public void testAddManagedRepoNoDirectory()
{
addManagedRepository( "identifier", "name" , "" , "/.index", "Maven 2.x Repository", "0 0 * * * ?", "", "" );
assertTextPresent( "You must enter a directory." );
}
- @Test(dependsOnMethods = { "testAddManagedRepoNoDirectory" } )
public void testAddManagedRepoNoCron()
{
addManagedRepository( "identifier", "name" , "/home" , "/.index", "Maven 2.x Repository", "", "", "" );
assertTextPresent( "Invalid cron expression." );
}
- @Test(dependsOnMethods = { "testAddManagedRepoNoCron" } )
- public void testAddManagedRepoForEdit()
- {
- goToRepositoriesPage();
- clickLinkWithText( "Add" );
- addManagedRepository( "managedrepo", "Managed Repository Sample" , getRepositoryDir() + "local-repo/", "", "Maven 2.x Repository", "0 0 * * * ?", "", "" );
- clickButtonWithValue( "Save" );
- assertTextPresent( "Managed Repository Sample" );
- }
+ public void testEditManagedRepo()
+ throws IOException
+ {
+ goToRepositoriesPage();
+ clickLinkWithText( "Add" );
+ String directory = getRepositoryDir() + "local-repo/";
+ File dir = new File( directory );
+ if ( dir.exists() )
+ {
+ FileUtils.deleteDirectory( dir );
+ }
+ addManagedRepository( "managedrepoedit", "Managed Repository for Editing", directory, "",
+ "Maven 2.x Repository", "0 0 * * * ?", "", "" );
- @Test(dependsOnMethods = { "testAddManagedRepoForEdit" } )
- public void testEditManagedRepoInvalidValues()
+ editManagedRepository( "repository.name" , "New Managed Repo Name" );
+ assertTextNotPresent( "Managed Repository for Editing" );
+ assertTextPresent( "New Managed Repo Name" );
+ }
+
+ public void testEditManagedRepoInvalidValues()
{
editManagedRepository("<>\\~+[]'\"" , "<> ~+[ ]'\"" , "<> ~+[ ]'\"", "Maven 2.x Repository", "", "-1", "101");
assertTextPresent( "Directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
assertTextPresent( "Invalid cron expression." );
}
- @Test(dependsOnMethods = { "testEditManagedRepoInvalidValues" } )
public void testEditManagedRepoInvalidRepoName()
{
editManagedRepository("<>\\~+[]'\"" , "/home" , "/.index", "Maven 2.x Repository", "0 0 * * * ?", "1", "1");
assertTextPresent( "Repository Name must only contain alphanumeric characters, white-spaces(' '), forward-slashes(/), open-parenthesis('('), close-parenthesis(')'), underscores(_), dots(.), and dashes(-)." );
}
- @Test(dependsOnMethods = { "testEditManagedRepoInvalidRepoName" } )
public void testEditManagedRepoInvalidDirectory()
{
editManagedRepository("name" , "<> ~+[ ]'\"" , "/.index", "Maven 2.x Repository", "0 0 * * * ?", "1", "1");
assertTextPresent( "Directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
}
- @Test(dependsOnMethods = { "testEditManagedRepoInvalidDirectory" } )
public void testEditManagedRepoInvalidIndexDir()
{
editManagedRepository("name" , "/home" , "<> ~+[ ]'\"", "Maven 2.x Repository", "0 0 * * * ?", "1", "1");
assertTextPresent( "Index directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
}
- @Test(dependsOnMethods = { "testEditManagedRepoInvalidIndexDir" } )
public void testEditManagedRepoInvalidCron()
{
editManagedRepository("name" , "/home" , "/.index", "Maven 2.x Repository", "", "1", "1");
assertTextPresent( "Invalid cron expression." );
}
- @Test(dependsOnMethods = { "testEditManagedRepoInvalidCron" } )
public void testEditManagedRepoInvalidRetentionCount()
{
editManagedRepository("name" , "/home" , "/.index", "Maven 2.x Repository", "0 0 * * * ?", "1", "101");
assertTextPresent( "Repository Purge By Retention Count needs to be between 1 and 100." );
}
- @Test(dependsOnMethods = { "testEditManagedRepoInvalidRetentionCount" } )
public void testEditManagedRepoInvalidDaysOlder()
{
editManagedRepository("name" , "/home" , "/.index", "Maven 2.x Repository", "0 0 * * * ?", "-1", "1");
assertTextPresent( "Repository Purge By Days Older Than needs to be larger than 0." );
}
- //TODO
- @Test(dependsOnMethods = { "testEditManagedRepoInvalidDaysOlder" } )
- public void testEditManagedRepo()
- {
- editManagedRepository( "repository.name" , "Managed Repo" );
- assertTextPresent( "Managed Repository Sample" );
- }
+ public void testDeleteManagedRepo()
+ throws IOException
+ {
+ goToRepositoriesPage();
+ clickLinkWithText( "Add" );
+ File dir = new File( getRepositoryDir() + "managedrepodelete/" );
+ if ( dir.exists() )
+ {
+ FileUtils.deleteDirectory( dir );
+ }
+ addManagedRepository( "managedrepodelete", "Managed Repository for Deleting", dir.getAbsolutePath(), "",
+ "Maven 2.x Repository", "0 0 * * * ?", "", "" );
- //TODO
- @Test(dependsOnMethods = { "testEditManagedRepo" } )
- public void testDeleteManageRepo()
- {
- deleteManagedRepository( "managedrepo", true );
- }
+ deleteManagedRepository( "managedrepodelete", false, true );
+
+ // assert removed, but contents remain
+ assertRepositoriesPage();
+ assertTextNotPresent( "managedrepodelete" );
+
+ Assert.assertTrue( dir.exists() && dir.isDirectory() );
+ }
+
+ public void testDeleteManagedRepoWithContents()
+ throws IOException
+ {
+ goToRepositoriesPage();
+ clickLinkWithText( "Add" );
+ File dir = new File( getRepositoryDir() + "managedrepodeletecontents/" );
+ if ( dir.exists() )
+ {
+ FileUtils.deleteDirectory( dir );
+ }
+ addManagedRepository( "managedrepodeletecontents", "Managed Repository for Deleting", dir.getAbsolutePath(), "",
+ "Maven 2.x Repository", "0 0 * * * ?", "", "" );
+
+ deleteManagedRepository( "managedrepodeletecontents", true, true );
+
+ // assert removed, but contents remain
+ assertRepositoriesPage();
+ assertTextNotPresent( "managedrepodeletecontents" );
+
+ Assert.assertFalse( dir.exists() );
+ }
- @Test(dependsOnMethods = { "testAddRemoteRepoValidValues" } )
public void testAddRemoteRepoNullValues()
{
- getSelenium().open( "/archiva/admin/addRemoteRepository.action" );
addRemoteRepository( "" , "" , "" , "" , "" , "" , "Maven 2.x Repository" );
assertTextPresent( "You must enter a repository identifier." );
assertTextPresent( "You must enter a repository name." );
assertTextPresent( "You must enter a url." );
}
- @Test(dependsOnMethods = { "testAddRemoteRepoNullValues" } )
public void testAddRemoteRepositoryNullIdentifier()
{
addRemoteRepository( "" , "Remote Repository Sample" , "http://repository.codehaus.org/org/codehaus/mojo/" , "" , "" , "" , "Maven 2.x Repository" );
assertTextPresent( "You must enter a repository identifier." );
}
- @Test(dependsOnMethods = { "testAddRemoteRepositoryNullIdentifier" } )
public void testAddRemoteRepoNullName()
{
- addRemoteRepository( "remoterepo" , "" , "http://repository.codehaus.org/org/codehaus/mojo/" , "" , "" , "" , "Maven 2.x Repository" );
+ addRemoteRepository( "remotenullrepo" , "" , "http://repository.codehaus.org/org/codehaus/mojo/" , "" , "" , "" , "Maven 2.x Repository" );
assertTextPresent( "You must enter a repository name." );
}
- @Test(dependsOnMethods = { "testAddRemoteRepoNullName" } )
public void testAddRemoteRepoNullURL()
{
- addRemoteRepository( "remoterepo" , "Remote Repository Sample" , "" , "" , "" , "" , "Maven 2.x Repository" );
+ addRemoteRepository( "remotenullrepo" , "Remote Repository Sample" , "" , "" , "" , "" , "Maven 2.x Repository" );
assertTextPresent( "You must enter a url." );
}
- @Test(dependsOnMethods = { "testDeleteManageRepo" } )
public void testAddRemoteRepoValidValues()
{
getSelenium().open( "/archiva/admin/addRemoteRepository.action" );