Search in sources :

Example 46 with TestComputationStepContext

use of org.sonar.ce.task.step.TestComputationStepContext in project sonarqube by SonarSource.

the class ReportPersistAnalysisStepTest method persist_snapshots_with_new_code_period.

@Test
public void persist_snapshots_with_new_code_period() {
    ComponentDto projectDto = ComponentTesting.newPrivateProjectDto("ABCD").setDbKey(PROJECT_KEY).setName("Project");
    dbTester.components().insertComponent(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("NUMBER_OF_DAYS", "10", analysisDate));
    Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).build();
    treeRootHolder.setRoot(project);
    underTest.execute(new TestComputationStepContext());
    SnapshotDto projectSnapshot = getUnprocessedSnapshot(projectDto.uuid());
    assertThat(projectSnapshot.getPeriodMode()).isEqualTo("NUMBER_OF_DAYS");
    assertThat(projectSnapshot.getPeriodDate()).isEqualTo(analysisDate);
    assertThat(projectSnapshot.getPeriodModeParameter()).isNotNull();
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) Period(org.sonar.ce.task.projectanalysis.period.Period) Component(org.sonar.ce.task.projectanalysis.component.Component) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 47 with TestComputationStepContext

use of org.sonar.ce.task.step.TestComputationStepContext in project sonarqube by SonarSource.

the class ReportPersistAnalysisStepTest method persist_analysis.

@Test
public void persist_analysis() {
    String projectVersion = randomAlphabetic(10);
    ComponentDto projectDto = ComponentTesting.newPrivateProjectDto("ABCD").setDbKey(PROJECT_KEY).setName("Project");
    dbTester.components().insertComponent(projectDto);
    ComponentDto moduleDto = ComponentTesting.newModuleDto("BCDE", projectDto).setDbKey("MODULE_KEY").setName("Module");
    dbTester.components().insertComponent(moduleDto);
    ComponentDto directoryDto = ComponentTesting.newDirectory(moduleDto, "CDEF", "MODULE_KEY:src/main/java/dir").setDbKey("MODULE_KEY:src/main/java/dir");
    dbTester.components().insertComponent(directoryDto);
    ComponentDto fileDto = ComponentTesting.newFileDto(moduleDto, directoryDto, "DEFG").setDbKey("MODULE_KEY:src/main/java/dir/Foo.java");
    dbTester.components().insertComponent(fileDto);
    dbTester.getSession().commit();
    Component file = ReportComponent.builder(Component.Type.FILE, 3).setUuid("DEFG").setKey("MODULE_KEY:src/main/java/dir/Foo.java").build();
    Component directory = ReportComponent.builder(Component.Type.DIRECTORY, 2).setUuid("CDEF").setKey("MODULE_KEY:src/main/java/dir").addChildren(file).build();
    String buildString = Optional.ofNullable(projectVersion).map(v -> randomAlphabetic(7)).orElse(null);
    Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).setProjectVersion(projectVersion).setBuildString(buildString).setScmRevisionId(REVISION_ID).addChildren(directory).build();
    treeRootHolder.setRoot(project);
    underTest.execute(new TestComputationStepContext());
    assertThat(dbTester.countRowsOfTable("snapshots")).isOne();
    SnapshotDto projectSnapshot = getUnprocessedSnapshot(projectDto.uuid());
    assertThat(projectSnapshot.getUuid()).isEqualTo(ANALYSIS_UUID);
    assertThat(projectSnapshot.getComponentUuid()).isEqualTo(project.getUuid());
    assertThat(projectSnapshot.getProjectVersion()).isEqualTo(projectVersion);
    assertThat(projectSnapshot.getBuildString()).isEqualTo(buildString);
    assertThat(projectSnapshot.getLast()).isFalse();
    assertThat(projectSnapshot.getStatus()).isEqualTo("U");
    assertThat(projectSnapshot.getCreatedAt()).isEqualTo(analysisDate);
    assertThat(projectSnapshot.getBuildDate()).isEqualTo(now);
    assertThat(projectSnapshot.getRevision()).isEqualTo(REVISION_ID);
}
Also used : Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DateUtils(org.sonar.api.utils.DateUtils) ComputationStep(org.sonar.ce.task.step.ComputationStep) AnalysisMetadataHolderRule(org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule) ComponentTesting(org.sonar.db.component.ComponentTesting) SnapshotTesting(org.sonar.db.component.SnapshotTesting) Before(org.junit.Before) Component(org.sonar.ce.task.projectanalysis.component.Component) DbTester(org.sonar.db.DbTester) System2(org.sonar.api.utils.System2) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) PeriodHolderRule(org.sonar.ce.task.projectanalysis.period.PeriodHolderRule) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Period(org.sonar.ce.task.projectanalysis.period.Period) DbClient(org.sonar.db.DbClient) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) Rule(org.junit.Rule) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Optional(java.util.Optional) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) SnapshotQuery(org.sonar.db.component.SnapshotQuery) TreeRootHolderRule(org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule) SnapshotDto(org.sonar.db.component.SnapshotDto) Mockito.mock(org.mockito.Mockito.mock) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) Component(org.sonar.ce.task.projectanalysis.component.Component) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 48 with TestComputationStepContext

use of org.sonar.ce.task.step.TestComputationStepContext in project sonarqube by SonarSource.

the class ReportPersistAnalysisStepTest method only_persist_snapshots_with_new_code_period_on_project_and_module.

