Search in sources :

Example 1 with GoogleDriveUtils

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

the class GoogleDriveDatasetTestIT method tearDown.

@After
public void tearDown() throws Exception {
    GoogleDriveDatasetRuntime rt = new GoogleDriveDatasetRuntime();
    rt.initialize(null, dataset);
    final GoogleDriveUtils utils = rt.createDataSource(properties).getDriveUtils();
    createdFolders.forEach(new Consumer<String>() {

        @Override
        public void accept(String s) {
            try {
                utils.deleteResourceById(s, false);
            } catch (IOException e) {
                LOG.error("Error during folder id {} removing : {}.", s, e);
            }
        }
    });
}
Also used : GoogleDriveUtils(org.talend.components.google.drive.runtime.GoogleDriveUtils) GoogleDriveDatasetRuntime(org.talend.components.google.drive.runtime.data.GoogleDriveDatasetRuntime) IOException(java.io.IOException) After(org.junit.After)

Example 2 with GoogleDriveUtils

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

the class GoogleDriveDatasetRuntimeTest method testGetSample.

@Test
public void testGetSample() throws Exception {
    rt = spy(rt);
    Drive drive = mock(Drive.class, RETURNS_DEEP_STUBS);
    GoogleDriveUtils utils = mock(GoogleDriveUtils.class, RETURNS_DEEP_STUBS);
    GoogleDriveDataSource source = mock(GoogleDriveDataSource.class);
    GoogleDriveInputReader reader = mock(GoogleDriveInputReader.class);
    // 
    doReturn(source).when(rt).createDataSource(any(GoogleDriveInputProperties.class));
    doReturn(reader).when(source).createReader(any(RuntimeContainer.class));
    doReturn(drive).when(source).getDriveService();
    doReturn(utils).when(source).getDriveUtils();
    // 
    rt.initialize(container, ds);
    rt.getSample(20, new Consumer<IndexedRecord>() {

        @Override
        public void accept(IndexedRecord indexedRecord) {
            assertNotNull(indexedRecord);
        }
    });
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) GoogleDriveInputProperties(org.talend.components.google.drive.data.GoogleDriveInputProperties) Drive(com.google.api.services.drive.Drive) GoogleDriveUtils(org.talend.components.google.drive.runtime.GoogleDriveUtils) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) Test(org.junit.Test)

Example 3 with GoogleDriveUtils

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

the class GoogleDriveInputReaderTest method testException.

@Test(expected = ComponentException.class)
public void testException() 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();
    doThrow(new IOException()).when(dataSource).getDriveUtils();
    dataSource.initialize(container, inputProperties);
    reader = (GoogleDriveInputReader) dataSource.createReader(container);
    fail("Should not be here");
}
Also used : Drive(com.google.api.services.drive.Drive) GoogleDriveUtils(org.talend.components.google.drive.runtime.GoogleDriveUtils) IOException(java.io.IOException) Test(org.junit.Test)

Example 4 with GoogleDriveUtils

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

the class GoogleDriveInputReaderTest method testGetLimit.

@Test
public void testGetLimit() 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);
    reader = (GoogleDriveInputReader) dataSource.createReader(container);
    reader.setLimit(30);
    assertEquals(30, reader.getLimit());
}
Also used : Drive(com.google.api.services.drive.Drive) GoogleDriveUtils(org.talend.components.google.drive.runtime.GoogleDriveUtils) Test(org.junit.Test)

Example 5 with GoogleDriveUtils

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

the class GoogleDriveDatasetTestIT method setUp.

@Before
public void setUp() throws Exception {
    datastore = new GoogleDriveDatastoreProperties("test");
    datastore.setupProperties();
    datastore.setupLayout();
    dataset = new GoogleDriveDatasetProperties("test");
    dataset.setupProperties();
    dataset.setupLayout();
    dataset.datastore.setReference(datastore);
    dataset.listMode.setValue(ListMode.Both);
    dataset.folder.setValue("root");
    dataset.includeSubDirectories.setValue(true);
    dataset.includeTrashedFiles.setValue(false);
    properties = new GoogleDriveInputProperties("test");
    properties.setupProperties();
    properties.setupLayout();
    properties.setDatasetProperties(dataset);
    // 
    createdFolders = new ArrayList<>();
    GoogleDriveDatasetRuntime rt = new GoogleDriveDatasetRuntime();
    rt.initialize(null, dataset);
    GoogleDriveUtils utils = rt.createDataSource(properties).getDriveUtils();
    for (int i = 0; i < LIMIT; i++) {
        createdFolders.add(utils.createFolder("root", "folder" + i));
    }
}
Also used : GoogleDriveDatasetProperties(org.talend.components.google.drive.data.GoogleDriveDatasetProperties) GoogleDriveInputProperties(org.talend.components.google.drive.data.GoogleDriveInputProperties) GoogleDriveUtils(org.talend.components.google.drive.runtime.GoogleDriveUtils) GoogleDriveDatasetRuntime(org.talend.components.google.drive.runtime.data.GoogleDriveDatasetRuntime) GoogleDriveDatastoreProperties(org.talend.components.google.drive.data.GoogleDriveDatastoreProperties) Before(org.junit.Before)

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