mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-09 08:56:22 +00:00
Updated CopyRemoteFileOperation and verified with the unit tests
This commit is contained in:
parent
8633efbb49
commit
2970b54e7c
@ -24,6 +24,7 @@
|
||||
|
||||
package com.owncloud.android.lib.resources.files;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
@ -61,6 +62,7 @@ public class CopyRemoteFileOperation extends RemoteOperation {
|
||||
private String mTargetRemotePath;
|
||||
|
||||
private boolean mOverwrite;
|
||||
private Context mContext;
|
||||
|
||||
|
||||
/**
|
||||
@ -71,10 +73,9 @@ public class CopyRemoteFileOperation extends RemoteOperation {
|
||||
* @param srcRemotePath Remote path of the file/folder to move.
|
||||
* @param targetRemotePath Remove path desired for the file/folder after moving it.
|
||||
*/
|
||||
public CopyRemoteFileOperation(
|
||||
String srcRemotePath, String targetRemotePath, boolean overwrite
|
||||
public CopyRemoteFileOperation(Context context, String srcRemotePath, String targetRemotePath, boolean overwrite
|
||||
) {
|
||||
|
||||
mContext = context;
|
||||
mSrcRemotePath = srcRemotePath;
|
||||
mTargetRemotePath = targetRemotePath;
|
||||
mOverwrite = overwrite;
|
||||
@ -107,6 +108,10 @@ public class CopyRemoteFileOperation extends RemoteOperation {
|
||||
return new RemoteOperationResult(ResultCode.INVALID_COPY_INTO_DESCENDANT);
|
||||
}
|
||||
|
||||
if (!new ExistenceCheckRemoteOperation(mSrcRemotePath, mContext, Boolean.FALSE).run(getClient()).isSuccess()) {
|
||||
return new RemoteOperationResult(ResultCode.FILE_NOT_FOUND);
|
||||
}
|
||||
|
||||
/// perform remote operation
|
||||
CopyMethod copyMethod = null;
|
||||
RemoteOperationResult result = null;
|
||||
|
@ -36,18 +36,11 @@ import com.owncloud.android.lib.common.network.NetworkUtils;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
||||
import com.owncloud.android.lib.resources.files.CopyRemoteFileOperation;
|
||||
import com.owncloud.android.lib.test_project.R;
|
||||
import com.owncloud.android.lib.test_project.SelfSignedConfidentSslSocketFactory;
|
||||
import com.owncloud.android.lib.test_project.TestActivity;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
import org.apache.commons.httpclient.protocol.Protocol;
|
||||
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.security.GeneralSecurityException;
|
||||
|
||||
//import android.test.AndroidTestCase;
|
||||
|
||||
@ -210,21 +203,6 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity>
|
||||
|
||||
public CopyFileTest() {
|
||||
super(TestActivity.class);
|
||||
|
||||
Protocol pr = Protocol.getProtocol("https");
|
||||
if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) {
|
||||
try {
|
||||
ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory();
|
||||
Protocol.registerProtocol(
|
||||
"https",
|
||||
new Protocol("https", psf, 443));
|
||||
|
||||
} catch (GeneralSecurityException e) {
|
||||
throw new AssertionFailedError(
|
||||
"Self-signed confident SSL context could not be loaded");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -277,6 +255,7 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity>
|
||||
|
||||
// copy file
|
||||
CopyRemoteFileOperation copyOperation = new CopyRemoteFileOperation(
|
||||
getContext(),
|
||||
SRC_PATH_TO_FILE_1,
|
||||
TARGET_PATH_TO_FILE_1,
|
||||
false
|
||||
@ -286,6 +265,7 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity>
|
||||
|
||||
// copy & rename file, different location
|
||||
copyOperation = new CopyRemoteFileOperation(
|
||||
getContext(),
|
||||
SRC_PATH_TO_FILE_2,
|
||||
TARGET_PATH_TO_FILE_2_RENAMED,
|
||||
false
|
||||
@ -295,6 +275,7 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity>
|
||||
|
||||
// copy & rename file, same location (rename file)
|
||||
copyOperation = new CopyRemoteFileOperation(
|
||||
getContext(),
|
||||
SRC_PATH_TO_FILE_3,
|
||||
SRC_PATH_TO_FILE_3_RENAMED,
|
||||
false
|
||||
@ -304,6 +285,7 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity>
|
||||
|
||||
// copy empty folder
|
||||
copyOperation = new CopyRemoteFileOperation(
|
||||
getContext(),
|
||||
SRC_PATH_TO_EMPTY_FOLDER,
|
||||
TARGET_PATH_TO_EMPTY_FOLDER,
|
||||
false
|
||||
@ -313,6 +295,7 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity>
|
||||
|
||||
// copy non-empty folder
|
||||
copyOperation = new CopyRemoteFileOperation(
|
||||
getContext(),
|
||||
SRC_PATH_TO_FULL_FOLDER_1,
|
||||
TARGET_PATH_TO_FULL_FOLDER_1,
|
||||
false
|
||||
@ -322,6 +305,7 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity>
|
||||
|
||||
// copy & rename folder, different location
|
||||
copyOperation = new CopyRemoteFileOperation(
|
||||
getContext(),
|
||||
SRC_PATH_TO_FULL_FOLDER_2,
|
||||
TARGET_PATH_TO_FULL_FOLDER_2_RENAMED,
|
||||
false
|
||||
@ -331,6 +315,7 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity>
|
||||
|
||||
// copy & rename folder, same location (rename folder)
|
||||
copyOperation = new CopyRemoteFileOperation(
|
||||
getContext(),
|
||||
SRC_PATH_TO_FULL_FOLDER_3,
|
||||
SRC_PATH_TO_FULL_FOLDER_3_RENAMED,
|
||||
false
|
||||
@ -340,6 +325,7 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity>
|
||||
|
||||
// copy for nothing (success, but no interaction with network)
|
||||
copyOperation = new CopyRemoteFileOperation(
|
||||
getContext(),
|
||||
SRC_PATH_TO_FILE_4,
|
||||
SRC_PATH_TO_FILE_4,
|
||||
false
|
||||
@ -349,6 +335,7 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity>
|
||||
|
||||
// copy overwriting
|
||||
copyOperation = new CopyRemoteFileOperation(
|
||||
getContext(),
|
||||
SRC_PATH_TO_FULL_FOLDER_4,
|
||||
TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4,
|
||||
true
|
||||
@ -361,6 +348,7 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity>
|
||||
|
||||
// file to copy does not exist
|
||||
copyOperation = new CopyRemoteFileOperation(
|
||||
getContext(),
|
||||
SRC_PATH_TO_NON_EXISTENT_FILE,
|
||||
TARGET_PATH_TO_NON_EXISTENT_FILE,
|
||||
false
|
||||
@ -370,6 +358,7 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity>
|
||||
|
||||
// folder to copy into does no exist
|
||||
copyOperation = new CopyRemoteFileOperation(
|
||||
getContext(),
|
||||
SRC_PATH_TO_FILE_5,
|
||||
TARGET_PATH_TO_FILE_5_INTO_NON_EXISTENT_FOLDER,
|
||||
false
|
||||
@ -379,6 +368,7 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity>
|
||||
|
||||
// target location (renaming) has invalid characters
|
||||
copyOperation = new CopyRemoteFileOperation(
|
||||
getContext(),
|
||||
SRC_PATH_TO_FILE_6,
|
||||
TARGET_PATH_RENAMED_WITH_INVALID_CHARS,
|
||||
false
|
||||
@ -388,7 +378,8 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity>
|
||||
|
||||
// name collision
|
||||
copyOperation = new CopyRemoteFileOperation(
|
||||
SRC_PATH_TO_FILE_7,
|
||||
getContext(),
|
||||
SRC_PATH_TO_FILE_1,
|
||||
TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7,
|
||||
false
|
||||
);
|
||||
@ -397,13 +388,13 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity>
|
||||
|
||||
// copy a folder into a descendant
|
||||
copyOperation = new CopyRemoteFileOperation(
|
||||
getContext(),
|
||||
SRC_BASE_FOLDER,
|
||||
SRC_PATH_TO_EMPTY_FOLDER,
|
||||
false
|
||||
);
|
||||
result = copyOperation.execute(mClient);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_COPY_INTO_DESCENDANT);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -437,12 +428,13 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity>
|
||||
mPass = context.getString(R.string.password);
|
||||
|
||||
mClient = new OwnCloudClient(
|
||||
Uri.parse(mServerUri),
|
||||
Uri.parse("http://" + mServerUri),
|
||||
NetworkUtils.getMultiThreadedConnManager()
|
||||
);
|
||||
mClient.setDefaultTimeouts(
|
||||
OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT,
|
||||
OwnCloudClientFactory.DEFAULT_CONNECTION_TIMEOUT);
|
||||
mClient.setBaseUri(Uri.parse("http://" + mServerUri));
|
||||
mClient.setFollowRedirects(true);
|
||||
mClient.setCredentials(
|
||||
OwnCloudCredentialsFactory.newBasicCredentials(
|
||||
|
Loading…
x
Reference in New Issue
Block a user