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());
}
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());
}
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);
}
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);
}
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]);
}
Aggregations