Search in sources :

Example 6 with GoogleDriveUtils

use of org.talend.components.google.drive.runtime.GoogleDriveUtils in project components by Talend.

the class GoogleDriveDataSourceTest method testCreateReader.

@Test
public void testCreateReader() throws Exception {
    dataSource = spy(dataSource);
    Drive drive = mock(Drive.class, RETURNS_DEEP_STUBS);
    GoogleDriveUtils utils = mock(GoogleDriveUtils.class, RETURNS_DEEP_STUBS);
    doReturn(drive).when(dataSource).getDriveService();
    doReturn(utils).when(dataSource).getDriveUtils();
    dataSource.initialize(container, inputProperties);
    BoundedReader reader = dataSource.createReader(container);
    assertNotNull(reader);
}
Also used : Drive(com.google.api.services.drive.Drive) GoogleDriveUtils(org.talend.components.google.drive.runtime.GoogleDriveUtils) BoundedReader(org.talend.components.api.component.runtime.BoundedReader) Test(org.junit.Test)

Example 7 with GoogleDriveUtils

use of org.talend.components.google.drive.runtime.GoogleDriveUtils in project components by Talend.

the class GoogleDriveDataSourceTest method testValidate.

@Test
public void testValidate() throws Exception {
    dataSource.initialize(container, inputProperties);
    assertEquals(Result.ERROR, dataSource.validate(container).getStatus());
    dataSource = spy(dataSource);
    Drive drive = mock(Drive.class, RETURNS_DEEP_STUBS);
    GoogleDriveUtils utils = mock(GoogleDriveUtils.class, RETURNS_DEEP_STUBS);
    doReturn(drive).when(dataSource).getDriveService();
    doReturn(utils).when(dataSource).getDriveUtils();
    inputProperties.getDatasetProperties().getDatastoreProperties().serviceAccountJSONFile.setValue("service.json");
    dataSource.initialize(container, inputProperties);
    About about = new About();
    User user = new User();
    user.setEmailAddress("test@example.org");
    about.setUser(user);
    when(drive.about().get().setFields(anyString()).execute()).thenReturn(about);
    assertEquals(Result.OK, dataSource.validate(container).getStatus());
}
Also used : User(com.google.api.services.drive.model.User) Drive(com.google.api.services.drive.Drive) GoogleDriveUtils(org.talend.components.google.drive.runtime.GoogleDriveUtils) About(com.google.api.services.drive.model.About) Test(org.junit.Test)

Example 8 with GoogleDriveUtils

use of org.talend.components.google.drive.runtime.GoogleDriveUtils in project components by Talend.

the class GoogleDriveInputReaderTest method testAdvance.

@Test
public void testAdvance() throws Exception {
    dataSource = spy(dataSource);
    Drive drive = mock(Drive.class, RETURNS_DEEP_STUBS);
    GoogleDriveUtils utils = mock(GoogleDriveUtils.class, RETURNS_DEEP_STUBS);
    doReturn(drive).when(dataSource).getDriveService();
    doReturn(utils).when(dataSource).getDriveUtils();
    List mockList = mock(List.class, RETURNS_DEEP_STUBS);
    when(drive.files().list()).thenReturn(mockList);
    // 
    // String qA = "name='A' and 'root' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false";
    // 
    // when(drive.files().list().setQ(eq(qA)).execute()).thenReturn(createFolderFileList("A", false));
    // 
    // GoogleDriveAbstractListReader alr = mock(GoogleDriveAbstractListReader.class);
    // doReturn(true).when(alr).start();
    inputProperties.getDatasetProperties().folder.setValue("A");
    FileList fileList = new FileList();
    File f = new File();
    f.setName("sd");
    f.setMimeType("text/text");
    f.setId("id-1");
    f.setModifiedTime(com.google.api.client.util.DateTime.parseRfc3339("2017-09-29T10:00:00"));
    f.setSize(100L);
    f.setKind("drive#fileName");
    f.setTrashed(false);
    f.setParents(Collections.singletonList(FOLDER_ROOT));
    f.setWebViewLink("https://toto.com");
    fileList.setFiles(Arrays.asList(f, f, f, f, f));
    when(mockList.execute()).thenReturn(fileList);
    dataSource.initialize(container, inputProperties);
    reader = (GoogleDriveInputReader) dataSource.createReader(container);
    reader.setLimit(2);
    assertTrue(reader.start());
    reader.getCurrent();
    assertTrue(reader.advance());
    reader.getCurrent();
    assertFalse(reader.advance());
}
Also used : FileList(com.google.api.services.drive.model.FileList) Drive(com.google.api.services.drive.Drive) GoogleDriveUtils(org.talend.components.google.drive.runtime.GoogleDriveUtils) List(com.google.api.services.drive.Drive.Files.List) FileList(com.google.api.services.drive.model.FileList) File(com.google.api.services.drive.model.File) Test(org.junit.Test)

Aggregations

GoogleDriveUtils (org.talend.components.google.drive.runtime.GoogleDriveUtils)8 Drive (com.google.api.services.drive.Drive)6 Test (org.junit.Test)6 IOException (java.io.IOException)2 GoogleDriveInputProperties (org.talend.components.google.drive.data.GoogleDriveInputProperties)2 GoogleDriveDatasetRuntime (org.talend.components.google.drive.runtime.data.GoogleDriveDatasetRuntime)2 List (com.google.api.services.drive.Drive.Files.List)1 About (com.google.api.services.drive.model.About)1 File (com.google.api.services.drive.model.File)1 FileList (com.google.api.services.drive.model.FileList)1 User (com.google.api.services.drive.model.User)1 IndexedRecord (org.apache.avro.generic.IndexedRecord)1 After (org.junit.After)1 Before (org.junit.Before)1 BoundedReader (org.talend.components.api.component.runtime.BoundedReader)1 RuntimeContainer (org.talend.components.api.container.RuntimeContainer)1 GoogleDriveDatasetProperties (org.talend.components.google.drive.data.GoogleDriveDatasetProperties)1 GoogleDriveDatastoreProperties (org.talend.components.google.drive.data.GoogleDriveDatastoreProperties)1