mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 16:35:45 +01:00
Some polishing during review
This commit is contained in:
@@ -143,6 +143,7 @@ public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
Throwables.propagateIfPossible(ex, RepositoryException.class);
|
Throwables.propagateIfPossible(ex, RepositoryException.class);
|
||||||
|
// This point will never be reached
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import sonia.scm.api.rest.resources.AbstractManagerResource;
|
|||||||
|
|
||||||
import javax.ws.rs.core.GenericEntity;
|
import javax.ws.rs.core.GenericEntity;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
@@ -17,13 +16,15 @@ import java.util.function.Supplier;
|
|||||||
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
|
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adapter from resource http endpoints to managers.
|
* Adapter from resource http endpoints to managers, for Collection resources (e.g. {@code /users}).
|
||||||
*
|
*
|
||||||
* Provides common CRUD operations and DTO to Model Object mapping to keep Resources more DRY.
|
* Provides common CRUD operations and DTO to Model Object mapping to keep Resources more DRY.
|
||||||
*
|
*
|
||||||
* @param <MODEL_OBJECT> The type of the model object, eg. {@link sonia.scm.user.User}.
|
* @param <MODEL_OBJECT> The type of the model object, eg. {@link sonia.scm.user.User}.
|
||||||
* @param <DTO> The corresponding transport object, eg. {@link UserDto}.
|
* @param <DTO> The corresponding transport object, eg. {@link UserDto}.
|
||||||
* @param <EXCEPTION> The exception type for the model object, eg. {@link sonia.scm.user.UserException}.
|
* @param <EXCEPTION> The exception type for the model object, eg. {@link sonia.scm.user.UserException}.
|
||||||
|
*
|
||||||
|
* @see SingleResourceManagerAdapter
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("squid:S00119") // "MODEL_OBJECT" is much more meaningful than "M", right?
|
@SuppressWarnings("squid:S00119") // "MODEL_OBJECT" is much more meaningful than "M", right?
|
||||||
class CollectionResourceManagerAdapter<MODEL_OBJECT extends ModelObject,
|
class CollectionResourceManagerAdapter<MODEL_OBJECT extends ModelObject,
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
package sonia.scm.api.v2.resources;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@Getter @Setter
|
|
||||||
public class PermissionDto {
|
|
||||||
private String type;
|
|
||||||
private String name;
|
|
||||||
private boolean groupPermission;
|
|
||||||
}
|
|
||||||
@@ -19,7 +19,6 @@ import javax.ws.rs.Path;
|
|||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class RepositoryCollectionResource {
|
public class RepositoryCollectionResource {
|
||||||
|
|
||||||
@@ -39,7 +38,7 @@ public class RepositoryCollectionResource {
|
|||||||
@GET
|
@GET
|
||||||
@Path("")
|
@Path("")
|
||||||
@Produces(VndMediaType.REPOSITORY_COLLECTION)
|
@Produces(VndMediaType.REPOSITORY_COLLECTION)
|
||||||
@TypeHint(UserDto[].class)
|
@TypeHint(RepositoryDto[].class)
|
||||||
@StatusCodes({
|
@StatusCodes({
|
||||||
@ResponseCode(code = 200, condition = "success"),
|
@ResponseCode(code = 200, condition = "success"),
|
||||||
@ResponseCode(code = 401, condition = "not authenticated / invalid credentials"),
|
@ResponseCode(code = 401, condition = "not authenticated / invalid credentials"),
|
||||||
@@ -66,7 +65,7 @@ public class RepositoryCollectionResource {
|
|||||||
})
|
})
|
||||||
@TypeHint(TypeHint.NO_CONTENT.class)
|
@TypeHint(TypeHint.NO_CONTENT.class)
|
||||||
@ResponseHeaders(@ResponseHeader(name = "Location", description = "uri to the created repository"))
|
@ResponseHeaders(@ResponseHeader(name = "Location", description = "uri to the created repository"))
|
||||||
public Response create(RepositoryDto repositoryDto) throws IOException, RepositoryException {
|
public Response create(RepositoryDto repositoryDto) throws RepositoryException {
|
||||||
return adapter.create(repositoryDto,
|
return adapter.create(repositoryDto,
|
||||||
() -> dtoToRepositoryMapper.map(repositoryDto, null),
|
() -> dtoToRepositoryMapper.map(repositoryDto, null),
|
||||||
repository -> resourceLinks.repository().self(repository.getNamespace(), repository.getName()));
|
repository -> resourceLinks.repository().self(repository.getNamespace(), repository.getName()));
|
||||||
|
|||||||
@@ -15,13 +15,15 @@ import java.util.function.Supplier;
|
|||||||
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
|
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adapter from resource http endpoints to managers.
|
* Adapter from resource http endpoints to managers, for Single resources (e.g. {@code /user/name}).
|
||||||
*
|
*
|
||||||
* Provides common CRUD operations and DTO to Model Object mapping to keep Resources more DRY.
|
* Provides common CRUD operations and DTO to Model Object mapping to keep Resources more DRY.
|
||||||
*
|
*
|
||||||
* @param <MODEL_OBJECT> The type of the model object, eg. {@link sonia.scm.user.User}.
|
* @param <MODEL_OBJECT> The type of the model object, eg. {@link sonia.scm.user.User}.
|
||||||
* @param <DTO> The corresponding transport object, eg. {@link UserDto}.
|
* @param <DTO> The corresponding transport object, eg. {@link UserDto}.
|
||||||
* @param <EXCEPTION> The exception type for the model object, eg. {@link sonia.scm.user.UserException}.
|
* @param <EXCEPTION> The exception type for the model object, eg. {@link sonia.scm.user.UserException}.
|
||||||
|
*
|
||||||
|
* @see CollectionResourceManagerAdapter
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("squid:S00119") // "MODEL_OBJECT" is much more meaningful than "M", right?
|
@SuppressWarnings("squid:S00119") // "MODEL_OBJECT" is much more meaningful than "M", right?
|
||||||
class SingleResourceManagerAdapter<MODEL_OBJECT extends ModelObject,
|
class SingleResourceManagerAdapter<MODEL_OBJECT extends ModelObject,
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import static org.mockito.MockitoAnnotations.initMocks;
|
|||||||
public class GroupToGroupDtoMapperTest {
|
public class GroupToGroupDtoMapperTest {
|
||||||
|
|
||||||
private final URI baseUri = URI.create("http://example.com/base/");
|
private final URI baseUri = URI.create("http://example.com/base/");
|
||||||
|
@SuppressWarnings("unused") // Is injected
|
||||||
private final ResourceLinks resourceLinks = ResourceLinksMock.createMock(baseUri);
|
private final ResourceLinks resourceLinks = ResourceLinksMock.createMock(baseUri);
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import sonia.scm.repository.Repository;
|
|||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
import static java.util.Arrays.asList;
|
import static java.util.Collections.singletonList;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.mockito.MockitoAnnotations.initMocks;
|
import static org.mockito.MockitoAnnotations.initMocks;
|
||||||
@@ -31,6 +31,7 @@ public class RepositoryToRepositoryDtoMapperTest {
|
|||||||
public final ShiroRule rule = new ShiroRule();
|
public final ShiroRule rule = new ShiroRule();
|
||||||
|
|
||||||
private final URI baseUri = URI.create("http://example.com/base/");
|
private final URI baseUri = URI.create("http://example.com/base/");
|
||||||
|
@SuppressWarnings("unused") // Is injected
|
||||||
private final ResourceLinks resourceLinks = ResourceLinksMock.createMock(baseUri);
|
private final ResourceLinks resourceLinks = ResourceLinksMock.createMock(baseUri);
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
@@ -140,8 +141,8 @@ public class RepositoryToRepositoryDtoMapperTest {
|
|||||||
repository.setContact("none@example.com");
|
repository.setContact("none@example.com");
|
||||||
repository.setId("1");
|
repository.setId("1");
|
||||||
repository.setCreationDate(System.currentTimeMillis());
|
repository.setCreationDate(System.currentTimeMillis());
|
||||||
repository.setHealthCheckFailures(asList(new HealthCheckFailure("1", "summary", "url", "failure")));
|
repository.setHealthCheckFailures(singletonList(new HealthCheckFailure("1", "summary", "url", "failure")));
|
||||||
repository.setPermissions(asList(new Permission("permission", PermissionType.READ)));
|
repository.setPermissions(singletonList(new Permission("permission", PermissionType.READ)));
|
||||||
|
|
||||||
return repository;
|
return repository;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public class UserRootResourceTest {
|
|||||||
private ArgumentCaptor<User> userCaptor = ArgumentCaptor.forClass(User.class);
|
private ArgumentCaptor<User> userCaptor = ArgumentCaptor.forClass(User.class);
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void prepareEnvironment() throws IOException, UserException {
|
public void prepareEnvironment() throws UserException {
|
||||||
initMocks(this);
|
initMocks(this);
|
||||||
User dummyUser = createDummyUser("Neo");
|
User dummyUser = createDummyUser("Neo");
|
||||||
when(userManager.create(userCaptor.capture())).thenAnswer(invocation -> invocation.getArguments()[0]);
|
when(userManager.create(userCaptor.capture())).thenAnswer(invocation -> invocation.getArguments()[0]);
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import static org.mockito.MockitoAnnotations.initMocks;
|
|||||||
public class UserToUserDtoMapperTest {
|
public class UserToUserDtoMapperTest {
|
||||||
|
|
||||||
private final URI baseUri = URI.create("http://example.com/base/");
|
private final URI baseUri = URI.create("http://example.com/base/");
|
||||||
|
@SuppressWarnings("unused") // Is injected
|
||||||
private final ResourceLinks resourceLinks = ResourceLinksMock.createMock(baseUri);
|
private final ResourceLinks resourceLinks = ResourceLinksMock.createMock(baseUri);
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
|
|||||||
@@ -93,10 +93,6 @@ import static org.mockito.Mockito.when;
|
|||||||
)
|
)
|
||||||
public class DefaultRepositoryManagerTest extends ManagerTestBase<Repository, RepositoryException> {
|
public class DefaultRepositoryManagerTest extends ManagerTestBase<Repository, RepositoryException> {
|
||||||
|
|
||||||
{
|
|
||||||
ThreadContext.unbindSecurityManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public ShiroRule shiro = new ShiroRule();
|
public ShiroRule shiro = new ShiroRule();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user