use of org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper in project linuxtools by eclipse.
the class TestOSIORestClient method testFormSearchURL.
@Test
public void testFormSearchURL() 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 taskData1 = new TaskData(mapper, repository.getConnectorKind(), repository.getRepositoryUrl(), "");
assertTrue(taskDataHandler.initializeTaskData(repository, taskData1, null, null));
taskData1.getRoot().createAttribute(OSIORestTaskSchema.getDefault().SPACE_ID.getKey()).addValue("SPACE-0001");
taskData1.getRoot().createAttribute(OSIORestTaskSchema.getDefault().WORKITEM_TYPE.getKey()).addValue("bug");
TaskData taskData2 = new TaskData(mapper, repository.getConnectorKind(), repository.getRepositoryUrl(), "");
assertTrue(taskDataHandler.initializeTaskData(repository, taskData2, null, null));
taskData2.getRoot().createAttribute(OSIORestTaskSchema.getDefault().SPACE_ID.getKey()).addValue("SPACE-0002");
taskData2.getRoot().createAttribute(OSIORestTaskSchema.getDefault().WORKITEM_TYPE.getKey()).addValue("bug");
List<TaskData> taskList = new ArrayList<>();
taskList.add(taskData1);
taskList.add(taskData2);
String query = "filter[expression]={\"$AND\":[{\"$OR\":[{\"space\":\"SPACE-0001\"},{\"space\":\"SPACE-0002\"}]},{\"$OR\":[{\"workitemtype\":\"WORKITEMTYPE-0001\"}]}]}";
String transformedQuery = URLQueryEncoder.transform(query);
requestProvider.addGetRequest("/search?" + transformedQuery, taskList);
RepositoryLocation location = client.getClient().getLocation();
location.setProperty(IOSIORestConstants.REPOSITORY_AUTH_ID, "user");
location.setProperty(IOSIORestConstants.REPOSITORY_AUTH_TOKEN, "xxxxxxTokenxxxxxx");
location.setUrl("https://api.openshift.io/api");
OSIORestConfiguration configuration = client.getConfiguration(repository, new NullOperationMonitor());
Map<String, Space> spaces = configuration.getSpaces();
TestTaskDataCollector collector = new TestTaskDataCollector();
RepositoryQuery repoQuery = new RepositoryQuery("https://api.openshift.io/api/query?space=mywork&space=mywork2&baseType=bug");
IStatus status = client.performQuery(repository, repoQuery, collector, new NullOperationMonitor());
assertTrue(status.isOK());
List<TaskData> dataList = collector.getTaskData();
assertTrue(dataList != null);
assertEquals(dataList.size(), 2);
assertEquals(dataList.get(0), taskData1);
assertEquals(dataList.get(1), taskData2);
}
use of org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper in project linuxtools by eclipse.
the class TestOSIORestGetTaskCreator method testGetTaskCreator.
@Test
public void testGetTaskCreator() throws Exception {
TestData spaceData = new TestData();
TestUtils.initSpaces(requestProvider, spaceData);
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(spaceData.spaceMap);
connector.setConfiguration(config);
RepositoryLocation location = client.getClient().getLocation();
location.setProperty(IOSIORestConstants.REPOSITORY_AUTH_ID, "user");
location.setProperty(IOSIORestConstants.REPOSITORY_AUTH_TOKEN, "xxxxxxTokenxxxxxx");
taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().CREATOR_ID.getKey()).setValue("USER-0001");
OSIORestGetTaskCreator data = new OSIORestGetTaskCreator(client.getClient(), taskData);
String bundleLocation = Activator.getContext().getBundle().getLocation();
int index = bundleLocation.indexOf('/');
String fileName = bundleLocation.substring(index) + "/testjson/user.data";
FileReader in = new FileReader(fileName);
TaskAttribute attr = data.testParseFromJson(in);
assertEquals(OSIORestTaskSchema.getDefault().CREATOR.getKey(), attr.getId());
assertEquals("User 1", attr.getValue());
}
use of org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper in project linuxtools by eclipse.
the class TestOSIORestGetTaskLabels method testGetTaskLabels.
@Test
public void testGetTaskLabels() 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");
OSIORestGetTaskLabels data = new OSIORestGetTaskLabels(client.getClient(), testData.spaceMap.get("mywork"), taskData);
String bundleLocation = Activator.getContext().getBundle().getLocation();
int index = bundleLocation.indexOf('/');
String fileName = bundleLocation.substring(index) + "/testjson/labels.data";
FileReader in = new FileReader(fileName);
TaskAttribute original = taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().LABELS.getKey());
assertTrue(original == null || original.getValues().isEmpty());
TaskAttribute attribute = data.testParseFromJson(in);
assertEquals(2, attribute.getValues().size());
List<String> values = attribute.getValues();
assertEquals("Label1", values.get(0));
assertEquals("Label2", values.get(1));
}
use of org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper 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());
}
use of org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper in project linuxtools by eclipse.
the class TestOSIORestPostNewLabel method testPostNewLabel.
@Test
public void testPostNewLabel() 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);
OSIORestPostNewLabelTask data = new OSIORestPostNewLabelTask(client.getClient(), testData.spaceMap.get("mywork"), "NewLabel");
OSIORestPostNewLabelTask.TaskAttributeTypeAdapter adapter = data.new TaskAttributeTypeAdapter();
StringWriter s = new StringWriter();
JsonWriter writer = new JsonWriter(s);
adapter.write(writer, "NewLabel");
assertEquals("{\"data\":{\"attributes\":{\"name\":\"NewLabel\",\"background-color\":\"#f9d67a\",\"border-color\":\"#f39d3c\"},\"type\":\"labels\"},\"included\":[]}", s.getBuffer().toString());
}
Aggregations