Search in sources :

Example 36 with OCUpload

use of com.owncloud.android.db.OCUpload in project android by nextcloud.

the class UploadIT method testUploadOnWifiOnlyButMeteredWifi.

@Test
public void testUploadOnWifiOnlyButMeteredWifi() {
    ConnectivityService connectivityServiceMock = new ConnectivityService() {

        @Override
        public boolean isInternetWalled() {
            return false;
        }

        @Override
        public Connectivity getConnectivity() {
            return new Connectivity(true, true, true, true);
        }
    };
    OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt", FOLDER + "noWifi.txt", account.name);
    ocUpload.setUseWifiOnly(true);
    UploadFileOperation newUpload = new UploadFileOperation(uploadsStorageManager, connectivityServiceMock, powerManagementServiceMock, user, null, ocUpload, NameCollisionPolicy.DEFAULT, FileUploader.LOCAL_BEHAVIOUR_COPY, targetContext, true, false, getStorageManager());
    newUpload.setRemoteFolderToBeCreated();
    newUpload.addRenameUploadListener(() -> {
    // dummy
    });
    RemoteOperationResult result = newUpload.execute(client);
    assertFalse(result.toString(), result.isSuccess());
    assertEquals(RemoteOperationResult.ResultCode.DELAYED_FOR_WIFI, result.getCode());
}
Also used : OCUpload(com.owncloud.android.db.OCUpload) ConnectivityService(com.nextcloud.client.network.ConnectivityService) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) Connectivity(com.nextcloud.client.network.Connectivity) UploadFileOperation(com.owncloud.android.operations.UploadFileOperation) Test(org.junit.Test)

Example 37 with OCUpload

use of com.owncloud.android.db.OCUpload in project android by nextcloud.

the class UploadIT method testUploadOnChargingOnlyButNotCharging.

@Test
public void testUploadOnChargingOnlyButNotCharging() {
    OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt", FOLDER + "notCharging.txt", account.name);
    ocUpload.setWhileChargingOnly(true);
    UploadFileOperation newUpload = new UploadFileOperation(uploadsStorageManager, connectivityServiceMock, powerManagementServiceMock, user, null, ocUpload, NameCollisionPolicy.DEFAULT, FileUploader.LOCAL_BEHAVIOUR_COPY, targetContext, false, true, getStorageManager());
    newUpload.setRemoteFolderToBeCreated();
    newUpload.addRenameUploadListener(() -> {
    // dummy
    });
    RemoteOperationResult result = newUpload.execute(client);
    assertFalse(result.toString(), result.isSuccess());
    assertEquals(RemoteOperationResult.ResultCode.DELAYED_FOR_CHARGING, result.getCode());
}
Also used : OCUpload(com.owncloud.android.db.OCUpload) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) UploadFileOperation(com.owncloud.android.operations.UploadFileOperation) Test(org.junit.Test)

Example 38 with OCUpload

use of com.owncloud.android.db.OCUpload in project android by nextcloud.

the class UploadIT method testUploadInNonExistingFolder.

@Test
public void testUploadInNonExistingFolder() {
    OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt", FOLDER + "2/3/4/1.txt", account.name);
    uploadOCUpload(ocUpload);
}
Also used : OCUpload(com.owncloud.android.db.OCUpload) Test(org.junit.Test)

Example 39 with OCUpload

use of com.owncloud.android.db.OCUpload in project android by nextcloud.

the class UploadIT method testEmptyUpload.

@Test
public void testEmptyUpload() {
    OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt", FOLDER + "empty.txt", account.name);
    uploadOCUpload(ocUpload);
}
Also used : OCUpload(com.owncloud.android.db.OCUpload) Test(org.junit.Test)

Example 40 with OCUpload

use of com.owncloud.android.db.OCUpload in project android by nextcloud.

the class UploadIT method testUploadWithDelete.

@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());
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) OCUpload(com.owncloud.android.db.OCUpload) OCFile(com.owncloud.android.datamodel.OCFile) File(java.io.File) Test(org.junit.Test)

Aggregations

OCUpload (com.owncloud.android.db.OCUpload)49 Test (org.junit.Test)29 OCFile (com.owncloud.android.datamodel.OCFile)22 File (java.io.File)15 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)8 UploadFileOperation (com.owncloud.android.operations.UploadFileOperation)8 FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)7 Intent (android.content.Intent)6 SmallTest (androidx.test.filters.SmallTest)5 ScreenshotTest (com.owncloud.android.utils.ScreenshotTest)4 Account (android.accounts.Account)3 Context (android.content.Context)3 Cursor (android.database.Cursor)3 DialogFragment (androidx.fragment.app.DialogFragment)3 BatteryStatus (com.nextcloud.client.device.BatteryStatus)3 Connectivity (com.nextcloud.client.network.Connectivity)3 ConnectivityService (com.nextcloud.client.network.ConnectivityService)3 RemoteFile (com.owncloud.android.lib.resources.files.model.RemoteFile)3 RandomAccessFile (java.io.RandomAccessFile)3 SuppressLint (android.annotation.SuppressLint)2