Search in sources :

Example 1 with FakeIdempotentImportExecutor

use of org.datatransferproject.test.types.FakeIdempotentImportExecutor in project data-transfer-project by google.

the class LocalImportTestRunner method main.

@SuppressWarnings("unchecked")
public static void main(String... args) throws Exception {
    AuthTestDriver authTestDriver = new AuthTestDriver();
    MicrosoftTransferExtension serviceProvider = new MicrosoftTransferExtension();
    TokenAuthData token = authTestDriver.getOAuthTokenCode();
    Importer<TokenAuthData, ContactsModelWrapper> contacts = (Importer<TokenAuthData, ContactsModelWrapper>) serviceProvider.getImporter("CONTACTS");
    ContactsModelWrapper wrapper = new ContactsModelWrapper(createCards());
    FakeIdempotentImportExecutor executor = new FakeIdempotentImportExecutor();
    ImportResult result = contacts.importItem(UUID.randomUUID(), executor, token, wrapper);
}
Also used : ImportResult(org.datatransferproject.spi.transfer.provider.ImportResult) TokenAuthData(org.datatransferproject.types.transfer.auth.TokenAuthData) FakeIdempotentImportExecutor(org.datatransferproject.test.types.FakeIdempotentImportExecutor) MicrosoftTransferExtension(org.datatransferproject.transfer.microsoft.MicrosoftTransferExtension) ContactsModelWrapper(org.datatransferproject.types.common.models.contacts.ContactsModelWrapper) AuthTestDriver(org.datatransferproject.auth.microsoft.harness.AuthTestDriver) Importer(org.datatransferproject.spi.transfer.provider.Importer)

Example 2 with FakeIdempotentImportExecutor

use of org.datatransferproject.test.types.FakeIdempotentImportExecutor in project data-transfer-project by google.

the class GoogleCalendarImporterTest method setup.

@Before
public void setup() {
    calendarClient = mock(Calendar.class);
    calendarCalendars = mock(Calendar.Calendars.class);
    calendarInsertRequest = mock(Calendar.Calendars.Insert.class);
    calendarEvents = mock(Calendar.Events.class);
    eventInsertRequest = mock(Calendar.Events.Insert.class);
    credentialFactory = mock(GoogleCredentialFactory.class);
    executor = new FakeIdempotentImportExecutor();
    calendarService = new GoogleCalendarImporter(credentialFactory, calendarClient);
    when(calendarClient.calendars()).thenReturn(calendarCalendars);
    when(calendarClient.events()).thenReturn(calendarEvents);
    verifyNoInteractions(credentialFactory);
}
Also used : FakeIdempotentImportExecutor(org.datatransferproject.test.types.FakeIdempotentImportExecutor) Calendar(com.google.api.services.calendar.Calendar) GoogleCredentialFactory(org.datatransferproject.datatransfer.google.common.GoogleCredentialFactory) Before(org.junit.Before)

Example 3 with FakeIdempotentImportExecutor

use of org.datatransferproject.test.types.FakeIdempotentImportExecutor in project data-transfer-project by google.

the class GoogleContactsImporterTest method setup.

@Before
public void setup() throws IOException {
    people = mock(People.class);
    peopleService = mock(PeopleService.class);
    createContact = mock(CreateContact.class);
    contactsService = new GoogleContactsImporter(peopleService);
    executor = new FakeIdempotentImportExecutor();
    when(peopleService.people()).thenReturn(people);
    when(people.createContact(any(Person.class))).thenReturn(createContact);
    Person person = new Person();
    when(createContact.execute()).thenReturn(person);
}
Also used : PeopleService(com.google.api.services.people.v1.PeopleService) FakeIdempotentImportExecutor(org.datatransferproject.test.types.FakeIdempotentImportExecutor) People(com.google.api.services.people.v1.PeopleService.People) CreateContact(com.google.api.services.people.v1.PeopleService.People.CreateContact) Person(com.google.api.services.people.v1.model.Person) Before(org.junit.Before)

Example 4 with FakeIdempotentImportExecutor

use of org.datatransferproject.test.types.FakeIdempotentImportExecutor in project data-transfer-project by google.

the class GoogleMailImporterTest method setUp.

