use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.
the class MeasureDaoTest method test_inserted_and_selected_columns.
@Test
public void test_inserted_and_selected_columns() {
ComponentDto project = db.components().insertProject();
insertAnalysis(LAST_ANALYSIS_UUID, project.uuid(), true);
db.components().insertComponent(newFileDto(project).setUuid("C4"));
MeasureDto inserted = new MeasureDto().setAnalysisUuid(LAST_ANALYSIS_UUID).setMetricId(2).setDeveloperId(3L).setComponentUuid("C4").setValue(5.0d).setData("data").setVariation(1d).setAlertStatus("alert").setAlertText("alert-text").setDescription("measure-description");
underTest.insert(db.getSession(), inserted);
db.commit();
MeasureDto selected = underTest.selectSingle(db.getSession(), MeasureQuery.builder().setComponentUuid(inserted.getComponentUuid()).setPersonId(inserted.getDeveloperId()).build()).get();
assertThat(selected.getAnalysisUuid()).isEqualTo(inserted.getAnalysisUuid());
assertThat(selected.getMetricId()).isEqualTo(inserted.getMetricId());
assertThat(selected.getDeveloperId()).isEqualTo(inserted.getDeveloperId());
assertThat(selected.getComponentUuid()).isEqualTo(inserted.getComponentUuid());
assertThat(selected.getValue()).isEqualTo(inserted.getValue());
assertThat(selected.getData()).isEqualTo(inserted.getData());
assertThat(selected.getVariation()).isEqualTo(inserted.getVariation());
assertThat(selected.getAlertStatus()).isEqualTo(inserted.getAlertStatus());
assertThat(selected.getAlertText()).isEqualTo(inserted.getAlertText());
}
use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.
the class MeasureDaoTest method selectProjectMeasuresOfDeveloper.
@Test
public void selectProjectMeasuresOfDeveloper() {
OrganizationDto organizationDto = db.organizations().insert();
ComponentDto dev = db.components().insertComponent(newDeveloper(organizationDto, "DEV"));
insertAnalysis(LAST_ANALYSIS_UUID, dev.uuid(), true);
insertAnalysis(PREVIOUS_ANALYSIS_UUID, dev.uuid(), false);
List<Integer> allMetricIds = Arrays.asList(NCLOC_METRIC_ID, COMPLEXITY_METRIC_ID, COVERAGE_METRIC_ID);
long developerId = dev.getId();
assertThat(underTest.selectProjectMeasuresOfDeveloper(db.getSession(), developerId, allMetricIds)).isEmpty();
String projectUuid = insertComponent(Scopes.PROJECT, PROJECT, true);
String viewUuid = insertComponent(Scopes.PROJECT, VIEW, true);
String disabledProjectUuid = insertComponent(Scopes.PROJECT, PROJECT, false);
insertMeasure("M1", LAST_ANALYSIS_UUID, projectUuid, NCLOC_METRIC_ID);
insertMeasure("M2", LAST_ANALYSIS_UUID, projectUuid, COMPLEXITY_METRIC_ID);
insertMeasure("M3", LAST_ANALYSIS_UUID, projectUuid, COVERAGE_METRIC_ID);
insertMeasure("M4", PREVIOUS_ANALYSIS_UUID, projectUuid, NCLOC_METRIC_ID);
insertMeasure("M5", PREVIOUS_ANALYSIS_UUID, projectUuid, COMPLEXITY_METRIC_ID);
insertMeasure("M6", PREVIOUS_ANALYSIS_UUID, projectUuid, COVERAGE_METRIC_ID);
insertMeasure("M11", LAST_ANALYSIS_UUID, projectUuid, developerId, NCLOC_METRIC_ID);
insertMeasure("M12", LAST_ANALYSIS_UUID, projectUuid, developerId, COMPLEXITY_METRIC_ID);
insertMeasure("M13", LAST_ANALYSIS_UUID, projectUuid, developerId, COVERAGE_METRIC_ID);
insertMeasure("M14", PREVIOUS_ANALYSIS_UUID, projectUuid, NCLOC_METRIC_ID);
insertMeasure("M15", PREVIOUS_ANALYSIS_UUID, projectUuid, COMPLEXITY_METRIC_ID);
insertMeasure("M16", PREVIOUS_ANALYSIS_UUID, projectUuid, COVERAGE_METRIC_ID);
insertMeasure("M51", LAST_ANALYSIS_UUID, viewUuid, NCLOC_METRIC_ID);
insertMeasure("M52", LAST_ANALYSIS_UUID, viewUuid, COMPLEXITY_METRIC_ID);
insertMeasure("M53", LAST_ANALYSIS_UUID, viewUuid, COVERAGE_METRIC_ID);
insertMeasure("M54", LAST_ANALYSIS_UUID, disabledProjectUuid, developerId, NCLOC_METRIC_ID);
insertMeasure("M55", LAST_ANALYSIS_UUID, disabledProjectUuid, developerId, COMPLEXITY_METRIC_ID);
insertMeasure("M56", LAST_ANALYSIS_UUID, disabledProjectUuid, developerId, COVERAGE_METRIC_ID);
assertThat(underTest.selectProjectMeasuresOfDeveloper(db.getSession(), developerId, allMetricIds)).extracting(MeasureDto::getData).containsOnly("M11", "M12", "M13", "M54", "M55", "M56");
assertThat(underTest.selectProjectMeasuresOfDeveloper(db.getSession(), developerId, singletonList(NCLOC_METRIC_ID))).extracting(MeasureDto::getData).containsOnly("M11", "M54");
}
use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.
the class MeasureDaoTest method select_tree_by_query_use_only_latest_analysis.
@Test
public void select_tree_by_query_use_only_latest_analysis() {
ComponentDto project = db.components().insertProject();
ComponentDto file1 = db.components().insertComponent(newFileDto(project).setUuid("C1").setName("File One"));
db.components().insertComponent(newFileDto(project).setUuid("C2").setName("File Two").setQualifier(UNIT_TEST_FILE));
insertAnalysis(LAST_ANALYSIS_UUID, project.uuid(), true);
insertAnalysis(OTHER_ANALYSIS_UUID, project.uuid(), false);
// project
insertMeasure("PROJECT_M1", LAST_ANALYSIS_UUID, project.uuid(), NCLOC_METRIC_ID);
insertMeasure("PROJECT_M2", OTHER_ANALYSIS_UUID, project.uuid(), NCLOC_METRIC_ID);
// component C1
insertMeasure("M2", LAST_ANALYSIS_UUID, "C1", NCLOC_METRIC_ID);
insertMeasure("M3", LAST_ANALYSIS_UUID, "C1", COVERAGE_METRIC_ID);
insertMeasure("M4", OTHER_ANALYSIS_UUID, "C1", COVERAGE_METRIC_ID);
// component C2
insertMeasure("M5", LAST_ANALYSIS_UUID, "C2", NCLOC_METRIC_ID);
insertMeasure("M6", OTHER_ANALYSIS_UUID, "C2", NCLOC_METRIC_ID);
db.commit();
// Children measures of project
verifyMeasures(project, MeasureTreeQuery.builder().setStrategy(CHILDREN), "PROJECT_M1", "M2", "M3", "M5");
// Children measure on file => only measures from itself
verifyMeasures(file1, MeasureTreeQuery.builder().setStrategy(CHILDREN), "M2", "M3");
// Leaves measures of project
verifyMeasures(project, MeasureTreeQuery.builder().setStrategy(LEAVES), "PROJECT_M1", "M2", "M3", "M5");
// Leaves measure on file
verifyMeasures(file1, MeasureTreeQuery.builder().setStrategy(LEAVES), "M2", "M3");
}
use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.
the class MeasureDaoTest method selectSingle.
@Test
public void selectSingle() {
ComponentDto project = db.components().insertProject();
db.components().insertComponent(newFileDto(project).setUuid("C1"));
insertAnalysis(LAST_ANALYSIS_UUID, project.uuid(), true);
insertMeasure("M1", LAST_ANALYSIS_UUID, "C1", NCLOC_METRIC_ID);
insertMeasure("M2", LAST_ANALYSIS_UUID, "C1", COMPLEXITY_METRIC_ID);
db.commit();
assertThat(selectSingle(MeasureQuery.builder().setComponentUuids(project.uuid(), emptyList()))).isNotPresent();
assertThat(selectSingle(MeasureQuery.builder().setComponentUuid("MISSING_COMPONENT"))).isNotPresent();
// select a single measure
assertThat(selectSingle(MeasureQuery.builder().setComponentUuid("C1").setMetricId(NCLOC_METRIC_ID))).isPresent();
// select multiple measures -> fail
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("expected one element");
selectSingle(MeasureQuery.builder().setComponentUuid("C1"));
}
use of org.sonar.db.component.ComponentDto 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().insertProject();
long lastAnalysisDate = parseDate("2017-01-25").getTime();
long previousAnalysisDate = lastAnalysisDate - 10_000_000_000L;
long oldAnalysisDate = lastAnalysisDate - 100_000_000_000L;
dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setUuid(LAST_ANALYSIS_UUID).setCreatedAt(lastAnalysisDate));
dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setUuid(OTHER_ANALYSIS_UUID).setCreatedAt(previousAnalysisDate).setLast(false));
dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setUuid("OLD_ANALYSIS_UUID").setCreatedAt(oldAnalysisDate).setLast(false));
db.commit();
// project
insertMeasure("PROJECT_M1", LAST_ANALYSIS_UUID, project.uuid(), NCLOC_METRIC_ID);
insertMeasure("PROJECT_M2", OTHER_ANALYSIS_UUID, project.uuid(), NCLOC_METRIC_ID);
insertMeasure("PROJECT_M3", "OLD_ANALYSIS_UUID", project.uuid(), NCLOC_METRIC_ID);
db.commit();
// Measures of project for last and previous analyses
List<MeasureDto> result = underTest.selectPastMeasures(db.getSession(), new PastMeasureQuery(project.uuid(), singletonList(NCLOC_METRIC_ID), previousAnalysisDate, lastAnalysisDate + 1_000L));
assertThat(result).hasSize(2).extracting(MeasureDto::getData).containsOnly("PROJECT_M1", "PROJECT_M2");
}
Aggregations