Rename group resource classes

This commit is contained in:
René Pfeuffer
2018-06-22 08:28:18 +02:00
parent ed1417b2ea
commit 5836688f30
7 changed files with 29 additions and 29 deletions

View File

@@ -23,12 +23,12 @@ import javax.ws.rs.core.UriInfo;
import java.util.Collection; import java.util.Collection;
@Produces(VndMediaType.GROUP) @Produces(VndMediaType.GROUP)
public class GroupSubResource extends AbstractManagerResource<Group, GroupException> { public class GroupResource extends AbstractManagerResource<Group, GroupException> {
private final GroupToGroupDtoMapper groupToGroupDtoMapper; private final GroupToGroupDtoMapper groupToGroupDtoMapper;
@Inject @Inject
public GroupSubResource(GroupManager manager, GroupToGroupDtoMapper groupToGroupDtoMapper) { public GroupResource(GroupManager manager, GroupToGroupDtoMapper groupToGroupDtoMapper) {
super(manager); super(manager);
this.groupToGroupDtoMapper = groupToGroupDtoMapper; this.groupToGroupDtoMapper = groupToGroupDtoMapper;
} }

View File

@@ -3,18 +3,18 @@ package sonia.scm.api.v2.resources;
import javax.inject.Inject; import javax.inject.Inject;
import javax.ws.rs.Path; import javax.ws.rs.Path;
@Path(GroupV2Resource.GROUPS_PATH_V2) @Path(GroupRootResource.GROUPS_PATH_V2)
public class GroupV2Resource { public class GroupRootResource {
public static final String GROUPS_PATH_V2 = "v2/groups/"; public static final String GROUPS_PATH_V2 = "v2/groups/";
private final GroupCollectionResource groupCollectionResource; private final GroupCollectionResource groupCollectionResource;
private final GroupSubResource groupSubResource; private final GroupResource groupResource;
@Inject @Inject
public GroupV2Resource(GroupCollectionResource groupCollectionResource, GroupSubResource groupSubResource) { public GroupRootResource(GroupCollectionResource groupCollectionResource, GroupResource groupResource) {
this.groupCollectionResource = groupCollectionResource; this.groupCollectionResource = groupCollectionResource;
this.groupSubResource = groupSubResource; this.groupResource = groupResource;
} }
@Path("") @Path("")
@@ -23,7 +23,7 @@ public class GroupV2Resource {
} }
@Path("{id}") @Path("{id}")
public GroupSubResource getGroupSubResource() { public GroupResource getGroupResource() {
return groupSubResource; return groupResource;
} }
} }

View File

@@ -15,19 +15,19 @@ class ResourceLinks {
private final LinkBuilder groupLinkBuilder; private final LinkBuilder groupLinkBuilder;
private GroupLinks(UriInfo uriInfo) { private GroupLinks(UriInfo uriInfo) {
groupLinkBuilder = new LinkBuilder(uriInfo, GroupV2Resource.class, GroupSubResource.class); groupLinkBuilder = new LinkBuilder(uriInfo, GroupRootResource.class, GroupResource.class);
} }
String self(String name) { String self(String name) {
return groupLinkBuilder.method("getGroupSubResource").parameters(name).method("get").parameters().href(); return groupLinkBuilder.method("getGroupResource").parameters(name).method("get").parameters().href();
} }
String delete(String name) { String delete(String name) {
return groupLinkBuilder.method("getGroupSubResource").parameters(name).method("delete").parameters().href(); return groupLinkBuilder.method("getGroupResource").parameters(name).method("delete").parameters().href();
} }
String update(String name) { String update(String name) {
return groupLinkBuilder.method("getGroupSubResource").parameters(name).method("update").parameters().href(); return groupLinkBuilder.method("getGroupResource").parameters(name).method("update").parameters().href();
} }
} }
@@ -39,7 +39,7 @@ class ResourceLinks {
private final LinkBuilder collectionLinkBuilder; private final LinkBuilder collectionLinkBuilder;
private GroupCollectionLinks(UriInfo uriInfo) { private GroupCollectionLinks(UriInfo uriInfo) {
collectionLinkBuilder = new LinkBuilder(uriInfo, GroupV2Resource.class, GroupCollectionResource.class); collectionLinkBuilder = new LinkBuilder(uriInfo, GroupRootResource.class, GroupCollectionResource.class);
} }
String self() { String self() {

View File

@@ -41,7 +41,7 @@ public class GroupCollectionToDtoMapperTest {
public void init() throws URISyntaxException { public void init() throws URISyntaxException {
uriInfoStore.set(uriInfo); uriInfoStore.set(uriInfo);
URI baseUri = new URI("http://example.com/base/"); URI baseUri = new URI("http://example.com/base/");
expectedBaseUri = baseUri.resolve(GroupV2Resource.GROUPS_PATH_V2 + "/"); expectedBaseUri = baseUri.resolve(GroupRootResource.GROUPS_PATH_V2 + "/");
when(uriInfo.getBaseUri()).thenReturn(baseUri); when(uriInfo.getBaseUri()).thenReturn(baseUri);
subjectThreadState.bind(); subjectThreadState.bind();
ThreadContext.bind(subject); ThreadContext.bind(subject);

View File

@@ -38,7 +38,7 @@ import static org.mockito.MockitoAnnotations.initMocks;
password = "secret", password = "secret",
configuration = "classpath:sonia/scm/repository/shiro.ini" configuration = "classpath:sonia/scm/repository/shiro.ini"
) )
public class GroupV2ResourceTest { public class GroupRootResourceTest {
@Rule @Rule
public ShiroRule shiro = new ShiroRule(); public ShiroRule shiro = new ShiroRule();
@@ -73,10 +73,10 @@ public class GroupV2ResourceTest {
when(groupManager.get("admin")).thenReturn(group); when(groupManager.get("admin")).thenReturn(group);
GroupCollectionResource groupCollectionResource = new GroupCollectionResource(groupManager, dtoToGroupMapper, groupToDtoMapper, groupCollectionToDtoMapper); GroupCollectionResource groupCollectionResource = new GroupCollectionResource(groupManager, dtoToGroupMapper, groupToDtoMapper, groupCollectionToDtoMapper);
GroupSubResource groupSubResource = new GroupSubResource(groupManager, groupToDtoMapper); GroupResource groupResource = new GroupResource(groupManager, groupToDtoMapper);
GroupV2Resource groupV2Resource = new GroupV2Resource(groupCollectionResource, groupSubResource); GroupRootResource groupRootResource = new GroupRootResource(groupCollectionResource, groupResource);
dispatcher.getRegistry().addSingletonResource(groupV2Resource); dispatcher.getRegistry().addSingletonResource(groupRootResource);
when(uriInfo.getBaseUri()).thenReturn(URI.create("/")); when(uriInfo.getBaseUri()).thenReturn(URI.create("/"));
when(uriInfoStore.get()).thenReturn(uriInfo); when(uriInfoStore.get()).thenReturn(uriInfo);
@@ -84,7 +84,7 @@ public class GroupV2ResourceTest {
@Test @Test
public void shouldGetNotFoundForNotExistentGroup() throws URISyntaxException { public void shouldGetNotFoundForNotExistentGroup() throws URISyntaxException {
MockHttpRequest request = MockHttpRequest.get("/" + GroupV2Resource.GROUPS_PATH_V2 + "nosuchgroup"); MockHttpRequest request = MockHttpRequest.get("/" + GroupRootResource.GROUPS_PATH_V2 + "nosuchgroup");
MockHttpResponse response = new MockHttpResponse(); MockHttpResponse response = new MockHttpResponse();
dispatcher.invoke(request, response); dispatcher.invoke(request, response);
@@ -95,7 +95,7 @@ public class GroupV2ResourceTest {
@Test @Test
@SubjectAware(username = "unpriv") @SubjectAware(username = "unpriv")
public void shouldGetNotAuthorizedForWrongUser() throws URISyntaxException { public void shouldGetNotAuthorizedForWrongUser() throws URISyntaxException {
MockHttpRequest request = MockHttpRequest.get("/" + GroupV2Resource.GROUPS_PATH_V2 + "admin"); MockHttpRequest request = MockHttpRequest.get("/" + GroupRootResource.GROUPS_PATH_V2 + "admin");
MockHttpResponse response = new MockHttpResponse(); MockHttpResponse response = new MockHttpResponse();
dispatcher.invoke(request, response); dispatcher.invoke(request, response);
@@ -111,7 +111,7 @@ public class GroupV2ResourceTest {
group.setMembers(Collections.singletonList("user")); group.setMembers(Collections.singletonList("user"));
when(groupManager.get("admin")).thenReturn(group); when(groupManager.get("admin")).thenReturn(group);
MockHttpRequest request = MockHttpRequest.get("/" + GroupV2Resource.GROUPS_PATH_V2 + "admin"); MockHttpRequest request = MockHttpRequest.get("/" + GroupRootResource.GROUPS_PATH_V2 + "admin");
MockHttpResponse response = new MockHttpResponse(); MockHttpResponse response = new MockHttpResponse();
dispatcher.invoke(request, response); dispatcher.invoke(request, response);
@@ -129,7 +129,7 @@ public class GroupV2ResourceTest {
byte[] groupJson = Resources.toByteArray(url); byte[] groupJson = Resources.toByteArray(url);
MockHttpRequest request = MockHttpRequest MockHttpRequest request = MockHttpRequest
.post("/" + GroupV2Resource.GROUPS_PATH_V2) .post("/" + GroupRootResource.GROUPS_PATH_V2)
.contentType(VndMediaType.GROUP) .contentType(VndMediaType.GROUP)
.content(groupJson); .content(groupJson);
MockHttpResponse response = new MockHttpResponse(); MockHttpResponse response = new MockHttpResponse();

View File

@@ -41,7 +41,7 @@ public class GroupToGroupDtoMapperTest {
public void init() throws URISyntaxException { public void init() throws URISyntaxException {
initMocks(this); initMocks(this);
URI baseUri = new URI("http://example.com/base/"); URI baseUri = new URI("http://example.com/base/");
expectedBaseUri = baseUri.resolve(GroupV2Resource.GROUPS_PATH_V2 + "/"); expectedBaseUri = baseUri.resolve(GroupRootResource.GROUPS_PATH_V2 + "/");
when(uriInfo.getBaseUri()).thenReturn(baseUri); when(uriInfo.getBaseUri()).thenReturn(baseUri);
when(uriInfoStore.get()).thenReturn(uriInfo); when(uriInfoStore.get()).thenReturn(uriInfo);
subjectThreadState.bind(); subjectThreadState.bind();

View File

@@ -52,31 +52,31 @@ public class ResourceLinksTest {
@Test @Test
public void shouldCreateCorrectGroupSelfUrl() { public void shouldCreateCorrectGroupSelfUrl() {
String url = group(uriInfo).self("nobodies"); String url = group(uriInfo).self("nobodies");
assertEquals(BASE_URL + GroupV2Resource.GROUPS_PATH_V2 + "nobodies", url); assertEquals(BASE_URL + GroupRootResource.GROUPS_PATH_V2 + "nobodies", url);
} }
@Test @Test
public void shouldCreateCorrectGroupDeleteUrl() { public void shouldCreateCorrectGroupDeleteUrl() {
String url = group(uriInfo).delete("nobodies"); String url = group(uriInfo).delete("nobodies");
assertEquals(BASE_URL + GroupV2Resource.GROUPS_PATH_V2 + "nobodies", url); assertEquals(BASE_URL + GroupRootResource.GROUPS_PATH_V2 + "nobodies", url);
} }
@Test @Test
public void shouldCreateCorrectGroupUpdateUrl() { public void shouldCreateCorrectGroupUpdateUrl() {
String url = group(uriInfo).update("nobodies"); String url = group(uriInfo).update("nobodies");
assertEquals(BASE_URL + GroupV2Resource.GROUPS_PATH_V2 + "nobodies", url); assertEquals(BASE_URL + GroupRootResource.GROUPS_PATH_V2 + "nobodies", url);
} }
// @Test // @Test
// public void shouldCreateCorrectGroupCreateUrl() { // public void shouldCreateCorrectGroupCreateUrl() {
// String url = ResourceLinks.groupCollection(uriInfo).create(); // String url = ResourceLinks.groupCollection(uriInfo).create();
// assertEquals(BASE_URL + GroupV2Resource.GROUPS_PATH_V2, url); // assertEquals(BASE_URL + GroupRootResource.GROUPS_PATH_V2, url);
// } // }
// //
// @Test // @Test
// public void shouldCreateCorrectGroupCollectionUrl() { // public void shouldCreateCorrectGroupCollectionUrl() {
// String url = ResourceLinks.groupCollection(uriInfo).self(); // String url = ResourceLinks.groupCollection(uriInfo).self();
// assertEquals(BASE_URL + GroupV2Resource.GROUPS_PATH_V2, url); // assertEquals(BASE_URL + GroupRootResource.GROUPS_PATH_V2, url);
// } // }
@Before @Before