From 14f81c5355d04c04426a4a6ba9a9f838e7a7416e Mon Sep 17 00:00:00 2001 From: alperozturk96 Date: Mon, 12 Oct 2026 09:22:00 +0200 Subject: [PATCH 1/4] fix tests Signed-off-by: alperozturk96 --- .../com/owncloud/android/operations/UploadFileOperation.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java b/app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java index be3f3fc7f4b1..7212caf8fea9 100644 --- a/app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java @@ -1802,6 +1802,8 @@ private void updateOCFile(OCFile file, RemoteFile remoteFile) { file.setPermissions(remoteFile.getPermissions()); file.setUploadTimestamp(remoteFile.getUploadTimestamp()); file.setPreviewAvailable(remoteFile.isHasPreview()); + file.setImageDimension(remoteFile.getImageDimension()); + file.setGeoLocation(remoteFile.getGeoLocation()); } public interface OnRenameListener { From 51333d98c70c36873ab1e1c817c705954fb066fd Mon Sep 17 00:00:00 2001 From: alperozturk96 Date: Mon, 12 Oct 2026 09:22:07 +0200 Subject: [PATCH 2/4] Rename .java to .kt Signed-off-by: alperozturk96 --- .../java/com/owncloud/android/{UploadIT.java => UploadIT.kt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename app/src/androidTest/java/com/owncloud/android/{UploadIT.java => UploadIT.kt} (100%) diff --git a/app/src/androidTest/java/com/owncloud/android/UploadIT.java b/app/src/androidTest/java/com/owncloud/android/UploadIT.kt similarity index 100% rename from app/src/androidTest/java/com/owncloud/android/UploadIT.java rename to app/src/androidTest/java/com/owncloud/android/UploadIT.kt From 357e9853e5415476e6a51cc7e1768a470da60a2c Mon Sep 17 00:00:00 2001 From: alperozturk96 Date: Mon, 12 Oct 2026 09:22:08 +0200 Subject: [PATCH 3/4] convert UploadIT to kotlin Signed-off-by: alperozturk96 --- .../java/com/owncloud/android/UploadIT.kt | 586 +++++++----------- 1 file changed, 223 insertions(+), 363 deletions(-) diff --git a/app/src/androidTest/java/com/owncloud/android/UploadIT.kt b/app/src/androidTest/java/com/owncloud/android/UploadIT.kt index 54966c13320a..bc1d638f3f6c 100644 --- a/app/src/androidTest/java/com/owncloud/android/UploadIT.kt +++ b/app/src/androidTest/java/com/owncloud/android/UploadIT.kt @@ -1,438 +1,298 @@ /* * Nextcloud - Android Client * + * SPDX-FileCopyrightText: 2026 Alper Ozturk * SPDX-FileCopyrightText: 2020 Tobias Kaminsky * SPDX-FileCopyrightText: 2020 Chris Narkiewicz * SPDX-FileCopyrightText: 2020 Nextcloud GmbH * SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only */ -package com.owncloud.android; - -import com.nextcloud.client.account.UserAccountManagerImpl; -import com.nextcloud.utils.PowerManagementFactory; -import com.nextcloud.client.device.PowerManagementService; -import com.nextcloud.client.jobs.upload.FileUploadWorker; -import com.nextcloud.client.network.ConnectivityManagerFactory; -import com.nextcloud.client.network.ConnectivityService; -import com.nextcloud.test.SinceServer; -import com.owncloud.android.datamodel.OCFile; -import com.owncloud.android.datamodel.UploadsStorageManager; -import com.owncloud.android.db.OCUpload; -import com.owncloud.android.files.services.NameCollisionPolicy; -import com.owncloud.android.lib.common.accounts.AccountUtils; -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.resources.files.model.GeoLocation; -import com.owncloud.android.lib.resources.files.model.ImageDimension; -import com.owncloud.android.lib.resources.status.NextcloudVersion; -import com.owncloud.android.operations.RefreshFolderOperation; -import com.owncloud.android.operations.RemoveFileOperation; -import com.owncloud.android.operations.UploadFileOperation; -import com.owncloud.android.utils.FileStorageUtils; - -import org.junit.Before; -import org.junit.Test; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import static junit.framework.TestCase.assertEquals; -import static junit.framework.TestCase.assertFalse; -import static junit.framework.TestCase.assertNotNull; -import static junit.framework.TestCase.assertTrue; - -/** - * Tests related to file uploads. - */ -public class UploadIT extends AbstractOnServerIT { - private static final String FOLDER = "/testUpload/"; - - private UploadsStorageManager uploadsStorageManager = - new UploadsStorageManager(UserAccountManagerImpl.fromContext(targetContext), - targetContext.getContentResolver()); - - private final PowerManagementService powerManagementServiceMock = PowerManagementFactory.getMock(); +@file:Suppress("DEPRECATION") + +package com.owncloud.android + +import com.nextcloud.client.account.UserAccountManagerImpl +import com.nextcloud.client.device.PowerManagementService +import com.nextcloud.client.jobs.upload.FileUploadWorker +import com.nextcloud.client.network.ConnectivityManagerFactory +import com.nextcloud.client.network.ConnectivityService +import com.nextcloud.test.SinceServer +import com.nextcloud.utils.PowerManagementFactory +import com.owncloud.android.datamodel.OCFile +import com.owncloud.android.datamodel.UploadsStorageManager +import com.owncloud.android.db.OCUpload +import com.owncloud.android.files.services.NameCollisionPolicy +import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode +import com.owncloud.android.lib.resources.files.model.GeoLocation +import com.owncloud.android.lib.resources.files.model.ImageDimension +import com.owncloud.android.lib.resources.status.NextcloudVersion +import com.owncloud.android.operations.RefreshFolderOperation +import com.owncloud.android.operations.RemoveFileOperation +import com.owncloud.android.operations.UploadFileOperation +import com.owncloud.android.utils.FileStorageUtils +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Before +import org.junit.Test +import java.io.File +import java.nio.file.Files +import java.nio.file.attribute.BasicFileAttributes +import java.util.concurrent.TimeUnit +import kotlin.math.abs + +class UploadIT : AbstractOnServerIT() { + private val uploadsStorageManager = UploadsStorageManager( + UserAccountManagerImpl.fromContext(targetContext), + targetContext.contentResolver + ) + + private val powerManagementServiceMock = PowerManagementFactory.mock @Before - public void before() throws IOException { - // make sure that every file is available, even after tests that remove source file - createDummyFiles(); + fun before() { + createDummyFiles() } @Test - public void testEmptyUpload() { - OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt", - FOLDER + "empty.txt", - account.name); + fun testEmptyUpload() { + uploadOCUpload(ocUpload(EMPTY_FILE, "$FOLDER$EMPTY_FILE")) + } - uploadOCUpload(ocUpload); + @Test + fun testNonEmptyUpload() { + uploadOCUpload(ocUpload(NON_EMPTY_FILE, "$FOLDER$NON_EMPTY_FILE")) } @Test - public void testNonEmptyUpload() { - OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt", - FOLDER + "nonEmpty.txt", - account.name); + fun testUploadWithCopy() { + uploadOCUpload(nonEmptyUpload(), FileUploadWorker.LOCAL_BEHAVIOUR_COPY) - uploadOCUpload(ocUpload); + val uploadedFile = uploadedNonEmptyFile() + assertTrue(temporalFile(NON_EMPTY_FILE).exists()) + assertTrue(File(uploadedFile.storagePath).exists()) + verifyStoragePath(uploadedFile) } @Test - public void testUploadWithCopy() { - OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt", - FOLDER + "nonEmpty.txt", - account.name); + fun testUploadWithMove() { + uploadOCUpload(nonEmptyUpload(), FileUploadWorker.LOCAL_BEHAVIOUR_MOVE) - uploadOCUpload(ocUpload, FileUploadWorker.LOCAL_BEHAVIOUR_COPY); + val uploadedFile = uploadedNonEmptyFile() + assertFalse(temporalFile(NON_EMPTY_FILE).exists()) + assertTrue(File(uploadedFile.storagePath).exists()) + verifyStoragePath(uploadedFile) + } - File originalFile = new File(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt"); - OCFile uploadedFile = fileDataStorageManager.getFileByDecryptedRemotePath(FOLDER + "nonEmpty.txt"); + @Test + fun testUploadWithForget() { + uploadOCUpload(nonEmptyUpload(), FileUploadWorker.LOCAL_BEHAVIOUR_FORGET) - assertTrue(originalFile.exists()); - assertTrue(new File(uploadedFile.getStoragePath()).exists()); - verifyStoragePath(uploadedFile); + val uploadedFile = uploadedNonEmptyFile() + assertTrue(temporalFile(NON_EMPTY_FILE).exists()) + assertFalse(File(uploadedFile.storagePath).exists()) + assertTrue(uploadedFile.storagePath.isEmpty()) } @Test - public void testUploadWithMove() { - OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt", - FOLDER + "nonEmpty.txt", - account.name); + fun testUploadWithDelete() { + uploadOCUpload(nonEmptyUpload(), FileUploadWorker.LOCAL_BEHAVIOUR_DELETE) - uploadOCUpload(ocUpload, FileUploadWorker.LOCAL_BEHAVIOUR_MOVE); - - File originalFile = new File(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt"); - OCFile uploadedFile = fileDataStorageManager.getFileByDecryptedRemotePath(FOLDER + "nonEmpty.txt"); + val uploadedFile = uploadedNonEmptyFile() + assertFalse(temporalFile(NON_EMPTY_FILE).exists()) + assertFalse(File(uploadedFile.storagePath).exists()) + assertTrue(uploadedFile.storagePath.isEmpty()) + } - assertFalse(originalFile.exists()); - assertTrue(new File(uploadedFile.getStoragePath()).exists()); - verifyStoragePath(uploadedFile); + @Test + fun testChunkedUpload() { + uploadOCUpload(ocUpload(CHUNKED_FILE, "$FOLDER$CHUNKED_FILE")) } @Test - public void testUploadWithForget() { - OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt", - FOLDER + "nonEmpty.txt", - account.name); + fun testUploadInNonExistingFolder() { + uploadOCUpload(ocUpload(EMPTY_FILE, "${FOLDER}2/3/4/1.txt")) + } - uploadOCUpload(ocUpload, FileUploadWorker.LOCAL_BEHAVIOUR_FORGET); + @Test + fun testUploadOnChargingOnlyButNotCharging() { + val upload = ocUpload(EMPTY_FILE, "${FOLDER}notCharging.txt").apply { isWhileChargingOnly = true } - File originalFile = new File(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt"); - OCFile uploadedFile = fileDataStorageManager.getFileByDecryptedRemotePath(FOLDER + "nonEmpty.txt"); + val result = uploadOperation(upload, whileChargingOnly = true).execute(client) - assertTrue(originalFile.exists()); - assertFalse(new File(uploadedFile.getStoragePath()).exists()); - assertTrue(uploadedFile.getStoragePath().isEmpty()); + assertFalse(result.toString(), result.isSuccess) + assertEquals(ResultCode.DELAYED_FOR_CHARGING, result.code) } @Test - public void testUploadWithDelete() { - OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt", - FOLDER + "nonEmpty.txt", - account.name); - - uploadOCUpload(ocUpload, FileUploadWorker.LOCAL_BEHAVIOUR_DELETE); + fun testUploadOnChargingOnlyAndCharging() { + val upload = ocUpload(EMPTY_FILE, "${FOLDER}charging.txt").apply { isWhileChargingOnly = true } - File originalFile = new File(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt"); - OCFile uploadedFile = fileDataStorageManager.getFileByDecryptedRemotePath(FOLDER + "nonEmpty.txt"); + val result = uploadOperation( + upload, + powerManagementService = PowerManagementFactory.mockCharging, + whileChargingOnly = true + ).execute(client) - assertFalse(originalFile.exists()); - assertFalse(new File(uploadedFile.getStoragePath()).exists()); - assertTrue(uploadedFile.getStoragePath().isEmpty()); + assertTrue(result.toString(), result.isSuccess) } @Test - public void testChunkedUpload() { - OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/chunkedFile.txt", - FOLDER + "chunkedFile.txt", account.name); + fun testUploadOnWifiOnlyButNoWifi() { + val upload = ocUpload(EMPTY_FILE, "${FOLDER}noWifi.txt").apply { isUseWifiOnly = true } + + val result = uploadOperation( + upload, + connectivityService = ConnectivityManagerFactory.wifi, + onWifiOnly = true + ).execute(client) - uploadOCUpload(ocUpload); + assertFalse(result.toString(), result.isSuccess) + assertEquals(ResultCode.DELAYED_FOR_WIFI, result.code) } @Test - public void testUploadInNonExistingFolder() { - OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt", - FOLDER + "2/3/4/1.txt", account.name); + fun testUploadOnWifiOnlyAndWifi() { + val upload = ocUpload(EMPTY_FILE, "${FOLDER}wifi.txt").apply { isWhileChargingOnly = true } - uploadOCUpload(ocUpload); + val result = uploadOperation(upload, onWifiOnly = true).execute(client) + + assertTrue(result.toString(), result.isSuccess) + removeTestFolder() } @Test - public void testUploadOnChargingOnlyButNotCharging() { - OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt", - FOLDER + "notCharging.txt", account.name); - ocUpload.setWhileChargingOnly(true); - - UploadFileOperation newUpload = new UploadFileOperation( - uploadsStorageManager, - connectivityServiceMock, - powerManagementServiceMock, - user, - null, - ocUpload, - NameCollisionPolicy.DEFAULT, - FileUploadWorker.LOCAL_BEHAVIOUR_COPY, - targetContext, - false, - true, - getStorageManager() - ); - newUpload.setRemoteFolderToBeCreated(); - newUpload.addRenameUploadListener(() -> { - // dummy - }); - - RemoteOperationResult result = newUpload.execute(client); - assertFalse(result.toString(), result.isSuccess()); - assertEquals(RemoteOperationResult.ResultCode.DELAYED_FOR_CHARGING, result.getCode()); + fun testUploadOnWifiOnlyButMeteredWifi() { + val upload = ocUpload(EMPTY_FILE, "${FOLDER}noWifi.txt").apply { isUseWifiOnly = true } + + val result = uploadOperation( + upload, + connectivityService = ConnectivityManagerFactory.metered, + onWifiOnly = true + ).execute(client) + + assertFalse(result.toString(), result.isSuccess) + assertEquals(ResultCode.DELAYED_FOR_WIFI, result.code) } @Test - public void testUploadOnChargingOnlyAndCharging() { - final var powerManagementServiceMock = PowerManagementFactory.getMockCharging(); - 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, - FileUploadWorker.LOCAL_BEHAVIOUR_COPY, - targetContext, - false, - true, - getStorageManager() - ); - newUpload.setRemoteFolderToBeCreated(); - newUpload.addRenameUploadListener(() -> { - // dummy - }); - - RemoteOperationResult result = newUpload.execute(client); - assertTrue(result.toString(), result.isSuccess()); + @SinceServer(majorVersion = 27) + fun testCreationAndUploadTimestamp() { + testOnlyOnServer(NextcloudVersion.nextcloud_27) + + val file = getDummyFile(EMPTY_FILE) + val remotePath = "/testFile.txt" + + assertTrue(uploadOperation(OCUpload(file.absolutePath, remotePath, account.name)).execute(client).isSuccess) + + val creationTimestamp = Files.readAttributes(file.toPath(), BasicFileAttributes::class.java) + .creationTime() + .to(TimeUnit.SECONDS) + val uploadTimestamp = nowInSeconds() + + val ocFile = refreshRootAndGetContent().first() + + assertEquals(remotePath, ocFile.remotePath) + assertEquals(creationTimestamp, ocFile.creationTimestamp) + assertTrue(abs(ocFile.uploadTimestamp - uploadTimestamp) < UPLOAD_TIMESTAMP_TOLERANCE_SECONDS) } @Test - public void testUploadOnWifiOnlyButNoWifi() { - ConnectivityService connectivityServiceMock = ConnectivityManagerFactory.INSTANCE.getWifi(); - OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt", - FOLDER + "noWifi.txt", account.name); - ocUpload.setUseWifiOnly(true); - - UploadFileOperation newUpload = new UploadFileOperation( - uploadsStorageManager, - connectivityServiceMock, - powerManagementServiceMock, - user, - null, - ocUpload, - NameCollisionPolicy.DEFAULT, - FileUploadWorker.LOCAL_BEHAVIOUR_COPY, - targetContext, - true, - false, - getStorageManager() - ); - newUpload.setRemoteFolderToBeCreated(); - newUpload.addRenameUploadListener(() -> { - // dummy - }); - - RemoteOperationResult result = newUpload.execute(client); - assertFalse(result.toString(), result.isSuccess()); - assertEquals(RemoteOperationResult.ResultCode.DELAYED_FOR_WIFI, result.getCode()); + @SinceServer(majorVersion = 27) + fun testMetadata() { + testOnlyOnServer(NextcloudVersion.nextcloud_27) + + val file = getFile("gps.jpg") + val remotePath = "/$METADATA_FILE" + + assertTrue(uploadOperation(OCUpload(file.absolutePath, remotePath, account.name)).execute(client).isSuccess) + + val ocFile = checkNotNull(refreshRootAndGetContent().find { it.fileName == METADATA_FILE }) { + "$METADATA_FILE not found in root folder" + } + + assertEquals(remotePath, ocFile.remotePath) + assertEquals(GeoLocation(EXPECTED_LATITUDE, EXPECTED_LONGITUDE), ocFile.geoLocation) + assertEquals(ImageDimension(EXPECTED_WIDTH, EXPECTED_HEIGHT), ocFile.imageDimension) } - @Test - public void testUploadOnWifiOnlyAndWifi() { - OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt", - FOLDER + "wifi.txt", account.name); - ocUpload.setWhileChargingOnly(true); - - UploadFileOperation newUpload = new UploadFileOperation( - uploadsStorageManager, - connectivityServiceMock, - powerManagementServiceMock, - user, - null, - ocUpload, - NameCollisionPolicy.DEFAULT, - FileUploadWorker.LOCAL_BEHAVIOUR_COPY, - targetContext, - true, - false, - getStorageManager() - ); - newUpload.setRemoteFolderToBeCreated(); - newUpload.addRenameUploadListener(() -> { - // dummy - }); - - RemoteOperationResult result = newUpload.execute(client); - assertTrue(result.toString(), result.isSuccess()); - - // cleanup - new RemoveFileOperation(getStorageManager().getFileByDecryptedRemotePath(FOLDER), - false, - user, - false, - targetContext, - getStorageManager()) - .execute(client); + private fun uploadOperation( + upload: OCUpload, + connectivityService: ConnectivityService = connectivityServiceMock, + powerManagementService: PowerManagementService = powerManagementServiceMock, + onWifiOnly: Boolean = false, + whileChargingOnly: Boolean = false + ): UploadFileOperation = UploadFileOperation( + uploadsStorageManager, + connectivityService, + powerManagementService, + user, + null, + upload, + NameCollisionPolicy.DEFAULT, + FileUploadWorker.LOCAL_BEHAVIOUR_COPY, + targetContext, + onWifiOnly, + whileChargingOnly, + storageManager + ).apply { + setRemoteFolderToBeCreated() + addRenameUploadListener {} } - @Test - public void testUploadOnWifiOnlyButMeteredWifi() { - ConnectivityService connectivityServiceMock = ConnectivityManagerFactory.INSTANCE.getMetered(); - OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt", - FOLDER + "noWifi.txt", - account.name); - ocUpload.setUseWifiOnly(true); - - UploadFileOperation newUpload = new UploadFileOperation( - uploadsStorageManager, - connectivityServiceMock, - powerManagementServiceMock, - user, - null, - ocUpload, - NameCollisionPolicy.DEFAULT, - FileUploadWorker.LOCAL_BEHAVIOUR_COPY, - targetContext, - true, + private fun refreshRootAndGetContent(): List { + val refreshResult = RefreshFolderOperation( + storageManager.getFileByDecryptedRemotePath(OCFile.ROOT_PATH), + nowInSeconds(), false, - getStorageManager() - ); - newUpload.setRemoteFolderToBeCreated(); - newUpload.addRenameUploadListener(() -> { - // dummy - }); - - RemoteOperationResult result = newUpload.execute(client); - assertFalse(result.toString(), result.isSuccess()); - assertEquals(RemoteOperationResult.ResultCode.DELAYED_FOR_WIFI, result.getCode()); - } + false, + storageManager, + user, + targetContext + ).execute(client) + assertTrue(refreshResult.isSuccess) - @Test - @SinceServer(majorVersion = 27) - public void testCreationAndUploadTimestamp() throws IOException, AccountUtils.AccountNotFoundException { - testOnlyOnServer(NextcloudVersion.nextcloud_27); - - File file = getDummyFile("empty.txt"); - String remotePath = "/testFile.txt"; - OCUpload ocUpload = new OCUpload(file.getAbsolutePath(), remotePath, account.name); - - assertTrue( - new UploadFileOperation( - uploadsStorageManager, - connectivityServiceMock, - powerManagementServiceMock, - user, - null, - ocUpload, - NameCollisionPolicy.DEFAULT, - FileUploadWorker.LOCAL_BEHAVIOUR_COPY, - targetContext, - false, - false, - getStorageManager() - ) - .setRemoteFolderToBeCreated() - .execute(client) - .isSuccess() - ); - - long creationTimestamp = Files.readAttributes(file.toPath(), BasicFileAttributes.class) - .creationTime() - .to(TimeUnit.SECONDS); + return storageManager.getFolderContent(storageManager.getFileByDecryptedRemotePath(OCFile.ROOT_PATH), false) + } - long uploadTimestamp = System.currentTimeMillis() / 1000; + private fun removeTestFolder() { + val folder = checkNotNull(storageManager.getFileByDecryptedRemotePath(FOLDER)) { "$FOLDER not found" } + RemoveFileOperation(folder, false, user, false, targetContext, storageManager).execute(client) + } - // RefreshFolderOperation - assertTrue(new RefreshFolderOperation(getStorageManager().getFileByDecryptedRemotePath("/"), - System.currentTimeMillis() / 1000, - false, - false, - getStorageManager(), - user, - targetContext).execute(client).isSuccess()); + private fun temporalPath(name: String) = "${FileStorageUtils.getTemporalPath(account.name)}/$name" - List files = getStorageManager().getFolderContent(getStorageManager().getFileByDecryptedRemotePath("/"), - false); + private fun temporalFile(name: String) = File(temporalPath(name)) - OCFile ocFile = files.get(0); + private fun ocUpload(localName: String, remotePath: String) = + OCUpload(temporalPath(localName), remotePath, account.name) - assertEquals(remotePath, ocFile.getRemotePath()); - assertEquals(creationTimestamp, ocFile.getCreationTimestamp()); - assertTrue(uploadTimestamp - 10 < ocFile.getUploadTimestamp() && - uploadTimestamp + 10 > ocFile.getUploadTimestamp()); - } + private fun nonEmptyUpload() = ocUpload(NON_EMPTY_FILE, "$FOLDER$NON_EMPTY_FILE") - @Test - @SinceServer(majorVersion = 27) - public void testMetadata() throws IOException, AccountUtils.AccountNotFoundException { - testOnlyOnServer(NextcloudVersion.nextcloud_27); - - File file = getFile("gps.jpg"); - String remotePath = "/metadata.jpg"; - OCUpload ocUpload = new OCUpload(file.getAbsolutePath(), remotePath, account.name); - - assertTrue( - new UploadFileOperation( - uploadsStorageManager, - connectivityServiceMock, - powerManagementServiceMock, - user, - null, - ocUpload, - NameCollisionPolicy.DEFAULT, - FileUploadWorker.LOCAL_BEHAVIOUR_COPY, - targetContext, - false, - false, - getStorageManager() - ) - .setRemoteFolderToBeCreated() - .execute(client) - .isSuccess() - ); - - // RefreshFolderOperation - assertTrue(new RefreshFolderOperation(getStorageManager().getFileByDecryptedRemotePath("/"), - System.currentTimeMillis() / 1000, - false, - false, - getStorageManager(), - user, - targetContext).execute(client).isSuccess()); - - List files = getStorageManager().getFolderContent(getStorageManager().getFileByDecryptedRemotePath("/"), - false); - - OCFile ocFile = null; - for (OCFile f : files) { - if ("metadata.jpg".equals(f.getFileName())) { - ocFile = f; - break; - } + private fun uploadedNonEmptyFile(): OCFile = + checkNotNull(storageManager.getFileByDecryptedRemotePath("$FOLDER$NON_EMPTY_FILE")) { + "$FOLDER$NON_EMPTY_FILE not found" } - assertNotNull(ocFile); - assertEquals(remotePath, ocFile.getRemotePath()); - assertEquals(new GeoLocation(64, -46), ocFile.getGeoLocation()); - assertEquals(new ImageDimension(300f, 200f), ocFile.getImageDimension()); + private fun nowInSeconds() = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()) + + private fun verifyStoragePath(file: OCFile) { + assertEquals( + FileStorageUtils.getSavePath(account.name) + FOLDER + file.decryptedFileName, + file.storagePath + ) } - private void verifyStoragePath(OCFile file) { - assertEquals(FileStorageUtils.getSavePath(account.name) + FOLDER + file.getDecryptedFileName(), - file.getStoragePath()); + companion object { + private const val FOLDER = "/testUpload/" + private const val EMPTY_FILE = "empty.txt" + private const val NON_EMPTY_FILE = "nonEmpty.txt" + private const val CHUNKED_FILE = "chunkedFile.txt" + private const val METADATA_FILE = "metadata.jpg" + private const val UPLOAD_TIMESTAMP_TOLERANCE_SECONDS = 10 + private const val EXPECTED_LATITUDE = 64.0 + private const val EXPECTED_LONGITUDE = -46.0 + private const val EXPECTED_WIDTH = 300f + private const val EXPECTED_HEIGHT = 200f } } From 0887263fbf45858ab80dd811919da57f36901a5f Mon Sep 17 00:00:00 2001 From: alperozturk96 Date: Mon, 12 Oct 2026 09:24:41 +0200 Subject: [PATCH 4/4] fix codacy Signed-off-by: alperozturk96 --- app/src/androidTest/java/com/owncloud/android/UploadIT.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/androidTest/java/com/owncloud/android/UploadIT.kt b/app/src/androidTest/java/com/owncloud/android/UploadIT.kt index bc1d638f3f6c..67ddf44fbb43 100644 --- a/app/src/androidTest/java/com/owncloud/android/UploadIT.kt +++ b/app/src/androidTest/java/com/owncloud/android/UploadIT.kt @@ -7,7 +7,6 @@ * SPDX-FileCopyrightText: 2020 Nextcloud GmbH * SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only */ -@file:Suppress("DEPRECATION") package com.owncloud.android @@ -41,6 +40,7 @@ import java.nio.file.attribute.BasicFileAttributes import java.util.concurrent.TimeUnit import kotlin.math.abs +@Suppress("TooManyFunctions", "DEPRECATION") class UploadIT : AbstractOnServerIT() { private val uploadsStorageManager = UploadsStorageManager( UserAccountManagerImpl.fromContext(targetContext),