Search in sources :

Example 26 with RuleQuery

use of org.sonar.server.rule.index.RuleQuery in project sonarqube by SonarSource.

the class QProfileExportersTest method import_xml.

@Test
public void import_xml() {
    QualityProfileDto profileDto = QProfileTesting.newQProfileDto("org-123", QProfileName.createFor("xoo", "import_xml"), "import_xml");
    db.qualityProfileDao().insert(dbSession, profileDto);
    dbSession.commit();
    assertThat(db.activeRuleDao().selectByProfileKey(dbSession, profileDto.getKey())).isEmpty();
    QProfileResult result = exporters.importXml(profileDto, "XooProfileImporter", toInputStream("<xml/>", UTF_8), dbSession);
    dbSession.commit();
    activeRuleIndexer.index(result.getChanges());
    // Check in db
    List<ActiveRuleDto> activeRules = db.activeRuleDao().selectByProfileKey(dbSession, profileDto.getKey());
    assertThat(activeRules).hasSize(1);
    ActiveRuleDto activeRule = activeRules.get(0);
    assertThat(activeRule.getKey().ruleKey()).isEqualTo(RuleKey.of("xoo", "R1"));
    assertThat(activeRule.getSeverityString()).isEqualTo(Severity.CRITICAL);
    // Check in es
    assertThat(tester.get(RuleIndex.class).searchAll(new RuleQuery().setQProfileKey(profileDto.getKey()).setActivation(true))).containsOnly(RuleKey.of("xoo", "R1"));
}
Also used : RuleIndex(org.sonar.server.rule.index.RuleIndex) RuleQuery(org.sonar.server.rule.index.RuleQuery) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Test(org.junit.Test)

Example 27 with RuleQuery

use of org.sonar.server.rule.index.RuleQuery in project sonarqube by SonarSource.

the class RuleActivatorMediumTest method verifyHasActiveRuleInIndex.

private void verifyHasActiveRuleInIndex(ActiveRuleKey activeRuleKey, String expectedSeverity, @Nullable String expectedInheritance) {
    // verify es
    List<RuleKey> ruleKeys = newArrayList(tester.get(RuleIndex.class).searchAll(new RuleQuery().setKey(activeRuleKey.ruleKey().toString()).setQProfileKey(activeRuleKey.qProfile()).setActivation(true).setInheritance(singleton(expectedInheritance == null ? ActiveRule.Inheritance.NONE.name() : ActiveRule.Inheritance.valueOf(expectedInheritance).name())).setActiveSeverities(singleton(expectedSeverity))));
    assertThat(ruleKeys).as("Rule is not activated in index").hasSize(1);
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) ActiveRuleKey(org.sonar.db.qualityprofile.ActiveRuleKey) RuleQuery(org.sonar.server.rule.index.RuleQuery)

Example 28 with RuleQuery

use of org.sonar.server.rule.index.RuleQuery in project sonarqube by SonarSource.

the class RuleActivatorMediumTest method bulk_activation_ignores_errors.

@Test
public void bulk_activation_ignores_errors() {
    // 1. bulk activate all the rules, even non xoo-rules and xoo templates
    BulkChangeResult result = ruleActivator.bulkActivate(new RuleQuery(), XOO_P1_KEY, "MINOR");
    // 2. assert that all activations have been commit to DB and ES
    // -> xoo rules x1, x2 and custom1
    dbSession.clearCache();
    assertThat(db.activeRuleDao().selectByProfileKey(dbSession, XOO_P1_KEY)).hasSize(3);
    assertThat(db.activeRuleDao().selectByProfileKey(dbSession, XOO_P1_KEY)).hasSize(3);
    assertThat(result.countSucceeded()).isEqualTo(3);
    assertThat(result.countFailed()).isGreaterThan(0);
}
Also used : RuleQuery(org.sonar.server.rule.index.RuleQuery) Test(org.junit.Test)

Example 29 with RuleQuery

use of org.sonar.server.rule.index.RuleQuery in project sonarqube by SonarSource.

the class RuleActivatorMediumTest method bulk_deactivate.

@Test
public void bulk_deactivate() {
    activate(new RuleActivation(XOO_X1), XOO_P1_KEY);
    activate(new RuleActivation(XOO_X2), XOO_P1_KEY);
    assertThat(countActiveRules(XOO_P1_KEY)).isEqualTo(2);
    BulkChangeResult result = ruleActivator.bulkDeactivate(new RuleQuery().setActivation(true).setQProfileKey(XOO_P1_KEY), XOO_P1_KEY);
    dbSession.clearCache();
    assertThat(countActiveRules(XOO_P1_KEY)).isEqualTo(0);
    assertThat(result.countFailed()).isEqualTo(0);
    assertThat(result.countSucceeded()).isEqualTo(2);
    assertThat(result.getChanges()).hasSize(2);
}
Also used : RuleQuery(org.sonar.server.rule.index.RuleQuery) Test(org.junit.Test)

Example 30 with RuleQuery

use of org.sonar.server.rule.index.RuleQuery in project sonarqube by SonarSource.

the class RuleQueryFactoryTest method create_empty_query.

@Test
public void create_empty_query() throws Exception {
    RuleQuery result = execute();
    assertThat(result.getKey()).isNull();
    assertThat(result.getActivation()).isNull();
    assertThat(result.getActiveSeverities()).isNull();
    assertThat(result.isAscendingSort()).isTrue();
    assertThat(result.getAvailableSinceLong()).isNull();
    assertThat(result.getInheritance()).isNull();
    assertThat(result.isTemplate()).isNull();
    assertThat(result.getLanguages()).isNull();
    assertThat(result.getQueryText()).isNull();
    assertThat(result.getQProfileKey()).isNull();
    assertThat(result.getRepositories()).isNull();
    assertThat(result.getRuleKey()).isNull();
    assertThat(result.getSeverities()).isNull();
    assertThat(result.getStatuses()).isEmpty();
    assertThat(result.getTags()).isNull();
    assertThat(result.templateKey()).isNull();
    assertThat(result.getTypes()).isEmpty();
    assertThat(result.getSortField()).isNull();
}
Also used : RuleQuery(org.sonar.server.rule.index.RuleQuery) Test(org.junit.Test)

Aggregations

RuleQuery (org.sonar.server.rule.index.RuleQuery)39 Test (org.junit.Test)34 SearchOptions (org.sonar.server.es.SearchOptions)22 RuleDto (org.sonar.db.rule.RuleDto)16 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)14 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)14 RuleIndex (org.sonar.server.rule.index.RuleIndex)7 ActiveRuleParamDto (org.sonar.db.qualityprofile.ActiveRuleParamDto)5 RuleKey (org.sonar.api.rule.RuleKey)4 RulesDefinition (org.sonar.api.server.rule.RulesDefinition)4 ActiveRuleDao (org.sonar.db.qualityprofile.ActiveRuleDao)4 RuleParamDto (org.sonar.db.rule.RuleParamDto)4 ActiveRuleKey (org.sonar.db.qualityprofile.ActiveRuleKey)3 RuleActivation (org.sonar.server.qualityprofile.RuleActivation)3 RuleActivator (org.sonar.server.qualityprofile.RuleActivator)3 ActiveRuleIndex (org.sonar.server.qualityprofile.index.ActiveRuleIndex)3 StringReader (java.io.StringReader)2 QProfileService (org.sonar.server.qualityprofile.QProfileService)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Map (java.util.Map)1