Search in sources :

Example 96 with QualityProfileDto

use of org.sonar.db.qualityprofile.QualityProfileDto in project sonarqube by SonarSource.

the class ChangeParentActionMediumTest method fail_if_profile_key_and_name_both_set.

@Test(expected = IllegalArgumentException.class)
public void fail_if_profile_key_and_name_both_set() throws Exception {
    QualityProfileDto child = createProfile("xoo", "Child");
    session.commit();
    assertThat(db.activeRuleDao().selectByProfileKey(session, child.getKey())).isEmpty();
    assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfileKey(child.getKey()), new SearchOptions()).getIds()).isEmpty();
    wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, "change_parent").setParam(QProfileRef.PARAM_PROFILE_KEY, child.getKee()).setParam(QProfileRef.PARAM_PROFILE_NAME, child.getName()).setParam("parentKey", "palap").execute();
}
Also used : RuleQuery(org.sonar.server.rule.index.RuleQuery) SearchOptions(org.sonar.server.es.SearchOptions) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Test(org.junit.Test)

Example 97 with QualityProfileDto

use of org.sonar.db.qualityprofile.QualityProfileDto in project sonarqube by SonarSource.

the class ChangeParentActionMediumTest method change_parent_with_names.

@Test
public void change_parent_with_names() throws Exception {
    QualityProfileDto parent1 = createProfile("xoo", "Parent 1");
    QualityProfileDto parent2 = createProfile("xoo", "Parent 2");
    QualityProfileDto child = createProfile("xoo", "Child");
    RuleDto rule1 = createRule("xoo", "rule1");
    RuleDto rule2 = createRule("xoo", "rule2");
    createActiveRule(rule1, parent1);
    createActiveRule(rule2, parent2);
    session.commit();
    ruleIndexer.index();
    activeRuleIndexer.index();
    assertThat(db.activeRuleDao().selectByProfileKey(session, child.getKey())).isEmpty();
    // 1. Set parent 1
    wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, "change_parent").setParam(QProfileRef.PARAM_LANGUAGE, "xoo").setParam(QProfileRef.PARAM_PROFILE_NAME, child.getName()).setParam("parentName", parent1.getName()).execute();
    session.clearCache();
    // 1. check rule 1 enabled
    List<ActiveRuleDto> activeRules1 = db.activeRuleDao().selectByProfileKey(session, child.getKey());
    assertThat(activeRules1).hasSize(1);
    assertThat(activeRules1.get(0).getKey().ruleKey().rule()).isEqualTo("rule1");
    assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfileKey(child.getKey()), new SearchOptions()).getIds()).hasSize(1);
    // 2. Set parent 2
    wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, "change_parent").setParam(QProfileRef.PARAM_LANGUAGE, "xoo").setParam(QProfileRef.PARAM_PROFILE_NAME, child.getName()).setParam("parentName", parent2.getName()).execute();
    session.clearCache();
    // 2. check rule 2 enabled
    List<ActiveRuleDto> activeRules2 = db.activeRuleDao().selectByProfileKey(session, child.getKey());
    assertThat(activeRules2).hasSize(1);
    assertThat(activeRules2.get(0).getKey().ruleKey().rule()).isEqualTo("rule2");
    // 3. Remove parent
    wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, "change_parent").setParam(QProfileRef.PARAM_LANGUAGE, "xoo").setParam(QProfileRef.PARAM_PROFILE_NAME, child.getName()).setParam("parentName", "").execute();
    session.clearCache();
    // 3. check no rule enabled
    List<ActiveRuleDto> activeRules = db.activeRuleDao().selectByProfileKey(session, child.getKey());
    assertThat(activeRules).isEmpty();
    assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfileKey(child.getKey()), new SearchOptions()).getIds()).isEmpty();
}
Also used : ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto) RuleQuery(org.sonar.server.rule.index.RuleQuery) SearchOptions(org.sonar.server.es.SearchOptions) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Test(org.junit.Test)

Example 98 with QualityProfileDto

use of org.sonar.db.qualityprofile.QualityProfileDto in project sonarqube by SonarSource.

the class ChangeParentActionMediumTest method remove_parent.

@Test
public void remove_parent() throws Exception {
    QualityProfileDto parent = createProfile("xoo", "Parent 1");
    QualityProfileDto child = createProfile("xoo", "Child");
    RuleDto rule1 = createRule("xoo", "rule1");
    createActiveRule(rule1, parent);
    session.commit();
    ruleIndexer.index();
    activeRuleIndexer.index();
    // Set parent
    tester.get(RuleActivator.class).setParent(session, child.getKey(), parent.getKey());
    session.clearCache();
    // Remove parent through WS
    wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, "change_parent").setParam(QProfileRef.PARAM_PROFILE_KEY, child.getKey()).execute();
    session.clearCache();
    // Check no rule enabled
    List<ActiveRuleDto> activeRules = db.activeRuleDao().selectByProfileKey(session, child.getKey());
    assertThat(activeRules).isEmpty();
    assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfileKey(child.getKey()), new SearchOptions()).getIds()).isEmpty();
}
Also used : ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto) RuleActivator(org.sonar.server.qualityprofile.RuleActivator) RuleQuery(org.sonar.server.rule.index.RuleQuery) SearchOptions(org.sonar.server.es.SearchOptions) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Test(org.junit.Test)

