|
40 | 40 | import com.owncloud.android.lib.common.OwnCloudClientFactory; |
41 | 41 | import com.owncloud.android.lib.common.operations.RemoteOperationResult; |
42 | 42 | import com.owncloud.android.lib.resources.files.model.RemoteFile; |
| 43 | +import com.owncloud.android.lib.resources.shares.CreateShareRemoteOperation; |
| 44 | +import com.owncloud.android.lib.resources.shares.ShareType; |
43 | 45 | import com.owncloud.android.lib.resources.status.GetCapabilitiesRemoteOperation; |
44 | 46 | import com.owncloud.android.lib.resources.status.OCCapability; |
45 | 47 |
|
@@ -180,6 +182,48 @@ public void oneFavorite() { |
180 | 182 | assertEquals(path, remoteFile.getRemotePath()); |
181 | 183 | } |
182 | 184 |
|
| 185 | + @Test |
| 186 | + public void favoriteFiles() throws IOException { |
| 187 | + // share a file by second user to test user |
| 188 | + String sharedFile = createFile("sharedFavoriteImage.jpg"); |
| 189 | + String sharedRemotePath = "/sharedFavoriteImage.jpg"; |
| 190 | + assertTrue(new UploadFileRemoteOperation(sharedFile, sharedRemotePath, "image/jpg", RANDOM_MTIME) |
| 191 | + .execute(client2).isSuccess()); |
| 192 | + |
| 193 | + // share |
| 194 | + assertTrue(new CreateShareRemoteOperation(sharedRemotePath, |
| 195 | + ShareType.USER, |
| 196 | + client.getUserId(), |
| 197 | + false, |
| 198 | + "", |
| 199 | + 31).execute(client2) |
| 200 | + .isSuccess() |
| 201 | + ); |
| 202 | + |
| 203 | + // test user: favorite it |
| 204 | + assertTrue(new ToggleFavoriteRemoteOperation(true, sharedRemotePath).execute(client).isSuccess()); |
| 205 | + |
| 206 | + String filePath = createFile("favoriteImage.jpg"); |
| 207 | + String remotePath = "/favoriteImage.jpg"; |
| 208 | + assertTrue(new UploadFileRemoteOperation(filePath, remotePath, "image/jpg", RANDOM_MTIME) |
| 209 | + .execute(client).isSuccess()); |
| 210 | + |
| 211 | + assertTrue(new ToggleFavoriteRemoteOperation(true, remotePath).execute(client).isSuccess()); |
| 212 | + |
| 213 | + SearchRemoteOperation sut = new SearchRemoteOperation("", |
| 214 | + SearchRemoteOperation.SearchType.FAVORITE_SEARCH, |
| 215 | + false, |
| 216 | + capability); |
| 217 | + RemoteOperationResult<List<RemoteFile>> result = sut.execute(client); |
| 218 | + |
| 219 | + // test |
| 220 | + assertTrue(result.isSuccess()); |
| 221 | + assertEquals(2, result.getResultData().size()); |
| 222 | + |
| 223 | + assertEquals(remotePath, result.getResultData().get(0).getRemotePath()); |
| 224 | + assertEquals(sharedRemotePath, result.getResultData().get(1).getRemotePath()); |
| 225 | + } |
| 226 | + |
183 | 227 | /** |
184 | 228 | * shows just all files, but sorted by date |
185 | 229 | */ |
|
0 commit comments