Search in sources :

Example 1 with CreateFolderErrorException

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);
    }
}
Also used : CreateFolderErrorException(com.dropbox.core.v2.files.CreateFolderErrorException) ByteArrayInputStream(java.io.ByteArrayInputStream) FileMetadata(com.dropbox.core.v2.files.FileMetadata) FolderMetadata(com.dropbox.core.v2.files.FolderMetadata) DeletedMetadata(com.dropbox.core.v2.files.DeletedMetadata) FileMetadata(com.dropbox.core.v2.files.FileMetadata) Metadata(com.dropbox.core.v2.files.Metadata) FolderMetadata(com.dropbox.core.v2.files.FolderMetadata) DeletedMetadata(com.dropbox.core.v2.files.DeletedMetadata) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

CreateFolderErrorException (com.dropbox.core.v2.files.CreateFolderErrorException)1 DeletedMetadata (com.dropbox.core.v2.files.DeletedMetadata)1 FileMetadata (com.dropbox.core.v2.files.FileMetadata)1 FolderMetadata (com.dropbox.core.v2.files.FolderMetadata)1 Metadata (com.dropbox.core.v2.files.Metadata)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1