use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.
the class IssueLifecycleTest method mergeIssueFromPRIntoBranch.
@Test
public void mergeIssueFromPRIntoBranch() {
DefaultIssue raw = new DefaultIssue().setKey("raw");
DefaultIssue fromShort = new DefaultIssue().setKey("short").setIsNewCodeReferenceIssue(true);
fromShort.setResolution("resolution");
fromShort.setStatus("status");
Date commentDate = new Date();
fromShort.addComment(new DefaultIssueComment().setIssueKey("short").setCreatedAt(commentDate).setUserUuid("user_uuid").setMarkdownText("A comment"));
Date diffDate = new Date();
// file diff alone
fromShort.addChange(new FieldDiffs().setCreationDate(diffDate).setIssueKey("short").setUserUuid("user_uuid").setDiff("file", "uuidA1", "uuidB1"));
// file diff with another field
fromShort.addChange(new FieldDiffs().setCreationDate(diffDate).setIssueKey("short").setUserUuid("user_uuid").setDiff("severity", "MINOR", "MAJOR").setDiff("file", "uuidA2", "uuidB2"));
Branch branch = mock(Branch.class);
when(branch.getName()).thenReturn("master");
analysisMetadataHolder.setBranch(branch);
underTest.mergeConfirmedOrResolvedFromPrOrBranch(raw, fromShort, BranchType.PULL_REQUEST, "2");
assertThat(raw.resolution()).isEqualTo("resolution");
assertThat(raw.status()).isEqualTo("status");
assertThat(raw.defaultIssueComments()).extracting(DefaultIssueComment::issueKey, DefaultIssueComment::createdAt, DefaultIssueComment::userUuid, DefaultIssueComment::markdownText).containsOnly(tuple("raw", commentDate, "user_uuid", "A comment"));
assertThat(raw.changes()).hasSize(2);
assertThat(raw.changes().get(0).creationDate()).isEqualTo(diffDate);
assertThat(raw.changes().get(0).userUuid()).isEqualTo("user_uuid");
assertThat(raw.changes().get(0).issueKey()).isEqualTo("raw");
assertThat(raw.changes().get(0).diffs()).containsOnlyKeys("severity");
assertThat(raw.changes().get(1).userUuid()).isEqualTo("default_user_uuid");
assertThat(raw.changes().get(1).diffs()).containsOnlyKeys(IssueFieldsSetter.FROM_BRANCH);
assertThat(raw.changes().get(1).get(IssueFieldsSetter.FROM_BRANCH).oldValue()).isEqualTo("#2");
assertThat(raw.changes().get(1).get(IssueFieldsSetter.FROM_BRANCH).newValue()).isEqualTo("master");
assertThat(raw.isNewCodeReferenceIssue()).isTrue();
}
use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.
the class IssueLifecycleTest method copyExistingIssuesFromSourceBranchOfPullRequest_only_works_for_pull_requests.
@Test
public void copyExistingIssuesFromSourceBranchOfPullRequest_only_works_for_pull_requests() {
DefaultIssue raw = new DefaultIssue().setKey("raw");
DefaultIssue from = new DefaultIssue().setKey("short");
from.setResolution("resolution");
from.setStatus("status");
Branch branch = mock(Branch.class);
when(branch.getType()).thenReturn(BranchType.BRANCH);
analysisMetadataHolder.setBranch(branch);
assertThatThrownBy(() -> underTest.copyExistingIssueFromSourceBranchToPullRequest(raw, from)).isInstanceOf(IllegalStateException.class).hasMessage("This operation should be done only on pull request analysis");
}
use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.
the class IssueLifecycleTest method copyExistingIssuesFromSourceBranchOfPullRequest.
@Test
public void copyExistingIssuesFromSourceBranchOfPullRequest() {
String pullRequestKey = "1";
Branch branch = mock(Branch.class);
when(branch.getType()).thenReturn(BranchType.PULL_REQUEST);
when(branch.getName()).thenReturn("sourceBranch-1");
when(branch.getPullRequestKey()).thenReturn(pullRequestKey);
analysisMetadataHolder.setBranch(branch);
analysisMetadataHolder.setPullRequestKey(pullRequestKey);
DefaultIssue raw = new DefaultIssue().setKey("raw");
DefaultIssue fromShort = new DefaultIssue().setKey("short");
fromShort.setResolution("resolution");
fromShort.setStatus("status");
Date commentDate = new Date();
fromShort.addComment(new DefaultIssueComment().setIssueKey("short").setCreatedAt(commentDate).setUserUuid("user_uuid").setMarkdownText("A comment"));
Date diffDate = new Date();
// file diff alone
fromShort.addChange(new FieldDiffs().setCreationDate(diffDate).setIssueKey("short").setUserUuid("user_uuid").setDiff("file", "uuidA1", "uuidB1"));
// file diff with another field
fromShort.addChange(new FieldDiffs().setCreationDate(diffDate).setIssueKey("short").setUserUuid("user_uuid").setDiff("severity", "MINOR", "MAJOR").setDiff("file", "uuidA2", "uuidB2"));
underTest.copyExistingIssueFromSourceBranchToPullRequest(raw, fromShort);
assertThat(raw.resolution()).isEqualTo("resolution");
assertThat(raw.status()).isEqualTo("status");
assertThat(raw.defaultIssueComments()).extracting(DefaultIssueComment::issueKey, DefaultIssueComment::createdAt, DefaultIssueComment::userUuid, DefaultIssueComment::markdownText).containsOnly(tuple("raw", commentDate, "user_uuid", "A comment"));
assertThat(raw.changes()).hasSize(2);
assertThat(raw.changes().get(0).creationDate()).isEqualTo(diffDate);
assertThat(raw.changes().get(0).userUuid()).isEqualTo("user_uuid");
assertThat(raw.changes().get(0).issueKey()).isEqualTo("raw");
assertThat(raw.changes().get(0).diffs()).containsOnlyKeys("severity");
assertThat(raw.changes().get(1).userUuid()).isEqualTo("default_user_uuid");
assertThat(raw.changes().get(1).diffs()).containsOnlyKeys(IssueFieldsSetter.FROM_BRANCH);
assertThat(raw.changes().get(1).get(IssueFieldsSetter.FROM_BRANCH).oldValue()).isEqualTo("sourceBranch-1");
assertThat(raw.changes().get(1).get(IssueFieldsSetter.FROM_BRANCH).newValue()).isEqualTo("#1");
}
use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.
the class IssueLifecycleTest method copiedIssue.
@Test
public void copiedIssue() {
DefaultIssue raw = new DefaultIssue().setNew(true).setKey("RAW_KEY").setCreationDate(parseDate("2015-10-01")).setUpdateDate(parseDate("2015-10-02")).setCloseDate(parseDate("2015-10-03"));
DbIssues.Locations issueLocations = DbIssues.Locations.newBuilder().setTextRange(DbCommons.TextRange.newBuilder().setStartLine(10).setEndLine(12).build()).build();
DefaultIssue base = new DefaultIssue().setKey("BASE_KEY").setCreationDate(parseDate("2015-01-01")).setUpdateDate(parseDate("2015-01-02")).setCloseDate(parseDate("2015-01-03")).setResolution(RESOLUTION_FIXED).setStatus(STATUS_CLOSED).setSeverity(BLOCKER).setAssigneeUuid("base assignee uuid").setAuthorLogin("base author").setTags(newArrayList("base tag")).setOnDisabledRule(true).setSelectedAt(1000L).setLine(10).setMessage("message").setGap(15d).setEffort(Duration.create(15L)).setManualSeverity(false).setLocations(issueLocations);
when(debtCalculator.calculate(raw)).thenReturn(DEFAULT_DURATION);
Branch branch = mock(Branch.class);
when(branch.getName()).thenReturn("release-2.x");
analysisMetadataHolder.setBranch(branch);
underTest.copyExistingOpenIssueFromBranch(raw, base, "master");
assertThat(raw.isNew()).isFalse();
assertThat(raw.isCopied()).isTrue();
assertThat(raw.key()).isNotNull();
assertThat(raw.key()).isNotEqualTo(base.key());
assertThat(raw.creationDate()).isEqualTo(base.creationDate());
assertThat(raw.updateDate()).isEqualTo(base.updateDate());
assertThat(raw.closeDate()).isEqualTo(base.closeDate());
assertThat(raw.resolution()).isEqualTo(RESOLUTION_FIXED);
assertThat(raw.status()).isEqualTo(STATUS_CLOSED);
assertThat(raw.assignee()).isEqualTo("base assignee uuid");
assertThat(raw.authorLogin()).isEqualTo("base author");
assertThat(raw.tags()).containsOnly("base tag");
assertThat(raw.effort()).isEqualTo(DEFAULT_DURATION);
assertThat(raw.isOnDisabledRule()).isTrue();
assertThat(raw.selectedAt()).isEqualTo(1000L);
assertThat(raw.changes().get(0).get(IssueFieldsSetter.FROM_BRANCH).oldValue()).isEqualTo("master");
assertThat(raw.changes().get(0).get(IssueFieldsSetter.FROM_BRANCH).newValue()).isEqualTo("release-2.x");
verifyNoInteractions(updater);
}
use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.
the class IssueTrackingDelegatorTest method delegate_merge_tracker.
@Test
public void delegate_merge_tracker() {
Branch branch = mock(Branch.class);
when(branch.getType()).thenReturn(BranchType.BRANCH);
when(branch.isMain()).thenReturn(false);
when(analysisMetadataHolder.getBranch()).thenReturn(branch);
when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(true);
underTest.track(component, rawInput);
verify(mergeBranchTracker).track(component, rawInput);
verifyNoInteractions(tracker);
verifyNoInteractions(prBranchTracker);
}
Aggregations