Search in sources :

Example 11 with UploadFileOperation

use of com.owncloud.android.operations.UploadFileOperation 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 12 with UploadFileOperation

use of com.owncloud.android.operations.UploadFileOperation 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 13 with UploadFileOperation

use of com.owncloud.android.operations.UploadFileOperation in project android by nextcloud.

the class UploadIT method testUploadOnChargingOnlyAndCharging.

@Test
public void testUploadOnChargingOnlyAndCharging() {
    PowerManagementService powerManagementServiceMock = new PowerManagementService() {

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

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

        @NonNull
        @Override
        public BatteryStatus getBattery() {
            return new BatteryStatus(true, 100);
        }
    };
    OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt", FOLDER + "charging.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);
    assertTrue(result.toString(), result.isSuccess());
}
Also used : OCUpload(com.owncloud.android.db.OCUpload) PowerManagementService(com.nextcloud.client.device.PowerManagementService) BatteryStatus(com.nextcloud.client.device.BatteryStatus) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) UploadFileOperation(com.owncloud.android.operations.UploadFileOperation) Test(org.junit.Test)

Aggregations

UploadFileOperation (com.owncloud.android.operations.UploadFileOperation)13 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)9 OCUpload (com.owncloud.android.db.OCUpload)8 Test (org.junit.Test)6 FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)5 ConnectivityService (com.nextcloud.client.network.ConnectivityService)4 OCFile (com.owncloud.android.datamodel.OCFile)4 File (java.io.File)4 BatteryStatus (com.nextcloud.client.device.BatteryStatus)3 PowerManagementService (com.nextcloud.client.device.PowerManagementService)3 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)3 UserAccountManager (com.nextcloud.client.account.UserAccountManager)2 Connectivity (com.nextcloud.client.network.Connectivity)2 UploadsStorageManager (com.owncloud.android.datamodel.UploadsStorageManager)2 ChunkedUploadFileOperation (com.owncloud.android.operations.ChunkedUploadFileOperation)2 Account (android.accounts.Account)1 SuppressLint (android.annotation.SuppressLint)1 Message (android.os.Message)1 Parcelable (android.os.Parcelable)1 User (com.nextcloud.client.account.User)1