Search in sources :

Example 11 with ActiveRuleDto

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

the class CompareActionMediumTest method createActiveRuleWithParam.

private ActiveRuleDto createActiveRuleWithParam(RuleDto rule, QualityProfileDto profile, String value) {
    ActiveRuleDto activeRule = createActiveRule(rule, profile);
    RuleParamDto paramDto = db.ruleDao().selectRuleParamsByRuleKey(session, rule.getKey()).get(0);
    ActiveRuleParamDto activeRuleParam = ActiveRuleParamDto.createFor(paramDto).setValue(value);
    db.activeRuleDao().insertParam(session, activeRule, activeRuleParam);
    return activeRule;
}
Also used : ActiveRuleParamDto(org.sonar.db.qualityprofile.ActiveRuleParamDto) ActiveRuleParamDto(org.sonar.db.qualityprofile.ActiveRuleParamDto) RuleParamDto(org.sonar.db.rule.RuleParamDto) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto)

Example 12 with ActiveRuleDto

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

the class CompareActionMediumTest method createActiveRuleWithSeverity.

private ActiveRuleDto createActiveRuleWithSeverity(RuleDto rule, QualityProfileDto profile, String severity) {
    ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule).setSeverity(severity);
    db.activeRuleDao().insert(session, activeRule);
    return activeRule;
}
Also used : ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto)

Example 13 with ActiveRuleDto

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

the class RuleActivatorMediumTest method verifyZeroActiveRules.

private void verifyZeroActiveRules(String key) {
    // verify db
    dbSession.clearCache();
    List<ActiveRuleDto> activeRuleDtos = db.activeRuleDao().selectByProfileKey(dbSession, key);
    assertThat(activeRuleDtos).isEmpty();
    // verify es
    assertThat(tester.get(RuleIndex.class).searchAll(new RuleQuery().setQProfileKey(key).setActivation(true))).isEmpty();
}
Also used : ActiveRuleIndex(org.sonar.server.qualityprofile.index.ActiveRuleIndex) RuleIndex(org.sonar.server.rule.index.RuleIndex) RuleQuery(org.sonar.server.rule.index.RuleQuery) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto)

Example 14 with ActiveRuleDto

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

the class QProfileBackuperMediumTest method restore_parent_profile.

@Test
public void restore_parent_profile() throws Exception {
    // define two parent/child profiles
    db.qualityProfileDao().insert(dbSession, newXooP1("org-123"), newXooP2("org-123").setParentKee(XOO_P1_KEY));
    dbSession.commit();
    // rule x1 is activated on parent profile (so inherited by child profile)
    RuleActivation activation = new RuleActivation(XOO_X1);
    activation.setSeverity(Severity.INFO);
    activation.setParameter("max", "10");
    tester.get(RuleActivator.class).activate(dbSession, activation, XOO_P1_KEY);
    dbSession.commit();
    dbSession.clearCache();
    activeRuleIndexer.index();
    // restore backup of parent profile -> update x1 and propagates to child
    tester.get(QProfileBackuper.class).restore(new StringReader(Resources.toString(getClass().getResource("QProfileBackuperMediumTest/restore-parent.xml"), StandardCharsets.UTF_8)), null);
    // parent profile is updated
    List<ActiveRuleDto> activeRules = db.activeRuleDao().selectByProfileKey(dbSession, XOO_P1_KEY);
    assertThat(activeRules).hasSize(1);
    ActiveRuleDto activeRuleDoc = activeRules.get(0);
    assertThat(activeRuleDoc.getSeverityString()).isEqualTo("BLOCKER");
    assertThat(activeRuleDoc.getInheritance()).isNull();
    ActiveRuleDto activeRuleDto = db.activeRuleDao().selectOrFailByKey(dbSession, activeRuleDoc.getKey());
    List<ActiveRuleParamDto> params = tester.get(ActiveRuleDao.class).selectParamsByActiveRuleId(dbSession, activeRuleDto.getId());
    assertThat(params).hasSize(1);
    assertThat(params.get(0).getKey()).isEqualTo("max");
    assertThat(params.get(0).getValue()).isEqualTo("7");
    // child profile is inherited
    activeRules = db.activeRuleDao().selectByProfileKey(dbSession, XOO_P2_KEY);
    assertThat(activeRules).hasSize(1);
    activeRuleDoc = activeRules.get(0);
    assertThat(activeRuleDoc.getSeverityString()).isEqualTo("BLOCKER");
    assertThat(activeRuleDoc.getInheritance()).isEqualTo(INHERITED);
    activeRuleDto = db.activeRuleDao().selectOrFailByKey(dbSession, activeRuleDoc.getKey());
    params = tester.get(ActiveRuleDao.class).selectParamsByActiveRuleId(dbSession, activeRuleDto.getId());
    assertThat(params).hasSize(1);
    assertThat(params.get(0).getKey()).isEqualTo("max");
    assertThat(params.get(0).getValue()).isEqualTo("7");
}
Also used : ActiveRuleDao(org.sonar.db.qualityprofile.ActiveRuleDao) ActiveRuleParamDto(org.sonar.db.qualityprofile.ActiveRuleParamDto) StringReader(java.io.StringReader) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) Test(org.junit.Test)

