Java Code Examples for com.google.api.services.drive.model.FileList#setFiles()
The following examples show how to use
com.google.api.services.drive.model.FileList#setFiles() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GoogleDrivePutRuntimeTest.java From components with Apache License 2.0 | 6 votes |
@Test public void testRunAtDriverTooManyFiles() throws Exception { FileList hasfilelist = new FileList(); List<File> hfiles = new ArrayList<>(); File hfile = new File(); hfile.setId(FILE_PUT_NAME); hfiles.add(hfile); hfiles.add(new File()); hasfilelist.setFiles(hfiles); when(drive.files().list().setQ(anyString()).execute()).thenReturn(hasfilelist); properties.overwrite.setValue(true); testRuntime.initialize(container, properties); try { testRuntime.runAtDriver(container); fail("Should not be here"); } catch (Exception e) { } }
Example 2
Source File: GoogleDrivePutRuntimeTest.java From components with Apache License 2.0 | 6 votes |
@Test public void testRunAtDriverOverwrite() throws Exception { FileList hasfilelist = new FileList(); List<File> hfiles = new ArrayList<>(); File hfile = new File(); hfile.setId(FILE_PUT_NAME); hfiles.add(hfile); hasfilelist.setFiles(hfiles); when(drive.files().list().setQ(anyString()).execute()).thenReturn(hasfilelist); properties.overwrite.setValue(true); testRuntime.initialize(container, properties); testRuntime.runAtDriver(container); assertNull(container.getComponentData(TEST_CONTAINER, getStudioName(GoogleDrivePutDefinition.RETURN_CONTENT))); assertEquals(PUT_FILE_ID, container.getComponentData(TEST_CONTAINER, getStudioName(GoogleDrivePutDefinition.RETURN_FILE_ID))); assertEquals(PUT_FILE_PARENT_ID, container.getComponentData(TEST_CONTAINER, getStudioName(GoogleDrivePutDefinition.RETURN_PARENT_FOLDER_ID))); }
Example 3
Source File: GoogleDrivePutRuntimeTest.java From components with Apache License 2.0 | 6 votes |
@Test public void testRunAtDriverOverwriteError() throws Exception { FileList hasfilelist = new FileList(); List<File> hfiles = new ArrayList<>(); File hfile = new File(); hfile.setId(FILE_PUT_NAME); hfiles.add(hfile); hasfilelist.setFiles(hfiles); when(drive.files().list().setQ(anyString()).execute()).thenReturn(hasfilelist); properties.overwrite.setValue(false); testRuntime.initialize(container, properties); try { testRuntime.runAtDriver(container); fail("Should not be here"); } catch (Exception e) { } }
Example 4
Source File: GoogleDriveTestBaseRuntime.java From components with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { container = new DefaultComponentRuntimeContainerImpl() { @Override public String getCurrentComponentId() { return TEST_CONTAINER; } }; // DATA_STORE_DIR = new File(getClass().getClassLoader().getResource("./").toURI().getPath()); HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport(); // drive = mock(Drive.class, RETURNS_DEEP_STUBS); sourceOrSink = spy(GoogleDriveSourceOrSink.class); source = spy(GoogleDriveSource.class); sink = spy(GoogleDriveSink.class); doReturn(drive).when(sourceOrSink).getDriveService(); doReturn(drive).when(source).getDriveService(); doReturn(drive).when(sink).getDriveService(); // emptyFileList = new FileList(); emptyFileList.setFiles(new ArrayList<com.google.api.services.drive.model.File>()); }
Example 5
Source File: GoogleDriveTestBaseRuntime.java From components with Apache License 2.0 | 6 votes |
protected FileList createFolderFileList(String folderId, boolean createDuplicate) { FileList fileList = new FileList(); java.util.List<com.google.api.services.drive.model.File> files = new ArrayList<>(); com.google.api.services.drive.model.File file = new com.google.api.services.drive.model.File(); file.setId(folderId); files.add(file); // if (createDuplicate) { com.google.api.services.drive.model.File fileDup = new com.google.api.services.drive.model.File(); fileDup.setId(folderId); files.add(fileDup); } fileList.setFiles(files); return fileList; }
Example 6
Source File: GoogleDriveCreateRuntimeTest.java From components with Apache License 2.0 | 6 votes |
@Test(expected = ComponentException.class) public void testManyResourcesMatching() throws Exception { FileList flA = new FileList(); List<File> fs = new ArrayList<>(); File fA = new File(); fA.setId("A"); fs.add(fA); File fAp = new File(); fAp.setId("A"); fs.add(fAp); flA.setFiles(fs); when(drive.files().list().setQ(eq(qA)).execute()).thenReturn(flA); properties.parentFolder.setValue("/A"); testRuntime.initialize(container, properties); testRuntime.runAtDriver(container); fail("Should not be here"); }
Example 7
Source File: GoogleDriveGetRuntimeTest.java From components with Apache License 2.0 | 6 votes |
@Test(expected = ComponentException.class) public void testManyFiles() throws Exception { FileList files = new FileList(); List<File> fl = new ArrayList<>(); File f1 = new File(); fl.add(f1); File f2 = new File(); fl.add(f2); files.setFiles(fl); String q1 = "name='A' and 'root' in parents and mimeType='application/vnd.google-apps.folder'"; when(drive.files().list().setQ(q1).execute()).thenReturn(files); when(drive.files().list().setQ(any()).execute()).thenReturn(files); // properties.file.setValue("/A"); testRuntime.initialize(container, properties); testRuntime.runAtDriver(container); fail("Should not be here"); }
Example 8
Source File: GoogleDriveListReaderTest.java From components with Apache License 2.0 | 5 votes |
@Test public void testStartOnly() throws Exception { 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)); when(mockList.execute()).thenReturn(fileList); // source.initialize(container, properties); GoogleDriveListReader reader = ((GoogleDriveListReader) source.createReader(container)); assertTrue(reader.start()); IndexedRecord record = (IndexedRecord) reader.getCurrent(); assertNotNull(record); assertEquals(9, record.getSchema().getFields().size()); assertEquals("id-1", record.get(0)); assertEquals("sd", record.get(1)); assertFalse(reader.advance()); reader.close(); }
Example 9
Source File: GoogleDriveListReaderTest.java From components with Apache License 2.0 | 5 votes |
@Test public void testAdvance() throws Exception { FileList fileList = new FileList(); for (int i = 0; i < 5; i++) { File f = new File(); f.setName("sd" + i); f.setMimeType("text/text"); f.setId("id-" + i); 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)); } when(mockList.execute()).thenReturn(fileList); // properties.folder.setValue("A"); source.initialize(container, properties); GoogleDriveListReader reader = ((GoogleDriveListReader) source.createReader(container)); assertTrue(reader.start()); while (reader.advance()) { assertNotNull(reader.getCurrent()); } reader.close(); }
Example 10
Source File: GoogleDriveCreateRuntimeTest.java From components with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { super.setUp(); properties = new GoogleDriveCreateProperties("test"); properties.setupProperties(); properties = (GoogleDriveCreateProperties) setupConnectionWithInstalledApplicationWithIdAndSecret(properties); // properties.parentFolder.setValue(FOLDER_ROOT); properties.newFolder.setValue(FOLDER_CREATE); testRuntime = spy(GoogleDriveCreateRuntime.class); doReturn(drive).when(testRuntime).getDriveService(); File fc = new File(); fc.setId(FOLDER_CREATE_ID); when(drive.files().create(any(File.class)).setFields(eq("id")).execute()).thenReturn(fc); // FileList flA = new FileList(); List<File> fs = new ArrayList<>(); File fA = new File(); fA.setId("A"); fs.add(fA); flA.setFiles(fs); when(drive.files().list().setQ(qA).execute()).thenReturn(flA); FileList flB = new FileList(); List<File> fsA = new ArrayList<>(); File fB = new File(); fB.setId("B"); fsA.add(fB); flB.setFiles(fsA); when(drive.files().list().setQ(qB).execute()).thenReturn(flB); FileList flC = new FileList(); List<File> fsC = new ArrayList<>(); File fC = new File(); fC.setId("C"); fsC.add(fC); flC.setFiles(fsC); when(drive.files().list().setQ(qC).execute()).thenReturn(flC); }
Example 11
Source File: GoogleDriveCopyReaderTest.java From components with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { super.setUp(); properties = new GoogleDriveCopyProperties("test"); properties.setupProperties(); properties = (GoogleDriveCopyProperties) setupConnectionWithInstalledApplicationWithIdAndSecret(properties); // properties.copyMode.setValue(CopyMode.File); properties.source.setValue(FILE_COPY_NAME); properties.destinationFolder.setValue("/A"); properties.newName.setValue("newName"); // source fileName/folder File dest = new File(); dest.setId(SOURCE_ID); FileList list = new FileList(); List<File> files = new ArrayList<>(); files.add(dest); list.setFiles(files); final String q1 = "name='A' and 'root' in parents and mimeType='application/vnd.google-apps.folder'"; final String q2 = "name='" + FILE_COPY_NAME + "' and mimeType!='application/vnd.google-apps.folder'"; when(drive.files().list().setQ(eq(q1)).execute()).thenReturn(list); when(drive.files().list().setQ(eq(q2)).execute()).thenReturn(list); // destination/copied File copiedFile = new File(); copiedFile.setId(DESTINATION_ID); copiedFile.setParents(Collections.singletonList(SOURCE_ID)); when(drive.files().copy(anyString(), any(File.class)).setFields(anyString()).execute()).thenReturn(copiedFile); File destFolder = new File(); destFolder.setId(DESTINATION_ID); destFolder.setParents(Collections.singletonList(SOURCE_ID)); when(drive.files().create(any(File.class)).setFields(anyString()).execute()).thenReturn(destFolder); }
Example 12
Source File: GoogleDriveInputReaderTest.java From components with Apache License 2.0 | 4 votes |
@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()); }
Example 13
Source File: GoogleDriveCopyRuntimeTest.java From components with Apache License 2.0 | 4 votes |
@Before public void setUp() throws Exception { super.setUp(); testRuntime = spy(GoogleDriveCopyRuntime.class); doReturn(drive).when(testRuntime).getDriveService(); properties = new GoogleDriveCopyProperties("test"); properties.setupProperties(); properties = (GoogleDriveCopyProperties) setupConnectionWithInstalledApplicationWithIdAndSecret(properties); // properties.copyMode.setValue(CopyMode.File); properties.source.setValue(FILE_COPY_NAME); properties.destinationFolder.setValue("/A"); properties.newName.setValue("newName"); // source fileName/folder File dest = new File(); dest.setId(SOURCE_ID); FileList list = new FileList(); List<File> files = new ArrayList<>(); files.add(dest); list.setFiles(files); final String q1 = "name='A' and 'root' in parents and mimeType='application/vnd.google-apps.folder'"; final String q2 = "name='fileName-copy-name' and mimeType!='application/vnd.google-apps.folder'"; final String q3 = "name='A' and mimeType='application/vnd.google-apps.folder'"; when(drive.files().list().setQ(eq(q1)).execute()).thenReturn(list); when(drive.files().list().setQ(eq(q2)).execute()).thenReturn(list); when(drive.files().list().setQ(eq(q3)).execute()).thenReturn(list); // destination/copied File copiedFile = new File(); copiedFile.setId(DESTINATION_ID); copiedFile.setParents(Collections.singletonList(SOURCE_ID)); when(drive.files().copy(anyString(), any(File.class)).setFields(anyString()).execute()).thenReturn(copiedFile); File destFolder = new File(); destFolder.setId(DESTINATION_ID); destFolder.setParents(Collections.singletonList(SOURCE_ID)); when(drive.files().create(any(File.class)).setFields(anyString()).execute()).thenReturn(destFolder); }
Example 14
Source File: GoogleDriveCopyRuntimeTest.java From components with Apache License 2.0 | 4 votes |
@Test public void testRunAtDriverCopyFolder() 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"); properties.newName.setValue(""); testRuntime.initialize(container, properties); testRuntime.runAtDriver(container); assertEquals(SOURCE_ID, container.getComponentData(TEST_CONTAINER, getStudioName(GoogleDriveCopyDefinition.RETURN_SOURCE_ID))); assertEquals(DESTINATION_ID, container.getComponentData(TEST_CONTAINER, getStudioName(GoogleDriveCopyDefinition.RETURN_DESTINATION_ID))); }
Example 15
Source File: GoogleDriveCopyReaderTest.java From components with Apache License 2.0 | 4 votes |
@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)); }