28f53e46e3151fe0e43fe529e06fcf38a7b67ff7
[pub/Android/ownCloud.git] /
1 /* ownCloud webDAV Library for Android is available under MIT license
2 * Copyright (C) 2014 ownCloud (http://www.owncloud.org/)
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 * THE SOFTWARE.
22 *
23 */
24
25 package com.owncloud.android.oc_framework_test_project.test;
26
27 import java.text.SimpleDateFormat;
28 import java.util.Date;
29
30 import com.owncloud.android.oc_framework.operations.RemoteFile;
31 import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
32 import com.owncloud.android.oc_framework_test_project.TestActivity;
33
34 import android.test.ActivityInstrumentationTestCase2;
35
36 /**
37 * Class to test Download File Operation
38 * @author masensio
39 *
40 */
41
42 public class DownloadFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
43
44
45 /* Files to download. These files must exist on the account */
46 private final String mRemoteFilePng = "/fileToDownload.png";
47 private final String mRemoteFileChunks = "/fileToDownload.mp4";
48 private final String mRemoteFileSpecialChars = "/@file@download.png";
49 private final String mRemoteFileSpecialCharsChunks = "/@file@download.mp4";
50 private final String mRemoteFileNotFound = "/fileNotFound.png"; /* This file mustn't exist on the account */
51
52 private String mCurrentDate;
53
54
55 private TestActivity mActivity;
56
57 public DownloadFileTest() {
58 super(TestActivity.class);
59
60 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
61 mCurrentDate = sdf.format(new Date());
62 }
63
64 @Override
65 protected void setUp() throws Exception {
66 super.setUp();
67 setActivityInitialTouchMode(false);
68 mActivity = getActivity();
69 }
70
71 /**
72 * Test Download a File
73 */
74 public void testDownloadFile() {
75 String temporalFolder = "/download" + mCurrentDate;
76
77 RemoteFile remoteFile= new RemoteFile(mRemoteFilePng);
78
79 RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder);
80 assertTrue(result.isSuccess());
81 }
82
83 /**
84 * Test Download a File with chunks
85 */
86 public void testDownloadFileChunks() {
87 String temporalFolder = "/download" + mCurrentDate;
88
89 RemoteFile remoteFile= new RemoteFile(mRemoteFileChunks);
90
91 RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder);
92 assertTrue(result.isSuccess());
93 }
94
95 /**
96 * Test Download a File with special chars
97 */
98 public void testDownloadFileSpecialChars() {
99 String temporalFolder = "/download" + mCurrentDate;
100
101 RemoteFile remoteFile= new RemoteFile(mRemoteFileSpecialChars);
102
103 RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder);
104 assertTrue(result.isSuccess());
105 }
106
107 /**
108 * Test Download a File with special chars and chunks
109 */
110 public void testDownloadFileSpecialCharsChunks() {
111 String temporalFolder = "/download" + mCurrentDate;
112
113 RemoteFile remoteFile= new RemoteFile(mRemoteFileSpecialCharsChunks);
114
115 RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder);
116 assertTrue(result.isSuccess());
117 }
118
119 /**
120 * Test Download a Not Found File
121 */
122 public void testDownloadFileNotFound() {
123 String temporalFolder = "/download" + mCurrentDate;
124
125 RemoteFile remoteFile = new RemoteFile(mRemoteFileNotFound);
126
127 RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder);
128 assertFalse(result.isSuccess());
129 }
130 }