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