mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-08 00:16:09 +00:00
Updated DeleteFileTest to work with an empty OC server
This commit is contained in:
parent
45eecf1ff8
commit
d2e6925396
@ -24,11 +24,13 @@
|
|||||||
|
|
||||||
package com.owncloud.android.lib.test_project.test;
|
package com.owncloud.android.lib.test_project.test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
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.test_project.TestActivity;
|
import com.owncloud.android.lib.test_project.TestActivity;
|
||||||
|
|
||||||
import android.test.ActivityInstrumentationTestCase2;
|
import android.test.ActivityInstrumentationTestCase2;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to test Delete a File Operation
|
* Class to test Delete a File Operation
|
||||||
@ -38,17 +40,20 @@ import android.test.ActivityInstrumentationTestCase2;
|
|||||||
|
|
||||||
public class DeleteFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
|
public class DeleteFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
|
||||||
|
|
||||||
|
private static final String LOG_TAG = DeleteFileTest.class.getCanonicalName();
|
||||||
|
|
||||||
/* Folder data to delete. */
|
/* Folder data to delete. */
|
||||||
private final String mFolderPath = "/folderToDelete";
|
private static final String FOLDER_PATH = "/folderToDelete";
|
||||||
|
|
||||||
/* File to delete. */
|
/* File to delete. */
|
||||||
private final String mFilePath = "fileToDelete.png";
|
private static final String FILE_PATH = "/fileToDelete.txt";
|
||||||
|
|
||||||
|
private static boolean mGlobalSetupDone = false;
|
||||||
|
|
||||||
private TestActivity mActivity;
|
private TestActivity mActivity;
|
||||||
|
|
||||||
public DeleteFileTest() {
|
public DeleteFileTest() {
|
||||||
super(TestActivity.class);
|
super(TestActivity.class);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -56,6 +61,28 @@ public class DeleteFileTest extends ActivityInstrumentationTestCase2<TestActivit
|
|||||||
super.setUp();
|
super.setUp();
|
||||||
setActivityInitialTouchMode(false);
|
setActivityInitialTouchMode(false);
|
||||||
mActivity = getActivity();
|
mActivity = getActivity();
|
||||||
|
|
||||||
|
if (!mGlobalSetupDone) {
|
||||||
|
|
||||||
|
Log.v(LOG_TAG, "Starting global set up");
|
||||||
|
RemoteOperationResult result = mActivity.createFolder(FOLDER_PATH, true);
|
||||||
|
if (!result.isSuccess()) {
|
||||||
|
Utils.logAndThrow(LOG_TAG, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
|
||||||
|
result = mActivity.uploadFile(
|
||||||
|
textFile.getAbsolutePath(),
|
||||||
|
FILE_PATH,
|
||||||
|
"txt/plain");
|
||||||
|
if (!result.isSuccess()) {
|
||||||
|
Utils.logAndThrow(LOG_TAG, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.v(LOG_TAG, "Global set up done");
|
||||||
|
mGlobalSetupDone = true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -63,8 +90,8 @@ public class DeleteFileTest extends ActivityInstrumentationTestCase2<TestActivit
|
|||||||
*/
|
*/
|
||||||
public void testRemoveFolder() {
|
public void testRemoveFolder() {
|
||||||
|
|
||||||
RemoteOperationResult result = mActivity.removeFile(mFolderPath);
|
RemoteOperationResult result = mActivity.removeFile(FOLDER_PATH);
|
||||||
assertTrue(result.isSuccess() || result.getCode() == ResultCode.FILE_NOT_FOUND);
|
assertTrue(result.isSuccess());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -72,16 +99,17 @@ public class DeleteFileTest extends ActivityInstrumentationTestCase2<TestActivit
|
|||||||
*/
|
*/
|
||||||
public void testRemoveFile() {
|
public void testRemoveFile() {
|
||||||
|
|
||||||
RemoteOperationResult result = mActivity.removeFile(mFilePath);
|
RemoteOperationResult result = mActivity.removeFile(FILE_PATH);
|
||||||
assertTrue(result.isSuccess() || result.getCode() == ResultCode.FILE_NOT_FOUND);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Restore initial conditions
|
|
||||||
*/
|
|
||||||
public void testRestoreInitialConditions() {
|
|
||||||
RemoteOperationResult result = mActivity.createFolder(mFolderPath, true);
|
|
||||||
assertTrue(result.isSuccess());
|
assertTrue(result.isSuccess());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void tearDown() throws Exception {
|
||||||
|
// nothing to do:
|
||||||
|
// - if tests were fine, there is nothing to clean up in the server side
|
||||||
|
// - if tests failed, there is nothing we can do to clean up the server side
|
||||||
|
super.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@ package com.owncloud.android.lib.test_project.test;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
import com.owncloud.android.lib.resources.files.FileUtils;
|
|
||||||
import com.owncloud.android.lib.test_project.TestActivity;
|
import com.owncloud.android.lib.test_project.TestActivity;
|
||||||
|
|
||||||
import android.test.ActivityInstrumentationTestCase2;
|
import android.test.ActivityInstrumentationTestCase2;
|
||||||
@ -43,7 +42,7 @@ public class ReadFileTest extends ActivityInstrumentationTestCase2<TestActivity
|
|||||||
|
|
||||||
private TestActivity mActivity;
|
private TestActivity mActivity;
|
||||||
|
|
||||||
private String mFilePath;
|
private String FILE_PATH = "/fileToRead.txt";
|
||||||
|
|
||||||
public ReadFileTest() {
|
public ReadFileTest() {
|
||||||
super(TestActivity.class);
|
super(TestActivity.class);
|
||||||
@ -55,12 +54,11 @@ public class ReadFileTest extends ActivityInstrumentationTestCase2<TestActivity
|
|||||||
|
|
||||||
setActivityInitialTouchMode(false);
|
setActivityInitialTouchMode(false);
|
||||||
mActivity = getActivity();
|
mActivity = getActivity();
|
||||||
mFilePath = FileUtils.PATH_SEPARATOR + TestActivity.ASSETS__TEXT_FILE_NAME;
|
|
||||||
|
|
||||||
File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
|
File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
|
||||||
RemoteOperationResult uploadResult = mActivity.uploadFile(
|
RemoteOperationResult uploadResult = mActivity.uploadFile(
|
||||||
textFile.getAbsolutePath(),
|
textFile.getAbsolutePath(),
|
||||||
mFilePath,
|
FILE_PATH,
|
||||||
"txt/plain");
|
"txt/plain");
|
||||||
if (!uploadResult.isSuccess()) {
|
if (!uploadResult.isSuccess()) {
|
||||||
Utils.logAndThrow(LOG_TAG, uploadResult);
|
Utils.logAndThrow(LOG_TAG, uploadResult);
|
||||||
@ -71,7 +69,7 @@ public class ReadFileTest extends ActivityInstrumentationTestCase2<TestActivity
|
|||||||
* Test Read File
|
* Test Read File
|
||||||
*/
|
*/
|
||||||
public void testReadFile() {
|
public void testReadFile() {
|
||||||
RemoteOperationResult result = mActivity.readFile(mFilePath);
|
RemoteOperationResult result = mActivity.readFile(FILE_PATH);
|
||||||
assertTrue(result.getData() != null && result.getData().size() == 1);
|
assertTrue(result.getData() != null && result.getData().size() == 1);
|
||||||
assertTrue(result.isSuccess());
|
assertTrue(result.isSuccess());
|
||||||
// TODO check more properties of the result
|
// TODO check more properties of the result
|
||||||
@ -79,7 +77,7 @@ public class ReadFileTest extends ActivityInstrumentationTestCase2<TestActivity
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
RemoteOperationResult removeResult = mActivity.removeFile(mFilePath);
|
RemoteOperationResult removeResult = mActivity.removeFile(FILE_PATH);
|
||||||
if (!removeResult.isSuccess()) {
|
if (!removeResult.isSuccess()) {
|
||||||
Utils.logAndThrow(LOG_TAG, removeResult);
|
Utils.logAndThrow(LOG_TAG, removeResult);
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,6 @@ package com.owncloud.android.lib.test_project.test;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
import com.owncloud.android.lib.resources.files.FileUtils;
|
|
||||||
import com.owncloud.android.lib.test_project.TestActivity;
|
import com.owncloud.android.lib.test_project.TestActivity;
|
||||||
|
|
||||||
import android.test.ActivityInstrumentationTestCase2;
|
import android.test.ActivityInstrumentationTestCase2;
|
||||||
@ -43,9 +42,11 @@ public class ReadFolderTest extends ActivityInstrumentationTestCase2<TestActivit
|
|||||||
private static final String LOG_TAG = ReadFolderTest.class.getCanonicalName();
|
private static final String LOG_TAG = ReadFolderTest.class.getCanonicalName();
|
||||||
|
|
||||||
private static final String FOLDER_PATH = "/folderToRead";
|
private static final String FOLDER_PATH = "/folderToRead";
|
||||||
private static final String FILE1_NAME = "file1.txt";
|
private static final String [] FILE_PATHS = {
|
||||||
private static final String FILE2_NAME = "file2.txt";
|
FOLDER_PATH + "/file1.txt",
|
||||||
private static final String FILE3_NAME = "file3.txt";
|
FOLDER_PATH + "/file2.txt",
|
||||||
|
FOLDER_PATH + "/file3.txt",
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
private TestActivity mActivity;
|
private TestActivity mActivity;
|
||||||
@ -63,16 +64,10 @@ public class ReadFolderTest extends ActivityInstrumentationTestCase2<TestActivit
|
|||||||
File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
|
File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
|
||||||
RemoteOperationResult result = mActivity.createFolder(FOLDER_PATH, true);
|
RemoteOperationResult result = mActivity.createFolder(FOLDER_PATH, true);
|
||||||
if (result.isSuccess()) {
|
if (result.isSuccess()) {
|
||||||
String [] filePaths = {
|
for (int i=0; i<FILE_PATHS.length && result.isSuccess(); i++) {
|
||||||
FOLDER_PATH + FileUtils.PATH_SEPARATOR + FILE1_NAME,
|
|
||||||
FOLDER_PATH + FileUtils.PATH_SEPARATOR + FILE2_NAME,
|
|
||||||
FOLDER_PATH + FileUtils.PATH_SEPARATOR + FILE3_NAME
|
|
||||||
};
|
|
||||||
|
|
||||||
for (int i=0; i<filePaths.length && result.isSuccess(); i++) {
|
|
||||||
result = mActivity.uploadFile(
|
result = mActivity.uploadFile(
|
||||||
textFile.getAbsolutePath(),
|
textFile.getAbsolutePath(),
|
||||||
filePaths[i],
|
FILE_PATHS[i],
|
||||||
"txt/plain");
|
"txt/plain");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,6 @@ import java.util.List;
|
|||||||
import android.test.ActivityInstrumentationTestCase2;
|
import android.test.ActivityInstrumentationTestCase2;
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
import com.owncloud.android.lib.resources.files.FileUtils;
|
|
||||||
import com.owncloud.android.lib.test_project.TestActivity;
|
import com.owncloud.android.lib.test_project.TestActivity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,14 +45,11 @@ public class UploadFileTest extends ActivityInstrumentationTestCase2<TestActivit
|
|||||||
|
|
||||||
private static final String LOG_TAG = UploadFileTest.class.getCanonicalName();
|
private static final String LOG_TAG = UploadFileTest.class.getCanonicalName();
|
||||||
|
|
||||||
private static final String UPLOAD_PATH =
|
private static final String UPLOAD_PATH = "/uploadedImage.png";
|
||||||
FileUtils.PATH_SEPARATOR + TestActivity.ASSETS__IMAGE_FILE_NAME;
|
|
||||||
|
|
||||||
private static final String CHUNKED_UPLOAD_PATH =
|
private static final String CHUNKED_UPLOAD_PATH = "/uploadedVideo.MP4";
|
||||||
FileUtils.PATH_SEPARATOR + TestActivity.ASSETS__VIDEO_FILE_NAME;
|
|
||||||
|
|
||||||
private static final String FILE_NOT_FOUND_PATH =
|
private static final String FILE_NOT_FOUND_PATH = "/notFoundShouldNotBeHere.png";
|
||||||
FileUtils.PATH_SEPARATOR + "fileNotFound.png";
|
|
||||||
|
|
||||||
|
|
||||||
private TestActivity mActivity;
|
private TestActivity mActivity;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user