public void putDocuments(String index, String type, BaseDoc... docs) { putDocuments(new IndexType(index, type), docs); }
@Test public void clear_indexes() { es.putDocuments(IssueIndexDefinition.INDEX_TYPE_ISSUE, IssueDocTesting.newDoc()); es.putDocuments(RuleIndexDefinition.INDEX_TYPE_RULE, newRuleDoc()); es.putDocuments(ComponentIndexDefinition.INDEX_TYPE_COMPONENT, newComponentDoc()); underTest.clearIndexes(); assertThat(es.countDocuments(IssueIndexDefinition.INDEX_TYPE_ISSUE)).isEqualTo(0); assertThat(es.countDocuments(ComponentIndexDefinition.INDEX_TYPE_COMPONENT)).isEqualTo(0); }
@Test public void getAtMostThreeActiveUsersForScmAccount_is_case_sensitive_for_login() { UserDoc user = newUser("the_login", singletonList("John.Smith")); es.putDocuments(INDEX_TYPE_USER, user); assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("the_login", ORGANIZATION_UUID)).hasSize(1); assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("the_Login", ORGANIZATION_UUID)).isEmpty(); }
@Test public void getAtMostThreeActiveUsersForScmAccount_is_case_insensitive_for_email() { UserDoc user = newUser("the_login", "the_EMAIL@corp.com", singletonList("John.Smith")); es.putDocuments(INDEX_TYPE_USER, user); assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("the_EMAIL@corp.com", ORGANIZATION_UUID)).hasSize(1); assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("the_email@corp.com", ORGANIZATION_UUID)).hasSize(1); assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("email", ORGANIZATION_UUID)).isEmpty(); }
@Test public void getAtMostThreeActiveUsersForScmAccount_is_case_insensitive_for_scm_account() { UserDoc user = newUser("the_login", singletonList("John.Smith")); es.putDocuments(INDEX_TYPE_USER, user); assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("John.Smith", ORGANIZATION_UUID)).hasSize(1); assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("JOHN.SMIth", ORGANIZATION_UUID)).hasSize(1); assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("JOHN.SMITH", ORGANIZATION_UUID)).hasSize(1); assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("JOHN", ORGANIZATION_UUID)).isEmpty(); }
private void index(ProjectMeasuresDoc... docs) { es.putDocuments(INDEX_TYPE_PROJECT_MEASURES, docs); authorizationIndexer.allow(stream(docs).map(doc -> new IndexPermissions(doc.getId(), PROJECT).allowAnyone()).collect(toList())); }
@Test public void getAtMostThreeActiveUsersForScmAccount_returns_maximum_three_users() { String email = "user@mail.com"; UserDoc user1 = newUser("user1", Collections.emptyList()).setEmail(email); UserDoc user2 = newUser("user2", Collections.emptyList()).setEmail(email); UserDoc user3 = newUser("user3", Collections.emptyList()).setEmail(email); UserDoc user4 = newUser("user4", Collections.emptyList()).setEmail(email); es.putDocuments(INDEX_TYPE_USER, user1); es.putDocuments(INDEX_TYPE_USER, user2); es.putDocuments(INDEX_TYPE_USER, user3); es.putDocuments(INDEX_TYPE_USER, user4); // restrict results to 3 users assertThat(underTest.getAtMostThreeActiveUsersForScmAccount(email, ORGANIZATION_UUID)).hasSize(3); }
private void index(ProjectMeasuresDoc... docs) { es.putDocuments(INDEX_TYPE_PROJECT_MEASURES, docs); authorizationIndexer.allow(stream(docs).map(doc -> new IndexPermissions(doc.getId(), PROJECT).allowAnyone()).collect(toList())); }
private void index(ProjectMeasuresDoc... docs) { es.putDocuments(INDEX_TYPE_PROJECT_MEASURES, docs); authorizationIndexer.allow(stream(docs).map(doc -> new IndexPermissions(doc.getId(), PROJECT).allowAnyone()).collect(toList())); }
private void indexForUser(UserDto user, ProjectMeasuresDoc... docs) { es.putDocuments(INDEX_TYPE_PROJECT_MEASURES, docs); authorizationIndexer.allow(stream(docs).map(doc -> new IndexPermissions(doc.getId(), PROJECT).addUserId(user.getId())).collect(toList())); }
@Test public void getAtMostThreeActiveUsersForScmAccount_ignores_inactive_user() { String scmAccount = "scmA"; UserDoc user = newUser(USER1_LOGIN, singletonList(scmAccount)).setActive(false); es.putDocuments(INDEX_TYPE_USER, user); assertThat(underTest.getAtMostThreeActiveUsersForScmAccount(user.login(), ORGANIZATION_UUID)).isEmpty(); assertThat(underTest.getAtMostThreeActiveUsersForScmAccount(scmAccount, ORGANIZATION_UUID)).isEmpty(); }
private void indexForGroup(GroupDto group, ProjectMeasuresDoc... docs) { es.putDocuments(INDEX_TYPE_PROJECT_MEASURES, docs); authorizationIndexer.allow(stream(docs).map(doc -> new IndexPermissions(doc.getId(), PROJECT).addGroupId(group.getId())).collect(toList())); }
@Test public void getAtMostThreeActiveUsersForScmAccount_search_only_user_within_given_organization() { UserDoc user1 = newUser("user1", singletonList("same_scm")).setOrganizationUuids(singletonList(ORGANIZATION_UUID)); UserDoc user2 = newUser("user2", singletonList("same_scm")).setOrganizationUuids(singletonList("another_organization")); es.putDocuments(INDEX_TYPE_USER, user1); es.putDocuments(INDEX_TYPE_USER, user2); assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("same_scm", ORGANIZATION_UUID)).extractingResultOf("login").containsOnly(user1.login()); }
@Test public void do_not_index_if_indexes_are_disabled() { settings.setProperty("sonar.internal.es.disableIndexes", "true"); es.putDocuments(INDEX_TYPE_FAKE, new FakeDoc()); underTest.execute(); // do not index verifyNoMoreInteractions(indexer); } }
private void addIssueToIndex(String projectUuid, String issueKey) { es.putDocuments(INDEX_TYPE_ISSUE, newDoc().setKey(issueKey).setProjectUuid(projectUuid)); }
@Test public void find_all_view_uuids() { ViewDoc view1 = new ViewDoc().setUuid("UUID1").setProjects(singletonList("P1")); ViewDoc view2 = new ViewDoc().setUuid("UUID2").setProjects(singletonList("P2")); es.putDocuments(INDEX_TYPE_VIEW, view1); es.putDocuments(INDEX_TYPE_VIEW, view2); List<String> result = newArrayList(index.findAllViewUuids()); assertThat(result).containsOnly(view1.uuid(), view2.uuid()); }
@Test public void search_users_filter_by_excluded_organization_uuid() { es.putDocuments(INDEX_TYPE_USER, newUser(USER1_LOGIN, asList("user_1", "u1")).setEmail("email1") .setOrganizationUuids(newArrayList("O1", "O2"))); es.putDocuments(INDEX_TYPE_USER, newUser(USER2_LOGIN, emptyList()).setEmail("email2") .setOrganizationUuids(newArrayList("O2"))); assertThat(underTest.search(userQuery.setExcludedOrganizationUuid("O42").build(), new SearchOptions()).getDocs()).hasSize(2); assertThat(underTest.search(userQuery.setExcludedOrganizationUuid("O2").build(), new SearchOptions()).getDocs()).isEmpty(); assertThat(underTest.search(userQuery.setExcludedOrganizationUuid("O1").build(), new SearchOptions()).getDocs()).hasSize(1); }
@Test public void delete_should_delete_the_view() { ViewDoc view1 = new ViewDoc().setUuid("UUID1").setProjects(asList("P1")); ViewDoc view2 = new ViewDoc().setUuid("UUID2").setProjects(asList("P2", "P3", "P4")); ViewDoc view3 = new ViewDoc().setUuid("UUID3").setProjects(asList("P2", "P3", "P4")); es.putDocuments(INDEX_TYPE_VIEW, view1); es.putDocuments(INDEX_TYPE_VIEW, view2); es.putDocuments(INDEX_TYPE_VIEW, view3); assertThat(es.getDocumentFieldValues(INDEX_TYPE_VIEW, ViewIndexDefinition.FIELD_UUID)) .containsOnly(view1.uuid(), view2.uuid(), view3.uuid()); underTest.delete(dbSession, asList(view1.uuid(), view2.uuid())); assertThat(es.getDocumentFieldValues(INDEX_TYPE_VIEW, ViewIndexDefinition.FIELD_UUID)) .containsOnly(view3.uuid()); }
@Test public void searchUsers() { es.putDocuments(INDEX_TYPE_USER, newUser(USER1_LOGIN, asList("user_1", "u1")).setEmail("email1")); es.putDocuments(INDEX_TYPE_USER, newUser(USER2_LOGIN, Collections.emptyList()).setEmail("email2")); assertThat(underTest.search(userQuery.build(), new SearchOptions()).getDocs()).hasSize(2); assertThat(underTest.search(userQuery.setTextQuery("user").build(), new SearchOptions()).getDocs()).hasSize(2); assertThat(underTest.search(userQuery.setTextQuery("ser").build(), new SearchOptions()).getDocs()).hasSize(2); assertThat(underTest.search(userQuery.setTextQuery(USER1_LOGIN).build(), new SearchOptions()).getDocs()).hasSize(1); assertThat(underTest.search(userQuery.setTextQuery(USER2_LOGIN).build(), new SearchOptions()).getDocs()).hasSize(1); assertThat(underTest.search(userQuery.setTextQuery("mail").build(), new SearchOptions()).getDocs()).hasSize(2); assertThat(underTest.search(userQuery.setTextQuery("EMAIL1").build(), new SearchOptions()).getDocs()).hasSize(1); }
@Test public void search_users_filter_by_organization_uuid() { es.putDocuments(INDEX_TYPE_USER, newUser(USER1_LOGIN, asList("user_1", "u1")).setEmail("email1") .setOrganizationUuids(newArrayList("O1", "O2"))); es.putDocuments(INDEX_TYPE_USER, newUser(USER2_LOGIN, emptyList()).setEmail("email2") .setOrganizationUuids(newArrayList("O2"))); assertThat(underTest.search(userQuery.setOrganizationUuid("O42").build(), new SearchOptions()).getDocs()).isEmpty(); 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); }