mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +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;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
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 android.test.ActivityInstrumentationTestCase2;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* Class to test Delete a File Operation
|
||||
@ -38,17 +40,20 @@ import android.test.ActivityInstrumentationTestCase2;
|
||||
|
||||
public class DeleteFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
|
||||
|
||||
private static final String LOG_TAG = DeleteFileTest.class.getCanonicalName();
|
||||
|
||||
/* Folder data to delete. */
|
||||
private final String mFolderPath = "/folderToDelete";
|
||||
private static final String FOLDER_PATH = "/folderToDelete";
|
||||
|
||||
/* 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;
|
||||
|
||||
public DeleteFileTest() {
|
||||
super(TestActivity.class);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -56,6 +61,28 @@ public class DeleteFileTest extends ActivityInstrumentationTestCase2<TestActivit
|
||||
super.setUp();
|
||||
setActivityInitialTouchMode(false);
|
||||
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() {
|
||||
|
||||
RemoteOperationResult result = mActivity.removeFile(mFolderPath);
|
||||
assertTrue(result.isSuccess() || result.getCode() == ResultCode.FILE_NOT_FOUND);
|
||||
RemoteOperationResult result = mActivity.removeFile(FOLDER_PATH);
|
||||
assertTrue(result.isSuccess());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -72,16 +99,17 @@ public class DeleteFileTest extends ActivityInstrumentationTestCase2<TestActivit
|
||||
*/
|
||||
public void testRemoveFile() {
|
||||
|
||||
RemoteOperationResult result = mActivity.removeFile(mFilePath);
|
||||
assertTrue(result.isSuccess() || result.getCode() == ResultCode.FILE_NOT_FOUND);
|
||||
RemoteOperationResult result = mActivity.removeFile(FILE_PATH);
|
||||
assertTrue(result.isSuccess());
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore initial conditions
|
||||
*/
|
||||
public void testRestoreInitialConditions() {
|
||||
RemoteOperationResult result = mActivity.createFolder(mFolderPath, true);
|
||||
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 com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.resources.files.FileUtils;
|
||||
import com.owncloud.android.lib.test_project.TestActivity;
|
||||
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
@ -43,7 +42,7 @@ public class ReadFileTest extends ActivityInstrumentationTestCase2<TestActivity
|
||||
|
||||
private TestActivity mActivity;
|
||||
|
||||
private String mFilePath;
|
||||
private String FILE_PATH = "/fileToRead.txt";
|
||||
|
||||
public ReadFileTest() {
|
||||
super(TestActivity.class);
|
||||
@ -55,12 +54,11 @@ public class ReadFileTest extends ActivityInstrumentationTestCase2<TestActivity
|
||||
|
||||
setActivityInitialTouchMode(false);
|
||||
mActivity = getActivity();
|
||||
mFilePath = FileUtils.PATH_SEPARATOR + TestActivity.ASSETS__TEXT_FILE_NAME;
|
||||
|
||||
File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
|
||||
RemoteOperationResult uploadResult = mActivity.uploadFile(
|
||||
textFile.getAbsolutePath(),
|
||||
mFilePath,
|
||||
FILE_PATH,
|
||||
"txt/plain");
|
||||
if (!uploadResult.isSuccess()) {
|
||||
Utils.logAndThrow(LOG_TAG, uploadResult);
|
||||
@ -71,7 +69,7 @@ public class ReadFileTest extends ActivityInstrumentationTestCase2<TestActivity
|
||||
* Test Read File
|
||||
*/
|
||||
public void testReadFile() {
|
||||
RemoteOperationResult result = mActivity.readFile(mFilePath);
|
||||
RemoteOperationResult result = mActivity.readFile(FILE_PATH);
|
||||
assertTrue(result.getData() != null && result.getData().size() == 1);
|
||||
assertTrue(result.isSuccess());
|
||||
// TODO check more properties of the result
|
||||
@ -79,7 +77,7 @@ public class ReadFileTest extends ActivityInstrumentationTestCase2<TestActivity
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
RemoteOperationResult removeResult = mActivity.removeFile(mFilePath);
|
||||
RemoteOperationResult removeResult = mActivity.removeFile(FILE_PATH);
|
||||
if (!removeResult.isSuccess()) {
|
||||
Utils.logAndThrow(LOG_TAG, removeResult);
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ 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.resources.files.FileUtils;
|
||||
import com.owncloud.android.lib.test_project.TestActivity;
|
||||
|
||||
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 FOLDER_PATH = "/folderToRead";
|
||||
private static final String FILE1_NAME = "file1.txt";
|
||||
private static final String FILE2_NAME = "file2.txt";
|
||||
private static final String FILE3_NAME = "file3.txt";
|
||||
private static final String [] FILE_PATHS = {
|
||||
FOLDER_PATH + "/file1.txt",
|
||||
FOLDER_PATH + "/file2.txt",
|
||||
FOLDER_PATH + "/file3.txt",
|
||||
};
|
||||
|
||||
|
||||
private TestActivity mActivity;
|
||||
@ -63,16 +64,10 @@ public class ReadFolderTest extends ActivityInstrumentationTestCase2<TestActivit
|
||||
File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
|
||||
RemoteOperationResult result = mActivity.createFolder(FOLDER_PATH, true);
|
||||
if (result.isSuccess()) {
|
||||
String [] filePaths = {
|
||||
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++) {
|
||||
for (int i=0; i<FILE_PATHS.length && result.isSuccess(); i++) {
|
||||
result = mActivity.uploadFile(
|
||||
textFile.getAbsolutePath(),
|
||||
filePaths[i],
|
||||
FILE_PATHS[i],
|
||||
"txt/plain");
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,6 @@ import java.util.List;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.resources.files.FileUtils;
|
||||
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 UPLOAD_PATH =
|
||||
FileUtils.PATH_SEPARATOR + TestActivity.ASSETS__IMAGE_FILE_NAME;
|
||||
private static final String UPLOAD_PATH = "/uploadedImage.png";
|
||||
|
||||
private static final String CHUNKED_UPLOAD_PATH =
|
||||
FileUtils.PATH_SEPARATOR + TestActivity.ASSETS__VIDEO_FILE_NAME;
|
||||
private static final String CHUNKED_UPLOAD_PATH = "/uploadedVideo.MP4";
|
||||
|
||||
private static final String FILE_NOT_FOUND_PATH =
|
||||
FileUtils.PATH_SEPARATOR + "fileNotFound.png";
|
||||
private static final String FILE_NOT_FOUND_PATH = "/notFoundShouldNotBeHere.png";
|
||||
|
||||
|
||||
private TestActivity mActivity;
|
||||
|
Loading…
x
Reference in New Issue
Block a user