Search in sources :

Example 1 with OSIORestClient

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

the class TestOSIORestClient method testValidate.

@Test
public void testValidate() throws Exception {
    OSIORestClient client = connector.getClient(repository, requestProvider);
    RepositoryLocation location = client.getClient().getLocation();
    location.setProperty(IOSIORestConstants.REPOSITORY_AUTH_ID, "user");
    location.setProperty(IOSIORestConstants.REPOSITORY_AUTH_TOKEN, "xxxxxxTokenxxxxxx");
    assertNotNull(client.getClient());
    assertTrue(client.validate(new NullOperationMonitor()));
}
Also used : OSIORestClient(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient) RepositoryLocation(org.eclipse.mylyn.commons.repositories.core.RepositoryLocation) NullOperationMonitor(org.eclipse.mylyn.internal.commons.core.operations.NullOperationMonitor) Test(org.junit.Test)

Example 2 with OSIORestClient

use of org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient 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");
}
Also used : TaskAttribute(org.eclipse.mylyn.tasks.core.data.TaskAttribute) TestData(org.eclipse.linuxtools.mylyn.osio.rest.test.support.TestData) OSIORestClient(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient) TaskMapping(org.eclipse.mylyn.tasks.core.TaskMapping) TaskAttributeMapper(org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper) AbstractTaskDataHandler(org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler) TaskData(org.eclipse.mylyn.tasks.core.data.TaskData) Test(org.junit.Test)

Example 3 with OSIORestClient

use of org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient 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");
}
Also used : TaskAttribute(org.eclipse.mylyn.tasks.core.data.TaskAttribute) TestData(org.eclipse.linuxtools.mylyn.osio.rest.test.support.TestData) AbstractTaskDataHandler(org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler) TaskData(org.eclipse.mylyn.tasks.core.data.TaskData) OSIORestClient(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient) TreeSet(java.util.TreeSet) TaskCommentMapper(org.eclipse.mylyn.tasks.core.data.TaskCommentMapper) TaskAttributeMapper(org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper) NullOperationMonitor(org.eclipse.mylyn.internal.commons.core.operations.NullOperationMonitor) Test(org.junit.Test)

Example 4 with OSIORestClient

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

the class TestOSIORestClient method testGetSpaceWorkItemsById.

@Test
public void testGetSpaceWorkItemsById() throws Exception {
    TestData testData = new TestData();
    TestUtils.initSpaces(requestProvider, testData);
    requestProvider.addGetRequest("/namedspaces/user", testData.spaces);
    OSIORestClient client = connector.getClient(repository, requestProvider);
    RepositoryLocation location = client.getClient().getLocation();
    location.setProperty(IOSIORestConstants.REPOSITORY_AUTH_ID, "user");
    location.setProperty(IOSIORestConstants.REPOSITORY_AUTH_TOKEN, "xxxxxxTokenxxxxxx");
    OSIORestConfiguration configuration = connector.getRepositoryConfiguration(repository);
    configuration.getSpaces();
    Map<String, Space> externSpaces = configuration.getExternalSpaces();
    assertTrue(externSpaces != null);
    assertTrue(externSpaces.isEmpty());
    Space s1 = client.getSpaceById("SPACE-0001", repository);
    assertTrue(s1 != null);
    assertEquals(s1.getName(), "mywork");
    assertEquals(s1.getId(), "SPACE-0001");
    Space s2 = client.getSpaceById("SPACE-0003", repository);
    assertTrue(s2 != null);
    assertEquals(s2.getName(), "mywork");
    assertEquals(s2.getId(), "SPACE-0003");
    externSpaces = configuration.getExternalSpaces();
    assertTrue(externSpaces != null);
    assertEquals(externSpaces.get("SPACE-0003"), s2);
}
Also used : Space(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space) TestData(org.eclipse.linuxtools.mylyn.osio.rest.test.support.TestData) OSIORestClient(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient) OSIORestConfiguration(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestConfiguration) RepositoryLocation(org.eclipse.mylyn.commons.repositories.core.RepositoryLocation) Test(org.junit.Test)

Example 5 with OSIORestClient

use of org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient 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);
}
Also used : TaskAttribute(org.eclipse.mylyn.tasks.core.data.TaskAttribute) IRepositoryPerson(org.eclipse.mylyn.tasks.core.IRepositoryPerson) ArrayList(java.util.ArrayList) AbstractTaskDataHandler(org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler) Date(java.sql.Date) TaskData(org.eclipse.mylyn.tasks.core.data.TaskData) TaskAttributeMetaData(org.eclipse.mylyn.tasks.core.data.TaskAttributeMetaData) OSIORestClient(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient) TaskCommentMapper(org.eclipse.mylyn.tasks.core.data.TaskCommentMapper) OSIORestTaskSchema(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestTaskSchema) TaskAttributeMapper(org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper)

Aggregations

OSIORestClient (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient)25 Test (org.junit.Test)23 TestData (org.eclipse.linuxtools.mylyn.osio.rest.test.support.TestData)21 RepositoryLocation (org.eclipse.mylyn.commons.repositories.core.RepositoryLocation)20 OSIORestConfiguration (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestConfiguration)19 TaskData (org.eclipse.mylyn.tasks.core.data.TaskData)16 NullOperationMonitor (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.NullOperationMonitor)15 AbstractTaskDataHandler (org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler)14 TaskAttributeMapper (org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper)14 TaskAttribute (org.eclipse.mylyn.tasks.core.data.TaskAttribute)13 FileReader (java.io.FileReader)10 JsonWriter (com.google.gson.stream.JsonWriter)5 StringWriter (java.io.StringWriter)5 OSIORestTaskSchema (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestTaskSchema)5 NullOperationMonitor (org.eclipse.mylyn.internal.commons.core.operations.NullOperationMonitor)5 ArrayList (java.util.ArrayList)3 Space (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space)3 TaskCommentMapper (org.eclipse.mylyn.tasks.core.data.TaskCommentMapper)3 LinkedHashSet (java.util.LinkedHashSet)2 Identity (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Identity)2