added unit tests for repository archive

This commit is contained in:
Sebastian Sdorra
2013-01-29 21:02:37 +01:00
parent 65c80b14fb
commit 60da1465d5
2 changed files with 79 additions and 4 deletions

View File

@@ -37,6 +37,7 @@ package sonia.scm.repository;
import org.junit.Test; import org.junit.Test;
import sonia.scm.Manager;
import sonia.scm.ManagerTestBase; import sonia.scm.ManagerTestBase;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@@ -55,6 +56,17 @@ public abstract class RepositoryManagerTestBase
extends ManagerTestBase<Repository, RepositoryException> extends ManagerTestBase<Repository, RepositoryException>
{ {
/**
* Method description
*
*
* @param archiveEnabled
*
* @return
*/
protected abstract RepositoryManager createRepositoryManager(
boolean archiveEnabled);
/** /**
* Method description * Method description
* *
@@ -96,11 +108,20 @@ public abstract class RepositoryManagerTestBase
@Test @Test
public void testDelete() throws RepositoryException, IOException public void testDelete() throws RepositoryException, IOException
{ {
Repository heartOfGold = createTestRepository(); delete(manager, createTestRepository());
String id = heartOfGold.getId(); }
manager.delete(heartOfGold); /**
assertNull(manager.get(id)); * Method description
*
*
* @throws IOException
* @throws RepositoryException
*/
@Test(expected = RepositoryIsNotArchivedException.class)
public void testDeleteNonArchived() throws RepositoryException, IOException
{
delete(createRepositoryManager(true), createTestRepository());
} }
/** /**
@@ -116,6 +137,23 @@ public abstract class RepositoryManagerTestBase
manager.delete(createRepositoryWithId()); manager.delete(createRepositoryWithId());
} }
/**
* Method description
*
*
* @throws IOException
* @throws RepositoryException
*/
@Test
public void testDeleteWithEnabledArchive()
throws RepositoryException, IOException
{
Repository repository = createTestRepository();
repository.setArchived(true);
delete(createRepositoryManager(true), repository);
}
/** /**
* Method description * Method description
* *
@@ -336,4 +374,24 @@ public abstract class RepositoryManagerTestBase
{ {
return createRepository(RepositoryTestData.createHeartOfGold()); return createRepository(RepositoryTestData.createHeartOfGold());
} }
/**
* Method description
*
*
* @param manager
* @param repository
*
* @throws IOException
* @throws RepositoryException
*/
private void delete(Manager<Repository, RepositoryException> manager,
Repository repository)
throws RepositoryException, IOException
{
String id = repository.getId();
manager.delete(repository);
assertNull(manager.get(id));
}
} }

View File

@@ -120,6 +120,21 @@ public class DefaultRepositoryManagerTest extends RepositoryManagerTestBase
*/ */
@Override @Override
protected DefaultRepositoryManager createManager() protected DefaultRepositoryManager createManager()
{
return createRepositoryManager(false);
}
/**
* Method description
*
*
* @param archiveEnabled
*
* @return
*/
@Override
protected DefaultRepositoryManager createRepositoryManager(
boolean archiveEnabled)
{ {
Set<RepositoryHandler> handlerSet = new HashSet<RepositoryHandler>(); Set<RepositoryHandler> handlerSet = new HashSet<RepositoryHandler>();
StoreFactory factory = new JAXBStoreFactory(); StoreFactory factory = new JAXBStoreFactory();
@@ -155,6 +170,8 @@ public class DefaultRepositoryManagerTest extends RepositoryManagerTestBase
ScmConfiguration configuration = new ScmConfiguration(); ScmConfiguration configuration = new ScmConfiguration();
configuration.setEnableRepositoryArchive(archiveEnabled);
return new DefaultRepositoryManager(configuration, contextProvider, return new DefaultRepositoryManager(configuration, contextProvider,
new DefaultKeyGenerator(), repositoryDAO, handlerSet, listenerProvider, new DefaultKeyGenerator(), repositoryDAO, handlerSet, listenerProvider,
hookProvider, createEmptyPreProcessorUtil()); hookProvider, createEmptyPreProcessorUtil());