--- /dev/null
+package com.owncloud.android.oc_framework_test_project.test;
+
+import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
+import com.owncloud.android.oc_framework.operations.RemoteOperationResult.ResultCode;
+import com.owncloud.android.oc_framework_test_project.TestActivity;
+
+import android.test.ActivityInstrumentationTestCase2;
+
+public class RenameFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
+
+ /* Folder data to rename. This folder must exist on the account */
+ private final String mOldFolderName = "folderToRename";
+ private final String mOldFolderPath = "/folderToRename/";
+ private final String mNewFolderName = "renamedFolder";
+ private final String mNewFolderPath = "/renameFolder/";
+ private final String mNewFolderNameInvalidChars = "renamedFolder:";
+ private final String mNewFolderPathInvalidChars = "/renamedFolder:/";
+
+ /* File data to rename. This file must exist on the account */
+ private final String mOldFileName = "fileToRename.png";
+ private final String mOldFilePath = "/fileToRename.png";
+ private final String mNewFileName = "renamedFile.png";
+ private final String mNewFilePath = "/renamedFile.png";
+ private final String mNewFileNameInvalidChars = "renamedFile:.png";
+ private final String mNewFilePathInvalidChars = "/renamedFile:.png";
+
+
+ private TestActivity mActivity;
+
+ public RenameFileTest() {
+ super(TestActivity.class);
+
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ setActivityInitialTouchMode(false);
+ mActivity = getActivity();
+ }
+
+ /**
+ * Test Rename Folder
+ */
+ public void testRenameFolder() {
+
+ RemoteOperationResult result = mActivity.renameFile(mOldFolderName, mOldFolderPath, mNewFolderName, mNewFolderPath);
+ assertTrue(result.isSuccess());
+ }
+
+ /**
+ * Test Rename Folder with forbidden characters
+ */
+ public void testRenameFolderForbiddenChars() {
+
+ RemoteOperationResult result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
+ mNewFolderNameInvalidChars, mNewFolderPathInvalidChars);
+ assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
+ }
+
+ /**
+ * Test Rename File
+ */
+ public void testRenameFile() {
+ RemoteOperationResult result = mActivity.renameFile(mOldFileName, mOldFilePath, mNewFileName, mNewFilePath);
+ assertTrue(result.isSuccess());
+ }
+
+
+ /**
+ * Test Rename Folder with forbidden characters
+ */
+ public void testRenameFileForbiddenChars() {
+ RemoteOperationResult result = mActivity.renameFile(mOldFileName, mOldFilePath,
+ mNewFileNameInvalidChars, mNewFilePathInvalidChars);
+ assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
+ }
+
+
+ /**
+ * Restore initial conditions
+ */
+ public void testRestoreInitialConditions() {
+ RemoteOperationResult result = mActivity.renameFile(mNewFolderName, mNewFolderPath, mOldFolderName, mOldFolderPath);
+ assertTrue(result.isSuccess());
+
+ result = mActivity.renameFile(mNewFileName, mNewFilePath, mOldFileName, mOldFilePath);
+ assertTrue(result.isSuccess());
+ }
+
+}
import com.owncloud.android.oc_framework.network.webdav.WebdavClient;
import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
import com.owncloud.android.oc_framework.operations.remote.CreateRemoteFolderOperation;
+import com.owncloud.android.oc_framework.operations.remote.RenameRemoteFileOperation;
import android.os.Bundle;
import android.accounts.Account;
private static final String TAG = "TestActivity";
+ // This account must exists on the simulator / device
+ private static final String mAccountHost = "beta.owncloud.com";
+ private static final String mAccountUser = "testandroid";
+ private static final String mAccountName = mAccountUser + "@"+ mAccountHost;
+ private static final String mAccountPass = "testandroid";
+ private static final String mAccountType = "owncloud";
+
private Account mAccount = null;
private WebdavClient mClient;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
-
- // This account must exists on the simulator / device
- String accountHost = "beta.owncloud.com";
- String accountUser = "masensio";
- String accountName = accountUser + "@"+ accountHost;
- String accountPass = "masensio";
- String accountType = "owncloud";
AccountManager am = AccountManager.get(this);
- Account[] ocAccounts = am.getAccountsByType(accountType);
+ Account[] ocAccounts = am.getAccountsByType(mAccountType);
for (Account ac : ocAccounts) {
- if (ac.name.equals(accountName)) {
+ if (ac.name.equals(mAccountName)) {
mAccount = ac;
break;
}
}
// if (mAccount == null) {
-// mAccount = new Account(accountName, accountType);
-// am.addAccountExplicitly(mAccount, accountPass, null);
+// mAccount = new Account(accountName, mAccountType);
+// am.addAccountExplicitly(mAccount, mAccountPass, null);
// am.setUserData(mAccount, "oc_version", "5.0.14");
// am.setUserData(mAccount, "oc_base_url", "http://beta.owncloud.com/owncloud");
// } else {
* @param folderName
* @param remotePath
* @param createFullPath
+ *
* @return
*/
public RemoteOperationResult createFolder(String folderName, String remotePath, boolean createFullPath) {
return result;
}
+
+ /**
+ * Access to the library method to Rename a File or Folder
+ * @param oldName Old name of the file.
+ * @param oldRemotePath Old remote path of the file. For folders it starts and ends by "/"
+ * @param newName New name to set as the name of file.
+ * @param newRemotePath New remote path to move the file, for folders it starts and ends by "/"
+ *
+ * @return
+ */
+
+ public RemoteOperationResult renameFile(String oldName, String oldRemotePath, String newName, String newRemotePath) {
+
+ RenameRemoteFileOperation renameOperation = new RenameRemoteFileOperation(oldName, oldRemotePath, newName, newRemotePath);
+ RemoteOperationResult result = renameOperation.execute(mClient);
+
+ return result;
+ }
}