OCFileUnitTest.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * ownCloud Android client application
  3. *
  4. * @author David A. Velasco
  5. * Copyright (C) 2016 ownCloud Inc.
  6. * <p>
  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. * <p>
  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. * <p>
  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. package com.owncloud.android.datamodel;
  20. import android.os.Parcel;
  21. import org.junit.Before;
  22. import org.junit.Test;
  23. import org.junit.runner.RunWith;
  24. import androidx.test.filters.SmallTest;
  25. import androidx.test.runner.AndroidJUnit4;
  26. import static org.hamcrest.CoreMatchers.is;
  27. import static org.hamcrest.MatcherAssert.assertThat;
  28. /**
  29. * Instrumented unit test, to be run in an Android emulator or device.
  30. *
  31. * At the moment, it's a sample to validate the automatic test environment, in the scope of instrumented unit tests.
  32. *vvlcvlc
  33. * Don't take it as an example of completeness.
  34. *
  35. * See http://developer.android.com/intl/es/training/testing/unit-testing/instrumented-unit-tests.html .
  36. */
  37. @RunWith(AndroidJUnit4.class)
  38. @SmallTest
  39. public class OCFileUnitTest {
  40. private final static String PATH = "/path/to/a/file.txt";
  41. private static final long ID = 12345L;
  42. private static final long PARENT_ID = 567890L;
  43. private static final String STORAGE_PATH = "/mnt/sd/localpath/to/a/file.txt";
  44. private static final String MIME_TYPE = "text/plain";
  45. private static final long FILE_LENGTH = 9876543210L;
  46. private static final long CREATION_TIMESTAMP = 8765432109L;
  47. private static final long MODIFICATION_TIMESTAMP = 7654321098L;
  48. private static final long MODIFICATION_TIMESTAMP_AT_LAST_SYNC_FOR_DATA = 6543210987L;
  49. private static final long LAST_SYNC_DATE_FOR_PROPERTIES = 5432109876L;
  50. private static final long LAST_SYNC_DATE_FOR_DATA = 4321098765L;
  51. private static final String ETAG = "adshfas98ferqw8f9yu2";
  52. private static final String PUBLIC_LINK = "https://nextcloud.localhost/owncloud/987427448712984sdas29";
  53. private static final String PERMISSIONS = "SRKNVD";
  54. private static final String REMOTE_ID = "jadñgiadf8203:9jrp98v2mn3er2089fh";
  55. private static final String ETAG_IN_CONFLICT = "2adshfas98ferqw8f9yu";
  56. private OCFile mFile;
  57. @Before
  58. public void createDefaultOCFile() {
  59. mFile = new OCFile(PATH);
  60. }
  61. @Test
  62. public void writeThenReadAsParcelable() {
  63. // Set up mFile with not-default values
  64. mFile.setFileId(ID);
  65. mFile.setParentId(PARENT_ID);
  66. mFile.setStoragePath(STORAGE_PATH);
  67. mFile.setMimeType(MIME_TYPE);
  68. mFile.setFileLength(FILE_LENGTH);
  69. mFile.setCreationTimestamp(CREATION_TIMESTAMP);
  70. mFile.setModificationTimestamp(MODIFICATION_TIMESTAMP);
  71. mFile.setModificationTimestampAtLastSyncForData(MODIFICATION_TIMESTAMP_AT_LAST_SYNC_FOR_DATA);
  72. mFile.setLastSyncDateForProperties(LAST_SYNC_DATE_FOR_PROPERTIES);
  73. mFile.setLastSyncDateForData(LAST_SYNC_DATE_FOR_DATA);
  74. mFile.setEtag(ETAG);
  75. mFile.setSharedViaLink(true);
  76. mFile.setSharedWithSharee(true);
  77. mFile.setPermissions(PERMISSIONS);
  78. mFile.setRemoteId(REMOTE_ID);
  79. mFile.setUpdateThumbnailNeeded(true);
  80. mFile.setDownloading(true);
  81. mFile.setEtagInConflict(ETAG_IN_CONFLICT);
  82. // Write the file data in a Parcel
  83. Parcel parcel = Parcel.obtain();
  84. mFile.writeToParcel(parcel, mFile.describeContents());
  85. // Read the data from the parcel
  86. parcel.setDataPosition(0);
  87. OCFile fileReadFromParcel = OCFile.CREATOR.createFromParcel(parcel);
  88. // Verify that the received data are correct
  89. assertThat(fileReadFromParcel.getRemotePath(), is(PATH));
  90. assertThat(fileReadFromParcel.getFileId(), is(ID));
  91. assertThat(fileReadFromParcel.getParentId(), is(PARENT_ID));
  92. assertThat(fileReadFromParcel.getStoragePath(), is(STORAGE_PATH));
  93. assertThat(fileReadFromParcel.getMimeType(), is(MIME_TYPE));
  94. assertThat(fileReadFromParcel.getFileLength(), is(FILE_LENGTH));
  95. assertThat(fileReadFromParcel.getCreationTimestamp(), is(CREATION_TIMESTAMP));
  96. assertThat(fileReadFromParcel.getModificationTimestamp(), is(MODIFICATION_TIMESTAMP));
  97. assertThat(
  98. fileReadFromParcel.getModificationTimestampAtLastSyncForData(),
  99. is(MODIFICATION_TIMESTAMP_AT_LAST_SYNC_FOR_DATA)
  100. );
  101. assertThat(fileReadFromParcel.getLastSyncDateForProperties(), is(LAST_SYNC_DATE_FOR_PROPERTIES));
  102. assertThat(fileReadFromParcel.getLastSyncDateForData(), is(LAST_SYNC_DATE_FOR_DATA));
  103. assertThat(fileReadFromParcel.getEtag(), is(ETAG));
  104. assertThat(fileReadFromParcel.isSharedViaLink(), is(true));
  105. assertThat(fileReadFromParcel.isSharedWithSharee(), is(true));
  106. assertThat(fileReadFromParcel.getPermissions(), is(PERMISSIONS));
  107. assertThat(fileReadFromParcel.getRemoteId(), is(REMOTE_ID));
  108. assertThat(fileReadFromParcel.isUpdateThumbnailNeeded(), is(true));
  109. assertThat(fileReadFromParcel.isDownloading(), is(true));
  110. assertThat(fileReadFromParcel.getEtagInConflict(), is(ETAG_IN_CONFLICT));
  111. }
  112. }