Search in sources :

Example 6 with IStorageService

use of org.eclipse.userstorage.IStorageService in project epp.mpc by eclipse.

the class MarketplaceStorageService method getStorageCredentials.

private Credentials getStorageCredentials() {
    ICredentialsProvider provider = getStorage().getCredentialsProvider();
    if (provider == null) {
        return null;
    }
    IStorageService service = getStorage().getService();
    return provider.hasCredentials(service) ? provider.getCredentials(service) : null;
}
Also used : IStorageService(org.eclipse.userstorage.IStorageService) ICredentialsProvider(org.eclipse.userstorage.spi.ICredentialsProvider)

Example 7 with IStorageService

use of org.eclipse.userstorage.IStorageService in project epp.mpc by eclipse.

the class MarketplaceStorageServiceRegistrationTest method testCleanupDuplicateStorageService.

@Test
public void testCleanupDuplicateStorageService() throws Exception {
    IStorageService withSlash = storageServices.provide("WithSlash", "https://api-test.example.org/");
    IStorageService withoutSlash = storageServices.provide("WithoutSlash", "https://api-test.example.org");
    ((StorageService) withSlash).getSecurePreferences().remove("username");
    ((StorageService) withoutSlash).getSecurePreferences().put("username", "testuser", false);
    IMarketplaceStorageService registered = serviceLocator.registerStorageService(DefaultMarketplaceService.DEFAULT_SERVICE_LOCATION, "https://api-test.example.org", null);
    assertNotNull(registered);
    assertEquals("https://api-test.example.org/", registered.getServiceUri().toString());
    assertSame(withSlash, registered.getStorage().getService());
    withoutSlash = IStorageService.Registry.INSTANCE.getService(URI.create("https://api-test.example.org"));
    assertNull(withoutSlash);
    String username = ((StorageService) withSlash).getSecurePreferences().get("username", null);
    assertEquals("testuser", username);
}
Also used : IStorageService(org.eclipse.userstorage.IStorageService) IMarketplaceStorageService(org.eclipse.epp.mpc.core.service.IMarketplaceStorageService) Test(org.junit.Test)

Example 8 with IStorageService

use of org.eclipse.userstorage.IStorageService in project epp.mpc by eclipse.

the class MarketplaceStorageServiceRegistrationTest method testCleanupDuplicateEclipseOrgStorageService.

@Test
public void testCleanupDuplicateEclipseOrgStorageService() throws Exception {
    IStorageService withSlash = storageServices.provide("WithSlash", "https://api.eclipse.org/");
    assertFalse(withSlash instanceof IStorageService.Dynamic);
    IStorageService withoutSlash = storageServices.provide("WithoutSlash", "https://api.eclipse.org");
    assertTrue(withoutSlash instanceof IStorageService.Dynamic);
    IMarketplaceStorageService registered = serviceLocator.registerStorageService(DefaultMarketplaceService.DEFAULT_SERVICE_LOCATION, "https://api.eclipse.org/", null);
    assertNotNull(registered);
    assertSame(withSlash, registered.getStorage().getService());
    withoutSlash = IStorageService.Registry.INSTANCE.getService(URI.create("https://api.eclipse.org"));
    assertNull(withoutSlash);
}
Also used : IStorageService(org.eclipse.userstorage.IStorageService) Dynamic(org.eclipse.userstorage.IStorageService.Dynamic) IMarketplaceStorageService(org.eclipse.epp.mpc.core.service.IMarketplaceStorageService) Test(org.junit.Test)

Example 9 with IStorageService

use of org.eclipse.userstorage.IStorageService in project epp.mpc by eclipse.

the class MarketplaceStorageServiceRegistrationTest method testRegisterNewStorageServiceWithoutSlash.

@Test
public void testRegisterNewStorageServiceWithoutSlash() {
    IMarketplaceStorageService registered = serviceLocator.registerStorageService(DefaultMarketplaceService.DEFAULT_SERVICE_LOCATION, "https://api-test.example.org", null);
    assertNotNull(registered);
    assertEquals("https://api-test.example.org/", registered.getServiceUri().toString());
    IStorageService withoutSlash = IStorageService.Registry.INSTANCE.getService(URI.create("https://api-test.example.org"));
    assertNull(withoutSlash);
}
Also used : IStorageService(org.eclipse.userstorage.IStorageService) IMarketplaceStorageService(org.eclipse.epp.mpc.core.service.IMarketplaceStorageService) Test(org.junit.Test)

Example 10 with IStorageService

use of org.eclipse.userstorage.IStorageService in project epp.mpc by eclipse.

the class UserFavoritesServiceTest method setUp.

@Before
public void setUp() throws Exception {
    marketplaceStorageService = ServiceHelper.getMarketplaceServiceLocator().getDefaultStorageService();
    assertNotNull(marketplaceStorageService);
    assertEquals(USERSTORAGE_SERVICE_URI, marketplaceStorageService.getServiceUri());
    marketplaceStorageService.getStorage().setCredentialsProvider(new AbstractCredentialsProvider() {

        @Override
        public Credentials provideCredentials(IStorageService service, boolean reauthentication) {
            String marketplaceUser;
            String marketplacePass;
            try {
                marketplaceUser = TestProperties.getTestProperty("mpc.storage.user");
                marketplacePass = TestProperties.getTestProperty("mpc.storage.pass");
            } catch (IOException e) {
                throw new AssertionError("Cannot load test properties", e);
            }
            Assume.assumeNotNull(marketplaceUser, marketplacePass);
            return new Credentials(marketplaceUser, marketplacePass);
        }
    });
    favoritesService = ServiceHelper.getMarketplaceServiceLocator().getDefaultFavoritesService();
    // assertNotNull(favoritesService);
    if (favoritesService == null) {
        ((ServiceLocator) ServiceHelper.getMarketplaceServiceLocator()).registerFavoritesService(DefaultMarketplaceService.DEFAULT_SERVICE_LOCATION, marketplaceStorageService.getServiceUri().toString(), null);
        favoritesService = ServiceHelper.getMarketplaceServiceLocator().getDefaultFavoritesService();
    }
    assertSame(marketplaceStorageService, favoritesService.getStorageService());
}
Also used : ServiceLocator(org.eclipse.epp.internal.mpc.core.ServiceLocator) IStorageService(org.eclipse.userstorage.IStorageService) AbstractCredentialsProvider(org.eclipse.userstorage.spi.AbstractCredentialsProvider) IOException(java.io.IOException) Credentials(org.eclipse.userstorage.spi.Credentials) Before(org.junit.Before)

Aggregations

IStorageService (org.eclipse.userstorage.IStorageService)10 IMarketplaceStorageService (org.eclipse.epp.mpc.core.service.IMarketplaceStorageService)6 Test (org.junit.Test)5 IOException (java.io.IOException)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)1 ServiceLocator (org.eclipse.epp.internal.mpc.core.ServiceLocator)1 ISecurePreferences (org.eclipse.equinox.security.storage.ISecurePreferences)1 StorageException (org.eclipse.equinox.security.storage.StorageException)1 Dynamic (org.eclipse.userstorage.IStorageService.Dynamic)1 StorageService (org.eclipse.userstorage.internal.StorageService)1 AbstractCredentialsProvider (org.eclipse.userstorage.spi.AbstractCredentialsProvider)1 Credentials (org.eclipse.userstorage.spi.Credentials)1 ICredentialsProvider (org.eclipse.userstorage.spi.ICredentialsProvider)1 Before (org.junit.Before)1