Search in sources :

Example 1 with PowerManagementService

use of com.nextcloud.client.device.PowerManagementService in project android by nextcloud.

the class AbstractIT method uploadOCUpload.

public void uploadOCUpload(OCUpload ocUpload) {
    ConnectivityService connectivityServiceMock = new ConnectivityService() {

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

        @Override
        public Connectivity getConnectivity() {
            return Connectivity.CONNECTED_WIFI;
        }
    };
    PowerManagementService powerManagementServiceMock = new PowerManagementService() {

        @NonNull
        @Override
        public BatteryStatus getBattery() {
            return new BatteryStatus();
        }

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

        @Override
        public boolean isPowerSavingExclusionAvailable() {
            return false;
        }
    };
    UserAccountManager accountManager = UserAccountManagerImpl.fromContext(targetContext);
    UploadsStorageManager uploadsStorageManager = new UploadsStorageManager(accountManager, targetContext.getContentResolver());
    UploadFileOperation newUpload = new UploadFileOperation(uploadsStorageManager, connectivityServiceMock, powerManagementServiceMock, user, null, ocUpload, NameCollisionPolicy.DEFAULT, FileUploader.LOCAL_BEHAVIOUR_COPY, targetContext, false, false, getStorageManager());
    newUpload.addRenameUploadListener(() -> {
    // dummy
    });
    newUpload.setRemoteFolderToBeCreated();
    RemoteOperationResult result = newUpload.execute(client);
    assertTrue(result.getLogMessage(), result.isSuccess());
}
Also used : UserAccountManager(com.nextcloud.client.account.UserAccountManager) ConnectivityService(com.nextcloud.client.network.ConnectivityService) PowerManagementService(com.nextcloud.client.device.PowerManagementService) BatteryStatus(com.nextcloud.client.device.BatteryStatus) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) UploadsStorageManager(com.owncloud.android.datamodel.UploadsStorageManager) UploadFileOperation(com.owncloud.android.operations.UploadFileOperation)

Example 2 with PowerManagementService

use of com.nextcloud.client.device.PowerManagementService in project android by nextcloud.

the class AbstractOnServerIT method uploadOCUpload.

public void uploadOCUpload(OCUpload ocUpload, int localBehaviour) {
    ConnectivityService connectivityServiceMock = new ConnectivityService() {

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

        @Override
        public Connectivity getConnectivity() {
            return Connectivity.CONNECTED_WIFI;
        }
    };
    PowerManagementService powerManagementServiceMock = new PowerManagementService() {

        @NonNull
        @Override
        public BatteryStatus getBattery() {
            return new BatteryStatus();
        }

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

        @Override
        public boolean isPowerSavingExclusionAvailable() {
            return false;
        }
    };
    UserAccountManager accountManager = UserAccountManagerImpl.fromContext(targetContext);
    UploadsStorageManager uploadsStorageManager = new UploadsStorageManager(accountManager, targetContext.getContentResolver());
    UploadFileOperation newUpload = new UploadFileOperation(uploadsStorageManager, connectivityServiceMock, powerManagementServiceMock, user, null, ocUpload, NameCollisionPolicy.DEFAULT, localBehaviour, targetContext, false, false, getStorageManager());
    newUpload.addRenameUploadListener(() -> {
    // dummy
    });
    newUpload.setRemoteFolderToBeCreated();
    RemoteOperationResult result = newUpload.execute(client);
    assertTrue(result.getLogMessage(), result.isSuccess());
    OCFile parentFolder = getStorageManager().getFileByEncryptedRemotePath(new File(ocUpload.getRemotePath()).getParent() + "/");
    String uploadedFileName = new File(ocUpload.getRemotePath()).getName();
    OCFile uploadedFile = getStorageManager().getFileByDecryptedRemotePath(parentFolder.getDecryptedRemotePath() + uploadedFileName);
    assertNotNull(uploadedFile.getRemoteId());
    if (localBehaviour == FileUploader.LOCAL_BEHAVIOUR_COPY || localBehaviour == FileUploader.LOCAL_BEHAVIOUR_MOVE) {
        assertTrue(new File(uploadedFile.getStoragePath()).exists());
    }
}
Also used : UserAccountManager(com.nextcloud.client.account.UserAccountManager) OCFile(com.owncloud.android.datamodel.OCFile) ConnectivityService(com.nextcloud.client.network.ConnectivityService) PowerManagementService(com.nextcloud.client.device.PowerManagementService) BatteryStatus(com.nextcloud.client.device.BatteryStatus) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) UploadsStorageManager(com.owncloud.android.datamodel.UploadsStorageManager) UploadFileOperation(com.owncloud.android.operations.UploadFileOperation) RemoteFile(com.owncloud.android.lib.resources.files.model.RemoteFile) OCFile(com.owncloud.android.datamodel.OCFile) File(java.io.File)

Example 3 with PowerManagementService

use of com.nextcloud.client.device.PowerManagementService 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

BatteryStatus (com.nextcloud.client.device.BatteryStatus)3 PowerManagementService (com.nextcloud.client.device.PowerManagementService)3 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)3 UploadFileOperation (com.owncloud.android.operations.UploadFileOperation)3 UserAccountManager (com.nextcloud.client.account.UserAccountManager)2 ConnectivityService (com.nextcloud.client.network.ConnectivityService)2 UploadsStorageManager (com.owncloud.android.datamodel.UploadsStorageManager)2 OCFile (com.owncloud.android.datamodel.OCFile)1 OCUpload (com.owncloud.android.db.OCUpload)1 RemoteFile (com.owncloud.android.lib.resources.files.model.RemoteFile)1 File (java.io.File)1 Test (org.junit.Test)1