mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 08:25:44 +01:00
Remove branch and tag hal-link from svn repository
This commit is contained in:
@@ -8,6 +8,9 @@ import org.mapstruct.MappingTarget;
|
||||
import sonia.scm.repository.HealthCheckFailure;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryPermissions;
|
||||
import sonia.scm.repository.api.Command;
|
||||
import sonia.scm.repository.api.RepositoryService;
|
||||
import sonia.scm.repository.api.RepositoryServiceFactory;
|
||||
|
||||
import static de.otto.edison.hal.Link.link;
|
||||
import static de.otto.edison.hal.Links.linkingTo;
|
||||
@@ -19,6 +22,8 @@ public abstract class RepositoryToRepositoryDtoMapper extends BaseMapper<Reposit
|
||||
|
||||
@Inject
|
||||
private ResourceLinks resourceLinks;
|
||||
@Inject
|
||||
private RepositoryServiceFactory serviceFactory;
|
||||
|
||||
abstract HealthCheckFailureDto toDto(HealthCheckFailure failure);
|
||||
|
||||
@@ -33,8 +38,13 @@ public abstract class RepositoryToRepositoryDtoMapper extends BaseMapper<Reposit
|
||||
linksBuilder.single(link("update", resourceLinks.repository().update(target.getNamespace(), target.getName())));
|
||||
linksBuilder.single(link("permissions", resourceLinks.permissionCollection().self(target.getNamespace(), target.getName())));
|
||||
}
|
||||
RepositoryService repositoryService = serviceFactory.create(repository);
|
||||
if (repositoryService.isSupported(Command.TAGS)) {
|
||||
linksBuilder.single(link("tags", resourceLinks.tagCollection().self(target.getNamespace(), target.getName())));
|
||||
}
|
||||
if (repositoryService.isSupported(Command.BRANCHES)) {
|
||||
linksBuilder.single(link("branches", resourceLinks.branchCollection().self(target.getNamespace(), target.getName())));
|
||||
}
|
||||
linksBuilder.single(link("changesets", resourceLinks.changeset().self(target.getNamespace(), target.getName())));
|
||||
linksBuilder.single(link("sources", resourceLinks.source().self(target.getNamespace(), target.getName())));
|
||||
target.add(linksBuilder.build());
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.jboss.resteasy.mock.MockHttpResponse;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import sonia.scm.PageResult;
|
||||
@@ -18,6 +19,7 @@ import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryException;
|
||||
import sonia.scm.repository.RepositoryIsNotArchivedException;
|
||||
import sonia.scm.repository.RepositoryManager;
|
||||
import sonia.scm.repository.api.RepositoryServiceFactory;
|
||||
import sonia.scm.web.VndMediaType;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -57,6 +59,9 @@ public class RepositoryRootResourceTest {
|
||||
|
||||
@Mock
|
||||
private RepositoryManager repositoryManager;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private RepositoryServiceFactory serviceFactory;
|
||||
|
||||
|
||||
private final URI baseUri = URI.create("/");
|
||||
private final ResourceLinks resourceLinks = ResourceLinksMock.createMock(baseUri);
|
||||
|
||||
@@ -7,17 +7,23 @@ import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import sonia.scm.repository.HealthCheckFailure;
|
||||
import sonia.scm.repository.Permission;
|
||||
import sonia.scm.repository.PermissionType;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.api.Command;
|
||||
import sonia.scm.repository.api.RepositoryServiceFactory;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.MockitoAnnotations.initMocks;
|
||||
|
||||
@SubjectAware(
|
||||
@@ -33,6 +39,8 @@ public class RepositoryToRepositoryDtoMapperTest {
|
||||
private final URI baseUri = URI.create("http://example.com/base/");
|
||||
@SuppressWarnings("unused") // Is injected
|
||||
private final ResourceLinks resourceLinks = ResourceLinksMock.createMock(baseUri);
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private RepositoryServiceFactory serviceFactory;
|
||||
|
||||
@InjectMocks
|
||||
private RepositoryToRepositoryDtoMapperImpl mapper;
|
||||
@@ -40,6 +48,7 @@ public class RepositoryToRepositoryDtoMapperTest {
|
||||
@Before
|
||||
public void init() {
|
||||
initMocks(this);
|
||||
when(serviceFactory.create(any(Repository.class)).isSupported(any(Command.class))).thenReturn(true);
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -103,7 +112,7 @@ public class RepositoryToRepositoryDtoMapperTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateTagsLink() {
|
||||
public void shouldCreateTagsLink_ifSupported() {
|
||||
RepositoryDto dto = mapper.map(createTestRepository());
|
||||
assertEquals(
|
||||
"http://example.com/base/v2/repositories/testspace/test/tags/",
|
||||
@@ -111,13 +120,27 @@ public class RepositoryToRepositoryDtoMapperTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateBranchesLink() {
|
||||
public void shouldCreateBranchesLink_ifSupported() {
|
||||
RepositoryDto dto = mapper.map(createTestRepository());
|
||||
assertEquals(
|
||||
"http://example.com/base/v2/repositories/testspace/test/branches/",
|
||||
dto.getLinks().getLinkBy("branches").get().getHref());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotCreateTagsLink_ifNotSupported() {
|
||||
when(serviceFactory.create(any(Repository.class)).isSupported(Command.TAGS)).thenReturn(false);
|
||||
RepositoryDto dto = mapper.map(createTestRepository());
|
||||
assertFalse(dto.getLinks().getLinkBy("tags").isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotCreateBranchesLink_ifNotSupported() {
|
||||
when(serviceFactory.create(any(Repository.class)).isSupported(Command.BRANCHES)).thenReturn(false);
|
||||
RepositoryDto dto = mapper.map(createTestRepository());
|
||||
assertFalse(dto.getLinks().getLinkBy("branches").isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateChangesetsLink() {
|
||||
RepositoryDto dto = mapper.map(createTestRepository());
|
||||
|
||||
Reference in New Issue
Block a user