1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-07 16:06:08 +00:00

Let the setup() - testXXX() - tearDown() flow normally

This commit is contained in:
David A. Velasco 2014-11-17 12:34:17 +01:00
parent fcf3bd2769
commit a5a2b2890f
3 changed files with 48 additions and 83 deletions

View File

@ -30,8 +30,6 @@ 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.test_project.TestActivity; import com.owncloud.android.lib.test_project.TestActivity;
import android.util.Log;
/** /**
* Class to test Delete a File Operation * Class to test Delete a File Operation
* @author masensio * @author masensio
@ -48,8 +46,6 @@ public class DeleteFileTest extends RemoteTest {
/* File to delete. */ /* File to delete. */
private static final String FILE_PATH = "/fileToDelete.txt"; private static final String FILE_PATH = "/fileToDelete.txt";
private static boolean mGlobalSetupDone = false;
private TestActivity mActivity; private TestActivity mActivity;
private String mFullPath2Folder; private String mFullPath2Folder;
private String mFullPath2File; private String mFullPath2File;
@ -62,26 +58,19 @@ public class DeleteFileTest extends RemoteTest {
mFullPath2Folder = mBaseFolderPath + FOLDER_PATH; mFullPath2Folder = mBaseFolderPath + FOLDER_PATH;
mFullPath2File = mBaseFolderPath + FILE_PATH; mFullPath2File = mBaseFolderPath + FILE_PATH;
if (!mGlobalSetupDone) { RemoteOperationResult result = mActivity.createFolder(mFullPath2Folder, true);
if (!result.isSuccess() && result.getCode() != ResultCode.TIMEOUT) {
Log.v(LOG_TAG, "Starting global set up"); Utils.logAndThrow(LOG_TAG, result);
RemoteOperationResult result = mActivity.createFolder(mFullPath2Folder, true); }
if (!result.isSuccess() && result.getCode() != ResultCode.TIMEOUT) {
Utils.logAndThrow(LOG_TAG, result); File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
} result = mActivity.uploadFile(
textFile.getAbsolutePath(),
File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME); mFullPath2File,
result = mActivity.uploadFile( "txt/plain");
textFile.getAbsolutePath(), if (!result.isSuccess()) {
mFullPath2File, Utils.logAndThrow(LOG_TAG, result);
"txt/plain"); }
if (!result.isSuccess()) {
Utils.logAndThrow(LOG_TAG, result);
}
Log.v(LOG_TAG, "Global set up done");
mGlobalSetupDone = true;
}
} }

View File

