mirror of
https://github.com/owncloud/android-library.git
synced 2025-07-25 18:57:33 +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;
|
package com.owncloud.android.lib.resources.files;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
@ -61,6 +62,7 @@ public class CopyRemoteFileOperation extends RemoteOperation {
|
|||||||
private String mTargetRemotePath;
|
private String mTargetRemotePath;
|
||||||
|
|
||||||
private boolean mOverwrite;
|
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 srcRemotePath Remote path of the file/folder to move.
|
||||||
* @param targetRemotePath Remove path desired for the file/folder after moving it.
|
* @param targetRemotePath Remove path desired for the file/folder after moving it.
|
||||||
*/
|
*/
|
||||||
public CopyRemoteFileOperation(
|
public CopyRemoteFileOperation(Context context, String srcRemotePath, String targetRemotePath, boolean overwrite
|
||||||
String srcRemotePath, String targetRemotePath, boolean overwrite
|
|
||||||
) {
|
) {
|
||||||
|
mContext = context;
|
||||||
mSrcRemotePath = srcRemotePath;
|
mSrcRemotePath = srcRemotePath;
|
||||||
mTargetRemotePath = targetRemotePath;
|
mTargetRemotePath = targetRemotePath;
|
||||||
mOverwrite = overwrite;
|
mOverwrite = overwrite;
|
||||||
@ -107,6 +108,10 @@ public class CopyRemoteFileOperation extends RemoteOperation {
|
|||||||
return new RemoteOperationResult(ResultCode.INVALID_COPY_INTO_DESCENDANT);
|
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
|
/// perform remote operation
|
||||||
CopyMethod copyMethod = null;
|
CopyMethod copyMethod = null;
|
||||||
RemoteOperationResult result = 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;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
||||||
import com.owncloud.android.lib.resources.files.CopyRemoteFileOperation;
|
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 com.owncloud.android.lib.test_project.TestActivity;
|
||||||
|
|
||||||
import junit.framework.AssertionFailedError;
|
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
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.io.File;
|
||||||
import java.security.GeneralSecurityException;
|
|
||||||
|
|
||||||
//import android.test.AndroidTestCase;
|
//import android.test.AndroidTestCase;
|
||||||
|
|
||||||
@ -210,21 +203,6 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity>
|
|||||||
|
|
||||||
public CopyFileTest() {
|
public CopyFileTest() {
|
||||||
super(TestActivity.class);
|
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
|
// copy file
|
||||||
CopyRemoteFileOperation copyOperation = new CopyRemoteFileOperation(
|
CopyRemoteFileOperation copyOperation = new CopyRemoteFileOperation(
|
||||||
|
getContext(),
|
||||||
SRC_PATH_TO_FILE_1,
|
SRC_PATH_TO_FILE_1,
|
||||||
TARGET_PATH_TO_FILE_1,
|
TARGET_PATH_TO_FILE_1,
|
||||||
false
|
false
|
||||||
@ -286,6 +265,7 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity>
|
|||||||
|
|
||||||
// copy & rename file, different location
|
// copy & rename file, different location
|
||||||
copyOperation = new CopyRemoteFileOperation(
|
copyOperation = new CopyRemoteFileOperation(
|
||||||
|
getContext(),
|
||||||
SRC_PATH_TO_FILE_2,
|
SRC_PATH_TO_FILE_2,
|
||||||
TARGET_PATH_TO_FILE_2_RENAMED,
|
TARGET_PATH_TO_FILE_2_RENAMED,
|
||||||
false
|
false
|
||||||
@ -295,6 +275,7 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity>
|
|||||||
|
|
||||||
// copy & rename file, same location (rename file)
|
// copy & rename file, same location (rename file)
|
||||||
copyOperation = new CopyRemoteFileOperation(
|
copyOperation = new CopyRemoteFileOperation(
|
||||||
|
getContext(),
|
||||||
SRC_PATH_TO_FILE_3,
|
SRC_PATH_TO_FILE_3,
|
||||||
SRC_PATH_TO_FILE_3_RENAMED,
|
SRC_PATH_TO_FILE_3_RENAMED,
|
||||||
false
|
false
|
||||||
@ -304,6 +285,7 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity>
|
|||||||
|
|
||||||
// copy empty folder
|
// copy empty folder
|
||||||
copyOperation = new CopyRemoteFileOperation(
|
copyOperation = new CopyRemoteFileOperation(
|
||||||
|
getContext(),
|
||||||
SRC_PATH_TO_EMPTY_FOLDER,
|
SRC_PATH_TO_EMPTY_FOLDER,
|
||||||
TARGET_PATH_TO_EMPTY_FOLDER,
|
TARGET_PATH_TO_EMPTY_FOLDER,
|
||||||
false
|
false
|
||||||
@ -313,6 +295,7 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity>
|
|||||||
|
|
||||||
// copy non-empty folder
|
// copy non-empty folder
|
||||||
copyOperation = new CopyRemoteFileOperation(
|
copyOperation = new CopyRemoteFileOperation(
|
||||||
|
getContext(),
|
||||||
SRC_PATH_TO_FULL_FOLDER_1,
|
SRC_PATH_TO_FULL_FOLDER_1,
|
||||||
TARGET_PATH_TO_FULL_FOLDER_1,
|
TARGET_PATH_TO_FULL_FOLDER_1,
|
||||||
false
|
false
|
||||||
@ -322,6 +305,7 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity>
|
|||||||
|
|
||||||
// copy & rename folder, different location
|
// copy & rename folder, different location
|
||||||
copyOperation = new CopyRemoteFileOperation(
|
copyOperation = new CopyRemoteFileOperation(
|
||||||
|
getContext(),
|
||||||
SRC_PATH_TO_FULL_FOLDER_2,
|
SRC_PATH_TO_FULL_FOLDER_2,
|
||||||
TARGET_PATH_TO_FULL_FOLDER_2_RENAMED,
|
TARGET_PATH_TO_FULL_FOLDER_2_RENAMED,
|
||||||
false
|
false
|
||||||
@ -331,6 +315,7 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity>
|
|||||||
|
|
||||||
// copy & rename folder, same location (rename folder)
|
// copy & rename folder, same location (rename folder)
|
||||||
copyOperation = new CopyRemoteFileOperation(
|
copyOperation = new CopyRemoteFileOperation(
|
||||||
|
getContext(),
|
||||||
SRC_PATH_TO_FULL_FOLDER_3,
|
SRC_PATH_TO_FULL_FOLDER_3,
|
||||||
SRC_PATH_TO_FULL_FOLDER_3_RENAMED,
|
SRC_PATH_TO_FULL_FOLDER_3_RENAMED,
|
||||||
false
|
false
|
||||||
@ -340,6 +325,7 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity>
|
|||||||
|
|
||||||
// copy for nothing (success, but no interaction with network)
|
// copy for nothing (success, but no interaction with network)
|
||||||
copyOperation = new CopyRemoteFileOperation(
|
copyOperation = new CopyRemoteFileOperation(
|
||||||
|
getContext(),
|
||||||
SRC_PATH_TO_FILE_4,
|
SRC_PATH_TO_FILE_4,
|
||||||
SRC_PATH_TO_FILE_4,
|
SRC_PATH_TO_FILE_4,
|
||||||
false
|
false
|
||||||
@ -349,6 +335,7 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity>
|
|||||||
|
|
||||||
// copy overwriting
|
// copy overwriting
|
||||||
copyOperation = new CopyRemoteFileOperation(
|
copyOperation = new CopyRemoteFileOperation(
|
||||||
|
getContext(),
|
||||||
SRC_PATH_TO_FULL_FOLDER_4,
|
SRC_PATH_TO_FULL_FOLDER_4,
|
||||||
TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4,
|
TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4,
|
||||||
true
|
true
|
||||||
@ -361,6 +348,7 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity>
|
|||||||
|
|
||||||
// file to copy does not exist
|
// file to copy does not exist
|
||||||
copyOperation = new CopyRemoteFileOperation(
|
copyOperation = new CopyRemoteFileOperation(
|
||||||
|
getContext(),
|
||||||
SRC_PATH_TO_NON_EXISTENT_FILE,
|
SRC_PATH_TO_NON_EXISTENT_FILE,
|
||||||
TARGET_PATH_TO_NON_EXISTENT_FILE,
|
TARGET_PATH_TO_NON_EXISTENT_FILE,
|
||||||
false
|
false
|
||||||
@ -370,6 +358,7 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity>
|
|||||||
|
|
||||||
// folder to copy into does no exist
|
// folder to copy into does no exist
|
||||||
copyOperation = new CopyRemoteFileOperation(
|
copyOperation = new CopyRemoteFileOperation(
|
||||||
|
getContext(),
|
||||||
SRC_PATH_TO_FILE_5,
|
SRC_PATH_TO_FILE_5,
|
||||||
TARGET_PATH_TO_FILE_5_INTO_NON_EXISTENT_FOLDER,
|
TARGET_PATH_TO_FILE_5_INTO_NON_EXISTENT_FOLDER,
|
||||||
false
|
false
|
||||||
@ -379,6 +368,7 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity>
|
|||||||
|
|
||||||
// target location (renaming) has invalid characters
|
// target location (renaming) has invalid characters
|
||||||
copyOperation = new CopyRemoteFileOperation(
|
copyOperation = new CopyRemoteFileOperation(
|
||||||
|
getContext(),
|
||||||
SRC_PATH_TO_FILE_6,
|
SRC_PATH_TO_FILE_6,
|
||||||
TARGET_PATH_RENAMED_WITH_INVALID_CHARS,
|
TARGET_PATH_RENAMED_WITH_INVALID_CHARS,
|
||||||
false
|
false
|
||||||
@ -388,7 +378,8 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity>
|
|||||||
|
|
||||||
// name collision
|
// name collision
|
||||||
copyOperation = new CopyRemoteFileOperation(
|
copyOperation = new CopyRemoteFileOperation(
|
||||||
SRC_PATH_TO_FILE_7,
|
getContext(),
|
||||||
|
SRC_PATH_TO_FILE_1,
|
||||||
TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7,
|
TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
@ -397,13 +388,13 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity>
|
|||||||
|
|
||||||
// copy a folder into a descendant
|
// copy a folder into a descendant
|
||||||
copyOperation = new CopyRemoteFileOperation(
|
copyOperation = new CopyRemoteFileOperation(
|
||||||
|
getContext(),
|
||||||
SRC_BASE_FOLDER,
|
SRC_BASE_FOLDER,
|
||||||
SRC_PATH_TO_EMPTY_FOLDER,
|
SRC_PATH_TO_EMPTY_FOLDER,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
result = copyOperation.execute(mClient);
|
result = copyOperation.execute(mClient);
|
||||||
assertTrue(result.getCode() == ResultCode.INVALID_COPY_INTO_DESCENDANT);
|
assertTrue(result.getCode() == ResultCode.INVALID_COPY_INTO_DESCENDANT);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -437,12 +428,13 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity>
|
|||||||
mPass = context.getString(R.string.password);
|
mPass = context.getString(R.string.password);
|
||||||
|
|
||||||
mClient = new OwnCloudClient(
|
mClient = new OwnCloudClient(
|
||||||
Uri.parse(mServerUri),
|
Uri.parse("http://" + mServerUri),
|
||||||
NetworkUtils.getMultiThreadedConnManager()
|
NetworkUtils.getMultiThreadedConnManager()
|
||||||
);
|
);
|
||||||
mClient.setDefaultTimeouts(
|
mClient.setDefaultTimeouts(
|
||||||
OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT,
|
OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT,
|
||||||
OwnCloudClientFactory.DEFAULT_CONNECTION_TIMEOUT);
|
OwnCloudClientFactory.DEFAULT_CONNECTION_TIMEOUT);
|
||||||
|
mClient.setBaseUri(Uri.parse("http://" + mServerUri));
|
||||||
mClient.setFollowRedirects(true);
|
mClient.setFollowRedirects(true);
|
||||||
mClient.setCredentials(
|
mClient.setCredentials(
|
||||||
OwnCloudCredentialsFactory.newBasicCredentials(
|
OwnCloudCredentialsFactory.newBasicCredentials(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user