1 /* ownCloud Android client application
2 * Copyright (C) 2012-2013 ownCloud Inc.
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.
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.
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/>.
18 package com.owncloud.android.oc_framework_test_project.test;
20 import java.text.SimpleDateFormat;
21 import java.util.Date;
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;
27 import android.test.ActivityInstrumentationTestCase2;
28 import android.util.Log;
31 * Class to test Download File Operation
36 public class DownloadFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
38 private final String TAG = DownloadFileTest.class.getSimpleName();
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 */
47 private String mCurrentDate;
50 private TestActivity mActivity;
52 public DownloadFileTest() {
53 super(TestActivity.class);
55 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
56 mCurrentDate = sdf.format(new Date());
60 protected void setUp() throws Exception {
62 setActivityInitialTouchMode(false);
63 mActivity = getActivity();
67 * Test Download a File
69 public void testDownloadFile() {
70 String temporalFolder = "/download" + mCurrentDate;
72 RemoteFile remoteFile= new RemoteFile(mRemoteFilePng);
74 RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder);
75 assertTrue(result.isSuccess());
79 * Test Download a File with chunks
81 public void testDownloadFileChunks() {
82 String temporalFolder = "/download" + mCurrentDate;
84 RemoteFile remoteFile= new RemoteFile(mRemoteFileChunks);
86 RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder);
87 assertTrue(result.isSuccess());
91 * Test Download a File with special chars
93 public void testDownloadFileSpecialChars() {
94 String temporalFolder = "/download" + mCurrentDate;
96 RemoteFile remoteFile= new RemoteFile(mRemoteFileSpecialChars);
98 RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder);
99 assertTrue(result.isSuccess());
103 * Test Download a File with special chars and chunks
105 public void testDownloadFileSpecialCharsChunks() {
106 String temporalFolder = "/download" + mCurrentDate;
108 RemoteFile remoteFile= new RemoteFile(mRemoteFileSpecialCharsChunks);
110 RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder);
111 assertTrue(result.isSuccess());
115 * Test Download a Not Found File
117 public void testDownloadFileNotFound() {
118 String temporalFolder = "/download" + mCurrentDate;
120 RemoteFile remoteFile = new RemoteFile(mRemoteFileNotFound);
122 RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder);
123 assertFalse(result.isSuccess());