- fix dummy storage location

- dummy files are re-created if needed

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2020-07-31 10:09:20 +02:00
parent 7f339f9fe0
commit e9733ad744
No known key found for this signature in database
GPG Key ID: 0E00D4D47D0C5AF7
7 changed files with 61 additions and 38 deletions

View File

@ -185,7 +185,47 @@ public abstract class AbstractIT {
return AccountManager.get(targetContext).getAccounts();
}
protected static void createDummyFiles() throws IOException {
File tempPath = new File(FileStorageUtils.getTemporalPath(account.name));
if (!tempPath.exists()) {
assertTrue(tempPath.mkdirs());
}
assertTrue(tempPath.exists());
createFile("empty.txt", 0);
createFile("nonEmpty.txt", 100);
createFile("chunkedFile.txt", 500000);
}
protected static File getDummyFile(String name) throws IOException {
File file = new File(FileStorageUtils.getTemporalPath(account.name) + File.pathSeparator + name);
if (file.exists()) {
return file;
} else {
switch (name) {
case "empty.txt":
return createFile("empty.txt", 0);
case "nonEmpty.txt":
return createFile("nonEmpty.txt", 100);
case "chunkedFile.txt":
return createFile("chunkedFile.txt", 500000);
default:
return createFile(name, 0);
}
}
}
public static File createFile(String name, int iteration) throws IOException {
File tempPath = new File(FileStorageUtils.getTemporalPath(account.name));
if (!tempPath.exists()) {
assertTrue(tempPath.mkdirs());
}
File file = new File(FileStorageUtils.getTemporalPath(account.name) + File.separator + name);
file.createNewFile();

View File

@ -30,7 +30,6 @@ import com.owncloud.android.lib.resources.files.RemoveFileRemoteOperation;
import com.owncloud.android.lib.resources.files.model.RemoteFile;
import com.owncloud.android.operations.RefreshFolderOperation;
import com.owncloud.android.operations.UploadFileOperation;
import com.owncloud.android.utils.FileStorageUtils;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
@ -141,19 +140,6 @@ public abstract class AbstractOnServerIT extends AbstractIT {
}
}
protected static void createDummyFiles() throws IOException {
File tempPath = new File(FileStorageUtils.getTemporalPath(account.name));
if (!tempPath.exists()) {
assertTrue(tempPath.mkdirs());
}
assertTrue(tempPath.exists());
createFile("empty.txt", 0);
createFile("nonEmpty.txt", 100);
createFile("chunkedFile.txt", 500000);
}
private static void waitForServer(OwnCloudClient client, Uri baseUrl) {
GetMethod get = new GetMethod(baseUrl + "/status.php");

View File

@ -89,13 +89,13 @@ abstract public class FileDataStorageManagerTest extends AbstractOnServerIT {
assertTrue(new CreateFolderRemoteOperation("/1/2/", true).execute(client).isSuccess());
assertTrue(new UploadFileRemoteOperation(FileStorageUtils.getSavePath(account.name) + "/chunkedFile.txt",
assertTrue(new UploadFileRemoteOperation(getDummyFile("/chunkedFile.txt").getAbsolutePath(),
"/1/1/chunkedFile.txt",
"text/plain",
String.valueOf(System.currentTimeMillis() / 1000))
.execute(client).isSuccess());
assertTrue(new UploadFileRemoteOperation(FileStorageUtils.getSavePath(account.name) + "/chunkedFile.txt",
assertTrue(new UploadFileRemoteOperation(getDummyFile("/chunkedFile.txt").getAbsolutePath(),
"/1/1/chunkedFile2.txt",
"text/plain",
String.valueOf(System.currentTimeMillis() / 1000))

View File

@ -35,13 +35,11 @@ import com.owncloud.android.db.OCUpload
import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation
import com.owncloud.android.lib.resources.files.model.RemoteFile
import com.owncloud.android.operations.UploadFileOperation
import com.owncloud.android.utils.FileStorageUtils.getSavePath
import junit.framework.Assert.assertEquals
import junit.framework.Assert.assertFalse
import junit.framework.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import java.io.File
class FileUploaderIT : AbstractOnServerIT() {
var uploadsStorageManager: UploadsStorageManager? = null
@ -74,7 +72,7 @@ class FileUploaderIT : AbstractOnServerIT() {
*/
@Test
fun testKeepLocalAndOverwriteRemote() {
val file = File(getSavePath(account.name) + "/chunkedFile.txt")
val file = getDummyFile("/chunkedFile.txt")
val ocUpload = OCUpload(file.absolutePath, "/testFile.txt", account.name)
assertTrue(
@ -101,7 +99,7 @@ class FileUploaderIT : AbstractOnServerIT() {
assertEquals(file.length(), (result.data[0] as RemoteFile).length)
val ocUpload2 = OCUpload(getSavePath(account.name) + "/empty.txt", "/testFile.txt", account.name)
val ocUpload2 = OCUpload(getDummyFile("/empty.txt").absolutePath, "/testFile.txt", account.name)
assertTrue(
UploadFileOperation(
@ -132,7 +130,7 @@ class FileUploaderIT : AbstractOnServerIT() {
*/
@Test
fun testKeepLocalAndOverwriteRemoteStatic() {
val file = File(getSavePath(account.name) + "/chunkedFile.txt")
val file = getDummyFile("/chunkedFile.txt")
FileUploader.uploadNewFile(
targetContext,
@ -156,7 +154,7 @@ class FileUploaderIT : AbstractOnServerIT() {
assertEquals(file.length(), (result.data[0] as RemoteFile).length)
val ocFile2 = OCFile("/testFile.txt")
ocFile2.setStoragePath(getSavePath(account.name) + "/empty.txt")
ocFile2.setStoragePath(getDummyFile("/empty.txt").absolutePath)
FileUploader.uploadUpdateFile(
targetContext,
@ -181,7 +179,7 @@ class FileUploaderIT : AbstractOnServerIT() {
fun testKeepBoth() {
var renameListenerWasTriggered = false
val file = File(getSavePath(account.name) + "/chunkedFile.txt")
val file = getDummyFile("/chunkedFile.txt")
val ocUpload = OCUpload(file.absolutePath, "/testFile.txt", account.name)
assertTrue(
@ -208,7 +206,7 @@ class FileUploaderIT : AbstractOnServerIT() {
assertEquals(file.length(), (result.data[0] as RemoteFile).length)
val file2 = File(getSavePath(account.name) + "/empty.txt")
val file2 = getDummyFile("empty.txt")
val ocUpload2 = OCUpload(file2.absolutePath, "/testFile.txt", account.name)
assertTrue(
@ -249,7 +247,7 @@ class FileUploaderIT : AbstractOnServerIT() {
*/
@Test
fun testKeepBothStatic() {
val file = File(getSavePath(account.name) + "/chunkedFile.txt")
val file = getDummyFile("/chunkedFile.txt")
FileUploader.uploadNewFile(
targetContext,
@ -273,7 +271,7 @@ class FileUploaderIT : AbstractOnServerIT() {
assertEquals(file.length(), (result.data[0] as RemoteFile).length)
val ocFile2 = OCFile("/testFile.txt")
ocFile2.setStoragePath(getSavePath(account.name) + "/empty.txt")
ocFile2.setStoragePath(getDummyFile("/empty.txt").absolutePath)
FileUploader.uploadUpdateFile(
targetContext,
@ -301,7 +299,7 @@ class FileUploaderIT : AbstractOnServerIT() {
*/
@Test
fun testKeepServer() {
val file = File(getSavePath(account.name) + "/chunkedFile.txt")
val file = getDummyFile("/chunkedFile.txt")
val ocUpload = OCUpload(file.absolutePath, "/testFile.txt", account.name)
assertTrue(
@ -328,7 +326,7 @@ class FileUploaderIT : AbstractOnServerIT() {
assertEquals(file.length(), (result.data[0] as RemoteFile).length)
val ocUpload2 = OCUpload(getSavePath(account.name) + "/empty.txt", "/testFile.txt", account.name)
val ocUpload2 = OCUpload(getDummyFile("/empty.txt").absolutePath, "/testFile.txt", account.name)
assertFalse(
UploadFileOperation(
@ -358,7 +356,7 @@ class FileUploaderIT : AbstractOnServerIT() {
*/
@Test
fun testKeepServerStatic() {
val file = File(getSavePath(account.name) + "/chunkedFile.txt")
val file = getDummyFile("/chunkedFile.txt")
FileUploader.uploadNewFile(
targetContext,
@ -382,7 +380,7 @@ class FileUploaderIT : AbstractOnServerIT() {
assertEquals(file.length(), (result.data[0] as RemoteFile).length)
val ocFile2 = OCFile("/testFile.txt")
ocFile2.setStoragePath(getSavePath(account.name) + "/empty.txt")
ocFile2.setStoragePath(getDummyFile("/empty.txt").absolutePath)
FileUploader.uploadUpdateFile(
targetContext,

View File

@ -25,10 +25,11 @@ package com.owncloud.android.operations;
import com.owncloud.android.AbstractOnServerIT;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.db.OCUpload;
import com.owncloud.android.utils.FileStorageUtils;
import org.junit.Test;
import java.io.IOException;
import static junit.framework.TestCase.assertNotNull;
import static junit.framework.TestCase.assertTrue;
@ -65,10 +66,10 @@ public class RemoveFileOperationIT extends AbstractOnServerIT {
}
@Test
public void deleteFile() {
public void deleteFile() throws IOException {
String parent = "/test/";
String path = parent + "empty.txt";
OCUpload ocUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/empty.txt", path, account.name);
OCUpload ocUpload = new OCUpload(getDummyFile("/empty.txt").getAbsolutePath(), path, account.name);
uploadOCUpload(ocUpload);

View File

@ -47,7 +47,6 @@ import com.owncloud.android.operations.CreateFolderOperation
import com.owncloud.android.operations.RefreshFolderOperation
import com.owncloud.android.operations.UploadFileOperation
import com.owncloud.android.ui.activity.FileDisplayActivity
import com.owncloud.android.utils.FileStorageUtils
import junit.framework.TestCase
import org.junit.Assert.assertTrue
import org.junit.Rule
@ -92,7 +91,7 @@ class OCFileListFragmentIT : AbstractOnServerIT() {
assertTrue(CreateFolderOperation("/test/", user, targetContext).execute(client, storageManager).isSuccess)
val ocUpload = OCUpload(
FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt",
getDummyFile("/nonEmpty.txt").absolutePath,
"/test/Readme.md",
account.name
)

View File

@ -27,7 +27,6 @@ import android.Manifest;
import com.owncloud.android.AbstractIT;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.utils.FileStorageUtils;
import com.owncloud.android.utils.MimeTypeUtil;
import org.junit.Rule;
@ -50,12 +49,12 @@ public class PreviewTextFileFragmentTest extends AbstractIT {
@Test
// @ScreenshotTest // todo run without real server
public void displaySimpleTextFile() {
public void displaySimpleTextFile() throws IOException {
FileDisplayActivity sut = activityRule.launchActivity(null);
shortSleep();
File file = new File(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt");
File file = getDummyFile("nonEmpty.txt");
OCFile test = new OCFile("/text.md");
test.setMimeType(MimeTypeUtil.MIMETYPE_TEXT_MARKDOWN);
test.setStoragePath(file.getAbsolutePath());