Search in sources :

Example 1 with QGChangeEvent

use of org.sonar.server.qualitygate.changeevent.QGChangeEvent in project sonarqube by SonarSource.

the class WebhookQGChangeEventListenerTest method onIssueChangesCallsWebhookOnBranch.

public void onIssueChangesCallsWebhookOnBranch(BranchType branchType) {
    ProjectAndBranch nonMainBranch = insertBranch(branchType, "foo");
    SnapshotDto analysis = insertAnalysisTask(nonMainBranch);
    Configuration configuration = mock(Configuration.class);
    QGChangeEvent qualityGateEvent = newQGChangeEvent(nonMainBranch, analysis, configuration, null);
    mockWebhookEnabled(qualityGateEvent.getProject());
    underTest.onIssueChanges(qualityGateEvent, CHANGED_ISSUES_ARE_IGNORED);
    verifyWebhookCalled(nonMainBranch, analysis, qualityGateEvent.getProject());
}
Also used : Configuration(org.sonar.api.config.Configuration) SnapshotDto(org.sonar.db.component.SnapshotDto) QGChangeEvent(org.sonar.server.qualitygate.changeevent.QGChangeEvent)

Example 2 with QGChangeEvent

use of org.sonar.server.qualitygate.changeevent.QGChangeEvent in project sonarqube by SonarSource.

the class WebhookQGChangeEventListenerTest method onIssueChanges_has_no_effect_if_event_has_neither_previousQGStatus_nor_qualityGate.

@Test
public void onIssueChanges_has_no_effect_if_event_has_neither_previousQGStatus_nor_qualityGate() {
    Configuration configuration = mock(Configuration.class);
    QGChangeEvent qualityGateEvent = newQGChangeEvent(configuration, null, null);
    mockWebhookEnabled(qualityGateEvent.getProject());
    underTest.onIssueChanges(qualityGateEvent, CHANGED_ISSUES_ARE_IGNORED);
    verifyZeroInteractions(webhookPayloadFactory, mockedDbClient);
}
Also used : Configuration(org.sonar.api.config.Configuration) QGChangeEvent(org.sonar.server.qualitygate.changeevent.QGChangeEvent) Test(org.junit.Test)

Example 3 with QGChangeEvent

use of org.sonar.server.qualitygate.changeevent.QGChangeEvent in project sonarqube by SonarSource.

the class WebhookQGChangeEventListenerTest method onIssueChanges_has_no_effect_if_event_has_same_status_in_previous_and_new_QG.

@Test
public void onIssueChanges_has_no_effect_if_event_has_same_status_in_previous_and_new_QG() {
    Configuration configuration = mock(Configuration.class);
    Metric.Level previousStatus = randomLevel();
    when(newQualityGate.getStatus()).thenReturn(previousStatus);
    QGChangeEvent qualityGateEvent = newQGChangeEvent(configuration, previousStatus, newQualityGate);
    mockWebhookEnabled(qualityGateEvent.getProject());
    underTest.onIssueChanges(qualityGateEvent, CHANGED_ISSUES_ARE_IGNORED);
    verifyZeroInteractions(webhookPayloadFactory, mockedDbClient);
}
Also used : Configuration(org.sonar.api.config.Configuration) Metric(org.sonar.api.measures.Metric) QGChangeEvent(org.sonar.server.qualitygate.changeevent.QGChangeEvent) Test(org.junit.Test)

Example 4 with QGChangeEvent

use of org.sonar.server.qualitygate.changeevent.QGChangeEvent in project sonarqube by SonarSource.

the class LiveMeasureComputerImplTest method variation_is_refreshed_when_rating_value_is_changed.

@Test
public void variation_is_refreshed_when_rating_value_is_changed() {
    markProjectAsAnalyzed(project);
    // value is:
    // B on last analysis
    // D on beginning of leak period --> variation is -2
    db.measures().insertLiveMeasure(project, ratingMetric, m -> m.setValue((double) Rating.B.getIndex()).setData("B").setVariation(-2.0));
    // new value is C, so variation on leak period is D to C = -1
    List<QGChangeEvent> result = run(file1, newRatingConstantFormula(Rating.C));
    LiveMeasureDto measure = assertThatRatingMeasureHasValue(project, Rating.C);
    assertThat(measure.getVariation()).isEqualTo(-1.0);
    assertThatProjectChanged(result, project);
}
Also used : LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) QGChangeEvent(org.sonar.server.qualitygate.changeevent.QGChangeEvent) Test(org.junit.Test)

Example 5 with QGChangeEvent

use of org.sonar.server.qualitygate.changeevent.QGChangeEvent in project sonarqube by SonarSource.

the class LiveMeasureComputerImplTest method variation_does_not_change_if_rating_value_does_not_change.

@Test
public void variation_does_not_change_if_rating_value_does_not_change() {
    markProjectAsAnalyzed(project);
    // value is:
    // B on last analysis
    // D on beginning of leak period --> variation is -2
    db.measures().insertLiveMeasure(project, ratingMetric, m -> m.setValue((double) Rating.B.getIndex()).setData("B").setVariation(-2.0));
    // new value is still B, so variation on leak period is still -2
    List<QGChangeEvent> result = run(file1, newRatingConstantFormula(Rating.B));
    LiveMeasureDto measure = assertThatRatingMeasureHasValue(project, Rating.B);
    assertThat(measure.getVariation()).isEqualTo(-2.0);
    assertThatProjectChanged(result, project);
}
Also used : LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) QGChangeEvent(org.sonar.server.qualitygate.changeevent.QGChangeEvent) Test(org.junit.Test)

Aggregations

QGChangeEvent (org.sonar.server.qualitygate.changeevent.QGChangeEvent)12 Test (org.junit.Test)10 Configuration (org.sonar.api.config.Configuration)8 LiveMeasureDto (org.sonar.db.measure.LiveMeasureDto)5 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)4 SnapshotDto (org.sonar.db.component.SnapshotDto)4 Metric (org.sonar.api.measures.Metric)3 ComponentDto (org.sonar.db.component.ComponentDto)3 BranchDto (org.sonar.db.component.BranchDto)2 MetricDto (org.sonar.db.metric.MetricDto)2 ProjectDto (org.sonar.db.project.ProjectDto)2 EvaluatedQualityGate (org.sonar.server.qualitygate.EvaluatedQualityGate)2 QualityGate (org.sonar.server.qualitygate.QualityGate)2 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)1 DataProviderRunner (com.tngtech.java.junit.dataprovider.DataProviderRunner)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 Collection (java.util.Collection)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.singleton (java.util.Collections.singleton)1