use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class ExportAnalysesStepTest method throws_ISE_if_error.
@Test
public void throws_ISE_if_error() {
SnapshotDto firstAnalysis = newAnalysis("U_1", 1_450_000_000_000L, PROJECT.uuid(), "1.0", false, "1.0.2.3", 1);
SnapshotDto secondAnalysis = newAnalysis("U_4", 1_460_000_000_000L, PROJECT.uuid(), "1.1", true, "1.1.3.4", 2);
dbTester.getDbClient().snapshotDao().insert(dbTester.getSession(), firstAnalysis, secondAnalysis);
dbTester.commit();
dumpWriter.failIfMoreThan(1, DumpElement.ANALYSES);
assertThatThrownBy(() -> underTest.execute(new TestComputationStepContext())).isInstanceOf(IllegalStateException.class).hasMessage("Analysis Export failed after processing 1 analyses successfully");
}
use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class ExportAnalysesStepTest method export_analyses_by_ordering_by_technical_creation_date.
@Test
public void export_analyses_by_ordering_by_technical_creation_date() {
SnapshotDto firstAnalysis = newAnalysis("U_1", 1_450_000_000_000L, PROJECT.uuid(), "1.0", false, "1.0.2.3", 3_000_000_000_000L);
SnapshotDto secondAnalysis = newAnalysis("U_4", 1_460_000_000_000L, PROJECT.uuid(), "1.1", true, "1.1.3.4", 1_000_000_000_000L);
SnapshotDto thirdAnalysis = newAnalysis("U_7", 1_460_500_000_000L, PROJECT.uuid(), null, true, null, 2_000_000_000_000L);
dbTester.getDbClient().snapshotDao().insert(dbTester.getSession(), firstAnalysis, secondAnalysis, thirdAnalysis);
dbTester.commit();
underTest.execute(new TestComputationStepContext());
List<ProjectDump.Analysis> analyses = dumpWriter.getWrittenMessagesOf(DumpElement.ANALYSES);
assertAnalysis(analyses.get(0), PROJECT, secondAnalysis);
assertAnalysis(analyses.get(1), PROJECT, thirdAnalysis);
assertAnalysis(analyses.get(2), PROJECT, firstAnalysis);
}
use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class ExportAnalysesStepTest method export_analyses.
@Test
@UseDataProvider("versionAndBuildStringCombinations")
public void export_analyses(@Nullable String version, @Nullable String buildString) {
SnapshotDto firstAnalysis = newAnalysis("U_1", 1_450_000_000_000L, PROJECT.uuid(), "1.0", false, "1.0.2.3", 1_450_000_000_000L);
SnapshotDto secondAnalysis = newAnalysis("U_4", 1_460_000_000_000L, PROJECT.uuid(), "1.1", true, "1.1.3.4", 1_460_000_000_000L);
SnapshotDto thirdAnalysis = newAnalysis("U_7", 1_460_000_000_000L, PROJECT.uuid(), version, true, buildString, 1_470_000_000_000L);
dbTester.getDbClient().snapshotDao().insert(dbTester.getSession(), firstAnalysis, secondAnalysis, thirdAnalysis);
dbTester.commit();
underTest.execute(new TestComputationStepContext());
assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("3 analyses exported");
List<ProjectDump.Analysis> analyses = dumpWriter.getWrittenMessagesOf(DumpElement.ANALYSES);
assertThat(analyses).hasSize(3);
assertAnalysis(analyses.get(0), PROJECT, firstAnalysis);
assertAnalysis(analyses.get(1), PROJECT, secondAnalysis);
assertAnalysis(analyses.get(2), PROJECT, thirdAnalysis);
}
use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class MeasureDaoTest method select_past_measures_with_several_analyses.
@Test
public void select_past_measures_with_several_analyses() {
ComponentDto project = db.components().insertPrivateProject();
long lastAnalysisDate = parseDate("2017-01-25").getTime();
long previousAnalysisDate = lastAnalysisDate - 10_000_000_000L;
long oldAnalysisDate = lastAnalysisDate - 100_000_000_000L;
SnapshotDto lastAnalysis = dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setCreatedAt(lastAnalysisDate));
SnapshotDto pastAnalysis = dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setCreatedAt(previousAnalysisDate).setLast(false));
dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setCreatedAt(oldAnalysisDate).setLast(false));
db.commit();
// project
insertMeasure("PROJECT_M1", lastAnalysis.getUuid(), project.uuid(), ncloc.getUuid());
insertMeasure("PROJECT_M2", pastAnalysis.getUuid(), project.uuid(), ncloc.getUuid());
insertMeasure("PROJECT_M3", "OLD_ANALYSIS_UUID", project.uuid(), ncloc.getUuid());
db.commit();
// Measures of project for last and previous analyses
List<MeasureDto> result = underTest.selectPastMeasures(db.getSession(), new PastMeasureQuery(project.uuid(), singletonList(ncloc.getUuid()), previousAnalysisDate, lastAnalysisDate + 1_000L));
assertThat(result).hasSize(2).extracting(MeasureDto::getData).containsOnly("PROJECT_M1", "PROJECT_M2");
}
use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class MeasureDaoTest method test_selectMeasure.
@Test
public void test_selectMeasure() {
MetricDto metric = db.measures().insertMetric();
ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
SnapshotDto lastAnalysis = insertAnalysis(project.uuid(), true);
SnapshotDto pastAnalysis = insertAnalysis(project.uuid(), false);
MeasureDto pastMeasure = MeasureTesting.newMeasureDto(metric, file, pastAnalysis);
MeasureDto lastMeasure = MeasureTesting.newMeasureDto(metric, file, lastAnalysis);
underTest.insert(db.getSession(), pastMeasure);
underTest.insert(db.getSession(), lastMeasure);
assertThat(underTest.selectMeasure(db.getSession(), lastAnalysis.getUuid(), file.uuid(), metric.getKey()).get()).isEqualToComparingFieldByField(lastMeasure);
assertThat(underTest.selectMeasure(db.getSession(), pastAnalysis.getUuid(), file.uuid(), metric.getKey()).get()).isEqualToComparingFieldByField(pastMeasure);
assertThat(underTest.selectMeasure(db.getSession(), "_missing_", file.uuid(), metric.getKey())).isEmpty();
assertThat(underTest.selectMeasure(db.getSession(), pastAnalysis.getUuid(), "_missing_", metric.getKey())).isEmpty();
assertThat(underTest.selectMeasure(db.getSession(), pastAnalysis.getUuid(), file.uuid(), "_missing_")).isEmpty();
}
Aggregations