Generate link to branches for repository

This commit is contained in:
René Pfeuffer
2018-07-04 08:37:57 +02:00
parent fb811ef725
commit 7c662ed42a
10 changed files with 92 additions and 5 deletions

View File

@@ -48,7 +48,7 @@ public class RepositoryRootResourceTest {
public void prepareEnvironment() {
initMocks(this);
ResourceLinksMock.initMock(resourceLinks, URI.create("/"));
RepositoryResource repositoryResource = new RepositoryResource(repositoryToDtoMapper, repositoryManager, null);
RepositoryResource repositoryResource = new RepositoryResource(repositoryToDtoMapper, repositoryManager, null, null);
RepositoryRootResource repositoryRootResource = new RepositoryRootResource(MockProvider.of(repositoryResource));
dispatcher.getRegistry().addSingletonResource(repositoryRootResource);
}

View File

@@ -109,6 +109,14 @@ public class RepositoryToRepositoryDtoMapperTest {
dto.getLinks().getLinkBy("tags").get().getHref());
}
@Test
public void shouldCreateBranchesLink() {
RepositoryDto dto = mapper.map(createTestRepository());
assertEquals(
"http://example.com/base/v2/groups/testspace/test/branches/",
dto.getLinks().getLinkBy("branches").get().getHref());
}
private Repository createTestRepository() {
Repository repository = new Repository();
repository.setNamespace("testspace");

View File

@@ -28,5 +28,7 @@ public class ResourceLinksMock {
when(resourceLinks.repository().delete(anyString(), anyString())).thenAnswer(invocation -> baseUri + GROUPS_PATH_V2 + invocation.getArguments()[0] + "/" + invocation.getArguments()[1]);
when(resourceLinks.tagCollection().self(anyString(), anyString())).thenAnswer(invocation -> baseUri + GROUPS_PATH_V2 + invocation.getArguments()[0] + "/" + invocation.getArguments()[1] + "/tags/");
when(resourceLinks.branchCollection().self(anyString(), anyString())).thenAnswer(invocation -> baseUri + GROUPS_PATH_V2 + invocation.getArguments()[0] + "/" + invocation.getArguments()[1] + "/branches/");
}
}

View File

@@ -108,6 +108,12 @@ public class ResourceLinksTest {
assertEquals(BASE_URL + RepositoryRootResource.REPOSITORIES_PATH_V2 + "space/repo/tags/", url);
}
@Test
public void shouldCreateCorrectBranchCollectionUrl() {
String url = resourceLinks.branchCollection().self("space", "repo");
assertEquals(BASE_URL + RepositoryRootResource.REPOSITORIES_PATH_V2 + "space/repo/branches/", url);
}
@Before
public void initUriInfo() {
initMocks(this);

View File

@@ -37,6 +37,7 @@ import com.github.sdorra.shiro.ShiroRule;
import com.github.sdorra.shiro.SubjectAware;
import com.google.common.collect.ImmutableSet;
import org.apache.shiro.authz.UnauthorizedException;
import org.apache.shiro.util.ThreadContext;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -92,6 +93,10 @@ import static org.mockito.Mockito.when;
)
public class DefaultRepositoryManagerTest extends ManagerTestBase<Repository, RepositoryException> {
{
ThreadContext.unbindSecurityManager();
}
@Rule
public ShiroRule shiro = new ShiroRule();