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