use of org.sonar.server.computation.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class ReportComputeMeasureVariationsStepTest method set_zero_variation_when_no_change.
@Test
public void set_zero_variation_when_no_change() {
// Project
SnapshotDto period1Snapshot = newAnalysis(project);
dbClient.snapshotDao().insert(session, period1Snapshot);
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), PROJECT_UUID, period1Snapshot.getUuid(), 60d));
// Directory
ComponentDto directoryDto = ComponentTesting.newDirectory(project, "dir");
dbClient.componentDao().insert(session, directoryDto);
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), directoryDto.uuid(), period1Snapshot.getUuid(), 10d));
session.commit();
periodsHolder.setPeriod(newPeriod(period1Snapshot));
Component directory = ReportComponent.builder(Component.Type.DIRECTORY, 2).setUuid(directoryDto.uuid()).build();
Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(PROJECT_UUID).addChildren(directory).build();
treeRootHolder.setRoot(project);
addRawMeasure(project, ISSUES_METRIC, newMeasureBuilder().create(60, null));
addRawMeasure(directory, ISSUES_METRIC, newMeasureBuilder().create(10, null));
underTest.execute();
assertThat(measureRepository.getRawMeasure(project, ISSUES_METRIC).get().getVariation()).isEqualTo(0d);
assertThat(measureRepository.getRawMeasure(directory, ISSUES_METRIC).get().getVariation()).isEqualTo(0d);
}
use of org.sonar.server.computation.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class ReportComputeMeasureVariationsStepTest method set_variation.
@Test
public void set_variation() {
// Project
SnapshotDto period1Snapshot = newAnalysis(project);
dbClient.snapshotDao().insert(session, period1Snapshot);
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), PROJECT_UUID, period1Snapshot.getUuid(), 60d));
// Directory
ComponentDto directoryDto = ComponentTesting.newDirectory(project, "dir");
dbClient.componentDao().insert(session, directoryDto);
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), directoryDto.uuid(), period1Snapshot.getUuid(), 10d));
session.commit();
periodsHolder.setPeriod(newPeriod(period1Snapshot));
Component directory = ReportComponent.builder(Component.Type.DIRECTORY, 2).setUuid(directoryDto.uuid()).build();
Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(PROJECT_UUID).addChildren(directory).build();
treeRootHolder.setRoot(project);
addRawMeasure(project, ISSUES_METRIC, newMeasureBuilder().create(80, null));
addRawMeasure(directory, ISSUES_METRIC, newMeasureBuilder().create(20, null));
underTest.execute();
assertThat(measureRepository.getRawMeasure(project, ISSUES_METRIC).get().getVariation()).isEqualTo(20d);
assertThat(measureRepository.getRawMeasure(directory, ISSUES_METRIC).get().getVariation()).isEqualTo(10d);
}
use of org.sonar.server.computation.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class ReportPersistAnalysisStepTest method only_persist_snapshots_with_leak_period_on_project_and_module.
@Test
public void only_persist_snapshots_with_leak_period_on_project_and_module() {
periodsHolder.setPeriod(new Period(LEAK_PERIOD_MODE_PREVIOUS_ANALYSIS, null, analysisDate, "u1"));
OrganizationDto organizationDto = dbTester.organizations().insert();
ComponentDto projectDto = ComponentTesting.newProjectDto(organizationDto, "ABCD").setKey(PROJECT_KEY).setName("Project");
dbClient.componentDao().insert(dbTester.getSession(), projectDto);
SnapshotDto projectSnapshot = SnapshotTesting.newAnalysis(projectDto);
dbClient.snapshotDao().insert(dbTester.getSession(), projectSnapshot);
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").addChildren(directory).build();
Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).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();
SnapshotDto newProjectSnapshot = getUnprocessedSnapshot(projectDto.uuid());
assertThat(newProjectSnapshot.getPeriodMode()).isEqualTo(LEAK_PERIOD_MODE_PREVIOUS_ANALYSIS);
}
use of org.sonar.server.computation.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class ReportPersistAnalysisStepTest method persist_snapshots_with_leak_period.
@Test
public void persist_snapshots_with_leak_period() {
OrganizationDto organizationDto = dbTester.organizations().insert();
ComponentDto projectDto = ComponentTesting.newProjectDto(organizationDto, "ABCD").setKey(PROJECT_KEY).setName("Project");
dbClient.componentDao().insert(dbTester.getSession(), projectDto);
SnapshotDto snapshotDto = SnapshotTesting.newAnalysis(projectDto).setCreatedAt(DateUtils.parseDateQuietly("2015-01-01").getTime());
dbClient.snapshotDao().insert(dbTester.getSession(), snapshotDto);
dbTester.getSession().commit();
periodsHolder.setPeriod(new Period(LEAK_PERIOD_MODE_DATE, "2015-01-01", analysisDate, "u1"));
Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).build();
treeRootHolder.setRoot(project);
dbIdsRepository.setComponentId(project, projectDto.getId());
underTest.execute();
SnapshotDto projectSnapshot = getUnprocessedSnapshot(projectDto.uuid());
assertThat(projectSnapshot.getPeriodMode()).isEqualTo(LEAK_PERIOD_MODE_DATE);
assertThat(projectSnapshot.getPeriodDate()).isEqualTo(analysisDate);
assertThat(projectSnapshot.getPeriodModeParameter()).isNotNull();
}
use of org.sonar.server.computation.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class ReportPersistAnalysisStepTest method set_no_period_on_snapshots_when_no_period.
@Test
public void set_no_period_on_snapshots_when_no_period() {
ComponentDto projectDto = ComponentTesting.newProjectDto(dbTester.organizations().insert(), "ABCD").setKey(PROJECT_KEY).setName("Project");
dbClient.componentDao().insert(dbTester.getSession(), projectDto);
SnapshotDto snapshotDto = SnapshotTesting.newAnalysis(projectDto);
dbClient.snapshotDao().insert(dbTester.getSession(), snapshotDto);
dbTester.getSession().commit();
Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).build();
treeRootHolder.setRoot(project);
dbIdsRepository.setComponentId(project, projectDto.getId());
underTest.execute();
SnapshotDto projectSnapshot = getUnprocessedSnapshot(projectDto.uuid());
assertThat(projectSnapshot.getPeriodMode()).isNull();
assertThat(projectSnapshot.getPeriodDate()).isNull();
assertThat(projectSnapshot.getPeriodModeParameter()).isNull();
}
Aggregations