FileDataStorageManagerContentResolverIT.kt 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. class FileDataStorageManagerContentResolverIT : FileDataStorageManagerIT() {
  26. companion object {
  27. private const val MANY_FILES_AMOUNT = 5000
  28. }
  29. override fun before() {
  30. sut = FileDataStorageManager(user, targetContext.contentResolver)
  31. super.before()
  32. }
  33. /**
  34. * only on FileDataStorageManager
  35. */
  36. @Test
  37. fun testFolderWithManyFiles() {
  38. // create folder
  39. val folderA = OCFile("/folderA/")
  40. folderA.setFolder().parentId = sut.getFileByDecryptedRemotePath("/")!!.fileId
  41. sut.saveFile(folderA)
  42. Assert.assertTrue(sut.fileExists("/folderA/"))
  43. Assert.assertEquals(0, sut.getFolderContent(folderA, false).size)
  44. val folderAId = sut.getFileByDecryptedRemotePath("/folderA/")!!.fileId
  45. // create files
  46. val newFiles = (1..MANY_FILES_AMOUNT).map {
  47. val file = OCFile("/folderA/file$it")
  48. file.parentId = folderAId
  49. sut.saveFile(file)
  50. val storedFile = sut.getFileByDecryptedRemotePath("/folderA/file$it")
  51. Assert.assertNotNull(storedFile)
  52. storedFile
  53. }
  54. // save files in folder
  55. sut.saveFolder(
  56. folderA,
  57. newFiles,
  58. ArrayList()
  59. )
  60. // check file count is correct
  61. Assert.assertEquals(MANY_FILES_AMOUNT, sut.getFolderContent(folderA, false).size)
  62. }
  63. }