Search in sources :

Example 41 with BoundedReader

use of org.talend.components.api.component.runtime.BoundedReader in project components by Talend.

the class GoogleDriveCopyReaderTest method testStartCopyFolder.

@Test
public void testStartCopyFolder() throws Exception {
    final String q1 = "name='folder' and 'root' in parents and mimeType='application/vnd.google-apps.folder'";
    final String q2 = "'" + SOURCE_ID + "' in parents and trashed=false";
    final String q3 = "'folder-id2' in parents and trashed=false";
    // 
    FileList fsource = new FileList();
    List<File> fsfiles = new ArrayList<>();
    File fsfolder = new File();
    fsfolder.setMimeType(GoogleDriveMimeTypes.MIME_TYPE_FOLDER);
    fsfolder.setName("folder");
    fsfolder.setId(SOURCE_ID);
    fsfiles.add(fsfolder);
    fsource.setFiles(fsfiles);
    when(drive.files().list().setQ(eq(q1)).execute()).thenReturn(fsource);
    FileList flist = new FileList();
    List<File> ffiles = new ArrayList<>();
    File ffile = new File();
    ffile.setMimeType(GoogleDriveMimeTypes.MIME_TYPE_CSV);
    ffile.setName("fileName");
    ffile.setId("fileName-id");
    ffiles.add(ffile);
    File ffolder = new File();
    ffolder.setMimeType(GoogleDriveMimeTypes.MIME_TYPE_FOLDER);
    ffolder.setName("folder");
    ffolder.setId("folder-id2");
    ffiles.add(ffolder);
    flist.setFiles(ffiles);
    when(drive.files().list().setQ(eq(q2)).execute()).thenReturn(flist);
    when(drive.files().list().setQ(eq(q3)).execute()).thenReturn(emptyFileList);
    properties.copyMode.setValue(CopyMode.Folder);
    properties.source.setValue("/folder");
    source.initialize(container, properties);
    BoundedReader reader = source.createReader(container);
    assertTrue(reader.start());
    IndexedRecord record = (IndexedRecord) reader.getCurrent();
    assertNotNull(record);
    assertEquals(2, record.getSchema().getFields().size());
    assertEquals(SOURCE_ID, record.get(0));
    assertEquals(DESTINATION_ID, record.get(1));
    reader.close();
    Map<String, Object> returnValues = reader.getReturnValues();
    assertNotNull(returnValues);
    assertEquals(SOURCE_ID, returnValues.get(GoogleDriveCopyDefinition.RETURN_SOURCE_ID));
    assertEquals(DESTINATION_ID, returnValues.get(GoogleDriveCopyDefinition.RETURN_DESTINATION_ID));
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) FileList(com.google.api.services.drive.model.FileList) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) File(com.google.api.services.drive.model.File) BoundedReader(org.talend.components.api.component.runtime.BoundedReader) Test(org.junit.Test)

Example 42 with BoundedReader

use of org.talend.components.api.component.runtime.BoundedReader in project components by Talend.

the class GoogleDriveCopyReaderTest method testStartCopyFile.

