Search in sources :

Example 21 with OSIORestClient

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());
}
Also used : TestData(org.eclipse.linuxtools.mylyn.osio.rest.test.support.TestData) OSIORestClient(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient) OSIORestConfiguration(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestConfiguration) FileReader(java.io.FileReader) Identity(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Identity) RepositoryLocation(org.eclipse.mylyn.commons.repositories.core.RepositoryLocation) OSIORestGetUser(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestGetUser) NullOperationMonitor(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.NullOperationMonitor) Test(org.junit.Test)

Example 22 with OSIORestClient

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());
}
Also used : TestData(org.eclipse.linuxtools.mylyn.osio.rest.test.support.TestData) OSIORestClient(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient) OSIORestGetWorkItem(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestGetWorkItem) OSIORestConfiguration(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestConfiguration) FileReader(java.io.FileReader) OSIORestGetWorkItem(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestGetWorkItem) WorkItem(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItem) RepositoryLocation(org.eclipse.mylyn.commons.repositories.core.RepositoryLocation) NullOperationMonitor(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.NullOperationMonitor) Test(org.junit.Test)

Example 23 with OSIORestClient

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());
}
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)

Example 24 with OSIORestClient

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());
}
Also used : 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) OSIORestPostNewLabelTask(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestPostNewLabelTask) 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)

Example 25 with OSIORestClient

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);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) OSIORestClient(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient) ArrayList(java.util.ArrayList) LayoutHint(org.eclipse.mylyn.tasks.ui.editors.LayoutHint)

Aggregations

OSIORestClient (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient)25 Test (org.junit.Test)23 TestData (org.eclipse.linuxtools.mylyn.osio.rest.test.support.TestData)21 RepositoryLocation (org.eclipse.mylyn.commons.repositories.core.RepositoryLocation)20 OSIORestConfiguration (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestConfiguration)19 TaskData (org.eclipse.mylyn.tasks.core.data.TaskData)16 NullOperationMonitor (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.NullOperationMonitor)15 AbstractTaskDataHandler (org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler)14 TaskAttributeMapper (org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper)14 TaskAttribute (org.eclipse.mylyn.tasks.core.data.TaskAttribute)13 FileReader (java.io.FileReader)10 JsonWriter (com.google.gson.stream.JsonWriter)5 StringWriter (java.io.StringWriter)5 OSIORestTaskSchema (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestTaskSchema)5 NullOperationMonitor (org.eclipse.mylyn.internal.commons.core.operations.NullOperationMonitor)5 ArrayList (java.util.ArrayList)3 Space (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space)3 TaskCommentMapper (org.eclipse.mylyn.tasks.core.data.TaskCommentMapper)3 LinkedHashSet (java.util.LinkedHashSet)2 Identity (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Identity)2