Search in sources :

Example 26 with File

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

the class DriveFilesIntegrationTest method testInsert.

@Test
public void testInsert() throws Exception {
    File file = new File();
    file.setTitle(UPLOAD_FILE.getName());
    // using com.google.api.services.drive.model.File message body for single parameter "content"
    File result = requestBody("direct://INSERT", file);
    assertNotNull("insert result", result);
    LOG.debug("insert: " + result);
}
Also used : File(com.google.api.services.drive.model.File) Test(org.junit.Test)

Example 27 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 28 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 29 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 30 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)

Aggregations

File (com.google.api.services.drive.model.File)41 Test (org.junit.Test)19 IOException (java.io.IOException)17 HashMap (java.util.HashMap)9 FileList (com.google.api.services.drive.model.FileList)7 ParseException (java.text.ParseException)7 ArrayList (java.util.ArrayList)7 FileContent (com.google.api.client.http.FileContent)6 GeneralSecurityException (java.security.GeneralSecurityException)6 GenericUrl (com.google.api.client.http.GenericUrl)4 HttpResponse (com.google.api.client.http.HttpResponse)4 Permission (com.google.api.services.drive.model.Permission)4 User (com.google.api.services.drive.model.User)4 InputStream (java.io.InputStream)4 UserRecoverableAuthIOException (com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException)3 DateTime (com.google.api.client.util.DateTime)3 ParentReference (com.google.api.services.drive.model.ParentReference)3 Comment (com.google.api.services.drive.model.Comment)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2