Search in sources :

Example 86 with TestComputationStepContext

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

the class PersistLiveMeasuresStepTest method delete_measures_from_db_if_no_longer_computed.

@Test
public void delete_measures_from_db_if_no_longer_computed() {
    prepareProject();
    // measure to be updated
    LiveMeasureDto measureOnFileInProject = insertMeasure("file-uuid", "project-uuid", INT_METRIC);
    // measure to be deleted because not computed anymore
    LiveMeasureDto otherMeasureOnFileInProject = insertMeasure("file-uuid", "project-uuid", STRING_METRIC);
    // measure in another project, not touched
    LiveMeasureDto measureInOtherProject = insertMeasure("other-file-uuid", "other-project-uuid", INT_METRIC);
    db.commit();
    measureRepository.addRawMeasure(REF_4, INT_METRIC.getKey(), newMeasureBuilder().create(42));
    TestComputationStepContext context = new TestComputationStepContext();
    step().execute(context);
    assertThatMeasureHasValue(measureOnFileInProject, 42);
    assertThatMeasureDoesNotExist(otherMeasureOnFileInProject);
    assertThatMeasureHasValue(measureInOtherProject, (int) measureInOtherProject.getValue().doubleValue());
    verifyStatistics(context, 1);
}
Also used : LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 87 with TestComputationStepContext

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

the class PersistProjectLinksStepTest method add_links_on_project.

@Test
public void add_links_on_project() {
    mockBranch(true);
    treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").build());
    // project
    reportReader.putComponent(ScannerReport.Component.newBuilder().setRef(1).setType(ComponentType.PROJECT).addChildRef(2).addLink(ScannerReport.ComponentLink.newBuilder().setType(HOME).setHref("http://www.sonarqube.org").build()).addLink(ScannerReport.ComponentLink.newBuilder().setType(SCM).setHref("https://github.com/SonarSource/sonar").build()).addLink(ScannerReport.ComponentLink.newBuilder().setType(ISSUE).setHref("http://jira.sonarsource.com/").build()).addLink(ScannerReport.ComponentLink.newBuilder().setType(CI).setHref("http://bamboo.ci.codehaus.org/browse/SONAR").build()).build());
    underTest.execute(new TestComputationStepContext());
    assertThat(db.getDbClient().projectLinkDao().selectByProjectUuid(db.getSession(), "ABCD")).extracting(ProjectLinkDto::getType, ProjectLinkDto::getHref, ProjectLinkDto::getName).containsExactlyInAnyOrder(tuple("homepage", "http://www.sonarqube.org", null), tuple("scm", "https://github.com/SonarSource/sonar", null), tuple("issue", "http://jira.sonarsource.com/", null), tuple("ci", "http://bamboo.ci.codehaus.org/browse/SONAR", null));
}
Also used : TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 88 with TestComputationStepContext

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

the class LoadPeriodsStepTest method no_period_date_if_not_branch.

@Test
public void no_period_date_if_not_branch() {
    when(analysisMetadataHolder.isBranch()).thenReturn(false);
    underTest.execute(new TestComputationStepContext());
    verify(analysisMetadataHolder).isBranch();
    assertThat(periodsHolder.hasPeriod()).isFalse();
    verifyNoMoreInteractions(analysisMetadataHolder);
}
Also used : TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 89 with TestComputationStepContext

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

the class LoadPeriodsStepTest method load_reference_branch_without_fork_date_in_report.

@Test
public void load_reference_branch_without_fork_date_in_report() {
    ComponentDto branch = dbTester.components().insertProjectBranch(project);
    setupRoot(branch);
    setProjectPeriod(project.uuid(), NewCodePeriodType.REFERENCE_BRANCH, "master");
    underTest.execute(new TestComputationStepContext());
    assertPeriod(NewCodePeriodType.REFERENCE_BRANCH, "master", null);
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 90 with TestComputationStepContext

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

the class LoadQualityProfilesStepTest method ignore_rules_with_status_REMOVED.

@Test
public void ignore_rules_with_status_REMOVED() {
    ruleRepository.add(new DumbRule(XOO_X1).setStatus(RuleStatus.REMOVED));
    ScannerReport.ActiveRule.Builder batch1 = ScannerReport.ActiveRule.newBuilder().setRuleRepository(XOO_X1.repository()).setRuleKey(XOO_X1.rule()).setSeverity(Constants.Severity.BLOCKER);
    batchReportReader.putActiveRules(asList(batch1.build()));
    underTest.execute(new TestComputationStepContext());
    assertThat(activeRulesHolder.getAll()).isEmpty();
}
Also used : DumbRule(org.sonar.ce.task.projectanalysis.issue.DumbRule) ActiveRule(org.sonar.ce.task.projectanalysis.qualityprofile.ActiveRule) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

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