mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 08:55:44 +01:00
Merge
This commit is contained in:
@@ -1,23 +1,13 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
|
||||
import com.webcohesion.enunciate.metadata.rs.ResponseHeader;
|
||||
import com.webcohesion.enunciate.metadata.rs.ResponseHeaders;
|
||||
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
||||
import com.webcohesion.enunciate.metadata.rs.TypeHint;
|
||||
import com.webcohesion.enunciate.metadata.rs.*;
|
||||
import sonia.scm.group.Group;
|
||||
import sonia.scm.group.GroupException;
|
||||
import sonia.scm.group.GroupManager;
|
||||
import sonia.scm.web.VndMediaType;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DefaultValue;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -60,7 +50,7 @@ public class GroupCollectionResource {
|
||||
})
|
||||
public Response getAll(@DefaultValue("0") @QueryParam("page") int page,
|
||||
@DefaultValue("" + DEFAULT_PAGE_SIZE) @QueryParam("pageSize") int pageSize,
|
||||
@QueryParam("sortby") String sortBy,
|
||||
@QueryParam("sortBy") String sortBy,
|
||||
@DefaultValue("false")
|
||||
@QueryParam("desc") boolean desc) {
|
||||
return adapter.getAll(page, pageSize, sortBy, desc,
|
||||
|
||||
@@ -89,6 +89,7 @@ public class GroupResource {
|
||||
@Consumes(VndMediaType.GROUP)
|
||||
@StatusCodes({
|
||||
@ResponseCode(code = 204, condition = "update success"),
|
||||
@ResponseCode(code = 400, condition = "Invalid body, e.g. illegal change of id/group name"),
|
||||
@ResponseCode(code = 401, condition = "not authenticated / invalid credentials"),
|
||||
@ResponseCode(code = 403, condition = "not authorized, the current user does not have the \"group\" privilege"),
|
||||
@ResponseCode(code = 404, condition = "not found, no group with the specified id/name available"),
|
||||
|
||||
@@ -89,6 +89,7 @@ public class UserResource {
|
||||
@Consumes(VndMediaType.USER)
|
||||
@StatusCodes({
|
||||
@ResponseCode(code = 204, condition = "update success"),
|
||||
@ResponseCode(code = 400, condition = "Invalid body, e.g. illegal change of id/user name"),
|
||||
@ResponseCode(code = 401, condition = "not authenticated / invalid credentials"),
|
||||
@ResponseCode(code = 403, condition = "not authorized, the current user does not have the \"user\" privilege"),
|
||||
@ResponseCode(code = 404, condition = "not found, no user with the specified id/name available"),
|
||||
|
||||
@@ -65,6 +65,7 @@ public class GroupRootResourceTest {
|
||||
public void prepareEnvironment() throws IOException, GroupException {
|
||||
initMocks(this);
|
||||
doNothing().when(groupManager).create(groupCaptor.capture());
|
||||
doNothing().when(groupManager).modify(groupCaptor.capture());
|
||||
|
||||
Group group = createDummyGroup();
|
||||
when(groupManager.getPage(any(), eq(0), eq(10))).thenReturn(new PageResult<>(singletonList(group), 1));
|
||||
@@ -107,6 +108,74 @@ public class GroupRootResourceTest {
|
||||
assertTrue(response.getContentAsString().contains("\"name\":\"user\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldUpdateGroup() throws URISyntaxException, IOException {
|
||||
URL url = Resources.getResource("sonia/scm/api/v2/group-test-update.json");
|
||||
byte[] groupJson = Resources.toByteArray(url);
|
||||
|
||||
Group group = createDummyGroup();
|
||||
when(groupManager.get("admin")).thenReturn(group);
|
||||
Group updatedGroup = createDummyGroup();
|
||||
updatedGroup.setDescription("Updated description");
|
||||
|
||||
MockHttpRequest request = MockHttpRequest
|
||||
.put("/" + GroupRootResource.GROUPS_PATH_V2 + "admin")
|
||||
.contentType(VndMediaType.GROUP)
|
||||
.content(groupJson);
|
||||
|
||||
MockHttpResponse response = new MockHttpResponse();
|
||||
|
||||
dispatcher.invoke(request, response);
|
||||
Group capturedGroup = groupCaptor.getValue();
|
||||
|
||||
assertEquals(HttpServletResponse.SC_NO_CONTENT, response.getStatus());
|
||||
|
||||
assertEquals("Updated description", capturedGroup.getDescription());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateShouldFailOnNonexistentGroup() throws URISyntaxException, IOException {
|
||||
URL url = Resources.getResource("sonia/scm/api/v2/group-test-update.json");
|
||||
byte[] groupJson = Resources.toByteArray(url);
|
||||
|
||||
Group updatedGroup = createDummyGroup();
|
||||
updatedGroup.setDescription("Updated description");
|
||||
|
||||
MockHttpRequest request = MockHttpRequest
|
||||
.put("/" + GroupRootResource.GROUPS_PATH_V2 + "idontexist")
|
||||
.contentType(VndMediaType.GROUP)
|
||||
.content(groupJson);
|
||||
|
||||
MockHttpResponse response = new MockHttpResponse();
|
||||
|
||||
dispatcher.invoke(request, response);
|
||||
|
||||
assertEquals(HttpServletResponse.SC_NOT_FOUND, response.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDeleteGroup() throws URISyntaxException {
|
||||
Group group = createDummyGroup();
|
||||
when(groupManager.get("admin")).thenReturn(group);
|
||||
|
||||
MockHttpRequest request = MockHttpRequest.delete("/" + GroupRootResource.GROUPS_PATH_V2 + "admin");
|
||||
MockHttpResponse response = new MockHttpResponse();
|
||||
|
||||
dispatcher.invoke(request, response);
|
||||
|
||||
assertEquals(HttpServletResponse.SC_NO_CONTENT, response.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotFailOnDeletingNonexistentGroup() throws URISyntaxException {
|
||||
MockHttpRequest request = MockHttpRequest.delete("/" + GroupRootResource.GROUPS_PATH_V2 + "idontexist");
|
||||
MockHttpResponse response = new MockHttpResponse();
|
||||
|
||||
dispatcher.invoke(request, response);
|
||||
|
||||
assertEquals(HttpServletResponse.SC_NO_CONTENT, response.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateNewGroupWithMembers() throws URISyntaxException, IOException {
|
||||
URL url = Resources.getResource("sonia/scm/api/v2/group-test-create.json");
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"description": "Updated description",
|
||||
"name": "admin",
|
||||
"_embedded": {
|
||||
"members": [
|
||||
{
|
||||
"name": "user"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user