private RemoteOperationResult createParentFolder(String parentPath, OwnCloudClient client) { RemoteOperation operation = new CreateFolderRemoteOperation(parentPath, mCreateFullPath); return operation.execute(client); }
/** * Performs the operation * * @param client Client object to communicate with the remote ownCloud server. */ @Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result; result = createFolder(client); if (!result.isSuccess() && mCreateFullPath && RemoteOperationResult.ResultCode.CONFLICT == result.getCode()) { result = createParentFolder(FileUtils.getParentPath(mRemotePath), client); if (result.isSuccess()) { result = createFolder(client); // second (and last) try } } return result; }
@Test public void testCreateFolderFailure() { String path = "/testFolder/"; // create folder assertTrue(new CreateFolderRemoteOperation(path, true).execute(client).isSuccess()); // create folder a second time will fail assertFalse(new CreateFolderRemoteOperation(path, true).execute(client).isSuccess()); // remove folder assertTrue(new RemoveFileRemoteOperation(path).execute(client).isSuccess()); }
@Test public void testCreateNonExistingSubFolder() { String path = "/testFolder/1/2/3/4/5/"; String top = "/testFolder/"; assertTrue(new CreateFolderRemoteOperation(path, true).execute(client).isSuccess()); // verify folder assertTrue(new ReadFolderRemoteOperation(path).execute(client).isSuccess()); // remove folder assertTrue(new RemoveFileRemoteOperation(top).execute(client).isSuccess()); } }
@Test public void testCreateFolderSuccess() { String path = "/testFolder/"; // create folder assertTrue(new CreateFolderRemoteOperation(path, true).execute(client).isSuccess()); // verify folder assertTrue(new ReadFolderRemoteOperation(path).execute(client).isSuccess()); // remove folder assertTrue(new RemoveFileRemoteOperation(path).execute(client).isSuccess()); }