Search in sources :

Example 41 with SnapshotDto

use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.

the class ExportMeasuresStepTest method insertSnapshot.

private SnapshotDto insertSnapshot(String snapshotUuid, ComponentDto project, String status) {
    SnapshotDto snapshot = new SnapshotDto().setUuid(snapshotUuid).setComponentUuid(project.uuid()).setStatus(status).setLast(true);
    dbTester.getDbClient().snapshotDao().insert(dbTester.getSession(), snapshot);
    return snapshot;
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto)

Example 42 with SnapshotDto

use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.

the class ExportMeasuresStepTest method export_measures.

@Test
public void export_measures() {
    SnapshotDto firstAnalysis = insertSnapshot("U_1", PROJECT, STATUS_PROCESSED);
    insertMeasure(firstAnalysis, PROJECT, new MeasureDto().setValue(100.0).setMetricUuid(NCLOC.getUuid()));
    SnapshotDto secondAnalysis = insertSnapshot("U_2", PROJECT, STATUS_PROCESSED);
    insertMeasure(secondAnalysis, PROJECT, new MeasureDto().setValue(110.0).setMetricUuid(NCLOC.getUuid()));
    SnapshotDto anotherProjectAnalysis = insertSnapshot("U_3", ANOTHER_PROJECT, STATUS_PROCESSED);
    insertMeasure(anotherProjectAnalysis, ANOTHER_PROJECT, new MeasureDto().setValue(500.0).setMetricUuid(NCLOC.getUuid()));
    dbTester.commit();
    underTest.execute(new TestComputationStepContext());
    List<ProjectDump.Measure> exportedMeasures = dumpWriter.getWrittenMessagesOf(DumpElement.MEASURES);
    assertThat(exportedMeasures).hasSize(2);
    assertThat(exportedMeasures).extracting(ProjectDump.Measure::getAnalysisUuid).containsOnly(firstAnalysis.getUuid(), secondAnalysis.getUuid());
    assertThat(exportedMeasures).extracting(ProjectDump.Measure::getMetricRef).containsOnly(0);
    assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("2 measures exported");
    assertThat(metricRepository.getRefByUuid()).containsOnlyKeys(NCLOC.getUuid());
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) ProjectDump(com.sonarsource.governance.projectdump.protobuf.ProjectDump) SnapshotDto(org.sonar.db.component.SnapshotDto) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 43 with SnapshotDto

use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.

the class ExportEventsStepTest method insertSnapshot.

private SnapshotDto insertSnapshot() {
    SnapshotDto snapshot = new SnapshotDto().setUuid("U1").setComponentUuid(PROJECT.uuid()).setStatus(STATUS_PROCESSED).setLast(false);
    dbTester.getDbClient().snapshotDao().insert(dbTester.getSession(), snapshot);
    dbTester.commit();
    return snapshot;
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto)

Example 44 with SnapshotDto

use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.

the class ExportEventsStepTest method export_events.

@Test
public void export_events() {
    SnapshotDto snapshot = insertSnapshot();
    insertEvent(snapshot, "E1", "one");
    insertEvent(snapshot, "E2", "two");
    underTest.execute(new TestComputationStepContext());
    assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("2 events exported");
    List<ProjectDump.Event> events = dumpWriter.getWrittenMessagesOf(DumpElement.EVENTS);
    assertThat(events).hasSize(2);
    assertThat(events).extracting(ProjectDump.Event::getUuid).containsOnly("E1", "E2");
}
Also used : ProjectDump(com.sonarsource.governance.projectdump.protobuf.ProjectDump) SnapshotDto(org.sonar.db.component.SnapshotDto) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 45 with SnapshotDto

use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.

the class PurgeCommandsTest method deleteAnalyses_by_analyses_deletes_analysis_properties.

@Test
@UseDataProvider("projectsAndViews")
public void deleteAnalyses_by_analyses_deletes_analysis_properties(ComponentDto projectOrView) {
    dbTester.components().insertComponent(projectOrView);
    SnapshotDto analysis = dbTester.components().insertSnapshot(projectOrView, randomLastAndStatus());
    SnapshotDto otherAnalysis = dbTester.components().insertSnapshot(projectOrView);
    int count = 4;
    IntStream.range(0, count).forEach(i -> {
        insertRandomAnalysisProperty(analysis);
        insertRandomAnalysisProperty(otherAnalysis);
    });
    underTest.deleteAnalyses(singletonList(analysis.getUuid()));
    assertThat(countAnalysisPropertiesOf(analysis)).isZero();
    assertThat(countAnalysisPropertiesOf(otherAnalysis)).isEqualTo(count);
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Aggregations

SnapshotDto (org.sonar.db.component.SnapshotDto)326 Test (org.junit.Test)257 ComponentDto (org.sonar.db.component.ComponentDto)219 MetricDto (org.sonar.db.metric.MetricDto)54 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)31 EventDto (org.sonar.db.event.EventDto)30 ProjectDto (org.sonar.db.project.ProjectDto)27 DbSession (org.sonar.db.DbSession)26 SnapshotTesting.newAnalysis (org.sonar.db.component.SnapshotTesting.newAnalysis)21 BranchDto (org.sonar.db.component.BranchDto)20 SearchEventsWsResponse (org.sonarqube.ws.Developers.SearchEventsWsResponse)20 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)17 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)14 DbClient (org.sonar.db.DbClient)14 NotFoundException (org.sonar.server.exceptions.NotFoundException)14 List (java.util.List)13 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)13 Rule (org.junit.Rule)13 UserRole (org.sonar.api.web.UserRole)13 DbTester (org.sonar.db.DbTester)13