@ -31,8 +31,6 @@ 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.test_project.TestActivity; import com.owncloud.android.lib.test_project.TestActivity;
import android.util.Log;
/** /**
* Class to test Download File Operation * Class to test Download File Operation
* @author masensio * @author masensio
@ -49,8 +47,6 @@ public class DownloadFileTest extends RemoteTest {
private static final String IMAGE_PATH_WITH_SPECIAL_CHARS = "/@file@download.png"; private static final String IMAGE_PATH_WITH_SPECIAL_CHARS = "/@file@download.png";
private static final String IMAGE_NOT_FOUND = "/fileNotFound.png"; private static final String IMAGE_NOT_FOUND = "/fileNotFound.png";
private static boolean mGlobalSetupDone = false;
private String mFullPath2Image; private String mFullPath2Image;
private String mFullPath2ImageWitSpecialChars; private String mFullPath2ImageWitSpecialChars;
private String mFullPath2ImageNotFound; private String mFullPath2ImageNotFound;
@ -68,35 +64,29 @@ public class DownloadFileTest extends RemoteTest {
mFullPath2ImageWitSpecialChars = mBaseFolderPath + IMAGE_PATH_WITH_SPECIAL_CHARS; mFullPath2ImageWitSpecialChars = mBaseFolderPath + IMAGE_PATH_WITH_SPECIAL_CHARS;
mFullPath2ImageNotFound = mBaseFolderPath + IMAGE_NOT_FOUND; mFullPath2ImageNotFound = mBaseFolderPath + IMAGE_NOT_FOUND;
if (!mGlobalSetupDone) { File imageFile = mActivity.extractAsset(TestActivity.ASSETS__IMAGE_FILE_NAME);
File imageFile = mActivity.extractAsset(TestActivity.ASSETS__IMAGE_FILE_NAME);
RemoteOperationResult result = mActivity.uploadFile( RemoteOperationResult result = mActivity.uploadFile(
imageFile.getAbsolutePath(), imageFile.getAbsolutePath(),
mFullPath2Image, mFullPath2Image,
"image/png"); "image/png");
if (!result.isSuccess()) { if (!result.isSuccess()) {
Utils.logAndThrow(LOG_TAG, result); Utils.logAndThrow(LOG_TAG, result);
} }
result = mActivity.uploadFile( result = mActivity.uploadFile(
imageFile.getAbsolutePath(), imageFile.getAbsolutePath(),
mFullPath2ImageWitSpecialChars, mFullPath2ImageWitSpecialChars,
"image/png"); "image/png");
if (!result.isSuccess()) { if (!result.isSuccess()) {
Utils.logAndThrow(LOG_TAG, result); Utils.logAndThrow(LOG_TAG, result);
} }
result = mActivity.removeFile(mFullPath2ImageNotFound); result = mActivity.removeFile(mFullPath2ImageNotFound);
if (!result.isSuccess() && result.getCode() != ResultCode.FILE_NOT_FOUND) { if (!result.isSuccess() && result.getCode() != ResultCode.FILE_NOT_FOUND) {
Utils.logAndThrow(LOG_TAG, result); Utils.logAndThrow(LOG_TAG, result);
} }
Log.v(LOG_TAG, "Global set up done");
mGlobalSetupDone = true;
}
} }
/** /**

View File

@ -31,8 +31,6 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCo
import com.owncloud.android.lib.resources.files.FileUtils; 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.util.Log;
/** /**
* Class to test Rename File Operation * Class to test Rename File Operation
* @author masensio * @author masensio
@ -56,8 +54,6 @@ public class RenameFileTest extends RemoteTest {
private static final String NEW_FILE_PATH = FileUtils.PATH_SEPARATOR + NEW_FILE_NAME; private static final String NEW_FILE_PATH = FileUtils.PATH_SEPARATOR + NEW_FILE_NAME;
private static boolean mGlobalSetupDone = false;
private String mToCleanUpInServer; private String mToCleanUpInServer;
private TestActivity mActivity; private TestActivity mActivity;
private String mFullPath2OldFolder; private String mFullPath2OldFolder;
@ -74,28 +70,20 @@ public class RenameFileTest extends RemoteTest {
mFullPath2NewFolder = mBaseFolderPath + NEW_FOLDER_PATH; mFullPath2NewFolder = mBaseFolderPath + NEW_FOLDER_PATH;
mFullPath2OldFile = mBaseFolderPath + OLD_FILE_PATH; mFullPath2OldFile = mBaseFolderPath + OLD_FILE_PATH;
mFullPath2NewFile = mBaseFolderPath + NEW_FILE_PATH; mFullPath2NewFile = mBaseFolderPath + NEW_FILE_PATH;
if (!mGlobalSetupDone) { RemoteOperationResult result = mActivity.createFolder(mFullPath2OldFolder, true);
if (!result.isSuccess() && result.getCode() != ResultCode.TIMEOUT) {
Log.v(LOG_TAG, "Starting global set up"); Utils.logAndThrow(LOG_TAG, result);
RemoteOperationResult result = mActivity.createFolder(mFullPath2OldFolder, true); }
if (!result.isSuccess() && result.getCode() != ResultCode.TIMEOUT) {
Utils.logAndThrow(LOG_TAG, result); File imageFile = mActivity.extractAsset(TestActivity.ASSETS__IMAGE_FILE_NAME);
} result = mActivity.uploadFile(
imageFile.getAbsolutePath(),
File imageFile = mActivity.extractAsset(TestActivity.ASSETS__IMAGE_FILE_NAME); mFullPath2OldFile,
result = mActivity.uploadFile( "image/png");
imageFile.getAbsolutePath(), if (!result.isSuccess()) {
mFullPath2OldFile, Utils.logAndThrow(LOG_TAG, result);
"image/png"); }
if (!result.isSuccess()) {
Utils.logAndThrow(LOG_TAG, result);
}
Log.v(LOG_TAG, "Global set up done");
mGlobalSetupDone = true;
}
mToCleanUpInServer = null; mToCleanUpInServer = null;
} }
@ -232,14 +220,12 @@ public class RenameFileTest extends RemoteTest {
@Override @Override
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
/*
if (mToCleanUpInServer != null) { if (mToCleanUpInServer != null) {
RemoteOperationResult removeResult = mActivity.removeFile(mToCleanUpInServer); RemoteOperationResult removeResult = mActivity.removeFile(mToCleanUpInServer);
if (!removeResult.isSuccess()) { if (!removeResult.isSuccess()) {
Utils.logAndThrow(LOG_TAG, removeResult); Utils.logAndThrow(LOG_TAG, removeResult);
} }
} }
*/
super.tearDown(); super.tearDown();
} }