Added unit tests for PUT/DELETE on groups

This commit is contained in:
Philipp Czora
2018-06-28 11:06:16 +02:00
parent 9ec59b680e
commit ad4ea743a0
2 changed files with 80 additions and 0 deletions

View File

@@ -65,6 +65,7 @@ public class GroupRootResourceTest {
public void prepareEnvironment() throws IOException, GroupException { public void prepareEnvironment() throws IOException, GroupException {
initMocks(this); initMocks(this);
doNothing().when(groupManager).create(groupCaptor.capture()); doNothing().when(groupManager).create(groupCaptor.capture());
doNothing().when(groupManager).modify(groupCaptor.capture());
Group group = createDummyGroup(); Group group = createDummyGroup();
when(groupManager.getPage(any(), eq(0), eq(10))).thenReturn(new PageResult<>(singletonList(group), 1)); 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\"")); 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 @Test
public void shouldCreateNewGroupWithMembers() throws URISyntaxException, IOException { public void shouldCreateNewGroupWithMembers() throws URISyntaxException, IOException {
URL url = Resources.getResource("sonia/scm/api/v2/group-test-create.json"); URL url = Resources.getResource("sonia/scm/api/v2/group-test-create.json");

View File

@@ -0,0 +1,11 @@
{
"description": "Updated description",
"name": "admin",
"_embedded": {
"members": [
{
"name": "user"
}
]
}
}