Search in sources :

Example 86 with File

use of com.google.api.services.drive.model.File in project components by Talend.

the class GoogleDriveCreateRuntimeTest method testManyResourcesMatching.

@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");
}
Also used : FileList(com.google.api.services.drive.model.FileList) ArrayList(java.util.ArrayList) File(com.google.api.services.drive.model.File) Test(org.junit.Test)

Example 87 with File

use of com.google.api.services.drive.model.File in project components by Talend.

the class GoogleDriveDeleteRuntimeTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    properties = new GoogleDriveDeleteProperties("test");
    properties.setupProperties();
    properties = (GoogleDriveDeleteProperties) setupConnectionWithInstalledApplicationWithJson(properties);
    // 
    properties.file.setValue(FOLDER_DELETE);
    testRuntime = spy(GoogleDriveDeleteRuntime.class);
    doReturn(drive).when(testRuntime).getDriveService();
    when(drive.files().update(anyString(), any(File.class)).execute()).thenReturn(null);
    when(drive.files().delete(anyString()).execute()).thenReturn(null);
    deleteFileList = new FileList();
    List<File> files = new ArrayList<>();
    File f = new File();
    f.setId(FOLDER_DELETE_ID);
    files.add(f);
    deleteFileList.setFiles(files);
}
Also used : GoogleDriveDeleteProperties(org.talend.components.google.drive.delete.GoogleDriveDeleteProperties) FileList(com.google.api.services.drive.model.FileList) ArrayList(java.util.ArrayList) File(com.google.api.services.drive.model.File) Before(org.junit.Before)

Example 88 with File

use of com.google.api.services.drive.model.File in project components by Talend.

the class GoogleDriveGetRuntimeTest method testRunAtDriverWithPath.

@Test
public void testRunAtDriverWithPath() throws Exception {
    String qA = "name='A' and 'root' in parents and mimeType='application/vnd.google-apps.folder'";
    String qB = "name='B' and 'A' in parents and mimeType='application/vnd.google-apps.folder'";
    String qC = "name='C' and 'B' in parents and mimeType='application/vnd.google-apps.folder'";
    File file = new File();
    file.setId("fileName-id");
    file.setMimeType(GoogleDriveMimeTypes.MIME_TYPE_GOOGLE_DOCUMENT);
    when(drive.files().list().setQ(eq(qA)).execute()).thenReturn(createFolderFileList("A", false));
    when(drive.files().list().setQ(eq(qB)).execute()).thenReturn(createFolderFileList("B", false));
    when(drive.files().list().setQ(eq(qC)).execute()).thenReturn(createFolderFileList("C", false));
    when(drive.files().get(anyString()).setFields(anyString()).execute()).thenReturn(file);
    // 
    properties.file.setValue("/A/B/C");
    testRuntime.initialize(container, properties);
    testRuntime.runAtDriver(container);
    assertEquals("C", container.getComponentData(TEST_CONTAINER, getStudioName(GoogleDriveGetDefinition.RETURN_FILE_ID)));
    assertNull(container.getComponentData(TEST_CONTAINER, getStudioName(GoogleDriveGetDefinition.RETURN_CONTENT)));
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) File(com.google.api.services.drive.model.File) Test(org.junit.Test)

Example 89 with File

use of com.google.api.services.drive.model.File in project components by Talend.

the class GoogleDriveGetRuntimeTest method testManyFiles.

@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(anyString()).execute()).thenReturn(files);
    // 
    properties.file.setValue("/A");
    testRuntime.initialize(container, properties);
    testRuntime.runAtDriver(container);
    fail("Should not be here");
}
Also used : 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) Test(org.junit.Test)

Example 90 with File

use of com.google.api.services.drive.model.File in project components by Talend.

the class GoogleDriveGetRuntimeTest method testRunAtDriverForGoogleDoc.

@Test
public void testRunAtDriverForGoogleDoc() throws Exception {
    File file = new File();
    file.setId("fileName-id");
    file.setMimeType(GoogleDriveMimeTypes.MIME_TYPE_GOOGLE_DOCUMENT);
    when(drive.files().get(anyString()).setFields(anyString()).execute()).thenReturn(file);
    // 
    testRuntime.initialize(container, properties);
    testRuntime.runAtDriver(container);
    assertEquals(FILE_GET_ID, container.getComponentData(TEST_CONTAINER, getStudioName(GoogleDriveGetDefinition.RETURN_FILE_ID)));
    assertNull(container.getComponentData(TEST_CONTAINER, getStudioName(GoogleDriveGetDefinition.RETURN_CONTENT)));
}
Also used : File(com.google.api.services.drive.model.File) Test(org.junit.Test)

Aggregations

File (com.google.api.services.drive.model.File)94 FileList (com.google.api.services.drive.model.FileList)35 Test (org.junit.Test)33 IOException (java.io.IOException)27 ArrayList (java.util.ArrayList)24 Before (org.junit.Before)12 FileContent (com.google.api.client.http.FileContent)10 HashMap (java.util.HashMap)10 UserRecoverableAuthIOException (com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException)9 FileNotFoundException (java.io.FileNotFoundException)7 ParseException (java.text.ParseException)7 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)6 DateTime (com.google.api.client.util.DateTime)6 Drive (com.google.api.services.drive.Drive)6 InputStream (java.io.InputStream)6 GeneralSecurityException (java.security.GeneralSecurityException)6 Matchers.anyString (org.mockito.Matchers.anyString)6 ParentReference (com.google.api.services.drive.model.ParentReference)5 Permission (com.google.api.services.drive.model.Permission)5 User (com.google.api.services.drive.model.User)5