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));
}
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));
}
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));
}
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);
}
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));
}
Aggregations