FileIT.java 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package com.owncloud.android;
  2. import com.owncloud.android.datamodel.OCFile;
  3. import com.owncloud.android.lib.common.operations.RemoteOperationResult;
  4. import com.owncloud.android.operations.CreateFolderOperation;
  5. import com.owncloud.android.operations.RemoveFileOperation;
  6. import com.owncloud.android.operations.common.SyncOperation;
  7. import org.junit.Test;
  8. import org.junit.runner.RunWith;
  9. import androidx.test.ext.junit.runners.AndroidJUnit4;
  10. import static junit.framework.TestCase.assertTrue;
  11. import static org.junit.Assert.assertNull;
  12. /**
  13. * Tests related to file operations
  14. */
  15. @RunWith(AndroidJUnit4.class)
  16. public class FileIT extends AbstractIT {
  17. @Test
  18. public void testCreateFolder() {
  19. String path = "/testFolder/";
  20. // folder does not exist yet
  21. assertNull(getStorageManager().getFileByPath(path));
  22. SyncOperation syncOp = new CreateFolderOperation(path, user, targetContext);
  23. RemoteOperationResult result = syncOp.execute(client, getStorageManager());
  24. assertTrue(result.toString(), result.isSuccess());
  25. // folder exists
  26. OCFile file = getStorageManager().getFileByPath(path);
  27. assertTrue(file.isFolder());
  28. // cleanup
  29. new RemoveFileOperation(file, false, account, false, targetContext).execute(client, getStorageManager());
  30. }
  31. @Test
  32. public void testCreateNonExistingSubFolder() {
  33. String path = "/testFolder/1/2/3/4/5/";
  34. // folder does not exist yet
  35. assertNull(getStorageManager().getFileByPath(path));
  36. SyncOperation syncOp = new CreateFolderOperation(path, user, targetContext);
  37. RemoteOperationResult result = syncOp.execute(client, getStorageManager());
  38. assertTrue(result.toString(), result.isSuccess());
  39. // folder exists
  40. OCFile file = getStorageManager().getFileByPath(path);
  41. assertTrue(file.isFolder());
  42. // cleanup
  43. new RemoveFileOperation(file,
  44. false,
  45. account,
  46. false,
  47. targetContext)
  48. .execute(client, getStorageManager());
  49. }
  50. }