1
0
mirror of https://github.com/owncloud/android-library.git synced 2026-08-11 16:33:03 +00:00

Merge branch 'develop' into wide_scope_clean_up

This commit is contained in:
David A. Velasco
2014-02-17 12:48:05 +01:00
8 changed files with 310 additions and 7 deletions
@@ -37,7 +37,10 @@ import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation;
import com.owncloud.android.lib.resources.files.RemoveRemoteFileOperation;
import com.owncloud.android.lib.resources.files.RenameRemoteFileOperation;
import com.owncloud.android.lib.resources.files.UploadRemoteFileOperation;
import com.owncloud.android.lib.resources.shares.CreateRemoteShareOperation;
import com.owncloud.android.lib.resources.shares.GetRemoteSharesOperation;
import com.owncloud.android.lib.operations.remote.RemoveRemoteShareOperation;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.lib.test_project.R;
import android.net.Uri;
@@ -190,6 +193,11 @@ public class TestActivity extends Activity {
return result;
}
/** Access to the library method to Get Shares
*
* @return
*/
public RemoteOperationResult getShares(){
GetRemoteSharesOperation getOperation = new GetRemoteSharesOperation();
@@ -197,4 +205,47 @@ public class TestActivity extends Activity {
return result;
}
/** Access to the library method to Create Share
* @param path Full path of the file/folder being shared. Mandatory argument
* @param shareType 0 = user, 1 = group, 3 = Public link. Mandatory argument
* @param shareWith User/group ID with who the file should be shared. This is mandatory for shareType of 0 or 1
* @param publicUpload If false (default) public cannot upload to a public shared folder.
* If true public can upload to a shared folder. Only available for public link shares
* @param password Password to protect a public link share. Only available for public link shares
* @param permissions 1 - Read only Default for “public” shares
* 2 - Update
* 4 - Create
* 8 - Delete
* 16- Re-share
* 31- All above Default for “private” shares
* For user or group shares.
* To obtain combinations, add the desired values together.
* For instance, for “Re-Share”, “delete”, “read”, “update”, add 16+8+2+1 = 27.
*
* @return
*/
public RemoteOperationResult createShare(String path, ShareType shareType, String shareWith, boolean publicUpload,
String password, int permissions){
CreateRemoteShareOperation createOperation = new CreateRemoteShareOperation(path, shareType, shareWith, publicUpload, password, permissions);
RemoteOperationResult result = createOperation.execute(mClient);
return result;
}
/**
* Access to the library method to Remove Share
*
* @param idShare Share ID
*/
public RemoteOperationResult removeShare(int idShare) {
RemoveRemoteShareOperation removeOperation = new RemoveRemoteShareOperation(idShare);
RemoteOperationResult result = removeOperation.execute(mClient);
return result;
}
}
@@ -0,0 +1,59 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2014 ownCloud (http://www.owncloud.org/)
*
* 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 com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.lib.test_project.TestActivity;
import android.test.ActivityInstrumentationTestCase2;
public class CreateShareTest extends ActivityInstrumentationTestCase2<TestActivity> {
/* File to share.*/
private final String mFileToShare = "/fileToShare.png";
private TestActivity mActivity;
public CreateShareTest() {
super(TestActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
setActivityInitialTouchMode(false);
mActivity = getActivity();
}
/**
* Test Create Share: the server must support SHARE API
*/
public void testCreateShare() {
RemoteOperationResult result = mActivity.createShare(mFileToShare, ShareType.PUBLIC_LINK, "", false, "", 1);
assertTrue(result.isSuccess());
}
}
@@ -24,7 +24,7 @@
package com.owncloud.android.lib.test_project.test;
import com.owncloud.android.lib.operations.common.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.test_project.TestActivity;
import android.test.ActivityInstrumentationTestCase2;
@@ -0,0 +1,74 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2014 ownCloud (http://www.owncloud.org/)
*
* 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 com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.test_project.TestActivity;
import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;
public class RemoveShareTest extends ActivityInstrumentationTestCase2<TestActivity> {
private static final String TAG = RemoveShareTest.class.getSimpleName();
private TestActivity mActivity;
public RemoveShareTest() {
super(TestActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
setActivityInitialTouchMode(false);
mActivity = getActivity();
}
/**
* Test Remove Share: the server must support SHARE API
*/
public void testRemoveShare() {
// Get the shares
RemoteOperationResult result = mActivity.getShares();
if (result.isSuccess()) {
int size = result.getData().size();
if (size > 0) {
OCShare share = ((OCShare) result.getData().get(size -1));
long id = share.getIdRemoteShared();
Log.d(TAG, "File to unshare: " + share.getPath() );
result = mActivity.removeShare((int) id); // Unshare
assertTrue(result.isSuccess());
} else {
assertTrue(true);
}
} else {
assertTrue(true);
}
}
}