Search in sources :

Example 1 with READY

use of org.sonar.api.rule.RuleStatus.READY in project sonarqube by SonarSource.

the class RegisterRulesTest method mass_insert_then_remove_rule.

@Test
public void mass_insert_then_remove_rule() {
    int numberOfRules = 5000;
    // register many rules
    execute(context -> {
        NewRepository repo = context.createRepository("fake", "java");
        IntStream.range(0, numberOfRules).mapToObj(i -> "rule-" + i).forEach(ruleKey -> repo.createRule(ruleKey).setName(randomAlphanumeric(20)).setHtmlDescription(randomAlphanumeric(20)));
        repo.done();
    });
    // verify db
    assertThat(dbClient.ruleDao().selectAllDefinitions(db.getSession())).hasSize(numberOfRules).extracting(RuleDefinitionDto::getStatus).containsOnly(READY);
    // verify index
    assertThat(es.countDocuments(RuleIndexDefinition.TYPE_RULE)).isEqualTo(numberOfRules);
    assertThat(ruleIndex.search(new RuleQuery(), new SearchOptions()).getUuids()).isNotEmpty();
    // register no rule
    execute(context -> context.createRepository("fake", "java").done());
    // verify db
    assertThat(dbClient.ruleDao().selectAllDefinitions(db.getSession())).hasSize(numberOfRules).extracting(RuleDefinitionDto::getStatus).containsOnly(REMOVED);
    // verify index (documents are still in the index, but all are removed)
    assertThat(es.countDocuments(RuleIndexDefinition.TYPE_RULE)).isEqualTo(numberOfRules);
    assertThat(ruleIndex.search(new RuleQuery(), new SearchOptions()).getUuids()).isEmpty();
}
Also used : NewRepository(org.sonar.api.server.rule.RulesDefinition.NewRepository) Arrays(java.util.Arrays) REMOVED(org.sonar.api.rule.RuleStatus.REMOVED) Y2021(org.sonar.api.server.rule.RulesDefinition.OwaspTop10Version.Y2021) RandomStringUtils.randomAlphanumeric(org.apache.commons.lang.RandomStringUtils.randomAlphanumeric) Date(java.util.Date) ActiveRuleIndexer(org.sonar.server.qualityprofile.index.ActiveRuleIndexer) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) DbSession(org.sonar.db.DbSession) Collections.singletonList(java.util.Collections.singletonList) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) NewRepository(org.sonar.api.server.rule.RulesDefinition.NewRepository) Languages(org.sonar.api.resources.Languages) BLOCKER(org.sonar.api.rule.Severity.BLOCKER) DebtRemediationFunction(org.sonar.api.server.debt.DebtRemediationFunction) MetadataIndex(org.sonar.server.es.metadata.MetadataIndex) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) UuidFactoryFast(org.sonar.core.util.UuidFactoryFast) RuleIndexer(org.sonar.server.rule.index.RuleIndexer) DbTester(org.sonar.db.DbTester) SearchIdResult(org.sonar.server.es.SearchIdResult) Context(org.sonar.api.server.rule.RulesDefinition.Context) NewRule(org.sonar.api.server.rule.RulesDefinition.NewRule) Set(java.util.Set) DbClient(org.sonar.db.DbClient) QProfileRules(org.sonar.server.qualityprofile.QProfileRules) List(java.util.List) RuleRepositoryDto(org.sonar.db.rule.RuleRepositoryDto) SearchOptions(org.sonar.server.es.SearchOptions) INFO(org.sonar.api.rule.Severity.INFO) RuleKey(org.sonar.api.rule.RuleKey) RuleIndexDefinition(org.sonar.server.rule.index.RuleIndexDefinition) OwaspTop10(org.sonar.api.server.rule.RulesDefinition.OwaspTop10) Mockito.mock(org.mockito.Mockito.mock) IntStream(java.util.stream.IntStream) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) RulesDefinition(org.sonar.api.server.rule.RulesDefinition) READY(org.sonar.api.rule.RuleStatus.READY) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) EsTester(org.sonar.server.es.EsTester) RuleStatus(org.sonar.api.rule.RuleStatus) RunWith(org.junit.runner.RunWith) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) TestSystem2(org.sonar.api.impl.utils.TestSystem2) RuleType(org.sonar.api.rules.RuleType) DateUtils(org.sonar.api.utils.DateUtils) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) RuleScope(org.sonar.api.rule.RuleScope) Scope(org.sonar.db.rule.RuleDto.Scope) ServerPluginRepository(org.sonar.server.plugins.ServerPluginRepository) Language(org.sonar.api.resources.Language) Before(org.junit.Before) Collections.emptySet(java.util.Collections.emptySet) Assertions.tuple(org.assertj.core.api.Assertions.tuple) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) UuidFactory(org.sonar.core.util.UuidFactory) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) RuleIndex(org.sonar.server.rule.index.RuleIndex) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) RuleQuery(org.sonar.server.rule.index.RuleQuery) LogTester(org.sonar.api.utils.log.LogTester) RuleParamDto(org.sonar.db.rule.RuleParamDto) String.valueOf(java.lang.String.valueOf) RuleDto(org.sonar.db.rule.RuleDto) DeprecatedRuleKeyDto(org.sonar.db.rule.DeprecatedRuleKeyDto) Mockito.reset(org.mockito.Mockito.reset) RuleQuery(org.sonar.server.rule.index.RuleQuery) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Aggregations

Sets.newHashSet (com.google.common.collect.Sets.newHashSet)1 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)1 DataProviderRunner (com.tngtech.java.junit.dataprovider.DataProviderRunner)1 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1 String.valueOf (java.lang.String.valueOf)1 Arrays (java.util.Arrays)1 Collections.emptySet (java.util.Collections.emptySet)1 Collections.singletonList (java.util.Collections.singletonList)1 Date (java.util.Date)1 List (java.util.List)1 Set (java.util.Set)1 Consumer (java.util.function.Consumer)1 IntStream (java.util.stream.IntStream)1 RandomStringUtils.randomAlphanumeric (org.apache.commons.lang.RandomStringUtils.randomAlphanumeric)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)1 Assertions.tuple (org.assertj.core.api.Assertions.tuple)1 Before (org.junit.Before)1 Test (org.junit.Test)1 RunWith (org.junit.runner.RunWith)1