Search in sources :

Example 1 with OSIORestGetTaskComments

use of org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestGetTaskComments in project linuxtools by eclipse.

the class TestOSIORestGetTaskComments method testGetTaskComments.

@Test
public void testGetTaskComments() 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");
    OSIORestGetTaskComments data = new OSIORestGetTaskComments(client.getClient(), testData.spaceMap.get("mywork"), taskData);
    String bundleLocation = Activator.getContext().getBundle().getLocation();
    int index = bundleLocation.indexOf('/');
    String fileName = bundleLocation.substring(index) + "/testjson/comments.data";
    FileReader in = new FileReader(fileName);
    TaskAttribute original = taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().ASSIGNEES.getKey());
    assertTrue(original == null || original.getValues().isEmpty());
    ArrayList<TaskAttribute> attributes = data.testParseFromJson(in);
    assertEquals(4, attributes.size());
    TaskAttribute attr1 = attributes.get(0);
    TaskCommentMapper commentMapper = TaskCommentMapper.createFrom(attr1);
    assertEquals("COMMENT-0004", commentMapper.getCommentId());
    assertEquals("This is the fourth comment.", commentMapper.getText());
    assertEquals(getDate("2017-11-21T20:46:47.383745Z"), commentMapper.getCreationDate());
    IRepositoryPerson person = commentMapper.getAuthor();
    assertEquals("User", person.getName());
    assertEquals("user@user.org", person.getPersonId());
    assertEquals(new Integer(4), commentMapper.getNumber());
    TaskAttribute attr2 = attributes.get(1);
    commentMapper = TaskCommentMapper.createFrom(attr2);
    assertEquals("COMMENT-0003", commentMapper.getCommentId());
    assertEquals("This is the third comment.", commentMapper.getText());
    assertEquals(getDate("2017-10-05T23:01:54.15784Z"), commentMapper.getCreationDate());
    IRepositoryPerson person2 = commentMapper.getAuthor();
    assertEquals("User", person2.getName());
    assertEquals("user@user.org", person2.getPersonId());
    assertEquals(new Integer(3), commentMapper.getNumber());
    TaskAttribute attr3 = attributes.get(2);
    commentMapper = TaskCommentMapper.createFrom(attr3);
    assertEquals("COMMENT-0002", commentMapper.getCommentId());
    assertEquals("This is the second comment.", commentMapper.getText());
    assertEquals(getDate("2017-10-05T21:09:19.673546Z"), commentMapper.getCreationDate());
    IRepositoryPerson person3 = commentMapper.getAuthor();
    assertEquals("User", person3.getName());
    assertEquals("user@user.org", person3.getPersonId());
    assertEquals(new Integer(2), commentMapper.getNumber());
    TaskAttribute attr4 = attributes.get(3);
    commentMapper = TaskCommentMapper.createFrom(attr4);
    assertEquals("COMMENT-0001", commentMapper.getCommentId());
    assertEquals("Comment on Task 1.", commentMapper.getText());
    assertEquals(getDate("2017-08-14T21:40:29.434379Z"), commentMapper.getCreationDate());
    IRepositoryPerson person4 = commentMapper.getAuthor();
    assertEquals("User", person4.getName());
    assertEquals("user@user.org", person4.getPersonId());
    assertEquals(new Integer(1), commentMapper.getNumber());
}
Also used : TaskAttribute(org.eclipse.mylyn.tasks.core.data.TaskAttribute) TestData(org.eclipse.linuxtools.mylyn.osio.rest.test.support.TestData) OSIORestConfiguration(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestConfiguration) IRepositoryPerson(org.eclipse.mylyn.tasks.core.IRepositoryPerson) OSIORestGetTaskComments(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestGetTaskComments) AbstractTaskDataHandler(org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler) RepositoryLocation(org.eclipse.mylyn.commons.repositories.core.RepositoryLocation) TaskData(org.eclipse.mylyn.tasks.core.data.TaskData) OSIORestClient(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient) FileReader(java.io.FileReader) TaskCommentMapper(org.eclipse.mylyn.tasks.core.data.TaskCommentMapper) TaskAttributeMapper(org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper) NullOperationMonitor(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.NullOperationMonitor) Test(org.junit.Test)

Aggregations

FileReader (java.io.FileReader)1 NullOperationMonitor (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.NullOperationMonitor)1 OSIORestClient (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient)1 OSIORestConfiguration (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestConfiguration)1 OSIORestGetTaskComments (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestGetTaskComments)1 TestData (org.eclipse.linuxtools.mylyn.osio.rest.test.support.TestData)1 RepositoryLocation (org.eclipse.mylyn.commons.repositories.core.RepositoryLocation)1 IRepositoryPerson (org.eclipse.mylyn.tasks.core.IRepositoryPerson)1 AbstractTaskDataHandler (org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler)1 TaskAttribute (org.eclipse.mylyn.tasks.core.data.TaskAttribute)1 TaskAttributeMapper (org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper)1 TaskCommentMapper (org.eclipse.mylyn.tasks.core.data.TaskCommentMapper)1 TaskData (org.eclipse.mylyn.tasks.core.data.TaskData)1 Test (org.junit.Test)1