@Test
public void only_persist_snapshots_with_new_code_period_on_project_and_module() {
    periodsHolder.setPeriod(new Period("PREVIOUS_VERSION", null, analysisDate));
    ComponentDto projectDto = ComponentTesting.newPrivateProjectDto("ABCD").setDbKey(PROJECT_KEY).setName("Project");
    dbTester.components().insertComponent(projectDto);
    SnapshotDto projectSnapshot = SnapshotTesting.newAnalysis(projectDto);
    dbClient.snapshotDao().insert(dbTester.getSession(), projectSnapshot);
    ComponentDto moduleDto = ComponentTesting.newModuleDto("BCDE", projectDto).setDbKey("MODULE_KEY").setName("Module");
    dbTester.components().insertComponent(moduleDto);
    ComponentDto directoryDto = ComponentTesting.newDirectory(moduleDto, "CDEF", "MODULE_KEY:src/main/java/dir").setDbKey("MODULE_KEY:src/main/java/dir");
    dbTester.components().insertComponent(directoryDto);
    ComponentDto fileDto = ComponentTesting.newFileDto(moduleDto, directoryDto, "DEFG").setDbKey("MODULE_KEY:src/main/java/dir/Foo.java");
    dbTester.components().insertComponent(fileDto);
    dbTester.getSession().commit();
    Component file = ReportComponent.builder(Component.Type.FILE, 3).setUuid("DEFG").setKey("MODULE_KEY:src/main/java/dir/Foo.java").build();
    Component directory = ReportComponent.builder(Component.Type.DIRECTORY, 2).setUuid("CDEF").setKey("MODULE_KEY:src/main/java/dir").addChildren(file).build();
    Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).addChildren(directory).build();
    treeRootHolder.setRoot(project);
    underTest.execute(new TestComputationStepContext());
    SnapshotDto newProjectSnapshot = getUnprocessedSnapshot(projectDto.uuid());
    assertThat(newProjectSnapshot.getPeriodMode()).isEqualTo("PREVIOUS_VERSION");
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) Period(org.sonar.ce.task.projectanalysis.period.Period) Component(org.sonar.ce.task.projectanalysis.component.Component) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 49 with TestComputationStepContext

use of org.sonar.ce.task.step.TestComputationStepContext 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.newPrivateProjectDto("ABCD").setDbKey(PROJECT_KEY).setName("Project");
    dbTester.components().insertComponent(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);
    underTest.execute(new TestComputationStepContext());
    SnapshotDto projectSnapshot = getUnprocessedSnapshot(projectDto.uuid());
    assertThat(projectSnapshot.getPeriodMode()).isNull();
    assertThat(projectSnapshot.getPeriodDate()).isNull();
    assertThat(projectSnapshot.getPeriodModeParameter()).isNull();
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) Component(org.sonar.ce.task.projectanalysis.component.Component) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 50 with TestComputationStepContext

use of org.sonar.ce.task.step.TestComputationStepContext in project sonarqube by SonarSource.

the class ReportSizeMeasuresStepTest method verifyMetricAggregation.

private void verifyMetricAggregation(String metricKey) {
    measureRepository.addRawMeasure(FILE_1_REF, metricKey, newMeasureBuilder().create(10));
    measureRepository.addRawMeasure(FILE_2_REF, metricKey, newMeasureBuilder().create(6));
    measureRepository.addRawMeasure(UNIT_TEST_1_REF, metricKey, newMeasureBuilder().create(3));
    underTest.execute(new TestComputationStepContext());
    verifyMeasuresOnFile(FILE_1_REF, 1, 1);
    verifyMeasuresOnFile(FILE_2_REF, 2, 1);
    verifyMeasuresOnFile(FILE_3_REF, 7, 1);
    verifyMeasuresOnFile(FILE_4_REF, 9, 1);
    verifyMeasuresOnFile(FILE_5_REF, 5, 1);
    verifyNoMeasure(UNIT_TEST_1_REF);
    verifyNoMeasure(UNIT_TEST_2_REF);
    verifyMeasuresOnOtherComponent(DIRECTORY_1_REF, 3, 2, NO_METRIC, entryOf(metricKey, newMeasureBuilder().create(16)));
    verifyMeasuresOnOtherComponent(DIRECTORY_2_REF, 7, 1, NO_METRIC, entryOf(metricKey, newMeasureBuilder().create(3)));
    verifyMeasuresOnOtherComponent(DIRECTORY_3_REF, NO_METRIC, NO_METRIC, NO_METRIC);
    verifyMeasuresOnOtherComponent(DIRECTORY_4_REF, 14, 2, 2);
    verifyMeasuresOnOtherComponent(ROOT_REF, 24, 5, 5, entryOf(metricKey, newMeasureBuilder().create(19)));
}
Also used : TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext)

Aggregations

TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)458 Test (org.junit.Test)431 ComponentDto (org.sonar.db.component.ComponentDto)91 ProjectDump (com.sonarsource.governance.projectdump.protobuf.ProjectDump)38 Component (org.sonar.ce.task.projectanalysis.component.Component)38 SnapshotDto (org.sonar.db.component.SnapshotDto)31 Date (java.util.Date)30 ReportComponent (org.sonar.ce.task.projectanalysis.component.ReportComponent)28 ComputationStep (org.sonar.ce.task.step.ComputationStep)24 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)17 FileSourceDto (org.sonar.db.source.FileSourceDto)15 BaseStepTest (org.sonar.ce.task.projectanalysis.step.BaseStepTest)14 Project (org.sonar.server.project.Project)14 TextBlock (org.sonar.ce.task.projectanalysis.duplication.TextBlock)13 QualityProfile (org.sonar.server.qualityprofile.QualityProfile)13 Notification (org.sonar.api.notifications.Notification)12 DefaultIssue (org.sonar.core.issue.DefaultIssue)12 MeasureComputer (org.sonar.api.ce.measure.MeasureComputer)11 IssueDto (org.sonar.db.issue.IssueDto)11 IssuesChangesNotification (org.sonar.server.issue.notification.IssuesChangesNotification)11