Search in sources :

Example 1 with OSIORestPatchUpdateTask

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

the class TestOSIORestPatchUpdateTask method testPatchUpdateTask.

@Test
public void testPatchUpdateTask() 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);
    OSIORestTaskSchema taskSchema = OSIORestTaskSchema.getDefault();
    TaskAttribute root = taskData.getRoot();
    TaskAttribute description = root.getAttribute(taskSchema.DESCRIPTION.getKey());
    description.setValue("This is a test bug");
    TaskAttribute operation = root.createAttribute(TaskAttribute.OPERATION);
    operation.setValue("in progress");
    TaskAttribute status = root.getAttribute(taskSchema.STATUS.getKey());
    status.setValue("open");
    TaskAttribute uuid = root.getAttribute(taskSchema.UUID.getKey());
    uuid.setValue("WORKITEM-0001");
    TaskAttribute summary = root.getAttribute(taskSchema.SUMMARY.getKey());
    summary.setValue("Bug0001");
    TaskAttribute version = root.getAttribute(taskSchema.VERSION.getKey());
    version.setValue("11");
    TaskAttribute area = root.getAttribute(taskSchema.AREA.getKey());
    area.setValue("mywork");
    TaskAttribute iteration = root.getAttribute(taskSchema.ITERATION.getKey());
    iteration.setValue("mywork");
    TaskAttribute labels = root.getAttribute(taskSchema.LABELS.getKey());
    labels.addValue("label1");
    labels.addValue("label3");
    TaskAttribute addLabels = root.getAttribute(taskSchema.ADD_LABEL.getKey());
    addLabels.addValue("label2");
    TaskAttribute removeLabels = root.getAttribute(taskSchema.REMOVE_LABEL.getKey());
    removeLabels.addValue("label3");
    TaskAttribute assignees = root.getAttribute(taskSchema.ASSIGNEES.getKey());
    assignees.addValue("user3");
    TaskAttribute addAssignees = root.getAttribute(taskSchema.ADD_ASSIGNEE.getKey());
    addAssignees.addValue("user");
    TaskAttribute removeAssignees = root.getAttribute(taskSchema.REMOVE_ASSIGNEE.getKey());
    removeAssignees.addValue("user3");
    OSIORestPatchUpdateTask data = new OSIORestPatchUpdateTask(client.getClient(), taskData, attributes, testData.spaceMap.get("mywork"));
    OSIORestPatchUpdateTask.TaskAttributeTypeAdapter adapter = data.new TaskAttributeTypeAdapter(location);
    OSIORestPatchUpdateTask.OldAttributes oldAttributes = data.new OldAttributes(attributes);
    StringWriter s = new StringWriter();
    JsonWriter writer = new JsonWriter(s);
    adapter.write(writer, oldAttributes);
    assertEquals("{\"data\":{\"attributes\":{\"system.description\":\"This is a test bug\",\"system.state\":\"in progress\",\"system.title\":\"Bug0001\",\"version\":\"11\"}," + "\"id\":\"WORKITEM-0001\",\"relationships\":{\"space\":{\"data\":{\"id\":\"SPACE-0001\",\"type\":\"spaces\"}},\"area\":{\"data\":{\"id\":\"AREA-0001\",\"type\":\"areas\"}}," + "\"iteration\":{\"data\":{\"id\":\"ITERATION-0001\",\"type\":\"iterations\"}},\"assignees\":{\"data\":[{\"id\":\"USER-0001\",\"type\":\"users\"}]}," + "\"labels\":{\"data\":[{\"id\":\"LABEL-0001\",\"type\":\"labels\"},{\"id\":\"LABEL-0002\",\"type\":\"labels\"}]}},\"type\":\"workitems\"},\"included\":[true]}", s.getBuffer().toString());
    StringWriter s2 = new StringWriter();
    JsonWriter writer2 = new JsonWriter(s2);
    root.removeAttribute(TaskAttribute.OPERATION);
    adapter.write(writer2, oldAttributes);
    assertEquals("{\"data\":{\"attributes\":{\"system.description\":\"This is a test bug\",\"system.state\":\"open\",\"system.title\":\"Bug0001\",\"version\":\"11\"}," + "\"id\":\"WORKITEM-0001\",\"relationships\":{\"space\":{\"data\":{\"id\":\"SPACE-0001\",\"type\":\"spaces\"}},\"area\":{\"data\":{\"id\":\"AREA-0001\",\"type\":\"areas\"}}," + "\"iteration\":{\"data\":{\"id\":\"ITERATION-0001\",\"type\":\"iterations\"}},\"assignees\":{\"data\":[{\"id\":\"USER-0001\",\"type\":\"users\"}]}," + "\"labels\":{\"data\":[{\"id\":\"LABEL-0001\",\"type\":\"labels\"},{\"id\":\"LABEL-0002\",\"type\":\"labels\"}]}},\"type\":\"workitems\"},\"included\":[true]}", s2.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) 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) OSIORestTaskSchema(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestTaskSchema) TaskAttributeMapper(org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper) OSIORestPatchUpdateTask(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestPatchUpdateTask) 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 OSIORestPatchUpdateTask (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestPatchUpdateTask)1 OSIORestTaskSchema (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestTaskSchema)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