@Test
public void testStartCopyFile() throws Exception {
    source.initialize(container, properties);
    BoundedReader reader = source.createReader(container);
    assertTrue(reader.start());
    IndexedRecord record = (IndexedRecord) reader.getCurrent();
    assertNotNull(record);
    assertEquals(2, record.getSchema().getFields().size());
    assertEquals(SOURCE_ID, record.get(0));
    assertEquals(DESTINATION_ID, record.get(1));
    reader.close();
    Map<String, Object> returnValues = reader.getReturnValues();
    assertNotNull(returnValues);
    assertEquals(SOURCE_ID, returnValues.get(GoogleDriveCopyDefinition.RETURN_SOURCE_ID));
    assertEquals(DESTINATION_ID, returnValues.get(GoogleDriveCopyDefinition.RETURN_DESTINATION_ID));
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Matchers.anyString(org.mockito.Matchers.anyString) BoundedReader(org.talend.components.api.component.runtime.BoundedReader) Test(org.junit.Test)

Example 43 with BoundedReader

use of org.talend.components.api.component.runtime.BoundedReader in project components by Talend.

the class GoogleDriveCreateReaderTest method testStart.

@Test
public void testStart() throws Exception {
    source.initialize(container, properties);
    BoundedReader reader = source.createReader(container);
    assertTrue(reader.start());
    IndexedRecord record = (IndexedRecord) reader.getCurrent();
    assertNotNull(record);
    assertEquals(2, record.getSchema().getFields().size());
    assertEquals(FOLDER_ROOT, record.get(0));
    assertEquals(FOLDER_CREATE_ID, record.get(1));
    reader.close();
    Map<String, Object> returnValues = reader.getReturnValues();
    assertNotNull(returnValues);
    assertEquals(FOLDER_ROOT, returnValues.get(GoogleDriveCreateDefinition.RETURN_PARENT_FOLDER_ID));
    assertEquals(FOLDER_CREATE_ID, returnValues.get(GoogleDriveCreateDefinition.RETURN_NEW_FOLDER_ID));
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) BoundedReader(org.talend.components.api.component.runtime.BoundedReader) Test(org.junit.Test)

Example 44 with BoundedReader

use of org.talend.components.api.component.runtime.BoundedReader 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 45 with BoundedReader

use of org.talend.components.api.component.runtime.BoundedReader in project components by Talend.

the class GoogleDrivePutReaderTest method testStart.

@Test
public void testStart() throws Exception {
    source.initialize(container, properties);
    BoundedReader reader = source.createReader(container);
    assertTrue(reader.start());
    reader.close();
    IndexedRecord record = (IndexedRecord) reader.getCurrent();
    assertNotNull(record);
    assertNotNull(record.get(0));
    assertEquals(PUT_FILE_PARENT_ID, record.get(1));
    assertEquals(PUT_FILE_ID, record.get(2));
    Map result = reader.getReturnValues();
    assertEquals(PUT_FILE_ID, result.get(GoogleDrivePutDefinition.RETURN_FILE_ID));
    assertEquals(PUT_FILE_PARENT_ID, result.get(GoogleDrivePutDefinition.RETURN_PARENT_FOLDER_ID));
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Map(java.util.Map) BoundedReader(org.talend.components.api.component.runtime.BoundedReader) Test(org.junit.Test)

Aggregations

BoundedReader (org.talend.components.api.component.runtime.BoundedReader)45 Test (org.junit.Test)37 IndexedRecord (org.apache.avro.generic.IndexedRecord)24 Matchers.anyString (org.mockito.Matchers.anyString)6 ArrayList (java.util.ArrayList)5 TAzureStorageQueueCreateProperties (org.talend.components.azurestorage.queue.tazurestoragequeuecreate.TAzureStorageQueueCreateProperties)4 GenericData (org.apache.avro.generic.GenericData)3 RemoteBlobsTable (org.talend.components.azurestorage.blob.helpers.RemoteBlobsTable)2 TAzureStorageQueueDeleteProperties (org.talend.components.azurestorage.queue.tazurestoragequeuedelete.TAzureStorageQueueDeleteProperties)2 Drive (com.google.api.services.drive.Drive)1 File (com.google.api.services.drive.model.File)1 FileList (com.google.api.services.drive.model.FileList)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Map (java.util.Map)1 Before (org.junit.Before)1 TAzureStorageContainerCreateProperties (org.talend.components.azurestorage.blob.tazurestoragecontainercreate.TAzureStorageContainerCreateProperties)1 TAzureStorageContainerDeleteProperties (org.talend.components.azurestorage.blob.tazurestoragecontainerdelete.TAzureStorageContainerDeleteProperties)1 TAzureStorageContainerExistProperties (org.talend.components.azurestorage.blob.tazurestoragecontainerexist.TAzureStorageContainerExistProperties)1 TAzureStorageContainerListProperties (org.talend.components.azurestorage.blob.tazurestoragecontainerlist.TAzureStorageContainerListProperties)1