* Unit tests no longer use the LargeSizeHandler for indexing. This handler is designed for indexing large amounts of data and is slower for the data sets used in unit tests. * Insert all data in DB before indexing in unit tests (there is a huge overhead in each call to index)tags/8.6.0.39681
@@ -51,7 +51,7 @@ public class ScmAccountToUserLoaderTest { | |||
@Test | |||
public void load_login_for_scm_account() { | |||
UserDto user = db.users().insertUser(u -> u.setScmAccounts(asList("charlie", "jesuis@charlie.com"))); | |||
userIndexer.indexOnStartup(null); | |||
userIndexer.indexAll(); | |||
UserIndex index = new UserIndex(es.client(), System2.INSTANCE); | |||
ScmAccountToUserLoader underTest = new ScmAccountToUserLoader(index); | |||
@@ -64,7 +64,7 @@ public class ScmAccountToUserLoaderTest { | |||
public void warn_if_multiple_users_share_the_same_scm_account() { | |||
db.users().insertUser(u -> u.setLogin("charlie").setScmAccounts(asList("charlie", "jesuis@charlie.com"))); | |||
db.users().insertUser(u -> u.setLogin("another.charlie").setScmAccounts(asList("charlie"))); | |||
userIndexer.indexOnStartup(null); | |||
userIndexer.indexAll(); | |||
UserIndex index = new UserIndex(es.client(), System2.INSTANCE); | |||
ScmAccountToUserLoader underTest = new ScmAccountToUserLoader(index); |
@@ -23,6 +23,7 @@ import java.util.Arrays; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.Set; | |||
import java.util.function.BiConsumer; | |||
import java.util.function.Consumer; | |||
import java.util.function.Function; | |||
@@ -38,7 +39,7 @@ import org.sonar.process.logging.LogbackHelper; | |||
class TestDbImpl extends CoreTestDb { | |||
private static TestDbImpl defaultSchemaBaseTestDb; | |||
// instantiating MyBatis objects is costly => we cache them for default schema | |||
private static final Map<List<String>, TestDbImpl> defaultSchemaTestDbsWithExtensions = new HashMap<>(); | |||
private static final Map<Set<String>, TestDbImpl> defaultSchemaTestDbsWithExtensions = new HashMap<>(); | |||
private boolean isDefault; | |||
private MyBatis myBatis; | |||
@@ -94,11 +95,10 @@ class TestDbImpl extends CoreTestDb { | |||
defaultSchemaBaseTestDb = new TestDbImpl(null); | |||
} | |||
if (confExtensions.length > 0) { | |||
List<String> key = Arrays.stream(confExtensions) | |||
Set<String> key = Arrays.stream(confExtensions) | |||
.flatMap(MyBatisConfExtension::getMapperClasses) | |||
.map(Class::getName) | |||
.sorted() | |||
.collect(Collectors.toList()); | |||
.collect(Collectors.toSet()); | |||
return defaultSchemaTestDbsWithExtensions.computeIfAbsent( | |||
key, | |||
k -> new TestDbImpl(defaultSchemaBaseTestDb, newMyBatis(defaultSchemaBaseTestDb.getDatabase(), confExtensions))); |
@@ -73,6 +73,10 @@ public class ComponentIndexer implements ProjectIndexer, NeedAuthorizationIndexe | |||
doIndexByProjectUuid(null, Size.LARGE); | |||
} | |||
public void indexAll() { | |||
doIndexByProjectUuid(null, Size.REGULAR); | |||
} | |||
@Override | |||
public void indexOnAnalysis(String branchUuid) { | |||
doIndexByProjectUuid(branchUuid, Size.REGULAR); |
@@ -103,10 +103,9 @@ public class IssueIndexer implements ProjectIndexer, NeedAuthorizationIndexer { | |||
asyncIssueIndexing.triggerOnIndexCreation(); | |||
} | |||
@VisibleForTesting | |||
public void indexAllIssues() { | |||
try (IssueIterator issues = issueIteratorFactory.createForAll()) { | |||
doIndex(issues, Size.LARGE, IndexingListener.FAIL_ON_ERROR); | |||
doIndex(issues, Size.REGULAR, IndexingListener.FAIL_ON_ERROR); | |||
} | |||
} | |||
@@ -249,7 +248,7 @@ public class IssueIndexer implements ProjectIndexer, NeedAuthorizationIndexer { | |||
@VisibleForTesting | |||
protected void index(Iterator<IssueDoc> issues) { | |||
doIndex(issues, Size.LARGE, IndexingListener.FAIL_ON_ERROR); | |||
doIndex(issues, Size.REGULAR, IndexingListener.FAIL_ON_ERROR); | |||
} | |||
private void doIndex(Iterator<IssueDoc> issues, Size size, IndexingListener listener) { |
@@ -73,6 +73,10 @@ public class ProjectMeasuresIndexer implements ProjectIndexer, NeedAuthorization | |||
doIndex(Size.LARGE, null); | |||
} | |||
public void indexAll() { | |||
doIndex(Size.REGULAR, null); | |||
} | |||
@Override | |||
public AuthorizationScope getAuthorizationScope() { | |||
return AUTHORIZATION_SCOPE; |
@@ -73,8 +73,16 @@ public class ActiveRuleIndexer implements ResilientIndexer { | |||
@Override | |||
public void indexOnStartup(Set<IndexType> uninitializedIndexTypes) { | |||
indexAll(Size.LARGE); | |||
} | |||
public void indexAll() { | |||
indexAll(Size.REGULAR); | |||
} | |||
private void indexAll(Size bulkSize) { | |||
try (DbSession dbSession = dbClient.openSession(false)) { | |||
BulkIndexer bulkIndexer = createBulkIndexer(Size.LARGE, IndexingListener.FAIL_ON_ERROR); | |||
BulkIndexer bulkIndexer = createBulkIndexer(bulkSize, IndexingListener.FAIL_ON_ERROR); | |||
bulkIndexer.start(); | |||
dbClient.activeRuleDao().scrollAllForIndexing(dbSession, ar -> bulkIndexer.add(newIndexRequest(ar))); | |||
bulkIndexer.stop(); |
@@ -70,15 +70,20 @@ public class RuleIndexer implements ResilientIndexer { | |||
@Override | |||
public void indexOnStartup(Set<IndexType> uninitializedIndexTypes) { | |||
try (DbSession dbSession = dbClient.openSession(false)) { | |||
BulkIndexer bulk = createBulkIndexer(Size.LARGE, IndexingListener.FAIL_ON_ERROR); | |||
bulk.start(); | |||
if (uninitializedIndexTypes.contains(TYPE_RULE)) { | |||
indexAll(Size.LARGE); | |||
} | |||
} | |||
// index all definitions | |||
if (uninitializedIndexTypes.contains(TYPE_RULE)) { | |||
dbClient.ruleDao().scrollIndexingRules(dbSession, dto -> bulk.add(ruleDocOf(dto).toIndexRequest())); | |||
} | |||
public void indexAll() { | |||
indexAll(Size.REGULAR); | |||
} | |||
private void indexAll(Size bulkSize) { | |||
try (DbSession dbSession = dbClient.openSession(false)) { | |||
BulkIndexer bulk = createBulkIndexer(bulkSize, IndexingListener.FAIL_ON_ERROR); | |||
bulk.start(); | |||
dbClient.ruleDao().scrollIndexingRules(dbSession, dto -> bulk.add(ruleDocOf(dto).toIndexRequest())); | |||
bulk.stop(); | |||
} | |||
} |
@@ -63,11 +63,19 @@ public class UserIndexer implements ResilientIndexer { | |||
@Override | |||
public void indexOnStartup(Set<IndexType> uninitializedIndexTypes) { | |||
indexAll(Size.LARGE); | |||
} | |||
public void indexAll() { | |||
indexAll(Size.REGULAR); | |||
} | |||
private void indexAll(Size bulkSize) { | |||
try (DbSession dbSession = dbClient.openSession(false)) { | |||
ListMultimap<String, String> organizationUuidsByUserUuid = ArrayListMultimap.create(); | |||
dbClient.organizationMemberDao().selectAllForUserIndexing(dbSession, organizationUuidsByUserUuid::put); | |||
BulkIndexer bulkIndexer = newBulkIndexer(Size.LARGE, IndexingListener.FAIL_ON_ERROR); | |||
BulkIndexer bulkIndexer = newBulkIndexer(bulkSize, IndexingListener.FAIL_ON_ERROR); | |||
bulkIndexer.start(); | |||
dbClient.userDao().scrollAll(dbSession, | |||
// only index requests, no deletion requests. |
@@ -62,12 +62,20 @@ public class ViewIndexer implements ResilientIndexer { | |||
@Override | |||
public void indexOnStartup(Set<IndexType> uninitializedIndexTypes) { | |||
indexAll(Size.LARGE); | |||
} | |||
public void indexAll() { | |||
indexAll(Size.REGULAR); | |||
} | |||
private void indexAll(Size bulkSize) { | |||
try (DbSession dbSession = dbClient.openSession(false)) { | |||
Map<String, String> viewAndProjectViewUuidMap = new HashMap<>(); | |||
for (UuidWithProjectUuidDto uuidWithProjectUuidDto : dbClient.componentDao().selectAllViewsAndSubViews(dbSession)) { | |||
viewAndProjectViewUuidMap.put(uuidWithProjectUuidDto.getUuid(), uuidWithProjectUuidDto.getProjectUuid()); | |||
} | |||
index(dbSession, viewAndProjectViewUuidMap, false, Size.LARGE); | |||
index(dbSession, viewAndProjectViewUuidMap, false, bulkSize); | |||
} | |||
} | |||
@@ -83,6 +83,16 @@ public class ComponentIndexerTest { | |||
assertThatIndexContainsOnly(project1, project2); | |||
} | |||
@Test | |||
public void indexOAll_indexes_all_components() { | |||
ComponentDto project1 = db.components().insertPrivateProject(); | |||
ComponentDto project2 = db.components().insertPrivateProject(); | |||
underTest.indexAll(); | |||
assertThatIndexContainsOnly(project1, project2); | |||
} | |||
@Test | |||
public void map_fields() { | |||
OrganizationDto organization = db.organizations().insert(); |
@@ -109,6 +109,19 @@ public class ProjectMeasuresIndexerTest { | |||
assertThatQualifierIs("TRK", project1, project2, project3); | |||
} | |||
@Test | |||
public void indexAll_indexes_all_projects() { | |||
OrganizationDto organization = db.organizations().insert(); | |||
SnapshotDto project1 = db.components().insertProjectAndSnapshot(newPrivateProjectDto(organization)); | |||
SnapshotDto project2 = db.components().insertProjectAndSnapshot(newPrivateProjectDto(organization)); | |||
SnapshotDto project3 = db.components().insertProjectAndSnapshot(newPrivateProjectDto(organization)); | |||
underTest.indexAll(); | |||
assertThatIndexContainsOnly(project1, project2, project3); | |||
assertThatQualifierIs("TRK", project1, project2, project3); | |||
} | |||
/** | |||
* Provisioned projects don't have analysis yet | |||
*/ |
@@ -89,6 +89,18 @@ public class ActiveRuleIndexerTest { | |||
assertThatEsQueueTableIsEmpty(); | |||
} | |||
@Test | |||
public void indexAll_indexes_all_data() { | |||
ActiveRuleDto activeRule = db.qualityProfiles().activateRule(profile1, rule1); | |||
underTest.indexAll(); | |||
List<ActiveRuleDoc> docs = es.getDocuments(TYPE_ACTIVE_RULE, ActiveRuleDoc.class); | |||
assertThat(docs).hasSize(1); | |||
verify(docs.get(0), profile1, activeRule); | |||
assertThatEsQueueTableIsEmpty(); | |||
} | |||
@Test | |||
public void test_commitAndIndex() { | |||
ActiveRuleDto ar1 = db.qualityProfiles().activateRule(profile1, rule1); |
@@ -29,8 +29,6 @@ import java.util.Set; | |||
import java.util.stream.IntStream; | |||
import java.util.stream.Stream; | |||
import javax.annotation.Nullable; | |||
import org.elasticsearch.action.search.SearchRequest; | |||
import org.elasticsearch.search.builder.SearchSourceBuilder; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.runner.RunWith; | |||
@@ -47,7 +45,6 @@ import org.sonar.db.rule.RuleDefinitionDto; | |||
import org.sonar.db.rule.RuleDto; | |||
import org.sonar.db.rule.RuleDto.Scope; | |||
import org.sonar.db.rule.RuleTesting; | |||
import org.sonar.server.es.EsClient; | |||
import org.sonar.server.es.EsTester; | |||
import org.sonar.server.security.SecurityStandards; | |||
import org.sonar.server.security.SecurityStandards.SQCategory; | |||
@@ -148,7 +145,6 @@ public class RuleIndexerTest { | |||
.setType(RuleType.SECURITY_HOTSPOT) | |||
.setSecurityStandards(standards) | |||
.setDescription(VALID_HOTSPOT_RULE_DESCRIPTION)); | |||
OrganizationDto organization = dbTester.organizations().insert(); | |||
underTest.commitAndIndex(dbTester.getSession(), rule.getUuid()); | |||
assertThat(logTester.getLogs()).hasSize(1); | |||
@@ -184,7 +180,6 @@ public class RuleIndexerTest { | |||
RuleDefinitionDto rule = dbTester.rules().insert(RuleTesting.newRule() | |||
.setType(RuleType.SECURITY_HOTSPOT) | |||
.setDescription(description)); | |||
OrganizationDto organization = dbTester.organizations().insert(); | |||
underTest.commitAndIndex(dbTester.getSession(), rule.getUuid()); | |||
assertThat(logTester.getLogs()).hasSize(1); | |||
@@ -207,7 +202,6 @@ public class RuleIndexerTest { | |||
RuleDefinitionDto rule = dbTester.rules().insert(RuleTesting.newRule() | |||
.setType(RuleType.SECURITY_HOTSPOT) | |||
.setDescription(randomAlphabetic(30))); | |||
OrganizationDto organization = dbTester.organizations().insert(); | |||
underTest.commitAndIndex(dbTester.getSession(), rule.getUuid()); | |||
assertThat(logTester.getLogs()).hasSize(1); | |||
@@ -224,7 +218,6 @@ public class RuleIndexerTest { | |||
.setDescription("bar\n" + | |||
"<h2>Ask Yourself Whether</h2>\n" + | |||
"foo")); | |||
OrganizationDto organization = dbTester.organizations().insert(); | |||
underTest.commitAndIndex(dbTester.getSession(), rule.getUuid()); | |||
assertThat(logTester.getLogs()).hasSize(1); |
@@ -72,6 +72,24 @@ public class UserIndexerTest { | |||
assertThat(doc.organizationUuids()).isEmpty(); | |||
} | |||
@Test | |||
public void indexAll_adds_all_users_to_index() { | |||
UserDto user = db.users().insertUser(u -> u.setScmAccounts(asList("user_1", "u1"))); | |||
underTest.indexAll(); | |||
List<UserDoc> docs = es.getDocuments(TYPE_USER, UserDoc.class); | |||
assertThat(docs).hasSize(1); | |||
UserDoc doc = docs.get(0); | |||
assertThat(doc.uuid()).isEqualTo(user.getUuid()); | |||
assertThat(doc.login()).isEqualTo(user.getLogin()); | |||
assertThat(doc.name()).isEqualTo(user.getName()); | |||
assertThat(doc.email()).isEqualTo(user.getEmail()); | |||
assertThat(doc.active()).isEqualTo(user.isActive()); | |||
assertThat(doc.scmAccounts()).isEqualTo(user.getScmAccountsAsList()); | |||
assertThat(doc.organizationUuids()).isEmpty(); | |||
} | |||
@Test | |||
public void indexOnStartup_adds_all_users_with_organizations() { | |||
OrganizationDto organization1 = db.organizations().insert(); |
@@ -166,6 +166,21 @@ public class ViewIndexerTest { | |||
assertThat(resultApp.projects()).containsExactlyInAnyOrder(project.uuid()); | |||
} | |||
@Test | |||
public void index_application_with_indexAll() { | |||
ComponentDto application = db.components().insertPrivateApplication(db.getDefaultOrganization()); | |||
ComponentDto project = db.components().insertPrivateProject(); | |||
db.components().insertComponent(newProjectCopy("PC1", project, application)); | |||
underTest.indexAll(); | |||
List<ViewDoc> result = es.getDocuments(TYPE_VIEW, ViewDoc.class); | |||
assertThat(result).hasSize(1); | |||
ViewDoc resultApp = result.get(0); | |||
assertThat(resultApp.uuid()).isEqualTo(application.uuid()); | |||
assertThat(resultApp.projects()).containsExactlyInAnyOrder(project.uuid()); | |||
} | |||
@Test | |||
public void index_application_branch() { | |||
ComponentDto application = db.components().insertPublicProject(c -> c.setQualifier(APP).setDbKey("app")); |
@@ -84,7 +84,7 @@ public class UserUpdaterUpdateTest { | |||
UserDto user = db.users().insertUser(newLocalUser(DEFAULT_LOGIN, "Marius", "marius@email.com") | |||
.setScmAccounts(asList("ma", "marius33"))); | |||
createDefaultGroup(); | |||
userIndexer.indexOnStartup(null); | |||
userIndexer.indexAll(); | |||
underTest.updateAndCommit(session, user, new UpdateUser() | |||
.setName("Marius2") | |||
@@ -216,7 +216,7 @@ public class UserUpdaterUpdateTest { | |||
public void update_index_when_updating_user_login() { | |||
UserDto oldUser = db.users().insertUser(); | |||
createDefaultGroup(); | |||
userIndexer.indexOnStartup(null); | |||
userIndexer.indexAll(); | |||
underTest.updateAndCommit(session, oldUser, new UpdateUser() | |||
.setLogin("new_login"), u -> { | |||
@@ -240,7 +240,7 @@ public class UserUpdaterUpdateTest { | |||
new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue(oldUser.getLogin()).setComponentUuid(project1.uuid()), | |||
new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue(oldUser.getLogin()).setComponentUuid(project2.uuid()), | |||
new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue("another login").setComponentUuid(anotherProject.uuid())); | |||
userIndexer.indexOnStartup(null); | |||
userIndexer.indexAll(); | |||
underTest.updateAndCommit(session, oldUser, new UpdateUser() | |||
.setLogin("new_login"), u -> { |
@@ -46,7 +46,6 @@ import org.sonar.server.user.index.UserIndexer; | |||
import org.sonar.updatecenter.common.Version; | |||
import static java.util.Arrays.asList; | |||
import static java.util.Collections.emptySet; | |||
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; | |||
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
@@ -99,7 +98,7 @@ public class TelemetryDataLoaderImplTest { | |||
int userCount = 3; | |||
IntStream.range(0, userCount).forEach(i -> db.users().insertUser()); | |||
db.users().insertUser(u -> u.setActive(false)); | |||
userIndexer.indexOnStartup(emptySet()); | |||
userIndexer.indexAll(); | |||
MetricDto lines = db.measures().insertMetric(m -> m.setKey(LINES_KEY)); | |||
MetricDto ncloc = db.measures().insertMetric(m -> m.setKey(NCLOC_KEY)); | |||
@@ -118,7 +117,7 @@ public class TelemetryDataLoaderImplTest { | |||
db.measures().insertLiveMeasure(project2, ncloc, m -> m.setValue(200d)); | |||
db.measures().insertLiveMeasure(project2, coverage, m -> m.setValue(80d)); | |||
db.measures().insertLiveMeasure(project2, nclocDistrib, m -> m.setValue(null).setData("java=300;kotlin=2500")); | |||
projectMeasuresIndexer.indexOnStartup(emptySet()); | |||
projectMeasuresIndexer.indexAll(); | |||
TelemetryData data = communityUnderTest.load(); | |||
assertThat(data.getServerId()).isEqualTo(serverId); | |||
@@ -157,7 +156,7 @@ public class TelemetryDataLoaderImplTest { | |||
db.measures().insertLiveMeasure(project, ncloc, m -> m.setValue(10d)); | |||
db.measures().insertLiveMeasure(branch1, ncloc, m -> m.setValue(20d)); | |||
db.measures().insertLiveMeasure(pr, ncloc, m -> m.setValue(30d)); | |||
projectMeasuresIndexer.indexOnStartup(emptySet()); | |||
projectMeasuresIndexer.indexAll(); | |||
TelemetryData data = communityUnderTest.load(); | |||
@@ -84,6 +84,13 @@ public class PermissionIndexer implements ProjectIndexer { | |||
index(authorizations, scopes, Size.LARGE); | |||
} | |||
public void indexAll(Set<IndexType> uninitializedIndexTypes) { | |||
// TODO do not load everything in memory. Db rows should be scrolled. | |||
List<IndexPermissions> authorizations = getAllAuthorizations(); | |||
Stream<AuthorizationScope> scopes = getScopes(uninitializedIndexTypes); | |||
index(authorizations, scopes, Size.REGULAR); | |||
} | |||
@VisibleForTesting | |||
void index(List<IndexPermissions> authorizations) { | |||
index(authorizations, authorizationScopes.stream(), Size.REGULAR); |
@@ -38,7 +38,6 @@ import org.sonar.server.permission.index.PermissionIndexerTester; | |||
import org.sonar.server.permission.index.WebAuthorizationTypeSupport; | |||
import org.sonar.server.tester.UserSessionRule; | |||
import static java.util.Collections.emptySet; | |||
import static java.util.Collections.singleton; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
@@ -134,7 +133,7 @@ public class ComponentIndexSearchTest { | |||
ComponentDto unauthorizedProject = db.components().insertPrivateProject(); | |||
ComponentDto project1 = db.components().insertPrivateProject(); | |||
ComponentDto project2 = db.components().insertPrivateProject(); | |||
indexer.indexOnStartup(emptySet()); | |||
indexer.indexAll(); | |||
authorizationIndexerTester.allowOnlyAnyone(project1); | |||
authorizationIndexerTester.allowOnlyAnyone(project2); | |||
@@ -145,7 +144,7 @@ public class ComponentIndexSearchTest { | |||
} | |||
private void index(ComponentDto... components) { | |||
indexer.indexOnStartup(emptySet()); | |||
indexer.indexAll(); | |||
Arrays.stream(components).forEach(c -> authorizationIndexerTester.allowOnlyAnyone(c)); | |||
} | |||
} |
@@ -76,6 +76,19 @@ public class PermissionIndexerTest { | |||
verifyAuthorized(project, user2); | |||
} | |||
@Test | |||
public void indexAll_grants_access_to_any_user_and_to_group_Anyone_on_public_projects() { | |||
ComponentDto project = createAndIndexPublicProject(); | |||
UserDto user1 = db.users().insertUser(); | |||
UserDto user2 = db.users().insertUser(); | |||
underTest.indexAll(underTest.getIndexTypes()); | |||
verifyAnyoneAuthorized(project); | |||
verifyAuthorized(project, user1); | |||
verifyAuthorized(project, user2); | |||
} | |||
@Test | |||
public void deletion_resilience_will_deindex_projects() { | |||
ComponentDto project1 = createUnindexedPublicProject(); |
@@ -53,7 +53,6 @@ import org.sonarqube.ws.Components.SearchWsResponse; | |||
import org.sonarqube.ws.MediaTypes; | |||
import static java.util.Arrays.asList; | |||
import static java.util.Collections.emptySet; | |||
import static java.util.Collections.singletonList; | |||
import static java.util.Optional.ofNullable; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
@@ -264,7 +263,7 @@ public class SearchActionTest { | |||
} | |||
private void index() { | |||
indexer.indexOnStartup(emptySet()); | |||
indexer.indexAll(); | |||
} | |||
private static Language[] javaLanguage() { |
@@ -25,8 +25,10 @@ import com.tngtech.java.junit.dataprovider.DataProviderRunner; | |||
import com.tngtech.java.junit.dataprovider.UseDataProvider; | |||
import java.util.Arrays; | |||
import java.util.Date; | |||
import java.util.HashSet; | |||
import java.util.List; | |||
import java.util.Optional; | |||
import java.util.Set; | |||
import java.util.function.Consumer; | |||
import java.util.stream.IntStream; | |||
import java.util.stream.Stream; | |||
@@ -262,6 +264,7 @@ public class SearchProjectsActionTest { | |||
p -> p.setTagsString("sales, offshore, java"), | |||
new Measure(coverage, c -> c.setValue(20d))); | |||
addFavourite(project1); | |||
index(); | |||
String jsonResult = ws.newRequest() | |||
.setParam(FACETS, COVERAGE) | |||
@@ -286,6 +289,7 @@ public class SearchProjectsActionTest { | |||
insertProject(organization, c -> c.setName("Maven")); | |||
insertProject(organization, c -> c.setName("Apache")); | |||
insertProject(organization, c -> c.setName("guava")); | |||
index(); | |||
SearchProjectsWsResponse result = call(request); | |||
@@ -298,6 +302,7 @@ public class SearchProjectsActionTest { | |||
userSession.logIn(); | |||
OrganizationDto organization = db.organizations().insert(); | |||
IntStream.rangeClosed(1, 9).forEach(i -> insertProject(organization, c -> c.setName("PROJECT-" + i))); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setPage(2).setPageSize(3)); | |||
@@ -338,6 +343,7 @@ public class SearchProjectsActionTest { | |||
ComponentDto project3 = insertProject(organizationDto, | |||
new Measure(coverage, c -> c.setValue(80d)), | |||
new Measure(ncloc, c -> c.setValue(10_001d))); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFilter("coverage <= 80 and ncloc <= 10000")); | |||
@@ -354,6 +360,7 @@ public class SearchProjectsActionTest { | |||
ComponentDto project1 = insertProject(organization1, new Measure(coverage, c -> c.setValue(81d)), new Measure(ncloc, c -> c.setValue(10_000d))); | |||
ComponentDto project2 = insertProject(organization1, new Measure(coverage, c -> c.setValue(80d)), new Measure(ncloc, c -> c.setValue(10_000d))); | |||
ComponentDto project3 = insertProject(organization2, new Measure(coverage, c -> c.setValue(80d)), new Measure(ncloc, c -> c.setValue(10_000d))); | |||
index(); | |||
assertThat(call(request.setOrganization(null)).getComponentsList()) | |||
.extracting(Component::getKey) | |||
@@ -374,6 +381,7 @@ public class SearchProjectsActionTest { | |||
ComponentDto project1 = insertProject(organizationDto, new Measure(qualityGateStatus, c -> c.setValue(null).setData("OK"))); | |||
ComponentDto project2 = insertProject(organizationDto, new Measure(qualityGateStatus, c -> c.setValue(null).setData("OK"))); | |||
ComponentDto project3 = insertProject(organizationDto, new Measure(qualityGateStatus, c -> c.setValue(null).setData("ERROR"))); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFilter("alert_status = OK")); | |||
@@ -391,6 +399,7 @@ public class SearchProjectsActionTest { | |||
ComponentDto project2 = insertProject(organizationDto, new Measure(languagesDistribution, c -> c.setValue(null).setData("java=3;xoo=9"))); | |||
ComponentDto project3 = insertProject(organizationDto, new Measure(languagesDistribution, c -> c.setValue(null).setData("xoo=1"))); | |||
ComponentDto project4 = insertProject(organizationDto, new Measure(languagesDistribution, c -> c.setValue(null).setData("<null>=1;java=5;xoo=13"))); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFilter("languages IN (java, js, <null>)")); | |||
@@ -406,6 +415,7 @@ public class SearchProjectsActionTest { | |||
ComponentDto project1 = insertProject(organizationDto, new Measure(ratingMetric, c -> c.setValue(1d))); | |||
ComponentDto project2 = insertProject(organizationDto, new Measure(ratingMetric, c -> c.setValue(2d))); | |||
ComponentDto project3 = insertProject(organizationDto, new Measure(ratingMetric, c -> c.setValue(3d))); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFilter(metricKey + " = 2")); | |||
@@ -421,6 +431,7 @@ public class SearchProjectsActionTest { | |||
insertProject(organizationDto, new Measure(ratingMetric, c -> c.setVariation(1d))); | |||
ComponentDto project2 = insertProject(organizationDto, new Measure(ratingMetric, c -> c.setVariation(2d))); | |||
insertProject(organizationDto, new Measure(ratingMetric, c -> c.setVariation(3d))); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFilter(newMetricKey + " = 2")); | |||
@@ -434,6 +445,7 @@ public class SearchProjectsActionTest { | |||
ComponentDto project1 = insertProject(organizationDto, defaults(), p -> p.setTags(asList("finance", "platform"))); | |||
insertProject(organizationDto, defaults(), p -> p.setTags(singletonList("marketing"))); | |||
ComponentDto project3 = insertProject(organizationDto, defaults(), p -> p.setTags(singletonList("offshore"))); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFilter("tags in (finance, offshore)")); | |||
@@ -448,6 +460,7 @@ public class SearchProjectsActionTest { | |||
ComponentDto project1 = insertProject(organizationDto, new Measure(coverage, c -> c.setValue(80d))); | |||
ComponentDto project2 = insertProject(organizationDto, new Measure(coverage, c -> c.setValue(85d))); | |||
ComponentDto project3 = insertProject(organizationDto, new Measure(coverage, c -> c.setValue(10d))); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFilter("coverage <= 80")); | |||
@@ -462,6 +475,7 @@ public class SearchProjectsActionTest { | |||
ComponentDto project1 = insertProject(organizationDto, new Measure(coverage, c -> c.setVariation(80d))); | |||
ComponentDto project2 = insertProject(organizationDto, new Measure(coverage, c -> c.setVariation(85d))); | |||
ComponentDto project3 = insertProject(organizationDto, new Measure(coverage, c -> c.setVariation(10d))); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFilter("new_coverage <= 80")); | |||
@@ -476,6 +490,7 @@ public class SearchProjectsActionTest { | |||
ComponentDto project1 = insertProject(organizationDto, new Measure(duplications, c -> c.setValue(80d))); | |||
ComponentDto project2 = insertProject(organizationDto, new Measure(duplications, c -> c.setValue(85d))); | |||
ComponentDto project3 = insertProject(organizationDto, new Measure(duplications, c -> c.setValue(10d))); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFilter("duplicated_lines_density <= 80")); | |||
@@ -491,6 +506,7 @@ public class SearchProjectsActionTest { | |||
ComponentDto project1 = insertProject(organizationDto, new Measure(coverage, c -> c.setValue(10d))); | |||
ComponentDto project2 = insertProject(organizationDto, new Measure(duplications, c -> c.setValue(0d))); | |||
ComponentDto project3 = insertProject(organizationDto, new Measure(duplications, c -> c.setValue(79d))); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFilter("duplicated_lines_density = NO_DATA")); | |||
@@ -504,6 +520,7 @@ public class SearchProjectsActionTest { | |||
MetricDto coverage = db.measures().insertMetric(c -> c.setKey(COVERAGE).setValueType("PERCENT")); | |||
MetricDto duplications = db.measures().insertMetric(c -> c.setKey(DUPLICATED_LINES_DENSITY_KEY).setValueType("PERCENT")); | |||
insertProject(organizationDto, new Measure(duplications, c -> c.setValue(10d)), new Measure(coverage, c -> c.setValue(50d))); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFilter("duplicated_lines_density = NO_DATA")); | |||
@@ -518,6 +535,7 @@ public class SearchProjectsActionTest { | |||
ComponentDto project1 = insertProject(organizationDto, new Measure(newDuplications, c -> c.setVariation(80d))); | |||
ComponentDto project2 = insertProject(organizationDto, new Measure(newDuplications, c -> c.setVariation(85d))); | |||
ComponentDto project3 = insertProject(organizationDto, new Measure(newDuplications, c -> c.setVariation(10d))); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFilter("new_duplicated_lines_density <= 80")); | |||
@@ -532,6 +550,7 @@ public class SearchProjectsActionTest { | |||
ComponentDto project1 = insertProject(organizationDto, new Measure(ncloc, c -> c.setValue(80d))); | |||
ComponentDto project2 = insertProject(organizationDto, new Measure(ncloc, c -> c.setValue(85d))); | |||
ComponentDto project3 = insertProject(organizationDto, new Measure(ncloc, c -> c.setValue(10d))); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFilter("ncloc <= 80")); | |||
@@ -546,6 +565,7 @@ public class SearchProjectsActionTest { | |||
ComponentDto project1 = insertProject(organizationDto, new Measure(newLines, c -> c.setVariation(80d))); | |||
ComponentDto project2 = insertProject(organizationDto, new Measure(newLines, c -> c.setVariation(85d))); | |||
ComponentDto project3 = insertProject(organizationDto, new Measure(newLines, c -> c.setVariation(10d))); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFilter("new_lines <= 80")); | |||
@@ -560,6 +580,7 @@ public class SearchProjectsActionTest { | |||
insertProject(organizationDto, c -> c.setDbKey("sonar-groovy").setName("Sonar Groovy")); | |||
insertProject(organizationDto, c -> c.setDbKey("sonar-markdown").setName("Sonar Markdown")); | |||
insertProject(organizationDto, c -> c.setDbKey("sonarqube").setName("Sonar Qube")); | |||
index(); | |||
assertThat(call(request.setFilter("query = \"Groovy\"")).getComponentsList()).extracting(Component::getName).containsOnly("Sonar Groovy"); | |||
assertThat(call(request.setFilter("query = \"oNar\"")).getComponentsList()).extracting(Component::getName).containsOnly("Sonar Java", "Sonar Groovy", "Sonar Markdown", | |||
@@ -582,7 +603,9 @@ public class SearchProjectsActionTest { | |||
ComponentDto nonFavourite2 = insertProject(organization2); | |||
ComponentDto favourite3 = insertProject(organization3); | |||
ComponentDto nonFavourite4 = insertProject(organization4); | |||
Stream.of(favourite1_1, favourite1_2, favourite2, favourite3).forEach(this::addFavourite); | |||
index(); | |||
assertThat(call(request.setFilter(null).setOrganization(null)).getComponentsList()) | |||
.extracting(Component::getName) | |||
@@ -621,6 +644,7 @@ public class SearchProjectsActionTest { | |||
ComponentDto markDownProject = insertProject(organization); | |||
ComponentDto sonarQubeProject = insertProject(organization); | |||
Stream.of(javaProject, markDownProject).forEach(this::addFavourite); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFilter("isFavorite")); | |||
@@ -636,6 +660,7 @@ public class SearchProjectsActionTest { | |||
ComponentDto markDownProject = insertProject(organization); | |||
ComponentDto sonarQubeProject = insertProject(organization); | |||
Stream.of(javaProject, markDownProject).forEach(this::addFavourite); | |||
index(); | |||
addFavourite((String) null); | |||
@@ -653,6 +678,7 @@ public class SearchProjectsActionTest { | |||
ComponentDto markDownProject = insertProject(organization); | |||
ComponentDto sonarQubeProject = insertProject(organization); | |||
Stream.of(javaProject, markDownProject).forEach(this::addFavourite); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFilter("isFavorite")); | |||
@@ -675,6 +701,7 @@ public class SearchProjectsActionTest { | |||
ComponentDto project1 = insertProject(organization); | |||
ComponentDto project2 = insertProject(organization); | |||
ComponentDto project3 = insertProject(organization); | |||
index(); | |||
SearchProjectsWsResponse result = call(request); | |||
@@ -707,6 +734,7 @@ public class SearchProjectsActionTest { | |||
ComponentDto project1 = insertProject(organization); | |||
ComponentDto project2 = insertProject(organization); | |||
ComponentDto project3 = insertProject(organization); | |||
index(); | |||
SearchProjectsWsResponse result = call(request); | |||
@@ -729,6 +757,7 @@ public class SearchProjectsActionTest { | |||
insertProject(organization); | |||
insertProject(organization); | |||
insertProject(organization); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFilter("qualifier = APP")); | |||
@@ -756,6 +785,7 @@ public class SearchProjectsActionTest { | |||
ComponentDto project1 = insertProject(organization); | |||
ComponentDto project2 = insertProject(organization); | |||
ComponentDto project3 = insertProject(organization); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFilter("qualifier = TRK")); | |||
@@ -774,7 +804,6 @@ public class SearchProjectsActionTest { | |||
public void fail_when_qualifier_filter_by_APP_set_when_ce_or_de(Edition edition) { | |||
when(editionProviderMock.get()).thenReturn(Optional.of(edition)); | |||
userSession.logIn(); | |||
OrganizationDto organization = db.organizations().insert(); | |||
assertThatThrownBy(() -> call(request.setFilter("qualifiers = APP"))) | |||
.isInstanceOf(IllegalArgumentException.class); | |||
@@ -785,7 +814,6 @@ public class SearchProjectsActionTest { | |||
public void fail_when_qualifier_filter_invalid_when_ee_or_dc(Edition edition) { | |||
when(editionProviderMock.get()).thenReturn(Optional.of(edition)); | |||
userSession.logIn(); | |||
OrganizationDto organization = db.organizations().insert(); | |||
assertThatThrownBy(() -> call(request.setFilter("qualifiers = BLA"))) | |||
.isInstanceOf(IllegalArgumentException.class); | |||
@@ -796,6 +824,7 @@ public class SearchProjectsActionTest { | |||
userSession.anonymous(); | |||
OrganizationDto organization = db.organizations().insert(); | |||
insertProject(organization); | |||
index(); | |||
SearchProjectsWsResponse result = call(request); | |||
@@ -811,6 +840,7 @@ public class SearchProjectsActionTest { | |||
insertProject(organizationDto, new Measure(ncloc, c -> c.setValue(5d))); | |||
insertProject(organizationDto, new Measure(ncloc, c -> c.setValue(10_000d))); | |||
insertProject(organizationDto, new Measure(ncloc, c -> c.setValue(500_001d))); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFacets(singletonList(NCLOC))); | |||
@@ -835,6 +865,7 @@ public class SearchProjectsActionTest { | |||
insertProject(organizationDto, new Measure(coverage, c -> c.setVariation(100d))); | |||
insertProject(organizationDto, new Measure(coverage, c -> c.setVariation(15_000d))); | |||
insertProject(organizationDto, new Measure(coverage, c -> c.setVariation(50_000d))); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFacets(singletonList(NEW_LINES_KEY))); | |||
@@ -860,6 +891,7 @@ public class SearchProjectsActionTest { | |||
insertProject(organizationDto, new Measure(languagesDistribution, c -> c.setValue(null).setData("java=5;xoo=19"))); | |||
insertProject(organizationDto, new Measure(languagesDistribution, c -> c.setValue(null).setData("xoo=1"))); | |||
insertProject(organizationDto, new Measure(languagesDistribution, c -> c.setValue(null).setData("<null>=1;java=3;xoo=8"))); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFacets(singletonList(FILTER_LANGUAGES))); | |||
@@ -881,6 +913,7 @@ public class SearchProjectsActionTest { | |||
MetricDto languagesDistribution = db.measures().insertMetric(c -> c.setKey(NCLOC_LANGUAGE_DISTRIBUTION_KEY).setValueType("DATA")); | |||
insertProject(organizationDto, new Measure(languagesDistribution, c -> c.setValue(null).setData("<null>=2;java=6"))); | |||
insertProject(organizationDto, new Measure(languagesDistribution, c -> c.setValue(null).setData("java=5"))); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFilter("languages = xoo").setFacets(singletonList(FILTER_LANGUAGES))); | |||
@@ -902,6 +935,7 @@ public class SearchProjectsActionTest { | |||
insertProject(organization, defaults(), p -> p.setTags(asList("finance", "platform"))); | |||
insertProject(organization, defaults(), p -> p.setTags(singletonList("offshore"))); | |||
insertProject(organization, defaults(), p -> p.setTags(singletonList("offshore"))); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFacets(singletonList(FILTER_TAGS))); | |||
@@ -923,6 +957,7 @@ public class SearchProjectsActionTest { | |||
insertProject(organization, defaults(), p -> p.setTags(asList("finance", "platform"))); | |||
insertProject(organization, defaults(), p -> p.setTags(singletonList("offshore"))); | |||
insertProject(organization, defaults(), p -> p.setTags(singletonList("offshore"))); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFilter("tags = marketing").setFacets(singletonList(FILTER_TAGS))); | |||
@@ -951,6 +986,7 @@ public class SearchProjectsActionTest { | |||
ComponentDto project1 = insertProject(organization); | |||
ComponentDto project2 = insertProject(organization); | |||
ComponentDto project3 = insertProject(organization); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFacets(singletonList(FILTER_QUALIFIER))); | |||
@@ -973,6 +1009,7 @@ public class SearchProjectsActionTest { | |||
ComponentDto application2 = insertApplication(organization); | |||
ComponentDto application3 = insertApplication(organization); | |||
ComponentDto application4 = insertApplication(organization); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFilter("qualifier = APP").setFacets(singletonList(FILTER_QUALIFIER))); | |||
@@ -996,6 +1033,7 @@ public class SearchProjectsActionTest { | |||
insertProject(organization, new Measure(ratingMetric, c -> c.setValue(1d))); | |||
insertProject(organization, new Measure(ratingMetric, c -> c.setValue(3d))); | |||
insertProject(organization, new Measure(ratingMetric, c -> c.setValue(5d))); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFacets(singletonList(ratingMetricKey))); | |||
@@ -1022,6 +1060,7 @@ public class SearchProjectsActionTest { | |||
insertProject(organization, new Measure(newRatingMetric, c -> c.setVariation(1d))); | |||
insertProject(organization, new Measure(newRatingMetric, c -> c.setVariation(3d))); | |||
insertProject(organization, new Measure(newRatingMetric, c -> c.setVariation(5d))); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFacets(singletonList(newRatingMetricKey))); | |||
@@ -1047,6 +1086,7 @@ public class SearchProjectsActionTest { | |||
insertProject(organizationDto, new Measure(coverage, c -> c.setValue(80d))); | |||
insertProject(organizationDto, new Measure(coverage, c -> c.setValue(85d))); | |||
insertProject(organizationDto, new Measure(coverage, c -> c.setValue(10d))); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFacets(singletonList(COVERAGE))); | |||
@@ -1073,6 +1113,7 @@ public class SearchProjectsActionTest { | |||
insertProject(organizationDto, new Measure(coverage, c -> c.setVariation(80d))); | |||
insertProject(organizationDto, new Measure(coverage, c -> c.setVariation(85d))); | |||
insertProject(organizationDto, new Measure(coverage, c -> c.setVariation(10d))); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFacets(singletonList(NEW_COVERAGE))); | |||
@@ -1099,6 +1140,7 @@ public class SearchProjectsActionTest { | |||
insertProject(organizationDto, new Measure(coverage, c -> c.setValue(15d))); | |||
insertProject(organizationDto, new Measure(coverage, c -> c.setValue(5d))); | |||
insertProject(organizationDto); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFacets(singletonList(DUPLICATED_LINES_DENSITY_KEY))); | |||
@@ -1125,6 +1167,7 @@ public class SearchProjectsActionTest { | |||
insertProject(organizationDto, new Measure(coverage, c -> c.setVariation(10d))); | |||
insertProject(organizationDto, new Measure(coverage, c -> c.setVariation(15d))); | |||
insertProject(organizationDto, new Measure(coverage, c -> c.setVariation(5d))); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFacets(singletonList(NEW_DUPLICATED_LINES_DENSITY_KEY))); | |||
@@ -1152,6 +1195,7 @@ public class SearchProjectsActionTest { | |||
insertProject(organizationDto, new Measure(qualityGateStatus, c -> c.setData(Metric.Level.WARN.name()).setValue(null))); | |||
insertProject(organizationDto, new Measure(qualityGateStatus, c -> c.setData(Metric.Level.OK.name()).setValue(null))); | |||
projectsInWarning.update(1L); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFacets(singletonList(ALERT_STATUS_KEY))); | |||
@@ -1175,6 +1219,7 @@ public class SearchProjectsActionTest { | |||
insertProject(organizationDto, new Measure(qualityGateStatus, c -> c.setData(Metric.Level.ERROR.name()).setValue(null))); | |||
insertProject(organizationDto, new Measure(qualityGateStatus, c -> c.setData(Metric.Level.OK.name()).setValue(null))); | |||
projectsInWarning.update(0L); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setFacets(singletonList(ALERT_STATUS_KEY))); | |||
@@ -1196,6 +1241,7 @@ public class SearchProjectsActionTest { | |||
insertProject(organization, c -> c.setName("Sonar Groovy")); | |||
insertProject(organization, c -> c.setName("Sonar Markdown")); | |||
insertProject(organization, c -> c.setName("Sonar Qube")); | |||
index(); | |||
SearchProjectsWsResponse result = call(request); | |||
@@ -1210,6 +1256,7 @@ public class SearchProjectsActionTest { | |||
insertProject(organization, c -> c.setName("Sonar Groovy")); | |||
insertProject(organization, c -> c.setName("Sonar Markdown")); | |||
insertProject(organization, c -> c.setName("Sonar Qube")); | |||
index(); | |||
assertThat(call(request.setSort("name").setAsc(true)).getComponentsList()).extracting(Component::getName) | |||
.containsExactly("Sonar Groovy", "Sonar Java", "Sonar Markdown", "Sonar Qube"); | |||
@@ -1226,6 +1273,7 @@ public class SearchProjectsActionTest { | |||
ComponentDto project2 = insertProject(organizationDto, c -> c.setName("Sonar Groovy"), new Measure(coverage, c -> c.setValue(81d))); | |||
ComponentDto project3 = insertProject(organizationDto, c -> c.setName("Sonar Markdown"), new Measure(coverage, c -> c.setValue(80d))); | |||
ComponentDto project4 = insertProject(organizationDto, c -> c.setName("Sonar Qube"), new Measure(coverage, c -> c.setValue(80d))); | |||
index(); | |||
assertThat(call(request.setSort(COVERAGE).setAsc(true)).getComponentsList()).extracting(Component::getKey) | |||
.containsExactly(project3.getDbKey(), project4.getDbKey(), project2.getDbKey(), project1.getDbKey()); | |||
@@ -1242,6 +1290,7 @@ public class SearchProjectsActionTest { | |||
ComponentDto project2 = insertProject(organization, c -> c.setName("Sonar Groovy"), new Measure(qualityGateStatus, c -> c.setValue(null).setData("ERROR"))); | |||
ComponentDto project3 = insertProject(organization, c -> c.setName("Sonar Markdown"), new Measure(qualityGateStatus, c -> c.setValue(null).setData("OK"))); | |||
ComponentDto project4 = insertProject(organization, c -> c.setName("Sonar Qube"), new Measure(qualityGateStatus, c -> c.setValue(null).setData("OK"))); | |||
index(); | |||
assertThat(call(request.setSort(QUALITY_GATE_STATUS).setAsc(true)).getComponentsList()).extracting(Component::getKey) | |||
.containsExactly(project3.getDbKey(), project4.getDbKey(), project2.getDbKey(), project1.getDbKey()); | |||
@@ -1265,7 +1314,7 @@ public class SearchProjectsActionTest { | |||
db.components().insertSnapshot(project4, snapshot -> snapshot.setCreatedAt(10_000_000_000L).setLast(false)); | |||
db.components().insertSnapshot(project4, snapshot -> snapshot.setCreatedAt(30_000_000_000L).setLast(true)); | |||
authorizationIndexerTester.allowOnlyAnyone(project4); | |||
projectMeasuresIndexer.indexOnStartup(null); | |||
index(); | |||
assertThat(call(request.setSort(ANALYSIS_DATE).setAsc(true)).getComponentsList()).extracting(Component::getKey) | |||
.containsExactly(project3.getDbKey(), project4.getDbKey(), project2.getDbKey(), project1.getDbKey()); | |||
@@ -1288,7 +1337,7 @@ public class SearchProjectsActionTest { | |||
// No snapshot on project 3 | |||
ComponentDto project3 = db.components().insertPublicProject(organization); | |||
authorizationIndexerTester.allowOnlyAnyone(project3); | |||
projectMeasuresIndexer.indexOnStartup(null); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setAdditionalFields(singletonList("analysisDate"))); | |||
@@ -1321,7 +1370,7 @@ public class SearchProjectsActionTest { | |||
db.components().insertSnapshot(application1); | |||
authorizationIndexerTester.allowOnlyAnyone(application1); | |||
projectMeasuresIndexer.indexOnStartup(null); | |||
index(); | |||
SearchProjectsWsResponse result = call(request.setAdditionalFields(singletonList("leakPeriodDate"))); | |||
@@ -1341,7 +1390,7 @@ public class SearchProjectsActionTest { | |||
authorizationIndexerTester.allowOnlyAnyone(privateProject); | |||
ComponentDto publicProject = db.components().insertPrivateProject(organization); | |||
authorizationIndexerTester.allowOnlyAnyone(publicProject); | |||
projectMeasuresIndexer.indexOnStartup(null); | |||
index(); | |||
SearchProjectsWsResponse result = call(request); | |||
@@ -1356,7 +1405,7 @@ public class SearchProjectsActionTest { | |||
ComponentDto project = db.components().insertPublicProject(); | |||
authorizationIndexerTester.allowOnlyAnyone(project); | |||
ComponentDto branch = db.components().insertProjectBranch(project); | |||
projectMeasuresIndexer.indexOnStartup(null); | |||
index(); | |||
SearchProjectsWsResponse result = call(request); | |||
@@ -1373,10 +1422,11 @@ public class SearchProjectsActionTest { | |||
ComponentDto project2 = insertProject(organization, c -> c.setName("Sonar Groovy"), new Measure(qualityGateStatus, c -> c.setValue(null).setData("WARN"))); | |||
ComponentDto project3 = insertProject(organization, c -> c.setName("Sonar Markdown"), new Measure(qualityGateStatus, c -> c.setValue(null).setData("WARN"))); | |||
ComponentDto project4 = insertProject(organization, c -> c.setName("Sonar Qube"), new Measure(qualityGateStatus, c -> c.setValue(null).setData("OK"))); | |||
index(); | |||
List<Component> projects = call(request | |||
.setFilter("alert_status = WARN")) | |||
.getComponentsList(); | |||
.getComponentsList(); | |||
assertThat(projects) | |||
.extracting(Component::getKey) | |||
@@ -1408,9 +1458,7 @@ public class SearchProjectsActionTest { | |||
@Test | |||
public void fail_if_page_size_greater_than_500() { | |||
userSession.logIn(); | |||
expectedException.expect(IllegalArgumentException.class); | |||
call(request.setPageSize(501)); | |||
} | |||
@@ -1449,8 +1497,6 @@ public class SearchProjectsActionTest { | |||
Measure... measures) { | |||
ComponentDto project = db.components().insertPublicProject(organizationDto, componentConsumer, projectConsumer); | |||
Arrays.stream(measures).forEach(m -> db.measures().insertLiveMeasure(project, m.metric, m.consumer)); | |||
authorizationIndexerTester.allowOnlyAnyone(project); | |||
projectMeasuresIndexer.indexOnAnalysis(project.uuid()); | |||
return project; | |||
} | |||
@@ -1461,16 +1507,18 @@ public class SearchProjectsActionTest { | |||
private ComponentDto insertApplication(OrganizationDto organizationDto, Consumer<ComponentDto> componentConsumer, Measure... measures) { | |||
ComponentDto application = db.components().insertPublicApplication(organizationDto, componentConsumer); | |||
Arrays.stream(measures).forEach(m -> db.measures().insertLiveMeasure(application, m.metric, m.consumer)); | |||
authorizationIndexerTester.allowOnlyAnyone(application); | |||
projectMeasuresIndexer.indexOnAnalysis(application.uuid()); | |||
return application; | |||
} | |||
private void index() { | |||
projectMeasuresIndexer.indexAll(); | |||
Set<ComponentDto> roots = dbClient.componentDao().selectComponentsByQualifiers(db.getSession(), | |||
new HashSet<>(asList(Qualifiers.PROJECT, Qualifiers.VIEW, Qualifiers.APP))); | |||
authorizationIndexerTester.allowOnlyAnyone(roots.toArray(new ComponentDto[0])); | |||
} | |||
private ComponentDto insertPortfolio(OrganizationDto organizationDto) { | |||
ComponentDto portfolio = db.components().insertPublicPortfolio(organizationDto); | |||
authorizationIndexerTester.allowOnlyAnyone(portfolio); | |||
projectMeasuresIndexer.indexOnAnalysis(portfolio.uuid()); | |||
return portfolio; | |||
return db.components().insertPublicPortfolio(organizationDto); | |||
} | |||
private static class Measure { |
@@ -141,7 +141,7 @@ public class SuggestionsActionTest { | |||
OrganizationDto organization = db.organizations().insert(o -> o.setKey("default-organization").setName("Default Organization")); | |||
ComponentDto project1 = db.components().insertPublicProject(organization, p -> p.setDbKey("org.sonarsource:sonarqube").setName("SonarSource :: SonarQube")); | |||
ComponentDto project2 = db.components().insertPublicProject(organization, p -> p.setDbKey("org.sonarsource:sonarlint").setName("SonarSource :: SonarLint")); | |||
componentIndexer.indexOnStartup(null); | |||
componentIndexer.indexAll(); | |||
authorizationIndexerTester.allowOnlyAnyone(project1); | |||
authorizationIndexerTester.allowOnlyAnyone(project2); | |||
@@ -159,7 +159,7 @@ public class SuggestionsActionTest { | |||
public void suggestions_without_query_should_contain_recently_browsed() { | |||
ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization)); | |||
componentIndexer.indexOnStartup(null); | |||
componentIndexer.indexAll(); | |||
userSessionRule.addProjectPermission(USER, project); | |||
SuggestionsWsResponse response = ws.newRequest() | |||
@@ -184,7 +184,7 @@ public class SuggestionsActionTest { | |||
public void suggestions_without_query_should_contain_recently_browsed_public_project() { | |||
ComponentDto project = db.components().insertComponent(newPublicProjectDto(organization)); | |||
componentIndexer.indexOnStartup(null); | |||
componentIndexer.indexAll(); | |||
SuggestionsWsResponse response = ws.newRequest() | |||
.setMethod("POST") | |||
@@ -208,7 +208,7 @@ public class SuggestionsActionTest { | |||
public void suggestions_without_query_should_not_contain_recently_browsed_without_permission() { | |||
ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization)); | |||
componentIndexer.indexOnStartup(null); | |||
componentIndexer.indexAll(); | |||
SuggestionsWsResponse response = ws.newRequest() | |||
.setMethod("POST") | |||
@@ -225,7 +225,7 @@ public class SuggestionsActionTest { | |||
ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization)); | |||
doReturn(singletonList(project)).when(favoriteFinder).list(); | |||
componentIndexer.indexOnStartup(null); | |||
componentIndexer.indexAll(); | |||
userSessionRule.addProjectPermission(USER, project); | |||
SuggestionsWsResponse response = ws.newRequest() | |||
@@ -250,7 +250,7 @@ public class SuggestionsActionTest { | |||
ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization)); | |||
doReturn(singletonList(project)).when(favoriteFinder).list(); | |||
componentIndexer.indexOnStartup(null); | |||
componentIndexer.indexAll(); | |||
SuggestionsWsResponse response = ws.newRequest() | |||
.setMethod("POST") | |||
@@ -266,7 +266,7 @@ public class SuggestionsActionTest { | |||
ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization)); | |||
doReturn(singletonList(project)).when(favoriteFinder).list(); | |||
componentIndexer.indexOnStartup(null); | |||
componentIndexer.indexAll(); | |||
userSessionRule.addProjectPermission(USER, project); | |||
SuggestionsWsResponse response = ws.newRequest() | |||
@@ -291,7 +291,7 @@ public class SuggestionsActionTest { | |||
public void suggestions_without_query_should_not_contain_matches_that_are_neither_favorites_nor_recently_browsed() { | |||
ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization)); | |||
componentIndexer.indexOnStartup(null); | |||
componentIndexer.indexAll(); | |||
userSessionRule.addProjectPermission(USER, project); | |||
SuggestionsWsResponse response = ws.newRequest() | |||
@@ -313,7 +313,7 @@ public class SuggestionsActionTest { | |||
ComponentDto project4 = db.components().insertComponent(newPrivateProjectDto(organization).setName("Delta")); | |||
doReturn(asList(project4, project2)).when(favoriteFinder).list(); | |||
componentIndexer.indexOnStartup(null); | |||
componentIndexer.indexAll(); | |||
userSessionRule.addProjectPermission(USER, project1); | |||
userSessionRule.addProjectPermission(USER, project2); | |||
userSessionRule.addProjectPermission(USER, project3); | |||
@@ -373,7 +373,7 @@ public class SuggestionsActionTest { | |||
public void exact_match_in_one_qualifier() { | |||
ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization)); | |||
componentIndexer.indexOnStartup(null); | |||
componentIndexer.indexAll(); | |||
authorizationIndexerTester.allowOnlyAnyone(project); | |||
SuggestionsWsResponse response = ws.newRequest() | |||
@@ -398,7 +398,7 @@ public class SuggestionsActionTest { | |||
public void should_not_return_suggestion_on_non_existing_project() { | |||
ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization)); | |||
componentIndexer.indexOnStartup(null); | |||
componentIndexer.indexAll(); | |||
authorizationIndexerTester.allowOnlyAnyone(project); | |||
db.getDbClient().componentDao().delete(db.getSession(), project.uuid()); | |||
@@ -419,7 +419,7 @@ public class SuggestionsActionTest { | |||
public void must_not_search_if_no_valid_tokens_are_provided() { | |||
ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization).setName("SonarQube")); | |||
componentIndexer.indexOnStartup(null); | |||
componentIndexer.indexAll(); | |||
authorizationIndexerTester.allowOnlyAnyone(project); | |||
SuggestionsWsResponse response = ws.newRequest() | |||
@@ -445,7 +445,7 @@ public class SuggestionsActionTest { | |||
public void should_warn_about_short_inputs_but_return_results_based_on_other_terms() { | |||
ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization).setName("SonarQube")); | |||
componentIndexer.indexOnStartup(null); | |||
componentIndexer.indexAll(); | |||
authorizationIndexerTester.allowOnlyAnyone(project); | |||
SuggestionsWsResponse response = ws.newRequest() | |||
@@ -593,7 +593,7 @@ public class SuggestionsActionTest { | |||
ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(project).setName(query)); | |||
ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(module).setName(query)); | |||
ComponentDto test = db.components().insertComponent(ComponentTesting.newFileDto(module).setName(query).setQualifier(UNIT_TEST_FILE)); | |||
componentIndexer.indexOnStartup(null); | |||
componentIndexer.indexAll(); | |||
authorizationIndexerTester.allowOnlyAnyone(project); | |||
authorizationIndexerTester.allowOnlyAnyone(view); | |||
authorizationIndexerTester.allowOnlyAnyone(app); | |||
@@ -617,7 +617,7 @@ public class SuggestionsActionTest { | |||
ComponentDto project = db.components().insertPublicProject(); | |||
authorizationIndexerTester.allowOnlyAnyone(project); | |||
ComponentDto branch = db.components().insertProjectBranch(project); | |||
componentIndexer.indexOnStartup(null); | |||
componentIndexer.indexAll(); | |||
authorizationIndexerTester.allowOnlyAnyone(project); | |||
SuggestionsWsResponse response = ws.newRequest() | |||
@@ -736,7 +736,7 @@ public class SuggestionsActionTest { | |||
.mapToObj(i -> db.components().insertComponent(newPublicProjectDto(organization).setName(namePrefix + i))) | |||
.collect(Collectors.toList()); | |||
componentIndexer.indexOnStartup(null); | |||
componentIndexer.indexAll(); | |||
projects.forEach(authorizationIndexerTester::allowOnlyAnyone); | |||
TestRequest request = ws.newRequest() |
@@ -1606,7 +1606,7 @@ public class SearchActionTest { | |||
} | |||
private void indexPermissions() { | |||
permissionIndexer.indexOnStartup(permissionIndexer.getIndexTypes()); | |||
permissionIndexer.indexAll(permissionIndexer.getIndexTypes()); | |||
} | |||
private void indexIssues() { | |||
@@ -1614,7 +1614,7 @@ public class SearchActionTest { | |||
} | |||
private void indexViews() { | |||
viewIndexer.indexOnStartup(viewIndexer.getIndexTypes()); | |||
viewIndexer.indexAll(); | |||
} | |||
private RuleDefinitionDto newRule(RuleType ruleType) { |
@@ -48,7 +48,6 @@ import org.sonar.server.ws.WsActionTester; | |||
import org.sonarqube.ws.Issues.AuthorsResponse; | |||
import static java.lang.String.format; | |||
import static java.util.Collections.emptySet; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.groups.Tuple.tuple; | |||
import static org.mockito.ArgumentMatchers.any; | |||
@@ -200,7 +199,7 @@ public class AuthorsActionTest { | |||
RuleDefinitionDto rule = db.rules().insertIssueRule(); | |||
db.issues().insertIssue(rule, project, project, issue -> issue.setAuthorLogin(leia)); | |||
indexIssues(); | |||
viewIndexer.indexOnStartup(emptySet()); | |||
viewIndexer.indexAll(); | |||
userSession.logIn(); | |||
assertThat(ws.newRequest() | |||
@@ -220,7 +219,7 @@ public class AuthorsActionTest { | |||
RuleDefinitionDto rule = db.rules().insertIssueRule(); | |||
db.issues().insertIssue(rule, project, project, issue -> issue.setAuthorLogin(leia)); | |||
indexIssues(); | |||
viewIndexer.indexOnStartup(emptySet()); | |||
viewIndexer.indexAll(); | |||
userSession.logIn(); | |||
assertThat(ws.newRequest() |
@@ -805,6 +805,6 @@ public class SearchActionComponentsTest { | |||
private void indexIssuesAndViews() { | |||
indexIssues(); | |||
viewIndexer.indexOnStartup(null); | |||
viewIndexer.indexAll(); | |||
} | |||
} |
@@ -39,7 +39,6 @@ import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.rule.RuleDefinitionDto; | |||
import org.sonar.db.user.UserDto; | |||
import org.sonar.server.es.EsTester; | |||
import org.sonar.server.es.StartupIndexer; | |||
import org.sonar.server.issue.AvatarResolverImpl; | |||
import org.sonar.server.issue.TextRangeResponseFormatter; | |||
import org.sonar.server.issue.TransitionService; | |||
@@ -89,7 +88,7 @@ public class SearchActionFacetsTest { | |||
private IssueIndex issueIndex = new IssueIndex(es.client(), System2.INSTANCE, userSession, new WebAuthorizationTypeSupport(userSession)); | |||
private IssueIndexer issueIndexer = new IssueIndexer(es.client(), db.getDbClient(), new IssueIteratorFactory(db.getDbClient()), null); | |||
private StartupIndexer permissionIndexer = new PermissionIndexer(db.getDbClient(), es.client(), issueIndexer); | |||
private PermissionIndexer permissionIndexer = new PermissionIndexer(db.getDbClient(), es.client(), issueIndexer); | |||
private IssueQueryFactory issueQueryFactory = new IssueQueryFactory(db.getDbClient(), Clock.systemUTC(), userSession); | |||
private SearchResponseLoader searchResponseLoader = new SearchResponseLoader(userSession, db.getDbClient(), new TransitionService(userSession, null)); | |||
private Languages languages = new Languages(); | |||
@@ -592,7 +591,7 @@ public class SearchActionFacetsTest { | |||
} | |||
private void indexPermissions() { | |||
permissionIndexer.indexOnStartup(permissionIndexer.getIndexTypes()); | |||
permissionIndexer.indexAll(permissionIndexer.getIndexTypes()); | |||
} | |||
private void indexIssues() { |
@@ -141,7 +141,7 @@ public class SearchActionTest { | |||
private IssueIndexSyncProgressChecker issueIndexSyncProgressChecker = new IssueIndexSyncProgressChecker(dbClient); | |||
private WsActionTester ws = new WsActionTester( | |||
new SearchAction(userSession, issueIndex, issueQueryFactory, issueIndexSyncProgressChecker, searchResponseLoader, searchResponseFormat, System2.INSTANCE, dbClient)); | |||
private StartupIndexer permissionIndexer = new PermissionIndexer(dbClient, es.client(), issueIndexer); | |||
private PermissionIndexer permissionIndexer = new PermissionIndexer(dbClient, es.client(), issueIndexer); | |||
@Before | |||
public void setUp() { | |||
@@ -1368,7 +1368,7 @@ public class SearchActionTest { | |||
} | |||
private void indexPermissions() { | |||
permissionIndexer.indexOnStartup(permissionIndexer.getIndexTypes()); | |||
permissionIndexer.indexAll(permissionIndexer.getIndexTypes()); | |||
} | |||
private void indexIssues() { |
@@ -49,7 +49,6 @@ import org.sonarqube.ws.Issues.TagsResponse; | |||
import static java.lang.String.format; | |||
import static java.util.Arrays.asList; | |||
import static java.util.Collections.emptySet; | |||
import static java.util.Collections.singletonList; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.tuple; | |||
@@ -226,7 +225,7 @@ public class TagsActionTest { | |||
RuleDefinitionDto rule = db.rules().insertIssueRule(); | |||
db.issues().insertIssue(rule, project, project, issue -> issue.setTags(singletonList("cwe"))); | |||
indexIssues(); | |||
viewIndexer.indexOnStartup(emptySet()); | |||
viewIndexer.indexAll(); | |||
assertThat(tagListOf(ws.newRequest().setParam("project", portfolio.getKey()))).containsExactly("cwe"); | |||
} | |||
@@ -243,7 +242,7 @@ public class TagsActionTest { | |||
db.issues().insertHotspot(hotspotRule, project, project, issue -> issue.setTags(singletonList("cwe"))); | |||
db.issues().insertIssue(issueRule, project, project, issue -> issue.setTags(singletonList("foo"))); | |||
indexIssues(); | |||
viewIndexer.indexOnStartup(emptySet()); | |||
viewIndexer.indexAll(); | |||
assertThat(tagListOf(ws.newRequest().setParam("project", portfolio.getKey()))).containsExactly("foo"); | |||
} | |||
@@ -258,7 +257,7 @@ public class TagsActionTest { | |||
RuleDefinitionDto rule = db.rules().insertIssueRule(); | |||
db.issues().insertIssue(rule, project, project, issue -> issue.setTags(singletonList("cwe"))); | |||
indexIssues(); | |||
viewIndexer.indexOnStartup(emptySet()); | |||
viewIndexer.indexAll(); | |||
assertThat(tagListOf(ws.newRequest().setParam("project", application.getKey()))).containsExactly("cwe"); | |||
} | |||
@@ -275,7 +274,7 @@ public class TagsActionTest { | |||
db.issues().insertIssue(issueRule, project, project, issue -> issue.setTags(singletonList("cwe"))); | |||
db.issues().insertHotspot(hotspotRule, project, project, issue -> issue.setTags(singletonList("foo"))); | |||
indexIssues(); | |||
viewIndexer.indexOnStartup(emptySet()); | |||
viewIndexer.indexAll(); | |||
assertThat(tagListOf(ws.newRequest().setParam("project", application.getKey()))).containsExactly("cwe"); | |||
} |
@@ -717,7 +717,7 @@ public class QProfileRuleImplTest { | |||
i -> rules.add(db.rules().insertRule(r -> r.setLanguage(language).setRepositoryKey(repositoryKey)))); | |||
verifyNoActiveRules(); | |||
ruleIndexer.indexOnStartup(ruleIndexer.getIndexTypes()); | |||
ruleIndexer.indexAll(); | |||
RuleQuery ruleQuery = new RuleQuery() | |||
.setRepositories(singletonList(repositoryKey)); | |||
@@ -744,7 +744,7 @@ public class QProfileRuleImplTest { | |||
i -> rules.add(db.rules().insertRule(r -> r.setLanguage(language).setRepositoryKey(repositoryKey)))); | |||
verifyNoActiveRules(); | |||
ruleIndexer.indexOnStartup(ruleIndexer.getIndexTypes()); | |||
ruleIndexer.indexAll(); | |||
RuleQuery ruleQuery = new RuleQuery() | |||
.setRepositories(singletonList(repositoryKey)); | |||
@@ -777,7 +777,7 @@ public class QProfileRuleImplTest { | |||
assertThatRuleIsActivated(parentProfile, rule, null, rule.getSeverityString(), null, emptyMap()); | |||
assertThatRuleIsActivated(childProfile, rule, null, rule.getSeverityString(), INHERITED, emptyMap()); | |||
ruleIndexer.indexOnStartup(ruleIndexer.getIndexTypes()); | |||
ruleIndexer.indexAll(); | |||
RuleQuery ruleQuery = new RuleQuery() | |||
.setQProfile(childProfile); | |||
@@ -801,7 +801,7 @@ public class QProfileRuleImplTest { | |||
activate(parentProfile, RuleActivation.create(rule1.getUuid())); | |||
activate(parentProfile, RuleActivation.create(rule2.getUuid())); | |||
ruleIndexer.indexOnStartup(ruleIndexer.getIndexTypes()); | |||
ruleIndexer.indexAll(); | |||
RuleQuery query = new RuleQuery() | |||
.setRuleKey(rule1.getRuleKey()) |
@@ -63,7 +63,6 @@ import org.sonar.server.ws.WsActionTester; | |||
import org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters; | |||
import static java.util.Arrays.asList; | |||
import static java.util.Collections.emptySet; | |||
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_PROFILES; | |||
@@ -133,7 +132,7 @@ public class ChangeParentActionTest { | |||
RuleDefinitionDto rule1 = createRule(); | |||
createActiveRule(rule1, parent1); | |||
ruleIndexer.commitAndIndex(dbSession, rule1.getUuid()); | |||
activeRuleIndexer.indexOnStartup(emptySet()); | |||
activeRuleIndexer.indexAll(); | |||
assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, child.getKee())).isEmpty(); | |||
@@ -164,7 +163,7 @@ public class ChangeParentActionTest { | |||
createActiveRule(rule1, parent1); | |||
createActiveRule(rule2, parent2); | |||
ruleIndexer.commitAndIndex(dbSession, asList(rule1.getUuid(), rule2.getUuid())); | |||
activeRuleIndexer.indexOnStartup(emptySet()); | |||
activeRuleIndexer.indexAll(); | |||
// Set parent 1 | |||
qProfileTree.setParentAndCommit(dbSession, child, parent1); | |||
@@ -193,7 +192,7 @@ public class ChangeParentActionTest { | |||
RuleDefinitionDto rule1 = createRule(); | |||
createActiveRule(rule1, parent); | |||
ruleIndexer.commitAndIndex(dbSession, rule1.getUuid()); | |||
activeRuleIndexer.indexOnStartup(emptySet()); | |||
activeRuleIndexer.indexAll(); | |||
// Set parent | |||
qProfileTree.setParentAndCommit(dbSession, child, parent); | |||
@@ -222,7 +221,7 @@ public class ChangeParentActionTest { | |||
createActiveRule(rule1, parent1); | |||
createActiveRule(rule2, parent2); | |||
ruleIndexer.commitAndIndex(dbSession, rule1.getUuid()); | |||
activeRuleIndexer.indexOnStartup(emptySet()); | |||
activeRuleIndexer.indexAll(); | |||
assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, child.getKee())).isEmpty(); | |||
@@ -275,7 +274,7 @@ public class ChangeParentActionTest { | |||
RuleDefinitionDto rule1 = createRule(); | |||
createActiveRule(rule1, parent); | |||
ruleIndexer.commitAndIndex(dbSession, rule1.getUuid()); | |||
activeRuleIndexer.indexOnStartup(emptySet()); | |||
activeRuleIndexer.indexAll(); | |||
assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, child.getKee())).isEmpty(); | |||
@@ -306,7 +305,7 @@ public class ChangeParentActionTest { | |||
createActiveRule(rule1, parent1); | |||
createActiveRule(rule2, parent2); | |||
ruleIndexer.commitAndIndex(dbSession, asList(rule1.getUuid(), rule2.getUuid())); | |||
activeRuleIndexer.indexOnStartup(emptySet()); | |||
activeRuleIndexer.indexAll(); | |||
// Set parent 1 | |||
qProfileTree.setParentAndCommit(dbSession, child, parent1); | |||
UserDto user = db.users().insertUser(); |
@@ -106,7 +106,7 @@ public class InheritanceActionTest { | |||
createActiveRule(rule2, sonarway); | |||
dbSession.commit(); | |||
activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes()); | |||
activeRuleIndexer.indexAll(); | |||
QProfileDto companyWide = createProfile("xoo", "My Company Profile", "xoo-my-company-profile-12345"); | |||
setParent(sonarway, companyWide); | |||
@@ -119,7 +119,7 @@ public class InheritanceActionTest { | |||
setParent(buWide, forProject1); | |||
createActiveRule(rule3, forProject1); | |||
dbSession.commit(); | |||
activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes()); | |||
activeRuleIndexer.indexAll(); | |||
QProfileDto forProject2 = createProfile("xoo", "For Project Two", "xoo-for-project-two-45678"); | |||
setParent(buWide, forProject2); | |||
@@ -150,7 +150,7 @@ public class InheritanceActionTest { | |||
db.qualityProfiles().activateRule(child, rule3); | |||
long childRules = 1; | |||
activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes()); | |||
activeRuleIndexer.indexAll(); | |||
InputStream response = ws.newRequest() | |||
.setMediaType(PROTOBUF) | |||
@@ -177,7 +177,7 @@ public class InheritanceActionTest { | |||
db.qualityProfiles().activateRule(profile, rule); | |||
long activeRules = 0; | |||
activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes()); | |||
activeRuleIndexer.indexAll(); | |||
InputStream response = ws.newRequest() | |||
.setMediaType(PROTOBUF) |
@@ -109,7 +109,7 @@ public class QProfilesWsMediumTest { | |||
RuleDefinitionDto rule = createRule(profile.getLanguage(), "toto"); | |||
createActiveRule(rule, profile); | |||
ruleIndexer.commitAndIndex(dbSession, rule.getUuid()); | |||
activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes()); | |||
activeRuleIndexer.indexAll(); | |||
// 0. Assert No Active Rule for profile | |||
assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, profile.getKee())).hasSize(1); | |||
@@ -137,7 +137,7 @@ public class QProfilesWsMediumTest { | |||
createActiveRule(rule3, profile); | |||
createActiveRule(rule1, profile); | |||
dbSession.commit(); | |||
activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes()); | |||
activeRuleIndexer.indexAll(); | |||
// 0. Assert No Active Rule for profile | |||
assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, profile.getKee())).hasSize(4); | |||
@@ -163,7 +163,7 @@ public class QProfilesWsMediumTest { | |||
createActiveRule(rule0, php); | |||
createActiveRule(rule1, php); | |||
dbSession.commit(); | |||
activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes()); | |||
activeRuleIndexer.indexAll(); | |||
// 0. Assert No Active Rule for profile | |||
assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, profile.getKee())).hasSize(2); | |||
@@ -187,7 +187,7 @@ public class QProfilesWsMediumTest { | |||
createActiveRule(rule0, profile); | |||
createActiveRule(rule1, profile); | |||
dbSession.commit(); | |||
activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes()); | |||
activeRuleIndexer.indexAll(); | |||
// 0. Assert No Active Rule for profile | |||
assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, profile.getKee())).hasSize(2); | |||
@@ -421,7 +421,7 @@ public class QProfilesWsMediumTest { | |||
dbClient.activeRuleDao().insert(dbSession, active2); | |||
dbSession.commit(); | |||
activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes()); | |||
activeRuleIndexer.indexAll(); | |||
// 0. assert rule child rule is minor | |||
Optional<ActiveRuleDto> activeRuleDto = dbClient.activeRuleDao().selectByKey(dbSession, active2.getKey()); |
@@ -166,8 +166,8 @@ public class ShowActionTest { | |||
db.qualityProfiles().activateRule(sonarWayProfile, commonRule); | |||
db.qualityProfiles().activateRule(sonarWayProfile, sonarWayRule1); | |||
db.qualityProfiles().activateRule(sonarWayProfile, sonarWayRule2); | |||
ruleIndexer.indexOnStartup(ruleIndexer.getIndexTypes()); | |||
activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes()); | |||
ruleIndexer.indexAll(); | |||
activeRuleIndexer.indexAll(); | |||
CompareToSonarWay result = call(ws.newRequest() | |||
.setParam(PARAM_KEY, profile.getKee()) | |||
@@ -186,8 +186,8 @@ public class ShowActionTest { | |||
RuleDefinitionDto commonRule = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())).getDefinition(); | |||
db.qualityProfiles().activateRule(profile, commonRule); | |||
db.qualityProfiles().activateRule(sonarWayProfile, commonRule); | |||
ruleIndexer.indexOnStartup(ruleIndexer.getIndexTypes()); | |||
activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes()); | |||
ruleIndexer.indexAll(); | |||
activeRuleIndexer.indexAll(); | |||
CompareToSonarWay result = call(ws.newRequest() | |||
.setParam(PARAM_KEY, profile.getKee()) |
@@ -921,11 +921,11 @@ public class SearchActionTest { | |||
} | |||
private void indexRules() { | |||
ruleIndexer.indexOnStartup(ruleIndexer.getIndexTypes()); | |||
ruleIndexer.indexAll(); | |||
} | |||
private void indexActiveRules() { | |||
activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes()); | |||
activeRuleIndexer.indexAll(); | |||
} | |||
private String[] get101Tags() { |
@@ -19,9 +19,7 @@ | |||
*/ | |||
package org.sonar.server.user.ws; | |||
import java.util.HashSet; | |||
import java.util.Optional; | |||
import org.elasticsearch.action.search.SearchRequest; | |||
import org.elasticsearch.search.builder.SearchSourceBuilder; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
@@ -225,7 +223,7 @@ public class CreateActionTest { | |||
logInAsSystemAdministrator(); | |||
db.users().insertUser(newUserDto("john", "John", "john@email.com").setActive(false)); | |||
userIndexer.indexOnStartup(new HashSet<>()); | |||
userIndexer.indexAll(); | |||
call(CreateRequest.builder() | |||
.setLogin("john") |
@@ -65,7 +65,7 @@ public class SearchActionTest { | |||
public void search_for_all_users() { | |||
UserDto user1 = db.users().insertUser(); | |||
UserDto user2 = db.users().insertUser(); | |||
userIndexer.indexOnStartup(null); | |||
userIndexer.indexAll(); | |||
userSession.logIn(); | |||
SearchWsResponse response = ws.newRequest() | |||
@@ -87,7 +87,7 @@ public class SearchActionTest { | |||
.setEmail("user@mail.com") | |||
.setLocal(true) | |||
.setScmAccounts(singletonList("user1"))); | |||
userIndexer.indexOnStartup(null); | |||
userIndexer.indexAll(); | |||
assertThat(ws.newRequest() | |||
.setParam("q", "user-%_%-") | |||
@@ -109,7 +109,7 @@ public class SearchActionTest { | |||
@Test | |||
public void return_avatar() { | |||
UserDto user = db.users().insertUser(u -> u.setEmail("john@doe.com")); | |||
userIndexer.indexOnStartup(null); | |||
userIndexer.indexAll(); | |||
userSession.logIn(); | |||
SearchWsResponse response = ws.newRequest() | |||
@@ -123,7 +123,7 @@ public class SearchActionTest { | |||
@Test | |||
public void return_scm_accounts() { | |||
UserDto user = db.users().insertUser(u -> u.setScmAccounts(asList("john1", "john2"))); | |||
userIndexer.indexOnStartup(null); | |||
userIndexer.indexAll(); | |||
userSession.logIn(); | |||
SearchWsResponse response = ws.newRequest() | |||
@@ -139,7 +139,7 @@ public class SearchActionTest { | |||
UserDto user = db.users().insertUser(); | |||
db.users().insertToken(user); | |||
db.users().insertToken(user); | |||
userIndexer.indexOnStartup(null); | |||
userIndexer.indexAll(); | |||
userSession.logIn().setSystemAdministrator(); | |||
assertThat(ws.newRequest() | |||
@@ -157,7 +157,7 @@ public class SearchActionTest { | |||
@Test | |||
public void return_email_only_when_system_administer() { | |||
UserDto user = db.users().insertUser(); | |||
userIndexer.indexOnStartup(null); | |||
userIndexer.indexAll(); | |||
userSession.logIn().setSystemAdministrator(); | |||
assertThat(ws.newRequest() | |||
@@ -175,7 +175,7 @@ public class SearchActionTest { | |||
@Test | |||
public void return_user_not_having_email() { | |||
UserDto user = db.users().insertUser(u -> u.setEmail(null)); | |||
userIndexer.indexOnStartup(null); | |||
userIndexer.indexAll(); | |||
userSession.logIn().setSystemAdministrator(); | |||
SearchWsResponse response = ws.newRequest() | |||
@@ -194,7 +194,7 @@ public class SearchActionTest { | |||
GroupDto group3 = db.users().insertGroup("group3"); | |||
db.users().insertMember(group1, user); | |||
db.users().insertMember(group2, user); | |||
userIndexer.indexOnStartup(null); | |||
userIndexer.indexAll(); | |||
userSession.logIn().setSystemAdministrator(); | |||
assertThat(ws.newRequest() | |||
@@ -212,7 +212,7 @@ public class SearchActionTest { | |||
@Test | |||
public void return_external_information() { | |||
UserDto user = db.users().insertUser(); | |||
userIndexer.indexOnStartup(null); | |||
userIndexer.indexAll(); | |||
userSession.logIn().setSystemAdministrator(); | |||
SearchWsResponse response = ws.newRequest() | |||
@@ -226,7 +226,7 @@ public class SearchActionTest { | |||
@Test | |||
public void return_external_identity_only_when_system_administer() { | |||
UserDto user = db.users().insertUser(); | |||
userIndexer.indexOnStartup(null); | |||
userIndexer.indexAll(); | |||
userSession.logIn().setSystemAdministrator(); | |||
assertThat(ws.newRequest() | |||
@@ -247,7 +247,7 @@ public class SearchActionTest { | |||
db.users().insertToken(user); | |||
GroupDto group = db.users().insertGroup(); | |||
db.users().insertMember(group, user); | |||
userIndexer.indexOnStartup(null); | |||
userIndexer.indexAll(); | |||
userSession.anonymous(); | |||
SearchWsResponse response = ws.newRequest() | |||
@@ -263,7 +263,7 @@ public class SearchActionTest { | |||
UserDto userWithLastConnectionDate = db.users().insertUser(); | |||
db.users().updateLastConnectionDate(userWithLastConnectionDate, 10_000_000_000L); | |||
UserDto userWithoutLastConnectionDate = db.users().insertUser(); | |||
userIndexer.indexOnStartup(null); | |||
userIndexer.indexAll(); | |||
userSession.logIn().setSystemAdministrator(); | |||
SearchWsResponse response = ws.newRequest() | |||
@@ -285,7 +285,7 @@ public class SearchActionTest { | |||
GroupDto group = db.users().insertGroup(); | |||
db.users().insertMember(group, user); | |||
UserDto otherUser = db.users().insertUser(); | |||
userIndexer.indexOnStartup(null); | |||
userIndexer.indexAll(); | |||
userSession.logIn(user); | |||
assertThat(ws.newRequest().setParam("q", user.getLogin()) | |||
@@ -308,7 +308,7 @@ public class SearchActionTest { | |||
public void search_with_paging() { | |||
userSession.logIn(); | |||
IntStream.rangeClosed(0, 9).forEach(i -> db.users().insertUser(u -> u.setLogin("user-" + i).setName("User " + i))); | |||
userIndexer.indexOnStartup(null); | |||
userIndexer.indexAll(); | |||
SearchWsResponse response = ws.newRequest() | |||
.setParam(Param.PAGE_SIZE, "5") | |||
@@ -364,7 +364,7 @@ public class SearchActionTest { | |||
db.users().insertToken(simon); | |||
db.users().insertToken(simon); | |||
db.users().insertToken(fmallet); | |||
userIndexer.indexOnStartup(null); | |||
userIndexer.indexAll(); | |||
userSession.logIn().setSystemAdministrator(); | |||
String response = ws.newRequest().execute().getInput(); |