use of com.dropbox.core.v2.files.CreateFolderErrorException in project dropbox-sdk-java by dropbox.
the class Main method testEnumeratedSubtypeSerialization.
private static void testEnumeratedSubtypeSerialization(DbxClientV2 client) throws DbxException, IOException {
String rootPath = "/test/proguard-tests";
try {
FolderMetadata root = client.files().createFolderV2(rootPath).getMetadata();
assertNotNull(root);
assertEquals(root.getPathLower(), rootPath);
assertEquals(root.getPathDisplay(), rootPath);
} catch (CreateFolderErrorException ex) {
if (ex.errorValue.isPath() && ex.errorValue.getPathValue().isConflict() && ex.errorValue.getPathValue().getConflictValue() == WriteConflictError.FOLDER) {
// ignore duplicate folder exception
} else {
throw ex;
}
}
Map<String, byte[]> files = new LinkedHashMap<String, byte[]>();
files.put(rootPath + "/foo.blob", bytes(1024));
files.put(rootPath + "/bar.blob", bytes(512));
files.put(rootPath + "/sub/a.dat", bytes(4096));
files.put(rootPath + "/sub/b/c.dat", bytes(64));
files.put(rootPath + "/pics/cat.rawb", bytes(8196));
try {
for (Map.Entry<String, byte[]> entry : files.entrySet()) {
String path = entry.getKey();
byte[] data = entry.getValue();
FileMetadata file = client.files().uploadBuilder(path).withMode(WriteMode.OVERWRITE).withAutorename(false).withMute(true).uploadAndFinish(new ByteArrayInputStream(data));
assertNotNull(file);
assertEquals(file.getPathLower(), path);
assertEquals(file.getSize(), data.length);
Metadata metadata = client.files().getMetadata(path);
assertEquals(metadata, file);
}
for (String path : files.keySet()) {
Metadata file = client.files().deleteV2(path).getMetadata();
assertNotNull(file);
assertEquals(file.getPathLower(), path);
assertTrue(file instanceof FileMetadata);
Metadata deleted = client.files().getMetadataBuilder(path).withIncludeDeleted(true).start();
assertNotNull(deleted);
assertTrue(deleted instanceof DeletedMetadata, deleted.getClass().toString());
assertEquals(deleted.getPathLower(), path);
}
} finally {
client.files().deleteV2(rootPath);
}
}
Aggregations