use of org.datatransferproject.spi.api.auth.extension.AuthServiceExtension in project data-transfer-project by google.
the class PortabilityAuthServiceProviderRegistry method getAuthDataGenerator.
@Override
public AuthDataGenerator getAuthDataGenerator(String serviceId, String transferDataType, AuthMode mode) {
AuthServiceExtension provider = authServiceProviderMap.get(serviceId);
Preconditions.checkArgument(provider != null, "AuthServiceExtension not found for serviceId [%s]", serviceId);
switch(mode) {
case EXPORT:
Preconditions.checkArgument(supportedExportTypes.contains(transferDataType), "AuthMode [%s] not valid for TransferDataType [%s]", mode, transferDataType);
break;
case IMPORT:
Preconditions.checkArgument(supportedImportTypes.contains(transferDataType), "AuthMode [%s] not valid for TransferDataType [%s]", mode, transferDataType);
break;
default:
throw new IllegalArgumentException("AuthMode [" + mode + "] not supported");
}
return provider.getAuthDataGenerator(transferDataType, mode);
}
use of org.datatransferproject.spi.api.auth.extension.AuthServiceExtension in project data-transfer-project by google.
the class PortabilityAuthServiceExtensionRegistryTest method testGetTransferDataTypes.
@Test
public void testGetTransferDataTypes() {
List<String> supportedServiceTypes = ImmutableList.of("PHOTOS", "CONTACTS");
AuthServiceExtension mockAuthProvider = getMockedAuthProvider(supportedServiceTypes, supportedServiceTypes, "mockAuthProvider");
AuthServiceProviderRegistry registry = new PortabilityAuthServiceProviderRegistry(ImmutableMap.of("mockServiceProvider", mockAuthProvider));
Set<String> actual = registry.getTransferDataTypes();
final String[] services = new String[] { "PHOTOS", "CONTACTS" };
Set<String> expected = new HashSet<>(Arrays.asList(services));
Assert.assertEquals(actual, expected);
}
use of org.datatransferproject.spi.api.auth.extension.AuthServiceExtension in project data-transfer-project by google.
the class PortabilityAuthServiceExtensionRegistryTest method testGetImportServices1.
@Test
public void testGetImportServices1() {
List<String> supportedServiceTypes1 = ImmutableList.of("PHOTOS", "CONTACTS");
List<String> supportedServiceTypes2 = ImmutableList.of("CONTACTS");
AuthServiceExtension mockAuthProvider1 = getMockedAuthProvider(supportedServiceTypes1, supportedServiceTypes1, "mockAuthProvider1");
AuthServiceExtension mockAuthProvider2 = getMockedAuthProvider(supportedServiceTypes2, supportedServiceTypes2, "mockAuthProvider2");
AuthServiceProviderRegistry registry = new PortabilityAuthServiceProviderRegistry(ImmutableMap.of("mockServiceProvider1", mockAuthProvider1, "mockServiceProvider2", mockAuthProvider2));
Set<String> actual = registry.getImportServices("CONTACTS");
final String[] services = new String[] { "mockAuthProvider1", "mockAuthProvider2" };
Set<String> expected = new HashSet<>(Arrays.asList(services));
Assert.assertEquals(actual, expected);
}
use of org.datatransferproject.spi.api.auth.extension.AuthServiceExtension in project data-transfer-project by google.
the class PortabilityAuthServiceExtensionRegistryTest method requireImportAndExportTest.
@Test
public void requireImportAndExportTest() {
List<String> supportedImportTypes = ImmutableList.of("PHOTOS", "CONTACTS");
List<String> supportedExportTypes = ImmutableList.of("CONTACTS");
AuthServiceExtension mockAuthProvider = getMockedAuthProvider(supportedImportTypes, supportedExportTypes, "mockAuthProvider");
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("available for import but not export");
AuthServiceProviderRegistry registry = new PortabilityAuthServiceProviderRegistry(ImmutableMap.of("mockServiceProvider", mockAuthProvider));
}
use of org.datatransferproject.spi.api.auth.extension.AuthServiceExtension in project data-transfer-project by google.
the class PortabilityAuthServiceExtensionRegistryTest method getMockedAuthProvider.
private AuthServiceExtension getMockedAuthProvider(List<String> supportedImportTypes, List<String> supportedExportTypes, String serviceId) {
AuthServiceExtension mockAuthProvider = mock(AuthServiceExtension.class);
when(mockAuthProvider.getExportTypes()).thenReturn(supportedExportTypes);
when(mockAuthProvider.getImportTypes()).thenReturn(supportedImportTypes);
when(mockAuthProvider.getServiceId()).thenReturn(serviceId);
return mockAuthProvider;
}
Aggregations