add tests

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2020-10-02 16:10:17 +02:00
parent b408c74b04
commit 6a5f5f4c41
No known key found for this signature in database
GPG key ID: 0E00D4D47D0C5AF7
2 changed files with 111 additions and 6 deletions

View file

@ -32,6 +32,7 @@ import com.owncloud.android.AbstractOnServerIT
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.datamodel.UploadsStorageManager
import com.owncloud.android.db.OCUpload
import com.owncloud.android.lib.common.operations.OperationCancelledException
import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation
import com.owncloud.android.lib.resources.files.model.RemoteFile
import com.owncloud.android.operations.UploadFileOperation
@ -397,4 +398,109 @@ class FileUploaderIT : AbstractOnServerIT() {
assertEquals(file.length(), (result2.data[0] as RemoteFile).length)
}
/**
* uploads a file with "skip if exists" option set, so do nothing if file exists
*/
@Test
fun testCancelServer() {
val file = getDummyFile("/chunkedFile.txt")
val ocUpload = OCUpload(file.absolutePath, "/testFile.txt", account.name)
assertTrue(
UploadFileOperation(
uploadsStorageManager,
connectivityServiceMock,
powerManagementServiceMock,
user,
null,
ocUpload,
FileUploader.NameCollisionPolicy.CANCEL,
FileUploader.LOCAL_BEHAVIOUR_COPY,
targetContext,
false,
false
)
.setRemoteFolderToBeCreated()
.execute(client, storageManager)
.isSuccess
)
val result = ReadFileRemoteOperation("/testFile.txt").execute(client)
assertTrue(result.isSuccess)
assertEquals(file.length(), (result.data[0] as RemoteFile).length)
val ocUpload2 = OCUpload(getDummyFile("/empty.txt").absolutePath, "/testFile.txt", account.name)
val uploadResult = UploadFileOperation(
uploadsStorageManager,
connectivityServiceMock,
powerManagementServiceMock,
user,
null,
ocUpload2,
FileUploader.NameCollisionPolicy.CANCEL,
FileUploader.LOCAL_BEHAVIOUR_COPY,
targetContext,
false,
false
)
.execute(client, storageManager)
assertFalse(uploadResult.isSuccess)
assertTrue(uploadResult.exception is OperationCancelledException)
val result2 = ReadFileRemoteOperation("/testFile.txt").execute(client)
assertTrue(result2.isSuccess)
assertEquals(file.length(), (result2.data[0] as RemoteFile).length)
}
/**
* uploads a file with "skip if exists" option set, so do nothing if file exists
*/
@Test
fun testKeepCancelStatic() {
val file = getDummyFile("/chunkedFile.txt")
FileUploader.uploadNewFile(
targetContext,
account,
file.absolutePath,
"/testFile.txt",
FileUploader.LOCAL_BEHAVIOUR_COPY,
null,
true,
UploadFileOperation.CREATED_BY_USER,
false,
false,
FileUploader.NameCollisionPolicy.DEFAULT
)
longSleep()
val result = ReadFileRemoteOperation("/testFile.txt").execute(client)
assertTrue(result.isSuccess)
assertEquals(file.length(), (result.data[0] as RemoteFile).length)
val ocFile2 = OCFile("/testFile.txt")
ocFile2.setStoragePath(getDummyFile("/empty.txt").absolutePath)
FileUploader.uploadUpdateFile(
targetContext,
account,
ocFile2,
FileUploader.LOCAL_BEHAVIOUR_COPY,
FileUploader.NameCollisionPolicy.CANCEL
)
shortSleep()
val result2 = ReadFileRemoteOperation("/testFile.txt").execute(client)
assertTrue(result2.isSuccess)
assertEquals(file.length(), (result2.data[0] as RemoteFile).length)
}
}

View file

@ -26,7 +26,6 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.text.style.StyleSpan;
@ -113,11 +112,11 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
}
@Override
public void onAttach(Activity activity) {
public void onAttach(@NonNull Activity activity) {
super.onAttach(activity);
if (!(activity instanceof OnSyncedFolderPreferenceListener)) {
throw new IllegalArgumentException("The host activity must implement "
+ OnSyncedFolderPreferenceListener.class.getCanonicalName());
+ OnSyncedFolderPreferenceListener.class.getCanonicalName());
}
}
@ -601,9 +600,9 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
}
/**
* Get index for name collision selection dialog.
* Inverse of getSelectionIndexForNameCollisionPolicy.
* @return ASK_USER if 0, OVERWRITE if 1, RENAME if 2, SKIP if 3. Otherwise: ASK_USEr
* Get index for name collision selection dialog. Inverse of getSelectionIndexForNameCollisionPolicy.
*
* @return ASK_USER if 0, OVERWRITE if 1, RENAME if 2, SKIP if 3. Otherwise: ASK_USER
*/
static private FileUploader.NameCollisionPolicy getNameCollisionPolicyForSelectionIndex(int index) {
switch (index) {