OCFileUnitTest.java 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /**
  2. * ownCloud Android client application
  3. *
  4. * @author David A. Velasco
  5. * Copyright (C) 2016 ownCloud Inc.
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2,
  9. * as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. package com.owncloud.android.datamodel;
  21. import android.os.Parcel;
  22. import android.support.test.filters.SmallTest;
  23. import android.support.test.runner.AndroidJUnit4;
  24. import org.junit.Before;
  25. import org.junit.Test;
  26. import org.junit.runner.RunWith;
  27. import static org.hamcrest.CoreMatchers.is;
  28. import static org.hamcrest.MatcherAssert.assertThat;
  29. /**
  30. * Instrumented unit test, to be run in an Android emulator or device.
  31. *
  32. * At the moment, it's a sample to validate the automatic test environment, in the scope of instrumented unit tests.
  33. *
  34. * Don't take it as an example of completeness.
  35. *
  36. * See http://developer.android.com/intl/es/training/testing/unit-testing/instrumented-unit-tests.html .
  37. */
  38. @RunWith(AndroidJUnit4.class)
  39. @SmallTest
  40. public class OCFileUnitTest {
  41. private final static String PATH = "/path/to/a/file.txt";
  42. private static final long ID = 12345L;
  43. private static final long PARENT_ID = 567890L;
  44. private static final String STORAGE_PATH = "/mnt/sd/localpath/to/a/file.txt";
  45. private static final String MIME_TYPE = "text/plain";
  46. private static final long FILE_LENGTH = 9876543210L;
  47. private static final long CREATION_TIMESTAMP = 8765432109L;
  48. private static final long MODIFICATION_TIMESTAMP = 7654321098L;
  49. private static final long MODIFICATION_TIMESTAMP_AT_LAST_SYNC_FOR_DATA = 6543210987L;
  50. private static final long LAST_SYNC_DATE_FOR_PROPERTIES = 5432109876L;
  51. private static final long LAST_SYNC_DATE_FOR_DATA = 4321098765L;
  52. private static final String ETAG = "adshfas98ferqw8f9yu2";
  53. private static final String PUBLIC_LINK = "https://fake.url.net/owncloud/987427448712984sdas29";
  54. private static final String PERMISSIONS = "SRKNVD";
  55. private static final String REMOTE_ID = "jadñgiadf8203:9jrp98v2mn3er2089fh";
  56. private static final String ETAG_IN_CONFLICT = "2adshfas98ferqw8f9yu";
  57. private OCFile mFile;
  58. @Before
  59. public void createDefaultOCFile() {
  60. mFile = new OCFile(PATH);
  61. }
  62. @Test
  63. public void writeThenReadAsParcelable() {
  64. // Set up mFile with not-default values
  65. mFile.setFileId(ID);
  66. mFile.setParentId(PARENT_ID);
  67. mFile.setStoragePath(STORAGE_PATH);
  68. mFile.setMimetype(MIME_TYPE);
  69. mFile.setFileLength(FILE_LENGTH);
  70. mFile.setCreationTimestamp(CREATION_TIMESTAMP);
  71. mFile.setModificationTimestamp(MODIFICATION_TIMESTAMP);
  72. mFile.setModificationTimestampAtLastSyncForData(MODIFICATION_TIMESTAMP_AT_LAST_SYNC_FOR_DATA);
  73. mFile.setLastSyncDateForProperties(LAST_SYNC_DATE_FOR_PROPERTIES);
  74. mFile.setLastSyncDateForData(LAST_SYNC_DATE_FOR_DATA);
  75. mFile.setAvailableOffline(true);
  76. mFile.setEtag(ETAG);
  77. mFile.setShareViaLink(true);
  78. mFile.setShareWithSharee(true);
  79. mFile.setPublicLink(PUBLIC_LINK);
  80. mFile.setPermissions(PERMISSIONS);
  81. mFile.setRemoteId(REMOTE_ID);
  82. mFile.setNeedsUpdateThumbnail(true);
  83. mFile.setDownloading(true);
  84. mFile.setEtagInConflict(ETAG_IN_CONFLICT);
  85. // Write the file data in a Parcel
  86. Parcel parcel = Parcel.obtain();
  87. mFile.writeToParcel(parcel, mFile.describeContents());
  88. // Read the data from the parcel
  89. parcel.setDataPosition(0);
  90. OCFile fileReadFromParcel = OCFile.CREATOR.createFromParcel(parcel);
  91. // Verify that the received data are correct
  92. assertThat(fileReadFromParcel.getRemotePath(), is(PATH));
  93. assertThat(fileReadFromParcel.getFileId(), is(ID));
  94. assertThat(fileReadFromParcel.getParentId(), is(PARENT_ID));
  95. assertThat(fileReadFromParcel.getStoragePath(), is(STORAGE_PATH));
  96. assertThat(fileReadFromParcel.getMimetype(), is(MIME_TYPE));
  97. assertThat(fileReadFromParcel.getFileLength(), is(FILE_LENGTH));
  98. assertThat(fileReadFromParcel.getCreationTimestamp(), is(CREATION_TIMESTAMP));
  99. assertThat(fileReadFromParcel.getModificationTimestamp(), is(MODIFICATION_TIMESTAMP));
  100. assertThat(
  101. fileReadFromParcel.getModificationTimestampAtLastSyncForData(),
  102. is(MODIFICATION_TIMESTAMP_AT_LAST_SYNC_FOR_DATA)
  103. );
  104. assertThat(fileReadFromParcel.getLastSyncDateForProperties(), is(LAST_SYNC_DATE_FOR_PROPERTIES));
  105. assertThat(fileReadFromParcel.getLastSyncDateForData(), is(LAST_SYNC_DATE_FOR_DATA));
  106. assertThat(fileReadFromParcel.setAvailableOffline(), is(true));
  107. assertThat(fileReadFromParcel.getEtag(), is(ETAG));
  108. assertThat(fileReadFromParcel.isSharedViaLink(), is(true));
  109. assertThat(fileReadFromParcel.isSharedWithSharee(), is(true));
  110. assertThat(fileReadFromParcel.getPublicLink(), is(PUBLIC_LINK));
  111. assertThat(fileReadFromParcel.getPermissions(), is(PERMISSIONS));
  112. assertThat(fileReadFromParcel.getRemoteId(), is(REMOTE_ID));
  113. assertThat(fileReadFromParcel.needsUpdateThumbnail(), is(true));
  114. assertThat(fileReadFromParcel.isDownloading(), is(true));
  115. assertThat(fileReadFromParcel.getEtagInConflict(), is(ETAG_IN_CONFLICT));
  116. }
  117. }