diff --git a/scm-core/src/main/java/sonia/scm/repository/AbstractSimpleRepositoryHandler.java b/scm-core/src/main/java/sonia/scm/repository/AbstractSimpleRepositoryHandler.java index 670cab93e1..b61a4dce19 100644 --- a/scm-core/src/main/java/sonia/scm/repository/AbstractSimpleRepositoryHandler.java +++ b/scm-core/src/main/java/sonia/scm/repository/AbstractSimpleRepositoryHandler.java @@ -1,19 +1,19 @@ /** * Copyright (c) 2010, Sebastian Sdorra * All rights reserved. - * + *
* Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + *
* 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. + *
* 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. - * + *
* 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
* 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.
+ *
* 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.
- *
+ *
* 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"));
+ }
}
diff --git a/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/HgRepositoryHandlerTest.java b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/HgRepositoryHandlerTest.java
index c14e5f1b61..2fdc039c53 100644
--- a/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/HgRepositoryHandlerTest.java
+++ b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/HgRepositoryHandlerTest.java
@@ -1,19 +1,19 @@
/**
* Copyright (c) 2010, Sebastian Sdorra
* All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
- *
+ *
* 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.
+ *
* 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.
- *
+ *
* 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
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
- *
+ *
* 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.
+ *
* 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.
- *
+ *
* 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
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
- *
+ *
* 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.
+ *
* 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.
- *
+ *
* 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
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
- *
+ *
* 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.
+ *
* 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.
- *
+ *
* 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;
}