Search in sources :

Example 1 with ServerTester

use of org.sonar.server.tester.ServerTester in project sonarqube by SonarSource.

the class RegisterQualityProfilesMediumTest method register_profile_definitions.

@Test
public void register_profile_definitions() {
    tester = new ServerTester().withEsIndexes().withStartupTasks().addXoo().addComponents(XooRulesDefinition.class, XooProfileDefinition.class);
    tester.start();
    dbSession = dbClient().openSession(false);
    // Check Profile in DB
    QualityProfileDao qualityProfileDao = dbClient().qualityProfileDao();
    assertThat(qualityProfileDao.selectAll(dbSession)).hasSize(1);
    QualityProfileDto profile = qualityProfileDao.selectByNameAndLanguage("Basic", "xoo", dbSession);
    assertThat(profile).isNotNull();
    // Check Default Profile
    verifyDefaultProfile("xoo", "Basic");
    // Check ActiveRules in DB
    ActiveRuleDao activeRuleDao = dbClient().activeRuleDao();
    assertThat(activeRuleDao.selectByProfileKey(dbSession, profile.getKey())).hasSize(2);
    RuleKey ruleKey = RuleKey.of("xoo", "x1");
    ActiveRuleDto activeRule = activeRuleDao.selectByKey(dbSession, ActiveRuleKey.of(profile.getKey(), ruleKey)).get();
    assertThat(activeRule.getKey().qProfile()).isEqualTo(profile.getKey());
    assertThat(activeRule.getKey().ruleKey()).isEqualTo(ruleKey);
    assertThat(activeRule.getSeverityString()).isEqualTo(Severity.CRITICAL);
    // Check ActiveRuleParameters in DB
    Map<String, ActiveRuleParamDto> params = ActiveRuleParamDto.groupByKey(activeRuleDao.selectParamsByActiveRuleId(dbSession, activeRule.getId()));
    assertThat(params).hasSize(2);
    // set by profile
    assertThat(params.get("acceptWhitespace").getValue()).isEqualTo("true");
    // default value
    assertThat(params.get("max").getValue()).isEqualTo("10");
}
Also used : ActiveRuleDao(org.sonar.db.qualityprofile.ActiveRuleDao) QualityProfileDao(org.sonar.db.qualityprofile.QualityProfileDao) ActiveRuleKey(org.sonar.db.qualityprofile.ActiveRuleKey) RuleKey(org.sonar.api.rule.RuleKey) ActiveRuleParamDto(org.sonar.db.qualityprofile.ActiveRuleParamDto) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) ServerTester(org.sonar.server.tester.ServerTester) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Test(org.junit.Test)

Example 2 with ServerTester

use of org.sonar.server.tester.ServerTester in project sonarqube by SonarSource.

the class RegisterQualityProfilesMediumTest method mark_profile_as_default.

@Test
public void mark_profile_as_default() {
    tester = new ServerTester().withEsIndexes().withStartupTasks().addXoo().addComponents(new SimpleProfileDefinition("one", false), new SimpleProfileDefinition("two", true));
    tester.start();
    verifyDefaultProfile("xoo", "two");
}
Also used : ServerTester(org.sonar.server.tester.ServerTester) Test(org.junit.Test)

Example 3 with ServerTester

use of org.sonar.server.tester.ServerTester in project sonarqube by SonarSource.

the class RegisterQualityProfilesMediumTest method register_existing_profile_definitions.

