|
@@ -26,6 +26,7 @@ import com.nextcloud.client.device.BatteryStatus;
|
|
|
import com.nextcloud.client.device.PowerManagementService;
|
|
|
import com.nextcloud.client.network.Connectivity;
|
|
|
import com.nextcloud.client.network.ConnectivityService;
|
|
|
+import com.owncloud.android.datamodel.OCFile;
|
|
|
import com.owncloud.android.datamodel.UploadsStorageManager;
|
|
|
import com.owncloud.android.db.OCUpload;
|
|
|
import com.owncloud.android.files.services.FileUploader;
|
|
@@ -36,10 +37,15 @@ import com.owncloud.android.operations.UploadFileOperation;
|
|
|
import com.owncloud.android.utils.FileStorageUtils;
|
|
|
|
|
|
import org.junit.After;
|
|
|
+import org.junit.Before;
|
|
|
import org.junit.Test;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
|
+import static junit.framework.TestCase.assertEquals;
|
|
|
import static junit.framework.TestCase.assertFalse;
|
|
|
import static junit.framework.TestCase.assertTrue;
|
|
|
|
|
@@ -84,6 +90,12 @@ public class UploadIT extends AbstractOnServerIT {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+ @Before
|
|
|
+ public void before() throws IOException {
|
|
|
+ // make sure that every file is available, even after tests that remove source file
|
|
|
+ createDummyFiles();
|
|
|
+ }
|
|
|
+
|
|
|
@After
|
|
|
public void after() {
|
|
|
RemoteOperationResult result = new RefreshFolderOperation(getStorageManager().getFileByPath("/"),
|
|
@@ -108,7 +120,7 @@ public class UploadIT extends AbstractOnServerIT {
|
|
|
|
|
|
@Test
|
|
|
public void testEmptyUpload() {
|
|
|
- OCUpload ocUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/empty.txt",
|
|
|
+ OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt",
|
|
|
FOLDER + "empty.txt",
|
|
|
account.name);
|
|
|
|
|
@@ -117,7 +129,7 @@ public class UploadIT extends AbstractOnServerIT {
|
|
|
|
|
|
@Test
|
|
|
public void testNonEmptyUpload() {
|
|
|
- OCUpload ocUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt",
|
|
|
+ OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt",
|
|
|
FOLDER + "nonEmpty.txt",
|
|
|
account.name);
|
|
|
|
|
@@ -125,46 +137,87 @@ public class UploadIT extends AbstractOnServerIT {
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void testChunkedUpload() {
|
|
|
- OCUpload ocUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/chunkedFile.txt",
|
|
|
- FOLDER + "chunkedFile.txt", account.name);
|
|
|
+ public void testUploadWithCopy() {
|
|
|
+ OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt",
|
|
|
+ FOLDER + "nonEmpty.txt",
|
|
|
+ account.name);
|
|
|
|
|
|
- uploadOCUpload(ocUpload);
|
|
|
+ uploadOCUpload(ocUpload, FileUploader.LOCAL_BEHAVIOUR_COPY);
|
|
|
+
|
|
|
+ File originalFile = new File(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt");
|
|
|
+ OCFile uploadedFile = fileDataStorageManager.getFileByDecryptedRemotePath(FOLDER + "nonEmpty.txt");
|
|
|
+
|
|
|
+ assertTrue(originalFile.exists());
|
|
|
+ assertTrue(new File(uploadedFile.getStoragePath()).exists());
|
|
|
+ verifyStoragePath(uploadedFile);
|
|
|
}
|
|
|
|
|
|
- public RemoteOperationResult testUpload(OCUpload ocUpload) {
|
|
|
- UploadFileOperation newUpload = new UploadFileOperation(
|
|
|
- uploadsStorageManager,
|
|
|
- connectivityServiceMock,
|
|
|
- powerManagementServiceMock,
|
|
|
- user,
|
|
|
- null,
|
|
|
- ocUpload,
|
|
|
- FileUploader.NameCollisionPolicy.DEFAULT,
|
|
|
- FileUploader.LOCAL_BEHAVIOUR_COPY,
|
|
|
- targetContext,
|
|
|
- false,
|
|
|
- false
|
|
|
- );
|
|
|
- newUpload.addRenameUploadListener(() -> {
|
|
|
- // dummy
|
|
|
- });
|
|
|
+ @Test
|
|
|
+ public void testUploadWithMove() {
|
|
|
+ OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt",
|
|
|
+ FOLDER + "nonEmpty.txt",
|
|
|
+ account.name);
|
|
|
|
|
|
- newUpload.setRemoteFolderToBeCreated();
|
|
|
+ uploadOCUpload(ocUpload, FileUploader.LOCAL_BEHAVIOUR_MOVE);
|
|
|
+
|
|
|
+ File originalFile = new File(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt");
|
|
|
+ OCFile uploadedFile = fileDataStorageManager.getFileByDecryptedRemotePath(FOLDER + "nonEmpty.txt");
|
|
|
+
|
|
|
+ assertFalse(originalFile.exists());
|
|
|
+ assertTrue(new File(uploadedFile.getStoragePath()).exists());
|
|
|
+ verifyStoragePath(uploadedFile);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testUploadWithForget() {
|
|
|
+ OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt",
|
|
|
+ FOLDER + "nonEmpty.txt",
|
|
|
+ account.name);
|
|
|
+
|
|
|
+ uploadOCUpload(ocUpload, FileUploader.LOCAL_BEHAVIOUR_FORGET);
|
|
|
+
|
|
|
+ File originalFile = new File(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt");
|
|
|
+ OCFile uploadedFile = fileDataStorageManager.getFileByDecryptedRemotePath(FOLDER + "nonEmpty.txt");
|
|
|
+
|
|
|
+ assertTrue(originalFile.exists());
|
|
|
+ assertFalse(new File(uploadedFile.getStoragePath()).exists());
|
|
|
+ assertTrue(uploadedFile.getStoragePath().isEmpty());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testUploadWithDelete() {
|
|
|
+ OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt",
|
|
|
+ FOLDER + "nonEmpty.txt",
|
|
|
+ account.name);
|
|
|
+
|
|
|
+ uploadOCUpload(ocUpload, FileUploader.LOCAL_BEHAVIOUR_DELETE);
|
|
|
+
|
|
|
+ File originalFile = new File(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt");
|
|
|
+ OCFile uploadedFile = fileDataStorageManager.getFileByDecryptedRemotePath(FOLDER + "nonEmpty.txt");
|
|
|
+
|
|
|
+ assertFalse(originalFile.exists());
|
|
|
+ assertFalse(new File(uploadedFile.getStoragePath()).exists());
|
|
|
+ assertTrue(uploadedFile.getStoragePath().isEmpty());
|
|
|
+ }
|
|
|
|
|
|
- return newUpload.execute(client, getStorageManager());
|
|
|
+ @Test
|
|
|
+ public void testChunkedUpload() {
|
|
|
+ OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/chunkedFile.txt",
|
|
|
+ FOLDER + "chunkedFile.txt", account.name);
|
|
|
+
|
|
|
+ uploadOCUpload(ocUpload);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testUploadInNonExistingFolder() {
|
|
|
- OCUpload ocUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/empty.txt",
|
|
|
+ OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt",
|
|
|
FOLDER + "2/3/4/1.txt", account.name);
|
|
|
|
|
|
uploadOCUpload(ocUpload);
|
|
|
}
|
|
|
@Test
|
|
|
public void testUploadOnChargingOnlyButNotCharging() {
|
|
|
- OCUpload ocUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/empty.txt",
|
|
|
+ OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt",
|
|
|
FOLDER + "notCharging.txt", account.name);
|
|
|
ocUpload.setWhileChargingOnly(true);
|
|
|
|
|
@@ -210,7 +263,7 @@ public class UploadIT extends AbstractOnServerIT {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- OCUpload ocUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/empty.txt",
|
|
|
+ OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt",
|
|
|
FOLDER + "charging.txt", account.name);
|
|
|
ocUpload.setWhileChargingOnly(true);
|
|
|
|
|
@@ -249,7 +302,7 @@ public class UploadIT extends AbstractOnServerIT {
|
|
|
return new Connectivity(true, false, false, true);
|
|
|
}
|
|
|
};
|
|
|
- OCUpload ocUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/empty.txt",
|
|
|
+ OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt",
|
|
|
FOLDER + "noWifi.txt", account.name);
|
|
|
ocUpload.setUseWifiOnly(true);
|
|
|
|
|
@@ -277,7 +330,7 @@ public class UploadIT extends AbstractOnServerIT {
|
|
|
|
|
|
@Test
|
|
|
public void testUploadOnWifiOnlyAndWifi() {
|
|
|
- OCUpload ocUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/empty.txt",
|
|
|
+ OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt",
|
|
|
FOLDER + "wifi.txt", account.name);
|
|
|
ocUpload.setWhileChargingOnly(true);
|
|
|
|
|
@@ -310,4 +363,9 @@ public class UploadIT extends AbstractOnServerIT {
|
|
|
targetContext)
|
|
|
.execute(client, getStorageManager());
|
|
|
}
|
|
|
+
|
|
|
+ private void verifyStoragePath(OCFile file) {
|
|
|
+ assertEquals(FileStorageUtils.getSavePath(account.name) + FOLDER + file.getDecryptedFileName(),
|
|
|
+ file.getStoragePath());
|
|
|
+ }
|
|
|
}
|