Search in sources :

Example 1 with OSIORestPostNewCommentTask

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

the class TestOSIORestPostNewComment method testPostNewComment.

@Test
public void testPostNewComment() 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");
    AbstractTaskDataHandler taskDataHandler = connector.getTaskDataHandler();
    TaskAttributeMapper mapper = taskDataHandler.getAttributeMapper(repository);
    TaskData taskData = new TaskData(mapper, repository.getConnectorKind(), repository.getRepositoryUrl(), "");
    OSIORestTaskSchema.getDefault().initialize(taskData);
    Set<TaskAttribute> attributes = new LinkedHashSet<>();
    TaskAttribute newComment = taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().NEW_COMMENT.getKey());
    newComment.setValue("This is a test comment");
    attributes.add(newComment);
    OSIORestPostNewCommentTask data = new OSIORestPostNewCommentTask(client.getClient(), taskData, attributes);
    OSIORestPostNewCommentTask.TaskAttributeTypeAdapter adapter = data.new TaskAttributeTypeAdapter(location);
    OSIORestPostNewCommentTask.OldAttributes oldAttributes = data.new OldAttributes(attributes);
    StringWriter s = new StringWriter();
    JsonWriter writer = new JsonWriter(s);
    adapter.write(writer, oldAttributes);
    assertEquals("{\"data\":{\"attributes\":{\"body\":\"This is a test comment\",\"markup\":\"Markdown\"},\"type\":\"comments\"},\"included\":[]}", s.getBuffer().toString());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TaskAttribute(org.eclipse.mylyn.tasks.core.data.TaskAttribute) TestData(org.eclipse.linuxtools.mylyn.osio.rest.test.support.TestData) OSIORestPostNewCommentTask(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestPostNewCommentTask) OSIORestConfiguration(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestConfiguration) AbstractTaskDataHandler(org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler) JsonWriter(com.google.gson.stream.JsonWriter) RepositoryLocation(org.eclipse.mylyn.commons.repositories.core.RepositoryLocation) TaskData(org.eclipse.mylyn.tasks.core.data.TaskData) StringWriter(java.io.StringWriter) OSIORestClient(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient) TaskAttributeMapper(org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper) NullOperationMonitor(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.NullOperationMonitor) Test(org.junit.Test)

Aggregations

JsonWriter (com.google.gson.stream.JsonWriter)1 StringWriter (java.io.StringWriter)1 LinkedHashSet (java.util.LinkedHashSet)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 OSIORestPostNewCommentTask (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestPostNewCommentTask)1 TestData (org.eclipse.linuxtools.mylyn.osio.rest.test.support.TestData)1 RepositoryLocation (org.eclipse.mylyn.commons.repositories.core.RepositoryLocation)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 TaskData (org.eclipse.mylyn.tasks.core.data.TaskData)1 Test (org.junit.Test)1