74cfb40009054a1daafc41a64b57f5bf7d0a9a5e
[pub/Android/ownCloud.git] /
1 /* ownCloud Android client application
2 * Copyright (C) 2012-2013 ownCloud Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18 package com.owncloud.android.oc_framework_test_project.test;
19
20 import java.text.SimpleDateFormat;
21 import java.util.Date;
22
23 import com.owncloud.android.oc_framework.operations.RemoteFile;
24 import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
25 import com.owncloud.android.oc_framework_test_project.TestActivity;
26
27 import android.test.ActivityInstrumentationTestCase2;
28 import android.util.Log;
29
30 /**
31 * Class to test Download File Operation
32 * @author masensio
33 *
34 */
35
36 public class DownloadFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
37
38 private final String TAG = DownloadFileTest.class.getSimpleName();
39
40 /* Files to download. These files must exist on the account */
41 private final String mRemoteFilePng = "/fileToDownload.png";
42 private final String mRemoteFileChunks = "/fileToDownload.mp4";
43 private final String mRemoteFileSpecialChars = "/@file@download.png";
44 private final String mRemoteFileSpecialCharsChunks = "/@file@download.mp4";
45 private final String mRemoteFileNotFound = "/fileNotFound.png"; /* This file mustn't exist on the account */
46
47 private String mCurrentDate;
48
49
50 private TestActivity mActivity;
51
52 public DownloadFileTest() {
53 super(TestActivity.class);
54
55 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
56 mCurrentDate = sdf.format(new Date());
57 }
58
59 @Override
60 protected void setUp() throws Exception {
61 super.setUp();
62 setActivityInitialTouchMode(false);
63 mActivity = getActivity();
64 }
65
66 /**
67 * Test Download a File
68 */
69 public void testDownloadFile() {
70 String temporalFolder = "/download" + mCurrentDate;
71
72 RemoteFile remoteFile= new RemoteFile(mRemoteFilePng);
73
74 RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder);
75 assertTrue(result.isSuccess());
76 }
77
78 /**
79 * Test Download a File with chunks
80 */
81 public void testDownloadFileChunks() {
82 String temporalFolder = "/download" + mCurrentDate;
83
84 RemoteFile remoteFile= new RemoteFile(mRemoteFileChunks);
85
86 RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder);
87 assertTrue(result.isSuccess());
88 }
89
90 /**
91 * Test Download a File with special chars
92 */
93 public void testDownloadFileSpecialChars() {
94 String temporalFolder = "/download" + mCurrentDate;
95
96 RemoteFile remoteFile= new RemoteFile(mRemoteFileSpecialChars);
97
98 RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder);
99 assertTrue(result.isSuccess());
100 }
101
102 /**
103 * Test Download a File with special chars and chunks
104 */
105 public void testDownloadFileSpecialCharsChunks() {
106 String temporalFolder = "/download" + mCurrentDate;
107
108 RemoteFile remoteFile= new RemoteFile(mRemoteFileSpecialCharsChunks);
109
110 RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder);
111 assertTrue(result.isSuccess());
112 }
113
114 /**
115 * Test Download a Not Found File
116 */
117 public void testDownloadFileNotFound() {
118 String temporalFolder = "/download" + mCurrentDate;
119
120 RemoteFile remoteFile = new RemoteFile(mRemoteFileNotFound);
121
122 RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder);
123 assertFalse(result.isSuccess());
124 }
125 }