From 5c48817712be36262002605c25abd0b41d02fb80 Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Mon, 2 Nov 2015 14:59:01 +0100 Subject: [PATCH] Update unit tests with cases for creating private shares --- .../test_project/test/CreateShareTest.java | 151 +++++++++++++++++- 1 file changed, 148 insertions(+), 3 deletions(-) diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/CreateShareTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/CreateShareTest.java index 782c06d8..8d08dd81 100644 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/CreateShareTest.java +++ b/test_client/tests/src/com/owncloud/android/lib/test_project/test/CreateShareTest.java @@ -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 + ); + }