// Ignore "May produce NPE" warnings, as we know what we are doing in tests
@SuppressWarnings("ConstantConditions")
public class IssueJsonParserTest {
@Test
public void testParseIssue() throws Exception {
final Issue issue = parseIssue("/json/issue/valid-all-expanded.json");
assertEquals("Testing attachem2", issue.getSummary());
assertEquals("TST-2", issue.getKey());
assertEquals("my description", issue.getDescription());
assertEquals(Long.valueOf(10010), issue.getId());
final BasicProject expectedProject = new BasicProject(toUri("http://localhost:8090/jira/rest/api/2/project/TST"), "TST", 10000L, "Test Project");
assertEquals(expectedProject, issue.getProject());
assertEquals("Major", issue.getPriority().getName());
assertNull(issue.getResolution());
assertEquals(toDateTime("2010-07-26T13:29:18.262+0200"), issue.getCreationDate());
assertEquals(toDateTime("2012-12-07T14:52:52.570+01:00"), issue.getUpdateDate());
assertEquals(null, issue.getDueDate());
final IssueType expectedIssueType = new IssueType(toUri("http://localhost:8090/jira/rest/api/2/issuetype/1"), 1L,
"Bug", false, "A problem which impairs or prevents the functions of the product.",
toUri("http://localhost:8090/jira/images/icons/bug.gif"));
assertEquals(expectedIssueType, issue.getIssueType());
assertEquals(TestConstants.USER_ADMIN, issue.getReporter());
assertEquals(TestConstants.USER1, issue.getAssignee());
// issue links
Assert.assertThat(issue.getIssueLinks(), containsInAnyOrder(
new IssueLink("TST-1", toUri("http://localhost:8090/jira/rest/api/2/issue/10000"),
new IssueLinkType("Duplicate", "duplicates", IssueLinkType.Direction.OUTBOUND)),
new IssueLink("TST-1", toUri("http://localhost:8090/jira/rest/api/2/issue/10000"),
new IssueLinkType("Duplicate", "is duplicated by", IssueLinkType.Direction.INBOUND))
));
// watchers
final BasicWatchers watchers = issue.getWatchers();
assertFalse(watchers.isWatching());
assertEquals(toUri("http://localhost:8090/jira/rest/api/2/issue/TST-2/watchers"), watchers.getSelf());
assertEquals(1, watchers.getNumWatchers());
// time tracking
assertEquals(new TimeTracking(0, 0, 145), issue.getTimeTracking());
// attachments
final Iterable<Attachment> attachments = issue.getAttachments();
assertEquals(7, Iterables.size(attachments));
final Attachment attachment = findAttachmentByFileName(attachments, "avatar1.png");
assertEquals(TestConstants.USER_ADMIN_BASIC, attachment.getAuthor());
assertEquals(359345, attachment.getSize());
assertEquals(toUri("http://localhost:8090/jira/secure/thumbnail/10070/_thumb_10070.png"), attachment.getThumbnailUri());
assertEquals(toUri("http://localhost:8090/jira/secure/attachment/10070/avatar1.png"), attachment.getContentUri());
final Iterable<String> attachmentsNames = EntityHelper.toFileNamesList(attachments);
assertThat(attachmentsNames, containsInAnyOrder("10000_thumb_snipe.jpg", "Admal pompa ciepła.pdf",
"apache-tomcat-5.5.30.zip", "avatar1.png", "jira_logo.gif", "snipe.png", "transparent-png.png"));
// worklogs
final Iterable<Worklog> worklogs = issue.getWorklogs();
assertEquals(5, Iterables.size(worklogs));
final Worklog expectedWorklog1 = new Worklog(
toUri("http://localhost:8090/jira/rest/api/2/issue/10010/worklog/10011"),
toUri("http://localhost:8090/jira/rest/api/latest/issue/10010"), TestConstants.USER1_BASIC,
TestConstants.USER1_BASIC, "another piece of work",
toDateTime("2010-08-17T16:38:00.013+02:00"), toDateTime("2010-08-17T16:38:24.948+02:00"),
toDateTime("2010-08-17T16:37:00.000+02:00"), 15, Visibility.role("Developers"));
final Worklog worklog1 = Iterables.get(worklogs, 1);
assertEquals(expectedWorklog1, worklog1);
final Worklog worklog2 = Iterables.get(worklogs, 2);
assertEquals(Visibility.group("jira-users"), worklog2.getVisibility());
final Worklog worklog3 = Iterables.get(worklogs, 3);
assertEquals(StringUtils.EMPTY, worklog3.getComment());
// comments
assertEquals(4, Iterables.size(issue.getComments()));
final Comment comment = issue.getComments().iterator().next();
assertEquals(Visibility.Type.ROLE, comment.getVisibility().getType());
assertEquals(TestConstants.USER_ADMIN_BASIC, comment.getAuthor());
assertEquals(TestConstants.USER_ADMIN_BASIC, comment.getUpdateAuthor());
// components
final Iterable<String> componentsNames = EntityHelper.toNamesList(issue.getComponents());
assertThat(componentsNames, containsInAnyOrder("Component A", "Component B"));
}