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);
}
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();
}
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);
}
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);
}
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");
}
Aggregations