Search in sources :

Example 21 with QualityProfile

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

the class QualityProfileEventsStepTest method verify_detection_with_complex_mix_of_qps.

@Test
public void verify_detection_with_complex_mix_of_qps() {
    final Set<Event> events = new HashSet<>();
    doAnswer(invocationOnMock -> {
        events.add((Event) invocationOnMock.getArguments()[1]);
        return null;
    }).when(eventRepository).add(eq(treeRootHolder.getRoot()), any(Event.class));
    Date date = new Date();
    QualityProfile qp1 = qp(QP_NAME_2, LANGUAGE_KEY_1, date);
    QualityProfile qp2 = qp(QP_NAME_2, LANGUAGE_KEY_2, date);
    QualityProfile qp3 = qp(QP_NAME_1, LANGUAGE_KEY_1, parseDateTime("2011-04-25T01:05:13+0100"));
    QualityProfile qp3_updated = qp(QP_NAME_1, LANGUAGE_KEY_1, parseDateTime("2011-04-25T01:05:17+0100"));
    QualityProfile qp4 = qp(QP_NAME_2, LANGUAGE_KEY_3, date);
    mockMeasures(treeRootHolder.getRoot(), arrayOf(qp1, qp2, qp3), arrayOf(qp3_updated, qp2, qp4));
    mockNoLanguageInRepository();
    qProfileStatusRepository.register(qp1.getQpKey(), REMOVED);
    qProfileStatusRepository.register(qp2.getQpKey(), UNCHANGED);
    qProfileStatusRepository.register(qp3.getQpKey(), UPDATED);
    qProfileStatusRepository.register(qp4.getQpKey(), ADDED);
    underTest.execute(new TestComputationStepContext());
    assertThat(events).extracting("name").containsOnly("Stop using '" + QP_NAME_2 + "' (" + LANGUAGE_KEY_1 + ")", "Use '" + QP_NAME_2 + "' (" + LANGUAGE_KEY_3 + ")", "Changes in '" + QP_NAME_1 + "' (" + LANGUAGE_KEY_1 + ")");
}
Also used : Event(org.sonar.ce.task.projectanalysis.event.Event) QualityProfile(org.sonar.server.qualityprofile.QualityProfile) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Date(java.util.Date) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 22 with QualityProfile

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

the class QualityProfileEventsStepTest method no_more_used_event_uses_language_key_in_message_if_language_not_found.

@Test
public void no_more_used_event_uses_language_key_in_message_if_language_not_found() {
    QualityProfile qp = qp(QP_NAME_1, LANGUAGE_KEY_1, new Date());
    qProfileStatusRepository.register(qp.getQpKey(), REMOVED);
    mockMeasures(treeRootHolder.getRoot(), arrayOf(qp), null);
    mockLanguageNotInRepository(LANGUAGE_KEY_1);
    underTest.execute(new TestComputationStepContext());
    verify(eventRepository).add(eq(treeRootHolder.getRoot()), eventArgumentCaptor.capture());
    verifyNoMoreInteractions(eventRepository);
    verifyEvent(eventArgumentCaptor.getValue(), "Stop using '" + qp.getQpName() + "' (" + qp.getLanguageKey() + ")", null);
}
Also used : QualityProfile(org.sonar.server.qualityprofile.QualityProfile) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Date(java.util.Date) Test(org.junit.Test)

Example 23 with QualityProfile

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

the class QualityProfileEventsStepTest method added_event_uses_language_key_in_message_if_language_not_found.

@Test
public void added_event_uses_language_key_in_message_if_language_not_found() {
    QualityProfile qp = qp(QP_NAME_1, LANGUAGE_KEY_1, new Date());
    qProfileStatusRepository.register(qp.getQpKey(), ADDED);
    mockLanguageNotInRepository(LANGUAGE_KEY_1);
    mockMeasures(treeRootHolder.getRoot(), null, arrayOf(qp));
    underTest.execute(new TestComputationStepContext());
    verify(eventRepository).add(eq(treeRootHolder.getRoot()), eventArgumentCaptor.capture());
    verifyNoMoreInteractions(eventRepository);
    verifyEvent(eventArgumentCaptor.getValue(), "Use '" + qp.getQpName() + "' (" + qp.getLanguageKey() + ")", null);
}
Also used : QualityProfile(org.sonar.server.qualityprofile.QualityProfile) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Date(java.util.Date) Test(org.junit.Test)

Example 24 with QualityProfile

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

the class QualityProfileEventsStepTest method added_event_if_qp_is_added.

@Test
public void added_event_if_qp_is_added() {
    QualityProfile qp = qp(QP_NAME_1, LANGUAGE_KEY_1, new Date());
    qProfileStatusRepository.register(qp.getQpKey(), ADDED);
    Language language = mockLanguageInRepository(LANGUAGE_KEY_1);
    mockMeasures(treeRootHolder.getRoot(), null, arrayOf(qp));
    underTest.execute(new TestComputationStepContext());
    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) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Date(java.util.Date) Test(org.junit.Test)

Example 25 with QualityProfile

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

the class RegisterQualityProfileStatusStepTest method register_unchanged_profile.

@Test
public void register_unchanged_profile() {
    QualityProfile qp1 = qp(QP_NAME_1, LANGUAGE_KEY_1, new Date(1000L));
    mockBaseQPMeasures(treeRootHolder.getRoot(), arrayOf(qp1));
    mockRawQProfiles(ImmutableList.of(qp1));
    underTest.execute(new TestComputationStepContext());
    verify(qProfileStatusRepository).register(qp1.getQpKey(), UNCHANGED);
    verifyNoMoreInteractions(qProfileStatusRepository);
}
Also used : QualityProfile(org.sonar.server.qualityprofile.QualityProfile) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Date(java.util.Date) Test(org.junit.Test)

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