use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class EnableAnalysisStepTest method insertAnalysis.
private void insertAnalysis(ComponentDto project, String uuid, String status, boolean isLastFlag) {
SnapshotDto snapshot = SnapshotTesting.newAnalysis(project).setLast(isLastFlag).setStatus(status).setUuid(uuid);
db.getDbClient().snapshotDao().insert(db.getSession(), snapshot);
}
use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class ReportPersistAnalysisStepTest method persist_analysis.
@Test
public void persist_analysis() {
OrganizationDto organizationDto = dbTester.organizations().insert();
ComponentDto projectDto = ComponentTesting.newProjectDto(organizationDto, "ABCD").setKey(PROJECT_KEY).setName("Project");
dbClient.componentDao().insert(dbTester.getSession(), projectDto);
ComponentDto moduleDto = ComponentTesting.newModuleDto("BCDE", projectDto).setKey("MODULE_KEY").setName("Module");
dbClient.componentDao().insert(dbTester.getSession(), moduleDto);
ComponentDto directoryDto = ComponentTesting.newDirectory(moduleDto, "CDEF", "MODULE_KEY:src/main/java/dir").setKey("MODULE_KEY:src/main/java/dir");
dbClient.componentDao().insert(dbTester.getSession(), directoryDto);
ComponentDto fileDto = ComponentTesting.newFileDto(moduleDto, directoryDto, "DEFG").setKey("MODULE_KEY:src/main/java/dir/Foo.java");
dbClient.componentDao().insert(dbTester.getSession(), fileDto);
dbTester.getSession().commit();
Component file = ReportComponent.builder(Component.Type.FILE, 4).setUuid("DEFG").setKey("MODULE_KEY:src/main/java/dir/Foo.java").build();
Component directory = ReportComponent.builder(Component.Type.DIRECTORY, 3).setUuid("CDEF").setKey("MODULE_KEY:src/main/java/dir").addChildren(file).build();
Component module = ReportComponent.builder(Component.Type.MODULE, 2).setUuid("BCDE").setKey("MODULE_KEY").setVersion("1.1").addChildren(directory).build();
Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).setVersion("1.0").addChildren(module).build();
treeRootHolder.setRoot(project);
dbIdsRepository.setComponentId(project, projectDto.getId());
dbIdsRepository.setComponentId(module, moduleDto.getId());
dbIdsRepository.setComponentId(directory, directoryDto.getId());
dbIdsRepository.setComponentId(file, fileDto.getId());
underTest.execute();
assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(1);
SnapshotDto projectSnapshot = getUnprocessedSnapshot(projectDto.uuid());
assertThat(projectSnapshot.getUuid()).isEqualTo(ANALYSIS_UUID);
assertThat(projectSnapshot.getComponentUuid()).isEqualTo(project.getUuid());
assertThat(projectSnapshot.getVersion()).isEqualTo("1.0");
assertThat(projectSnapshot.getLast()).isFalse();
assertThat(projectSnapshot.getStatus()).isEqualTo("U");
assertThat(projectSnapshot.getCreatedAt()).isEqualTo(analysisDate);
assertThat(projectSnapshot.getBuildDate()).isEqualTo(now);
assertThat(dbIdsRepository.getComponentId(module)).isEqualTo(moduleDto.getId());
assertThat(dbIdsRepository.getComponentId(directory)).isEqualTo(directoryDto.getId());
assertThat(dbIdsRepository.getComponentId(file)).isEqualTo(fileDto.getId());
}
use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class ReportComputeMeasureVariationsStepTest method does_not_update_existing_variation.
@Test
public void does_not_update_existing_variation() throws Exception {
SnapshotDto period1ProjectSnapshot = newAnalysis(project);
dbClient.snapshotDao().insert(session, period1ProjectSnapshot);
dbClient.measureDao().insert(session, newMeasureDto(NEW_DEBT.getId(), PROJECT_UUID, period1ProjectSnapshot.getUuid(), 60d));
session.commit();
periodsHolder.setPeriod(newPeriod(period1ProjectSnapshot));
treeRootHolder.setRoot(PROJECT);
addRawMeasure(PROJECT, NEW_DEBT, newMeasureBuilder().setVariation(10d).createNoValue());
underTest.execute();
// As the measure has already variations it has been ignored, then variations will be the same
assertThat(measureRepository.getRawMeasure(PROJECT, NEW_DEBT).get().getVariation()).isEqualTo(10d);
}
use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class ViewsComputeMeasureVariationsStepTest method set_variation.
@Test
public void set_variation() {
// View
SnapshotDto period1Snapshot = newAnalysis(view);
dbClient.snapshotDao().insert(session, period1Snapshot);
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), VIEW_UUID, period1Snapshot.getUuid(), 60d));
// SubView
ComponentDto subviewDto = ComponentTesting.newSubView(view, "dir", "key");
dbClient.componentDao().insert(session, subviewDto);
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), subviewDto.uuid(), period1Snapshot.getUuid(), 10d));
session.commit();
periodsHolder.setPeriod(newPeriod(period1Snapshot));
Component subview = ViewsComponent.builder(Component.Type.SUBVIEW, 2).setUuid(subviewDto.uuid()).build();
Component view = ViewsComponent.builder(Component.Type.VIEW, 1).setUuid(VIEW_UUID).addChildren(subview).build();
treeRootHolder.setRoot(view);
addRawMeasure(view, ISSUES_METRIC, Measure.newMeasureBuilder().create(80, null));
addRawMeasure(subview, ISSUES_METRIC, Measure.newMeasureBuilder().create(20, null));
underTest.execute();
assertThat(measureRepository.getRawMeasure(view, ISSUES_METRIC).get().getVariation()).isEqualTo(20d);
assertThat(measureRepository.getRawMeasure(subview, ISSUES_METRIC).get().getVariation()).isEqualTo(10d);
}
use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class ViewsComputeMeasureVariationsStepTest method set_variation_on_all_numeric_metrics.
@Test
public void set_variation_on_all_numeric_metrics() {
SnapshotDto period1ViewSnapshot = newAnalysis(view);
dbClient.snapshotDao().insert(session, period1ViewSnapshot);
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), VIEW_UUID, period1ViewSnapshot.getUuid(), 60d), newMeasureDto(DEBT_METRIC.getId(), VIEW_UUID, period1ViewSnapshot.getUuid(), 10d), newMeasureDto(FILE_COMPLEXITY_METRIC.getId(), VIEW_UUID, period1ViewSnapshot.getUuid(), 2d), newMeasureDto(BUILD_BREAKER_METRIC.getId(), VIEW_UUID, period1ViewSnapshot.getUuid(), 1d));
session.commit();
periodsHolder.setPeriod(newPeriod(period1ViewSnapshot));
treeRootHolder.setRoot(VIEW);
addRawMeasure(VIEW, ISSUES_METRIC, Measure.newMeasureBuilder().create(80, null));
addRawMeasure(VIEW, DEBT_METRIC, Measure.newMeasureBuilder().create(5L, null));
addRawMeasure(VIEW, FILE_COMPLEXITY_METRIC, Measure.newMeasureBuilder().create(3d, 1));
addRawMeasure(VIEW, BUILD_BREAKER_METRIC, Measure.newMeasureBuilder().create(false, null));
underTest.execute();
assertThat(measureRepository.getRawMeasures(VIEW).keys()).hasSize(4);
assertThat(measureRepository.getRawMeasure(VIEW, ISSUES_METRIC).get().getVariation()).isEqualTo(20d);
assertThat(measureRepository.getRawMeasure(VIEW, DEBT_METRIC).get().getVariation()).isEqualTo(-5d);
assertThat(measureRepository.getRawMeasure(VIEW, FILE_COMPLEXITY_METRIC).get().getVariation()).isEqualTo(1d);
assertThat(measureRepository.getRawMeasure(VIEW, BUILD_BREAKER_METRIC).get().getVariation()).isEqualTo(-1d);
}
Aggregations