use of org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient in project linuxtools by eclipse.
the class TestOSIORestGetUser method testGetUser.
@Test
public void testGetUser() 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");
OSIORestGetUser data = new OSIORestGetUser(client.getClient(), "USER-0001");
String bundleLocation = Activator.getContext().getBundle().getLocation();
int index = bundleLocation.indexOf('/');
String fileName = bundleLocation.substring(index) + "/testjson/user.data";
FileReader in = new FileReader(fileName);
Identity user = data.testParseFromJson(in);
assertEquals("User.org", user.getCompany());
assertEquals("user@user.org", user.getEmail());
assertEquals("User 1", user.getFullName());
assertEquals("IDENTITY-0001", user.getIdentityID());
assertEquals("https://www.gravatar.com/avatar/user.jpg", user.getImageURL());
assertEquals("USER-0001", user.getUserID());
assertEquals("user", user.getUsername());
assertEquals("IDENTITY-0001", user.getId());
}
use of org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient in project linuxtools by eclipse.
the class TestOSIORestGetWorkItem method testGetWorkItem.
@Test
public void testGetWorkItem() 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");
OSIORestGetWorkItem data = new OSIORestGetWorkItem(client.getClient(), "WORKITEM-0001");
String bundleLocation = Activator.getContext().getBundle().getLocation();
int index = bundleLocation.indexOf('/');
String fileName = bundleLocation.substring(index) + "/testjson/workitem.data";
FileReader in = new FileReader(fileName);
WorkItem workitem = data.testParseFromJson(in);
assertEquals("WORKITEM-0001", workitem.getId());
assertEquals("00001", workitem.getTitle());
assertEquals("SPACE-0001", workitem.getSpaceId());
assertEquals("1", workitem.getNumber());
}
use of org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient 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.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient 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());
}
use of org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient in project linuxtools by eclipse.
the class OSIOAddLinksAttributeEditor method populateFromAttribute.
private void populateFromAttribute() {
OSIORestClient client;
// $NON-NLS-1$
String spaceId = getTaskAttribute().getOption("space");
try {
client = ((OSIORestConnector) connector).getClient(repository);
linkTypes = client.getSpaceLinkTypes(spaceId, repository);
workitems = client.getSpaceWorkItems(spaceId);
} catch (CoreException e) {
// do nothing
}
typeCombo.setItems(linkTypes.keySet().toArray(new String[0]));
typeCombo.add("", 0);
String link = getTaskAttribute().getValue();
int index = 0;
if (link != null && !link.isEmpty()) {
int i = 1;
for (String linkType : linkTypes.keySet()) {
if (link.startsWith(linkType)) {
index = i;
}
++i;
}
}
if (index >= 0) {
typeCombo.select(index);
}
ArrayList<String> workitemsList = new ArrayList<>();
String sourceName = getModel().getTaskData().getRoot().getMappedAttribute(OSIORestTaskSchema.getDefault().SUMMARY.getKey()).getValue();
for (String workitemName : workitems.keySet()) {
if (!workitemName.equals(sourceName)) {
workitemsList.add(workitemName);
}
}
workitemCombo.setItems(workitemsList.toArray(new String[0]));
index = -1;
if (link != null && !link.isEmpty()) {
int i = 0;
for (String workitem : workitems.keySet()) {
if (link.endsWith(workitem)) {
index = i;
}
++i;
}
}
if (index >= 0) {
workitemCombo.select(index);
}
}
Aggregations