public String createUser() {
    UserRepresentation user = new UserRepresentation();
    user.setUsername("user1");
    user.setEmail("user1@localhost");

    Response response = realm.users().create(user);
    String createdId = ApiUtil.getCreatedId(response);
    response.close();
    return createdId;
  }
  @Test
  public void createDuplicatedUser5() {
    createUser();

    UserRepresentation user = new UserRepresentation();
    user.setUsername("user2");
    user.setEmail("User1@localhost");
    Response response = realm.users().create(user);
    assertEquals(409, response.getStatus());
    response.close();
  }
  private void createUsers() {
    for (int i = 1; i < 10; i++) {
      UserRepresentation user = new UserRepresentation();
      user.setUsername("username" + i);
      user.setEmail("user" + i + "@localhost");
      user.setFirstName("First" + i);
      user.setLastName("Last" + i);

      realm.users().create(user).close();
    }
  }
  @Before
  public void createUser() {
    log.debug("creating user for realm " + bc.providerRealmName());

    UserRepresentation user = new UserRepresentation();
    user.setUsername(bc.getUserLogin());
    user.setEmail(bc.getUserEmail());
    user.setEmailVerified(true);
    user.setEnabled(true);

    RealmResource realmResource = adminClient.realm(bc.providerRealmName());
    String userId = createUserWithAdminClient(realmResource, user);

    resetUserPassword(realmResource.users().get(userId), bc.getUserPassword(), false);
  }
  @Test
  public void sendVerifyEmail() {
    UserRepresentation userRep = new UserRepresentation();
    userRep.setUsername("user1");
    Response response = realm.users().create(userRep);
    String id = ApiUtil.getCreatedId(response);
    response.close();

    UserResource user = realm.users().get(id);

    try {
      user.sendVerifyEmail();
      fail("Expected failure");
    } catch (ClientErrorException e) {
      assertEquals(400, e.getResponse().getStatus());

      ErrorRepresentation error = e.getResponse().readEntity(ErrorRepresentation.class);
      Assert.assertEquals("User email missing", error.getErrorMessage());
    }
    try {
      userRep = user.toRepresentation();
      userRep.setEmail("user1@localhost");
      userRep.setEnabled(false);
      user.update(userRep);
      user.sendVerifyEmail();
      fail("Expected failure");
    } catch (ClientErrorException e) {
      assertEquals(400, e.getResponse().getStatus());

      ErrorRepresentation error = e.getResponse().readEntity(ErrorRepresentation.class);
      Assert.assertEquals("User is disabled", error.getErrorMessage());
    }
    try {
      userRep.setEnabled(true);
      user.update(userRep);
      user.sendVerifyEmail("invalidClientId");
      fail("Expected failure");
    } catch (ClientErrorException e) {
      assertEquals(400, e.getResponse().getStatus());

      ErrorRepresentation error = e.getResponse().readEntity(ErrorRepresentation.class);
      Assert.assertEquals("invalidClientId not enabled", error.getErrorMessage());
    }
  }