Search in sources :

Example 11 with OCUpload

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

the class UploadStorageManagerTest method getById.

@Test
public void getById() {
    OCUpload upload = createUpload(account);
    long id = uploadsStorageManager.storeUpload(upload);
    OCUpload newUpload = uploadsStorageManager.getUploadById(id);
    assertNotNull(newUpload);
    assertEquals(upload.getLocalAction(), newUpload.getLocalAction());
    assertEquals(upload.getFolderUnlockToken(), newUpload.getFolderUnlockToken());
}
Also used : OCUpload(com.owncloud.android.db.OCUpload) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test)

Example 12 with OCUpload

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

the class UploadStorageManagerTest method getByIdNull.

@Test
public void getByIdNull() {
    OCUpload newUpload = uploadsStorageManager.getUploadById(-1);
    assertNull(newUpload);
}
Also used : OCUpload(com.owncloud.android.db.OCUpload) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test)

Example 13 with OCUpload

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

the class UploadStorageManagerTest method corruptedUpload.

@Test(expected = IllegalArgumentException.class)
public void corruptedUpload() {
    OCUpload corruptUpload = new OCUpload(File.separator + "LocalPath", OCFile.PATH_SEPARATOR + "RemotePath", account.name);
    corruptUpload.setLocalPath(null);
    uploadsStorageManager.storeUpload(corruptUpload);
    uploadsStorageManager.getAllStoredUploads();
}
Also used : OCUpload(com.owncloud.android.db.OCUpload) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test)

Example 14 with OCUpload

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

the class ConflictsResolveActivityIT method keepBoth.

@Test
@ScreenshotTest
public void keepBoth() {
    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_BOTH);
        returnCode = true;
    };
    getInstrumentation().waitForIdleSync();
    onView(withId(R.id.existing_checkbox)).perform(click());
    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 15 with OCUpload

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

the class ConflictsResolveActivityIT method cancel.

// @Test
// @ScreenshotTest // todo run without real server
// public void screenshotImages() throws IOException {
// FileDataStorageManager storageManager = new FileDataStorageManager(user,
// targetContext.getContentResolver());
// 
// OCFile newFile = new OCFile("/newFile.txt");
// newFile.setFileLength(56000);
// newFile.setModificationTimestamp(1522019340);
// newFile.setStoragePath(FileStorageUtils.getSavePath(user.getAccountName()) + "/nonEmpty.txt");
// 
// File image = getFile("image.jpg");
// 
// assertTrue(new UploadFileRemoteOperation(image.getAbsolutePath(),
// "/image.jpg",
// "image/jpg",
// "10000000").execute(client).isSuccess());
// 
// assertTrue(new RefreshFolderOperation(storageManager.getFileByPath("/"),
// System.currentTimeMillis(),
// false,
// true,
// storageManager,
// user.toPlatformAccount(),
// targetContext
// ).execute(client).isSuccess());
// 
// OCFile existingFile = storageManager.getFileByPath("/image.jpg");
// 
// Intent intent = new Intent(targetContext, ConflictsResolveActivity.class);
// intent.putExtra(ConflictsResolveActivity.EXTRA_FILE, newFile);
// intent.putExtra(ConflictsResolveActivity.EXTRA_EXISTING_FILE, existingFile);
// 
// ConflictsResolveActivity sut = activityRule.launchActivity(intent);
// 
// ConflictsResolveDialog.OnConflictDecisionMadeListener listener = decision -> {
// 
// };
// 
// ConflictsResolveDialog dialog = ConflictsResolveDialog.newInstance(existingFile,
// newFile,
// UserAccountManagerImpl
// .fromContext(targetContext)
// .getUser()
// );
// dialog.showDialog(sut);
// dialog.listener = listener;
// 
// getInstrumentation().waitForIdleSync();
// shortSleep();
// 
// screenshot(Objects.requireNonNull(dialog.requireDialog().getWindow()).getDecorView());
// }
@Test
public void cancel() {
    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.CANCEL);
        returnCode = true;
    };
    getInstrumentation().waitForIdleSync();
    shortSleep();
    onView(withText("Cancel")).perform(click());
    assertTrue(returnCode);
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) OCUpload(com.owncloud.android.db.OCUpload) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) Intent(android.content.Intent) Test(org.junit.Test) ScreenshotTest(com.owncloud.android.utils.ScreenshotTest)

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