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;
public class RepositoryTest
extends AbstractRepositoryTest
{
+
+ public static final String DELETE_CONFIGURATION_AND_CONTENTS = "Delete Configuration and Contents";
+
@BeforeTest
public void setUp()
{
public void tearDown()
{
goToRepositoriesPage();
- deleteManagedRepository( "managedrepo1", true, false );
- deleteManagedRepository( "managedrepo2", true, false );
- deleteManagedRepository( "managedrepoedit", true, false );
+ deleteManagedRepository( "managedrepo1", false, DELETE_CONFIGURATION_AND_CONTENTS );
+ deleteManagedRepository( "managedrepo2", false, DELETE_CONFIGURATION_AND_CONTENTS );
+ deleteManagedRepository( "managedrepoedit", false, DELETE_CONFIGURATION_AND_CONTENTS );
deleteRemoteRepository( "remoterepo", false );
+ deleteRemoteRepository( "remoterepoedit", false );
}
public void testAddManagedRepoValidValues()
public void testDeleteManagedRepo()
throws IOException
{
- File dir = new File( getRepositoryDir() + "managedrepodelete/" );
+ File dir = new File( getRepositoryDir() + "managedrepodeleteconfig/" );
if ( dir.exists() )
{
FileUtils.deleteDirectory( dir );
}
- addManagedRepository( "managedrepodelete", "Managed Repository for Deleting", dir.getAbsolutePath(), "",
+ addManagedRepository( "managedrepodeleteconfig", "Managed Repository for Deleting", dir.getAbsolutePath(), "",
"Maven 2.x Repository", "0 0 * * * ?", "", "" );
- deleteManagedRepository( "managedrepodelete", false, true );
+ deleteManagedRepository( "managedrepodeleteconfig", true, "Delete Configuration Only" );
// assert removed, but contents remain
assertRepositoriesPage();
- assertTextNotPresent( "managedrepodelete" );
+ assertTextNotPresent( "managedrepodeleteconfig" );
+
+ Assert.assertTrue( dir.exists() && dir.isDirectory() );
+ }
+
+ public void testDeleteManagedRepoCancel()
+ throws IOException
+ {
+ File dir = new File( getRepositoryDir() + "managedrepodeletecancel/" );
+
+ goToRepositoriesPage();
+ if ( !isTextPresent( "managedrepodeletecancel" ) )
+ {
+ if ( dir.exists() )
+ {
+ FileUtils.deleteDirectory( dir );
+ }
+
+ addManagedRepository( "managedrepodeletecancel", "Managed Repository for Deleting", dir.getAbsolutePath(),
+ "", "Maven 2.x Repository", "0 0 * * * ?", "", "" );
+ }
+ deleteManagedRepository( "managedrepodeletecancel", true, "Cancel" );
+
+ assertRepositoriesPage();
+ assertTextPresent( "managedrepodeletecancel" );
Assert.assertTrue( dir.exists() && dir.isDirectory() );
}
addManagedRepository( "managedrepodeletecontents", "Managed Repository for Deleting", dir.getAbsolutePath(), "",
"Maven 2.x Repository", "0 0 * * * ?", "", "" );
- deleteManagedRepository( "managedrepodeletecontents", true, true );
+ deleteManagedRepository( "managedrepodeletecontents", true, DELETE_CONFIGURATION_AND_CONTENTS );
- // assert removed, but contents remain
assertRepositoriesPage();
assertTextNotPresent( "managedrepodeletecontents" );
public void testAddRemoteRepositoryNullIdentifier()
{
- addRemoteRepository( "" , "Remote Repository Sample" , "http://repository.codehaus.org/org/codehaus/mojo/" , "" , "" , "" , "Maven 2.x Repository" );
+ addRemoteRepository( "", "Remote Repository Sample", "http://repository.codehaus.org/org/codehaus/mojo/", "",
+ "", "", "Maven 2.x Repository" );
assertTextPresent( "You must enter a repository identifier." );
}
assertTextPresent( "Remote Repository Sample" );
}
+ public void testDeleteRemoteRepo()
+ {
+ addRemoteRepository( "remoterepodeleteconfirm", "Remote Repository for Deleting",
+ "https://repository.apache.org/", "", "", "", "Maven 2.x Repository" );
+ assertTextPresent( "Remote Repository for Deleting" );
+
+ deleteRemoteRepository( "remoterepodeleteconfirm", true );
+ assertRepositoriesPage();
+ assertTextNotPresent( "remoterepodeleteconfirm" );
+ }
+
+ public void testDeleteRemoteRepoCancel()
+ {
+ goToRepositoriesPage();
+ if ( !isTextPresent( "remoterepodeletecancel" ) )
+ {
+ addRemoteRepository( "remoterepodeletecancel", "Remote Repository for Deleting",
+ "https://repository.apache.org/", "", "", "", "Maven 2.x Repository" );
+ assertTextPresent( "Remote Repository for Deleting" );
+ }
+
+ deleteRemoteRepository( "remoterepodeletecancel", true, "Cancel" );
+ assertRepositoriesPage();
+ assertTextPresent( "remoterepodeletecancel" );
+ }
+
+ public void testEditRemoteRepo()
+ {
+ goToRepositoriesPage();
+ addRemoteRepository( "remoterepoedit", "Remote Repository for Editing",
+ "https://archiva-repository.apache.org/archiva/repository/all", "", "", "",
+ "Maven 2.x Repository" );
+ assertTextPresent( "Remote Repository for Editing" );
+
+ editRemoteRepository( "repository.name" , "New Remote Repo Name" );
+ assertRepositoriesPage();
+ assertTextNotPresent( "Remote Repository for Editing" );
+ assertTextPresent( "New Remote Repo Name" );
+ }
+
// *** BUNDLED REPOSITORY TEST ***
@Test ( dependsOnMethods = { "testWithCorrectUsernamePassword" }, alwaysRun = true )
}
public void deleteRemoteRepository( String id, boolean validate )
+ {
+ deleteRemoteRepository( id, validate, "Confirm" );
+ }
+
+ public void deleteRemoteRepository( String id, boolean validate, String option )
{
goToRepositoriesPage();
String xpath = "//div[@id='contentArea']//a[contains(@href,'confirmDeleteRemoteRepository.action?repoid=" + id + "')]";
{
clickLinkWithXPath( xpath );
assertDeleteRemoteRepositoryPage();
- clickButtonWithValue( "Confirm" );
+ clickButtonWithValue( option );
}
}
public void editRemoteRepository( String fieldName, String value)
{
goToRepositoriesPage();
- clickLinkWithXPath( "//div[@id='contentArea']/div/div[8]/div[1]/a[1]" );
+ clickLinkWithXPath( getRepositoryXpath( "remoterepoedit" ) + "//a[contains(text(),'Edit')]" );
setFieldValue( fieldName, value );
clickButtonWithValue( "Update Repository" );
}
clickButtonWithValue( "Update Repository" );
}
- public void deleteManagedRepository( String id, boolean deleteContents, boolean validate )
+ public void deleteManagedRepository( String id, boolean validate, String option )
{
String xpath = "//div[@id='contentArea']//a[contains(@href,'confirmDeleteRepository.action?repoid=" + id + "')]";
if ( validate || isElementPresent( "xpath=" + xpath ) )
{
clickLinkWithXPath( xpath );
assertPage( "Apache Archiva \\ Admin: Delete Managed Repository" );
- if ( deleteContents )
- {
- clickButtonWithValue( "Delete Configuration and Contents" );
- }
- else
- {
- clickButtonWithValue( "Delete Configuration Only" );
- }
+ clickButtonWithValue( option );
}
}