FileDataStorageManagerContentResolverIT.kt 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. *
  3. * Nextcloud Android client application
  4. *
  5. * @author Tobias Kaminsky
  6. * Copyright (C) 2020 Tobias Kaminsky
  7. * Copyright (C) 2020 Nextcloud GmbH
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. package com.owncloud.android.datamodel
  23. import org.junit.Assert
  24. import org.junit.Test
  25. import java.util.ArrayList
  26. class FileDataStorageManagerContentResolverIT : FileDataStorageManagerIT() {
  27. companion object {
  28. private const val MANY_FILES_AMOUNT = 5000
  29. }
  30. override fun before() {
  31. sut = FileDataStorageManager(user, targetContext.contentResolver)
  32. super.before()
  33. }
  34. /**
  35. * only on FileDataStorageManager
  36. */
  37. @Test
  38. fun testFolderWithManyFiles() {
  39. // create folder
  40. val folderA = OCFile("/folderA/", "00001") // remote Id must never be null
  41. folderA.setFolder().parentId = sut.getFileByDecryptedRemotePath("/")!!.fileId
  42. sut.saveFile(folderA)
  43. Assert.assertTrue(sut.fileExists("/folderA/"))
  44. Assert.assertEquals(0, sut.getFolderContent(folderA, false).size)
  45. val folderAId = sut.getFileByDecryptedRemotePath("/folderA/")!!.fileId
  46. // create files
  47. val newFiles = (1..MANY_FILES_AMOUNT).map {
  48. val file = OCFile("/folderA/file$it", it.toString())
  49. file.parentId = folderAId
  50. sut.saveFile(file)
  51. val storedFile = sut.getFileByDecryptedRemotePath("/folderA/file$it")
  52. Assert.assertNotNull(storedFile)
  53. storedFile
  54. }
  55. // save files in folder
  56. sut.saveFolder(
  57. folderA,
  58. newFiles,
  59. ArrayList()
  60. )
  61. // check file count is correct
  62. Assert.assertEquals(MANY_FILES_AMOUNT, sut.getFolderContent(folderA, false).size)
  63. }
  64. }