RemoveFileOperationIT.java 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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.operations;
  23. import com.owncloud.android.AbstractOnServerIT;
  24. import com.owncloud.android.datamodel.OCFile;
  25. import com.owncloud.android.db.OCUpload;
  26. import com.owncloud.android.utils.FileStorageUtils;
  27. import org.junit.Test;
  28. import static junit.framework.TestCase.assertNotNull;
  29. import static junit.framework.TestCase.assertTrue;
  30. public class RemoveFileOperationIT extends AbstractOnServerIT {
  31. @Test
  32. public void deleteFolder() {
  33. String parent = "/test/";
  34. String path = parent + "folder1/";
  35. assertTrue(new CreateFolderOperation(path, user, targetContext).execute(client, getStorageManager())
  36. .isSuccess());
  37. OCFile folder = getStorageManager().getFileByPath(path);
  38. assertNotNull(folder);
  39. assertTrue(new RemoveFileOperation(folder,
  40. false,
  41. account,
  42. false,
  43. targetContext)
  44. .execute(client, getStorageManager())
  45. .isSuccess());
  46. OCFile parentFolder = getStorageManager().getFileByPath(parent);
  47. assertNotNull(parentFolder);
  48. assertTrue(new RemoveFileOperation(parentFolder,
  49. false,
  50. account,
  51. false,
  52. targetContext)
  53. .execute(client, getStorageManager())
  54. .isSuccess());
  55. }
  56. @Test
  57. public void deleteFile() {
  58. String parent = "/test/";
  59. String path = parent + "empty.txt";
  60. OCUpload ocUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/empty.txt", path, account.name);
  61. uploadOCUpload(ocUpload);
  62. OCFile file = getStorageManager().getFileByPath(path);
  63. assertNotNull(file);
  64. assertTrue(new RemoveFileOperation(file,
  65. false,
  66. account,
  67. false,
  68. targetContext)
  69. .execute(client, getStorageManager())
  70. .isSuccess());
  71. OCFile parentFolder = getStorageManager().getFileByPath(parent);
  72. assertNotNull(parentFolder);
  73. assertTrue(new RemoveFileOperation(parentFolder,
  74. false,
  75. account,
  76. false,
  77. targetContext)
  78. .execute(client, getStorageManager())
  79. .isSuccess());
  80. }
  81. }