This commit is contained in:
René Pfeuffer
2018-06-28 12:00:57 +02:00
5 changed files with 85 additions and 13 deletions

View File

@@ -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");