diff --git a/library/src/androidTest/java/com/nextcloud/android/lib/resources/directediting/DirectEditingOpenFileRemoteOperationIT.java b/library/src/androidTest/java/com/nextcloud/android/lib/resources/directediting/DirectEditingOpenFileRemoteOperationIT.java index 0f3505100..4657320bf 100644 --- a/library/src/androidTest/java/com/nextcloud/android/lib/resources/directediting/DirectEditingOpenFileRemoteOperationIT.java +++ b/library/src/androidTest/java/com/nextcloud/android/lib/resources/directediting/DirectEditingOpenFileRemoteOperationIT.java @@ -47,8 +47,12 @@ public void openFile() throws IOException { // create file String filePath = createFile("text"); String remotePath = "/text.md"; - TestCase.assertTrue(new UploadFileRemoteOperation(filePath, remotePath, "text/markdown", "1464818400") - .execute(client).isSuccess()); + TestCase.assertTrue(new UploadFileRemoteOperation( + filePath, + remotePath, + "text/markdown", + 1464818400 + ).execute(client).isSuccess()); TestCase.assertTrue(new ReadFileRemoteOperation(remotePath).execute(client).isSuccess()); @@ -66,8 +70,12 @@ public void openFileWithSpecialChars() throws IOException { // create file String filePath = createFile("text"); String remotePath = "/äää.md"; - TestCase.assertTrue(new UploadFileRemoteOperation(filePath, remotePath, "text/markdown", "1464818400") - .execute(client).isSuccess()); + TestCase.assertTrue(new UploadFileRemoteOperation( + filePath, + remotePath, + "text/markdown", + 1464818400 + ).execute(client).isSuccess()); TestCase.assertTrue(new ReadFileRemoteOperation(remotePath).execute(client).isSuccess()); @@ -85,8 +93,12 @@ public void openFileWithSpecialChars2() throws IOException { // create file String filePath = createFile("text"); String remotePath = "/あ.md"; - TestCase.assertTrue(new UploadFileRemoteOperation(filePath, remotePath, "text/markdown", "1464818400") - .execute(client).isSuccess()); + TestCase.assertTrue(new UploadFileRemoteOperation( + filePath, + remotePath, + "text/markdown", + 1464818400 + ).execute(client).isSuccess()); TestCase.assertTrue(new ReadFileRemoteOperation(remotePath).execute(client).isSuccess()); diff --git a/library/src/androidTest/java/com/nextcloud/android/lib/resources/files/ToggleFileLockRemoteOperationIT.kt b/library/src/androidTest/java/com/nextcloud/android/lib/resources/files/ToggleFileLockRemoteOperationIT.kt index d8b45ef1f..080c7ab03 100644 --- a/library/src/androidTest/java/com/nextcloud/android/lib/resources/files/ToggleFileLockRemoteOperationIT.kt +++ b/library/src/androidTest/java/com/nextcloud/android/lib/resources/files/ToggleFileLockRemoteOperationIT.kt @@ -56,7 +56,8 @@ class ToggleFileLockRemoteOperationIT : AbstractIT() { val filePath: String = createFile("text") val remotePath = "/text.md" assertTrue( - UploadFileRemoteOperation(filePath, remotePath, "text/markdown", "1464818400") + @Suppress("Detekt.MagicNumber") + UploadFileRemoteOperation(filePath, remotePath, "text/markdown", 1464818400) .execute(client).isSuccess ) val initialFile = diff --git a/library/src/androidTest/java/com/nextcloud/android/lib/richWorkspace/RichWorkspaceDirectEditingRemoteOperationIT.java b/library/src/androidTest/java/com/nextcloud/android/lib/richWorkspace/RichWorkspaceDirectEditingRemoteOperationIT.java index a844ed441..7a758f1f5 100644 --- a/library/src/androidTest/java/com/nextcloud/android/lib/richWorkspace/RichWorkspaceDirectEditingRemoteOperationIT.java +++ b/library/src/androidTest/java/com/nextcloud/android/lib/richWorkspace/RichWorkspaceDirectEditingRemoteOperationIT.java @@ -72,11 +72,12 @@ public void reuseExistingFile() throws IOException { assertTrue(new CreateFolderRemoteOperation(folder, true).execute(client).isSuccess()); - RemoteOperationResult uploadResult = new UploadFileRemoteOperation(txtFile.getAbsolutePath(), + RemoteOperationResult uploadResult = new UploadFileRemoteOperation( + txtFile.getAbsolutePath(), filePath, "txt/plain", - String.valueOf(System.currentTimeMillis() / MILLI_TO_SECOND)) - .execute(client); + System.currentTimeMillis() / MILLI_TO_SECOND + ).execute(client); assertTrue("Error uploading file " + filePath + ": " + uploadResult, uploadResult.isSuccess()); diff --git a/library/src/androidTest/java/com/owncloud/android/AbstractIT.java b/library/src/androidTest/java/com/owncloud/android/AbstractIT.java index de9516071..e0565ecb1 100644 --- a/library/src/androidTest/java/com/owncloud/android/AbstractIT.java +++ b/library/src/androidTest/java/com/owncloud/android/AbstractIT.java @@ -78,7 +78,7 @@ public abstract class AbstractIT { public RetryTestRule retryTestRule = new RetryTestRule(); private static final int BUFFER_SIZE = 1024; - public static final String RANDOM_MTIME = "1464818400"; + public static final long RANDOM_MTIME = 1464818400L; public static final int MILLI_TO_SECOND = 1000; public static OwnCloudClient client; diff --git a/library/src/androidTest/java/com/owncloud/android/CopyFileIT.java b/library/src/androidTest/java/com/owncloud/android/CopyFileIT.java index 2c83629f0..4caae0d58 100644 --- a/library/src/androidTest/java/com/owncloud/android/CopyFileIT.java +++ b/library/src/androidTest/java/com/owncloud/android/CopyFileIT.java @@ -26,6 +26,10 @@ */ package com.owncloud.android; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + import android.util.Log; import com.owncloud.android.lib.common.operations.RemoteOperationResult; @@ -42,10 +46,6 @@ import java.io.File; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - /** * Class to test CopyRemoteFileOperation */ @@ -188,7 +188,12 @@ public void createFixtures() throws Exception { File txtFile = getFile(ASSETS__TEXT_FILE_NAME); for (String filePath : FILES_IN_FIXTURE) { - result = new UploadFileRemoteOperation(txtFile.getAbsolutePath(), filePath, "txt/plain", String.valueOf(System.currentTimeMillis() / 1000)).execute(client); + result = new UploadFileRemoteOperation( + txtFile.getAbsolutePath(), + filePath, + "txt/plain", + System.currentTimeMillis() / 1000 + ).execute(client); assertTrue("Error uploading file " + filePath + ": " + result, result.isSuccess()); } @@ -243,13 +248,13 @@ public void testCopyRemoteFileOperation() { // copy & rename folder, different location copyOperation = new CopyFileRemoteOperation(SRC_PATH_TO_FULL_FOLDER_2, TARGET_PATH_TO_FULL_FOLDER_2_RENAMED, - false); + false); result = copyOperation.execute(client); assertTrue("copy & rename folder, different location", result.isSuccess()); // copy & rename folder, same location (rename folder) copyOperation = new CopyFileRemoteOperation(SRC_PATH_TO_FULL_FOLDER_3, SRC_PATH_TO_FULL_FOLDER_3_RENAMED, - false); + false); result = copyOperation.execute(client); assertTrue("copy & rename folder, same location (rename folder)", result.isSuccess()); @@ -260,7 +265,7 @@ public void testCopyRemoteFileOperation() { // copy overwriting copyOperation = new CopyFileRemoteOperation(SRC_PATH_TO_FULL_FOLDER_4, - TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4, true); + TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4, true); result = copyOperation.execute(client); assertTrue("copy overwriting", result.isSuccess()); @@ -269,13 +274,13 @@ public void testCopyRemoteFileOperation() { // file to copy does not exist copyOperation = new CopyFileRemoteOperation(SRC_PATH_TO_NON_EXISTENT_FILE, TARGET_PATH_TO_NON_EXISTENT_FILE, - false); + false); result = copyOperation.execute(client); assertSame("file to copy does not exist", result.getCode(), ResultCode.FILE_NOT_FOUND); // folder to copy into does no exist copyOperation = new CopyFileRemoteOperation(SRC_PATH_TO_FILE_5, TARGET_PATH_TO_FILE_5_INTO_NON_EXISTENT_FOLDER, - false); + false); result = copyOperation.execute(client); assertEquals("folder to copy into does no exist", result.getHttpCode(), HttpStatus.SC_CONFLICT); diff --git a/library/src/androidTest/java/com/owncloud/android/DeleteFileIT.java b/library/src/androidTest/java/com/owncloud/android/DeleteFileIT.java index 9fc04a648..f3125c42e 100644 --- a/library/src/androidTest/java/com/owncloud/android/DeleteFileIT.java +++ b/library/src/androidTest/java/com/owncloud/android/DeleteFileIT.java @@ -62,8 +62,11 @@ public void setUp() throws Exception { assertTrue("Error creating folder" + mFullPath2Folder + ": " + result, result.isSuccess()); File textFile = getFile(ASSETS__TEXT_FILE_NAME); - result = new UploadFileRemoteOperation(textFile.getAbsolutePath(), mFullPath2File, "txt/plain", - String.valueOf(System.currentTimeMillis() / MILLI_TO_SECOND)).execute(client); + result = new UploadFileRemoteOperation( + textFile.getAbsolutePath(), + mFullPath2File, "txt/plain", + System.currentTimeMillis() / MILLI_TO_SECOND + ).execute(client); assertTrue("Error uploading file " + textFile.getAbsolutePath() + ": " + result, result.isSuccess()); } diff --git a/library/src/androidTest/java/com/owncloud/android/lib/common/operations/CreateShareIT.java b/library/src/androidTest/java/com/owncloud/android/lib/common/operations/CreateShareIT.java index ecc806ea2..7b4874484 100644 --- a/library/src/androidTest/java/com/owncloud/android/lib/common/operations/CreateShareIT.java +++ b/library/src/androidTest/java/com/owncloud/android/lib/common/operations/CreateShareIT.java @@ -57,34 +57,36 @@ public void setUp() throws Exception { mFullPath2NonExistentFile = NON_EXISTENT_FILE; File textFile = getFile(ASSETS__TEXT_FILE_NAME); - RemoteOperationResult result = new UploadFileRemoteOperation(textFile.getAbsolutePath(), - mFullPath2FileToShare, - "txt/plain", - String.valueOf(System.currentTimeMillis() / MILLI_TO_SECOND)) - .execute(client); + RemoteOperationResult result = new UploadFileRemoteOperation( + textFile.getAbsolutePath(), + mFullPath2FileToShare, + "txt/plain", + System.currentTimeMillis() / MILLI_TO_SECOND + ).execute(client); assertTrue("Error uploading file " + textFile + ": " + result, result.isSuccess()); } @Test public void testCreatePublicShareSuccessful() { - RemoteOperationResult result = new CreateShareRemoteOperation(mFullPath2FileToShare, - ShareType.PUBLIC_LINK, - "", - false, - "", - 1).execute(client); + RemoteOperationResult result = new CreateShareRemoteOperation( + mFullPath2FileToShare, + ShareType.PUBLIC_LINK, + "", + false, + "", + 1).execute(client); assertTrue(result.isSuccess()); } @Test public void testCreatePublicShareFailure() { RemoteOperationResult result = new CreateShareRemoteOperation(mFullPath2NonExistentFile, - ShareType.PUBLIC_LINK, - "", - false, - "", - 1).execute(client); + ShareType.PUBLIC_LINK, + "", + false, + "", + 1).execute(client); assertFalse(result.isSuccess()); assertEquals(ResultCode.FILE_NOT_FOUND, result.getCode()); @@ -96,11 +98,11 @@ public void testCreatePublicShareFailure() { @Test public void testCreatePrivateShareWithUserSuccessful() { RemoteOperationResult result = new CreateShareRemoteOperation(mFullPath2FileToShare, - ShareType.USER, - "admin", - false, - "", - 31).execute(client); + ShareType.USER, + "admin", + false, + "", + 31).execute(client); assertTrue(result.isSuccess()); } @@ -110,11 +112,11 @@ public void testCreatePrivateShareWithUserSuccessful() { @Test public void testCreatePrivateShareWithUserNotExists() { RemoteOperationResult result = new CreateShareRemoteOperation(mFullPath2FileToShare, - ShareType.USER, - "no_exist", - false, - "", - 31).execute(client); + ShareType.USER, + "no_exist", + false, + "", + 31).execute(client); assertFalse(result.isSuccess()); // TODO 404 is File not found, but actually it is "user not found" @@ -127,11 +129,11 @@ public void testCreatePrivateShareWithUserNotExists() { @Test public void testCreatePrivateShareWithFileNotExists() { RemoteOperationResult result = new CreateShareRemoteOperation(mFullPath2NonExistentFile, - ShareType.USER, - "admin", - false, - "", - 31).execute(client); + ShareType.USER, + "admin", + false, + "", + 31).execute(client); assertFalse(result.isSuccess()); assertEquals(ResultCode.FILE_NOT_FOUND, result.getCode()); } @@ -142,11 +144,11 @@ public void testCreatePrivateShareWithFileNotExists() { @Test public void testCreatePrivateShareWithGroupSuccessful() { RemoteOperationResult result = new CreateShareRemoteOperation(mFullPath2FileToShare, - ShareType.GROUP, - "admin", - false, - "", - 1).execute(client); + ShareType.GROUP, + "admin", + false, + "", + 1).execute(client); assertTrue(result.isSuccess()); } @@ -156,11 +158,11 @@ public void testCreatePrivateShareWithGroupSuccessful() { @Test public void testCreatePrivateShareWithNonExistingGroupSharee() { RemoteOperationResult result = new CreateShareRemoteOperation(mFullPath2FileToShare, - ShareType.GROUP, - "no_exist", - false, - "", - 31).execute(client); + ShareType.GROUP, + "no_exist", + false, + "", + 31).execute(client); assertFalse(result.isSuccess()); // TODO 404 is File not found, but actually it is "user not found" @@ -173,11 +175,11 @@ public void testCreatePrivateShareWithNonExistingGroupSharee() { @Test public void testCreatePrivateShareWithNonExistingFile() { RemoteOperationResult result = new CreateShareRemoteOperation(mFullPath2NonExistentFile, - ShareType.GROUP, - "admin", - false, - "", - 31).execute(client); + ShareType.GROUP, + "admin", + false, + "", + 31).execute(client); assertFalse(result.isSuccess()); assertEquals(ResultCode.FILE_NOT_FOUND, result.getCode()); } @@ -202,15 +204,15 @@ public void testCreatePrivateShareWithNonExistingFile() { @Test public void testCreateFederatedShareWithNonExistingSharee() { RemoteOperationResult result = new CreateShareRemoteOperation(mFullPath2FileToShare, - ShareType.FEDERATED, - "no_exist@" + serverUri2, - false, - "", - 31).execute(client); + ShareType.FEDERATED, + "no_exist@" + serverUri2, + false, + "", + 31).execute(client); assertFalse("sharee doesn't exist in an existing remote server", result.isSuccess()); assertEquals("sharee doesn't exist in an existing remote server, forbidden", - RemoteOperationResult.ResultCode.SHARE_FORBIDDEN, result.getCode()); + RemoteOperationResult.ResultCode.SHARE_FORBIDDEN, result.getCode()); } /** @@ -219,11 +221,11 @@ public void testCreateFederatedShareWithNonExistingSharee() { @Test public void testCreateFederatedShareWithNonExistingRemoteServer() { RemoteOperationResult result = new CreateShareRemoteOperation(mFullPath2FileToShare, - ShareType.FEDERATED, - "no_exist", - false, - "", - 31).execute(client); + ShareType.FEDERATED, + "no_exist", + false, + "", + 31).execute(client); assertFalse(result.isSuccess()); // TODO expected: but was: assertEquals("remote server doesn't exist", ResultCode.SHARE_FORBIDDEN, result.getCode()); @@ -235,11 +237,11 @@ public void testCreateFederatedShareWithNonExistingRemoteServer() { @Test public void testCreateFederatedShareWithNonExistingFile() { RemoteOperationResult result = new CreateShareRemoteOperation(mFullPath2NonExistentFile, - ShareType.FEDERATED, - "admin@" + serverUri2, - false, - "", - 31).execute(client); + ShareType.FEDERATED, + "admin@" + serverUri2, + false, + "", + 31).execute(client); assertFalse("file doesn't exist", result.isSuccess()); assertEquals("file doesn't exist", ResultCode.FILE_NOT_FOUND, result.getCode()); diff --git a/library/src/androidTest/java/com/owncloud/android/lib/common/operations/RemoveShareIT.java b/library/src/androidTest/java/com/owncloud/android/lib/common/operations/RemoveShareIT.java index d44f2dd8e..79d6529cb 100644 --- a/library/src/androidTest/java/com/owncloud/android/lib/common/operations/RemoveShareIT.java +++ b/library/src/androidTest/java/com/owncloud/android/lib/common/operations/RemoveShareIT.java @@ -50,11 +50,12 @@ public class RemoveShareIT extends AbstractIT { @Test public void testRemoveShare() throws IOException { File textFile = getFile(ASSETS__TEXT_FILE_NAME); - assertTrue(new UploadFileRemoteOperation(textFile.getAbsolutePath(), + assertTrue(new UploadFileRemoteOperation( + textFile.getAbsolutePath(), FILE_TO_UNSHARE, "txt/plain", - String.valueOf(System.currentTimeMillis() / MILLI_TO_SECOND)) - .execute(client).isSuccess()); + System.currentTimeMillis() / MILLI_TO_SECOND + ).execute(client).isSuccess()); RemoteOperationResult> result = new CreateShareRemoteOperation(FILE_TO_UNSHARE, ShareType.PUBLIC_LINK, diff --git a/library/src/androidTest/java/com/owncloud/android/lib/resources/files/CheckEtagRemoteOperationIT.kt b/library/src/androidTest/java/com/owncloud/android/lib/resources/files/CheckEtagRemoteOperationIT.kt index 3f4c6f04e..eb05664a8 100644 --- a/library/src/androidTest/java/com/owncloud/android/lib/resources/files/CheckEtagRemoteOperationIT.kt +++ b/library/src/androidTest/java/com/owncloud/android/lib/resources/files/CheckEtagRemoteOperationIT.kt @@ -39,7 +39,8 @@ class CheckEtagRemoteOperationIT : AbstractIT() { val filePath = createFile("eTagFile") val remotePath = "/eTagFile.txt" assertTrue( - UploadFileRemoteOperation(filePath, remotePath, "image/jpg", "1464818400") + @Suppress("Detekt.MagicNumber") + UploadFileRemoteOperation(filePath, remotePath, "image/jpg", 1464818400) .execute(client).isSuccess ) diff --git a/library/src/androidTest/java/com/owncloud/android/lib/resources/files/DownloadFileRemoteOperationIT.kt b/library/src/androidTest/java/com/owncloud/android/lib/resources/files/DownloadFileRemoteOperationIT.kt index 9b90cf7e6..c23512a65 100644 --- a/library/src/androidTest/java/com/owncloud/android/lib/resources/files/DownloadFileRemoteOperationIT.kt +++ b/library/src/androidTest/java/com/owncloud/android/lib/resources/files/DownloadFileRemoteOperationIT.kt @@ -38,7 +38,8 @@ class DownloadFileRemoteOperationIT : AbstractIT() { val filePath = createFile("download") val remotePath = "/download.jpg" assertTrue( - UploadFileRemoteOperation(filePath, remotePath, "image/jpg", "1464818400") + @Suppress("Detekt.MagicNumber") + UploadFileRemoteOperation(filePath, remotePath, "image/jpg", 1464818400) .execute(client).isSuccess ) diff --git a/library/src/androidTest/java/com/owncloud/android/lib/resources/files/ReadFileVersionsRemoteOperationIT.kt b/library/src/androidTest/java/com/owncloud/android/lib/resources/files/ReadFileVersionsRemoteOperationIT.kt index 429f29c6f..c1cfd6186 100644 --- a/library/src/androidTest/java/com/owncloud/android/lib/resources/files/ReadFileVersionsRemoteOperationIT.kt +++ b/library/src/androidTest/java/com/owncloud/android/lib/resources/files/ReadFileVersionsRemoteOperationIT.kt @@ -41,7 +41,7 @@ class ReadFileVersionsRemoteOperationIT : AbstractIT() { txtFile.absolutePath, filePath, "txt/plain", - (System.currentTimeMillis() / MILLI_TO_SECOND).toString() + System.currentTimeMillis() / MILLI_TO_SECOND ) .execute(client) @@ -73,7 +73,7 @@ class ReadFileVersionsRemoteOperationIT : AbstractIT() { txtFile.absolutePath, filePath, "txt/plain", - (System.currentTimeMillis() / MILLI_TO_SECOND).toString() + System.currentTimeMillis() / MILLI_TO_SECOND ) .execute(client) diff --git a/library/src/androidTest/java/com/owncloud/android/lib/resources/files/SearchRemoteOperationIT.java b/library/src/androidTest/java/com/owncloud/android/lib/resources/files/SearchRemoteOperationIT.java index fcf2bf308..f73b519d4 100644 --- a/library/src/androidTest/java/com/owncloud/android/lib/resources/files/SearchRemoteOperationIT.java +++ b/library/src/androidTest/java/com/owncloud/android/lib/resources/files/SearchRemoteOperationIT.java @@ -231,15 +231,15 @@ public void favoriteFiles() throws IOException { public void testRecentlyModifiedSearch() throws IOException { long now = System.currentTimeMillis() / MILLI_TO_SECOND; String filePath = createFile("image"); - assertTrue(new UploadFileRemoteOperation(filePath, "/image.jpg", "image/jpg", String.valueOf(now - 50)) + assertTrue(new UploadFileRemoteOperation(filePath, "/image.jpg", "image/jpg", now - 50) .execute(client).isSuccess()); String videoPath = createFile("video"); - assertTrue(new UploadFileRemoteOperation(videoPath, "/video.mp4", "video/mpeg", String.valueOf(now - 10)) + assertTrue(new UploadFileRemoteOperation(videoPath, "/video.mp4", "video/mpeg", now - 10) .execute(client).isSuccess()); String pdfPath = createFile("pdf"); - assertTrue(new UploadFileRemoteOperation(pdfPath, "/pdf.pdf", "application/pdf", String.valueOf(now - 30)) + assertTrue(new UploadFileRemoteOperation(pdfPath, "/pdf.pdf", "application/pdf", now - 30) .execute(client).isSuccess()); String oldPath = createFile("pdf"); @@ -295,11 +295,12 @@ public void testPhotoSearchLimit() throws IOException { for (int i = 0; i < 10; i++) { String filePath = createFile("image" + i); String remotePath = "/image" + i + ".jpg"; - assertTrue(new UploadFileRemoteOperation(filePath, + assertTrue(new UploadFileRemoteOperation( + filePath, remotePath, "image/jpg", - String.valueOf(100000 + i * 10000)) - .execute(client).isSuccess()); + 100000 + i * 10000 + ).execute(client).isSuccess()); } // get all @@ -329,8 +330,8 @@ public void testPhotoSearchTimestamps() throws IOException { filePath, remotePath, "image/jpg", - String.valueOf(1464818400 + i)) - .execute(client).isSuccess()); + 1464818400 + i + ).execute(client).isSuccess()); } SearchRemoteOperation sut = new SearchRemoteOperation("image/%", @@ -361,8 +362,8 @@ public void testPhotoSearchLimitDates() throws IOException { filePath, remotePath, "image/jpg", - String.valueOf(randomUnixTimestamp + i)) - .execute(client).isSuccess()); + randomUnixTimestamp + i + ).execute(client).isSuccess()); } SearchRemoteOperation sut = new SearchRemoteOperation("image/%", @@ -388,11 +389,12 @@ public void testPhotoSearchLimitAndTimestamp() throws IOException { for (int i = 0; i < 10; i++) { String filePath = createFile("image" + i); String remotePath = "/image" + i + ".jpg"; - assertTrue(new UploadFileRemoteOperation(filePath, + assertTrue(new UploadFileRemoteOperation( + filePath, remotePath, "image/jpg", - String.valueOf(100000 + i * 10000)) - .execute(client).isSuccess()); + 100000 + i * 10000 + ).execute(client).isSuccess()); } // get all diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/ChunkedFileUploadRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/files/ChunkedFileUploadRemoteOperation.java index 6d93a9f21..520bf3ff4 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/ChunkedFileUploadRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/ChunkedFileUploadRemoteOperation.java @@ -69,7 +69,7 @@ public ChunkedFileUploadRemoteOperation(String storagePath, String remotePath, String mimeType, String requiredEtag, - String lastModificationTimestamp, + long lastModificationTimestamp, boolean onWifiConnection) { this(storagePath, remotePath, mimeType, requiredEtag, lastModificationTimestamp, onWifiConnection, null); } @@ -78,7 +78,7 @@ public ChunkedFileUploadRemoteOperation(String storagePath, String remotePath, String mimeType, String requiredEtag, - String lastModificationTimestamp, + long lastModificationTimestamp, Long creationTimestamp, boolean onWifiConnection, boolean disableRetries) { @@ -97,7 +97,7 @@ public ChunkedFileUploadRemoteOperation(String storagePath, String remotePath, String mimeType, String requiredEtag, - String lastModificationTimestamp, + long lastModificationTimestamp, boolean onWifiConnection, String token) { this(storagePath, @@ -115,7 +115,7 @@ public ChunkedFileUploadRemoteOperation(String storagePath, String remotePath, String mimeType, String requiredEtag, - String lastModificationTimestamp, + long lastModificationTimestamp, boolean onWifiConnection, String token, Long creationTimestamp, @@ -207,7 +207,10 @@ protected RemoteOperationResult run(OwnCloudClient client) { String originUri = uploadFolderUri + "/.file"; moveMethod = new MoveMethod(originUri, destinationUri, true); - moveMethod.addRequestHeader(OC_X_OC_MTIME_HEADER, lastModificationTimestamp); + moveMethod.addRequestHeader( + OC_X_OC_MTIME_HEADER, + String.valueOf(lastModificationTimestamp) + ); if (creationTimestamp != null && creationTimestamp > 0) { moveMethod.addRequestHeader(OC_X_OC_CTIME_HEADER, String.valueOf(creationTimestamp)); diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/UploadFileRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/files/UploadFileRemoteOperation.java index 8d87c895e..268fbdfc8 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/UploadFileRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/UploadFileRemoteOperation.java @@ -64,10 +64,7 @@ public class UploadFileRemoteOperation extends RemoteOperation { protected String localPath; protected String remotePath; protected String mimeType; - /** - * Must be in seconds, according to UNIX time - */ - protected String lastModificationTimestamp; + protected long lastModificationTimestamp; // must be in seconds, according to UNIX time protected Long creationTimestamp = null; protected boolean disableRetries = false; PutMethod putMethod = null; @@ -89,7 +86,7 @@ public UploadFileRemoteOperation(String localPath, String remotePath, String mimeType, String requiredEtag, - String lastModificationTimestamp) { + long lastModificationTimestamp) { this(localPath, remotePath, mimeType, requiredEtag, lastModificationTimestamp, null); } @@ -97,7 +94,7 @@ public UploadFileRemoteOperation(String localPath, String remotePath, String mimeType, String requiredEtag, - String lastModificationTimestamp, + long lastModificationTimestamp, Long creationTimestamp, boolean disableRetries) { this(localPath, @@ -113,25 +110,18 @@ public UploadFileRemoteOperation(String localPath, public UploadFileRemoteOperation(String localPath, String remotePath, String mimeType, - String lastModificationTimestamp) { + long lastModificationTimestamp) { this(localPath, remotePath, mimeType, lastModificationTimestamp, true); } public UploadFileRemoteOperation(String localPath, String remotePath, String mimeType, - String lastModificationTimestamp, + long lastModificationTimestamp, boolean disableRetries) { this.localPath = localPath; this.remotePath = remotePath; this.mimeType = mimeType; - - if (lastModificationTimestamp == null) { - throw new AssertionError("LastModificationTimestamp may NOT be null!"); - } - - // TODO check for max value of lastModificationTimestamp - this.lastModificationTimestamp = lastModificationTimestamp; this.disableRetries = disableRetries; } @@ -140,7 +130,7 @@ public UploadFileRemoteOperation(String localPath, String remotePath, String mimeType, String requiredEtag, - String lastModificationTimestamp, + long lastModificationTimestamp, String token) { this(localPath, remotePath, mimeType, requiredEtag, lastModificationTimestamp, null, token, true); } @@ -149,7 +139,7 @@ public UploadFileRemoteOperation(String localPath, String remotePath, String mimeType, String requiredEtag, - String lastModificationTimestamp, + long lastModificationTimestamp, Long creationTimestamp, String token, boolean disableRetries) { @@ -226,7 +216,10 @@ protected RemoteOperationResult uploadFile(OwnCloudClient client) throws putMethod.addRequestHeader(IF_MATCH_HEADER, "\"" + requiredEtag + "\""); } putMethod.addRequestHeader(OC_TOTAL_LENGTH_HEADER, String.valueOf(f.length())); - putMethod.addRequestHeader(OC_X_OC_MTIME_HEADER, lastModificationTimestamp); + putMethod.addRequestHeader( + OC_X_OC_MTIME_HEADER, + String.valueOf(lastModificationTimestamp) + ); if (creationTimestamp != null && creationTimestamp > 0) { putMethod.addRequestHeader(OC_X_OC_CTIME_HEADER, String.valueOf(creationTimestamp)); diff --git a/library/src/test/java/com/owncloud/android/lib/resources/files/ChunkedFileUploadRemoteOperationTest.java b/library/src/test/java/com/owncloud/android/lib/resources/files/ChunkedFileUploadRemoteOperationTest.java index 5ed47ab62..c73af1b85 100644 --- a/library/src/test/java/com/owncloud/android/lib/resources/files/ChunkedFileUploadRemoteOperationTest.java +++ b/library/src/test/java/com/owncloud/android/lib/resources/files/ChunkedFileUploadRemoteOperationTest.java @@ -148,12 +148,11 @@ public void testUploadChunksMissingChunks2() { public void testAssembleTimeout() { MockitoAnnotations.openMocks(this); - String modificationTimestamp = String.valueOf(System.currentTimeMillis() / 1000); ChunkedFileUploadRemoteOperation sut = new ChunkedFileUploadRemoteOperation(null, null, null, null, - modificationTimestamp, + System.currentTimeMillis() / 1000, false); // 0b @@ -215,12 +214,11 @@ private boolean test(List existingChunks, List expectedMissingChunks, long chunkSize, long length) { - String modificationTimestamp = String.valueOf(System.currentTimeMillis() / 1000); ChunkedFileUploadRemoteOperation sut = new ChunkedFileUploadRemoteOperation(null, null, null, null, - modificationTimestamp, + System.currentTimeMillis() / 1000, false); List missingChunks = sut.checkMissingChunks(existingChunks, length, chunkSize); diff --git a/sample_client/src/main/java/com/owncloud/android/lib/sampleclient/MainActivity.java b/sample_client/src/main/java/com/owncloud/android/lib/sampleclient/MainActivity.java index 05f447786..56a8cab92 100644 --- a/sample_client/src/main/java/com/owncloud/android/lib/sampleclient/MainActivity.java +++ b/sample_client/src/main/java/com/owncloud/android/lib/sampleclient/MainActivity.java @@ -154,20 +154,24 @@ private void startRefresh() { } private void startUpload() { - File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path)); - File fileToUpload = upFolder.listFiles()[0]; - String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName(); - String mimeType = getString(R.string.sample_file_mimetype); + File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path)); + File fileToUpload = upFolder.listFiles()[0]; + String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName(); + String mimeType = getString(R.string.sample_file_mimetype); // Get the last modification date of the file from the file system - Long timeStampLong = fileToUpload.lastModified() / 1000; - String timeStamp = timeStampLong.toString(); + long timeStamp = fileToUpload.lastModified() / 1000; - UploadFileRemoteOperation uploadOperation = - new UploadFileRemoteOperation(fileToUpload.getAbsolutePath(), remotePath, mimeType, timeStamp); - uploadOperation.addDataTransferProgressListener(this); - uploadOperation.execute(mClient, this, mHandler); - } + UploadFileRemoteOperation uploadOperation = + new UploadFileRemoteOperation( + fileToUpload.getAbsolutePath(), + remotePath, + mimeType, + timeStamp + ); + uploadOperation.addDataTransferProgressListener(this); + uploadOperation.execute(mClient, this, mHandler); + } private void startRemoteDeletion() { File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path)); diff --git a/scripts/uploadReport.sh b/scripts/uploadReport.sh index a13ddae73..7a8276efd 100755 --- a/scripts/uploadReport.sh +++ b/scripts/uploadReport.sh @@ -18,6 +18,11 @@ else cd library/build/reports/tests/testDebugUnitTest fi +if [ $? -ne 0 ]; then + echo "No reports folder available! Perhaps compilation failed." + exit 1 +fi + find . -type d -exec curl -u $USER:$PASS -X MKCOL $URL/$REMOTE_FOLDER/$(echo {} | sed s#\./##) \; find . -type f -exec curl -u $USER:$PASS -X PUT $URL/$REMOTE_FOLDER/$(echo {} | sed s#\./##) --upload-file {} \;