@Before
public void setUp() throws IOException {
    Label label = new Label();
    label.setId(LABEL1);
    label.setName(LABEL1);
    labelsListResponse = new ListLabelsResponse().setLabels(Collections.singletonList(label));
    Monitor monitor = new Monitor() {
    };
    googleMailImporter = new GoogleMailImporter(googleCredentialFactory, gmail, monitor);
    executor = new FakeIdempotentImportExecutor();
    when(gmail.users()).thenReturn(users);
    when(users.messages()).thenReturn(messages);
    when(messages.insert(anyString(), any(Message.class))).thenReturn(insert);
    when(insert.execute()).thenReturn(new Message().setId("fooBar"));
    when(users.labels()).thenReturn(labels);
    when(labels.list(anyString())).thenReturn(labelsList);
    when(labelsList.execute()).thenReturn(labelsListResponse);
    when(labels.create(anyString(), any(Label.class))).thenReturn(labelsCreate);
    when(labelsCreate.execute()).thenReturn(label);
    verifyNoInteractions(googleCredentialFactory);
}
Also used : Monitor(org.datatransferproject.api.launcher.Monitor) Message(com.google.api.services.gmail.model.Message) FakeIdempotentImportExecutor(org.datatransferproject.test.types.FakeIdempotentImportExecutor) Label(com.google.api.services.gmail.model.Label) ListLabelsResponse(com.google.api.services.gmail.model.ListLabelsResponse) Before(org.junit.Before)

Example 5 with FakeIdempotentImportExecutor

use of org.datatransferproject.test.types.FakeIdempotentImportExecutor in project data-transfer-project by google.

the class MicrosoftPhotosImporterTest method setUp.

@Before
public void setUp() throws IOException {
    executor = new FakeIdempotentImportExecutor();
    authData = mock(TokensAndUrlAuthData.class);
    client = mock(OkHttpClient.class);
    objectMapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    // mocked on a per test basis
    jobStore = mock(TemporaryPerJobDataStore.class);
    monitor = new ConsoleMonitor(ConsoleMonitor.Level.INFO);
    credentialFactory = mock(MicrosoftCredentialFactory.class);
    credential = new Credential.Builder(BearerToken.authorizationHeaderAccessMethod()).build();
    when(credentialFactory.createCredential(any())).thenReturn(credential);
    when(credentialFactory.refreshCredential(any())).thenReturn(credential);
    credential.setAccessToken("acc");
    credential.setExpirationTimeMilliseconds(null);
    importer = new MicrosoftPhotosImporter(BASE_URL, client, objectMapper, jobStore, monitor, credentialFactory);
}
Also used : ConsoleMonitor(org.datatransferproject.launcher.monitor.ConsoleMonitor) TemporaryPerJobDataStore(org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore) OkHttpClient(okhttp3.OkHttpClient) FakeIdempotentImportExecutor(org.datatransferproject.test.types.FakeIdempotentImportExecutor) TokensAndUrlAuthData(org.datatransferproject.types.transfer.auth.TokensAndUrlAuthData) MicrosoftCredentialFactory(org.datatransferproject.transfer.microsoft.common.MicrosoftCredentialFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Aggregations

FakeIdempotentImportExecutor (org.datatransferproject.test.types.FakeIdempotentImportExecutor)6 Before (org.junit.Before)4 ImportResult (org.datatransferproject.spi.transfer.provider.ImportResult)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Calendar (com.google.api.services.calendar.Calendar)1 Label (com.google.api.services.gmail.model.Label)1 ListLabelsResponse (com.google.api.services.gmail.model.ListLabelsResponse)1 Message (com.google.api.services.gmail.model.Message)1 PeopleService (com.google.api.services.people.v1.PeopleService)1 People (com.google.api.services.people.v1.PeopleService.People)1 CreateContact (com.google.api.services.people.v1.PeopleService.People.CreateContact)1 Person (com.google.api.services.people.v1.model.Person)1 HttpUrl (com.squareup.okhttp.HttpUrl)1 MockResponse (com.squareup.okhttp.mockwebserver.MockResponse)1 RecordedRequest (com.squareup.okhttp.mockwebserver.RecordedRequest)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 Map (java.util.Map)1 OkHttpClient (okhttp3.OkHttpClient)1 Monitor (org.datatransferproject.api.launcher.Monitor)1