@Test
public void testUpdateTaskData() throws Exception{
Issue issue = TestData.issue2;
TaskData taskData = buildEmptyTaskData(issue);
TaskAttribute root = taskData.getRoot();
TaskAttribute attribute = null;
IssueMapper.updateTaskData(repository, taskData, cfg, issue);
assertEquals(issue.getSubject(), root.getAttribute(RedmineAttribute.SUMMARY.getTaskKey()).getValue());
assertEquals(issue.getDescription(), root.getAttribute(RedmineAttribute.DESCRIPTION.getTaskKey()).getValue());
assertEquals(""+issue.getCreatedOn().getTime(), root.getAttribute(RedmineAttribute.DATE_SUBMITTED.getTaskKey()).getValue());
assertEquals(""+issue.getUpdatedOn().getTime(), root.getAttribute(RedmineAttribute.DATE_UPDATED.getTaskKey()).getValue());
assertEquals(""+issue.getTrackerId(), root.getAttribute(RedmineAttribute.TRACKER.getTaskKey()).getValue());
assertEquals(""+issue.getProjectId(), root.getAttribute(RedmineAttribute.PROJECT.getTaskKey()).getValue());
assertEquals(""+issue.getStatusId(), root.getAttribute(RedmineAttribute.STATUS.getTaskKey()).getValue());
assertEquals(""+issue.getStatusId(), root.getAttribute(RedmineAttribute.STATUS_CHG.getTaskKey()).getValue());
assertEquals(""+issue.getPriorityId(), root.getAttribute(RedmineAttribute.PRIORITY.getTaskKey()).getValue());
//TODO watched
assertEquals("[1, 3]", Arrays.toString(root.getAttribute(RedmineAttribute.WATCHERS.getTaskKey()).getValues().toArray(new String[2])));
assertEquals("", root.getAttribute(RedmineAttribute.WATCHERS.getTaskKey()).getAttribute(RedmineAttribute.WATCHERS_ADD.getTaskKey()).getValue());
assertEquals("", root.getAttribute(RedmineAttribute.WATCHERS.getTaskKey()).getAttribute(RedmineAttribute.WATCHERS_REMOVE.getTaskKey()).getValue());
assertEquals(""+issue.getStartDate().getTime(), root.getAttribute(RedmineAttribute.DATE_START.getTaskKey()).getValue());
assertEquals("", root.getAttribute(RedmineAttribute.DATE_DUE.getTaskKey()).getValue());
assertEquals(""+issue.getDoneRatio(), root.getAttribute(RedmineAttribute.PROGRESS.getTaskKey()).getValue());
assertEquals(""+issue.getEstimatedHours(), root.getAttribute(RedmineAttribute.ESTIMATED.getTaskKey()).getValue());
assertEquals(""+issue.getAuthorId(), root.getAttribute(RedmineAttribute.REPORTER.getTaskKey()).getValue());
assertEquals("", root.getAttribute(RedmineAttribute.CATEGORY.getTaskKey()).getValue());
assertEquals(""+issue.getAssignedToId(), root.getAttribute(RedmineAttribute.ASSIGNED_TO.getTaskKey()).getValue());
assertEquals(""+issue.getFixedVersionId(), root.getAttribute(RedmineAttribute.VERSION.getTaskKey()).getValue());
assertEquals(""+issue.getParentId(), root.getAttribute(RedmineAttribute.PARENT.getTaskKey()).getValue());
assertEquals("[3, 4]", Arrays.toString(root.getAttribute(RedmineAttribute.SUBTASKS.getTaskKey()).getValues().toArray()));
//TODO available Status
/* CustomValues */
CustomValue cv = issue.getCustomValues().get(5);
attribute = root.getAttribute(IRedmineConstants.TASK_KEY_PREFIX_ISSUE_CF+cv.getCustomFieldId());
assertNotNull(attribute);
assertEquals("", attribute.getValue());
cv = issue.getCustomValues().get(11);
attribute = root.getAttribute(IRedmineConstants.TASK_KEY_PREFIX_ISSUE_CF+cv.getCustomFieldId());
assertNotNull(attribute);
assertEquals(cv.getValue(), attribute.getValue());
cv = issue.getCustomValues().get(12);
attribute = root.getAttribute(IRedmineConstants.TASK_KEY_PREFIX_ISSUE_CF+cv.getCustomFieldId());
assertNotNull(attribute);
assertEquals(cv.getValue(), attribute.getValue());
cv = issue.getCustomValues().get(13);
attribute = root.getAttribute(IRedmineConstants.TASK_KEY_PREFIX_ISSUE_CF+cv.getCustomFieldId());
assertNotNull(attribute);
assertEquals(""+df.parse(cv.getValue()).getTime(), attribute.getValue());
/* Journals */
/* affected by TaskAttributeMapper, RedmineTaskAttributeMapper */
attribute = root.getAttribute(TaskAttribute.PREFIX_COMMENT + "3");
Journal journal = issue.getJournals().get(3);
assertNotNull(attribute);
assertEquals(""+journal.getId(), attribute.getValue());
assertEquals("1", attribute.getAttribute(TaskAttribute.COMMENT_NUMBER).getValue());
assertEquals(""+journal.getUserId(), attribute.getAttribute(TaskAttribute.COMMENT_AUTHOR).getValue());
assertEquals(""+journal.getCreatedOn().getTime(), attribute.getAttribute(TaskAttribute.COMMENT_DATE).getValue());
assertEquals(""+journal.getNotes(), attribute.getAttribute(TaskAttribute.COMMENT_TEXT).getValue());
assertEquals(URL + "/issues/" + issue.getId() + "#note-3", attribute.getAttribute(TaskAttribute.COMMENT_URL).getValue());
/* Attachments */
/* affected by TaskAttributeMapper, RedmineTaskAttributeMapper */
attribute = root.getAttribute(TaskAttribute.PREFIX_ATTACHMENT + "10");
Attachment attachment = issue.getAttachments().get(10);
assertNotNull(attribute);
assertEquals(""+attachment.getId(), attribute.getValue());
assertEquals(""+attachment.getAuthorId(), attribute.getAttribute(TaskAttribute.ATTACHMENT_AUTHOR).getValue());
assertEquals(""+attachment.getCreatedOn().getTime(), attribute.getAttribute(TaskAttribute.ATTACHMENT_DATE).getValue());
assertEquals(attachment.getFilename(), attribute.getAttribute(TaskAttribute.ATTACHMENT_FILENAME).getValue());
assertEquals(""+attachment.getFilesize(), attribute.getAttribute(TaskAttribute.ATTACHMENT_SIZE).getValue());
assertEquals(attachment.getDescription(), attribute.getAttribute(TaskAttribute.ATTACHMENT_DESCRIPTION).getValue());
assertEquals(URL + "/attachments/download/10", attribute.getAttribute(TaskAttribute.ATTACHMENT_URL).getValue());
/* IssueRelations */
/* TimeEntries + sum*/
/* affected by TaskAttributeMapper, RedmineTaskAttributeMapper, TaskTimeEntryMapper */
// assertEquals(""+issue.getTimeEntries().getSum(), root.getAttribute(IRedmineConstants.TASK_ATTRIBUTE_TIMEENTRY_TOTAL).getValue());
assertEquals("4.25", root.getAttribute(IRedmineConstants.TASK_ATTRIBUTE_TIMEENTRY_TOTAL).getValue());
TimeEntry te = issue.getTimeEntries().get(1);
attribute = root.getAttribute(IRedmineConstants.TASK_ATTRIBUTE_TIMEENTRY_PREFIX + te.getId());
assertNotNull(attribute);
assertEquals(""+te.getId(), attribute.getValue());
assertEquals(""+te.getUserId(), attribute.getAttribute(IRedmineConstants.TASK_ATTRIBUTE_TIMEENTRY_AUTHOR).getValue());
assertEquals(""+te.getActivityId(), attribute.getAttribute(IRedmineConstants.TASK_ATTRIBUTE_TIMEENTRY_ACTIVITY).getValue());
assertEquals(""+te.getHours(), attribute.getAttribute(IRedmineConstants.TASK_ATTRIBUTE_TIMEENTRY_HOURS).getValue());
assertEquals(""+te.getComments(), attribute.getAttribute(IRedmineConstants.TASK_ATTRIBUTE_TIMEENTRY_COMMENTS).getValue());
assertEquals(""+te.getSpentOn().getTime(), attribute.getAttribute(IRedmineConstants.TASK_ATTRIBUTE_TIMEENTRY_SPENTON).getValue());
assertEquals("1", attribute.getAttribute(IRedmineConstants.TASK_KEY_PREFIX_TIMEENTRY_CF+"7").getValue());
fail("Not finished yet implemented");
}