Przeglądaj źródła

OC-2333: Complete Unit Tests

masensio 11 lat temu
rodzic
commit
64ddaf8d9a

+ 15 - 1
oc_framework-test-project/oc_framework-test-test/src/com/owncloud/android/oc_framework_test_project/test/UploadFileTest.java

@@ -31,7 +31,6 @@ import android.test.ActivityInstrumentationTestCase2;
 import android.util.Log;
 
 import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
-import com.owncloud.android.oc_framework.operations.RemoteOperationResult.ResultCode;
 import com.owncloud.android.oc_framework_test_project.TestActivity;
 
 /**
@@ -49,6 +48,8 @@ public class UploadFileTest extends ActivityInstrumentationTestCase2<TestActivit
 	private final String mFileToUploadWithChunks = "fileToUploadChunks.MP4";
 	private final String mMimeTypeWithChunks = "video/mp4";
 	
+	private final String mFileNotFound = "fileNotFound.png";
+	
 	private final String mStoragePath = "/owncloud/tmp/uploadTest";
 	private String mPath;
 	
@@ -144,4 +145,17 @@ public class UploadFileTest extends ActivityInstrumentationTestCase2<TestActivit
 		assertTrue(result.isSuccess());
 	}
 	
+	/**
+	 * Test Upload Not Found File
+	 */
+	public void testUploadFileNotFound() {
+
+		String storagePath = mPath + "/" + mFileNotFound;
+		//String remotePath = "/uploadTest" + mCurrentDate + "/" + mFileToUpload;
+		String remotePath = "/" + mFileNotFound;
+		
+		RemoteOperationResult result = mActivity.uploadFile(storagePath, remotePath, mMimeType);
+		assertFalse(result.isSuccess());
+	}
+	
 }

+ 9 - 4
oc_framework-test-project/src/com/owncloud/android/oc_framework_test_project/TestActivity.java

@@ -1,10 +1,9 @@
 package com.owncloud.android.oc_framework_test_project;
 
-import java.io.File;
-
 import com.owncloud.android.oc_framework.network.webdav.OwnCloudClientFactory;
 import com.owncloud.android.oc_framework.network.webdav.WebdavClient;
 import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
+import com.owncloud.android.oc_framework.operations.remote.ChunkedUploadRemoteFileOperation;
 import com.owncloud.android.oc_framework.operations.remote.CreateRemoteFolderOperation;
 import com.owncloud.android.oc_framework.operations.remote.ReadRemoteFolderOperation;
 import com.owncloud.android.oc_framework.operations.remote.RemoveRemoteFileOperation;
@@ -13,7 +12,6 @@ import com.owncloud.android.oc_framework.operations.remote.UploadRemoteFileOpera
 
 import android.net.Uri;
 import android.os.Bundle;
-import android.os.Environment;
 import android.app.Activity;
 import android.view.Menu;
 
@@ -28,6 +26,7 @@ public class TestActivity extends Activity {
 	private static final String mServerUri = "https://beta.owncloud.com/owncloud/remote.php/webdav";
 	private static final String mUser = "testandroid";
 	private static final String mPass = "testandroid";
+	private static final boolean mChunked = true;
 	
 	//private Account mAccount = null;
 	private WebdavClient mClient;
@@ -117,8 +116,14 @@ public class TestActivity extends Activity {
 	 * @return
 	 */
 	public RemoteOperationResult uploadFile(String storagePath, String remotePath, String mimeType) {
+
+		UploadRemoteFileOperation uploadOperation;
+		if (mChunked) {
+            uploadOperation = new ChunkedUploadRemoteFileOperation(storagePath, remotePath, mimeType);
+        } else {
+            uploadOperation = new UploadRemoteFileOperation(storagePath, remotePath, mimeType);
+        }
 		
-		UploadRemoteFileOperation uploadOperation = new UploadRemoteFileOperation(storagePath, remotePath, mimeType);
 		RemoteOperationResult result = uploadOperation.execute(mClient);
 		
 		return result;

+ 22 - 22
src/com/owncloud/android/operations/UploadFileOperation.java

@@ -372,28 +372,28 @@ public class UploadFileOperation extends RemoteOperation {
         mFile = newFile;
     }
 
-    public boolean isSuccess(int status) {
-        return ((status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED || status == HttpStatus.SC_NO_CONTENT));
-    }
-
-    protected int uploadFile(WebdavClient client) throws HttpException, IOException, OperationCancelledException {
-        int status = -1;
-        try {
-            File f = new File(mFile.getStoragePath());
-            mEntity  = new FileRequestEntity(f, getMimeType());
-            synchronized (mDataTransferListeners) {
-                ((ProgressiveDataTransferer)mEntity).addDatatransferProgressListeners(mDataTransferListeners);
-            }
-            mPutMethod.setRequestEntity(mEntity);
-            status = client.executeMethod(mPutMethod);
-            client.exhaustResponse(mPutMethod.getResponseBodyAsStream());
-
-        } finally {
-            mPutMethod.releaseConnection(); // let the connection available for
-                                            // other methods
-        }
-        return status;
-    }
+//    public boolean isSuccess(int status) {
+//        return ((status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED || status == HttpStatus.SC_NO_CONTENT));
+//    }
+//
+//    protected int uploadFile(WebdavClient client) throws HttpException, IOException, OperationCancelledException {
+//        int status = -1;
+//        try {
+//            File f = new File(mFile.getStoragePath());
+//            mEntity  = new FileRequestEntity(f, getMimeType());
+//            synchronized (mDataTransferListeners) {
+//                ((ProgressiveDataTransferer)mEntity).addDatatransferProgressListeners(mDataTransferListeners);
+//            }
+//            mPutMethod.setRequestEntity(mEntity);
+//            status = client.executeMethod(mPutMethod);
+//            client.exhaustResponse(mPutMethod.getResponseBodyAsStream());
+//
+//        } finally {
+//            mPutMethod.releaseConnection(); // let the connection available for
+//                                            // other methods
+//        }
+//        return status;
+//    }
 
     /**
      * Checks if remotePath does not exist in the server and returns it, or adds