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;
30 * Class to test Download File Operation
35 public class DownloadFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
38 /* Files to download. These files must exist on the account */
39 private final String mRemoteFilePng = "/fileToDownload.png";
40 private final String mRemoteFileChunks = "/fileToDownload.mp4";
41 private final String mRemoteFileSpecialChars = "/@file@download.png";
42 private final String mRemoteFileSpecialCharsChunks = "/@file@download.mp4";
43 private final String mRemoteFileNotFound = "/fileNotFound.png"; /* This file mustn't exist on the account */
45 private String mCurrentDate;
48 private TestActivity mActivity;
50 public DownloadFileTest() {
51 super(TestActivity.class);
53 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
54 mCurrentDate = sdf.format(new Date());
58 protected void setUp() throws Exception {
60 setActivityInitialTouchMode(false);
61 mActivity = getActivity();
65 * Test Download a File
67 public void testDownloadFile() {
68 String temporalFolder = "/download" + mCurrentDate;
70 RemoteFile remoteFile= new RemoteFile(mRemoteFilePng);
72 RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder);
73 assertTrue(result.isSuccess());
77 * Test Download a File with chunks
79 public void testDownloadFileChunks() {
80 String temporalFolder = "/download" + mCurrentDate;
82 RemoteFile remoteFile= new RemoteFile(mRemoteFileChunks);
84 RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder);
85 assertTrue(result.isSuccess());
89 * Test Download a File with special chars
91 public void testDownloadFileSpecialChars() {
92 String temporalFolder = "/download" + mCurrentDate;
94 RemoteFile remoteFile= new RemoteFile(mRemoteFileSpecialChars);
96 RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder);
97 assertTrue(result.isSuccess());
101 * Test Download a File with special chars and chunks
103 public void testDownloadFileSpecialCharsChunks() {
104 String temporalFolder = "/download" + mCurrentDate;
106 RemoteFile remoteFile= new RemoteFile(mRemoteFileSpecialCharsChunks);
108 RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder);
109 assertTrue(result.isSuccess());
113 * Test Download a Not Found File
115 public void testDownloadFileNotFound() {
116 String temporalFolder = "/download" + mCurrentDate;
118 RemoteFile remoteFile = new RemoteFile(mRemoteFileNotFound);
120 RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder);
121 assertFalse(result.isSuccess());