Search in sources :

Example 11 with RepositoryLocation

use of org.eclipse.mylyn.commons.repositories.core.RepositoryLocation 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());
}
Also used : TaskAttribute(org.eclipse.mylyn.tasks.core.data.TaskAttribute) TestData(org.eclipse.linuxtools.mylyn.osio.rest.test.support.TestData) OSIORestPostNewTask(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestPostNewTask) 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) NullOperationMonitor(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.NullOperationMonitor) Test(org.junit.Test)

Example 12 with RepositoryLocation

use of org.eclipse.mylyn.commons.repositories.core.RepositoryLocation in project linuxtools by eclipse.

the class OSIORestClient method validate.

public boolean validate(IOperationMonitor monitor) throws OSIORestException {
    RepositoryLocation location = getClient().getLocation();
    if (location.getProperty(IOSIORestConstants.REPOSITORY_AUTH_TOKEN) != null) {
        // UserCredentials credentials = location.getCredentials(AuthenticationType.REPOSITORY);
        // Preconditions.checkState(credentials != null, "Authentication requested without valid credentials");
        String userName = location.getProperty(IOSIORestConstants.REPOSITORY_AUTH_ID);
        Identity response = restRequestProvider.getAuthUser(monitor, client);
        if (response.getUsername().equals(userName)) {
            return true;
        }
    }
    return false;
}
Also used : Identity(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Identity) RepositoryLocation(org.eclipse.mylyn.commons.repositories.core.RepositoryLocation)

Example 13 with RepositoryLocation

use of org.eclipse.mylyn.commons.repositories.core.RepositoryLocation in project linuxtools by eclipse.

the class TestOSIORestClient method testGetConfiguration.

@Test
public void testGetConfiguration() throws Exception {
    TestData testData = new TestData();
    TestUtils.initSpaces(requestProvider, testData);
    requestProvider.addGetRequest("/namedspaces/user", testData.spaces);
    OSIORestClient client = connector.getClient(repository, requestProvider);
    RepositoryLocation location = client.getClient().getLocation();
    location.setProperty(IOSIORestConstants.REPOSITORY_AUTH_ID, "user");
    location.setProperty(IOSIORestConstants.REPOSITORY_AUTH_TOKEN, "xxxxxxTokenxxxxxx");
    OSIORestConfiguration configuration = client.getConfiguration(repository, new NullOperationMonitor());
    Map<String, Space> spaces = configuration.getSpaces();
    assertEquals(spaces.size(), 2);
    assertTrue(spaces.containsKey("mywork"));
    assertTrue(spaces.containsKey("mywork2"));
}
Also used : Space(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space) 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) RepositoryLocation(org.eclipse.mylyn.commons.repositories.core.RepositoryLocation) NullOperationMonitor(org.eclipse.mylyn.internal.commons.core.operations.NullOperationMonitor) Test(org.junit.Test)

Example 14 with RepositoryLocation

use of org.eclipse.mylyn.commons.repositories.core.RepositoryLocation in project linuxtools by eclipse.

the class TestOSIORestClient method testGetSpaceLinkTypes.

@Test
public void testGetSpaceLinkTypes() throws Exception {
    TestData testData = new TestData();
    TestUtils.initSpaces(requestProvider, testData);
    requestProvider.addGetRequest("/namedspaces/user", testData.spaces);
    OSIORestClient client = connector.getClient(repository, requestProvider);
    RepositoryLocation location = client.getClient().getLocation();
    location.setProperty(IOSIORestConstants.REPOSITORY_AUTH_ID, "user");
    location.setProperty(IOSIORestConstants.REPOSITORY_AUTH_TOKEN, "xxxxxxTokenxxxxxx");
    OSIORestConfiguration configuration = client.getConfiguration(repository, new NullOperationMonitor());
    configuration.getSpaces();
    Map<String, String> linktypes = client.getSpaceLinkTypes("SPACE-0001", repository);
    assertTrue(linktypes != null);
    assertTrue(!linktypes.isEmpty());
    assertEquals(linktypes.get("blocks"), "LINKTYPE-0001");
    assertEquals(linktypes.get("is blocked by"), "LINKTYPE-0001");
}
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) RepositoryLocation(org.eclipse.mylyn.commons.repositories.core.RepositoryLocation) NullOperationMonitor(org.eclipse.mylyn.internal.commons.core.operations.NullOperationMonitor) Test(org.junit.Test)

Example 15 with RepositoryLocation

use of org.eclipse.mylyn.commons.repositories.core.RepositoryLocation 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);
}
Also used : Space(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space) IStatus(org.eclipse.core.runtime.IStatus) TestData(org.eclipse.linuxtools.mylyn.osio.rest.test.support.TestData) OSIORestConfiguration(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestConfiguration) ArrayList(java.util.ArrayList) AbstractTaskDataHandler(org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler) RepositoryLocation(org.eclipse.mylyn.commons.repositories.core.RepositoryLocation) TaskData(org.eclipse.mylyn.tasks.core.data.TaskData) IRepositoryQuery(org.eclipse.mylyn.tasks.core.IRepositoryQuery) OSIORestClient(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient) TaskAttributeMapper(org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper) NullOperationMonitor(org.eclipse.mylyn.internal.commons.core.operations.NullOperationMonitor) Test(org.junit.Test)

Aggregations

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