mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-03-06 12:20:56 +01:00
Implemented persisting repositories according to namespace changes
Repository directories are now named after the repo's id instead of it's name
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* <p>
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
@@ -24,13 +24,11 @@
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* <p>
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
@@ -38,181 +36,118 @@ package sonia.scm.repository;
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.io.Resources;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.ConfigurationException;
|
||||
import sonia.scm.io.CommandResult;
|
||||
import sonia.scm.io.ExtendedCommand;
|
||||
import sonia.scm.io.FileSystem;
|
||||
import sonia.scm.store.ConfigurationStoreFactory;
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.net.URL;
|
||||
import sonia.scm.store.ConfigurationStoreFactory;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*
|
||||
*
|
||||
* @param <C>
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepositoryConfig>
|
||||
extends AbstractRepositoryHandler<C> implements RepositoryDirectoryHandler
|
||||
{
|
||||
extends AbstractRepositoryHandler<C> implements RepositoryDirectoryHandler {
|
||||
|
||||
/** Field description */
|
||||
public static final String DEFAULT_VERSION_INFORMATION = "unknown";
|
||||
|
||||
/** Field description */
|
||||
public static final String DIRECTORY_REPOSITORY = "repositories";
|
||||
|
||||
/** Field description */
|
||||
public static final String DOT = ".";
|
||||
|
||||
/** the logger for AbstractSimpleRepositoryHandler */
|
||||
/**
|
||||
* the logger for AbstractSimpleRepositoryHandler
|
||||
*/
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(AbstractSimpleRepositoryHandler.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
private FileSystem fileSystem;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param storeFactory
|
||||
* @param fileSystem
|
||||
*/
|
||||
public AbstractSimpleRepositoryHandler(ConfigurationStoreFactory storeFactory,
|
||||
FileSystem fileSystem)
|
||||
{
|
||||
FileSystem fileSystem) {
|
||||
super(storeFactory);
|
||||
this.fileSystem = fileSystem;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Override
|
||||
public void create(Repository repository)
|
||||
throws RepositoryException, IOException
|
||||
{
|
||||
throws RepositoryException, IOException {
|
||||
File directory = getDirectory(repository);
|
||||
|
||||
if (directory.exists())
|
||||
{
|
||||
if (directory.exists()) {
|
||||
throw RepositoryAlreadyExistsException.create(repository);
|
||||
}
|
||||
|
||||
checkPath(directory);
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
fileSystem.create(directory);
|
||||
create(repository, directory);
|
||||
postCreate(repository, directory);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (directory.exists())
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
} catch (Exception ex) {
|
||||
if (directory.exists()) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(
|
||||
"delete repository directory {}, because of failed repository creation",
|
||||
directory);
|
||||
"delete repository directory {}, because of failed repository creation",
|
||||
directory);
|
||||
}
|
||||
|
||||
fileSystem.destroy(directory);
|
||||
}
|
||||
|
||||
Throwables.propagateIfPossible(ex, RepositoryException.class,
|
||||
IOException.class);
|
||||
IOException.class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String createResourcePath(Repository repository)
|
||||
{
|
||||
public String createResourcePath(Repository repository) {
|
||||
StringBuilder path = new StringBuilder("/");
|
||||
|
||||
path.append(getType().getName()).append("/").append(repository.getName());
|
||||
path.append(getType().getName()).append("/").append(repository.getId());
|
||||
|
||||
return path.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Override
|
||||
public void delete(Repository repository)
|
||||
throws RepositoryException, IOException
|
||||
{
|
||||
throws RepositoryException, IOException {
|
||||
File directory = getDirectory(repository);
|
||||
|
||||
if (directory.exists())
|
||||
{
|
||||
if (directory.exists()) {
|
||||
fileSystem.destroy(directory);
|
||||
cleanupEmptyDirectories(config.getRepositoryDirectory(),
|
||||
directory.getParentFile());
|
||||
}
|
||||
else if (logger.isWarnEnabled())
|
||||
{
|
||||
directory.getParentFile());
|
||||
} else if (logger.isWarnEnabled()) {
|
||||
logger.warn("repository {} not found", repository);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void loadConfig()
|
||||
{
|
||||
public void loadConfig() {
|
||||
super.loadConfig();
|
||||
|
||||
if (config == null)
|
||||
{
|
||||
if (config == null) {
|
||||
config = createInitialConfig();
|
||||
|
||||
if (config != null)
|
||||
{
|
||||
if (config != null) {
|
||||
File repositoryDirectory = config.getRepositoryDirectory();
|
||||
|
||||
if (repositoryDirectory == null)
|
||||
{
|
||||
if (repositoryDirectory == null) {
|
||||
repositoryDirectory = new File(
|
||||
baseDirectory,
|
||||
DIRECTORY_REPOSITORY.concat(File.separator).concat(
|
||||
getType().getName()));
|
||||
baseDirectory,
|
||||
DIRECTORY_REPOSITORY.concat(File.separator).concat(
|
||||
getType().getName()));
|
||||
config.setRepositoryDirectory(repositoryDirectory);
|
||||
}
|
||||
|
||||
@@ -222,108 +157,52 @@ public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepository
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Override
|
||||
public void modify(Repository repository)
|
||||
throws RepositoryException, IOException
|
||||
{
|
||||
throws RepositoryException, IOException {
|
||||
|
||||
// nothing todo
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public File getDirectory(Repository repository)
|
||||
{
|
||||
public File getDirectory(Repository repository) {
|
||||
File directory = null;
|
||||
|
||||
if (isConfigured())
|
||||
{
|
||||
if (isConfigured()) {
|
||||
File repositoryDirectory = config.getRepositoryDirectory();
|
||||
|
||||
directory = new File(repositoryDirectory, repository.getName());
|
||||
directory = new File(repositoryDirectory, repository.getId());
|
||||
|
||||
if (!IOUtil.isChild(repositoryDirectory, directory))
|
||||
{
|
||||
if (!IOUtil.isChild(repositoryDirectory, directory)) {
|
||||
StringBuilder msg = new StringBuilder(directory.getPath());
|
||||
|
||||
msg.append("is not a child of ").append(repositoryDirectory.getPath());
|
||||
|
||||
throw new ConfigurationException(msg.toString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
throw new ConfigurationException("RepositoryHandler is not configured");
|
||||
}
|
||||
|
||||
return directory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getVersionInformation()
|
||||
{
|
||||
public String getVersionInformation() {
|
||||
return DEFAULT_VERSION_INFORMATION;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
* @param directory
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected ExtendedCommand buildCreateCommand(Repository repository,
|
||||
File directory)
|
||||
{
|
||||
File directory) {
|
||||
throw new UnsupportedOperationException("method is not implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
* @param directory
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
protected void create(Repository repository, File directory)
|
||||
throws RepositoryException, IOException
|
||||
{
|
||||
throws RepositoryException, IOException {
|
||||
ExtendedCommand cmd = buildCreateCommand(repository, directory);
|
||||
CommandResult result = cmd.execute();
|
||||
|
||||
if (!result.isSuccessfull())
|
||||
{
|
||||
if (!result.isSuccessfull()) {
|
||||
StringBuilder msg = new StringBuilder("command exit with error ");
|
||||
|
||||
msg.append(result.getReturnCode()).append(" and message: '");
|
||||
@@ -333,56 +212,31 @@ public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepository
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected C createInitialConfig()
|
||||
{
|
||||
protected C createInitialConfig() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
* @param directory
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
protected void postCreate(Repository repository, File directory)
|
||||
throws IOException, RepositoryException {}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
throws IOException, RepositoryException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content of a classpath resource or the given default content.
|
||||
*
|
||||
*
|
||||
* @param resource path of a classpath resource
|
||||
* @param resource path of a classpath resource
|
||||
* @param defaultContent default content to return
|
||||
*
|
||||
* @return content of a classpath resource or defaultContent
|
||||
*/
|
||||
protected String getStringFromResource(String resource, String defaultContent)
|
||||
{
|
||||
protected String getStringFromResource(String resource, String defaultContent) {
|
||||
String content = defaultContent;
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
URL url = Resources.getResource(resource);
|
||||
|
||||
if (url != null)
|
||||
{
|
||||
if (url != null) {
|
||||
content = Resources.toString(url, Charsets.UTF_8);
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
} catch (IOException ex) {
|
||||
logger.error("could not read resource", ex);
|
||||
}
|
||||
|
||||
@@ -392,43 +246,31 @@ public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepository
|
||||
/**
|
||||
* Returns true if the directory is a repository.
|
||||
*
|
||||
*
|
||||
* @param directory directory to check
|
||||
*
|
||||
* @return true if the directory is a repository
|
||||
* @since 1.9
|
||||
*/
|
||||
protected boolean isRepository(File directory)
|
||||
{
|
||||
protected boolean isRepository(File directory) {
|
||||
return new File(directory, DOT.concat(getType().getName())).exists();
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Check path for existing repositories
|
||||
*
|
||||
*
|
||||
* @param directory repository target directory
|
||||
*
|
||||
* @throws RepositoryAlreadyExistsException
|
||||
*/
|
||||
private void checkPath(File directory) throws RepositoryAlreadyExistsException
|
||||
{
|
||||
private void checkPath(File directory) throws RepositoryAlreadyExistsException {
|
||||
File repositoryDirectory = config.getRepositoryDirectory();
|
||||
File parent = directory.getParentFile();
|
||||
|
||||
while ((parent != null) &&!repositoryDirectory.equals(parent))
|
||||
{
|
||||
if (logger.isTraceEnabled())
|
||||
{
|
||||
while ((parent != null) && !repositoryDirectory.equals(parent)) {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("check {} for existing repository", parent);
|
||||
}
|
||||
|
||||
if (isRepository(parent))
|
||||
{
|
||||
if (logger.isErrorEnabled())
|
||||
{
|
||||
if (isRepository(parent)) {
|
||||
if (logger.isErrorEnabled()) {
|
||||
logger.error("parent path {} is a repository", parent);
|
||||
}
|
||||
|
||||
@@ -441,49 +283,24 @@ public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepository
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param baseDirectory
|
||||
* @param directory
|
||||
*/
|
||||
private void cleanupEmptyDirectories(File baseDirectory, File directory)
|
||||
{
|
||||
if (IOUtil.isChild(baseDirectory, directory))
|
||||
{
|
||||
if (IOUtil.isEmpty(directory))
|
||||
{
|
||||
private void cleanupEmptyDirectories(File baseDirectory, File directory) {
|
||||
if (IOUtil.isChild(baseDirectory, directory)) {
|
||||
if (IOUtil.isEmpty(directory)) {
|
||||
|
||||
// TODO use filesystem
|
||||
if (directory.delete())
|
||||
{
|
||||
if (logger.isInfoEnabled())
|
||||
{
|
||||
logger.info("successfully deleted directory {}", directory);
|
||||
}
|
||||
|
||||
if (directory.delete()) {
|
||||
logger.info("successfully deleted directory {}", directory);
|
||||
cleanupEmptyDirectories(baseDirectory, directory.getParentFile());
|
||||
}
|
||||
else if (logger.isWarnEnabled())
|
||||
{
|
||||
} else {
|
||||
logger.warn("could not delete directory {}", directory);
|
||||
}
|
||||
}
|
||||
else if (logger.isDebugEnabled())
|
||||
{
|
||||
} else {
|
||||
logger.debug("could not remove non empty directory {}", directory);
|
||||
}
|
||||
}
|
||||
else if (logger.isWarnEnabled())
|
||||
{
|
||||
logger.warn("directory {} is not a child of {}", directory,
|
||||
baseDirectory);
|
||||
} else {
|
||||
logger.warn("directory {} is not a child of {}", directory, baseDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private FileSystem fileSystem;
|
||||
}
|
||||
|
||||
@@ -43,13 +43,5 @@ import java.io.File;
|
||||
public interface RepositoryDirectoryHandler extends RepositoryHandler
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public File getDirectory(Repository repository);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* <p>
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
@@ -24,50 +24,45 @@
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* <p>
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.io.DefaultFileSystem;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import sonia.scm.store.ConfigurationStoreFactory;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import sonia.scm.io.DefaultFileSystem;
|
||||
import sonia.scm.schedule.Scheduler;
|
||||
import sonia.scm.store.ConfigurationStoreFactory;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class GitRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase
|
||||
{
|
||||
public class GitRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase {
|
||||
|
||||
@Mock
|
||||
private Scheduler scheduler;
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param directory
|
||||
*/
|
||||
|
||||
@Mock
|
||||
private ConfigurationStoreFactory factory;
|
||||
|
||||
@Override
|
||||
protected void checkDirectory(File directory)
|
||||
{
|
||||
protected void checkDirectory(File directory) {
|
||||
File head = new File(directory, "HEAD");
|
||||
|
||||
assertTrue(head.exists());
|
||||
@@ -84,21 +79,12 @@ public class GitRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase
|
||||
assertTrue(refs.isDirectory());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param factory
|
||||
* @param directory
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
|
||||
@Override
|
||||
protected RepositoryHandler createRepositoryHandler(ConfigurationStoreFactory factory,
|
||||
File directory)
|
||||
{
|
||||
File directory) {
|
||||
GitRepositoryHandler repositoryHandler = new GitRepositoryHandler(factory,
|
||||
new DefaultFileSystem(), scheduler);
|
||||
new DefaultFileSystem(), scheduler);
|
||||
|
||||
repositoryHandler.init(contextProvider);
|
||||
|
||||
@@ -110,4 +96,20 @@ public class GitRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase
|
||||
|
||||
return repositoryHandler;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDirectory() {
|
||||
GitRepositoryHandler repositoryHandler = new GitRepositoryHandler(factory,
|
||||
new DefaultFileSystem(), scheduler);
|
||||
|
||||
GitConfig gitConfig = new GitConfig();
|
||||
gitConfig.setRepositoryDirectory(new File("/path"));
|
||||
repositoryHandler.setConfig(gitConfig);
|
||||
|
||||
Repository repository = new Repository("id", "git", "Name");
|
||||
|
||||
File path = repositoryHandler.getDirectory(repository);
|
||||
assertEquals("/path/id", path.getAbsolutePath());
|
||||
assertTrue(path.getAbsolutePath().endsWith("id"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* <p>
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
@@ -24,43 +24,45 @@
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* <p>
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import sonia.scm.io.DefaultFileSystem;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
import sonia.scm.store.ConfigurationStoreFactory;
|
||||
|
||||
import java.io.File;
|
||||
import sonia.scm.store.ConfigurationStoreFactory;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class HgRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase
|
||||
{
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class HgRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase {
|
||||
|
||||
@Mock
|
||||
private ConfigurationStoreFactory factory;
|
||||
|
||||
@Mock
|
||||
private com.google.inject.Provider<HgContext> provider;
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param directory
|
||||
*/
|
||||
@Override
|
||||
protected void checkDirectory(File directory)
|
||||
{
|
||||
protected void checkDirectory(File directory) {
|
||||
File hgDirectory = new File(directory, ".hg");
|
||||
|
||||
assertTrue(hgDirectory.exists());
|
||||
@@ -73,22 +75,12 @@ public class HgRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase
|
||||
assertTrue(hgrc.length() > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param factory
|
||||
* @param directory
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected RepositoryHandler createRepositoryHandler(ConfigurationStoreFactory factory,
|
||||
File directory)
|
||||
{
|
||||
File directory) {
|
||||
HgRepositoryHandler handler = new HgRepositoryHandler(factory,
|
||||
new DefaultFileSystem(),
|
||||
new HgContextProvider());
|
||||
new DefaultFileSystem(),
|
||||
new HgContextProvider());
|
||||
|
||||
handler.init(contextProvider);
|
||||
handler.getConfig().setRepositoryDirectory(directory);
|
||||
@@ -97,5 +89,22 @@ public class HgRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase
|
||||
|
||||
return handler;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDirectory() {
|
||||
HgRepositoryHandler repositoryHandler = new HgRepositoryHandler(factory,
|
||||
new DefaultFileSystem(), provider);
|
||||
|
||||
HgConfig hgConfig = new HgConfig();
|
||||
hgConfig.setRepositoryDirectory(new File("/path"));
|
||||
hgConfig.setHgBinary("hg");
|
||||
hgConfig.setPythonBinary("python");
|
||||
repositoryHandler.setConfig(hgConfig);
|
||||
|
||||
Repository repository = new Repository("id", "git", "Name");
|
||||
|
||||
File path = repositoryHandler.getDirectory(repository);
|
||||
assertEquals("/path/id", path.getAbsolutePath());
|
||||
assertTrue(path.getAbsolutePath().endsWith("id"));
|
||||
}
|
||||
}
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* <p>
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
@@ -24,42 +24,56 @@
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* <p>
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import sonia.scm.io.DefaultFileSystem;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
import sonia.scm.repository.api.HookContextFactory;
|
||||
import sonia.scm.repository.spi.HookEventFacade;
|
||||
import sonia.scm.store.ConfigurationStore;
|
||||
import sonia.scm.store.ConfigurationStoreFactory;
|
||||
|
||||
import java.io.File;
|
||||
import sonia.scm.store.ConfigurationStoreFactory;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class SvnRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase
|
||||
{
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class SvnRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase {
|
||||
|
||||
@Mock
|
||||
private ConfigurationStoreFactory factory;
|
||||
|
||||
@Mock
|
||||
private ConfigurationStore store;
|
||||
|
||||
@Mock
|
||||
private com.google.inject.Provider<RepositoryManager> repositoryManagerProvider;
|
||||
|
||||
private HookContextFactory hookContextFactory = new HookContextFactory(mock(PreProcessorUtil.class));
|
||||
|
||||
private HookEventFacade facade = new HookEventFacade(repositoryManagerProvider, hookContextFactory);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param directory
|
||||
*/
|
||||
@Override
|
||||
protected void checkDirectory(File directory)
|
||||
{
|
||||
protected void checkDirectory(File directory) {
|
||||
File format = new File(directory, "format");
|
||||
|
||||
assertTrue(format.exists());
|
||||
@@ -71,21 +85,11 @@ public class SvnRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase
|
||||
assertTrue(db.isDirectory());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param factory
|
||||
* @param directory
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected RepositoryHandler createRepositoryHandler(ConfigurationStoreFactory factory,
|
||||
File directory)
|
||||
{
|
||||
File directory) {
|
||||
SvnRepositoryHandler handler = new SvnRepositoryHandler(factory,
|
||||
new DefaultFileSystem(), null);
|
||||
new DefaultFileSystem(), null);
|
||||
|
||||
handler.init(contextProvider);
|
||||
|
||||
@@ -98,4 +102,21 @@ public class SvnRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase
|
||||
|
||||
return handler;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDirectory() {
|
||||
when(factory.getStore(any(), any())).thenReturn(store);
|
||||
SvnRepositoryHandler repositoryHandler = new SvnRepositoryHandler(factory,
|
||||
new DefaultFileSystem(), facade);
|
||||
|
||||
SvnConfig svnConfig = new SvnConfig();
|
||||
svnConfig.setRepositoryDirectory(new File("/path"));
|
||||
repositoryHandler.setConfig(svnConfig);
|
||||
|
||||
Repository repository = new Repository("id", "svn", "Name");
|
||||
|
||||
File path = repositoryHandler.getDirectory(repository);
|
||||
assertEquals("/path/id", path.getAbsolutePath());
|
||||
assertTrue(path.getAbsolutePath().endsWith("id"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* <p>
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
@@ -24,113 +24,67 @@
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* <p>
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.Type;
|
||||
import sonia.scm.io.DefaultFileSystem;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
import sonia.scm.store.ConfigurationStoreFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import sonia.scm.store.ConfigurationStoreFactory;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class DummyRepositoryHandler
|
||||
extends AbstractSimpleRepositoryHandler<SimpleRepositoryConfig>
|
||||
{
|
||||
extends AbstractSimpleRepositoryHandler<SimpleRepositoryConfig> {
|
||||
|
||||
/** Field description */
|
||||
public static final String TYPE_DISPLAYNAME = "Dummy";
|
||||
|
||||
/** Field description */
|
||||
public static final String TYPE_NAME = "dummy";
|
||||
|
||||
/** Field description */
|
||||
public static final Type TYPE = new Type(TYPE_NAME, TYPE_DISPLAYNAME);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
private Set<String> existingRepoNames = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param storeFactory
|
||||
*/
|
||||
public DummyRepositoryHandler(ConfigurationStoreFactory storeFactory)
|
||||
{
|
||||
public DummyRepositoryHandler(ConfigurationStoreFactory storeFactory) {
|
||||
super(storeFactory, new DefaultFileSystem());
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Type getType()
|
||||
{
|
||||
public Type getType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
* @param directory
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Override
|
||||
protected void create(Repository repository, File directory)
|
||||
throws RepositoryException, IOException
|
||||
{
|
||||
|
||||
// do nothing
|
||||
throws RepositoryException {
|
||||
if (existingRepoNames.contains(repository.getNamespace() + repository.getName())) {
|
||||
throw new RepositoryAlreadyExistsException("Repo exists");
|
||||
} else {
|
||||
existingRepoNames.add(repository.getNamespace() + repository.getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected SimpleRepositoryConfig createInitialConfig()
|
||||
{
|
||||
protected SimpleRepositoryConfig createInitialConfig() {
|
||||
return new SimpleRepositoryConfig();
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected Class<SimpleRepositoryConfig> getConfigClass()
|
||||
{
|
||||
protected Class<SimpleRepositoryConfig> getConfigClass() {
|
||||
return SimpleRepositoryConfig.class;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ public final class RepositoryTestData
|
||||
heartOfGold.setName("HeartOfGold");
|
||||
heartOfGold.setDescription(
|
||||
"Heart of Gold is the first prototype ship to successfully utilise the revolutionary Infinite Improbability Drive");
|
||||
|
||||
heartOfGold.setId("hogId");
|
||||
return heartOfGold;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* <p>
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
@@ -24,169 +24,94 @@
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* <p>
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import sonia.scm.AbstractTestBase;
|
||||
import sonia.scm.store.ConfigurationStoreFactory;
|
||||
import sonia.scm.store.InMemoryConfigurationStoreFactory;
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import sonia.scm.store.ConfigurationStoreFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public abstract class SimpleRepositoryHandlerTestBase extends AbstractTestBase
|
||||
{
|
||||
public abstract class SimpleRepositoryHandlerTestBase extends AbstractTestBase {
|
||||
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param directory
|
||||
*/
|
||||
protected abstract void checkDirectory(File directory);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param factory
|
||||
* @param directory
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract RepositoryHandler createRepositoryHandler(
|
||||
ConfigurationStoreFactory factory, File directory);
|
||||
ConfigurationStoreFactory factory, File directory);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Test
|
||||
public void testCreate() throws RepositoryException, IOException
|
||||
{
|
||||
public void testCreate() throws RepositoryException, IOException {
|
||||
createRepository();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Test(expected = RepositoryAlreadyExistsException.class)
|
||||
public void testCreateExisitingRepository()
|
||||
throws RepositoryException, IOException
|
||||
{
|
||||
throws RepositoryException, IOException {
|
||||
createRepository();
|
||||
createRepository();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Test
|
||||
public void testCreateResourcePath() throws RepositoryException, IOException
|
||||
{
|
||||
public void testCreateResourcePath() throws RepositoryException, IOException {
|
||||
Repository repository = createRepository();
|
||||
String path = handler.createResourcePath(repository);
|
||||
|
||||
assertNotNull(path);
|
||||
assertTrue(path.trim().length() > 0);
|
||||
assertTrue(path.contains(repository.getName()));
|
||||
assertTrue(path.contains(repository.getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Test
|
||||
public void testDelete() throws RepositoryException, IOException
|
||||
{
|
||||
public void testDelete() throws RepositoryException, IOException {
|
||||
Repository repository = createRepository();
|
||||
|
||||
handler.delete(repository);
|
||||
|
||||
File directory = new File(baseDirectory, repository.getName());
|
||||
File directory = new File(baseDirectory, repository.getId());
|
||||
|
||||
assertFalse(directory.exists());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
protected void postSetUp() throws Exception
|
||||
{
|
||||
protected void postSetUp() throws Exception {
|
||||
InMemoryConfigurationStoreFactory storeFactory = new InMemoryConfigurationStoreFactory();
|
||||
baseDirectory = new File(contextProvider.getBaseDirectory(), "repositories");
|
||||
IOUtil.mkdirs(baseDirectory);
|
||||
handler = createRepositoryHandler(storeFactory, baseDirectory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
protected void preTearDown() throws Exception
|
||||
{
|
||||
if (handler != null)
|
||||
{
|
||||
protected void preTearDown() throws Exception {
|
||||
if (handler != null) {
|
||||
handler.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
private Repository createRepository() throws RepositoryException, IOException
|
||||
{
|
||||
private Repository createRepository() throws RepositoryException, IOException {
|
||||
Repository repository = RepositoryTestData.createHeartOfGold();
|
||||
|
||||
handler.create(repository);
|
||||
|
||||
File directory = new File(baseDirectory, repository.getName());
|
||||
File directory = new File(baseDirectory, repository.getId());
|
||||
|
||||
assertTrue(directory.exists());
|
||||
assertTrue(directory.isDirectory());
|
||||
@@ -195,11 +120,8 @@ public abstract class SimpleRepositoryHandlerTestBase extends AbstractTestBase
|
||||
return repository;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
protected File baseDirectory;
|
||||
|
||||
/** Field description */
|
||||
private RepositoryHandler handler;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user