Example 15 with ActiveRuleDto

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

the class QProfileBackuperMediumTest method restore_and_update_profile.

@Test
public void restore_and_update_profile() throws Exception {
    // create profile P1 with rules x1 and x2 activated
    db.qualityProfileDao().insert(dbSession, newXooP1("org-123"));
    RuleActivation activation = new RuleActivation(XOO_X1);
    activation.setSeverity(Severity.INFO);
    activation.setParameter("max", "10");
    tester.get(RuleActivator.class).activate(dbSession, activation, XOO_P1_NAME);
    activation = new RuleActivation(XOO_X2);
    activation.setSeverity(Severity.INFO);
    tester.get(RuleActivator.class).activate(dbSession, activation, XOO_P1_NAME);
    dbSession.commit();
    dbSession.clearCache();
    activeRuleIndexer.index();
    // restore backup, which activates only x1
    // -> update x1 and deactivate x2
    tester.get(QProfileBackuper.class).restore(new StringReader(Resources.toString(getClass().getResource("QProfileBackuperMediumTest/restore.xml"), StandardCharsets.UTF_8)), null);
    // Check in db
    List<ActiveRuleDto> activeRules = db.activeRuleDao().selectByProfileKey(dbSession, XOO_P1_KEY);
    assertThat(activeRules).hasSize(1);
    ActiveRuleDto activeRuleDoc = activeRules.get(0);
    assertThat(activeRuleDoc.getSeverityString()).isEqualTo("BLOCKER");
    assertThat(activeRuleDoc.getInheritance()).isNull();
    ActiveRuleDto activeRuleDto = db.activeRuleDao().selectOrFailByKey(dbSession, activeRuleDoc.getKey());
    List<ActiveRuleParamDto> params = tester.get(ActiveRuleDao.class).selectParamsByActiveRuleId(dbSession, activeRuleDto.getId());
    assertThat(params).hasSize(1);
    assertThat(params.get(0).getKey()).isEqualTo("max");
    assertThat(params.get(0).getValue()).isEqualTo("7");
    // Check in es
    assertThat(tester.get(RuleIndex.class).searchAll(new RuleQuery().setQProfileKey(XOO_P1_KEY).setActivation(true))).containsOnly(XOO_X1);
}
Also used : ActiveRuleDao(org.sonar.db.qualityprofile.ActiveRuleDao) RuleIndex(org.sonar.server.rule.index.RuleIndex) ActiveRuleParamDto(org.sonar.db.qualityprofile.ActiveRuleParamDto) RuleQuery(org.sonar.server.rule.index.RuleQuery) StringReader(java.io.StringReader) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) Test(org.junit.Test)

Aggregations

ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)112 Test (org.junit.Test)51 ActiveRuleParamDto (org.sonar.db.qualityprofile.ActiveRuleParamDto)49 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)26 OrgActiveRuleDto (org.sonar.db.qualityprofile.OrgActiveRuleDto)21 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)21 RuleDto (org.sonar.db.rule.RuleDto)21 ActiveRuleDao (org.sonar.db.qualityprofile.ActiveRuleDao)19 RuleParamDto (org.sonar.db.rule.RuleParamDto)19 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)18 ActiveRuleKey (org.sonar.db.qualityprofile.ActiveRuleKey)15 ActiveRuleChange (org.sonar.server.qualityprofile.ActiveRuleChange)14 RuleKey (org.sonar.api.rule.RuleKey)12 RuleQuery (org.sonar.server.rule.index.RuleQuery)11 QualityProfileDao (org.sonar.db.qualityprofile.QualityProfileDao)10 ArrayList (java.util.ArrayList)9 BuiltInQualityProfilesDefinition (org.sonar.api.server.profile.BuiltInQualityProfilesDefinition)9 NewBuiltInQualityProfile (org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile)9 Map (java.util.Map)7 WsTester (org.sonar.server.ws.WsTester)6