Search in sources :

Example 41 with OCUpload

use of com.owncloud.android.db.OCUpload 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)

Example 42 with OCUpload

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

the class RemoveFileOperationIT method deleteFile.

@Test
public void deleteFile() throws IOException {
    String parent = "/test/";
    String path = parent + "empty.txt";
    OCUpload ocUpload = new OCUpload(getDummyFile("/empty.txt").getAbsolutePath(), path, account.name);
    uploadOCUpload(ocUpload);
    OCFile file = getStorageManager().getFileByPath(path);
    assertNotNull(file);
    assertTrue(new RemoveFileOperation(file, false, account, false, targetContext, getStorageManager()).execute(client).isSuccess());
    OCFile parentFolder = getStorageManager().getFileByPath(parent);
    assertNotNull(parentFolder);
    assertTrue(new RemoveFileOperation(parentFolder, false, account, false, targetContext, getStorageManager()).execute(client).isSuccess());
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) OCUpload(com.owncloud.android.db.OCUpload) Test(org.junit.Test)

Example 43 with OCUpload

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

the class ConflictsResolveActivityIT method keepNew.

@Test
@ScreenshotTest
public void keepNew() {
    returnCode = false;
    OCUpload newUpload = new OCUpload(FileStorageUtils.getSavePath(user.getAccountName()) + "/nonEmpty.txt", "/newFile.txt", user.getAccountName());
    OCFile existingFile = new OCFile("/newFile.txt");
    existingFile.setFileLength(1024000);
    existingFile.setModificationTimestamp(1582019340);
    existingFile.setRemoteId("123abc");
    OCFile newFile = new OCFile("/newFile.txt");
    newFile.setFileLength(56000);
    newFile.setModificationTimestamp(1522019340);
    newFile.setStoragePath(FileStorageUtils.getSavePath(user.getAccountName()) + "/nonEmpty.txt");
    FileDataStorageManager storageManager = new FileDataStorageManager(user, targetContext.getContentResolver());
    storageManager.saveNewFile(existingFile);
    Intent intent = new Intent(targetContext, ConflictsResolveActivity.class);
    intent.putExtra(ConflictsResolveActivity.EXTRA_FILE, newFile);
    intent.putExtra(ConflictsResolveActivity.EXTRA_EXISTING_FILE, existingFile);
    intent.putExtra(ConflictsResolveActivity.EXTRA_CONFLICT_UPLOAD_ID, newUpload.getUploadId());
    ConflictsResolveActivity sut = activityRule.launchActivity(intent);
    sut.listener = decision -> {
        assertEquals(decision, ConflictsResolveDialog.Decision.KEEP_LOCAL);
        returnCode = true;
    };
    getInstrumentation().waitForIdleSync();
    onView(withId(R.id.new_checkbox)).perform(click());
    DialogFragment dialog = (DialogFragment) sut.getSupportFragmentManager().findFragmentByTag("conflictDialog");
    screenshot(Objects.requireNonNull(dialog.requireDialog().getWindow()).getDecorView());
    onView(withText("OK")).perform(click());
    assertTrue(returnCode);
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) OCUpload(com.owncloud.android.db.OCUpload) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) DialogFragment(androidx.fragment.app.DialogFragment) Intent(android.content.Intent) Test(org.junit.Test) ScreenshotTest(com.owncloud.android.utils.ScreenshotTest) ScreenshotTest(com.owncloud.android.utils.ScreenshotTest)

Example 44 with OCUpload

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

the class ConflictsResolveActivityIT method keepExisting.

