private void testLinkIssuesImpl(@Nullable Comment commentInput) {
if (!doesJiraSupportRestIssueLinking()) {
return;
}
final IssueRestClient issueClient = client.getIssueClient();
final Issue originalIssue = issueClient.getIssue("TST-7", pm);
int origNumComments = Iterables.size(originalIssue.getComments());
assertFalse(originalIssue.getIssueLinks().iterator().hasNext());
issueClient.linkIssue(new LinkIssuesInput("TST-7", "TST-6", "Duplicate", commentInput), pm);
final Issue linkedIssue = issueClient.getIssue("TST-7", pm);
assertEquals(1, Iterables.size(linkedIssue.getIssueLinks()));
final IssueLink addedLink = linkedIssue.getIssueLinks().iterator().next();
assertEquals("Duplicate", addedLink.getIssueLinkType().getName());
assertEquals("TST-6", addedLink.getTargetIssueKey());
assertEquals(IssueLinkType.Direction.OUTBOUND, addedLink.getIssueLinkType().getDirection());
final int expectedNumComments = commentInput != null ? origNumComments + 1 : origNumComments;
assertEquals(expectedNumComments, Iterables.size(linkedIssue.getComments()));
if (commentInput != null) {
final Comment comment = linkedIssue.getComments().iterator().next();
assertEquals(commentInput.getBody(), comment.getBody());
assertEquals(USER_ADMIN, comment.getAuthor());
assertEquals(commentInput.getVisibility(), comment.getVisibility());
} else {
assertFalse(linkedIssue.getComments().iterator().hasNext());
}
final Issue targetIssue = issueClient.getIssue("TST-6", pm);
final IssueLink targetLink = targetIssue.getIssueLinks().iterator().next();
assertEquals(IssueLinkType.Direction.INBOUND, targetLink.getIssueLinkType().getDirection());
assertEquals("Duplicate", targetLink.getIssueLinkType().getName());
}