Search in sources :

Example 31 with OCUpload

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

the class EndToEndRandomIT method uploadFile.

private void uploadFile(int i) throws IOException {
    String fileName = RandomString.make(5) + ".txt";
    File file;
    if (new Random().nextBoolean()) {
        file = createFile(fileName, new Random().nextInt(50000));
    } else {
        file = createFile(fileName, 500000 + new Random().nextInt(50000));
    }
    String remotePath = currentFolder.getRemotePath() + fileName;
    Log_OC.d(this, "[" + i + "/" + actionCount + "] " + "Upload file to: " + currentFolder.getDecryptedRemotePath() + fileName);
    OCUpload ocUpload = new OCUpload(file.getAbsolutePath(), remotePath, account.name);
    uploadOCUpload(ocUpload);
    shortSleep();
    OCFile parentFolder = getStorageManager().getFileByEncryptedRemotePath(new File(ocUpload.getRemotePath()).getParent() + "/");
    String uploadedFileName = new File(ocUpload.getRemotePath()).getName();
    String decryptedPath = parentFolder.getDecryptedRemotePath() + uploadedFileName;
    OCFile uploadedFile = getStorageManager().getFileByDecryptedRemotePath(decryptedPath);
    verifyStoragePath(uploadedFile);
    // verify storage path
    refreshFolder(currentFolder.getRemotePath());
    uploadedFile = getStorageManager().getFileByDecryptedRemotePath(decryptedPath);
    verifyStoragePath(uploadedFile);
    // verify that encrypted file is on server
    assertTrue(new ReadFileRemoteOperation(currentFolder.getRemotePath() + uploadedFile.getEncryptedFileName()).execute(client).isSuccess());
    // verify that unencrypted file is not on server
    assertFalse(new ReadFileRemoteOperation(currentFolder.getDecryptedRemotePath() + fileName).execute(client).isSuccess());
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) OCUpload(com.owncloud.android.db.OCUpload) Random(java.util.Random) ReadFileRemoteOperation(com.owncloud.android.lib.resources.files.ReadFileRemoteOperation) RandomString(net.bytebuddy.utility.RandomString) OCFile(com.owncloud.android.datamodel.OCFile) File(java.io.File)

Example 32 with OCUpload

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

the class DownloadIT method verifyDownload.

@Test
public void verifyDownload() {
    OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt", FOLDER + "nonEmpty.txt", account.name);
    uploadOCUpload(ocUpload);
    OCUpload ocUpload2 = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt", FOLDER + "nonEmpty2.txt", account.name);
    uploadOCUpload(ocUpload2);
    refreshFolder("/");
    refreshFolder(FOLDER);
    OCFile file1 = fileDataStorageManager.getFileByDecryptedRemotePath(FOLDER + "nonEmpty.txt");
    OCFile file2 = fileDataStorageManager.getFileByDecryptedRemotePath(FOLDER + "nonEmpty2.txt");
    verifyDownload(file1, file2);
    assertTrue(new DownloadFileOperation(user, file1, targetContext).execute(client).isSuccess());
    assertTrue(new DownloadFileOperation(user, file2, targetContext).execute(client).isSuccess());
    refreshFolder(FOLDER);
    file1 = fileDataStorageManager.getFileByDecryptedRemotePath(FOLDER + "nonEmpty.txt");
    file2 = fileDataStorageManager.getFileByDecryptedRemotePath(FOLDER + "nonEmpty2.txt");
    verifyDownload(file1, file2);
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) OCUpload(com.owncloud.android.db.OCUpload) DownloadFileOperation(com.owncloud.android.operations.DownloadFileOperation) Test(org.junit.Test)

Example 33 with OCUpload

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

the class UploadIT method testUploadWithCopy.

@Test
public void testUploadWithCopy() {
    OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt", FOLDER + "nonEmpty.txt", account.name);
    uploadOCUpload(ocUpload, FileUploader.LOCAL_BEHAVIOUR_COPY);
    File originalFile = new File(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt");
    OCFile uploadedFile = fileDataStorageManager.getFileByDecryptedRemotePath(FOLDER + "nonEmpty.txt");
    assertTrue(originalFile.exists());
    assertTrue(new File(uploadedFile.getStoragePath()).exists());
    verifyStoragePath(uploadedFile);
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) OCUpload(com.owncloud.android.db.OCUpload) OCFile(com.owncloud.android.datamodel.OCFile) File(java.io.File) Test(org.junit.Test)

Example 34 with OCUpload

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

the class UploadIT method testCreationAndUploadTimestamp.

@Test
public void testCreationAndUploadTimestamp() throws IOException {
    File file = getDummyFile("/empty.txt");
    String remotePath = "/testFile.txt";
    OCUpload ocUpload = new OCUpload(file.getAbsolutePath(), remotePath, account.name);
    long creationTimestamp = Files.readAttributes(file.toPath(), BasicFileAttributes.class).creationTime().to(TimeUnit.SECONDS);
    // wait a bit to simulate a later upload, so we can verify if creation date is set correct
    shortSleep();
    assertTrue(new UploadFileOperation(uploadsStorageManager, connectivityServiceMock, powerManagementServiceMock, user, null, ocUpload, NameCollisionPolicy.DEFAULT, FileUploader.LOCAL_BEHAVIOUR_COPY, targetContext, false, false, getStorageManager()).setRemoteFolderToBeCreated().execute(client).isSuccess());
    long uploadTimestamp = System.currentTimeMillis() / 1000;
    // RefreshFolderOperation
    assertTrue(new RefreshFolderOperation(getStorageManager().getFileByDecryptedRemotePath("/"), System.currentTimeMillis() / 1000, false, false, getStorageManager(), user, targetContext).execute(client).isSuccess());
    List<OCFile> files = getStorageManager().getFolderContent(getStorageManager().getFileByDecryptedRemotePath("/"), false);
    OCFile ocFile = files.get(0);
    assertEquals(remotePath, ocFile.getRemotePath());
    assertEquals(creationTimestamp, ocFile.getCreationTimestamp());
    assertTrue(uploadTimestamp - 10 < ocFile.getUploadTimestamp() || uploadTimestamp + 10 > ocFile.getUploadTimestamp());
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) OCUpload(com.owncloud.android.db.OCUpload) RefreshFolderOperation(com.owncloud.android.operations.RefreshFolderOperation) UploadFileOperation(com.owncloud.android.operations.UploadFileOperation) OCFile(com.owncloud.android.datamodel.OCFile) File(java.io.File) Test(org.junit.Test)

Example 35 with OCUpload

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

the class UploadIT method testUploadWithForget.

@Test
public void testUploadWithForget() {
    OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt", FOLDER + "nonEmpty.txt", account.name);
    uploadOCUpload(ocUpload, FileUploader.LOCAL_BEHAVIOUR_FORGET);
    File originalFile = new File(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt");
    OCFile uploadedFile = fileDataStorageManager.getFileByDecryptedRemotePath(FOLDER + "nonEmpty.txt");
    assertTrue(originalFile.exists());
    assertFalse(new File(uploadedFile.getStoragePath()).exists());
    assertTrue(uploadedFile.getStoragePath().isEmpty());
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) OCUpload(com.owncloud.android.db.OCUpload) OCFile(com.owncloud.android.datamodel.OCFile) File(java.io.File) Test(org.junit.Test)

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