UploadStorageManagerTest.java 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package com.owncloud.android.datamodel;
  2. import android.accounts.Account;
  3. import android.content.ContentResolver;
  4. import android.content.Context;
  5. import android.support.test.InstrumentationRegistry;
  6. import android.support.test.filters.SmallTest;
  7. import android.support.test.runner.AndroidJUnit4;
  8. import com.owncloud.android.db.OCUpload;
  9. import org.junit.After;
  10. import org.junit.Assert;
  11. import org.junit.Before;
  12. import org.junit.Test;
  13. import org.junit.runner.RunWith;
  14. import java.io.File;
  15. /**
  16. * Created by JARP on 6/7/17.
  17. */
  18. @RunWith(AndroidJUnit4.class)
  19. @SmallTest
  20. public class UploadStorageManagerTest {
  21. private ContentResolver contentResolver;
  22. private Context instrumentationCtx;
  23. private Account [] Accounts;
  24. private UploadsStorageManager uploadsStorageManager;
  25. @Before
  26. public void setup() {
  27. instrumentationCtx = InstrumentationRegistry.getTargetContext();
  28. contentResolver = instrumentationCtx.getContentResolver();
  29. uploadsStorageManager = new UploadsStorageManager(contentResolver,instrumentationCtx);
  30. Accounts = new Account[]{ new Account("A","A"),new Account("B","B") };
  31. }
  32. @Test
  33. public void testDeleteAllUploads() {
  34. //Clean
  35. for (Account account : Accounts) {
  36. uploadsStorageManager.removeAccountUploads(account);
  37. }
  38. int accountRowsA = 3;
  39. int accountRowsB = 4;
  40. insertUploads(Accounts[0],accountRowsA);
  41. insertUploads(Accounts[1],accountRowsB);
  42. Assert.assertTrue("Expected 4 removed uploads files",uploadsStorageManager.removeAccountUploads(Accounts[1]) == 4 );
  43. }
  44. private void insertUploads(Account account, int rowsToInsert) {
  45. for (int i = 0; i < rowsToInsert; i++) {
  46. uploadsStorageManager.storeUpload(createUpload(account));
  47. }
  48. }
  49. private OCUpload createUpload(Account acc) {
  50. return new OCUpload( File.separator + "LocalPath",
  51. OCFile.PATH_SEPARATOR + "RemotePath",
  52. acc.name);
  53. }
  54. @After
  55. public void tearDown()
  56. {
  57. for (Account account : Accounts) {
  58. uploadsStorageManager.removeAccountUploads(account);
  59. }
  60. }
  61. }