Search in sources :

Example 16 with QualityProfile

use of org.sonar.server.qualityprofile.QualityProfile in project sonarqube by SonarSource.

the class QualityProfileEventsStepTest method no_event_if_same_qp_with_same_date.

@Test
public void no_event_if_same_qp_with_same_date() {
    QualityProfile qp = qp(QP_NAME_1, LANGUAGE_KEY_1);
    mockMeasures(treeRootHolder.getRoot(), arrayOf(qp), arrayOf(qp));
    underTest.execute();
    verify(eventRepository, never()).add(any(Component.class), any(Event.class));
}
Also used : Event(org.sonar.server.computation.task.projectanalysis.event.Event) QualityProfile(org.sonar.server.qualityprofile.QualityProfile) Component(org.sonar.server.computation.task.projectanalysis.component.Component) ReportComponent(org.sonar.server.computation.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Example 17 with QualityProfile

use of org.sonar.server.qualityprofile.QualityProfile in project sonarqube by SonarSource.

the class QualityProfileEventsStepTest method added_event_if_one_new_qp.

@Test
public void added_event_if_one_new_qp() {
    QualityProfile qp = qp(QP_NAME_1, LANGUAGE_KEY_1);
    Language language = mockLanguageInRepository(LANGUAGE_KEY_1);
    mockMeasures(treeRootHolder.getRoot(), null, arrayOf(qp));
    underTest.execute();
    verify(eventRepository).add(eq(treeRootHolder.getRoot()), eventArgumentCaptor.capture());
    verifyNoMoreInteractions(eventRepository);
    verifyEvent(eventArgumentCaptor.getValue(), "Use '" + qp.getQpName() + "' (" + language.getName() + ")", null);
}
Also used : AbstractLanguage(org.sonar.api.resources.AbstractLanguage) Language(org.sonar.api.resources.Language) QualityProfile(org.sonar.server.qualityprofile.QualityProfile) Test(org.junit.Test)

Example 18 with QualityProfile

use of org.sonar.server.qualityprofile.QualityProfile in project sonarqube by SonarSource.

the class QualityProfileEventsStepTest method changed_event_if_same_qp_but_no_same_date.

@Test
public void changed_event_if_same_qp_but_no_same_date() {
    QualityProfile qp1 = qp(QP_NAME_1, LANGUAGE_KEY_1, parseDateTime("2011-04-25T01:05:13+0100"));
    QualityProfile qp2 = qp(QP_NAME_1, LANGUAGE_KEY_1, parseDateTime("2011-04-25T01:05:17+0100"));
    mockMeasures(treeRootHolder.getRoot(), arrayOf(qp1), arrayOf(qp2));
    Language language = mockLanguageInRepository(LANGUAGE_KEY_1);
    underTest.execute();
    verify(eventRepository).add(eq(treeRootHolder.getRoot()), eventArgumentCaptor.capture());
    verifyNoMoreInteractions(eventRepository);
    verifyEvent(eventArgumentCaptor.getValue(), "Changes in '" + qp2.getQpName() + "' (" + language.getName() + ")", "from=" + UtcDateUtils.formatDateTime(parseDateTime("2011-04-25T01:05:14+0100")) + ";key=" + qp1.getQpKey() + ";to=" + UtcDateUtils.formatDateTime(parseDateTime("2011-04-25T01:05:18+0100")));
}
Also used : AbstractLanguage(org.sonar.api.resources.AbstractLanguage) Language(org.sonar.api.resources.Language) QualityProfile(org.sonar.server.qualityprofile.QualityProfile) Test(org.junit.Test)

Example 19 with QualityProfile

use of org.sonar.server.qualityprofile.QualityProfile in project sonarqube by SonarSource.

the class ComputeQProfileMeasureStepTest method fail_if_report_inconsistent.

@Test
public void fail_if_report_inconsistent() {
    treeRootHolder.setRoot(MULTI_MODULE_PROJECT);
    QualityProfile qpJava = createQProfile(QP_NAME_1, LANGUAGE_KEY_1);
    analysisMetadataHolder.setQProfilesByLanguage(ImmutableMap.of(LANGUAGE_KEY_1, qpJava));
    try {
        underTest.execute(new TestComputationStepContext());
        fail("Expected exception");
    } catch (Exception e) {
        assertThat(e).hasCause(new IllegalStateException("Report contains a file with language 'php' but no matching quality profile"));
    }
}
Also used : QualityProfile(org.sonar.server.qualityprofile.QualityProfile) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 20 with QualityProfile

use of org.sonar.server.qualityprofile.QualityProfile in project sonarqube by SonarSource.

the class UpdateQualityProfilesLastUsedDateStep method execute.

@Override
public void execute(ComputationStep.Context context) {
    Component root = treeRootHolder.getRoot();
    Metric metric = metricRepository.getByKey(QUALITY_PROFILES_KEY);
    Set<QualityProfile> qualityProfiles = parseQualityProfiles(measureRepository.getRawMeasure(root, metric));
    try (DbSession dbSession = dbClient.openSession(true)) {
        for (QualityProfile qualityProfile : qualityProfiles) {
            updateDate(dbSession, qualityProfile.getQpKey(), analysisMetadataHolder.getAnalysisDate());
        }
        dbSession.commit();
    }
}
Also used : DbSession(org.sonar.db.DbSession) Metric(org.sonar.ce.task.projectanalysis.metric.Metric) QualityProfile(org.sonar.server.qualityprofile.QualityProfile) Component(org.sonar.ce.task.projectanalysis.component.Component)

Aggregations

QualityProfile (org.sonar.server.qualityprofile.QualityProfile)25 Test (org.junit.Test)22 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)13 Date (java.util.Date)12 AbstractLanguage (org.sonar.api.resources.AbstractLanguage)6 Language (org.sonar.api.resources.Language)6 Component (org.sonar.ce.task.projectanalysis.component.Component)2 Event (org.sonar.ce.task.projectanalysis.event.Event)2 DbSession (org.sonar.db.DbSession)2 Component (org.sonar.server.computation.task.projectanalysis.component.Component)2 HashSet (java.util.HashSet)1 ExpectedException (org.junit.rules.ExpectedException)1 ScannerPlugin (org.sonar.ce.task.projectanalysis.analysis.ScannerPlugin)1 ReportComponent (org.sonar.ce.task.projectanalysis.component.ReportComponent)1 Metric (org.sonar.ce.task.projectanalysis.metric.Metric)1 ComponentDto (org.sonar.db.component.ComponentDto)1 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)1 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)1 Plugin (org.sonar.scanner.protocol.output.ScannerReport.Metadata.Plugin)1 QProfile (org.sonar.scanner.protocol.output.ScannerReport.Metadata.QProfile)1