mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-17 02:31:14 +01:00
Added unit tests for PUT/DELETE on groups
This commit is contained in:
@@ -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));
|
||||
@@ -108,6 +109,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