Example 99 with QualityProfileDto

use of org.sonar.db.qualityprofile.QualityProfileDto in project sonarqube by SonarSource.

the class QProfilesWsMediumTest method bulk_deactivate_rule_by_profile.

@Test
public void bulk_deactivate_rule_by_profile() throws Exception {
    QualityProfileDto profile = createProfile("java");
    RuleDto rule0 = createRule(profile.getLanguage(), "hello");
    RuleDto rule1 = createRule(profile.getLanguage(), "world");
    createActiveRule(rule0, profile);
    createActiveRule(rule1, profile);
    session.commit();
    ruIndexer.index();
    activeRuIndexer.index();
    // 0. Assert No Active Rule for profile
    assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(2);
    // 1. Deactivate Rule
    WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, BulkRuleActivationActions.BULK_DEACTIVATE_ACTION);
    request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey());
    request.setParam(WebService.Param.TEXT_QUERY, "hello");
    WsTester.Result result = request.execute();
    session.clearCache();
    // 2. Assert ActiveRule in DAO
    assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(1);
}
Also used : WsTester(org.sonar.server.ws.WsTester) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Test(org.junit.Test)

Example 100 with QualityProfileDto

use of org.sonar.db.qualityprofile.QualityProfileDto in project sonarqube by SonarSource.

the class QProfilesWsMediumTest method bulk_activate_rule_by_query_with_severity.

@Test
public void bulk_activate_rule_by_query_with_severity() throws Exception {
    QualityProfileDto profile = createProfile("java");
    RuleDto rule0 = createRule(profile.getLanguage(), "toto");
    RuleDto rule1 = createRule(profile.getLanguage(), "tata");
    session.commit();
    ruIndexer.index();
    // 0. Assert No Active Rule for profile
    assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();
    // 2. Assert ActiveRule with BLOCKER severity
    assertThat(tester.get(RuleIndex.class).search(new RuleQuery().setSeverities(ImmutableSet.of("BLOCKER")), new SearchOptions()).getIds()).hasSize(2);
    // 1. Activate Rule with query returning 2 hits
    WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, BulkRuleActivationActions.BULK_ACTIVATE_ACTION);
    request.setParam(BulkRuleActivationActions.PROFILE_KEY, profile.getKey());
    request.setParam(BulkRuleActivationActions.SEVERITY, "MINOR");
    request.execute();
    session.commit();
    // 2. Assert ActiveRule with MINOR severity
    assertThat(tester.get(ActiveRuleDao.class).selectByRuleId(session, rule0.getId()).get(0).getSeverityString()).isEqualTo("MINOR");
    assertThat(tester.get(RuleIndex.class).searchAll(new RuleQuery().setQProfileKey(profile.getKey()).setKey(rule0.getKey().toString()).setActiveSeverities(Collections.singleton("MINOR")).setActivation(true))).hasSize(1);
}
Also used : ActiveRuleDao(org.sonar.db.qualityprofile.ActiveRuleDao) RuleIndex(org.sonar.server.rule.index.RuleIndex) WsTester(org.sonar.server.ws.WsTester) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto) RuleQuery(org.sonar.server.rule.index.RuleQuery) SearchOptions(org.sonar.server.es.SearchOptions) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Test(org.junit.Test)

Aggregations

QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)126 Test (org.junit.Test)76 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)37 RuleDto (org.sonar.db.rule.RuleDto)29 WsTester (org.sonar.server.ws.WsTester)21 RuleQuery (org.sonar.server.rule.index.RuleQuery)14 QualityProfileDao (org.sonar.db.qualityprofile.QualityProfileDao)13 ActiveRuleDao (org.sonar.db.qualityprofile.ActiveRuleDao)12 DbSession (org.sonar.db.DbSession)11 ActiveRuleParamDto (org.sonar.db.qualityprofile.ActiveRuleParamDto)9 SearchOptions (org.sonar.server.es.SearchOptions)9 ComponentDto (org.sonar.db.component.ComponentDto)8 OrganizationDto (org.sonar.db.organization.OrganizationDto)7 ActiveRuleKey (org.sonar.db.qualityprofile.ActiveRuleKey)6 Date (java.util.Date)5 QualityProfileTesting.newQualityProfileDto (org.sonar.db.qualityprofile.QualityProfileTesting.newQualityProfileDto)5 RuleParamDto (org.sonar.db.rule.RuleParamDto)5 RulesProfile (org.sonar.api.profiles.RulesProfile)4 Language (org.sonar.api.resources.Language)4 RuleKey (org.sonar.api.rule.RuleKey)4