use of org.eclipse.mylyn.tasks.core.data.TaskAttribute in project linuxtools by eclipse.
the class TestOSIORestClient method testinitializeTaskData.
@Test
public void testinitializeTaskData() throws Exception {
final TaskMapping taskMappingInit = new TaskMapping() {
@Override
public String getSummary() {
return "The Summary";
}
@Override
public String getDescription() {
return "The Description";
}
};
TestData testData = new TestData();
TestUtils.initSpaces(requestProvider, testData);
OSIORestClient client = connector.getClient(repository, requestProvider);
AbstractTaskDataHandler taskDataHandler = connector.getTaskDataHandler();
TaskAttributeMapper mapper = taskDataHandler.getAttributeMapper(repository);
TaskData taskData = new TaskData(mapper, repository.getConnectorKind(), repository.getRepositoryUrl(), "");
assertTrue(taskDataHandler.initializeTaskData(repository, taskData, null, null));
TaskAttribute attribute = taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().SUMMARY.getKey());
assertTrue(attribute != null);
assertEquals(attribute.getValue(), "");
taskData = new TaskData(mapper, repository.getConnectorKind(), repository.getRepositoryUrl(), "");
assertTrue(taskDataHandler.initializeTaskData(repository, taskData, taskMappingInit, null));
attribute = taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().SUMMARY.getKey());
assertEquals(attribute.getValue(), "The Summary");
attribute = taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().DESCRIPTION.getKey());
assertEquals(attribute.getValue(), "The Description");
}
use of org.eclipse.mylyn.tasks.core.data.TaskAttribute in project linuxtools by eclipse.
the class TestOSIORestClient method testGetTaskData.
@Test
public void testGetTaskData() throws Exception {
TestData testData = new TestData();
TestUtils.initSpaces(requestProvider, testData);
requestProvider.addGetRequest("/namedspaces/user", testData.spaces);
OSIORestClient client = connector.getClient(repository, requestProvider);
AbstractTaskDataHandler taskDataHandler = connector.getTaskDataHandler();
TaskAttributeMapper mapper = taskDataHandler.getAttributeMapper(repository);
TaskData taskData = new TaskData(mapper, repository.getConnectorKind(), repository.getRepositoryUrl(), "");
TaskData task1 = new TaskData(mapper, repository.getConnectorKind(), repository.getRepositoryUrl(), "");
TaskData task2 = new TaskData(mapper, repository.getConnectorKind(), repository.getRepositoryUrl(), "");
initWorkItems(task1, task2);
client.getConfiguration(repository, new NullOperationMonitor());
requestProvider.addGetRequest("/workitems/WORKITEM-0001", task1);
requestProvider.addRelocation("/namedspaces/user/mywork/workitems/1", "/spaces/SPACE-0001/workitem/WORKITEM-0001");
requestProvider.addGetRequest("/workitems/WORKITEM-0002", task2);
requestProvider.addRelocation("/namedspaces/user3/mywork/workitems/1", "/spaces/SPACE-0003/workitem/WORKITEM-0002");
TestTaskDataCollector collector = new TestTaskDataCollector();
Set<String> taskIds = new TreeSet<>();
taskIds.add("user/mywork#1");
taskIds.add("user3/mywork#1");
client.getTaskData(taskIds, repository, collector, new NullOperationMonitor());
List<TaskData> results = collector.getTaskData();
assertTrue(results != null);
assertEquals(2, results.size());
TaskData data = results.get(0);
assertEquals(data, task1);
TaskAttribute comment0 = data.getRoot().getAttribute(TaskAttribute.PREFIX_COMMENT + "0");
assertTrue(comment0 != null);
TaskCommentMapper commentMapper = TaskCommentMapper.createFrom(comment0);
assertEquals(commentMapper.getText(), "This is comment 1");
TaskAttribute comment1 = data.getRoot().getAttribute(TaskAttribute.PREFIX_COMMENT + "1");
assertTrue(comment1 != null);
commentMapper = TaskCommentMapper.createFrom(comment1);
assertEquals(commentMapper.getText(), "This is comment 2");
data = results.get(1);
assertEquals(data, task2);
comment0 = data.getRoot().getAttribute(TaskAttribute.PREFIX_COMMENT + "0");
assertTrue(comment0 != null);
commentMapper = TaskCommentMapper.createFrom(comment0);
assertEquals(commentMapper.getText(), "This is first comment");
}
use of org.eclipse.mylyn.tasks.core.data.TaskAttribute in project linuxtools by eclipse.
the class TestOSIORestClient method initWorkItems.
@SuppressWarnings("deprecation")
private void initWorkItems(TaskData task1, TaskData task2) throws Exception {
OSIORestClient client = connector.getClient(repository, requestProvider);
AbstractTaskDataHandler taskDataHandler = connector.getTaskDataHandler();
TaskAttributeMapper mapper = taskDataHandler.getAttributeMapper(repository);
TaskData taskData = task1;
OSIORestTaskSchema.getDefault().initialize(taskData);
taskDataHandler.initializeTaskData(repository, taskData, null, null);
OSIORestTaskSchema schema = OSIORestTaskSchema.getDefault();
TaskAttribute root = taskData.getRoot();
root.createAttribute(schema.UUID.getKey()).addValue("WORKITEM-0001");
root.createAttribute(schema.SPACE.getKey()).addValue("mywork");
root.createAttribute(schema.SPACE_ID.getKey()).addValue("SPACE-0001");
root.createAttribute(schema.AREA.getKey()).addValue("otherarea");
root.createAttribute(schema.ITERATION.getKey()).addValue("mywork");
root.createAttribute(schema.DESCRIPTION.getKey()).addValue("This is Bug 1");
root.createAttribute(schema.NUMBER.getKey()).addValue("1");
root.createAttribute(schema.ORDER.getKey()).addValue("1000");
root.createAttribute(schema.STATUS.getKey()).addValue("in progress");
root.createAttribute(schema.SUMMARY.getKey()).addValue("Bug 0001");
root.createAttribute(schema.TASK_URL.getKey()).addValue("https://api.openshift.io/api/workitems/WORKITEM-0001");
root.createAttribute(schema.WORKITEM_TYPE.getKey()).addValue("bug");
root.createAttribute(schema.ID.getKey()).addValue("user/mywork#1");
root.createAttribute(schema.ASSIGNEE_IDS.getKey()).addValue("USER-0001");
root.createAttribute(schema.CREATOR_ID.getKey()).addValue("USER-0001");
TaskAttribute attribute = taskData.getRoot().createAttribute(TaskAttribute.PREFIX_COMMENT + "0");
TaskAttribute numComments = taskData.getRoot().createAttribute(OSIORestTaskSchema.getDefault().COMMENT_COUNT.getKey());
numComments.setValue("1");
TaskCommentMapper taskComment = TaskCommentMapper.createFrom(attribute);
taskComment.setCommentId("COMMENT-0001");
taskComment.setNumber(1);
taskComment.setUrl("https://api.openshift.io/api/workitems/comments/COMMENT-0001");
// $NON-NLS-1$
String email = "user@user.org";
// $NON-NLS-1$
String fullName = "User 1";
IRepositoryPerson author = taskData.getAttributeMapper().getTaskRepository().createPerson(// $NON-NLS-1$
email);
author.setName(fullName);
taskComment.setAuthor(author);
taskComment.setIsPrivate(null);
taskComment.setCreationDate(new Date(2017, 01, 01));
taskComment.setText("This is comment 1");
taskComment.applyTo(attribute);
TaskAttribute attribute2 = taskData.getRoot().createAttribute(TaskAttribute.PREFIX_COMMENT + "1");
taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().COMMENT_COUNT.getKey());
numComments.setValue("2");
taskComment = TaskCommentMapper.createFrom(attribute2);
taskComment.setCommentId("COMMENT-0002");
taskComment.setNumber(2);
taskComment.setUrl("https://api.openshift.io/api/workitems/comments/COMMENT-0002");
// $NON-NLS-1$
email = "user2@user.org";
// $NON-NLS-1$
fullName = "User 2";
author = taskData.getAttributeMapper().getTaskRepository().createPerson(// $NON-NLS-1$
email);
author.setName(fullName);
taskComment.setAuthor(author);
taskComment.setIsPrivate(null);
taskComment.setCreationDate(new Date(2017, 01, 02));
taskComment.setText("This is comment 2");
taskComment.applyTo(attribute2);
List<TaskAttribute> comments = new ArrayList<>();
comments.add(attribute);
comments.add(attribute2);
requestProvider.addGetRequest("/workitems/WORKITEM-0001/comments", comments);
TaskAttribute attribute5 = taskData.getRoot().createAttribute(OSIORestTaskSchema.getDefault().LABELS.getKey());
attribute5.addValue("LabelA");
attribute5.addValue("LabelB");
requestProvider.addGetRequest("/workitems/WORKITEM-0001/labels", attribute5);
TaskAttribute attribute6 = taskData.getRoot().createAttribute(OSIORestTaskSchema.getDefault().LINKS.getKey());
attribute6.addValue("blocks Bug 3 [user/mywork#3]");
requestProvider.addGetRequest("/workitems/WORKITEM-0001/relationships/links", attribute6);
TaskAttribute creator = taskData.getRoot().createAttribute(OSIORestTaskSchema.getDefault().CREATOR.getKey());
TaskAttributeMetaData creatorMeta = creator.getMetaData();
creator.setValue("User 1");
creatorMeta.putValue("email", "user@user.org");
creatorMeta.putValue("username", "user");
creatorMeta.putValue("id", "USER-0001");
requestProvider.addGetRequest("/users/USER-0001", creator);
TaskData taskData2 = task2;
OSIORestTaskSchema.getDefault().initialize(taskData2);
taskDataHandler.initializeTaskData(repository, taskData2, null, null);
root = taskData2.getRoot();
root.createAttribute(schema.UUID.getKey()).addValue("WORKITEM-0002");
root.createAttribute(schema.SPACE.getKey()).addValue("mywork");
root.createAttribute(schema.SPACE_ID.getKey()).addValue("SPACE-0003");
root.createAttribute(schema.AREA.getKey()).addValue("mywork");
root.createAttribute(schema.ITERATION.getKey()).addValue("mywork");
root.createAttribute(schema.DESCRIPTION.getKey()).addValue("This is Feature 1");
root.createAttribute(schema.NUMBER.getKey()).addValue("1");
root.createAttribute(schema.ORDER.getKey()).addValue("1010");
root.createAttribute(schema.STATUS.getKey()).addValue("open");
root.createAttribute(schema.SUMMARY.getKey()).addValue("Feature 0001");
root.createAttribute(schema.TASK_URL.getKey()).addValue("https://api.openshift.io/api/workitems/WORKITEM-0002");
root.createAttribute(schema.WORKITEM_TYPE.getKey()).addValue("bug");
root.createAttribute(schema.ID.getKey()).addValue("user3/mywork#1");
root.createAttribute(schema.ASSIGNEE_IDS.getKey()).addValue("USER-0001");
root.createAttribute(schema.CREATOR_ID.getKey()).addValue("USER-0003");
TaskAttribute attribute3 = taskData.getRoot().createAttribute(TaskAttribute.PREFIX_COMMENT + "0");
TaskAttribute numComments3 = taskData.getRoot().createAttribute(OSIORestTaskSchema.getDefault().COMMENT_COUNT.getKey());
numComments.setValue("1");
taskComment = TaskCommentMapper.createFrom(attribute);
taskComment.setCommentId("COMMENT-0003");
taskComment.setNumber(1);
taskComment.setUrl("https://api.openshift.io/api/workitems/comments/COMMENT-0003");
// $NON-NLS-1$
String email3 = "user@user.org";
// $NON-NLS-1$
String fullName3 = "User 1";
IRepositoryPerson author3 = taskData.getAttributeMapper().getTaskRepository().createPerson(// $NON-NLS-1$
email3);
author3.setName(fullName3);
taskComment.setAuthor(author3);
taskComment.setIsPrivate(null);
taskComment.setCreationDate(new Date(2017, 01, 01));
taskComment.setText("This is first comment");
taskComment.applyTo(attribute3);
List<TaskAttribute> comments2 = new ArrayList<>();
comments2.add(attribute3);
requestProvider.addGetRequest("/workitems/WORKITEM-0002/comments", comments2);
TaskAttribute attribute4 = taskData.getRoot().createAttribute(OSIORestTaskSchema.getDefault().LABELS.getKey());
attribute4.addValue("Label1");
attribute4.addValue("Label2");
requestProvider.addGetRequest("/workitems/WORKITEM-0002/labels", attribute4);
TaskAttribute attribute7 = taskData.getRoot().createAttribute(OSIORestTaskSchema.getDefault().LINKS.getKey());
attribute7.clearValues();
requestProvider.addGetRequest("/workitems/WORKITEM-0002/relationships/links", attribute7);
TaskAttribute creator2 = taskData.getRoot().createAttribute(OSIORestTaskSchema.getDefault().CREATOR.getKey());
TaskAttributeMetaData creatorMeta2 = creator.getMetaData();
creator2.setValue("User 3");
creatorMeta2.putValue("email", "user3@user.org");
creatorMeta2.putValue("username", "user3");
creatorMeta2.putValue("id", "USER-0003");
requestProvider.addGetRequest("/users/USER-0003", creator2);
}
use of org.eclipse.mylyn.tasks.core.data.TaskAttribute in project linuxtools by eclipse.
the class TestOSIORestGetSingleTask method testGetSingleTask.
@Test
public void testGetSingleTask() throws Exception {
TestData testData = new TestData();
TestUtils.initSpaces(requestProvider, testData);
OSIORestClient client = connector.getClient(repository, requestProvider);
OSIORestConfiguration config = client.getConfiguration(repository, new NullOperationMonitor());
config.setSpaces(testData.spaceMap);
connector.setConfiguration(config);
RepositoryLocation location = client.getClient().getLocation();
location.setProperty(IOSIORestConstants.REPOSITORY_AUTH_ID, "user");
location.setProperty(IOSIORestConstants.REPOSITORY_AUTH_TOKEN, "xxxxxxTokenxxxxxx");
OSIORestGetSingleTaskData data = new OSIORestGetSingleTaskData(client.getClient(), connector, "/workitems/WORKITEM-0001", repository);
String bundleLocation = Activator.getContext().getBundle().getLocation();
int index = bundleLocation.indexOf('/');
String fileName = bundleLocation.substring(index) + "/testjson/workitem.data";
FileReader in = new FileReader(fileName);
TaskData taskData = data.testParseFromJson(in);
TaskAttribute root = taskData.getRoot();
OSIORestTaskSchema schema = OSIORestTaskSchema.getDefault();
TaskAttribute space = root.getAttribute(schema.SPACE.getKey());
assertEquals("mywork", space.getValue());
TaskAttribute spaceid = root.getAttribute(schema.SPACE_ID.getKey());
assertEquals("SPACE-0001", spaceid.getValue());
TaskAttribute uuid = root.getAttribute(schema.UUID.getKey());
assertEquals("WORKITEM-0001", uuid.getValue());
TaskAttribute labelsLink = root.getAttribute(schema.LABELS_LINK.getKey());
assertEquals("https://openshift.io/api/workitems/WORKITEM-0001/labels", labelsLink.getValue());
TaskAttribute creatorId = root.getAttribute(schema.CREATOR_ID.getKey());
assertEquals("USER-0001", creatorId.getValue());
TaskAttribute taskUrl = root.getAttribute(schema.TASK_URL.getKey());
assertEquals("https://openshift.io/api/workitems/WORKITEM-0001", taskUrl.getValue());
TaskAttribute assigneeIds = root.getAttribute(schema.ASSIGNEE_IDS.getKey());
assertEquals("USER-0001", assigneeIds.getValue());
TaskAttribute id = root.getAttribute(schema.ID.getKey());
assertEquals("user/mywork#1", id.getValue());
TaskAttribute status = root.getAttribute(schema.STATUS.getKey());
assertEquals("resolved", status.getValue());
TaskAttribute title = root.getAttribute(schema.SUMMARY.getKey());
assertEquals("00001", title.getValue());
TaskAttribute description = root.getAttribute(schema.DESCRIPTION.getKey());
assertEquals("Test bug", description.getValue());
TaskAttribute version = root.getAttribute(schema.VERSION.getKey());
assertEquals("11", version.getValue());
TaskAttribute order = root.getAttribute(schema.ORDER.getKey());
assertEquals("1000", order.getValue());
TaskAttribute created_at = root.getAttribute(schema.DATE_CREATION.getKey());
assertEquals(getDate("2017-08-14T21:37:15.863435Z"), created_at.getValue());
TaskAttribute updated_at = root.getAttribute(schema.DATE_MODIFICATION.getKey());
assertEquals(getDate("2017-09-15T15:54:43.08915Z"), updated_at.getValue());
}
use of org.eclipse.mylyn.tasks.core.data.TaskAttribute in project linuxtools by eclipse.
the class TestOSIORestGetTaskAssignee method testGetTaskAssignee.
@Test
public void testGetTaskAssignee() throws Exception {
TestData testData = new TestData();
TestUtils.initSpaces(requestProvider, testData);
OSIORestClient client = connector.getClient(repository, requestProvider);
AbstractTaskDataHandler taskDataHandler = connector.getTaskDataHandler();
TaskAttributeMapper mapper = taskDataHandler.getAttributeMapper(repository);
TaskData taskData = new TaskData(mapper, repository.getConnectorKind(), repository.getRepositoryUrl(), "");
OSIORestTaskSchema.getDefault().initialize(taskData);
OSIORestConfiguration config = client.getConfiguration(repository, new NullOperationMonitor());
config.setSpaces(testData.spaceMap);
connector.setConfiguration(config);
RepositoryLocation location = client.getClient().getLocation();
location.setProperty(IOSIORestConstants.REPOSITORY_AUTH_ID, "user");
location.setProperty(IOSIORestConstants.REPOSITORY_AUTH_TOKEN, "xxxxxxTokenxxxxxx");
OSIORestGetTaskAssignee data = new OSIORestGetTaskAssignee(client.getClient(), "USER-0001", taskData);
String bundleLocation = Activator.getContext().getBundle().getLocation();
int index = bundleLocation.indexOf('/');
String fileName = bundleLocation.substring(index) + "/testjson/assignee.data";
FileReader in = new FileReader(fileName);
TaskAttribute original = taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().ASSIGNEES.getKey());
assertTrue(original == null || original.getValues().isEmpty());
TaskAttribute attribute = data.testParseFromJson(in);
assertEquals(1, attribute.getValues().size());
assertEquals(1, original.getValues().size());
assertEquals("user", original.getValue());
}
Aggregations