@Test
public void register_existing_profile_definitions() {
    tester = new ServerTester().withEsIndexes().withStartupTasks().addXoo().addComponents(XooRulesDefinition.class, XooProfileDefinition.class);
    tester.start();
    dbSession = dbClient().openSession(false);
    // Check Profile in DB
    QualityProfileDao qualityProfileDao = dbClient().qualityProfileDao();
    assertThat(qualityProfileDao.selectAll(dbSession)).hasSize(1);
    QualityProfileDto profile = qualityProfileDao.selectByNameAndLanguage("Basic", "xoo", dbSession);
    assertThat(profile).isNotNull();
    // Check ActiveRules in DB
    ActiveRuleDao activeRuleDao = dbClient().activeRuleDao();
    assertThat(activeRuleDao.selectByProfileKey(dbSession, profile.getKey())).hasSize(2);
    RuleKey ruleKey = RuleKey.of("xoo", "x1");
    ActiveRuleKey activeRuleKey = ActiveRuleKey.of(profile.getKey(), ruleKey);
    assertThat(activeRuleDao.selectByKey(dbSession, activeRuleKey)).isPresent();
    // Check in ES
    assertThat(tester.get(RuleIndex.class).search(new RuleQuery().setActivation(true), new SearchOptions()).getIds()).containsOnly(ruleKey, RuleKey.of("xoo", "x2"));
    tester.get(Platform.class).restart();
    assertThat(activeRuleDao.selectByKey(dbSession, activeRuleKey)).isPresent();
    // Check ActiveRules
    ActiveRuleDto activeRule = activeRuleDao.selectByKey(dbSession, activeRuleKey).get();
    assertThat(activeRule.getKey().qProfile()).isEqualTo(profile.getKee());
    assertThat(activeRule.getKey().ruleKey()).isEqualTo(ruleKey);
    assertThat(activeRule.getSeverityString()).isEqualTo(Severity.CRITICAL);
    // Check in ES
    assertThat(tester.get(RuleIndex.class).search(new RuleQuery().setActivation(true), new SearchOptions()).getIds()).containsOnly(ruleKey, RuleKey.of("xoo", "x2"));
    // TODO
    // Check ActiveRuleParameters in DB
    Map<String, ActiveRuleParamDto> params = ActiveRuleParamDto.groupByKey(activeRuleDao.selectParamsByActiveRuleId(dbSession, activeRule.getId()));
    assertThat(params).hasSize(2);
    // set by profile
    assertThat(params.get("acceptWhitespace").getValue()).isEqualTo("true");
    // default value
    assertThat(params.get("max").getValue()).isEqualTo("10");
}
Also used : QualityProfileDao(org.sonar.db.qualityprofile.QualityProfileDao) Platform(org.sonar.server.platform.Platform) ActiveRuleKey(org.sonar.db.qualityprofile.ActiveRuleKey) RuleKey(org.sonar.api.rule.RuleKey) ActiveRuleParamDto(org.sonar.db.qualityprofile.ActiveRuleParamDto) SearchOptions(org.sonar.server.es.SearchOptions) ServerTester(org.sonar.server.tester.ServerTester) ActiveRuleDao(org.sonar.db.qualityprofile.ActiveRuleDao) RuleQuery(org.sonar.server.rule.index.RuleQuery) ActiveRuleKey(org.sonar.db.qualityprofile.ActiveRuleKey) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Test(org.junit.Test)

Example 4 with ServerTester

use of org.sonar.server.tester.ServerTester in project sonarqube by SonarSource.

the class RegisterQualityProfilesMediumTest method use_sonar_way_as_default_profile_if_none_are_marked_as_default.

@Test
public void use_sonar_way_as_default_profile_if_none_are_marked_as_default() {
    tester = new ServerTester().withEsIndexes().withStartupTasks().addXoo().addComponents(new SimpleProfileDefinition("Sonar way", false), new SimpleProfileDefinition("Other way", false));
    tester.start();
    verifyDefaultProfile("xoo", "Sonar way");
}
Also used : ServerTester(org.sonar.server.tester.ServerTester) Test(org.junit.Test)

Example 5 with ServerTester

use of org.sonar.server.tester.ServerTester in project sonarqube by SonarSource.

the class RegisterQualityProfilesMediumTest method do_not_reset_default_profile_if_still_valid.

@Test
public void do_not_reset_default_profile_if_still_valid() {
    tester = new ServerTester().withEsIndexes().withStartupTasks().addXoo().addComponents(new SimpleProfileDefinition("one", true), new SimpleProfileDefinition("two", false));
    tester.start();
    QualityProfileDao profileDao = dbClient().qualityProfileDao();
    dbSession = dbClient().openSession(false);
    QualityProfileDto profileTwo = profileDao.selectByNameAndLanguage("two", "xoo", dbSession);
    tester.get(QProfileFactory.class).setDefault(dbSession, profileTwo.getKee());
    dbSession.commit();
    verifyDefaultProfile("xoo", "two");
    tester.get(Platform.class).restart();
    // restart must keep "two" as default profile, even if "one" is marked as it
    verifyDefaultProfile("xoo", "two");
}
Also used : QualityProfileDao(org.sonar.db.qualityprofile.QualityProfileDao) Platform(org.sonar.server.platform.Platform) ServerTester(org.sonar.server.tester.ServerTester) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 ServerTester (org.sonar.server.tester.ServerTester)6 QualityProfileDao (org.sonar.db.qualityprofile.QualityProfileDao)4 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)3 RuleKey (org.sonar.api.rule.RuleKey)2 ActiveRuleDao (org.sonar.db.qualityprofile.ActiveRuleDao)2 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)2 ActiveRuleKey (org.sonar.db.qualityprofile.ActiveRuleKey)2 ActiveRuleParamDto (org.sonar.db.qualityprofile.ActiveRuleParamDto)2 Platform (org.sonar.server.platform.Platform)2 SearchOptions (org.sonar.server.es.SearchOptions)1 RuleQuery (org.sonar.server.rule.index.RuleQuery)1