@ApiOperation(value = "Create a group", tags = { "Groups" }, code = 201)
    @ApiResponses(value = {
            @ApiResponse(code = 201, message = "Indicates the group was created."),
            @ApiResponse(code = 400, message = "Indicates the id of the group was missing.")
    })
    @PostMapping(value = "/identity/groups", produces = "application/json")
    @ResponseStatus(HttpStatus.CREATED)
    public GroupResponse createGroup(@RequestBody GroupRequest groupRequest) {
        if (groupRequest.getId() == null) {
            throw new FlowableIllegalArgumentException("Id cannot be null.");
        }
        
        if (restApiInterceptor != null) {
            restApiInterceptor.createGroup(groupRequest);
        }

        // Check if a user with the given ID already exists so we return a CONFLICT
        if (identityService.createGroupQuery().groupId(groupRequest.getId()).count() > 0) {
            throw new FlowableConflictException("A group with id '" + groupRequest.getId() + "' already exists.");
        }

        Group created = identityService.newGroup(groupRequest.getId());
        created.setId(groupRequest.getId());
        created.setName(groupRequest.getName());
        created.setType(groupRequest.getType());
        identityService.saveGroup(created);

        return restResponseFactory.createGroupResponse(created);
    }
@Test
    public void testCreateGroup() throws Exception {
        try {
            ObjectNode requestNode = objectMapper.createObjectNode();
            requestNode.put("id", "testgroup");
            requestNode.put("name", "Test group");
            requestNode.put("type", "Test type");

            HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_COLLECTION));
            httpPost.setEntity(new StringEntity(requestNode.toString()));
            CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);
            JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
            closeResponse(response);
            assertThat(responseNode).isNotNull();
            assertThatJson(responseNode)
                    .when(Option.IGNORING_EXTRA_FIELDS)
                    .isEqualTo("{"
                            + " id: 'testgroup',"
                            + " name: 'Test group',"
                            + " type: 'Test type',"
                            + " url: '" + SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, "testgroup") + "'"
                            + "}");

            assertThat(identityService.createGroupQuery().groupId("testgroup").singleResult()).isNotNull();
        } finally {
            try {
                identityService.deleteGroup("testgroup");
            } catch (Throwable t) {
                // Ignore, user might not have been created by test
            }
        }
    }