use of org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestPostNewTask in project linuxtools by eclipse.
the class TestOSIORestPostNewTask method testPostNewTask.
@Test
public void testPostNewTask() 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);
TaskAttribute root = taskData.getRoot();
OSIORestTaskSchema taskSchema = OSIORestTaskSchema.getDefault();
TaskAttribute summary = root.getAttribute(taskSchema.SUMMARY.getKey());
summary.setValue("Bug0001");
TaskAttribute description = root.getAttribute(taskSchema.DESCRIPTION.getKey());
description.setValue("This is a bug");
TaskAttribute workitemtype = root.getAttribute(taskSchema.WORKITEM_TYPE.getKey());
workitemtype.setValue("bug");
OSIORestPostNewTask data = new OSIORestPostNewTask(client.getClient(), taskData, testData.spaceMap.get("mywork"), connector, repository);
OSIORestPostNewTask.TaskAttributeTypeAdapter adapter = data.new TaskAttributeTypeAdapter(location);
StringWriter s = new StringWriter();
JsonWriter writer = new JsonWriter(s);
adapter.write(writer, taskData);
assertEquals("{\"data\":{\"attributes\":{\"system.state\":\"new\",\"system.title\":\"Bug0001\",\"version\":\"1\",\"system.description\":\"This is a bug\"},\"relationships\":{\"baseType\":{\"data\":{\"id\":\"WORKITEMTYPE-0001\",\"type\":\"workitemtypes\"}},\"space\":{\"data\":{\"id\":\"SPACE-0001\",\"type\":\"spaces\"}}},\"type\":\"workitems\"},\"included\":[true]}", s.toString());
}
Aggregations