Search in sources :

Example 1 with Identity

use of org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Identity in project linuxtools by eclipse.

the class TestOSIORestGetAuthUser method testGetAuthUser.

@Test
public void testGetAuthUser() 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");
    OSIORestGetAuthUser data = new OSIORestGetAuthUser(client.getClient());
    String bundleLocation = Activator.getContext().getBundle().getLocation();
    int index = bundleLocation.indexOf('/');
    String fileName = bundleLocation.substring(index) + "/testjson/authuser.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 : OSIORestGetAuthUser(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestGetAuthUser) 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) NullOperationMonitor(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.NullOperationMonitor) Test(org.junit.Test)

Example 2 with Identity

use of org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Identity 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 3 with Identity

use of org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Identity in project linuxtools by eclipse.

the class TestOSIORestClient method setUp.

@SuppressWarnings("deprecation")
@Before
public void setUp() {
    connector = new OSIORestConnector();
    repository = new TaskRepository(connector.getConnectorKind(), "http://openshift.io/api");
    repository.setProperty(IOSIORestConstants.REPOSITORY_AUTH_ID, "user");
    repository.setProperty(IOSIORestConstants.REPOSITORY_AUTH_TOKEN, "xxxxxxTokenxxxxxx");
    requestProvider = new OSIOTestRestRequestProvider();
    requestProvider.addGetRequest("/user", new Identity("user", "user", new Date(2017, 01, 01), new Date(2017, 01, 01), "User", "//image/user", "user", Boolean.TRUE, "user@user.org", "userCo", "", "//users/user", "TestUser"));
}
Also used : OSIOTestRestRequestProvider(org.eclipse.linuxtools.mylyn.osio.rest.test.support.OSIOTestRestRequestProvider) TaskRepository(org.eclipse.mylyn.tasks.core.TaskRepository) OSIORestConnector(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestConnector) Identity(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Identity) Date(java.sql.Date) Before(org.junit.Before)

Example 4 with Identity

use of org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Identity 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)

Aggregations

Identity (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Identity)4 RepositoryLocation (org.eclipse.mylyn.commons.repositories.core.RepositoryLocation)3 FileReader (java.io.FileReader)2 NullOperationMonitor (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.NullOperationMonitor)2 OSIORestClient (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient)2 OSIORestConfiguration (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestConfiguration)2 TestData (org.eclipse.linuxtools.mylyn.osio.rest.test.support.TestData)2 Test (org.junit.Test)2 Date (java.sql.Date)1 OSIORestConnector (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestConnector)1 OSIORestGetAuthUser (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestGetAuthUser)1 OSIORestGetUser (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestGetUser)1 OSIOTestRestRequestProvider (org.eclipse.linuxtools.mylyn.osio.rest.test.support.OSIOTestRestRequestProvider)1 TaskRepository (org.eclipse.mylyn.tasks.core.TaskRepository)1 Before (org.junit.Before)1