Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5c488177 authored by David A. Velasco's avatar David A. Velasco
Browse files

Update unit tests with cases for creating private shares

parent b5074f43
Loading
Loading
Loading
Loading
+148 −3
Original line number Diff line number Diff line
@@ -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,8 +41,12 @@ 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 {
@@ -47,6 +54,7 @@ public class CreateShareTest extends RemoteTest {
	    setActivityInitialTouchMode(false);
	    mActivity = getActivity();
	    mFullPath2FileToShare = mBaseFolderPath + FILE_TO_SHARE;
	    mFullPath2NonExistentFile = mBaseFolderPath + NON_EXISTENT_FILE;
	    		
		File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
		RemoteOperationResult result = mActivity.uploadFile(
@@ -59,9 +67,11 @@ public class CreateShareTest extends RemoteTest {
	}

	/**
	 * 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
		);
		
	}