From 2fd734e5be7e8381b95fbaf469cd2cff66343973 Mon Sep 17 00:00:00 2001 From: Juan Carlos Garrote Date: Mon, 30 Sep 2024 15:03:00 +0200 Subject: [PATCH 1/4] refactor: changed FileRepository methods order in interface and implementation --- .../data/files/repository/OCFileRepository.kt | 90 +++++++++---------- .../android/domain/files/FileRepository.kt | 8 +- 2 files changed, 46 insertions(+), 52 deletions(-) diff --git a/owncloudData/src/main/java/com/owncloud/android/data/files/repository/OCFileRepository.kt b/owncloudData/src/main/java/com/owncloud/android/data/files/repository/OCFileRepository.kt index c161b5cb462..0ada7453f64 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/files/repository/OCFileRepository.kt +++ b/owncloudData/src/main/java/com/owncloud/android/data/files/repository/OCFileRepository.kt @@ -157,12 +157,12 @@ class OCFileRepository( override fun getFileById(fileId: Long): OCFile? = localFileDataSource.getFileById(fileId) - override fun getFileWithSyncInfoByIdAsFlow(fileId: Long): Flow = - localFileDataSource.getFileWithSyncInfoByIdAsFlow(fileId) - override fun getFileByIdAsFlow(fileId: Long): Flow = localFileDataSource.getFileByIdAsFlow(fileId) + override fun getFileWithSyncInfoByIdAsFlow(fileId: Long): Flow = + localFileDataSource.getFileWithSyncInfoByIdAsFlow(fileId) + override fun getFileByRemotePath(remotePath: String, owner: String, spaceId: String?): OCFile? = localFileDataSource.getFileByRemotePath(remotePath, owner, spaceId) @@ -328,46 +328,6 @@ class OCFileRepository( return filesNeedsAction } - private fun getFinalRemotePath( - replace: List, - expectedRemotePath: String, - targetFolder: OCFile, - targetSpaceWebDavUrl: String?, - filesNeedsAction: MutableList, - ocFile: OCFile, - position: Int, - isUserLogged: Boolean, - ) = - if (replace.isEmpty()) { - val pathExists = remoteFileDataSource.checkPathExistence( - path = expectedRemotePath, - isUserLogged = isUserLogged, - accountName = targetFolder.owner, - spaceWebDavUrl = targetSpaceWebDavUrl, - ) - if (pathExists) { - filesNeedsAction.add(ocFile) - null - } else { - if (ocFile.isFolder) expectedRemotePath.plus(File.separator) else expectedRemotePath - } - } else { - if (replace[position] == true) { - if (ocFile.isFolder) expectedRemotePath.plus(File.separator) else expectedRemotePath - } else if (replace[position] == false) { - remoteFileDataSource.getAvailableRemotePath( - remotePath = expectedRemotePath, - accountName = targetFolder.owner, - spaceWebDavUrl = targetSpaceWebDavUrl, - isUserLogged = isUserLogged, - ).let { - if (ocFile.isFolder) it.plus(File.separator) else it - } - } else { - null - } - } - override fun readFile(remotePath: String, accountName: String, spaceId: String?): OCFile { val spaceWebDavUrl = localSpacesDataSource.getWebDavUrlForSpace(spaceId, accountName) @@ -571,10 +531,6 @@ class OCFileRepository( localFileDataSource.updateDownloadedFilesStorageDirectoryInStoragePath(oldDirectory, newDirectory) } - override fun saveUploadWorkerUuid(fileId: Long, workerUuid: UUID) { - TODO("Not yet implemented") - } - override fun saveDownloadWorkerUuid(fileId: Long, workerUuid: UUID) { localFileDataSource.saveDownloadWorkerUuid(fileId, workerUuid) } @@ -583,6 +539,46 @@ class OCFileRepository( localFileDataSource.cleanWorkersUuid(fileId) } + private fun getFinalRemotePath( + replace: List, + expectedRemotePath: String, + targetFolder: OCFile, + targetSpaceWebDavUrl: String?, + filesNeedsAction: MutableList, + ocFile: OCFile, + position: Int, + isUserLogged: Boolean, + ) = + if (replace.isEmpty()) { + val pathExists = remoteFileDataSource.checkPathExistence( + path = expectedRemotePath, + isUserLogged = isUserLogged, + accountName = targetFolder.owner, + spaceWebDavUrl = targetSpaceWebDavUrl, + ) + if (pathExists) { + filesNeedsAction.add(ocFile) + null + } else { + if (ocFile.isFolder) expectedRemotePath.plus(File.separator) else expectedRemotePath + } + } else { + if (replace[position] == true) { + if (ocFile.isFolder) expectedRemotePath.plus(File.separator) else expectedRemotePath + } else if (replace[position] == false) { + remoteFileDataSource.getAvailableRemotePath( + remotePath = expectedRemotePath, + accountName = targetFolder.owner, + spaceWebDavUrl = targetSpaceWebDavUrl, + isUserLogged = isUserLogged, + ).let { + if (ocFile.isFolder) it.plus(File.separator) else it + } + } else { + null + } + } + private fun deleteLocalFolderRecursively(ocFile: OCFile, onlyFromLocalStorage: Boolean) { val folderContent = localFileDataSource.getFolderContent(ocFile.id!!) diff --git a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/FileRepository.kt b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/FileRepository.kt index 1e29e03f1a9..4674664ce10 100644 --- a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/FileRepository.kt +++ b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/FileRepository.kt @@ -68,13 +68,11 @@ interface FileRepository { fun saveFile(file: OCFile) fun saveConflict(fileId: Long, eTagInConflict: String) fun cleanConflict(fileId: Long) - fun saveUploadWorkerUuid(fileId: Long, workerUuid: UUID) - fun saveDownloadWorkerUuid(fileId: Long, workerUuid: UUID) - fun cleanWorkersUuid(fileId: Long) - fun disableThumbnailsForFile(fileId: Long) fun updateFileWithNewAvailableOfflineStatus(ocFile: OCFile, newAvailableOfflineStatus: AvailableOfflineStatus) - fun updateDownloadedFilesStorageDirectoryInStoragePath(oldDirectory: String, newDirectory: String) fun updateFileWithLastUsage(fileId: Long, lastUsage: Long?) + fun updateDownloadedFilesStorageDirectoryInStoragePath(oldDirectory: String, newDirectory: String) + fun saveDownloadWorkerUuid(fileId: Long, workerUuid: UUID) + fun cleanWorkersUuid(fileId: Long) } From e9a432eb159a8b799ffac94d3b83cee3a1d1d6d0 Mon Sep 17 00:00:00 2001 From: Juan Carlos Garrote Date: Tue, 1 Oct 2024 16:54:48 +0200 Subject: [PATCH 2/4] test: added tests for createFolder and copyFile from OCFileRepository --- .../files/repository/OCFileRepositoryTest.kt | 411 ++++++++++++++++-- .../com/owncloud/android/testutil/OCFile.kt | 50 ++- 2 files changed, 435 insertions(+), 26 deletions(-) diff --git a/owncloudData/src/test/java/com/owncloud/android/data/files/repository/OCFileRepositoryTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/files/repository/OCFileRepositoryTest.kt index eb3fffd4343..12b48a77526 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/files/repository/OCFileRepositoryTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/files/repository/OCFileRepositoryTest.kt @@ -3,6 +3,7 @@ * * @author Abel García de Prada * @author Aitor Ballesteros Pavón + * @author Juan Carlos Garrote Gascón * * Copyright (C) 2024 ownCloud GmbH. * @@ -25,13 +26,19 @@ import com.owncloud.android.data.files.datasources.LocalFileDataSource import com.owncloud.android.data.files.datasources.RemoteFileDataSource import com.owncloud.android.data.providers.LocalStorageProvider import com.owncloud.android.data.spaces.datasources.LocalSpacesDataSource +import com.owncloud.android.domain.exceptions.ConflictException import com.owncloud.android.domain.exceptions.FileNotFoundException import com.owncloud.android.domain.exceptions.NoConnectionWithServerException +import com.owncloud.android.domain.files.model.MIME_DIR import com.owncloud.android.domain.files.model.OCFile import com.owncloud.android.testutil.OC_ACCOUNT_NAME import com.owncloud.android.testutil.OC_FILE +import com.owncloud.android.testutil.OC_FILE_WITH_SPACE_ID import com.owncloud.android.testutil.OC_FILE_WITH_SYNC_INFO_AND_SPACE import com.owncloud.android.testutil.OC_FOLDER +import com.owncloud.android.testutil.OC_FOLDER_WITH_SPACE_ID +import com.owncloud.android.testutil.OC_PARENT_FOLDER_WITH_SPACE_ID +import com.owncloud.android.testutil.OC_SPACE_PERSONAL import io.mockk.every import io.mockk.mockk import io.mockk.verify @@ -40,23 +47,29 @@ import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.test.runTest import org.junit.Assert.assertEquals import org.junit.Assert.assertNull -import org.junit.Ignore +import org.junit.Assert.assertThrows +import org.junit.Before import org.junit.Test -@Ignore("Ignore temporary, pretty dependant on implementation... Will be reworked when finished") @ExperimentalCoroutinesApi class OCFileRepositoryTest { - private val remoteFileDataSource = mockk(relaxed = true) - private val localFileDataSource = mockk(relaxed = true) - private val localSpacesDataSource = mockk(relaxed = true) - private val localStorageProvider = mockk() - private val ocFileRepository: OCFileRepository = - OCFileRepository(localFileDataSource, remoteFileDataSource, localSpacesDataSource, localStorageProvider) + private val localFileDataSource = mockk(relaxUnitFun = true) + private val remoteFileDataSource = mockk(relaxUnitFun = true) + private val localSpacesDataSource = mockk(relaxUnitFun = true) + private val localStorageProvider = mockk(relaxUnitFun = true) + private val ocFileRepository = OCFileRepository( + localFileDataSource, + remoteFileDataSource, + localSpacesDataSource, + localStorageProvider + ) + + private val expectedRemotePath = OC_FOLDER_WITH_SPACE_ID.remotePath + OC_FILE_WITH_SPACE_ID.fileName + private val remoteId = "remoteId" - private val folderToFetch = OC_FOLDER - private val listOfFilesRetrieved = listOf( - folderToFetch, + /*private val listOfFilesRetrieved = listOf( + OC_FOLDER, OC_FOLDER.copy(remoteId = "one"), OC_FOLDER.copy(remoteId = "two") ) @@ -66,37 +79,384 @@ class OCFileRepositoryTest { OC_FILE.copy(id = 3) ) - private val timeInMilliseconds = 3600000L + private val timeInMilliseconds = 3600000L*/ + + @Before + fun setUp() { + every { + localSpacesDataSource.getWebDavUrlForSpace( + spaceId = OC_FILE_WITH_SPACE_ID.spaceId, + accountName = OC_FILE_WITH_SPACE_ID.owner + ) + } returns OC_SPACE_PERSONAL.root.webDavUrl + every { + localSpacesDataSource.getWebDavUrlForSpace( + spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId, + accountName = OC_FOLDER_WITH_SPACE_ID.owner + ) + } returns OC_SPACE_PERSONAL.root.webDavUrl + } + + @Test + fun `createFolder creates a new folder and saves it`() { + every { + localSpacesDataSource.getWebDavUrlForSpace( + spaceId = OC_PARENT_FOLDER_WITH_SPACE_ID.spaceId, + accountName = OC_PARENT_FOLDER_WITH_SPACE_ID.owner + ) + } returns OC_SPACE_PERSONAL.root.webDavUrl + // The result of this method is not used, so it can be anything + every { localFileDataSource.saveFilesInFolderAndReturnTheFilesThatChanged(any(), any()) } returns emptyList() + + ocFileRepository.createFolder(OC_FOLDER_WITH_SPACE_ID.remotePath, OC_PARENT_FOLDER_WITH_SPACE_ID) + + verify(exactly = 1) { + localSpacesDataSource.getWebDavUrlForSpace( + spaceId = OC_PARENT_FOLDER_WITH_SPACE_ID.spaceId, + accountName = OC_PARENT_FOLDER_WITH_SPACE_ID.owner + ) + remoteFileDataSource.createFolder( + remotePath = OC_FOLDER_WITH_SPACE_ID.remotePath, + createFullPath = false, + isChunksFolder = false, + accountName = OC_PARENT_FOLDER_WITH_SPACE_ID.owner, + spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl + ) + localFileDataSource.saveFilesInFolderAndReturnTheFilesThatChanged( + folder = OC_PARENT_FOLDER_WITH_SPACE_ID, + listOfFiles = withArg> { + assertEquals(1, it.size) + assertEquals(OC_FOLDER_WITH_SPACE_ID.remotePath, it[0].remotePath) + assertEquals(OC_PARENT_FOLDER_WITH_SPACE_ID.owner, it[0].owner) + assertEquals(0, it[0].length) + assertEquals(MIME_DIR, it[0].mimeType) + assertEquals(OC_PARENT_FOLDER_WITH_SPACE_ID.spaceId, it[0].spaceId) + assertEquals("CK", it[0].permissions) + } + ) + } + } @Test - fun `create folder - ok`() { - every { remoteFileDataSource.createFolder(OC_FOLDER.remotePath, false, false, OC_ACCOUNT_NAME, null) } returns Unit + fun `copyFile returns a list with the OCFile in conflict (the copied OCFile) when replace parameter is empty and expected path already exists`() { + every { + remoteFileDataSource.checkPathExistence( + path = expectedRemotePath, + isUserLogged = true, + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl + ) + } returns true + val filesNeedAction = ocFileRepository.copyFile(listOf(OC_FILE_WITH_SPACE_ID), OC_FOLDER_WITH_SPACE_ID, emptyList(), true) - ocFileRepository.createFolder(OC_FOLDER.remotePath, OC_FOLDER) + assertEquals(listOf(OC_FILE_WITH_SPACE_ID), filesNeedAction) verify(exactly = 1) { - remoteFileDataSource.createFolder(any(), false, false, OC_ACCOUNT_NAME, null) - localFileDataSource.saveFilesInFolderAndReturnTheFilesThatChanged(any(), OC_FOLDER) + localSpacesDataSource.getWebDavUrlForSpace( + spaceId = OC_FILE_WITH_SPACE_ID.spaceId, + accountName = OC_FILE_WITH_SPACE_ID.owner + ) + localSpacesDataSource.getWebDavUrlForSpace( + spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId, + accountName = OC_FOLDER_WITH_SPACE_ID.owner + ) + remoteFileDataSource.checkPathExistence( + path = expectedRemotePath, + isUserLogged = true, + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl + ) } } - @Test(expected = NoConnectionWithServerException::class) - fun `create folder - ko - no connection exception`() { + @Test + fun `copyFile returns an empty list with no OCFiles in conflict when replace parameter is empty and expected path doesn't exist`() { every { - remoteFileDataSource.createFolder(OC_FOLDER.remotePath, false, false, OC_ACCOUNT_NAME, null) - } throws NoConnectionWithServerException() + remoteFileDataSource.checkPathExistence( + path = expectedRemotePath, + isUserLogged = true, + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl + ) + } returns false + every { + remoteFileDataSource.copyFile( + sourceRemotePath = OC_FILE_WITH_SPACE_ID.remotePath, + targetRemotePath = expectedRemotePath, + accountName = OC_FILE_WITH_SPACE_ID.owner, + sourceSpaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + targetSpaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + replace = false + ) + } returns remoteId - ocFileRepository.createFolder(OC_FOLDER.remotePath, OC_FOLDER) + val filesNeedAction = ocFileRepository.copyFile(listOf(OC_FILE_WITH_SPACE_ID), OC_FOLDER_WITH_SPACE_ID, emptyList(), true) + + assertEquals(emptyList(), filesNeedAction) verify(exactly = 1) { - remoteFileDataSource.createFolder(any(), false, false, OC_ACCOUNT_NAME, null) + localSpacesDataSource.getWebDavUrlForSpace( + spaceId = OC_FILE_WITH_SPACE_ID.spaceId, + accountName = OC_FILE_WITH_SPACE_ID.owner + ) + localSpacesDataSource.getWebDavUrlForSpace( + spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId, + accountName = OC_FOLDER_WITH_SPACE_ID.owner + ) + remoteFileDataSource.checkPathExistence( + path = expectedRemotePath, + isUserLogged = true, + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + ) + remoteFileDataSource.copyFile( + sourceRemotePath = OC_FILE_WITH_SPACE_ID.remotePath, + targetRemotePath = expectedRemotePath, + accountName = OC_FILE_WITH_SPACE_ID.owner, + sourceSpaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + targetSpaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + replace = false + ) + localFileDataSource.copyFile( + sourceFile = OC_FILE_WITH_SPACE_ID, + targetFolder = OC_FOLDER_WITH_SPACE_ID, + finalRemotePath = expectedRemotePath, + remoteId = remoteId, + replace = null + ) } - verify(exactly = 0) { - localFileDataSource.saveFilesInFolderAndReturnTheFilesThatChanged(any(), OC_FOLDER) + } + + @Test + fun `copyFile returns an empty list with no OCFiles in conflict when replace parameter is true`() { + every { + remoteFileDataSource.copyFile( + sourceRemotePath = OC_FILE_WITH_SPACE_ID.remotePath, + targetRemotePath = expectedRemotePath, + accountName = OC_FILE_WITH_SPACE_ID.owner, + sourceSpaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + targetSpaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + replace = true + ) + } returns remoteId + + val filesNeedAction = ocFileRepository.copyFile(listOf(OC_FILE_WITH_SPACE_ID), OC_FOLDER_WITH_SPACE_ID, listOf(true), true) + + assertEquals(emptyList(), filesNeedAction) + + verify(exactly = 1) { + localSpacesDataSource.getWebDavUrlForSpace( + spaceId = OC_FILE_WITH_SPACE_ID.spaceId, + accountName = OC_FILE_WITH_SPACE_ID.owner + ) + localSpacesDataSource.getWebDavUrlForSpace( + spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId, + accountName = OC_FOLDER_WITH_SPACE_ID.owner + ) + remoteFileDataSource.copyFile( + sourceRemotePath = OC_FILE_WITH_SPACE_ID.remotePath, + targetRemotePath = expectedRemotePath, + accountName = OC_FILE_WITH_SPACE_ID.owner, + sourceSpaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + targetSpaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + replace = true + ) + localFileDataSource.copyFile( + sourceFile = OC_FILE_WITH_SPACE_ID, + targetFolder = OC_FOLDER_WITH_SPACE_ID, + finalRemotePath = expectedRemotePath, + remoteId = remoteId, + replace = true + ) + } + } + + @Test + fun `copyFile returns an empty list with no OCFiles in conflict when replace parameter is false`() { + val availableRemotePath = "$expectedRemotePath (1)" + every { + remoteFileDataSource.getAvailableRemotePath( + remotePath = expectedRemotePath, + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + isUserLogged = true + ) + } returns availableRemotePath + every { + remoteFileDataSource.copyFile( + sourceRemotePath = OC_FILE_WITH_SPACE_ID.remotePath, + targetRemotePath = availableRemotePath, + accountName = OC_FILE_WITH_SPACE_ID.owner, + sourceSpaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + targetSpaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + replace = false + ) + } returns remoteId + + val filesNeedAction = ocFileRepository.copyFile(listOf(OC_FILE_WITH_SPACE_ID), OC_FOLDER_WITH_SPACE_ID, listOf(false), true) + + assertEquals(emptyList(), filesNeedAction) + + verify(exactly = 1) { + localSpacesDataSource.getWebDavUrlForSpace( + spaceId = OC_FILE_WITH_SPACE_ID.spaceId, + accountName = OC_FILE_WITH_SPACE_ID.owner + ) + localSpacesDataSource.getWebDavUrlForSpace( + spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId, + accountName = OC_FOLDER_WITH_SPACE_ID.owner + ) + remoteFileDataSource.copyFile( + sourceRemotePath = OC_FILE_WITH_SPACE_ID.remotePath, + targetRemotePath = availableRemotePath, + accountName = OC_FILE_WITH_SPACE_ID.owner, + sourceSpaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + targetSpaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + replace = false + ) + localFileDataSource.copyFile( + sourceFile = OC_FILE_WITH_SPACE_ID, + targetFolder = OC_FOLDER_WITH_SPACE_ID, + finalRemotePath = availableRemotePath, + remoteId = remoteId, + replace = false + ) + } + } + + @Test + fun `copyFile returns an empty list with no OCFiles in conflict when replace parameter is null`() { + val filesNeedAction = ocFileRepository.copyFile(listOf(OC_FILE_WITH_SPACE_ID), OC_FOLDER_WITH_SPACE_ID, listOf(null), true) + + assertEquals(emptyList(), filesNeedAction) + + verify(exactly = 1) { + localSpacesDataSource.getWebDavUrlForSpace( + spaceId = OC_FILE_WITH_SPACE_ID.spaceId, + accountName = OC_FILE_WITH_SPACE_ID.owner + ) + localSpacesDataSource.getWebDavUrlForSpace( + spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId, + accountName = OC_FOLDER_WITH_SPACE_ID.owner + ) + } + } + + @Test + fun `copyFile removes target folder locally and throws a ConflictException when replace parameter is empty and expected path doesn't exist but target folder doesn't exist anymore`() { + every { + remoteFileDataSource.checkPathExistence( + path = expectedRemotePath, + isUserLogged = true, + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl + ) + } returns false + every { + remoteFileDataSource.copyFile( + sourceRemotePath = OC_FILE_WITH_SPACE_ID.remotePath, + targetRemotePath = expectedRemotePath, + accountName = OC_FILE_WITH_SPACE_ID.owner, + sourceSpaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + targetSpaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + replace = false + ) + } throws ConflictException() + every { + localFileDataSource.getFolderContent(OC_FOLDER_WITH_SPACE_ID.id!!) + } returns emptyList() + + assertThrows(ConflictException::class.java) { + ocFileRepository.copyFile(listOf(OC_FILE_WITH_SPACE_ID), OC_FOLDER_WITH_SPACE_ID, emptyList(), true) + } + + verify(exactly = 1) { + localSpacesDataSource.getWebDavUrlForSpace( + spaceId = OC_FILE_WITH_SPACE_ID.spaceId, + accountName = OC_FILE_WITH_SPACE_ID.owner + ) + localSpacesDataSource.getWebDavUrlForSpace( + spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId, + accountName = OC_FOLDER_WITH_SPACE_ID.owner + ) + remoteFileDataSource.checkPathExistence( + path = expectedRemotePath, + isUserLogged = true, + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + ) + remoteFileDataSource.copyFile( + sourceRemotePath = OC_FILE_WITH_SPACE_ID.remotePath, + targetRemotePath = expectedRemotePath, + accountName = OC_FILE_WITH_SPACE_ID.owner, + sourceSpaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + targetSpaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + replace = false + ) + localFileDataSource.getFolderContent(OC_FOLDER_WITH_SPACE_ID.id!!) + localStorageProvider.deleteLocalFolderIfItHasNoFilesInside(OC_FOLDER_WITH_SPACE_ID) + localFileDataSource.deleteFile(OC_FOLDER_WITH_SPACE_ID.id!!) + } + } + + @Test + fun `copyFile removes source file locally and throws a FileNotFoundException when replace parameter is empty and expected path doesn't exist but source file doesn't exist anymore`() { + every { + remoteFileDataSource.checkPathExistence( + path = expectedRemotePath, + isUserLogged = true, + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl + ) + } returns false + every { + remoteFileDataSource.copyFile( + sourceRemotePath = OC_FILE_WITH_SPACE_ID.remotePath, + targetRemotePath = expectedRemotePath, + accountName = OC_FILE_WITH_SPACE_ID.owner, + sourceSpaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + targetSpaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + replace = false + ) + } throws FileNotFoundException() + every { + localStorageProvider.deleteLocalFile(OC_FILE_WITH_SPACE_ID) + } returns true + + assertThrows(FileNotFoundException::class.java) { + ocFileRepository.copyFile(listOf(OC_FILE_WITH_SPACE_ID), OC_FOLDER_WITH_SPACE_ID, emptyList(), true) + } + + verify(exactly = 1) { + localSpacesDataSource.getWebDavUrlForSpace( + spaceId = OC_FILE_WITH_SPACE_ID.spaceId, + accountName = OC_FILE_WITH_SPACE_ID.owner + ) + localSpacesDataSource.getWebDavUrlForSpace( + spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId, + accountName = OC_FOLDER_WITH_SPACE_ID.owner + ) + remoteFileDataSource.checkPathExistence( + path = expectedRemotePath, + isUserLogged = true, + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + ) + remoteFileDataSource.copyFile( + sourceRemotePath = OC_FILE_WITH_SPACE_ID.remotePath, + targetRemotePath = expectedRemotePath, + accountName = OC_FILE_WITH_SPACE_ID.owner, + sourceSpaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + targetSpaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + replace = false + ) + localStorageProvider.deleteLocalFile(OC_FILE_WITH_SPACE_ID) + localFileDataSource.deleteFile(OC_FILE_WITH_SPACE_ID.id!!) } } + /* @Test fun `get file by id - ok`() { every { localFileDataSource.getFileById(OC_FOLDER.id!!) } returns OC_FOLDER @@ -403,4 +763,5 @@ class OCFileRepositoryTest { verify(exactly = 1) { localFileDataSource.saveFile(OC_FILE) } } + */ } diff --git a/owncloudTestUtil/src/main/java/com/owncloud/android/testutil/OCFile.kt b/owncloudTestUtil/src/main/java/com/owncloud/android/testutil/OCFile.kt index e0bba606233..afa1af6a3e0 100644 --- a/owncloudTestUtil/src/main/java/com/owncloud/android/testutil/OCFile.kt +++ b/owncloudTestUtil/src/main/java/com/owncloud/android/testutil/OCFile.kt @@ -4,7 +4,7 @@ * @author Abel García de Prada * @author Juan Carlos Garrote Gascón * - * Copyright (C) 2023 ownCloud GmbH. + * Copyright (C) 2024 ownCloud GmbH. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -45,6 +45,38 @@ val OC_FOLDER = OCFile( length = 123123123 ) +val OC_PARENT_FOLDER_WITH_SPACE_ID = OCFile( + id = 123, + parentId = 1, + remotePath = "/Folder", + owner = OC_ACCOUNT_NAME, + permissions = "RDNVCK", + remoteId = "00000003oci9p7er2hay2", + privateLink = "http://server.url/f/5", + creationTimestamp = 0, + modificationTimestamp = 1593510589000, + etag = "5efb0c13c688g", + mimeType = "DIR", + length = 123123123, + spaceId = OC_SPACE_PERSONAL.id +) + +val OC_FOLDER_WITH_SPACE_ID = OCFile( + id = 125, + parentId = 123, + remotePath = "/Folder/Photos", + owner = OC_ACCOUNT_NAME, + permissions = "RDNVCK", + remoteId = "00000003oci9p7er2hay3", + privateLink = "http://server.url/f/6", + creationTimestamp = 0, + modificationTimestamp = 1593510589000, + etag = "5efb0c13c688h", + mimeType = "DIR", + length = 0, + spaceId = OC_SPACE_PERSONAL.id +) + val OC_FILE = OCFile( id = 124, parentId = 122, @@ -77,6 +109,22 @@ val OC_FILE_AVAILABLE_OFFLINE = OCFile( availableOfflineStatus = AvailableOfflineStatus.AVAILABLE_OFFLINE ) +val OC_FILE_WITH_SPACE_ID = OCFile( + id = 126, + parentId = 123, + remotePath = "/Folder/image2.jpt", + owner = OC_ACCOUNT_NAME, + permissions = "RDNVCK", + remoteId = "00000003oci9p7er2hox", + privateLink = "http://server.url/f/7", + creationTimestamp = 1593510589000, + modificationTimestamp = 1593510589000, + etag = "5efb0c13c688i", + mimeType = "image/jpeg", + length = 3000000, + availableOfflineStatus = AvailableOfflineStatus.NOT_AVAILABLE_OFFLINE +) + val OC_FILE_WITH_SYNC_INFO = OCFileWithSyncInfo( file = OC_FILE, uploadWorkerUuid = null, From 33434338453772647912571f0391b9da17bcf7e4 Mon Sep 17 00:00:00 2001 From: Juan Carlos Garrote Date: Tue, 15 Oct 2024 11:33:58 +0200 Subject: [PATCH 3/4] test: added tests for several more methods from OCFileRepository --- .../files/repository/OCFileRepositoryTest.kt | 422 ++++++++++++++++-- .../com/owncloud/android/testutil/OCFile.kt | 24 + .../com/owncloud/android/testutil/OCSpace.kt | 22 +- 3 files changed, 424 insertions(+), 44 deletions(-) diff --git a/owncloudData/src/test/java/com/owncloud/android/data/files/repository/OCFileRepositoryTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/files/repository/OCFileRepositoryTest.kt index 12b48a77526..4cea2c20521 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/files/repository/OCFileRepositoryTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/files/repository/OCFileRepositoryTest.kt @@ -29,20 +29,29 @@ import com.owncloud.android.data.spaces.datasources.LocalSpacesDataSource import com.owncloud.android.domain.exceptions.ConflictException import com.owncloud.android.domain.exceptions.FileNotFoundException import com.owncloud.android.domain.exceptions.NoConnectionWithServerException +import com.owncloud.android.domain.files.model.FileListOption import com.owncloud.android.domain.files.model.MIME_DIR import com.owncloud.android.domain.files.model.OCFile +import com.owncloud.android.domain.files.model.OCFile.Companion.ROOT_PATH import com.owncloud.android.testutil.OC_ACCOUNT_NAME import com.owncloud.android.testutil.OC_FILE +import com.owncloud.android.testutil.OC_FILE_ENTITY import com.owncloud.android.testutil.OC_FILE_WITH_SPACE_ID import com.owncloud.android.testutil.OC_FILE_WITH_SYNC_INFO_AND_SPACE import com.owncloud.android.testutil.OC_FOLDER import com.owncloud.android.testutil.OC_FOLDER_WITH_SPACE_ID +import com.owncloud.android.testutil.OC_META_FILE +import com.owncloud.android.testutil.OC_META_FILE_ROOT_FOLDER import com.owncloud.android.testutil.OC_PARENT_FOLDER_WITH_SPACE_ID +import com.owncloud.android.testutil.OC_ROOT_FOLDER import com.owncloud.android.testutil.OC_SPACE_PERSONAL +import com.owncloud.android.testutil.OC_SPACE_SHARES import io.mockk.every import io.mockk.mockk +import io.mockk.spyk import io.mockk.verify import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.test.runTest import org.junit.Assert.assertEquals @@ -64,9 +73,11 @@ class OCFileRepositoryTest { localSpacesDataSource, localStorageProvider ) + private val ocFileRepositorySpy = spyk(ocFileRepository) private val expectedRemotePath = OC_FOLDER_WITH_SPACE_ID.remotePath + OC_FILE_WITH_SPACE_ID.fileName private val remoteId = "remoteId" + private val searchText = "image" /*private val listOfFilesRetrieved = listOf( OC_FOLDER, @@ -456,109 +467,434 @@ class OCFileRepositoryTest { } } - /* @Test - fun `get file by id - ok`() { - every { localFileDataSource.getFileById(OC_FOLDER.id!!) } returns OC_FOLDER - - val ocFile = ocFileRepository.getFileById(OC_FOLDER.id!!) + fun `getFileById returns a OCFile`() { + every { + localFileDataSource.getFileById(OC_FILE_WITH_SPACE_ID.id!!) + } returns OC_FILE_WITH_SPACE_ID - assertEquals(OC_FOLDER, ocFile) + val ocFile = ocFileRepository.getFileById(OC_FILE_WITH_SPACE_ID.id!!) + assertEquals(OC_FILE_WITH_SPACE_ID, ocFile) verify(exactly = 1) { - localFileDataSource.getFileById(OC_FOLDER.id!!) + localFileDataSource.getFileById(OC_FILE_WITH_SPACE_ID.id!!) } } @Test - fun `getFileWithSyncInfoByIdAsFlow returns OCFileWithSyncInfo`() = runTest { - every { localFileDataSource.getFileWithSyncInfoByIdAsFlow(OC_FILE.id!!) } returns flowOf(OC_FILE_WITH_SYNC_INFO_AND_SPACE) + fun `getFileById returns null when local datasource returns a null file`() { + every { + localFileDataSource.getFileById(OC_FILE_WITH_SPACE_ID.id!!) + } returns null - val ocFile = ocFileRepository.getFileWithSyncInfoByIdAsFlow(OC_FILE.id!!) + val ocFile = ocFileRepository.getFileById(OC_FILE_WITH_SPACE_ID.id!!) + assertNull(ocFile) - ocFile.collect { result -> - assertEquals(OC_FILE_WITH_SYNC_INFO_AND_SPACE, result) + verify(exactly = 1) { + localFileDataSource.getFileById(OC_FILE_WITH_SPACE_ID.id!!) } + } + + @Test + fun `getFileByIdAsFlow returns a Flow with an OCFile`() = runTest { + every { + localFileDataSource.getFileByIdAsFlow(OC_FILE_WITH_SPACE_ID.id!!) + } returns flowOf(OC_FILE_WITH_SPACE_ID) + + val ocFile = ocFileRepository.getFileByIdAsFlow(OC_FILE_WITH_SPACE_ID.id!!).first() + assertEquals(OC_FILE_WITH_SPACE_ID, ocFile) verify(exactly = 1) { - localFileDataSource.getFileWithSyncInfoByIdAsFlow(OC_FILE.id!!) + localFileDataSource.getFileByIdAsFlow(OC_FILE_WITH_SPACE_ID.id!!) } } @Test - fun `getFileWithSyncInfoByIdAsFlow returns null`() = runTest { - every { localFileDataSource.getFileWithSyncInfoByIdAsFlow(OC_FILE.id!!) } returns flowOf(null) + fun `getFileByIdAsFlow returns a Flow with null when local datasource returns a Flow with null`() = runTest { + every { + localFileDataSource.getFileByIdAsFlow(OC_FILE_WITH_SPACE_ID.id!!) + } returns flowOf(null) - val ocFile = ocFileRepository.getFileWithSyncInfoByIdAsFlow(OC_FILE.id!!) + val ocFile = ocFileRepository.getFileByIdAsFlow(OC_FILE_WITH_SPACE_ID.id!!).first() + assertNull(ocFile) - ocFile.collect { result -> - assertNull(result) + verify(exactly = 1) { + localFileDataSource.getFileByIdAsFlow(OC_FILE_WITH_SPACE_ID.id!!) } + } + + @Test + fun `getFileWithSyncInfoByIdAsFlow returns a Flow with an OCFileWithSyncInfo`() = runTest { + every { + localFileDataSource.getFileWithSyncInfoByIdAsFlow(OC_FILE_WITH_SYNC_INFO_AND_SPACE.file.id!!) + } returns flowOf(OC_FILE_WITH_SYNC_INFO_AND_SPACE) + + val ocFile = ocFileRepository.getFileWithSyncInfoByIdAsFlow(OC_FILE_WITH_SYNC_INFO_AND_SPACE.file.id!!).first() + assertEquals(OC_FILE_WITH_SYNC_INFO_AND_SPACE, ocFile) verify(exactly = 1) { - localFileDataSource.getFileWithSyncInfoByIdAsFlow(OC_FILE.id!!) + localFileDataSource.getFileWithSyncInfoByIdAsFlow(OC_FILE_WITH_SYNC_INFO_AND_SPACE.file.id!!) } } - @Test(expected = Exception::class) - fun `getFileWithSyncInfoByIdAsFlow returns an exception`() = runTest { - every { localFileDataSource.getFileWithSyncInfoByIdAsFlow(OC_FILE.id!!) } throws Exception() + @Test + fun `getFileWithSyncInfoByIdAsFlow returns a Flow with null when local datasource returns a Flow with null`() = runTest { + every { + localFileDataSource.getFileWithSyncInfoByIdAsFlow(OC_FILE_WITH_SYNC_INFO_AND_SPACE.file.id!!) + } returns flowOf(null) - ocFileRepository.getFileWithSyncInfoByIdAsFlow(OC_FILE.id!!) + val ocFile = ocFileRepository.getFileWithSyncInfoByIdAsFlow(OC_FILE_WITH_SYNC_INFO_AND_SPACE.file.id!!).first() + assertNull(ocFile) verify(exactly = 1) { - localFileDataSource.getFileWithSyncInfoByIdAsFlow(OC_FILE.id!!) + localFileDataSource.getFileWithSyncInfoByIdAsFlow(OC_FILE_WITH_SYNC_INFO_AND_SPACE.file.id!!) } } @Test - fun `get file by id - ok - null`() { - every { localFileDataSource.getFileById(OC_FOLDER.id!!) } returns null + fun `getFileByRemotePath returns a OCFile`() { + every { + localFileDataSource.getFileByRemotePath( + remotePath = OC_FILE_WITH_SPACE_ID.remotePath, + owner = OC_FOLDER_WITH_SPACE_ID.owner, + spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId + ) + } returns OC_FILE_WITH_SPACE_ID - val ocFile = ocFileRepository.getFileById(OC_FOLDER.id!!) + val ocFile = ocFileRepository.getFileByRemotePath(OC_FILE_WITH_SPACE_ID.remotePath, OC_FOLDER_WITH_SPACE_ID.owner, OC_FOLDER_WITH_SPACE_ID.spaceId) + assertEquals(OC_FILE_WITH_SPACE_ID, ocFile) + + verify(exactly = 1) { + localFileDataSource.getFileByRemotePath( + remotePath = OC_FILE_WITH_SPACE_ID.remotePath, + owner = OC_FOLDER_WITH_SPACE_ID.owner, + spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId + ) + } + } + @Test + fun `getFileByRemotePath returns null when local datasource returns a null file`() { + every { + localFileDataSource.getFileByRemotePath( + remotePath = OC_FILE_WITH_SPACE_ID.remotePath, + owner = OC_FOLDER_WITH_SPACE_ID.owner, + spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId + ) + } returns null + + val ocFile = ocFileRepository.getFileByRemotePath(OC_FILE_WITH_SPACE_ID.remotePath, OC_FOLDER_WITH_SPACE_ID.owner, OC_FOLDER_WITH_SPACE_ID.spaceId) assertNull(ocFile) verify(exactly = 1) { - localFileDataSource.getFileById(OC_FOLDER.id!!) + localFileDataSource.getFileByRemotePath( + remotePath = OC_FILE_WITH_SPACE_ID.remotePath, + owner = OC_FOLDER_WITH_SPACE_ID.owner, + spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId + ) } } - @Test(expected = Exception::class) - fun `get file by id - ko`() { - every { localFileDataSource.getFileById(OC_FOLDER.id!!) } throws Exception() + @Test + fun `getFileFromRemoteId returns a OCFile when the remoteId belongs to a normal file`() { + every { + remoteFileDataSource.getMetaFile(OC_FILE.remoteId!!, OC_FILE.owner) + } returns OC_META_FILE + // The result of this method is not used, so it can be anything + every { + ocFileRepositorySpy.refreshFolder( + remotePath = "", + accountName = OC_FILE.owner, + spaceId = null + ) + } returns emptyList() + every { + ocFileRepositorySpy.refreshFolder( + remotePath = "/Photos", + accountName = OC_FILE.owner, + spaceId = null + ) + } returns listOf(OC_FILE) + // The result of this method is not used, so it can be anything + every { + ocFileRepositorySpy.refreshFolder( + remotePath = OC_FILE.remotePath, + accountName = OC_FILE.owner, + spaceId = null + ) + } returns emptyList() - ocFileRepository.getFileById(OC_FOLDER.id!!) + val ocFile = ocFileRepositorySpy.getFileFromRemoteId(OC_FILE.remoteId!!, OC_FILE.owner) + assertEquals(OC_FILE, ocFile) verify(exactly = 1) { - localFileDataSource.getFileById(OC_FOLDER.id!!) + remoteFileDataSource.getMetaFile(OC_FILE.remoteId!!, OC_FILE.owner) + ocFileRepositorySpy.refreshFolder( + remotePath = "", + accountName = OC_FILE.owner, + spaceId = null + ) + ocFileRepositorySpy.refreshFolder( + remotePath = "/Photos", + accountName = OC_FILE.owner, + spaceId = null + ) + ocFileRepositorySpy.refreshFolder( + remotePath = OC_FILE.remotePath, + accountName = OC_FILE.owner, + spaceId = null + ) } } @Test - fun `get file by remote path - ok`() { - every { localFileDataSource.getFileByRemotePath(OC_FOLDER.remotePath, OC_FOLDER.owner, null) } returns OC_FOLDER + fun `getFileFromRemoteId returns root folder as OCFile when the remoteId belongs to a root folder`() { + every { + remoteFileDataSource.getMetaFile(OC_ROOT_FOLDER.remoteId!!, OC_ROOT_FOLDER.owner) + } returns OC_META_FILE_ROOT_FOLDER + // The result of this method is not used, so it can be anything + every { + ocFileRepositorySpy.refreshFolder( + remotePath = "", + accountName = OC_ROOT_FOLDER.owner, + spaceId = null + ) + } returns emptyList() + // The result of this method is not used, so it can be anything + every { + ocFileRepositorySpy.refreshFolder( + remotePath = OC_ROOT_FOLDER.remotePath, + accountName = OC_ROOT_FOLDER.owner, + spaceId = null + ) + } returns emptyList() + every { + localFileDataSource.getFileByRemotePath( + remotePath = OC_ROOT_FOLDER.remotePath, + owner = OC_ROOT_FOLDER.owner, + spaceId = null + ) + } returns OC_ROOT_FOLDER - ocFileRepository.getFileByRemotePath(OC_FOLDER.remotePath, OC_FOLDER.owner) + val ocFile = ocFileRepositorySpy.getFileFromRemoteId(OC_ROOT_FOLDER.remoteId!!, OC_ROOT_FOLDER.owner) + assertEquals(OC_ROOT_FOLDER, ocFile) verify(exactly = 1) { - localFileDataSource.getFileByRemotePath(OC_FOLDER.remotePath, OC_FOLDER.owner, null) + remoteFileDataSource.getMetaFile(OC_ROOT_FOLDER.remoteId!!, OC_ROOT_FOLDER.owner) + ocFileRepositorySpy.refreshFolder( + remotePath = "", + accountName = OC_ROOT_FOLDER.owner, + spaceId = null + ) + ocFileRepositorySpy.refreshFolder( + remotePath = OC_ROOT_FOLDER.remotePath, + accountName = OC_ROOT_FOLDER.owner, + spaceId = null + ) + localFileDataSource.getFileByRemotePath( + remotePath = OC_ROOT_FOLDER.remotePath, + owner = OC_ROOT_FOLDER.owner, + spaceId = null + ) } } - @Test(expected = Exception::class) - fun `get file by remote path - ko`() { + @Test + fun `getPersonalRootFolderForAccount returns root folder as OCFile when personal space is not null`() { + every { + localSpacesDataSource.getPersonalSpaceForAccount(OC_SPACE_PERSONAL.accountName) + } returns OC_SPACE_PERSONAL + every { + localFileDataSource.getFileByRemotePath( + remotePath = ROOT_PATH, + owner = OC_SPACE_PERSONAL.accountName, + spaceId = OC_SPACE_PERSONAL.root.id + ) + } returns OC_ROOT_FOLDER + + val ocFolder = ocFileRepository.getPersonalRootFolderForAccount(OC_SPACE_PERSONAL.accountName) + assertEquals(OC_ROOT_FOLDER, ocFolder) + + verify(exactly = 1) { + localSpacesDataSource.getPersonalSpaceForAccount(OC_SPACE_PERSONAL.accountName) + localFileDataSource.getFileByRemotePath( + remotePath = ROOT_PATH, + owner = OC_SPACE_PERSONAL.accountName, + spaceId = OC_SPACE_PERSONAL.root.id + ) + } + } + + @Test + fun `getPersonalRootFolderForAccount returns root folder as OCFile when personal space is null`() { + every { + localSpacesDataSource.getPersonalSpaceForAccount(OC_SPACE_PERSONAL.accountName) + } returns null + every { + localFileDataSource.getFileByRemotePath( + remotePath = ROOT_PATH, + owner = OC_SPACE_PERSONAL.accountName, + spaceId = null + ) + } returns OC_ROOT_FOLDER + + val ocFolder = ocFileRepository.getPersonalRootFolderForAccount(OC_SPACE_PERSONAL.accountName) + assertEquals(OC_ROOT_FOLDER, ocFolder) + + verify(exactly = 1) { + localSpacesDataSource.getPersonalSpaceForAccount(OC_SPACE_PERSONAL.accountName) + localFileDataSource.getFileByRemotePath( + remotePath = ROOT_PATH, + owner = OC_SPACE_PERSONAL.accountName, + spaceId = null + ) + } + } + + @Test + fun `getPersonalRootFolderForAccount throws NullPointerException when local datasource returns a null root folder`() { every { - localFileDataSource.getFileByRemotePath(OC_FOLDER.remotePath, OC_FOLDER.owner, null) - } throws Exception() + localSpacesDataSource.getPersonalSpaceForAccount(OC_SPACE_PERSONAL.accountName) + } returns OC_SPACE_PERSONAL + every { + localFileDataSource.getFileByRemotePath( + remotePath = ROOT_PATH, + owner = OC_SPACE_PERSONAL.accountName, + spaceId = OC_SPACE_PERSONAL.root.id + ) + } returns null - ocFileRepository.getFileByRemotePath(OC_FOLDER.remotePath, OC_FOLDER.owner) + assertThrows(NullPointerException::class.java) { + ocFileRepository.getPersonalRootFolderForAccount(OC_SPACE_PERSONAL.accountName) + } verify(exactly = 1) { - localFileDataSource.getFileByRemotePath(OC_FOLDER.remotePath, OC_FOLDER.owner, null) + localSpacesDataSource.getPersonalSpaceForAccount(OC_SPACE_PERSONAL.accountName) + localFileDataSource.getFileByRemotePath( + remotePath = ROOT_PATH, + owner = OC_SPACE_PERSONAL.accountName, + spaceId = OC_SPACE_PERSONAL.root.id + ) } } + @Test + fun `getSharesRootFolderForAccount returns root folder as OCFile when shares space is not null`() { + every { + localSpacesDataSource.getSharesSpaceForAccount(OC_SPACE_SHARES.accountName) + } returns OC_SPACE_SHARES + every { + localFileDataSource.getFileByRemotePath( + remotePath = ROOT_PATH, + owner = OC_SPACE_SHARES.accountName, + spaceId = OC_SPACE_SHARES.root.id + ) + } returns OC_ROOT_FOLDER + + val ocFolder = ocFileRepository.getSharesRootFolderForAccount(OC_SPACE_SHARES.accountName) + assertEquals(OC_ROOT_FOLDER, ocFolder) + + verify(exactly = 1) { + localSpacesDataSource.getSharesSpaceForAccount(OC_SPACE_SHARES.accountName) + localFileDataSource.getFileByRemotePath( + remotePath = ROOT_PATH, + owner = OC_SPACE_SHARES.accountName, + spaceId = OC_SPACE_SHARES.root.id + ) + } + } + + @Test + fun `getSharesRootFolderForAccount returns null when shares space is null`() { + every { + localSpacesDataSource.getSharesSpaceForAccount(OC_SPACE_SHARES.accountName) + } returns null + + val ocFolder = ocFileRepository.getSharesRootFolderForAccount(OC_SPACE_SHARES.accountName) + assertNull(ocFolder) + + verify(exactly = 1) { + localSpacesDataSource.getSharesSpaceForAccount(OC_SPACE_SHARES.accountName) + } + } + + @Test + fun `getSharesRootFolderForAccount throws NullPointerException when local datasource returns a null root folder`() { + every { + localSpacesDataSource.getSharesSpaceForAccount(OC_SPACE_SHARES.accountName) + } returns OC_SPACE_SHARES + every { + localFileDataSource.getFileByRemotePath( + remotePath = ROOT_PATH, + owner = OC_SPACE_SHARES.accountName, + spaceId = OC_SPACE_SHARES.root.id + ) + } returns null + + assertThrows(NullPointerException::class.java) { + ocFileRepository.getSharesRootFolderForAccount(OC_SPACE_SHARES.accountName) + } + + verify(exactly = 1) { + localSpacesDataSource.getSharesSpaceForAccount(OC_SPACE_SHARES.accountName) + localFileDataSource.getFileByRemotePath( + remotePath = ROOT_PATH, + owner = OC_SPACE_SHARES.accountName, + spaceId = OC_SPACE_SHARES.root.id + ) + } + } + + @Test + fun `getSearchFolderContent returns a list of OCFiles when the file list option is all files`() { + every { + localFileDataSource.getSearchFolderContent(OC_PARENT_FOLDER_WITH_SPACE_ID.id!!, searchText) + } returns listOf(OC_FILE_WITH_SPACE_ID) + + val listOfFiles = ocFileRepository.getSearchFolderContent(FileListOption.ALL_FILES, OC_PARENT_FOLDER_WITH_SPACE_ID.id!!, searchText) + assertEquals(listOf(OC_FILE_WITH_SPACE_ID), listOfFiles) + + verify(exactly = 1) { + localFileDataSource.getSearchFolderContent(OC_PARENT_FOLDER_WITH_SPACE_ID.id!!, searchText) + } + } + + @Test + fun `getSearchFolderContent returns an empty list with no OCFiles when the file list option is spaces list`() { + val listOfFiles = ocFileRepository.getSearchFolderContent(FileListOption.SPACES_LIST, OC_PARENT_FOLDER_WITH_SPACE_ID.id!!, searchText) + assertEquals(emptyList(), listOfFiles) + } + + @Test + fun `getSearchFolderContent returns a list of OCFiles when the file list option is available offline`() { + every { + localFileDataSource.getSearchAvailableOfflineFolderContent(OC_PARENT_FOLDER_WITH_SPACE_ID.id!!, searchText) + } returns listOf(OC_FILE_WITH_SPACE_ID) + + val listOfFiles = ocFileRepository.getSearchFolderContent(FileListOption.AV_OFFLINE, OC_PARENT_FOLDER_WITH_SPACE_ID.id!!, searchText) + assertEquals(listOf(OC_FILE_WITH_SPACE_ID), listOfFiles) + + verify(exactly = 1) { + localFileDataSource.getSearchAvailableOfflineFolderContent(OC_PARENT_FOLDER_WITH_SPACE_ID.id!!, searchText) + } + } + + @Test + fun `getSearchFolderContent returns a list of OCFiles when the file list option is shared by link`() { + every { + localFileDataSource.getSearchSharedByLinkFolderContent(OC_PARENT_FOLDER_WITH_SPACE_ID.id!!, searchText) + } returns listOf(OC_FILE_WITH_SPACE_ID) + + val listOfFiles = ocFileRepository.getSearchFolderContent(FileListOption.SHARED_BY_LINK, OC_PARENT_FOLDER_WITH_SPACE_ID.id!!, searchText) + assertEquals(listOf(OC_FILE_WITH_SPACE_ID), listOfFiles) + + verify(exactly = 1) { + localFileDataSource.getSearchSharedByLinkFolderContent(OC_PARENT_FOLDER_WITH_SPACE_ID.id!!, searchText) + } + } + + /* + @Test fun `getDownloadedFilesForAccount returns a list of OCFile`() { every { diff --git a/owncloudTestUtil/src/main/java/com/owncloud/android/testutil/OCFile.kt b/owncloudTestUtil/src/main/java/com/owncloud/android/testutil/OCFile.kt index afa1af6a3e0..cd65030bfda 100644 --- a/owncloudTestUtil/src/main/java/com/owncloud/android/testutil/OCFile.kt +++ b/owncloudTestUtil/src/main/java/com/owncloud/android/testutil/OCFile.kt @@ -27,6 +27,7 @@ import com.owncloud.android.data.files.db.OCFileSyncEntity import com.owncloud.android.domain.availableoffline.model.AvailableOfflineStatus import com.owncloud.android.domain.files.model.OCFile import com.owncloud.android.domain.files.model.OCFileWithSyncInfo +import com.owncloud.android.domain.files.model.OCMetaFile import com.owncloud.android.lib.resources.files.RemoteFile import com.owncloud.android.lib.resources.files.RemoteMetaFile @@ -45,6 +46,21 @@ val OC_FOLDER = OCFile( length = 123123123 ) +val OC_ROOT_FOLDER = OCFile( + id = 1, + parentId = 0, + remotePath = "/", + owner = OC_ACCOUNT_NAME, + permissions = "RDNVCK", + remoteId = "00000003oci9p7er2hay4", + privateLink = "http://server.url/f/8", + creationTimestamp = 0, + modificationTimestamp = 1593510589000, + etag = "5efb0c13c688k", + mimeType = "DIR", + length = 123123123 +) + val OC_PARENT_FOLDER_WITH_SPACE_ID = OCFile( id = 123, parentId = 1, @@ -153,6 +169,14 @@ val OC_FILE_WITH_SYNC_INFO_AVAILABLE_OFFLINE = OCFileWithSyncInfo( space = OC_SPACE_PROJECT_WITH_IMAGE ) +val OC_META_FILE = OCMetaFile( + path = OC_FILE.remotePath +) + +val OC_META_FILE_ROOT_FOLDER = OCMetaFile( + path = OC_ROOT_FOLDER.remotePath +) + val OC_FILES_WITH_SYNC_INFO = listOf(OC_FILE_WITH_SYNC_INFO, OC_FILE_WITH_SYNC_INFO, OC_FILE_WITH_SYNC_INFO) val OC_AVAILABLE_OFFLINE_FILES = listOf(OC_FILE_AVAILABLE_OFFLINE, OC_FILE_AVAILABLE_OFFLINE, OC_FILE_AVAILABLE_OFFLINE) val OC_FILES_EMPTY = emptyList() diff --git a/owncloudTestUtil/src/main/java/com/owncloud/android/testutil/OCSpace.kt b/owncloudTestUtil/src/main/java/com/owncloud/android/testutil/OCSpace.kt index 3cbc85b0a39..26ff75cd45a 100644 --- a/owncloudTestUtil/src/main/java/com/owncloud/android/testutil/OCSpace.kt +++ b/owncloudTestUtil/src/main/java/com/owncloud/android/testutil/OCSpace.kt @@ -3,7 +3,7 @@ * * @author Juan Carlos Garrote Gascón * - * Copyright (C) 2023 ownCloud GmbH. + * Copyright (C) 2024 ownCloud GmbH. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -126,6 +126,26 @@ val OC_SPACE_PERSONAL = OC_SPACE_PROJECT_WITH_IMAGE.copy( special = null ) +val OC_SPACE_SHARES = OCSpace( + accountName = OC_ACCOUNT_NAME, + driveAlias = "virtual/shares", + driveType = "virtual", + id = "a0ca6a90-a365-4782-871e-d44447bbc668\$a0ca6a90-a365-4782-871e-d44447bbc668", + lastModifiedDateTime = "2024-01-01T00:00:00.00000000Z", + name = "Shares", + owner = null, + quota = null, + root = SpaceRoot( + eTag = "989c7968dbbbde8c5fd9849b9123c384", + id = "a0ca6a90-a365-4782-871e-d44447bbc668\$a0ca6a90-a365-4782-871e-d44447bbc668", + webDavUrl = "https://server.com/dav/spaces/a0ca6a90-a365-4782-871e-d44447bbc668\$a0ca6a90-a365-4782-871e-d44447bbc668", + deleted = null + ), + webUrl = "https://server.com/f/a0ca6a90-a365-4782-871e-d44447bbc668\$a0ca6a90-a365-4782-871e-d44447bbc669", + description = null, + special = null +) + val OC_SPACE_PROJECT_DISABLED = OC_SPACE_PROJECT_WITH_IMAGE.copy( quota = SpaceQuota( remaining = null, From dd23495254ea00edab9806ebf033148cb82814d2 Mon Sep 17 00:00:00 2001 From: Juan Carlos Garrote Date: Mon, 21 Oct 2024 14:59:56 +0200 Subject: [PATCH 4/4] test: added more tests for methods from OCFileRepository --- .../files/repository/OCFileRepositoryTest.kt | 658 +++++++++++++++--- .../com/owncloud/android/testutil/OCFile.kt | 7 +- 2 files changed, 576 insertions(+), 89 deletions(-) diff --git a/owncloudData/src/test/java/com/owncloud/android/data/files/repository/OCFileRepositoryTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/files/repository/OCFileRepositoryTest.kt index 4cea2c20521..74daa7af259 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/files/repository/OCFileRepositoryTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/files/repository/OCFileRepositoryTest.kt @@ -28,17 +28,17 @@ import com.owncloud.android.data.providers.LocalStorageProvider import com.owncloud.android.data.spaces.datasources.LocalSpacesDataSource import com.owncloud.android.domain.exceptions.ConflictException import com.owncloud.android.domain.exceptions.FileNotFoundException -import com.owncloud.android.domain.exceptions.NoConnectionWithServerException import com.owncloud.android.domain.files.model.FileListOption import com.owncloud.android.domain.files.model.MIME_DIR import com.owncloud.android.domain.files.model.OCFile import com.owncloud.android.domain.files.model.OCFile.Companion.ROOT_PATH -import com.owncloud.android.testutil.OC_ACCOUNT_NAME +import com.owncloud.android.testutil.OC_AVAILABLE_OFFLINE_FILES import com.owncloud.android.testutil.OC_FILE -import com.owncloud.android.testutil.OC_FILE_ENTITY +import com.owncloud.android.testutil.OC_FILE_AVAILABLE_OFFLINE +import com.owncloud.android.testutil.OC_FILE_DOWNLOADED import com.owncloud.android.testutil.OC_FILE_WITH_SPACE_ID +import com.owncloud.android.testutil.OC_FILE_WITH_SYNC_INFO import com.owncloud.android.testutil.OC_FILE_WITH_SYNC_INFO_AND_SPACE -import com.owncloud.android.testutil.OC_FOLDER import com.owncloud.android.testutil.OC_FOLDER_WITH_SPACE_ID import com.owncloud.android.testutil.OC_META_FILE import com.owncloud.android.testutil.OC_META_FILE_ROOT_FOLDER @@ -76,6 +76,7 @@ class OCFileRepositoryTest { private val ocFileRepositorySpy = spyk(ocFileRepository) private val expectedRemotePath = OC_FOLDER_WITH_SPACE_ID.remotePath + OC_FILE_WITH_SPACE_ID.fileName + private val storagePath = "/local/storage/path/username@demo.owncloud.com/Folder/Photos/image2.jpt" private val remoteId = "remoteId" private val searchText = "image" @@ -163,15 +164,15 @@ class OCFileRepositoryTest { assertEquals(listOf(OC_FILE_WITH_SPACE_ID), filesNeedAction) - verify(exactly = 1) { - localSpacesDataSource.getWebDavUrlForSpace( - spaceId = OC_FILE_WITH_SPACE_ID.spaceId, - accountName = OC_FILE_WITH_SPACE_ID.owner - ) + val sourceAndTargetSpaceId = OC_FILE_WITH_SPACE_ID.spaceId + val sourceAndTargetOwner = OC_FILE_WITH_SPACE_ID.owner + verify(exactly = 2) { localSpacesDataSource.getWebDavUrlForSpace( - spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId, - accountName = OC_FOLDER_WITH_SPACE_ID.owner + spaceId = sourceAndTargetSpaceId, + accountName = sourceAndTargetOwner ) + } + verify(exactly = 1) { remoteFileDataSource.checkPathExistence( path = expectedRemotePath, isUserLogged = true, @@ -206,15 +207,15 @@ class OCFileRepositoryTest { assertEquals(emptyList(), filesNeedAction) - verify(exactly = 1) { + val sourceAndTargetSpaceId = OC_FILE_WITH_SPACE_ID.spaceId + val sourceAndTargetOwner = OC_FILE_WITH_SPACE_ID.owner + verify(exactly = 2) { localSpacesDataSource.getWebDavUrlForSpace( - spaceId = OC_FILE_WITH_SPACE_ID.spaceId, - accountName = OC_FILE_WITH_SPACE_ID.owner - ) - localSpacesDataSource.getWebDavUrlForSpace( - spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId, - accountName = OC_FOLDER_WITH_SPACE_ID.owner + spaceId = sourceAndTargetSpaceId, + accountName = sourceAndTargetOwner ) + } + verify(exactly = 1) { remoteFileDataSource.checkPathExistence( path = expectedRemotePath, isUserLogged = true, @@ -256,15 +257,15 @@ class OCFileRepositoryTest { assertEquals(emptyList(), filesNeedAction) - verify(exactly = 1) { - localSpacesDataSource.getWebDavUrlForSpace( - spaceId = OC_FILE_WITH_SPACE_ID.spaceId, - accountName = OC_FILE_WITH_SPACE_ID.owner - ) + val sourceAndTargetSpaceId = OC_FILE_WITH_SPACE_ID.spaceId + val sourceAndTargetOwner = OC_FILE_WITH_SPACE_ID.owner + verify(exactly = 2) { localSpacesDataSource.getWebDavUrlForSpace( - spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId, - accountName = OC_FOLDER_WITH_SPACE_ID.owner + spaceId = sourceAndTargetSpaceId, + accountName = sourceAndTargetOwner ) + } + verify(exactly = 1) { remoteFileDataSource.copyFile( sourceRemotePath = OC_FILE_WITH_SPACE_ID.remotePath, targetRemotePath = expectedRemotePath, @@ -309,14 +310,20 @@ class OCFileRepositoryTest { assertEquals(emptyList(), filesNeedAction) - verify(exactly = 1) { + val sourceAndTargetSpaceId = OC_FILE_WITH_SPACE_ID.spaceId + val sourceAndTargetOwner = OC_FILE_WITH_SPACE_ID.owner + verify(exactly = 2) { localSpacesDataSource.getWebDavUrlForSpace( - spaceId = OC_FILE_WITH_SPACE_ID.spaceId, - accountName = OC_FILE_WITH_SPACE_ID.owner + spaceId = sourceAndTargetSpaceId, + accountName = sourceAndTargetOwner ) - localSpacesDataSource.getWebDavUrlForSpace( - spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId, - accountName = OC_FOLDER_WITH_SPACE_ID.owner + } + verify(exactly = 1) { + remoteFileDataSource.getAvailableRemotePath( + remotePath = expectedRemotePath, + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + isUserLogged = true ) remoteFileDataSource.copyFile( sourceRemotePath = OC_FILE_WITH_SPACE_ID.remotePath, @@ -342,14 +349,12 @@ class OCFileRepositoryTest { assertEquals(emptyList(), filesNeedAction) - verify(exactly = 1) { + val sourceAndTargetSpaceId = OC_FILE_WITH_SPACE_ID.spaceId + val sourceAndTargetOwner = OC_FILE_WITH_SPACE_ID.owner + verify(exactly = 2) { localSpacesDataSource.getWebDavUrlForSpace( - spaceId = OC_FILE_WITH_SPACE_ID.spaceId, - accountName = OC_FILE_WITH_SPACE_ID.owner - ) - localSpacesDataSource.getWebDavUrlForSpace( - spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId, - accountName = OC_FOLDER_WITH_SPACE_ID.owner + spaceId = sourceAndTargetSpaceId, + accountName = sourceAndTargetOwner ) } } @@ -382,15 +387,15 @@ class OCFileRepositoryTest { ocFileRepository.copyFile(listOf(OC_FILE_WITH_SPACE_ID), OC_FOLDER_WITH_SPACE_ID, emptyList(), true) } - verify(exactly = 1) { - localSpacesDataSource.getWebDavUrlForSpace( - spaceId = OC_FILE_WITH_SPACE_ID.spaceId, - accountName = OC_FILE_WITH_SPACE_ID.owner - ) + val sourceAndTargetSpaceId = OC_FILE_WITH_SPACE_ID.spaceId + val sourceAndTargetOwner = OC_FILE_WITH_SPACE_ID.owner + verify(exactly = 2) { localSpacesDataSource.getWebDavUrlForSpace( - spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId, - accountName = OC_FOLDER_WITH_SPACE_ID.owner + spaceId = sourceAndTargetSpaceId, + accountName = sourceAndTargetOwner ) + } + verify(exactly = 1) { remoteFileDataSource.checkPathExistence( path = expectedRemotePath, isUserLogged = true, @@ -439,15 +444,15 @@ class OCFileRepositoryTest { ocFileRepository.copyFile(listOf(OC_FILE_WITH_SPACE_ID), OC_FOLDER_WITH_SPACE_ID, emptyList(), true) } - verify(exactly = 1) { - localSpacesDataSource.getWebDavUrlForSpace( - spaceId = OC_FILE_WITH_SPACE_ID.spaceId, - accountName = OC_FILE_WITH_SPACE_ID.owner - ) + val sourceAndTargetSpaceId = OC_FILE_WITH_SPACE_ID.spaceId + val sourceAndTargetOwner = OC_FILE_WITH_SPACE_ID.owner + verify(exactly = 2) { localSpacesDataSource.getWebDavUrlForSpace( - spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId, - accountName = OC_FOLDER_WITH_SPACE_ID.owner + spaceId = sourceAndTargetSpaceId, + accountName = sourceAndTargetOwner ) + } + verify(exactly = 1) { remoteFileDataSource.checkPathExistence( path = expectedRemotePath, isUserLogged = true, @@ -893,98 +898,575 @@ class OCFileRepositoryTest { } } - /* + @Test + fun `getFolderContent returns a list of OCFiles`() { + every { + localFileDataSource.getFolderContent(OC_PARENT_FOLDER_WITH_SPACE_ID.id!!) + } returns listOf(OC_FILE_WITH_SPACE_ID) + + val listOfFiles = ocFileRepository.getFolderContent(OC_PARENT_FOLDER_WITH_SPACE_ID.id!!) + assertEquals(listOf(OC_FILE_WITH_SPACE_ID), listOfFiles) + + verify(exactly = 1) { + localFileDataSource.getFolderContent(OC_PARENT_FOLDER_WITH_SPACE_ID.id!!) + } + } @Test - fun `getDownloadedFilesForAccount returns a list of OCFile`() { + fun `getFolderContentWithSyncInfoAsFlow returns a Flow with a list of OCFileWithSyncInfo`() = runTest { every { - localFileDataSource.getDownloadedFilesForAccount(OC_ACCOUNT_NAME) - } returns listOf(OC_FILE) + localFileDataSource.getFolderContentWithSyncInfoAsFlow(OC_PARENT_FOLDER_WITH_SPACE_ID.id!!) + } returns flowOf(listOf(OC_FILE_WITH_SYNC_INFO)) + + val listOfFiles = ocFileRepository.getFolderContentWithSyncInfoAsFlow(OC_PARENT_FOLDER_WITH_SPACE_ID.id!!).first() + assertEquals(listOf(OC_FILE_WITH_SYNC_INFO), listOfFiles) + + verify(exactly = 1) { + localFileDataSource.getFolderContentWithSyncInfoAsFlow(OC_PARENT_FOLDER_WITH_SPACE_ID.id!!) + } + } - val result = ocFileRepository.getDownloadedFilesForAccount(OC_ACCOUNT_NAME) + @Test + fun `getFolderImages returns a list of OCFiles`() { + every { + localFileDataSource.getFolderImages(OC_PARENT_FOLDER_WITH_SPACE_ID.id!!) + } returns listOf(OC_FILE_WITH_SPACE_ID) - assertEquals(listOf(OC_FILE), result) + val listOfFiles = ocFileRepository.getFolderImages(OC_PARENT_FOLDER_WITH_SPACE_ID.id!!) + assertEquals(listOf(OC_FILE_WITH_SPACE_ID), listOfFiles) verify(exactly = 1) { - localFileDataSource.getDownloadedFilesForAccount(OC_ACCOUNT_NAME) + localFileDataSource.getFolderImages(OC_PARENT_FOLDER_WITH_SPACE_ID.id!!) } } @Test - fun `get folder content - ok`() { - every { localFileDataSource.getFolderContent(OC_FOLDER.parentId!!) } returns listOf(OC_FOLDER) + fun `getSharedByLinkWithSyncInfoForAccountAsFlow returns a Flow with a list of OCFileWithSyncInfo`() = runTest { + every { + localFileDataSource.getSharedByLinkWithSyncInfoForAccountAsFlow(OC_FILE_WITH_SYNC_INFO.file.owner) + } returns flowOf(listOf(OC_FILE_WITH_SYNC_INFO)) - val folderContent = ocFileRepository.getFolderContent(OC_FOLDER.parentId!!) + val listOfFiles = ocFileRepository.getSharedByLinkWithSyncInfoForAccountAsFlow(OC_FILE_WITH_SYNC_INFO.file.owner).first() + assertEquals(listOf(OC_FILE_WITH_SYNC_INFO), listOfFiles) - assertEquals(listOf(OC_FOLDER), folderContent) + verify(exactly = 1) { + localFileDataSource.getSharedByLinkWithSyncInfoForAccountAsFlow(OC_FILE_WITH_SYNC_INFO.file.owner) + } + } + + @Test + fun `getFilesWithSyncInfoAvailableOfflineFromAccountAsFlow returns a Flow with a list of OCFileWithSyncInfo`() = runTest { + every { + localFileDataSource.getFilesWithSyncInfoAvailableOfflineFromAccountAsFlow(OC_FILE_WITH_SYNC_INFO.file.owner) + } returns flowOf(listOf(OC_FILE_WITH_SYNC_INFO)) + + val listOfFiles = ocFileRepository.getFilesWithSyncInfoAvailableOfflineFromAccountAsFlow(OC_FILE_WITH_SYNC_INFO.file.owner).first() + assertEquals(listOf(OC_FILE_WITH_SYNC_INFO), listOfFiles) verify(exactly = 1) { - localFileDataSource.getFolderContent(OC_FOLDER.parentId!!) + localFileDataSource.getFilesWithSyncInfoAvailableOfflineFromAccountAsFlow(OC_FILE_WITH_SYNC_INFO.file.owner) } } @Test - fun `getFilesLastUsageIsOlderThanGivenTime returns a list of OCFile`() { + fun `getFilesAvailableOfflineFromAccount returns a list of OCFiles`() { every { - localFileDataSource.getFilesWithLastUsageOlderThanGivenTime(timeInMilliseconds) - } returns listOf(OC_FILE) + localFileDataSource.getFilesAvailableOfflineFromAccount(OC_FILE_AVAILABLE_OFFLINE.owner) + } returns listOf(OC_FILE_AVAILABLE_OFFLINE) + + val listOfFiles = ocFileRepository.getFilesAvailableOfflineFromAccount(OC_FILE_AVAILABLE_OFFLINE.owner) + assertEquals(listOf(OC_FILE_AVAILABLE_OFFLINE), listOfFiles) + + verify(exactly = 1) { + localFileDataSource.getFilesAvailableOfflineFromAccount(OC_FILE_AVAILABLE_OFFLINE.owner) + } + } + + @Test + fun `getFilesAvailableOfflineFromEveryAccount returns a list of OCFiles`() { + every { + localFileDataSource.getFilesAvailableOfflineFromEveryAccount() + } returns OC_AVAILABLE_OFFLINE_FILES + + val listOfFiles = ocFileRepository.getFilesAvailableOfflineFromEveryAccount() + assertEquals(OC_AVAILABLE_OFFLINE_FILES, listOfFiles) + + verify(exactly = 1) { + localFileDataSource.getFilesAvailableOfflineFromEveryAccount() + } + } + + @Test + fun `getDownloadedFilesForAccount returns a list of OCFiles`() { + every { + localFileDataSource.getDownloadedFilesForAccount(OC_FILE_DOWNLOADED.owner) + } returns listOf(OC_FILE_DOWNLOADED) + + val listOfFiles = ocFileRepository.getDownloadedFilesForAccount(OC_FILE_DOWNLOADED.owner) + assertEquals(listOf(OC_FILE_DOWNLOADED), listOfFiles) + + verify(exactly = 1) { + localFileDataSource.getDownloadedFilesForAccount(OC_FILE_DOWNLOADED.owner) + } + } + + @Test + fun `getFilesWithLastUsageOlderThanGivenTime returns a list of OCFiles`() { + every { + localFileDataSource.getFilesWithLastUsageOlderThanGivenTime(0) + } returns listOf(OC_FILE_WITH_SPACE_ID) + + val listOfFiles = ocFileRepository.getFilesWithLastUsageOlderThanGivenTime(0) + assertEquals(listOf(OC_FILE_WITH_SPACE_ID), listOfFiles) + + verify(exactly = 1) { + localFileDataSource.getFilesWithLastUsageOlderThanGivenTime(0) + } + } + + @Test + fun `moveFile returns a list with the OCFile in conflict (the moved OCFile) when replace parameter is empty and expected path already exists`() { + every { + remoteFileDataSource.checkPathExistence( + path = expectedRemotePath, + isUserLogged = true, + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl + ) + } returns true + + val filesNeedAction = ocFileRepository.moveFile(listOf(OC_FILE_WITH_SPACE_ID), OC_FOLDER_WITH_SPACE_ID, emptyList(), true) + + assertEquals(listOf(OC_FILE_WITH_SPACE_ID), filesNeedAction) + + verify(exactly = 1) { + localSpacesDataSource.getWebDavUrlForSpace( + spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId, + accountName = OC_FOLDER_WITH_SPACE_ID.owner + ) + remoteFileDataSource.checkPathExistence( + path = expectedRemotePath, + isUserLogged = true, + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl + ) + } + } + + @Test + fun `moveFile returns an empty list with no OCFiles in conflict when replace parameter is empty and expected path doesn't exist`() { + every { + remoteFileDataSource.checkPathExistence( + path = expectedRemotePath, + isUserLogged = true, + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl + ) + } returns false + every { + localStorageProvider.getDefaultSavePathFor( + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + remotePath = expectedRemotePath, + spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId + ) + } returns storagePath + + val filesNeedAction = ocFileRepository.moveFile(listOf(OC_FILE_WITH_SPACE_ID), OC_FOLDER_WITH_SPACE_ID, emptyList(), true) + + assertEquals(emptyList(), filesNeedAction) + + verify(exactly = 1) { + localSpacesDataSource.getWebDavUrlForSpace( + spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId, + accountName = OC_FOLDER_WITH_SPACE_ID.owner + ) + remoteFileDataSource.checkPathExistence( + path = expectedRemotePath, + isUserLogged = true, + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + ) + localStorageProvider.getDefaultSavePathFor( + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + remotePath = expectedRemotePath, + spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId + ) + remoteFileDataSource.moveFile( + sourceRemotePath = OC_FILE_WITH_SPACE_ID.remotePath, + targetRemotePath = expectedRemotePath, + accountName = OC_FILE_WITH_SPACE_ID.owner, + spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + replace = false + ) + localFileDataSource.moveFile( + sourceFile = OC_FILE_WITH_SPACE_ID, + targetFolder = OC_FOLDER_WITH_SPACE_ID, + finalRemotePath = expectedRemotePath, + finalStoragePath = storagePath + ) + localStorageProvider.moveLocalFile( + ocFile = OC_FILE_WITH_SPACE_ID, + finalStoragePath = storagePath + ) + } + } + + @Test + fun `moveFile returns an empty list with no OCFiles in conflict when replace parameter is empty, expected path doesn't exist and file has a conflict`() { + val fileWithConflict = OC_FILE_WITH_SPACE_ID.copy( + etagInConflict = "5efb0c13c688i" + ) + every { + remoteFileDataSource.checkPathExistence( + path = expectedRemotePath, + isUserLogged = true, + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl + ) + } returns false + every { + localStorageProvider.getDefaultSavePathFor( + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + remotePath = expectedRemotePath, + spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId + ) + } returns storagePath + + val filesNeedAction = ocFileRepository.moveFile(listOf(fileWithConflict), OC_FOLDER_WITH_SPACE_ID, emptyList(), true) + + assertEquals(emptyList(), filesNeedAction) + + verify(exactly = 1) { + localSpacesDataSource.getWebDavUrlForSpace( + spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId, + accountName = OC_FOLDER_WITH_SPACE_ID.owner + ) + remoteFileDataSource.checkPathExistence( + path = expectedRemotePath, + isUserLogged = true, + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + ) + localStorageProvider.getDefaultSavePathFor( + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + remotePath = expectedRemotePath, + spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId + ) + remoteFileDataSource.moveFile( + sourceRemotePath = fileWithConflict.remotePath, + targetRemotePath = expectedRemotePath, + accountName = fileWithConflict.owner, + spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + replace = false + ) + localFileDataSource.cleanConflict(fileWithConflict.id!!) + localFileDataSource.moveFile( + sourceFile = fileWithConflict, + targetFolder = OC_FOLDER_WITH_SPACE_ID, + finalRemotePath = expectedRemotePath, + finalStoragePath = storagePath + ) + localFileDataSource.saveConflict(fileWithConflict.id!!, fileWithConflict.etagInConflict!!) + localStorageProvider.moveLocalFile( + ocFile = fileWithConflict, + finalStoragePath = storagePath + ) + } + } + + @Test + fun `moveFile returns an empty list with no OCFiles in conflict when replace parameter is true`() { + every { + localStorageProvider.getDefaultSavePathFor( + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + remotePath = expectedRemotePath, + spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId + ) + } returns storagePath + + val filesNeedAction = ocFileRepository.moveFile(listOf(OC_FILE_WITH_SPACE_ID), OC_FOLDER_WITH_SPACE_ID, listOf(true), true) + + assertEquals(emptyList(), filesNeedAction) + + verify(exactly = 1) { + localSpacesDataSource.getWebDavUrlForSpace( + spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId, + accountName = OC_FOLDER_WITH_SPACE_ID.owner + ) + localStorageProvider.getDefaultSavePathFor( + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + remotePath = expectedRemotePath, + spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId + ) + remoteFileDataSource.moveFile( + sourceRemotePath = OC_FILE_WITH_SPACE_ID.remotePath, + targetRemotePath = expectedRemotePath, + accountName = OC_FILE_WITH_SPACE_ID.owner, + spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + replace = true + ) + localFileDataSource.moveFile( + sourceFile = OC_FILE_WITH_SPACE_ID, + targetFolder = OC_FOLDER_WITH_SPACE_ID, + finalRemotePath = expectedRemotePath, + finalStoragePath = storagePath + ) + localStorageProvider.moveLocalFile( + ocFile = OC_FILE_WITH_SPACE_ID, + finalStoragePath = storagePath + ) + } + } + + @Test + fun `moveFile returns an empty list with no OCFiles in conflict when replace parameter is false`() { + val availableRemotePath = "$expectedRemotePath (1)" + val actualStoragePath = "/local/storage/path/username@demo.owncloud.com/Folder/Photos/image2 (1).jpt" + every { + remoteFileDataSource.getAvailableRemotePath( + remotePath = expectedRemotePath, + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + isUserLogged = true + ) + } returns availableRemotePath + every { + localStorageProvider.getDefaultSavePathFor( + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + remotePath = availableRemotePath, + spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId + ) + } returns actualStoragePath + + val filesNeedAction = ocFileRepository.moveFile(listOf(OC_FILE_WITH_SPACE_ID), OC_FOLDER_WITH_SPACE_ID, listOf(false), true) + + assertEquals(emptyList(), filesNeedAction) + + verify(exactly = 1) { + localSpacesDataSource.getWebDavUrlForSpace( + spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId, + accountName = OC_FOLDER_WITH_SPACE_ID.owner + ) + remoteFileDataSource.getAvailableRemotePath( + remotePath = expectedRemotePath, + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + isUserLogged = true + ) + localStorageProvider.getDefaultSavePathFor( + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + remotePath = availableRemotePath, + spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId + ) + remoteFileDataSource.moveFile( + sourceRemotePath = OC_FILE_WITH_SPACE_ID.remotePath, + targetRemotePath = availableRemotePath, + accountName = OC_FILE_WITH_SPACE_ID.owner, + spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + replace = false + ) + localFileDataSource.moveFile( + sourceFile = OC_FILE_WITH_SPACE_ID, + targetFolder = OC_FOLDER_WITH_SPACE_ID, + finalRemotePath = availableRemotePath, + finalStoragePath = actualStoragePath + ) + localStorageProvider.moveLocalFile( + ocFile = OC_FILE_WITH_SPACE_ID, + finalStoragePath = actualStoragePath + ) + } + } - val result = ocFileRepository.getFilesWithLastUsageOlderThanGivenTime(timeInMilliseconds) + @Test + fun `moveFile returns an empty list with no OCFiles in conflict when replace parameter is null`() { + val filesNeedAction = ocFileRepository.moveFile(listOf(OC_FILE_WITH_SPACE_ID), OC_FOLDER_WITH_SPACE_ID, listOf(null), true) - assertEquals(listOf(OC_FILE), result) + assertEquals(emptyList(), filesNeedAction) verify(exactly = 1) { - localFileDataSource.getFilesWithLastUsageOlderThanGivenTime(timeInMilliseconds) + localSpacesDataSource.getWebDavUrlForSpace( + spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId, + accountName = OC_FOLDER_WITH_SPACE_ID.owner + ) } } @Test - fun `getFilesLastUsageIsOlderThanGivenTime returns an empty list when datasource returns an empty list`() { + fun `moveFile removes target folder locally and throws a ConflictException when replace parameter is empty and expected path doesn't exist but target folder doesn't exist anymore`() { + every { + remoteFileDataSource.checkPathExistence( + path = expectedRemotePath, + isUserLogged = true, + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl + ) + } returns false + every { + localStorageProvider.getDefaultSavePathFor( + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + remotePath = expectedRemotePath, + spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId + ) + } returns storagePath + every { + remoteFileDataSource.moveFile( + sourceRemotePath = OC_FILE_WITH_SPACE_ID.remotePath, + targetRemotePath = expectedRemotePath, + accountName = OC_FILE_WITH_SPACE_ID.owner, + spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + replace = false + ) + } throws ConflictException() every { - localFileDataSource.getFilesWithLastUsageOlderThanGivenTime(timeInMilliseconds) + localFileDataSource.getFolderContent(OC_FOLDER_WITH_SPACE_ID.id!!) } returns emptyList() - val result = ocFileRepository.getFilesWithLastUsageOlderThanGivenTime(timeInMilliseconds) + assertThrows(ConflictException::class.java) { + ocFileRepository.moveFile(listOf(OC_FILE_WITH_SPACE_ID), OC_FOLDER_WITH_SPACE_ID, emptyList(), true) + } + + verify(exactly = 1) { + localSpacesDataSource.getWebDavUrlForSpace( + spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId, + accountName = OC_FOLDER_WITH_SPACE_ID.owner + ) + remoteFileDataSource.checkPathExistence( + path = expectedRemotePath, + isUserLogged = true, + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + ) + localStorageProvider.getDefaultSavePathFor( + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + remotePath = expectedRemotePath, + spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId + ) + remoteFileDataSource.moveFile( + sourceRemotePath = OC_FILE_WITH_SPACE_ID.remotePath, + targetRemotePath = expectedRemotePath, + accountName = OC_FILE_WITH_SPACE_ID.owner, + spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + replace = false + ) + localFileDataSource.getFolderContent(OC_FOLDER_WITH_SPACE_ID.id!!) + localStorageProvider.deleteLocalFolderIfItHasNoFilesInside(OC_FOLDER_WITH_SPACE_ID) + localFileDataSource.deleteFile(OC_FOLDER_WITH_SPACE_ID.id!!) + } + } + + @Test + fun `moveFile removes source file locally and throws a FileNotFoundException when replace parameter is empty and expected path doesn't exist but source file doesn't exist anymore`() { + every { + remoteFileDataSource.checkPathExistence( + path = expectedRemotePath, + isUserLogged = true, + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl + ) + } returns false + every { + localStorageProvider.getDefaultSavePathFor( + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + remotePath = expectedRemotePath, + spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId + ) + } returns storagePath + every { + remoteFileDataSource.moveFile( + sourceRemotePath = OC_FILE_WITH_SPACE_ID.remotePath, + targetRemotePath = expectedRemotePath, + accountName = OC_FILE_WITH_SPACE_ID.owner, + spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + replace = false + ) + } throws FileNotFoundException() + every { + localStorageProvider.deleteLocalFile(OC_FILE_WITH_SPACE_ID) + } returns true - assertEquals(emptyList(), result) + assertThrows(FileNotFoundException::class.java) { + ocFileRepository.moveFile(listOf(OC_FILE_WITH_SPACE_ID), OC_FOLDER_WITH_SPACE_ID, emptyList(), true) + } verify(exactly = 1) { - localFileDataSource.getFilesWithLastUsageOlderThanGivenTime(timeInMilliseconds) + localSpacesDataSource.getWebDavUrlForSpace( + spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId, + accountName = OC_FOLDER_WITH_SPACE_ID.owner + ) + remoteFileDataSource.checkPathExistence( + path = expectedRemotePath, + isUserLogged = true, + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + ) + localStorageProvider.getDefaultSavePathFor( + accountName = OC_FOLDER_WITH_SPACE_ID.owner, + remotePath = expectedRemotePath, + spaceId = OC_FOLDER_WITH_SPACE_ID.spaceId + ) + remoteFileDataSource.moveFile( + sourceRemotePath = OC_FILE_WITH_SPACE_ID.remotePath, + targetRemotePath = expectedRemotePath, + accountName = OC_FILE_WITH_SPACE_ID.owner, + spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl, + replace = false + ) + localStorageProvider.deleteLocalFile(OC_FILE_WITH_SPACE_ID) + localFileDataSource.deleteFile(OC_FILE_WITH_SPACE_ID.id!!) } } - @Test(expected = Exception::class) - fun `get folder content - ko`() { - every { localFileDataSource.getFolderContent(OC_FOLDER.parentId!!) } throws Exception() + @Test + fun `readFile returns a OCFile`() { + val ocFileWithoutSpaceId = OC_FILE_WITH_SPACE_ID.copy(spaceId = null) + every { + remoteFileDataSource.readFile( + remotePath = OC_FILE_WITH_SPACE_ID.remotePath, + accountName = OC_FILE_WITH_SPACE_ID.owner, + spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl + ) + } returns ocFileWithoutSpaceId - ocFileRepository.getFolderContent(OC_FOLDER.parentId!!) + val ocFile = ocFileRepository.readFile(OC_FILE_WITH_SPACE_ID.remotePath, OC_FILE_WITH_SPACE_ID.owner, OC_FILE_WITH_SPACE_ID.spaceId) + assertEquals(OC_FILE_WITH_SPACE_ID, ocFile) verify(exactly = 1) { - localFileDataSource.getFolderContent(OC_FOLDER.parentId!!) + localSpacesDataSource.getWebDavUrlForSpace( + spaceId = OC_FILE_WITH_SPACE_ID.spaceId, + accountName = OC_FILE_WITH_SPACE_ID.owner + ) + remoteFileDataSource.readFile( + remotePath = OC_FILE_WITH_SPACE_ID.remotePath, + accountName = OC_FILE_WITH_SPACE_ID.owner, + spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl + ) } } + /* + @Test - fun `get folder images - ok`() { - every { localFileDataSource.getFolderImages(OC_FOLDER.parentId!!) } returns listOf(OC_FOLDER) + fun `get folder content - ok`() { + every { localFileDataSource.getFolderContent(OC_FOLDER.parentId!!) } returns listOf(OC_FOLDER) - val folderContent = ocFileRepository.getFolderImages(OC_FOLDER.parentId!!) + val folderContent = ocFileRepository.getFolderContent(OC_FOLDER.parentId!!) assertEquals(listOf(OC_FOLDER), folderContent) verify(exactly = 1) { - localFileDataSource.getFolderImages(OC_FOLDER.parentId!!) + localFileDataSource.getFolderContent(OC_FOLDER.parentId!!) } } @Test(expected = Exception::class) - fun `get folder images - ko`() { - every { localFileDataSource.getFolderImages(OC_FOLDER.parentId!!) } throws Exception() + fun `get folder content - ko`() { + every { localFileDataSource.getFolderContent(OC_FOLDER.parentId!!) } throws Exception() - ocFileRepository.getFolderImages(OC_FOLDER.parentId!!) + ocFileRepository.getFolderContent(OC_FOLDER.parentId!!) verify(exactly = 1) { - localFileDataSource.getFolderImages(OC_FOLDER.parentId!!) + localFileDataSource.getFolderContent(OC_FOLDER.parentId!!) } } diff --git a/owncloudTestUtil/src/main/java/com/owncloud/android/testutil/OCFile.kt b/owncloudTestUtil/src/main/java/com/owncloud/android/testutil/OCFile.kt index cd65030bfda..ef7990e2ad5 100644 --- a/owncloudTestUtil/src/main/java/com/owncloud/android/testutil/OCFile.kt +++ b/owncloudTestUtil/src/main/java/com/owncloud/android/testutil/OCFile.kt @@ -125,6 +125,10 @@ val OC_FILE_AVAILABLE_OFFLINE = OCFile( availableOfflineStatus = AvailableOfflineStatus.AVAILABLE_OFFLINE ) +val OC_FILE_DOWNLOADED = OC_FILE.copy( + storagePath = "/local/storage/path/username@demo.owncloud.com/Photos/image.jpt" +) + val OC_FILE_WITH_SPACE_ID = OCFile( id = 126, parentId = 123, @@ -138,7 +142,8 @@ val OC_FILE_WITH_SPACE_ID = OCFile( etag = "5efb0c13c688i", mimeType = "image/jpeg", length = 3000000, - availableOfflineStatus = AvailableOfflineStatus.NOT_AVAILABLE_OFFLINE + availableOfflineStatus = AvailableOfflineStatus.NOT_AVAILABLE_OFFLINE, + spaceId = OC_SPACE_PERSONAL.id ) val OC_FILE_WITH_SYNC_INFO = OCFileWithSyncInfo(