use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class ViewsPersistAnalysisStepTest method persist_snapshots_with_leak_period.
@Test
public void persist_snapshots_with_leak_period() {
OrganizationDto organizationDto = dbTester.organizations().insert();
ComponentDto viewDto = save(newView(organizationDto, "UUID_VIEW").setKey("KEY_VIEW"));
ComponentDto subViewDto = save(newSubView(viewDto, "UUID_SUBVIEW", "KEY_SUBVIEW"));
dbTester.getSession().commit();
Component subView = ViewsComponent.builder(SUBVIEW, "KEY_SUBVIEW").setUuid("UUID_SUBVIEW").build();
Component view = ViewsComponent.builder(VIEW, "KEY_VIEW").setUuid("UUID_VIEW").addChildren(subView).build();
treeRootHolder.setRoot(view);
periodsHolder.setPeriod(new Period(LEAK_PERIOD_MODE_DATE, "2015-01-01", analysisDate, "u1"));
underTest.execute();
SnapshotDto viewSnapshot = getUnprocessedSnapshot(viewDto.uuid());
assertThat(viewSnapshot.getPeriodMode()).isEqualTo(LEAK_PERIOD_MODE_DATE);
assertThat(viewSnapshot.getPeriodDate()).isEqualTo(analysisDate);
assertThat(viewSnapshot.getPeriodModeParameter()).isNotNull();
}
use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class ReportComputeMeasureVariationsStepTest method do_not_set_variation_on_numeric_metric_for_developer.
@Test
public void do_not_set_variation_on_numeric_metric_for_developer() {
SnapshotDto period1ProjectSnapshot = newAnalysis(project);
dbClient.snapshotDao().insert(session, period1ProjectSnapshot);
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), PROJECT_UUID, period1ProjectSnapshot.getUuid(), 60d));
session.commit();
periodsHolder.setPeriod(newPeriod(period1ProjectSnapshot));
treeRootHolder.setRoot(PROJECT);
DumbDeveloper developer = new DumbDeveloper("a");
measureRepository.addRawMeasure(PROJECT_REF, ISSUES_METRIC.getKey(), newMeasureBuilder().forDeveloper(developer).create(80, null));
underTest.execute();
assertThat(measureRepository.getRawMeasures(PROJECT).keys()).hasSize(1);
assertThat(measureRepository.getRawMeasure(PROJECT, ISSUES_METRIC, developer).get().hasVariation()).isFalse();
}
use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class ReportComputeMeasureVariationsStepTest method do_nothing_when_no_raw_measure.
@Test
public void do_nothing_when_no_raw_measure() {
SnapshotDto period1ProjectSnapshot = newAnalysis(project);
dbClient.snapshotDao().insert(session, period1ProjectSnapshot);
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), PROJECT_UUID, period1ProjectSnapshot.getUuid(), 60d));
session.commit();
periodsHolder.setPeriod(newPeriod(period1ProjectSnapshot));
treeRootHolder.setRoot(PROJECT);
underTest.execute();
assertThat(measureRepository.getRawMeasures(PROJECT).keys()).isEmpty();
}
use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class ReportComputeMeasureVariationsStepTest method set_variation_on_all_numeric_metrics.
@Test
public void set_variation_on_all_numeric_metrics() {
SnapshotDto period1ProjectSnapshot = newAnalysis(project);
dbClient.snapshotDao().insert(session, period1ProjectSnapshot);
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), PROJECT_UUID, period1ProjectSnapshot.getUuid(), 60d), newMeasureDto(DEBT_METRIC.getId(), PROJECT_UUID, period1ProjectSnapshot.getUuid(), 10d), newMeasureDto(FILE_COMPLEXITY_METRIC.getId(), PROJECT_UUID, period1ProjectSnapshot.getUuid(), 2d), newMeasureDto(BUILD_BREAKER_METRIC.getId(), PROJECT_UUID, period1ProjectSnapshot.getUuid(), 1d));
session.commit();
periodsHolder.setPeriod(newPeriod(period1ProjectSnapshot));
treeRootHolder.setRoot(PROJECT);
addRawMeasure(PROJECT, ISSUES_METRIC, newMeasureBuilder().create(80, null));
addRawMeasure(PROJECT, DEBT_METRIC, newMeasureBuilder().create(5L, null));
addRawMeasure(PROJECT, FILE_COMPLEXITY_METRIC, newMeasureBuilder().create(3d, 1, null));
addRawMeasure(PROJECT, BUILD_BREAKER_METRIC, newMeasureBuilder().create(false, null));
underTest.execute();
assertThat(measureRepository.getRawMeasures(PROJECT).keys()).hasSize(4);
assertThat(measureRepository.getRawMeasure(PROJECT, ISSUES_METRIC).get().getVariation()).isEqualTo(20d);
assertThat(measureRepository.getRawMeasure(PROJECT, DEBT_METRIC).get().getVariation()).isEqualTo(-5d);
assertThat(measureRepository.getRawMeasure(PROJECT, FILE_COMPLEXITY_METRIC).get().getVariation()).isEqualTo(1d);
assertThat(measureRepository.getRawMeasure(PROJECT, BUILD_BREAKER_METRIC).get().getVariation()).isEqualTo(-1d);
}
use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class ShowActionTest method verifyCallToFileWithDuplications.
private void verifyCallToFileWithDuplications(Function<ComponentDto, WsTester.TestRequest> requestFactory) throws Exception {
ComponentDto project = db.components().insertProject();
ComponentDto file = db.components().insertComponent(newFileDto(project).setKey("foo.js"));
SnapshotDto snapshot = db.components().insertSnapshot(newAnalysis(project));
String xml = "<duplications>\n" + " <g>\n" + " <b s=\"31\" l=\"5\" r=\"foo.js\"/>\n" + " <b s=\"20\" l=\"5\" r=\"foo.js\"/>\n" + " </g>\n" + "</duplications>\n";
db.getDbClient().measureDao().insert(db.getSession(), newMeasureDto(dataMetric, file, snapshot).setData(xml));
db.commit();
userSessionRule.addProjectUuidPermissions(UserRole.CODEVIEWER, project.uuid());
WsTester.TestRequest request = requestFactory.apply(file);
WsTester.Result result = request.execute();
result.assertJson("{\"duplications\":[" + "{\"blocks\":[{\"from\":20,\"size\":5,\"_ref\":\"1\"},{\"from\":31,\"size\":5,\"_ref\":\"1\"}]}]," + "\"files\":{\"1\":{\"key\":\"foo.js\",\"uuid\":\"" + file.uuid() + "\"}}}");
}
Aggregations