Search in sources :

Example 6 with Period

use of org.sonar.ce.task.projectanalysis.period.Period in project sonarqube by SonarSource.

the class NewIssueClassifierTest method isEnabled_returns_true_when_periodDate_present.

@Test
public void isEnabled_returns_true_when_periodDate_present() {
    periodHolder.setPeriod(new Period(NewCodePeriodType.NUMBER_OF_DAYS.name(), "10", 1000L));
    assertThat(newIssueClassifier.isEnabled()).isTrue();
}
Also used : Period(org.sonar.ce.task.projectanalysis.period.Period) Test(org.junit.Test)

Example 7 with Period

use of org.sonar.ce.task.projectanalysis.period.Period 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 8 with Period

use of org.sonar.ce.task.projectanalysis.period.Period 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 9 with Period

use of org.sonar.ce.task.projectanalysis.period.Period in project sonarqube by SonarSource.

the class ViewsPersistAnalysisStepTest method persist_snapshots_with_new_code_period.

@Test
public void persist_snapshots_with_new_code_period() {
    ComponentDto viewDto = save(ComponentTesting.newPortfolio("UUID_VIEW").setDbKey("KEY_VIEW"));
    ComponentDto subViewDto = save(ComponentTesting.newSubPortfolio(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("NUMBER_OF_DAYS", "30", analysisDate));
    underTest.execute(new TestComputationStepContext());
    SnapshotDto viewSnapshot = getUnprocessedSnapshot(viewDto.uuid());
    assertThat(viewSnapshot.getPeriodMode()).isEqualTo("NUMBER_OF_DAYS");
    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.ce.task.projectanalysis.period.Period) ViewsComponent(org.sonar.ce.task.projectanalysis.component.ViewsComponent) Component(org.sonar.ce.task.projectanalysis.component.Component) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 10 with Period

use of org.sonar.ce.task.projectanalysis.period.Period in project sonarqube by SonarSource.

the class LoadPeriodsStepTest method assertPeriod.

private void assertPeriod(NewCodePeriodType type, @Nullable String value, @Nullable Long date) {
    Period period = periodsHolder.getPeriod();
    assertThat(period).isNotNull();
    assertThat(period.getMode()).isEqualTo(type.name());
    assertThat(period.getModeParameter()).isEqualTo(value);
    assertThat(period.getDate()).isEqualTo(date);
}
Also used : Period(org.sonar.ce.task.projectanalysis.period.Period)

Aggregations

Period (org.sonar.ce.task.projectanalysis.period.Period)17 Test (org.junit.Test)15 Component (org.sonar.ce.task.projectanalysis.component.Component)10 DefaultIssue (org.sonar.core.issue.DefaultIssue)7 Set (java.util.Set)3 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)3 ComponentDto (org.sonar.db.component.ComponentDto)3 SnapshotDto (org.sonar.db.component.SnapshotDto)3 Date (java.util.Date)2 ReportComponent (org.sonar.ce.task.projectanalysis.component.ReportComponent)2 ViewsComponent (org.sonar.ce.task.projectanalysis.component.ViewsComponent)1 DbSession (org.sonar.db.DbSession)1 NewCodePeriodDto (org.sonar.db.newcodeperiod.NewCodePeriodDto)1