Search in sources :

Example 81 with QualityProfileDto

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

the class CreateAction method doHandle.

private CreateWsResponse doHandle(DbSession dbSession, CreateRequest createRequest, Request request) {
    QProfileResult result = new QProfileResult();
    QualityProfileDto profile = profileFactory.create(dbSession, QProfileName.createFor(createRequest.getLanguage(), createRequest.getProfileName()));
    result.setProfile(profile);
    for (ProfileImporter importer : importers) {
        String importerKey = importer.getKey();
        InputStream contentToImport = request.paramAsInputStream(getBackupParamName(importerKey));
        if (contentToImport != null) {
            result.add(exporters.importXml(profile, importerKey, contentToImport, dbSession));
        }
    }
    dbSession.commit();
    activeRuleIndexer.index(result.getChanges());
    return buildResponse(result);
}
Also used : InputStream(java.io.InputStream) ProfileImporter(org.sonar.api.profiles.ProfileImporter) QProfileResult(org.sonar.server.qualityprofile.QProfileResult) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto)

Example 82 with QualityProfileDto

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

the class UpdateQualityProfilesLastUsedDateStepTest method fail_when_profile_is_linked_to_unknown_parent.

@Test
public void fail_when_profile_is_linked_to_unknown_parent() throws Exception {
    QualityProfileDto currentProfile = newQualityProfileDto().setKey("current").setParentKee("unknown");
    qualityProfileDb.insertQualityProfiles(currentProfile);
    measureRepository.addRawMeasure(1, QUALITY_PROFILES_KEY, Measure.newMeasureBuilder().create(toJson(currentProfile.getKey())));
    expectedException.expect(RowNotFoundException.class);
    underTest.execute();
}
Also used : QualityProfileTesting.newQualityProfileDto(org.sonar.db.qualityprofile.QualityProfileTesting.newQualityProfileDto) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Test(org.junit.Test)

Example 83 with QualityProfileDto

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

the class QProfileBackuperMediumTest method restore_and_create_profile.

@Test
public void restore_and_create_profile() throws Exception {
    // Backup file declares profile P1 on xoo
    tester.get(QProfileBackuper.class).restore(new StringReader(Resources.toString(getClass().getResource("QProfileBackuperMediumTest/restore.xml"), StandardCharsets.UTF_8)), null);
    // Check in db
    QualityProfileDto profile = db.qualityProfileDao().selectByNameAndLanguage("P1", "xoo", dbSession);
    assertThat(profile).isNotNull();
    List<ActiveRuleDto> activeRules = db.activeRuleDao().selectByProfileKey(dbSession, profile.getKey());
    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(profile.getKey()).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) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Test(org.junit.Test)

Example 84 with QualityProfileDto

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

the class QProfileBackuperMediumTest method restore_and_override_profile_name.

@Test
public void restore_and_override_profile_name() throws Exception {
    tester.get(QProfileBackuper.class).restore(new StringReader(Resources.toString(getClass().getResource("QProfileBackuperMediumTest/restore.xml"), StandardCharsets.UTF_8)), XOO_P3_NAME);
    List<ActiveRuleDto> activeRules = db.activeRuleDao().selectByProfileKey(dbSession, XOO_P1_KEY);
    assertThat(activeRules).hasSize(0);
    QualityProfileDto target = db.qualityProfileDao().selectByNameAndLanguage("P3", "xoo", dbSession);
    assertThat(target).isNotNull();
    assertThat(db.activeRuleDao().selectByProfileKey(dbSession, target.getKey())).hasSize(1);
}
Also used : StringReader(java.io.StringReader) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Test(org.junit.Test)

Example 85 with QualityProfileDto

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

the class QProfileBackuperMediumTest method restore_profile_with_zero_rules.

@Test
public void restore_profile_with_zero_rules() throws Exception {
    tester.get(QProfileBackuper.class).restore(new StringReader(Resources.toString(getClass().getResource("QProfileBackuperMediumTest/empty.xml"), StandardCharsets.UTF_8)), null);
    dbSession.clearCache();
    assertThat(db.activeRuleDao().selectAll(dbSession)).hasSize(0);
    List<QualityProfileDto> profiles = db.qualityProfileDao().selectAll(dbSession);
    assertThat(profiles).hasSize(1);
    assertThat(profiles.get(0).getName()).isEqualTo("P1");
}
Also used : StringReader(java.io.StringReader) 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