mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 02:17:41 +00:00 
			
		
		
		
	Updated ReadFolderTest to work with an empty OC server
This commit is contained in:
		
							parent
							
								
									e2380a6a5c
								
							
						
					
					
						commit
						596c793243
					
				| @ -28,7 +28,6 @@ import java.io.File; | ||||
| import java.io.FileOutputStream; | ||||
| import java.io.IOException; | ||||
| import java.io.InputStream; | ||||
| import java.io.OutputStream; | ||||
| import java.security.GeneralSecurityException; | ||||
| 
 | ||||
| import org.apache.commons.httpclient.protocol.Protocol; | ||||
| @ -56,7 +55,6 @@ import android.net.Uri; | ||||
| import android.os.Bundle; | ||||
| import android.os.Environment; | ||||
| import android.app.Activity; | ||||
| import android.content.res.AssetManager; | ||||
| import android.util.Log; | ||||
| import android.view.Menu; | ||||
| 
 | ||||
| @ -78,6 +76,8 @@ public class TestActivity extends Activity { | ||||
| 	private static final String WEBDAV_PATH = "/remote.php/webdav"; | ||||
| 	private static final int BUFFER_SIZE = 1024; | ||||
| 	 | ||||
| 	public static final String ASSETS__TEXT_FILE_NAME = "textFile.txt"; | ||||
| 	 | ||||
| 	//private Account mAccount = null; | ||||
| 	private OwnCloudClient mClient; | ||||
| 	 | ||||
|  | ||||
| @ -30,7 +30,6 @@ import com.owncloud.android.lib.resources.files.FileUtils; | ||||
| import com.owncloud.android.lib.test_project.TestActivity; | ||||
| 
 | ||||
| import android.test.ActivityInstrumentationTestCase2; | ||||
| import android.util.Log; | ||||
| 
 | ||||
| /** | ||||
|  * Class to test Read File Operation | ||||
| @ -42,10 +41,10 @@ public class ReadFileTest extends 	ActivityInstrumentationTestCase2<TestActivity | ||||
| 	 | ||||
| 	private static final String LOG_TAG = ReadFileTest.class.getCanonicalName(); | ||||
| 	 | ||||
| 	private static final String TEXT_FILE_NAME = "textFile.txt"; | ||||
| 
 | ||||
| 	private TestActivity mActivity; | ||||
| 	 | ||||
| 	private String mFilePath;  | ||||
| 	 | ||||
| 	public ReadFileTest() { | ||||
| 		super(TestActivity.class); | ||||
| 	} | ||||
| @ -56,14 +55,15 @@ public class ReadFileTest extends 	ActivityInstrumentationTestCase2<TestActivity | ||||
| 
 | ||||
| 		setActivityInitialTouchMode(false); | ||||
| 		mActivity = getActivity(); | ||||
| 		mFilePath = FileUtils.PATH_SEPARATOR + TestActivity.ASSETS__TEXT_FILE_NAME; | ||||
| 		 | ||||
| 		File textFile = mActivity.extractAsset(TEXT_FILE_NAME); | ||||
| 		File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME); | ||||
| 		RemoteOperationResult uploadResult = mActivity.uploadFile( | ||||
| 				textFile.getAbsolutePath(),  | ||||
| 				FileUtils.PATH_SEPARATOR + TEXT_FILE_NAME,  | ||||
| 				mFilePath,  | ||||
| 				"txt/plain"); | ||||
| 		if (!uploadResult.isSuccess()) { | ||||
| 			logAndThrow(uploadResult); | ||||
| 			Utils.logAndThrow(LOG_TAG, uploadResult); | ||||
| 		} | ||||
| 	} | ||||
| 	 | ||||
| @ -71,25 +71,20 @@ public class ReadFileTest extends 	ActivityInstrumentationTestCase2<TestActivity | ||||
| 	 * Test Read File | ||||
| 	 */ | ||||
| 	public void testReadFile() { | ||||
| 		RemoteOperationResult result = mActivity.readFile(TEXT_FILE_NAME); | ||||
| 		assertTrue(result.getData().size() ==  1); | ||||
| 		RemoteOperationResult result = mActivity.readFile(mFilePath); | ||||
| 		assertTrue(result.getData() != null && result.getData().size() ==  1); | ||||
| 		assertTrue(result.isSuccess()); | ||||
| 		// TODO check more properties of the result | ||||
| 	} | ||||
| 	 | ||||
| 	@Override | ||||
| 	protected void tearDown() throws Exception { | ||||
| 		RemoteOperationResult removeResult = mActivity.removeFile(TEXT_FILE_NAME); | ||||
| 		RemoteOperationResult removeResult = mActivity.removeFile(mFilePath); | ||||
| 		if (!removeResult.isSuccess()) { | ||||
| 			logAndThrow(removeResult); | ||||
| 			Utils.logAndThrow(LOG_TAG, removeResult); | ||||
| 		} | ||||
| 		 | ||||
| 		super.tearDown(); | ||||
| 	} | ||||
| 
 | ||||
| 	private void logAndThrow(RemoteOperationResult result) throws Exception { | ||||
| 		Log.e(LOG_TAG, result.getLogMessage(), result.getException()); | ||||
| 		throw new Exception(result.getLogMessage(), result.getException()); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -24,7 +24,10 @@ | ||||
| 
 | ||||
| package com.owncloud.android.lib.test_project.test; | ||||
| 
 | ||||
| import java.io.File; | ||||
| 
 | ||||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult; | ||||
| import com.owncloud.android.lib.resources.files.FileUtils; | ||||
| import com.owncloud.android.lib.test_project.TestActivity; | ||||
| 
 | ||||
| import android.test.ActivityInstrumentationTestCase2; | ||||
| @ -32,14 +35,17 @@ import android.test.ActivityInstrumentationTestCase2; | ||||
| /** | ||||
|  * Class to test Read Folder Operation | ||||
|  * @author masensio | ||||
|  * | ||||
|  * @author David A. Velasco | ||||
|  */ | ||||
| 
 | ||||
| public class ReadFolderTest extends	ActivityInstrumentationTestCase2<TestActivity> { | ||||
| 	 | ||||
| 	private static final String LOG_TAG = ReadFolderTest.class.getCanonicalName(); | ||||
| 
 | ||||
| 	/* Folder data to read. This folder must exist on the account */ | ||||
| 	private final String mRemoteFolderPath = "/folderToRead"; | ||||
| 	private static final String FOLDER_PATH = "/folderToRead"; | ||||
| 	private static final String FILE1_NAME = "file1.txt"; | ||||
| 	private static final String FILE2_NAME = "file2.txt"; | ||||
| 	private static final String FILE3_NAME = "file3.txt"; | ||||
| 
 | ||||
| 	 | ||||
| 	private TestActivity mActivity; | ||||
| @ -53,6 +59,28 @@ public class ReadFolderTest extends	ActivityInstrumentationTestCase2<TestActivit | ||||
| 		super.setUp(); | ||||
| 		setActivityInitialTouchMode(false); | ||||
| 		mActivity = getActivity(); | ||||
| 		 | ||||
| 		File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME); | ||||
| 		RemoteOperationResult result = mActivity.createFolder(FOLDER_PATH, true); | ||||
| 		if (result.isSuccess()) { | ||||
| 			String [] filePaths = { | ||||
| 					FOLDER_PATH + FileUtils.PATH_SEPARATOR + FILE1_NAME, | ||||
| 					FOLDER_PATH + FileUtils.PATH_SEPARATOR + FILE2_NAME, | ||||
| 					FOLDER_PATH + FileUtils.PATH_SEPARATOR + FILE3_NAME | ||||
| 			}; | ||||
| 
 | ||||
| 			for (int i=0; i<filePaths.length && result.isSuccess(); i++) { | ||||
| 				result = mActivity.uploadFile( | ||||
| 						textFile.getAbsolutePath(),  | ||||
| 						filePaths[i],  | ||||
| 						"txt/plain"); | ||||
| 			} | ||||
| 		} | ||||
| 				 | ||||
| 		if (!result.isSuccess()) { | ||||
| 			Utils.logAndThrow(LOG_TAG, result); | ||||
| 		} | ||||
| 	     | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| @ -60,10 +88,22 @@ public class ReadFolderTest extends	ActivityInstrumentationTestCase2<TestActivit | ||||
| 	 */ | ||||
| 	public void testReadFolder() { | ||||
| 
 | ||||
| 		RemoteOperationResult result = mActivity.readFile(mRemoteFolderPath); | ||||
| 		assertTrue(result.getData().size() > 1); | ||||
| 		assertTrue(result.getData().size() == 4); | ||||
| 		RemoteOperationResult result = mActivity.readFile(FOLDER_PATH); | ||||
| 		assertTrue(result.isSuccess()); | ||||
| 		assertTrue(result.getData() != null && result.getData().size() > 1); | ||||
| 		assertTrue(result.getData().size() == 4); | ||||
| 		// TODO assert more properties about the result | ||||
| 	} | ||||
| 
 | ||||
| 	 | ||||
| 	@Override | ||||
| 	protected void tearDown() throws Exception { | ||||
| 		RemoteOperationResult removeResult = mActivity.removeFile(FOLDER_PATH); | ||||
| 		if (!removeResult.isSuccess()) { | ||||
| 			Utils.logAndThrow(LOG_TAG, removeResult); | ||||
| 		} | ||||
| 		 | ||||
| 		super.tearDown(); | ||||
| 	} | ||||
| 	 | ||||
| } | ||||
|  | ||||
| @ -0,0 +1,38 @@ | ||||
| /* ownCloud Android Library is available under MIT license | ||||
|  *   Copyright (C) 2014 ownCloud Inc. | ||||
|  *    | ||||
|  *   Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
|  *   of this software and associated documentation files (the "Software"), to deal | ||||
|  *   in the Software without restriction, including without limitation the rights | ||||
|  *   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||
|  *   copies of the Software, and to permit persons to whom the Software is | ||||
|  *   furnished to do so, subject to the following conditions: | ||||
|  *    | ||||
|  *   The above copyright notice and this permission notice shall be included in | ||||
|  *   all copies or substantial portions of the Software. | ||||
|  *    | ||||
|  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,  | ||||
|  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||||
|  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND  | ||||
|  *   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS  | ||||
|  *   BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN  | ||||
|  *   ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN  | ||||
|  *   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||||
|  *   THE SOFTWARE. | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| package com.owncloud.android.lib.test_project.test; | ||||
| 
 | ||||
| import android.util.Log; | ||||
| 
 | ||||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult; | ||||
| 
 | ||||
| public class Utils { | ||||
| 
 | ||||
| 	public static void logAndThrow(String tag, RemoteOperationResult result) throws Exception { | ||||
| 		Log.e(tag, result.getLogMessage(), result.getException()); | ||||
| 		throw new Exception(result.getLogMessage(), result.getException()); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user