Search in sources :

Example 21 with SnapshotDto

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();
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) Period(org.sonar.server.computation.task.projectanalysis.period.Period) ViewsComponent(org.sonar.server.computation.task.projectanalysis.component.ViewsComponent) Component(org.sonar.server.computation.task.projectanalysis.component.Component) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 22 with SnapshotDto

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();
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) DumbDeveloper(org.sonar.server.computation.task.projectanalysis.component.DumbDeveloper) Test(org.junit.Test)

Example 23 with SnapshotDto

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();
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) Test(org.junit.Test)

Example 24 with SnapshotDto

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);
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) Test(org.junit.Test)

Example 25 with SnapshotDto

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() + "\"}}}");
}
Also used : WsTester(org.sonar.server.ws.WsTester) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto)

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