Search in sources :

Example 46 with File

use of com.google.api.services.drive.model.File in project camel by apache.

the class DriveFilesIntegrationTest method testCopy.

@Test
public void testCopy() throws Exception {
    File testFile = uploadTestFile();
    String fromFileId = testFile.getId();
    File toFile = new File();
    toFile.setTitle(UPLOAD_FILE.getName() + "_copy");
    final Map<String, Object> headers = new HashMap<String, Object>();
    // parameter type is String
    headers.put("CamelGoogleDrive.fileId", fromFileId);
    // parameter type is com.google.api.services.drive.model.File
    headers.put("CamelGoogleDrive.content", toFile);
    final File result = requestBodyAndHeaders("direct://COPY", null, headers);
    assertNotNull("copy result", result);
    assertEquals(toFile.getTitle(), result.getTitle());
    LOG.debug("copy: " + result);
}
Also used : HashMap(java.util.HashMap) File(com.google.api.services.drive.model.File) Test(org.junit.Test)

Example 47 with File

use of com.google.api.services.drive.model.File in project camel by apache.

the class DriveFilesIntegrationTest method testUpdate1.

@Test
public void testUpdate1() throws Exception {
    // First retrieve the file from the API.
    File testFile = uploadTestFile();
    String fileId = testFile.getId();
    // using String message body for single parameter "fileId"
    final File file = requestBody("direct://GET", fileId);
    // File's new metadata.
    file.setTitle("camel.png");
    // File's new content.
    java.io.File fileContent = new java.io.File(TEST_UPLOAD_IMG);
    FileContent mediaContent = new FileContent(null, fileContent);
    // Send the request to the API.
    final Map<String, Object> headers = new HashMap<String, Object>();
    // parameter type is String
    headers.put("CamelGoogleDrive.fileId", fileId);
    // parameter type is com.google.api.services.drive.model.File
    headers.put("CamelGoogleDrive.content", file);
    // parameter type is com.google.api.client.http.AbstractInputStreamContent
    headers.put("CamelGoogleDrive.mediaContent", mediaContent);
    File result = requestBodyAndHeaders("direct://UPDATE_1", null, headers);
    assertNotNull("update result", result);
    LOG.debug("update: " + result);
}
Also used : FileContent(com.google.api.client.http.FileContent) HashMap(java.util.HashMap) File(com.google.api.services.drive.model.File) Test(org.junit.Test)

Example 48 with File

use of com.google.api.services.drive.model.File in project camel by apache.

the class DriveFilesIntegrationTest method testDelete.

@Test
public void testDelete() throws Exception {
    File testFile = uploadTestFile();
    String fileId = testFile.getId();
    // using String message body for single parameter "fileId"
    sendBody("direct://DELETE", fileId);
    try {
        // the file should be gone now
        final File result = requestBody("direct://GET", fileId);
        assertTrue("Should have not found deleted file.", false);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : File(com.google.api.services.drive.model.File) Test(org.junit.Test)

Example 49 with File

use of com.google.api.services.drive.model.File in project camel by apache.

the class DriveFilesIntegrationTest method testList.

@Test
public void testList() throws Exception {
    // upload a test file
    File testFile = uploadTestFile();
    FileList result = requestBody("direct://LIST", null);
    assertNotNull("list result", result);
    assertTrue(result.getItems().size() >= 1);
    File testFile2 = uploadTestFile();
    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put("CamelGoogleDrive.maxResults", 1);
    result = requestBodyAndHeaders("direct://LIST", null, headers);
    assertNotNull("list result", result);
    assertTrue(result.getItems().size() == 1);
    // test paging the list
    List<File> resultList = new ArrayList<File>();
    String pageToken;
    int i = 0;
    do {
        result = requestBodyAndHeaders("direct://LIST", null, headers);
        resultList.addAll(result.getItems());
        pageToken = result.getNextPageToken();
        headers.put("CamelGoogleDrive.pageToken", pageToken);
        i++;
    } while (pageToken != null && pageToken.length() > 0 && i < 2);
    // we should have 2 files in result (one file for each of the 2 pages)
    assertTrue(resultList.size() == 2);
    // they should be different files
    assertFalse(resultList.get(0).getId().equals(resultList.get(1)));
}
Also used : FileList(com.google.api.services.drive.model.FileList) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) File(com.google.api.services.drive.model.File) Test(org.junit.Test)

Example 50 with File

use of com.google.api.services.drive.model.File in project camel by apache.

the class DriveFilesIntegrationTest method testTouch.

@Test
public void testTouch() throws Exception {
    File theTestFile = uploadTestFile();
    DateTime createdDate = theTestFile.getModifiedDate();
    // using String message body for single parameter "fileId"
    File result = requestBody("direct://TOUCH", theTestFile.getId());
    assertNotNull("touch result", result);
    assertTrue(result.getModifiedDate().getValue() > createdDate.getValue());
}
Also used : File(com.google.api.services.drive.model.File) DateTime(com.google.api.client.util.DateTime) 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