public void documentFindAllUsers()

in component-test/src/main/java/IdentityApiDocumentation.java [443:484]


  public void documentFindAllUsers ( ) throws InterruptedException {

    final String username = createUserWithNonexpiredPassword(AHMES_PASSWORD, ADMIN_ROLE);

    final Authentication userAuthentication =
            getTestSubject().login(username, TestEnvironment.encodePassword(AHMES_PASSWORD));

    try (final AutoUserContext ignored = new AutoUserContext(username, userAuthentication.getAccessToken())) {

      UserWithPassword ahmesFriend = new UserWithPassword("Ahmes_friend", "scribe",
              TestEnvironment.encodePassword(AHMES_FRIENDS_PASSWORD));
      getTestSubject().createUser(ahmesFriend);
      final boolean found = eventRecorder.wait(EventConstants.OPERATION_POST_USER, ahmesFriend.getIdentifier());
      Assert.assertTrue(found);

      UserWithPassword ahmesOtherFriend = new UserWithPassword("Ahmes_Other_friend", "cobbler",
              TestEnvironment.encodePassword(AHMES_FRIENDS_PASSWORD + "Other"));
      getTestSubject().createUser(ahmesOtherFriend);
      Assert.assertTrue(eventRecorder.wait(EventConstants.OPERATION_POST_USER, ahmesOtherFriend.getIdentifier()));

      try {
        this.mockMvc.perform(get("/users")
                .accept(MediaType.ALL_VALUE)
                .contentType(MediaType.APPLICATION_JSON_VALUE))
                .andExpect(status().isOk())
                .andDo(document("document-find-all-users", preprocessResponse(prettyPrint()),
                        responseFields(
                                fieldWithPath("[].identifier").description("first user's identifier"),
                                fieldWithPath("[].role").description("first user's role"),
                                fieldWithPath("[1].identifier").description("second user's identifier"),
                                fieldWithPath("[1].role").description("second user's role"),
                                fieldWithPath("[2].identifier").description("third user's identifier"),
                                fieldWithPath("[2].role").description("third user's role"),
                                fieldWithPath("[3].identifier").description("fourth user's identifier"),
                                fieldWithPath("[3].role").description("fourth user's role")
                        )
                ));
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }