Exemplo n.º 1
0
  @Test
  public void createDuplicatedUser1() {
    createUser();

    UserRepresentation user = new UserRepresentation();
    user.setUsername("user1");
    Response response = realm.users().create(user);
    assertEquals(409, response.getStatus());

    // Just to show how to retrieve underlying error message
    ErrorRepresentation error = response.readEntity(ErrorRepresentation.class);
    Assert.assertEquals("User exists with same username", error.getErrorMessage());

    response.close();
  }
Exemplo n.º 2
0
  @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());
    }
  }