mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 07:55:47 +01:00
Use correct namespace of created repository
This commit is contained in:
@@ -53,13 +53,9 @@ public interface HandlerBase<T extends TypedObject, E extends Exception>
|
||||
/**
|
||||
* Persists a new object.
|
||||
*
|
||||
*
|
||||
* @param object to store
|
||||
*
|
||||
* @throws E
|
||||
* @throws IOException
|
||||
* @return The persisted object.
|
||||
*/
|
||||
public void create(T object) throws E, IOException;
|
||||
public T create(T object) throws E, IOException;
|
||||
|
||||
/**
|
||||
* Removes a persistent object.
|
||||
|
||||
@@ -35,7 +35,6 @@ package sonia.scm;
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
|
||||
@@ -78,9 +77,9 @@ public class ManagerDecorator<T extends ModelObject, E extends Exception>
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void create(T object) throws E, IOException
|
||||
public T create(T object) throws E, IOException
|
||||
{
|
||||
decorated.create(object);
|
||||
return decorated.create(object);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -38,23 +38,20 @@ 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 ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -108,7 +105,7 @@ public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepository
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Override
|
||||
public void create(Repository repository)
|
||||
public Repository create(Repository repository)
|
||||
throws RepositoryException, IOException
|
||||
{
|
||||
File directory = getDirectory(repository);
|
||||
@@ -125,6 +122,7 @@ public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepository
|
||||
fileSystem.create(directory);
|
||||
create(repository, directory);
|
||||
postCreate(repository, directory);
|
||||
return repository;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -142,6 +140,7 @@ public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepository
|
||||
|
||||
Throwables.propagateIfPossible(ex, RepositoryException.class,
|
||||
IOException.class);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ public class ManagerTest {
|
||||
public Collection getAll(Comparator comparator, int start, int limit) { return null; }
|
||||
|
||||
@Override
|
||||
public void create(TypedObject object) {}
|
||||
public TypedObject create(TypedObject object) { return null; }
|
||||
|
||||
@Override
|
||||
public void delete(TypedObject object) {}
|
||||
|
||||
@@ -52,8 +52,8 @@ class CollectionResourceManagerAdapter<MODEL_OBJECT extends ModelObject,
|
||||
return Response.status(BAD_REQUEST).build();
|
||||
}
|
||||
MODEL_OBJECT modelObject = modelObjectSupplier.get();
|
||||
manager.create(modelObject);
|
||||
return Response.created(URI.create(uriCreator.apply(modelObject))).build();
|
||||
MODEL_OBJECT created = manager.create(modelObject);
|
||||
return Response.created(URI.create(uriCreator.apply(created))).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -51,7 +51,12 @@ import sonia.scm.util.CollectionAppender;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
@@ -106,7 +111,7 @@ public class DefaultGroupManager extends AbstractGroupManager
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public void create(Group group) throws GroupException, IOException
|
||||
public Group create(Group group) throws GroupException, IOException
|
||||
{
|
||||
String type = group.getType();
|
||||
|
||||
@@ -135,6 +140,7 @@ public class DefaultGroupManager extends AbstractGroupManager
|
||||
fireEvent(HandlerEventType.BEFORE_CREATE, group);
|
||||
groupDAO.add(group);
|
||||
fireEvent(HandlerEventType.CREATE, group);
|
||||
return group;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -138,7 +138,7 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager {
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
public void create(Repository repository, boolean initRepository)
|
||||
public Repository create(Repository repository, boolean initRepository)
|
||||
throws RepositoryException, IOException {
|
||||
logger.info("create repository {} of type {}", repository.getName(),
|
||||
repository.getType());
|
||||
@@ -161,6 +161,7 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager {
|
||||
fireEvent(HandlerEventType.BEFORE_CREATE, repository);
|
||||
repositoryDAO.add(repository);
|
||||
fireEvent(HandlerEventType.CREATE, repository);
|
||||
return repository;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -173,9 +174,9 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager {
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Override
|
||||
public void create(Repository repository)
|
||||
public Repository create(Repository repository)
|
||||
throws RepositoryException, IOException {
|
||||
create(repository, true);
|
||||
return create(repository, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -137,7 +137,7 @@ public class DefaultUserManager extends AbstractUserManager
|
||||
* @throws UserException
|
||||
*/
|
||||
@Override
|
||||
public void create(User user) throws UserException, IOException
|
||||
public User create(User user) throws UserException, IOException
|
||||
{
|
||||
String type = user.getType();
|
||||
|
||||
@@ -163,6 +163,7 @@ public class DefaultUserManager extends AbstractUserManager
|
||||
fireEvent(HandlerEventType.BEFORE_CREATE, user);
|
||||
userDAO.add(user);
|
||||
fireEvent(HandlerEventType.CREATE, user);
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -62,7 +62,7 @@ public class GroupRootResourceTest {
|
||||
@Before
|
||||
public void prepareEnvironment() throws IOException, GroupException {
|
||||
initMocks(this);
|
||||
doNothing().when(groupManager).create(groupCaptor.capture());
|
||||
when(groupManager.create(groupCaptor.capture())).thenAnswer(invocation -> invocation.getArguments()[0]);
|
||||
doNothing().when(groupManager).modify(groupCaptor.capture());
|
||||
|
||||
Group group = createDummyGroup();
|
||||
|
||||
@@ -158,7 +158,13 @@ public class RepositoryRootResourceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateNewRepository() throws URISyntaxException, IOException, RepositoryException {
|
||||
public void shouldCreateNewRepositoryInCorrectNamespace() throws URISyntaxException, IOException, RepositoryException {
|
||||
when(repositoryManager.create(any())).thenAnswer(invocation -> {
|
||||
Repository repository = (Repository) invocation.getArguments()[0];
|
||||
repository.setNamespace("otherspace");
|
||||
return repository;
|
||||
});
|
||||
|
||||
URL url = Resources.getResource("sonia/scm/api/v2/repository-test-update.json");
|
||||
byte[] repositoryJson = Resources.toByteArray(url);
|
||||
|
||||
@@ -171,7 +177,7 @@ public class RepositoryRootResourceTest {
|
||||
dispatcher.invoke(request, response);
|
||||
|
||||
assertEquals(HttpServletResponse.SC_CREATED, response.getStatus());
|
||||
assertEquals("/v2/repositories/space/repo", response.getOutputHeaders().get("Location").get(0).toString());
|
||||
assertEquals("/v2/repositories/otherspace/repo", response.getOutputHeaders().get("Location").get(0).toString());
|
||||
verify(repositoryManager).create(any(Repository.class));
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ public class UserRootResourceTest {
|
||||
public void prepareEnvironment() throws IOException, UserException {
|
||||
initMocks(this);
|
||||
User dummyUser = createDummyUser("Neo");
|
||||
doNothing().when(userManager).create(userCaptor.capture());
|
||||
when(userManager.create(userCaptor.capture())).thenAnswer(invocation -> invocation.getArguments()[0]);
|
||||
doNothing().when(userManager).modify(userCaptor.capture());
|
||||
doNothing().when(userManager).delete(userCaptor.capture());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user