@ApiOperation(value = "Delete a member from a group", tags = { "Groups" }, code = 204)
    @ApiResponses(value = {
            @ApiResponse(code = 204, message = "Indicates the group was found and the member has been deleted. The response body is left empty intentionally."),
            @ApiResponse(code = 404, message = "Indicates the requested group was not found or that the user is not a member of the group. The status description contains additional information about the error.")
    })
    @DeleteMapping("/identity/groups/{groupId}/members/{userId}")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public void deleteMembership(@ApiParam(name = "groupId") @PathVariable("groupId") String groupId, @ApiParam(name = "userId") @PathVariable("userId") String userId) {

        Group group = getGroupFromRequest(groupId);

        // Check if user is not a member of group since API does not return typed exception
        if (identityService.createUserQuery().memberOfGroup(group.getId()).userId(userId).count() != 1) {
            throw new FlowableObjectNotFoundException("User '" + userId + "' is not part of group '" + group.getId() + "'.", null);
        }

        identityService.deleteMembership(userId, group.getId());
    }
@Test
    public void testDeleteMembership() throws Exception {
        try {
            Group testGroup = identityService.newGroup("testgroup");
            testGroup.setName("Test group");
            testGroup.setType("Test type");
            identityService.saveGroup(testGroup);

            User testUser = identityService.newUser("testuser");
            identityService.saveUser(testUser);

            identityService.createMembership("testuser", "testgroup");

            HttpDelete httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_MEMBERSHIP, "testgroup", "testuser"));
            CloseableHttpResponse response = executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT);
            closeResponse(response);

            // Check if membership is actually deleted
            assertThat(identityService.createUserQuery().memberOfGroup("testgroup").singleResult()).isNull();
        } finally {
            try {
                identityService.deleteGroup("testgroup");
            } catch (Throwable ignore) {
                // Ignore, since the group may not have been created in the test
                // or already deleted
            }

            try {
                identityService.deleteUser("testuser");
            } catch (Throwable ignore) {
                // Ignore, since the group may not have been created in the test
                // or already deleted
            }
        }
    }