Search in sources :

Example 11 with QGChangeEvent

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

the class LiveMeasureComputerImplTest method refresh_multiple_projects_at_the_same_time.

@Test
public void refresh_multiple_projects_at_the_same_time() {
    markProjectAsAnalyzed(project);
    ComponentDto project2 = db.components().insertPublicProject();
    ComponentDto fileInProject2 = db.components().insertComponent(ComponentTesting.newFileDto(project2));
    markProjectAsAnalyzed(project2);
    List<QGChangeEvent> result = run(asList(file1, fileInProject2), newQualifierBasedIntFormula());
    // generated values depend on position of qualifier in Qualifiers.ORDERED_BOTTOM_UP (see formula)
    assertThatIntMeasureHasValue(file1, 0);
    assertThatIntMeasureHasValue(dir, 2);
    assertThatIntMeasureHasValue(project, 4);
    assertThatIntMeasureHasValue(fileInProject2, 0);
    assertThatIntMeasureHasValue(project2, 4);
    // no other measures generated
    assertThat(db.countRowsOfTable(db.getSession(), "live_measures")).isEqualTo(5);
    assertThatProjectChanged(result, project, project2);
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) QGChangeEvent(org.sonar.server.qualitygate.changeevent.QGChangeEvent) Test(org.junit.Test)

Example 12 with QGChangeEvent

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

the class LiveMeasureComputerImplTest method event_contains_newQualityGate_computed_by_LiveQualityGateComputer.

@Test
public void event_contains_newQualityGate_computed_by_LiveQualityGateComputer() {
    markProjectAsAnalyzed(project);
    db.measures().insertLiveMeasure(project, alertStatusMetric, m -> m.setData(Metric.Level.ERROR.name()));
    db.measures().insertLiveMeasure(project, intMetric, m -> m.setVariation(42.0).setValue(null));
    BranchDto branch = db.getDbClient().branchDao().selectByBranchKey(db.getSession(), project.projectUuid(), "master").orElseThrow(() -> new IllegalStateException("Can't find master branch"));
    List<QGChangeEvent> result = run(file1, newQualifierBasedIntLeakFormula());
    assertThat(result).extracting(QGChangeEvent::getQualityGateSupplier).extracting(Supplier::get).containsExactly(Optional.of(newQualityGate));
    verify(qGateComputer).loadQualityGate(any(DbSession.class), argThat(p -> p.getUuid().equals(projectDto.getUuid())), eq(branch));
    verify(qGateComputer).getMetricsRelatedTo(qualityGate);
    verify(qGateComputer).refreshGateStatus(eq(project), same(qualityGate), any(MeasureMatrix.class), any(Configuration.class));
}
Also used : Arrays(java.util.Arrays) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CorePropertyDefinitions(org.sonar.core.config.CorePropertyDefinitions) MapSettings(org.sonar.api.config.internal.MapSettings) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) DbSession(org.sonar.db.DbSession) Collections.singleton(java.util.Collections.singleton) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Arrays.asList(java.util.Arrays.asList) Configuration(org.sonar.api.config.Configuration) ComponentTesting(org.sonar.db.component.ComponentTesting) PropertyDefinitions(org.sonar.api.config.PropertyDefinitions) QualityGate(org.sonar.server.qualitygate.QualityGate) TestProjectConfigurationLoader(org.sonar.server.setting.TestProjectConfigurationLoader) DbTester(org.sonar.db.DbTester) System2(org.sonar.api.utils.System2) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) EvaluatedQualityGate(org.sonar.server.qualitygate.EvaluatedQualityGate) CoreMetrics(org.sonar.api.measures.CoreMetrics) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) ProjectDto(org.sonar.db.project.ProjectDto) Optional(java.util.Optional) QGChangeEvent(org.sonar.server.qualitygate.changeevent.QGChangeEvent) Mockito.mock(org.mockito.Mockito.mock) BranchDto(org.sonar.db.component.BranchDto) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) RunWith(org.junit.runner.RunWith) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Supplier(java.util.function.Supplier) TestProjectIndexers(org.sonar.server.es.TestProjectIndexers) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ProjectIndexer(org.sonar.server.es.ProjectIndexer) ORDERED_BOTTOM_UP(org.sonar.api.resources.Qualifiers.ORDERED_BOTTOM_UP) Nullable(javax.annotation.Nullable) Before(org.junit.Before) BranchType(org.sonar.db.component.BranchType) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) ProjectConfigurationLoader(org.sonar.server.setting.ProjectConfigurationLoader) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Rule(org.junit.Rule) MetricDto(org.sonar.db.metric.MetricDto) Qualifiers(org.sonar.api.resources.Qualifiers) LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) Metric(org.sonar.api.measures.Metric) Rating(org.sonar.server.measure.Rating) ArgumentMatchers.same(org.mockito.ArgumentMatchers.same) DbSession(org.sonar.db.DbSession) BranchDto(org.sonar.db.component.BranchDto) Configuration(org.sonar.api.config.Configuration) 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