mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 02:17:41 +00:00 
			
		
		
		
	Updated DownloadFileTest to work with an empty OC server
This commit is contained in:
		
							parent
							
								
									d2e6925396
								
							
						
					
					
						commit
						7000fbeaa2
					
				| @ -24,41 +24,45 @@ | |||||||
| 
 | 
 | ||||||
| package com.owncloud.android.lib.test_project.test; | package com.owncloud.android.lib.test_project.test; | ||||||
| 
 | 
 | ||||||
| import java.text.SimpleDateFormat; | import java.io.File; | ||||||
| import java.util.Date; | import java.util.ArrayList; | ||||||
|  | import java.util.Iterator; | ||||||
|  | import java.util.List; | ||||||
| 
 | 
 | ||||||
| import com.owncloud.android.lib.resources.files.RemoteFile; | import com.owncloud.android.lib.resources.files.RemoteFile; | ||||||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult; | import com.owncloud.android.lib.common.operations.RemoteOperationResult; | ||||||
|  | import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; | ||||||
| import com.owncloud.android.lib.test_project.TestActivity; | import com.owncloud.android.lib.test_project.TestActivity; | ||||||
| 
 | 
 | ||||||
| import android.test.ActivityInstrumentationTestCase2; | import android.test.ActivityInstrumentationTestCase2; | ||||||
|  | import android.util.Log; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Class to test Download File Operation |  * Class to test Download File Operation | ||||||
|  * @author masensio |  * @author masensio | ||||||
|  * |  * @author David A. Velasco | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| public class DownloadFileTest extends ActivityInstrumentationTestCase2<TestActivity> { | public class DownloadFileTest extends ActivityInstrumentationTestCase2<TestActivity> { | ||||||
| 
 | 
 | ||||||
| 	 | 	 | ||||||
|  | 	private static final String LOG_TAG = DownloadFileTest.class.getCanonicalName(); | ||||||
|  | 	 | ||||||
| 	/* Files to download. These files must exist on the account */ | 	/* Files to download. These files must exist on the account */ | ||||||
| 	private final String mRemoteFilePng = "/fileToDownload.png"; | 	private static final String IMAGE_PATH = "/fileToDownload.png"; | ||||||
| 	private final String mRemoteFileChunks = "/fileToDownload.mp4"; | 	private static final String IMAGE_PATH_WITH_SPECIAL_CHARS = "/@file@download.png"; | ||||||
| 	private final String mRemoteFileSpecialChars = "/@file@download.png"; | 	private static final String IMAGE_NOT_FOUND = "/fileNotFound.png"; | ||||||
| 	private final String mRemoteFileSpecialCharsChunks = "/@file@download.mp4"; | 	private static final String [] FILE_PATHS = { IMAGE_PATH, IMAGE_PATH_WITH_SPECIAL_CHARS };  | ||||||
| 	private final String mRemoteFileNotFound = "/fileNotFound.png"; /* This file mustn't exist on the account */ |  | ||||||
| 	 |  | ||||||
| 	private String mCurrentDate; |  | ||||||
| 	 | 	 | ||||||
|  | 	private static boolean mGlobalSetupDone = false; | ||||||
| 	 | 	 | ||||||
|  | 	private List<String> mDownloadedFilesPaths; | ||||||
| 	private TestActivity mActivity; | 	private TestActivity mActivity; | ||||||
|  | 
 | ||||||
| 	 | 	 | ||||||
| 	public DownloadFileTest() { | 	public DownloadFileTest() { | ||||||
| 	    super(TestActivity.class); | 	    super(TestActivity.class); | ||||||
| 	     | 		mDownloadedFilesPaths = new ArrayList<String>(); | ||||||
| 		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss"); |  | ||||||
| 		mCurrentDate = sdf.format(new Date()); |  | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	@Override | 	@Override | ||||||
| @ -66,67 +70,88 @@ public class DownloadFileTest extends ActivityInstrumentationTestCase2<TestActiv | |||||||
| 	    super.setUp(); | 	    super.setUp(); | ||||||
| 	    setActivityInitialTouchMode(false); | 	    setActivityInitialTouchMode(false); | ||||||
| 	    mActivity = getActivity(); | 	    mActivity = getActivity(); | ||||||
|  | 	    mDownloadedFilesPaths.clear(); | ||||||
|  | 	     | ||||||
|  | 	    if (!mGlobalSetupDone) { | ||||||
|  | 	    	 | ||||||
|  | 	    	RemoteOperationResult result = null; | ||||||
|  | 			File imageFile = mActivity.extractAsset(TestActivity.ASSETS__IMAGE_FILE_NAME); | ||||||
|  | 
 | ||||||
|  | 			for (int i=0; i<FILE_PATHS.length && (result == null || result.isSuccess()); i++) { | ||||||
|  | 				result = mActivity.uploadFile( | ||||||
|  | 						imageFile.getAbsolutePath(),  | ||||||
|  | 						FILE_PATHS[i],  | ||||||
|  | 						"image/png"); | ||||||
|  | 			} | ||||||
|  | 			if (!result.isSuccess()) { | ||||||
|  | 				Utils.logAndThrow(LOG_TAG, result); | ||||||
|  | 			} | ||||||
|  | 			 | ||||||
|  | 			result = mActivity.removeFile(IMAGE_NOT_FOUND); | ||||||
|  | 			if (!result.isSuccess() && result.getCode() != ResultCode.FILE_NOT_FOUND) { | ||||||
|  | 				Utils.logAndThrow(LOG_TAG, result); | ||||||
|  | 			} | ||||||
|  | 			 | ||||||
|  | 			Log.v(LOG_TAG, "Global set up done"); | ||||||
|  | 		    mGlobalSetupDone = true; | ||||||
|  | 	    } | ||||||
|  | 	     | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	/** | 	/** | ||||||
| 	 * Test Download a File | 	 * Test Download a File | ||||||
| 	 */ | 	 */ | ||||||
| 	public void testDownloadFile() { | 	public void testDownloadFile() { | ||||||
| 		String temporalFolder = "/download" + mCurrentDate; | 		RemoteOperationResult result = mActivity.downloadFile( | ||||||
| 		 | 				new RemoteFile(IMAGE_PATH),  | ||||||
| 		RemoteFile remoteFile= new RemoteFile(mRemoteFilePng); | 				mActivity.getFilesDir().getAbsolutePath() | ||||||
| 
 | 				); | ||||||
| 		RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder); | 		mDownloadedFilesPaths.add(IMAGE_PATH); | ||||||
| 		assertTrue(result.isSuccess()); |  | ||||||
| 	} |  | ||||||
| 	 |  | ||||||
| 	/** |  | ||||||
| 	 * Test Download a File with chunks |  | ||||||
| 	 */ |  | ||||||
| 	public void testDownloadFileChunks() { |  | ||||||
| 		String temporalFolder = "/download" + mCurrentDate; |  | ||||||
| 		 |  | ||||||
| 		RemoteFile remoteFile= new RemoteFile(mRemoteFileChunks); |  | ||||||
| 
 |  | ||||||
| 		RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder); |  | ||||||
| 		assertTrue(result.isSuccess()); | 		assertTrue(result.isSuccess()); | ||||||
|  | 		// TODO some checks involving the local file | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	/** | 	/** | ||||||
| 	 * Test Download a File with special chars | 	 * Test Download a File with special chars | ||||||
| 	 */ | 	 */ | ||||||
| 	public void testDownloadFileSpecialChars() { | 	public void testDownloadFileSpecialChars() { | ||||||
| 		String temporalFolder = "/download" + mCurrentDate; | 		RemoteOperationResult result = mActivity.downloadFile( | ||||||
| 		 | 				new RemoteFile(IMAGE_PATH_WITH_SPECIAL_CHARS), | ||||||
| 		RemoteFile remoteFile= new RemoteFile(mRemoteFileSpecialChars); | 				mActivity.getFilesDir().getAbsolutePath() | ||||||
| 
 | 				); | ||||||
| 		RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder); | 		mDownloadedFilesPaths.add(IMAGE_PATH_WITH_SPECIAL_CHARS); | ||||||
| 		assertTrue(result.isSuccess()); |  | ||||||
| 	} |  | ||||||
| 	 |  | ||||||
| 	/** |  | ||||||
| 	 * Test Download a File with special chars and chunks |  | ||||||
| 	 */ |  | ||||||
| 	public void testDownloadFileSpecialCharsChunks() { |  | ||||||
| 		String temporalFolder = "/download" + mCurrentDate; |  | ||||||
| 		 |  | ||||||
| 		RemoteFile remoteFile= new RemoteFile(mRemoteFileSpecialCharsChunks); |  | ||||||
| 
 |  | ||||||
| 		RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder); |  | ||||||
| 		assertTrue(result.isSuccess()); | 		assertTrue(result.isSuccess()); | ||||||
|  | 		// TODO some checks involving the local file | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	/** | 	/** | ||||||
| 	 * Test Download a Not Found File  | 	 * Test Download a Not Found File  | ||||||
| 	 */ | 	 */ | ||||||
| 	public void testDownloadFileNotFound() { | 	public void testDownloadFileNotFound() { | ||||||
| 		String temporalFolder = "/download" + mCurrentDate; | 		RemoteOperationResult result = mActivity.downloadFile( | ||||||
| 
 | 				new RemoteFile(IMAGE_NOT_FOUND),  | ||||||
| 		RemoteFile remoteFile = new RemoteFile(mRemoteFileNotFound); | 				mActivity.getFilesDir().getAbsolutePath() | ||||||
| 
 | 				); | ||||||
| 		RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder); |  | ||||||
| 		assertFalse(result.isSuccess()); | 		assertFalse(result.isSuccess()); | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	 | 	 | ||||||
|  | 	@Override | ||||||
|  | 	protected void tearDown() throws Exception { | ||||||
|  | 		Iterator<String> it = mDownloadedFilesPaths.iterator(); | ||||||
|  | 		RemoteOperationResult removeResult = null; | ||||||
|  | 		while (it.hasNext()) { | ||||||
|  | 			removeResult = mActivity.removeFile(it.next()); | ||||||
|  | 			if (!removeResult.isSuccess()) { | ||||||
|  | 				Utils.logAndThrow(LOG_TAG, removeResult); | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 		File[] files = mActivity.getFilesDir().listFiles(); | ||||||
|  | 		for (File file : files) { | ||||||
|  | 			file.delete(); | ||||||
|  | 		} | ||||||
|  | 		super.tearDown(); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user