Search in sources :

Example 31 with Branch

use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.

the class QualityGateEventsStepTest method no_alert_on_pull_request_branches.

@Test
public void no_alert_on_pull_request_branches() {
    Branch pr = mock(Branch.class);
    when(pr.getType()).thenReturn(BranchType.PULL_REQUEST);
    analysisMetadataHolder.setBranch(pr);
    TreeRootHolder treeRootHolder = mock(TreeRootHolder.class);
    MetricRepository metricRepository = mock(MetricRepository.class);
    MeasureRepository measureRepository = mock(MeasureRepository.class);
    EventRepository eventRepository = mock(EventRepository.class);
    NotificationService notificationService = mock(NotificationService.class);
    QualityGateEventsStep underTest = new QualityGateEventsStep(treeRootHolder, metricRepository, measureRepository, eventRepository, notificationService, analysisMetadataHolder);
    underTest.execute(new TestComputationStepContext());
    verifyZeroInteractions(treeRootHolder, metricRepository, measureRepository, eventRepository, notificationService);
}
Also used : MeasureRepository(org.sonar.ce.task.projectanalysis.measure.MeasureRepository) MetricRepository(org.sonar.ce.task.projectanalysis.metric.MetricRepository) Branch(org.sonar.ce.task.projectanalysis.analysis.Branch) EventRepository(org.sonar.ce.task.projectanalysis.event.EventRepository) NotificationService(org.sonar.server.notification.NotificationService) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) TreeRootHolder(org.sonar.ce.task.projectanalysis.component.TreeRootHolder) Test(org.junit.Test)

Example 32 with Branch

use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.

the class ValidateProjectStepTest method setBranch.

private void setBranch(BranchType type, @Nullable String mergeBranchUuid) {
    Branch branch = mock(Branch.class);
    when(branch.getType()).thenReturn(type);
    when(branch.getReferenceBranchUuid()).thenReturn(mergeBranchUuid);
    analysisMetadataHolder.setBranch(branch);
}
Also used : Branch(org.sonar.ce.task.projectanalysis.analysis.Branch)

Example 33 with Branch

use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.

the class SendIssueNotificationsStepTest method newPullRequest.

private static Branch newPullRequest() {
    Branch branch = mock(Branch.class);
    when(branch.isMain()).thenReturn(false);
    when(branch.getType()).thenReturn(PULL_REQUEST);
    when(branch.getName()).thenReturn(BRANCH_NAME);
    when(branch.getPullRequestKey()).thenReturn(PULL_REQUEST_ID);
    return branch;
}
Also used : Branch(org.sonar.ce.task.projectanalysis.analysis.Branch)

Example 34 with Branch

use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.

the class SendIssueNotificationsStepTest method newBranch.

private static Branch newBranch(BranchType type) {
    Branch branch = mock(Branch.class);
    when(branch.isMain()).thenReturn(false);
    when(branch.getName()).thenReturn(BRANCH_NAME);
    when(branch.getType()).thenReturn(type);
    return branch;
}
Also used : Branch(org.sonar.ce.task.projectanalysis.analysis.Branch)

Example 35 with Branch

use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.

the class IntegrateIssuesVisitorTest method copy_issues_when_creating_new_non_main_branch.

@Test
public void copy_issues_when_creating_new_non_main_branch() {
    when(mergeBranchComponentsUuids.getComponentUuid(FILE_KEY)).thenReturn(FILE_UUID_ON_BRANCH);
    when(referenceBranchComponentUuids.getReferenceBranchName()).thenReturn("master");
    when(analysisMetadataHolder.isBranch()).thenReturn(true);
    when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(true);
    Branch branch = mock(Branch.class);
    when(branch.isMain()).thenReturn(false);
    when(branch.getType()).thenReturn(BranchType.BRANCH);
    when(analysisMetadataHolder.getBranch()).thenReturn(branch);
    RuleKey ruleKey = RuleTesting.XOO_X1;
    // Issue from main branch has severity major
    addBaseIssueOnBranch(ruleKey);
    // Issue from report has severity blocker
    ScannerReport.Issue reportIssue = ScannerReport.Issue.newBuilder().setMsg("the message").setRuleRepository(ruleKey.repository()).setRuleKey(ruleKey.rule()).setSeverity(Constants.Severity.BLOCKER).build();
    reportReader.putIssues(FILE_REF, singletonList(reportIssue));
    fileSourceRepository.addLine(FILE_REF, "line1");
    underTest.visitAny(FILE);
    List<DefaultIssue> issues = newArrayList(protoIssueCache.traverse());
    assertThat(issues).hasSize(1);
    assertThat(issues.get(0).severity()).isEqualTo(Severity.BLOCKER);
    assertThat(issues.get(0).isNew()).isFalse();
    assertThat(issues.get(0).isCopied()).isTrue();
    assertThat(issues.get(0).changes()).hasSize(1);
    assertThat(issues.get(0).changes().get(0).diffs()).contains(entry(IssueFieldsSetter.FROM_BRANCH, new FieldDiffs.Diff<>("master", null)));
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) Branch(org.sonar.ce.task.projectanalysis.analysis.Branch) ScannerReport(org.sonar.scanner.protocol.output.ScannerReport) DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Aggregations

Branch (org.sonar.ce.task.projectanalysis.analysis.Branch)40 Test (org.junit.Test)21 DefaultIssue (org.sonar.core.issue.DefaultIssue)7 ComponentDto (org.sonar.db.component.ComponentDto)7 Before (org.junit.Before)5 BranchType (org.sonar.db.component.BranchType)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Rule (org.junit.Rule)4 Mockito.mock (org.mockito.Mockito.mock)4 Mockito.when (org.mockito.Mockito.when)4 AnalysisMetadataHolderRule (org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule)4 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)4 DbTester (org.sonar.db.DbTester)4 Project (org.sonar.server.project.Project)4 Date (java.util.Date)3 FieldDiffs (org.sonar.core.issue.FieldDiffs)3 ComponentTesting (org.sonar.db.component.ComponentTesting)3 SnapshotTesting.newAnalysis (org.sonar.db.component.SnapshotTesting.newAnalysis)3 ScannerReport (org.sonar.scanner.protocol.output.ScannerReport)3 RuleKey (org.sonar.api.rule.RuleKey)2