diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2017-03-24 16:35:10 +0100 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2017-03-24 17:38:54 +0100 |
commit | 48699b502c866ea5a309c57f8ad5e737d1933280 (patch) | |
tree | 81b5e7ed55fe1faf20bb061c8846b7e7f0cf5468 | |
parent | 0d5af9736727386bb2d7e441cb13395855a693cf (diff) | |
download | sonarqube-48699b502c866ea5a309c57f8ad5e737d1933280.tar.gz sonarqube-48699b502c866ea5a309c57f8ad5e737d1933280.zip |
SONAR-8980 Do not user index method getNullableByLogin
4 files changed, 15 insertions, 11 deletions
diff --git a/server/sonar-server/src/test/java/org/sonar/server/organization/OrganizationCreationImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/organization/OrganizationCreationImplTest.java index 14a9bc843cf..5fde346f9e3 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/organization/OrganizationCreationImplTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/organization/OrganizationCreationImplTest.java @@ -47,16 +47,17 @@ import org.sonar.db.user.UserDto; import org.sonar.db.user.UserMembershipDto; import org.sonar.db.user.UserMembershipQuery; import org.sonar.server.es.EsTester; -import org.sonar.server.user.index.UserDoc; -import org.sonar.server.user.index.UserIndex; -import org.sonar.server.user.index.UserIndexDefinition; -import org.sonar.server.user.index.UserIndexer; +import org.sonar.server.es.SearchOptions; import org.sonar.server.language.LanguageTesting; import org.sonar.server.qualityprofile.ActiveRuleChange; import org.sonar.server.qualityprofile.DefinedQProfile; import org.sonar.server.qualityprofile.DefinedQProfileCreationRule; import org.sonar.server.qualityprofile.DefinedQProfileRepositoryRule; import org.sonar.server.qualityprofile.index.ActiveRuleIndexer; +import org.sonar.server.user.index.UserIndex; +import org.sonar.server.user.index.UserIndexDefinition; +import org.sonar.server.user.index.UserIndexer; +import org.sonar.server.user.index.UserQuery; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; @@ -263,7 +264,6 @@ public class OrganizationCreationImplTest { public void create_add_current_user_as_member_of_organization() throws OrganizationCreation.KeyConflictException { UserDto user = dbTester.users().insertUser(); userIndexer.index(user.getLogin()); - UserDoc userDoc = userIndex.getNullableByLogin(user.getLogin()); mockForSuccessfulInsert(SOME_UUID, SOME_DATE); definedQProfileRepositoryRule.initialize(); @@ -272,7 +272,7 @@ public class OrganizationCreationImplTest { underTest.create(dbSession, someUser, FULL_POPULATED_NEW_ORGANIZATION); assertThat(dbClient.organizationMemberDao().select(dbSession, SOME_UUID, someUser.getId())).isPresent(); - assertThat(userIndex.getNullableByLogin(someUser.getLogin()).organizationUuids()).contains(SOME_UUID); + assertThat(userIndex.search(UserQuery.builder().setOrganizationUuid(SOME_UUID).setTextQuery(someUser.getLogin()).build(), new SearchOptions()).getTotal()).isEqualTo(1L); } @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/organization/ws/DeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/organization/ws/DeleteActionTest.java index 3d6c399b2d5..48b9b287138 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/organization/ws/DeleteActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/organization/ws/DeleteActionTest.java @@ -42,6 +42,7 @@ import org.sonar.db.user.GroupDto; import org.sonar.db.user.UserDto; import org.sonar.server.component.ComponentCleanerService; import org.sonar.server.es.EsTester; +import org.sonar.server.es.SearchOptions; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.exceptions.UnauthorizedException; @@ -53,6 +54,7 @@ import org.sonar.server.tester.UserSessionRule; import org.sonar.server.user.index.UserIndex; import org.sonar.server.user.index.UserIndexDefinition; import org.sonar.server.user.index.UserIndexer; +import org.sonar.server.user.index.UserQuery; import org.sonar.server.ws.WsActionTester; import static com.google.common.collect.ImmutableList.of; @@ -311,8 +313,8 @@ public class DeleteActionTest { assertThat(db.getDbClient().organizationMemberDao().select(db.getSession(), org.getUuid(), user1.getId())).isNotPresent(); assertThat(db.getDbClient().organizationMemberDao().select(db.getSession(), org.getUuid(), user2.getId())).isNotPresent(); assertThat(db.getDbClient().organizationMemberDao().select(db.getSession(), otherOrg.getUuid(), user1.getId())).isPresent(); - assertThat(userIndex.getNullableByLogin(user1.getLogin()).organizationUuids()).doesNotContain(org.getUuid()).contains(otherOrg.getUuid()); - assertThat(userIndex.getNullableByLogin(user2.getLogin()).organizationUuids()).isEmpty(); + assertThat(userIndex.search(UserQuery.builder().setOrganizationUuid(org.getUuid()).build(), new SearchOptions()).getTotal()).isEqualTo(0); + assertThat(userIndex.search(UserQuery.builder().setOrganizationUuid(otherOrg.getUuid()).build(), new SearchOptions()).getTotal()).isEqualTo(1); } @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/organization/ws/RemoveMemberActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/organization/ws/RemoveMemberActionTest.java index be648db8745..ff331f7e280 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/organization/ws/RemoveMemberActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/organization/ws/RemoveMemberActionTest.java @@ -40,6 +40,7 @@ import org.sonar.db.property.PropertyQuery; import org.sonar.db.user.GroupDto; import org.sonar.db.user.UserDto; import org.sonar.server.es.EsTester; +import org.sonar.server.es.SearchOptions; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; @@ -47,6 +48,7 @@ import org.sonar.server.tester.UserSessionRule; import org.sonar.server.user.index.UserIndex; import org.sonar.server.user.index.UserIndexDefinition; import org.sonar.server.user.index.UserIndexer; +import org.sonar.server.user.index.UserQuery; import org.sonar.server.ws.TestRequest; import org.sonar.server.ws.TestResponse; import org.sonar.server.ws.WsActionTester; @@ -340,7 +342,7 @@ public class RemoveMemberActionTest { private void assertNotAMember(String organizationUuid, UserDto user) { assertThat(dbClient.organizationMemberDao().select(dbSession, organizationUuid, user.getId())).isNotPresent(); - assertThat(userIndex.getNullableByLogin(user.getLogin()).organizationUuids()).doesNotContain(organizationUuid); + assertThat(userIndex.search(UserQuery.builder().setOrganizationUuid(organizationUuid).setTextQuery(user.getLogin()).build(), new SearchOptions()).getDocs()).isEmpty(); } private void assertMember(String organizationUuid, UserDto user) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexTest.java index 1159085b851..95713f9bcb5 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexTest.java @@ -150,8 +150,8 @@ public class UserIndexTest { .setOrganizationUuids(newArrayList("O2"))); assertThat(underTest.search(userQuery.setOrganizationUuid("O42").build(), new SearchOptions()).getDocs()).isEmpty(); - assertThat(underTest.search(userQuery.setOrganizationUuid("O2").build(), new SearchOptions()).getDocs()).hasSize(2); - assertThat(underTest.search(userQuery.setOrganizationUuid("O1").build(), new SearchOptions()).getDocs()).hasSize(1); + assertThat(underTest.search(userQuery.setOrganizationUuid("O2").build(), new SearchOptions()).getDocs()).extracting(UserDoc::login).containsOnly(USER1_LOGIN, USER2_LOGIN); + assertThat(underTest.search(userQuery.setOrganizationUuid("O1").build(), new SearchOptions()).getDocs()).extracting(UserDoc::login).containsOnly(USER1_LOGIN); } @Test |