Skip to content

Commit

Permalink
test CreateFolderOperation without server
Browse files Browse the repository at this point in the history
Signed-off-by: tobiasKaminsky <[email protected]>
  • Loading branch information
tobiasKaminsky committed Feb 14, 2019
1 parent 918895a commit 76dd4e2
Show file tree
Hide file tree
Showing 11 changed files with 328 additions and 40 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ dependencies {
// JUnit4 Rules
androidTestImplementation 'androidx.test:rules:1.1.1'
// Android JUnit Runner
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'

// Espresso core
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
import lombok.Setter;

@Getter
public class FileDataStorageManager {
public class FileDataStorageManager implements FileDataStorageManagerInterface {
private static final String TAG = FileDataStorageManager.class.getSimpleName();

private static final String AND = "=? AND ";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.owncloud.android.datamodel;

import android.accounts.Account;

import com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.lib.resources.status.OCCapability;

import java.util.Collection;
import java.util.List;

import androidx.annotation.Nullable;

public interface FileDataStorageManagerInterface {

OCFile getFileByPath(String path);

Account getAccount();

@Nullable
OCFile getFileById(long id);

void saveConflict(OCFile file, String etagInConflict);

void deleteFileInMediaScan(String path);

boolean saveFile(OCFile file);

boolean fileExists(long id);

List<OCFile> getFolderContent(OCFile f, boolean onlyOnDevice);

void saveFolder(OCFile folder, Collection<OCFile> updatedFiles, Collection<OCFile> filesToRemove);

boolean removeFile(OCFile file, boolean removeDBData, boolean removeLocalCopy);

boolean removeFolder(OCFile folder, boolean removeDBData, boolean removeLocalContent);

void moveLocalFile(OCFile file, String targetPath, String targetParentPath);

boolean saveShare(OCShare share);

List<OCShare> getSharesWithForAFile(String filePath, String accountName);

void removeShare(OCShare share);

void copyLocalFile(OCFile file, String targetPath);

OCShare getFirstShareByPathAndType(String path, ShareType type, String shareWith);

OCCapability saveCapabilities(OCCapability capability);

void saveSharesDB(List<OCShare> shares);

void removeSharesForFile(String remotePath);

OCShare getShareById(long id);
}
2 changes: 1 addition & 1 deletion src/main/java/com/owncloud/android/datamodel/OCFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa

private static final String TAG = OCFile.class.getSimpleName();

@Getter @Setter private long fileId; // android internal ID of the file
@Getter @Setter private long fileId; // android internal ID of the file
@Getter @Setter private long parentId;
@Getter @Setter private long fileLength;
@Getter @Setter private long creationTimestamp; // UNIX timestamp of the time the file was created
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ public static class ThumbnailGenerationTask extends AsyncTask<ThumbnailGeneratio
private List<ThumbnailGenerationTask> mAsyncTasks;
private Object mFile;
private String mImageKey;
private FileDataStorageManager mStorageManager;
private FileDataStorageManagerInterface mStorageManager;
private GetMethod getMethod;

public ThumbnailGenerationTask(ImageView imageView, FileDataStorageManager storageManager, Account account)
Expand All @@ -424,7 +424,7 @@ public GetMethod getGetMethod() {
return getMethod;
}

public ThumbnailGenerationTask(FileDataStorageManager storageManager, Account account){
public ThumbnailGenerationTask(FileDataStorageManagerInterface storageManager, Account account) {
if (storageManager == null) {
throw new IllegalArgumentException("storageManager must not be NULL");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ public CreateFolderOperation(String remotePath, boolean createFullPath) {


@Override
protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result = new CreateFolderRemoteOperation(mRemotePath, mCreateFullPath).execute(client);
public RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result = createCreateFolderRemoteOperation(mRemotePath, mCreateFullPath).execute(client);

if (result.isSuccess()) {
RemoteOperationResult remoteFolderOperationResult = new ReadFolderRemoteOperation(mRemotePath)
RemoteOperationResult remoteFolderOperationResult = createReadFolderRemoteOperation(mRemotePath)
.execute(client, true);

createdRemoteFolder = (RemoteFile) remoteFolderOperationResult.getData().get(0);
Expand All @@ -76,6 +76,14 @@ protected RemoteOperationResult run(OwnCloudClient client) {
return result;
}

public CreateFolderRemoteOperation createCreateFolderRemoteOperation(String mRemotePath, boolean mCreateFullPath) {
return new CreateFolderRemoteOperation(mRemotePath, mCreateFullPath);
}

public ReadFolderRemoteOperation createReadFolderRemoteOperation(String mRemotePath) {
return new ReadFolderRemoteOperation(mRemotePath);
}

@Override
public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
if (operation instanceof CreateFolderRemoteOperation) {
Expand Down Expand Up @@ -120,7 +128,7 @@ private void saveFolderInDB() {
newDir.setEncrypted(FileStorageUtils.checkEncryptionStatus(newDir, getStorageManager()));
getStorageManager().saveFile(newDir);

Log_OC.d(TAG, "Create directory " + mRemotePath + " in Database");
// Log_OC.d(TAG, "Create directory " + mRemotePath + " in Database");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import android.content.Intent;
import android.util.Log;

import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.FileDataStorageManagerInterface;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.files.services.FileDownloader;
import com.owncloud.android.lib.common.OwnCloudClient;
Expand Down Expand Up @@ -225,7 +225,7 @@ private RemoteOperationResult fetchAndSyncRemoteFolder(OwnCloudClient client) th


private void removeLocalFolder() {
FileDataStorageManager storageManager = getStorageManager();
FileDataStorageManagerInterface storageManager = getStorageManager();
if (storageManager.fileExists(mLocalFolder.getFileId())) {
String currentSavePath = FileStorageUtils.getSavePath(mAccount.name);
storageManager.removeFolder(
Expand Down Expand Up @@ -260,7 +260,7 @@ private void synchronizeData(List<Object> folderAndFiles) throws OperationCancel
throw new OperationCancelledException();
}

FileDataStorageManager storageManager = getStorageManager();
FileDataStorageManagerInterface storageManager = getStorageManager();
List<OCFile> updatedFiles = new Vector<>(folderAndFiles.size() - 1);

// get current data about local contents of the folder to synchronize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.os.Handler;

import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.FileDataStorageManagerInterface;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
import com.owncloud.android.lib.common.operations.RemoteOperation;
Expand All @@ -33,33 +34,33 @@
/**
* Operation which execution involves both interactions with an ownCloud server and
* with local data in the device.
*
*
* Provides methods to execute the operation both synchronously or asynchronously.
*/
public abstract class SyncOperation extends RemoteOperation {

//private static final String TAG = SyncOperation.class.getSimpleName();

private FileDataStorageManager mStorageManager;
public FileDataStorageManager getStorageManager() {
private FileDataStorageManagerInterface mStorageManager;

public FileDataStorageManagerInterface getStorageManager() {
return mStorageManager;
}


/**
* Synchronously executes the operation on the received ownCloud account.
*
*
* Do not call this method from the main thread.
*
*
* This method should be used whenever an ownCloud account is available, instead of
* {@link #execute(OwnCloudClient, com.owncloud.android.datamodel.FileDataStorageManager)}.
*
* {@link #execute(OwnCloudClient, com.owncloud.android.datamodel.FileDataStorageManagerInterface)}.
*
* @param storageManager
* @param context Android context for the component calling the method.
* @return Result of the operation.
*/
public RemoteOperationResult execute(FileDataStorageManager storageManager, Context context) {
public RemoteOperationResult execute(FileDataStorageManagerInterface storageManager, Context context) {
if (storageManager == null) {
throw new IllegalArgumentException("Trying to execute a sync operation with a " +
"NULL storage manager");
Expand All @@ -71,35 +72,33 @@ public RemoteOperationResult execute(FileDataStorageManager storageManager, Cont
mStorageManager = storageManager;
return super.execute(mStorageManager.getAccount(), context);
}
/**


/**
* Synchronously executes the remote operation
*
*
* Do not call this method from the main thread.
*
*
* @param client Client object to reach an ownCloud server during the execution of the o
* peration.
* @param storageManager
* @return Result of the operation.
*/
public RemoteOperationResult execute(OwnCloudClient client,
FileDataStorageManager storageManager) {
public RemoteOperationResult execute(OwnCloudClient client, FileDataStorageManagerInterface storageManager) {
if (storageManager == null) {
throw new IllegalArgumentException("Trying to execute a sync operation with a " +
"NULL storage manager");
throw new IllegalArgumentException("Trying to execute a sync operation with a NULL storage manager");
}
mStorageManager = storageManager;
return super.execute(client);
}


/**
* Asynchronously executes the remote operation
*
*
* This method should be used whenever an ownCloud account is available, instead of
* {@link #execute(OwnCloudClient)}.
*
*
* @param account ownCloud account in remote ownCloud server to reach during the
* execution of the operation.
* @param context Android context for the component calling the method.
Expand All @@ -125,10 +124,10 @@ public Thread execute(FileDataStorageManager storageManager,
}
*/

/**

/**
* Asynchronously executes the remote operation
*
*
* @param client Client object to reach an ownCloud server during the
* execution of the operation.
* @param listener Listener to be notified about the execution of the operation.
Expand All @@ -146,5 +145,5 @@ public Thread execute(OwnCloudClient client, FileDataStorageManager storageManag
return super.execute(client, listener, listenerHandler);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import com.owncloud.android.MainApp;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.FileDataStorageManagerInterface;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.files.model.RemoteFile;
Expand Down Expand Up @@ -409,7 +410,7 @@ public static void checkIfFileFinishedSaving(OCFile file) {
* @param storageManager up to date reference to storage manager
* @return true if file itself or ancestor is encrypted
*/
public static boolean checkEncryptionStatus(OCFile file, FileDataStorageManager storageManager) {
public static boolean checkEncryptionStatus(OCFile file, FileDataStorageManagerInterface storageManager) {
if (file.isEncrypted()) {
return true;
}
Expand Down
Loading

0 comments on commit 76dd4e2

Please sign in to comment.