Search in sources :

Example 31 with SnapshotDto

use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.

the class ProjectStatusActionTest method return_status_by_project_key.

@Test
public void return_status_by_project_key() throws IOException {
    ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert()).setKey("project-key"));
    SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setPeriodMode("last_version").setPeriodParam("2015-12-07").setPeriodDate(956789123987L));
    MetricDto metric = dbClient.metricDao().insert(dbSession, newMetricDto().setEnabled(true).setKey(CoreMetrics.QUALITY_GATE_DETAILS_KEY));
    dbClient.measureDao().insert(dbSession, newMeasureDto(metric, project, snapshot).setData(IOUtils.toString(getClass().getResource("ProjectStatusActionTest/measure_data.json"))));
    dbSession.commit();
    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
    String response = ws.newRequest().setParam(PARAM_PROJECT_KEY, "project-key").execute().getInput();
    assertJson(response).isSimilarTo(getClass().getResource("project_status-example.json"));
}
Also used : MetricTesting.newMetricDto(org.sonar.db.metric.MetricTesting.newMetricDto) MetricDto(org.sonar.db.metric.MetricDto) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 32 with SnapshotDto

use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.

the class NewCodePeriodResolver method resolveByDays.

private Period resolveByDays(DbSession dbSession, String rootUuid, Integer days, String value, long referenceDate) {
    checkPeriodProperty(days > 0, value, "number of days is <= 0");
    List<SnapshotDto> snapshots = dbClient.snapshotDao().selectAnalysesByQuery(dbSession, createCommonQuery(rootUuid).setCreatedBefore(referenceDate).setSort(BY_DATE, ASC));
    Instant targetDate = DateUtils.addDays(Instant.ofEpochMilli(referenceDate), -days);
    LOG.debug("Resolving new code period by {} days: {}", days, supplierToString(() -> logDate(targetDate)));
    SnapshotDto snapshot = findNearestSnapshotToTargetDate(snapshots, targetDate);
    return newPeriod(NewCodePeriodType.NUMBER_OF_DAYS, String.valueOf((int) days), snapshot.getCreatedAt());
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) Instant(java.time.Instant)

Example 33 with SnapshotDto

use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.

the class NewCodePeriodResolver method findNearestSnapshotToTargetDate.

private static SnapshotDto findNearestSnapshotToTargetDate(List<SnapshotDto> snapshots, Instant targetDate) {
    // FIXME shouldn't this be the first analysis after targetDate?
    Duration bestDuration = null;
    SnapshotDto nearest = null;
    ensureNotOnFirstAnalysis(!snapshots.isEmpty());
    for (SnapshotDto snapshot : snapshots) {
        Instant createdAt = Instant.ofEpochMilli(snapshot.getCreatedAt());
        Duration duration = Duration.between(targetDate, createdAt).abs();
        if (bestDuration == null || duration.compareTo(bestDuration) <= 0) {
            bestDuration = duration;
            nearest = snapshot;
        }
    }
    return nearest;
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) Instant(java.time.Instant) Duration(java.time.Duration)

Example 34 with SnapshotDto

use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.

the class LoadCrossProjectDuplicationsRepositoryStepTest method nothing_to_do_when_cross_project_duplication_is_disabled.

@Test
public void nothing_to_do_when_cross_project_duplication_is_disabled() {
    when(crossProjectDuplicationStatusHolder.isEnabled()).thenReturn(false);
    analysisMetadataHolder.setBaseAnalysis(baseProjectAnalysis);
    ComponentDto otherProject = createProject("OTHER_PROJECT_KEY");
    SnapshotDto otherProjectSnapshot = createProjectSnapshot(otherProject);
    ComponentDto otherFIle = createFile("OTHER_FILE_KEY", otherProject);
    String hash = "a8998353e96320ec";
    DuplicationUnitDto duplicate = new DuplicationUnitDto().setHash(hash).setStartLine(40).setEndLine(55).setIndexInFile(0).setAnalysisUuid(otherProjectSnapshot.getUuid()).setComponentUuid(otherFIle.uuid());
    dbClient.duplicationDao().insert(dbSession, duplicate);
    dbSession.commit();
    ScannerReport.CpdTextBlock originBlock = ScannerReport.CpdTextBlock.newBuilder().setHash(hash).setStartLine(30).setEndLine(45).setStartTokenIndex(0).setEndTokenIndex(10).build();
    batchReportReader.putDuplicationBlocks(FILE_REF, singletonList(originBlock));
    underTest.execute(new TestComputationStepContext());
    verifyZeroInteractions(integrateCrossProjectDuplications);
}
Also used : DuplicationUnitDto(org.sonar.db.duplication.DuplicationUnitDto) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) ScannerReport(org.sonar.scanner.protocol.output.ScannerReport) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 35 with SnapshotDto

use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.

the class LoadCrossProjectDuplicationsRepositoryStepTest method createProjectSnapshot.

private SnapshotDto createProjectSnapshot(ComponentDto project) {
    SnapshotDto projectSnapshot = SnapshotTesting.newAnalysis(project);
    dbClient.snapshotDao().insert(dbSession, projectSnapshot);
    dbSession.commit();
    return projectSnapshot;
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto)

Aggregations

SnapshotDto (org.sonar.db.component.SnapshotDto)326 Test (org.junit.Test)257 ComponentDto (org.sonar.db.component.ComponentDto)219 MetricDto (org.sonar.db.metric.MetricDto)54 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)31 EventDto (org.sonar.db.event.EventDto)30 ProjectDto (org.sonar.db.project.ProjectDto)27 DbSession (org.sonar.db.DbSession)26 SnapshotTesting.newAnalysis (org.sonar.db.component.SnapshotTesting.newAnalysis)21 BranchDto (org.sonar.db.component.BranchDto)20 SearchEventsWsResponse (org.sonarqube.ws.Developers.SearchEventsWsResponse)20 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)17 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)14 DbClient (org.sonar.db.DbClient)14 NotFoundException (org.sonar.server.exceptions.NotFoundException)14 List (java.util.List)13 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)13 Rule (org.junit.Rule)13 UserRole (org.sonar.api.web.UserRole)13 DbTester (org.sonar.db.DbTester)13