@ApiOperation(value = "Create a user", tags = { "Users" }, code = 201)
    @ApiResponses(value = {
            @ApiResponse(code = 201, message = "Indicates the user was created."),
            @ApiResponse(code = 400, message = "Indicates the id of the user was missing.")

    })
    @PostMapping(value = "/identity/users", produces = "application/json")
    @ResponseStatus(HttpStatus.CREATED)
    public UserResponse createUser(@RequestBody UserRequest userRequest) {
        if (userRequest.getId() == null) {
            throw new FlowableIllegalArgumentException("Id cannot be null.");
        }
        
        if (restApiInterceptor != null) {
            restApiInterceptor.createUser(userRequest);
        }

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

        User created = identityService.newUser(userRequest.getId());
        created.setEmail(userRequest.getEmail());
        created.setFirstName(userRequest.getFirstName());
        created.setLastName(userRequest.getLastName());
        created.setDisplayName(userRequest.getDisplayName());
        created.setPassword(userRequest.getPassword());
        created.setTenantId(userRequest.getTenantId());
        identityService.saveUser(created);

        return restResponseFactory.createUserResponse(created, true);
    }
@Test
    public void testCreateUser() throws Exception {
        try {
            ObjectNode requestNode = objectMapper.createObjectNode();
            requestNode.put("id", "testuser");
            requestNode.put("firstName", "Frederik");
            requestNode.put("lastName", "Heremans");
            requestNode.put("displayName", "Frederik Heremans");
            requestNode.put("password", "test");
            requestNode.put("email", "no-reply@flowable.org");

            HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_COLLECTION, "testuser"));
            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: 'testuser',"
                            + "firstName: 'Frederik',"
                            + "lastName: 'Heremans',"
                            + "displayName: 'Frederik Heremans',"
                            + "email: 'no-reply@flowable.org',"
                            + "url: '" + SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER, "testuser") + "'"
                            + "}");

            User createdUser = identityService.createUserQuery().userId("testuser").singleResult();
            assertThat(createdUser).isNotNull();
            assertThat(createdUser.getFirstName()).isEqualTo("Frederik");
            assertThat(createdUser.getLastName()).isEqualTo("Heremans");
            assertThat(createdUser.getDisplayName()).isEqualTo("Frederik Heremans");
            assertThat(createdUser.getPassword()).isEqualTo("test");
            assertThat(createdUser.getEmail()).isEqualTo("no-reply@flowable.org");
        } finally {
            try {
                identityService.deleteUser("testuser");
            } catch (Throwable t) {
                // Ignore, user might not have been created by test
            }
        }
    }