mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 02:17:41 +00:00 
			
		
		
		
	Update unit tests with cases for creating private shares
This commit is contained in:
		
							parent
							
								
									b5074f4381
								
							
						
					
					
						commit
						5c48817712
					
				| @ -31,6 +31,9 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCo | ||||
| import com.owncloud.android.lib.resources.shares.ShareType; | ||||
| import com.owncloud.android.lib.test_project.TestActivity; | ||||
| 
 | ||||
| /** | ||||
|  * Test Create Share: the server must support SHARE API | ||||
|  */ | ||||
| public class CreateShareTest extends RemoteTest { | ||||
| 
 | ||||
| 	private static final String LOG_TAG = CreateShareTest.class.getCanonicalName(); | ||||
| @ -38,15 +41,20 @@ public class CreateShareTest extends RemoteTest { | ||||
| 	/* File to share.*/ | ||||
| 	private static final String FILE_TO_SHARE = "/fileToShare.txt"; | ||||
| 
 | ||||
| 	/* Non-existent file*/ | ||||
| 	private static final String NON_EXISTENT_FILE = "/nonExistentFile.txt"; | ||||
| 	 | ||||
| 	private TestActivity mActivity; | ||||
| 	private String mFullPath2FileToShare; | ||||
| 	private String mFullPath2NonExistentFile; | ||||
| 	 | ||||
| 	@Override | ||||
| 	protected void setUp() throws Exception { | ||||
| 	    super.setUp(); | ||||
| 	    setActivityInitialTouchMode(false); | ||||
| 	    mActivity = getActivity(); | ||||
| 	    mFullPath2FileToShare = mBaseFolderPath + FILE_TO_SHARE;   | ||||
| 	    mFullPath2FileToShare = mBaseFolderPath + FILE_TO_SHARE; | ||||
| 	    mFullPath2NonExistentFile = mBaseFolderPath + NON_EXISTENT_FILE; | ||||
| 	    		 | ||||
| 		File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME); | ||||
| 		RemoteOperationResult result = mActivity.uploadFile( | ||||
| @ -57,11 +65,13 @@ public class CreateShareTest extends RemoteTest { | ||||
| 			Utils.logAndThrow(LOG_TAG, result); | ||||
| 		} | ||||
| 	} | ||||
| 	 | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Test Create Share: the server must support SHARE API | ||||
| 	 * Test creation of public shares | ||||
| 	 */ | ||||
| 	public void testCreatePublicShare() { | ||||
| 
 | ||||
| 		/// Successful cases | ||||
| 		RemoteOperationResult result = mActivity.createShare( | ||||
| 				mFullPath2FileToShare,  | ||||
| 				ShareType.PUBLIC_LINK,  | ||||
| @ -70,6 +80,141 @@ public class CreateShareTest extends RemoteTest { | ||||
| 				"",  | ||||
| 				1); | ||||
| 		assertTrue(result.isSuccess()); | ||||
| 		 | ||||
| 		/// Failed cases | ||||
| 		 | ||||
| 		// file doesn't exist | ||||
| 		result = mActivity.createShare( | ||||
| 				mFullPath2NonExistentFile,  | ||||
| 				ShareType.PUBLIC_LINK,  | ||||
| 				"",  | ||||
| 				false,  | ||||
| 				"",  | ||||
| 				1); | ||||
| 		assertFalse(result.isSuccess()); | ||||
| 		assertEquals( | ||||
| 				RemoteOperationResult.ResultCode.SHARE_NOT_FOUND,  | ||||
| 				result.getCode() | ||||
| 		); | ||||
| 		assertTrue(		// error message from server as part of the result | ||||
| 				result.getData().size() == 1 &&  | ||||
| 				result.getData().get(0) instanceof String | ||||
| 		); | ||||
| 		 | ||||
| 	} | ||||
| 	 | ||||
| 	 | ||||
| 	/** | ||||
| 	 * Test creation of private shares with groups | ||||
| 	 */ | ||||
| 	public void testCreatePrivateShareWithUser() { | ||||
| 		 | ||||
| 		/// Successful cases | ||||
| 		RemoteOperationResult result = mActivity.createShare( | ||||
| 				mFullPath2FileToShare,  | ||||
| 				ShareType.USER,  | ||||
| 				"admin",  | ||||
| 				false,  | ||||
| 				"",  | ||||
| 				31); | ||||
| 		assertTrue(result.isSuccess()); | ||||
| 		 | ||||
| 		 | ||||
| 		/// Failed cases | ||||
| 		 | ||||
| 		// sharee doesn't exist | ||||
| 		result = mActivity.createShare( | ||||
| 				mFullPath2FileToShare,  | ||||
| 				ShareType.USER,  | ||||
| 				"no_exist",  | ||||
| 				false,  | ||||
| 				"",  | ||||
| 				31); | ||||
| 		assertFalse(result.isSuccess()); | ||||
| 		assertEquals( | ||||
| 				RemoteOperationResult.ResultCode.SHARE_WRONG_PARAMETER,  | ||||
| 				result.getCode() | ||||
| 		); | ||||
| 		assertTrue(		// error message from server as part of the result | ||||
| 				result.getData().size() == 1 &&  | ||||
| 				result.getData().get(0) instanceof String | ||||
| 		); | ||||
| 		 | ||||
| 		// file doesn't exist | ||||
| 		result = mActivity.createShare( | ||||
| 				mFullPath2NonExistentFile,  | ||||
| 				ShareType.USER,  | ||||
| 				"admin",  | ||||
| 				false,  | ||||
| 				"",  | ||||
| 				31); | ||||
| 		assertFalse(result.isSuccess()); | ||||
| 		assertEquals( | ||||
| 				RemoteOperationResult.ResultCode.SHARE_NOT_FOUND,  | ||||
| 				result.getCode() | ||||
| 		); | ||||
| 		assertTrue(		// error message from server as part of the result | ||||
| 				result.getData().size() == 1 &&  | ||||
| 				result.getData().get(0) instanceof String | ||||
| 		); | ||||
| 		 | ||||
| 	} | ||||
| 	 | ||||
| 	 | ||||
| 	/** | ||||
| 	 * Test creation of private shares with groups | ||||
| 	 */ | ||||
| 	public void testCreatePrivateShareWithGroup() { | ||||
| 		 | ||||
| 		/// Successful cases | ||||
| 		RemoteOperationResult result = mActivity.createShare( | ||||
| 				mFullPath2FileToShare,  | ||||
| 				ShareType.GROUP,  | ||||
| 				"admin",  | ||||
| 				false,  | ||||
| 				"",  | ||||
| 				1); | ||||
| 		assertTrue(result.isSuccess()); | ||||
| 		 | ||||
| 		 | ||||
| 		/// Failed cases | ||||
| 		 | ||||
| 		// sharee doesn't exist | ||||
| 		result = mActivity.createShare( | ||||
| 				mFullPath2FileToShare,  | ||||
| 				ShareType.GROUP,  | ||||
| 				"no_exist",  | ||||
| 				false,  | ||||
| 				"",  | ||||
| 				31); | ||||
| 		assertFalse(result.isSuccess()); | ||||
| 		assertEquals( | ||||
| 				RemoteOperationResult.ResultCode.SHARE_WRONG_PARAMETER,  | ||||
| 				result.getCode() | ||||
| 		); | ||||
| 		assertTrue(		// error message from server as part of the result | ||||
| 				result.getData().size() == 1 &&  | ||||
| 				result.getData().get(0) instanceof String | ||||
| 		); | ||||
| 		 | ||||
| 		// file doesn't exist | ||||
| 		result = mActivity.createShare( | ||||
| 				mFullPath2NonExistentFile,  | ||||
| 				ShareType.GROUP,  | ||||
| 				"admin",  | ||||
| 				false,  | ||||
| 				"",  | ||||
| 				31); | ||||
| 		assertFalse(result.isSuccess()); | ||||
| 		assertEquals( | ||||
| 				RemoteOperationResult.ResultCode.SHARE_NOT_FOUND,  | ||||
| 				result.getCode() | ||||
| 		); | ||||
| 		assertTrue(		// error message from server as part of the result | ||||
| 				result.getData().size() == 1 &&  | ||||
| 				result.getData().get(0) instanceof String | ||||
| 		); | ||||
| 		 | ||||
| 	} | ||||
| 	 | ||||
| 	 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user