OC-2333: Complete Unit Tests
authormasensio <masensio@solidgear.es>
Wed, 18 Dec 2013 08:02:56 +0000 (09:02 +0100)
committermasensio <masensio@solidgear.es>
Wed, 18 Dec 2013 08:02:56 +0000 (09:02 +0100)
oc_framework-test-project/oc_framework-test-test/src/com/owncloud/android/oc_framework_test_project/test/UploadFileTest.java
oc_framework-test-project/src/com/owncloud/android/oc_framework_test_project/TestActivity.java
src/com/owncloud/android/operations/UploadFileOperation.java

index 6aabf5b..6710371 100644 (file)
@@ -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());
+       }
+       
 }
index f259ec4..c42aca2 100644 (file)
@@ -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;
index 7501fa1..b0b9466 100644 (file)
@@ -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