use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class MeasureDaoTest method test_selectLastMeasure.
@Test
public void test_selectLastMeasure() {
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);
MeasureDto selected = underTest.selectLastMeasure(db.getSession(), file.uuid(), metric.getKey()).get();
assertThat(selected).isEqualToComparingFieldByField(lastMeasure);
assertThat(underTest.selectLastMeasure(dbSession, "_missing_", metric.getKey())).isEmpty();
assertThat(underTest.selectLastMeasure(dbSession, file.uuid(), "_missing_")).isEmpty();
assertThat(underTest.selectLastMeasure(dbSession, "_missing_", "_missing_")).isEmpty();
}
use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class MeasureDaoTest method test_selects.
@Test
public void test_selects() {
ComponentDto project1 = db.components().insertPrivateProject();
ComponentDto module = db.components().insertComponent(newModuleDto(project1));
db.components().insertComponent(newFileDto(module).setUuid("C1"));
db.components().insertComponent(newFileDto(module).setUuid("C2"));
SnapshotDto lastAnalysis = insertAnalysis(project1.uuid(), true);
SnapshotDto pastAnalysis = insertAnalysis(project1.uuid(), false);
ComponentDto project2 = db.components().insertPrivateProject();
SnapshotDto project2LastAnalysis = insertAnalysis(project2.uuid(), true);
// project 1
insertMeasure("P1_M1", lastAnalysis.getUuid(), project1.uuid(), ncloc.getUuid());
insertMeasure("P1_M2", lastAnalysis.getUuid(), project1.uuid(), coverage.getUuid());
insertMeasure("P1_M3", pastAnalysis.getUuid(), project1.uuid(), ncloc.getUuid());
// project 2
insertMeasure("P2_M1", project2LastAnalysis.getUuid(), project2.uuid(), ncloc.getUuid());
insertMeasure("P2_M2", project2LastAnalysis.getUuid(), project2.uuid(), coverage.getUuid());
// component C1
insertMeasure("M1", pastAnalysis.getUuid(), "C1", ncloc.getUuid());
insertMeasure("M2", lastAnalysis.getUuid(), "C1", ncloc.getUuid());
insertMeasure("M3", lastAnalysis.getUuid(), "C1", coverage.getUuid());
// component C2
insertMeasure("M6", lastAnalysis.getUuid(), "C2", ncloc.getUuid());
db.commit();
verifyNoMeasure("C1", ncloc.getKey(), "invalid_analysis");
verifyNoMeasure("C1", "INVALID_KEY");
verifyNoMeasure("C1", "INVALID_KEY", pastAnalysis.getUuid());
verifyNoMeasure("MISSING_COMPONENT", ncloc.getKey());
verifyNoMeasure("MISSING_COMPONENT", ncloc.getKey(), pastAnalysis.getUuid());
// ncloc measure of component C1 of last analysis
verifyMeasure("C1", ncloc.getKey(), "M2");
// ncloc measure of component C1 of non last analysis
verifyMeasure("C1", ncloc.getKey(), pastAnalysis.getUuid(), "M1");
// ncloc measure of component C1 of last analysis by UUID
verifyMeasure("C1", ncloc.getKey(), lastAnalysis.getUuid(), "M2");
// missing measure of component C1 of last analysis
verifyNoMeasure("C1", complexity.getKey());
// missing measure of component C1 of non last analysis
verifyNoMeasure("C1", complexity.getKey(), pastAnalysis.getUuid());
// missing measure of component C1 of last analysis by UUID
verifyNoMeasure("C1", complexity.getKey(), lastAnalysis.getUuid());
// projects measures of last analysis
verifyMeasure(project1.uuid(), ncloc.getKey(), "P1_M1");
// projects measures of none last analysis
verifyMeasure(project1.uuid(), ncloc.getKey(), pastAnalysis.getUuid(), "P1_M3");
}
use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class ProjectMeasuresIndexerIteratorTest method return_application_measure.
@Test
public void return_application_measure() {
ComponentDto project = dbTester.components().insertPrivateApplication(c -> c.setDbKey("App-Key").setName("App Name"));
SnapshotDto analysis = dbTester.components().insertSnapshot(project);
MetricDto metric1 = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setKey("ncloc"));
MetricDto metric2 = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setKey("coverage"));
dbTester.measures().insertLiveMeasure(project, metric1, m -> m.setValue(10d));
dbTester.measures().insertLiveMeasure(project, metric2, m -> m.setValue(20d));
Map<String, ProjectMeasures> docsById = createResultSetAndReturnDocsById();
assertThat(docsById).hasSize(1);
ProjectMeasures doc = docsById.get(project.uuid());
assertThat(doc).isNotNull();
assertThat(doc.getProject().getUuid()).isEqualTo(project.uuid());
assertThat(doc.getProject().getKey()).isEqualTo("App-Key");
assertThat(doc.getProject().getName()).isEqualTo("App Name");
assertThat(doc.getProject().getAnalysisDate()).isNotNull().isEqualTo(analysis.getCreatedAt());
assertThat(doc.getMeasures().getNumericMeasures()).containsOnly(entry(metric1.getKey(), 10d), entry(metric2.getKey(), 20d));
}
use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class DuplicationDaoTest method selectCandidates_returns_block_from_last_snapshot_only_of_component_with_language_and_if_not_specified_analysis.
@Test
public void selectCandidates_returns_block_from_last_snapshot_only_of_component_with_language_and_if_not_specified_analysis() {
ComponentDto project1 = db.components().insertPrivateProject();
ComponentDto fooFile = db.components().insertComponent(ComponentTesting.newFileDto(project1).setLanguage("foo").setEnabled(true));
ComponentDto fooFile1 = db.components().insertComponent(ComponentTesting.newFileDto(project1).setLanguage("foo").setEnabled(true));
ComponentDto disabledFooFile = db.components().insertComponent(ComponentTesting.newFileDto(project1).setLanguage("foo").setEnabled(false));
ComponentDto barFile = db.components().insertComponent(ComponentTesting.newFileDto(project1).setLanguage("bar").setEnabled(true));
ComponentDto noLanguageFile = db.components().insertComponent(ComponentTesting.newFileDto(project1).setLanguage(null).setEnabled(true));
SnapshotDto newAnalysis = db.components().insertSnapshot(project1, t -> t.setLast(false));
SnapshotDto lastAnalysis = db.components().insertSnapshot(project1, t -> t.setLast(true));
SnapshotDto notLastAnalysis = db.components().insertSnapshot(project1, t -> t.setLast(false));
for (String hash : Arrays.asList("aa", "bb")) {
for (ComponentDto component : Arrays.asList(project1, fooFile, fooFile1, disabledFooFile, barFile, noLanguageFile)) {
insert(component, lastAnalysis, hash, 0, 1, 2);
insert(component, notLastAnalysis, hash, 0, 4, 5);
insert(component, newAnalysis, hash, 0, 6, 7);
}
}
for (String hash : Arrays.asList("aa", "bb")) {
assertThat(dao.selectCandidates(dbSession, newAnalysis.getUuid(), "foo", singletonList(hash))).containsOnly(tuple(fooFile.uuid(), fooFile.getKey(), lastAnalysis.getUuid(), hash), tuple(fooFile1.uuid(), fooFile1.getKey(), lastAnalysis.getUuid(), hash));
assertThat(dao.selectCandidates(dbSession, newAnalysis.getUuid(), "bar", singletonList(hash))).containsOnly(tuple(barFile.uuid(), barFile.getKey(), lastAnalysis.getUuid(), hash));
assertThat(dao.selectCandidates(dbSession, newAnalysis.getUuid(), "donut", singletonList(hash))).isEmpty();
}
for (List<String> hashes : Arrays.asList(of("aa", "bb"), of("bb", "aa"), of("aa", "bb", "cc"))) {
assertThat(dao.selectCandidates(dbSession, newAnalysis.getUuid(), "foo", hashes)).containsOnly(tuple(fooFile.uuid(), fooFile.getKey(), lastAnalysis.getUuid(), "aa"), tuple(fooFile.uuid(), fooFile.getKey(), lastAnalysis.getUuid(), "bb"), tuple(fooFile1.uuid(), fooFile1.getKey(), lastAnalysis.getUuid(), "aa"), tuple(fooFile1.uuid(), fooFile1.getKey(), lastAnalysis.getUuid(), "bb"));
assertThat(dao.selectCandidates(dbSession, newAnalysis.getUuid(), "bar", hashes)).containsOnly(tuple(barFile.uuid(), barFile.getKey(), lastAnalysis.getUuid(), "aa"), tuple(barFile.uuid(), barFile.getKey(), lastAnalysis.getUuid(), "bb"));
assertThat(dao.selectCandidates(dbSession, newAnalysis.getUuid(), "donut", hashes)).isEmpty();
}
assertThat(dao.selectCandidates(dbSession, lastAnalysis.getUuid(), "foo", singletonList("aa"))).isEmpty();
assertThat(dao.selectCandidates(dbSession, lastAnalysis.getUuid(), "bar", singletonList("aa"))).isEmpty();
assertThat(dao.selectCandidates(dbSession, lastAnalysis.getUuid(), "donut", singletonList("aa"))).isEmpty();
}
use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class DuplicationDaoTest method insert.
@Test
public void insert() {
ComponentDto project = newPrivateProjectDto();
SnapshotDto analysis = db.components().insertProjectAndSnapshot(project);
insert(project, analysis, "bb", 0, 1, 2);
List<Map<String, Object>> rows = db.select("select " + "uuid as \"UUID\", analysis_uuid as \"ANALYSIS\", component_uuid as \"COMPONENT\", hash as \"HASH\", " + "index_in_file as \"INDEX\", start_line as \"START\", end_line as \"END\"" + " from duplications_index");
Assertions.assertThat(rows).hasSize(1);
Map<String, Object> row = rows.get(0);
Assertions.assertThat(row.get("UUID")).isNotNull();
Assertions.assertThat(row).containsEntry("ANALYSIS", analysis.getUuid()).containsEntry("COMPONENT", project.uuid()).containsEntry("HASH", "bb").containsEntry("INDEX", 0L).containsEntry("START", 1L).containsEntry("END", 2L);
}
Aggregations