import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.assertj.core.api.AssertionsForClassTypes.tuple;
import static org.assertj.core.api.Fail.fail;
class ScimUserDaoIT {
List<String> expectedScimUserUuids) {
generateScimUsers(totalScimUsers);
- List<ScimUserDto> scimUserDtos = scimUserDao.findScimUsers(dbSession, ScimUserQuery.empty(), OffsetBasedPagination.forOffset(offset,
+ List<ScimUserWithUsernameDto> scimUserDtos = scimUserDao.findScimUsers(dbSession, ScimUserQuery.empty(), OffsetBasedPagination.forOffset(offset,
pageSize));
List<String> scimUsersUuids = toScimUsersUuids(scimUserDtos);
assertThat(scimUsersUuids).containsExactlyElementsOf(expectedScimUserUuids);
}
- private List<String> toScimUsersUuids(Collection<ScimUserDto> scimUserDtos) {
+ private List<String> toScimUsersUuids(Collection<ScimUserWithUsernameDto> scimUserDtos) {
return scimUserDtos.stream()
- .map(ScimUserDto::getScimUserUuid)
+ .map(ScimUserWithUsernameDto::getScimUserUuid)
.toList();
}
insertScimUsersWithUsers(userLogins);
ScimUserQuery query = ScimUserQuery.builder().userName(search).build();
- List<ScimUserDto> scimUsersByQuery = scimUserDao.findScimUsers(dbSession, query, Pagination.all());
+ List<ScimUserWithUsernameDto> scimUsersByQuery = scimUserDao.findScimUsers(dbSession, query, Pagination.all());
List<String> scimUsersUuids = toScimUsersUuids(scimUsersByQuery);
assertThat(scimUsersUuids).containsExactlyElementsOf(expectedScimUserUuids);
ScimUserQuery query = ScimUserQuery.builder().groupUuid(group1dto.getUuid()).build();
- List<ScimUserDto> scimUsers = scimUserDao.findScimUsers(dbSession, query, Pagination.all());
+ List<ScimUserWithUsernameDto> scimUsers = scimUserDao.findScimUsers(dbSession, query, Pagination.all());
List<String> scimUsersUuids = toScimUsersUuids(scimUsers);
assertThat(scimUsersUuids).containsExactlyInAnyOrder(
);
}
+ @Test
+ void findScimUsers_shouldReturnTheExpectedScimUsersWithUsername() {
+ insertScimUsersWithUsers(List.of("userA", "userB"));
+
+ ScimUserQuery query = ScimUserQuery.builder().userName("userA").build();
+
+ List<ScimUserWithUsernameDto> scimUsers = scimUserDao.findScimUsers(dbSession, query, Pagination.all());
+
+ List<String> scimUsersUuids = toScimUsersUuids(scimUsers);
+
+ assertThat(scimUsers)
+ .extracting(ScimUserWithUsernameDto::getScimUserUuid, ScimUserWithUsernameDto::getUserName)
+ .contains(
+ tuple(scimUsersUuids.get(0), "userA")
+ );
+ }
+
private GroupDto createGroupWithUsers(ScimUserTestData... testUsers) {
GroupDto group = db.users().insertGroup();
ScimUserQuery query = ScimUserQuery.builder().scimUserUuids(expectedScimUserUuids).build();
- List<ScimUserDto> scimUsersByQuery = scimUserDao.findScimUsers(dbSession, query, Pagination.all());
+ List<ScimUserWithUsernameDto> scimUsersByQuery = scimUserDao.findScimUsers(dbSession, query, Pagination.all());
List<String> scimUsersUuids = toScimUsersUuids(scimUsersByQuery);
assertThat(scimUsersByQuery)
ScimUserQuery query = ScimUserQuery.builder().scimUserUuids(scimUserUuids).userName("username_5").build();
- List<ScimUserDto> scimUsersByQuery = scimUserDao.findScimUsers(dbSession, query, Pagination.all());
+ List<ScimUserWithUsernameDto> scimUsersByQuery = scimUserDao.findScimUsers(dbSession, query, Pagination.all());
assertThat(scimUsersByQuery).hasSize(1)
- .extracting(ScimUserDto::getScimUserUuid)
+ .extracting(ScimUserWithUsernameDto::getScimUserUuid)
.contains("6");
}
ScimUserQuery query = ScimUserQuery.builder().userUuids(allUsersUuid).build();
- List<ScimUserDto> scimUsersByQuery = scimUserDao.findScimUsers(dbSession, query, Pagination.all());
+ List<ScimUserWithUsernameDto> scimUsersByQuery = scimUserDao.findScimUsers(dbSession, query, Pagination.all());
assertThat(scimUsersByQuery)
.hasSameSizeAs(allUsersUuid)
- .extracting(ScimUserDto::getUserUuid)
+ .extracting(ScimUserWithUsernameDto::getUserUuid)
.containsAll(allUsersUuid);
}
ScimUserQuery query = ScimUserQuery.builder().userUuids(allUsersUuid).userName("username_5").build();
- List<ScimUserDto> scimUsersByQuery = scimUserDao.findScimUsers(dbSession, query, Pagination.all());
+ List<ScimUserWithUsernameDto> scimUsersByQuery = scimUserDao.findScimUsers(dbSession, query, Pagination.all());
assertThat(scimUsersByQuery).hasSize(1)
- .extracting(ScimUserDto::getScimUserUuid)
+ .extracting(ScimUserWithUsernameDto::getScimUserUuid)
.contains("6");
}
return scimUserDto;
}
- public List<ScimUserDto> findScimUsers(DbSession dbSession, ScimUserQuery scimUserQuery, Pagineable pagination) {
+ public List<ScimUserWithUsernameDto> findScimUsers(DbSession dbSession, ScimUserQuery scimUserQuery, Pagineable pagination) {
checkState(scimUserQuery.getUserUuids() == null || scimUserQuery.getScimUserUuids() == null,
"Only one of userUuids & scimUserUuids request parameter is supported.");
if (scimUserQuery.getScimUserUuids() != null) {
return mapper(dbSession).findScimUsers(scimUserQuery, pagination);
}
- private static List<ScimUserDto> createPartialQuery(ScimUserQuery completeQuery, List<String> strings,
+ private static List<ScimUserWithUsernameDto> createPartialQuery(ScimUserQuery completeQuery, List<String> strings,
BiFunction<ScimUserQuery.ScimUserQueryBuilder, List<String>, ScimUserQuery.ScimUserQueryBuilder> queryModifier,
DbSession dbSession, Pagineable pagination) {
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.scim;
+
+public final class ScimUserWithUsernameDto extends ScimUserDto {
+
+ private String userName;
+
+ public ScimUserWithUsernameDto(String scimUserUuid, String userUuid, String userName) {
+ super(scimUserUuid, userUuid);
+ this.userName = userName;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+}