@Test
@ScreenshotTest
public void keepExisting() {
    returnCode = false;
    OCUpload newUpload = new OCUpload(FileStorageUtils.getSavePath(user.getAccountName()) + "/nonEmpty.txt", "/newFile.txt", user.getAccountName());
    OCFile existingFile = new OCFile("/newFile.txt");
    existingFile.setFileLength(1024000);
    existingFile.setModificationTimestamp(1582019340);
    OCFile newFile = new OCFile("/newFile.txt");
    newFile.setFileLength(56000);
    newFile.setModificationTimestamp(1522019340);
    newFile.setStoragePath(FileStorageUtils.getSavePath(user.getAccountName()) + "/nonEmpty.txt");
    FileDataStorageManager storageManager = new FileDataStorageManager(user, targetContext.getContentResolver());
    storageManager.saveNewFile(existingFile);
    Intent intent = new Intent(targetContext, ConflictsResolveActivity.class);
    intent.putExtra(ConflictsResolveActivity.EXTRA_FILE, newFile);
    intent.putExtra(ConflictsResolveActivity.EXTRA_EXISTING_FILE, existingFile);
    intent.putExtra(ConflictsResolveActivity.EXTRA_CONFLICT_UPLOAD_ID, newUpload.getUploadId());
    ConflictsResolveActivity sut = activityRule.launchActivity(intent);
    sut.listener = decision -> {
        assertEquals(decision, ConflictsResolveDialog.Decision.KEEP_SERVER);
        returnCode = true;
    };
    getInstrumentation().waitForIdleSync();
    onView(withId(R.id.existing_checkbox)).perform(click());
    DialogFragment dialog = (DialogFragment) sut.getSupportFragmentManager().findFragmentByTag("conflictDialog");
    screenshot(Objects.requireNonNull(dialog.requireDialog().getWindow()).getDecorView());
    onView(withText("OK")).perform(click());
    assertTrue(returnCode);
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) OCUpload(com.owncloud.android.db.OCUpload) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) DialogFragment(androidx.fragment.app.DialogFragment) Intent(android.content.Intent) Test(org.junit.Test) ScreenshotTest(com.owncloud.android.utils.ScreenshotTest) ScreenshotTest(com.owncloud.android.utils.ScreenshotTest)

Example 45 with OCUpload

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

the class UploadsStorageManager method getUploads.

private OCUpload[] getUploads(@Nullable String selection, @Nullable String... selectionArgs) {
    ArrayList<OCUpload> uploads = new ArrayList<>();
    final long pageSize = 100;
    long page = 0;
    long rowsRead;
    long rowsTotal = 0;
    long lastRowID = -1;
    do {
        String pageSelection = selection;
        String[] pageSelectionArgs = selectionArgs;
        if (page > 0 && lastRowID >= 0) {
            if (selection != null) {
                pageSelection = "(" + selection + ") AND _id < ?";
            } else {
                pageSelection = "_id < ?";
            }
            if (selectionArgs != null) {
                pageSelectionArgs = Arrays.copyOf(selectionArgs, selectionArgs.length + 1);
            } else {
                pageSelectionArgs = new String[1];
            }
            pageSelectionArgs[pageSelectionArgs.length - 1] = String.valueOf(lastRowID);
            Log_OC.d(TAG, String.format(Locale.ENGLISH, "QUERY: %s ROWID: %d", pageSelection, lastRowID));
        } else {
            Log_OC.d(TAG, String.format(Locale.ENGLISH, "QUERY: %s ROWID: %d", selection, lastRowID));
        }
        rowsRead = 0;
        Cursor c = getDB().query(ProviderTableMeta.CONTENT_URI_UPLOADS, null, pageSelection, pageSelectionArgs, String.format(Locale.ENGLISH, "_id DESC LIMIT %d", pageSize));
        if (c != null) {
            if (c.moveToFirst()) {
                do {
                    rowsRead++;
                    rowsTotal++;
                    lastRowID = c.getLong(c.getColumnIndexOrThrow(ProviderTableMeta._ID));
                    OCUpload upload = createOCUploadFromCursor(c);
                    if (upload == null) {
                        Log_OC.e(TAG, "OCUpload could not be created from cursor");
                    } else {
                        uploads.add(upload);
                    }
                } while (c.moveToNext() && !c.isAfterLast());
            }
            c.close();
            Log_OC.v(TAG, String.format(Locale.ENGLISH, "getUploads() got %d rows from page %d, %d rows total so far, last ID %d", rowsRead, page, rowsTotal, lastRowID));
            page += 1;
        } else {
            break;
        }
    } while (rowsRead > 0);
    Log_OC.v(TAG, String.format(Locale.ENGLISH, "getUploads() returning %d (%d) rows after reading %d pages", rowsTotal, uploads.size(), page));
    return uploads.toArray(new OCUpload[0]);
}
Also used : OCUpload(com.owncloud.android.db.OCUpload) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

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