void testSearchUsersByAttributes()

in src/it/java/com/epam/digital/data/platform/integration/idm/client/KeycloakAuthRestClientIT.java [115:156]


  void testSearchUsersByAttributes() {
    keycloakMockServer.addStubMapping(stubFor(
        post(urlPathEqualTo("/auth/realms/" + realm + "/users/v2/search-by-attributes"))
            .withRequestBody(
                equalToJson(jsonToStr("/json/keycloakSearchUserByAttributesRequest.json")))
            .willReturn(aResponse().withStatus(200)
                .withHeader("Content-type", "application/json")
                .withBody(jsonToStr("/json/keycloakSearchUserByAttributesResponse.json")))));

    var searchRequestDto = SearchUsersByAttributesRequestDto.builder()
        .attributesStartsWith(Map.of("hierarchy", List.of("100")))
        .pagination(Pagination.builder().continueToken(1022).limit(2).build())
        .build();

    var actualIdmUserResponse = idmService.searchUsers(searchRequestDto);

    Assertions.assertThat(actualIdmUserResponse)
        .hasFieldOrProperty("users")
        .hasFieldOrProperty("pagination");
    Assertions.assertThat(actualIdmUserResponse.getUsers())
        .hasSize(2)
        .element(0)
        .hasFieldOrPropertyWithValue("id", "someNextId")
        .hasFieldOrPropertyWithValue("userName", "jane_doe")
        .hasFieldOrPropertyWithValue("fullName", "Jane Doe")
        .hasFieldOrPropertyWithValue("attributes", Map.of(
            KeycloakSystemAttribute.FULL_NAME_ATTRIBUTE, List.of("Jane Doe"),
            KeycloakSystemAttribute.DRFO, List.of("1234567890"),
            "hierarchy", List.of("100.200", "101")));
    Assertions.assertThat(actualIdmUserResponse.getUsers())
        .hasSize(2)
        .element(1)
        .hasFieldOrPropertyWithValue("id", "someId")
        .hasFieldOrPropertyWithValue("userName", "john_doe")
        .hasFieldOrPropertyWithValue("fullName", "John Doe")
        .hasFieldOrPropertyWithValue("attributes", Map.of(
            KeycloakSystemAttribute.FULL_NAME_ATTRIBUTE, List.of("John Doe"),
            KeycloakSystemAttribute.DRFO, List.of("1234567891"),
            "hierarchy", List.of("100")));
    Assertions.assertThat(actualIdmUserResponse.getPagination())
        .hasFieldOrPropertyWithValue("continueToken", 1025);
  }