Adjust to repository storage with id

This commit is contained in:
René Pfeuffer
2018-07-10 15:31:18 +02:00
parent 43ca72255e
commit dc8ecd5689
40 changed files with 619 additions and 1120 deletions

View File

@@ -56,7 +56,7 @@ public class DummyRepositoryHandler
public static final Type TYPE = new Type(TYPE_NAME, TYPE_DISPLAYNAME);
private Set<String> existingRepoNames = new HashSet<>();
private final Set<String> existingRepoNames = new HashSet<>();
public DummyRepositoryHandler(ConfigurationStoreFactory storeFactory) {
super(storeFactory, new DefaultFileSystem());
@@ -69,12 +69,12 @@ public class DummyRepositoryHandler
@Override
protected void create(Repository repository, File directory)
throws RepositoryException {
if (existingRepoNames.contains(repository.getNamespace() + repository.getName())) {
protected void create(Repository repository, File directory) throws RepositoryException {
String key = repository.getNamespace() + "/" + repository.getName();
if (existingRepoNames.contains(key)) {
throw new RepositoryAlreadyExistsException("Repo exists");
} else {
existingRepoNames.add(repository.getNamespace() + repository.getName());
existingRepoNames.add(key);
}
}

View File

@@ -0,0 +1,49 @@
package sonia.scm.repository;
public class RepositoryBuilder {
private String id = "id-" + ++nextID;
private String contact = "test@example.com";
private String description = "";
private String namespace = "test";
private String name = "name";
private String type = "git";
private static int nextID = 0;
public RepositoryBuilder type(String type) {
this.type = type;
return this;
}
public RepositoryBuilder contact(String contact) {
this.contact = contact;
return this;
}
public RepositoryBuilder namespace(String namespace) {
this.namespace = namespace;
return this;
}
public RepositoryBuilder name(String name) {
this.name = name;
return this;
}
public RepositoryBuilder description(String description) {
this.description = description;
return this;
}
public Repository build() {
Repository repository = new Repository();
repository.setId(id);
repository.setType(type);
repository.setContact(contact);
repository.setNamespace(namespace);
repository.setName(name);
repository.setDescription(description);
return repository;
}
}

View File

@@ -6,13 +6,13 @@
* 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
@@ -26,26 +26,22 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.repository;
public final class RepositoryTestData
{
public final class RepositoryTestData {
private RepositoryTestData() {}
private RepositoryTestData() {
}
public static Repository create42Puzzle()
{
public static Repository create42Puzzle() {
return create42Puzzle(DummyRepositoryHandler.TYPE_NAME);
}
public static Repository create42Puzzle(String type)
{
return new Builder()
public static Repository create42Puzzle(String type) {
return new RepositoryBuilder()
.type(type)
.contact("douglas.adams@hitchhiker.com")
.name("42Puzzle")
@@ -53,15 +49,13 @@ public final class RepositoryTestData
.build();
}
public static Repository createHappyVerticalPeopleTransporter()
{
public static Repository createHappyVerticalPeopleTransporter() {
return createHappyVerticalPeopleTransporter(
DummyRepositoryHandler.TYPE_NAME);
}
public static Repository createHappyVerticalPeopleTransporter(String type)
{
return new Builder()
public static Repository createHappyVerticalPeopleTransporter(String type) {
return new RepositoryBuilder()
.type(type)
.contact("zaphod.beeblebrox@hitchhiker.com")
.name("happyVerticalPeopleTransporter")
@@ -69,14 +63,12 @@ public final class RepositoryTestData
.build();
}
public static Repository createHeartOfGold()
{
public static Repository createHeartOfGold() {
return createHeartOfGold(DummyRepositoryHandler.TYPE_NAME);
}
public static Repository createHeartOfGold(String type)
{
return new Builder()
public static Repository createHeartOfGold(String type) {
return new RepositoryBuilder()
.type(type)
.contact("zaphod.beeblebrox@hitchhiker.com")
.name("HeartOfGold")
@@ -85,51 +77,17 @@ public final class RepositoryTestData
.build();
}
public static Repository createRestaurantAtTheEndOfTheUniverse()
{
public static Repository createRestaurantAtTheEndOfTheUniverse() {
return createRestaurantAtTheEndOfTheUniverse(
DummyRepositoryHandler.TYPE_NAME);
}
public static Repository createRestaurantAtTheEndOfTheUniverse(String type)
{
return new Builder()
public static Repository createRestaurantAtTheEndOfTheUniverse(String type) {
return new RepositoryBuilder()
.type(type)
.contact("douglas.adams@hitchhiker.com")
.name("RestaurantAtTheEndOfTheUniverse")
.description("The Restaurant at the End of the Universe")
.build();
}
private static class Builder {
private static int nextID = 0;
Repository repository = new Repository();
{
repository.setId("ID-" + ++nextID);
}
Builder type(String type) {
repository.setType(type);
return this;
}
Builder contact(String contact) {
repository.setContact(contact);
return this;
}
Builder name(String name) {
repository.setName(name);
return this;
}
Builder description(String description) {
repository.setDescription(description);
return this;
}
public Repository build() {
return repository;
}
}
}

View File

@@ -40,9 +40,10 @@ import sonia.scm.store.InMemoryConfigurationStoreFactory;
import sonia.scm.util.IOUtil;
import java.io.File;
import java.io.IOException;
import static org.junit.Assert.*;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
//~--- JDK imports ------------------------------------------------------------
@@ -59,19 +60,12 @@ public abstract class SimpleRepositoryHandlerTestBase extends AbstractTestBase {
ConfigurationStoreFactory factory, File directory);
@Test
public void testCreate() throws RepositoryException, IOException {
createRepository();
}
@Test(expected = RepositoryAlreadyExistsException.class)
public void testCreateExisitingRepository()
throws RepositoryException, IOException {
createRepository();
public void testCreate() throws RepositoryException {
createRepository();
}
@Test
public void testCreateResourcePath() throws RepositoryException, IOException {
public void testCreateResourcePath() throws RepositoryException {
Repository repository = createRepository();
String path = handler.createResourcePath(repository);
@@ -81,7 +75,7 @@ public abstract class SimpleRepositoryHandlerTestBase extends AbstractTestBase {
}
@Test
public void testDelete() throws RepositoryException, IOException {
public void testDelete() throws RepositoryException {
Repository repository = createRepository();
handler.delete(repository);
@@ -92,7 +86,7 @@ public abstract class SimpleRepositoryHandlerTestBase extends AbstractTestBase {
}
@Override
protected void postSetUp() throws Exception {
protected void postSetUp() {
InMemoryConfigurationStoreFactory storeFactory = new InMemoryConfigurationStoreFactory();
baseDirectory = new File(contextProvider.getBaseDirectory(), "repositories");
IOUtil.mkdirs(baseDirectory);
@@ -106,7 +100,7 @@ public abstract class SimpleRepositoryHandlerTestBase extends AbstractTestBase {
}
}
private Repository createRepository() throws RepositoryException, IOException {
private Repository createRepository() throws RepositoryException {
Repository repository = RepositoryTestData.createHeartOfGold();
handler.create(repository);
@@ -120,7 +114,6 @@ public abstract class SimpleRepositoryHandlerTestBase extends AbstractTestBase {
return repository;
}
protected File baseDirectory;
private RepositoryHandler handler;