diff --git a/src/com/owncloud/android/lib/operations/common/RemoteOperationResult.java b/src/com/owncloud/android/lib/operations/common/RemoteOperationResult.java index ba5dd2c0..acd30590 100644 --- a/src/com/owncloud/android/lib/operations/common/RemoteOperationResult.java +++ b/src/com/owncloud/android/lib/operations/common/RemoteOperationResult.java @@ -97,7 +97,8 @@ public class RemoteOperationResult implements Serializable { ACCOUNT_EXCEPTION, ACCOUNT_NOT_NEW, ACCOUNT_NOT_THE_SAME, - INVALID_CHARACTER_IN_NAME + INVALID_CHARACTER_IN_NAME, + SHARE_NOT_FOUND } private boolean mSuccess = false; diff --git a/src/com/owncloud/android/lib/operations/remote/CreateShareRemoteOperation.java b/src/com/owncloud/android/lib/operations/remote/CreateShareRemoteOperation.java index 968ca71e..c5be688a 100644 --- a/src/com/owncloud/android/lib/operations/remote/CreateShareRemoteOperation.java +++ b/src/com/owncloud/android/lib/operations/remote/CreateShareRemoteOperation.java @@ -143,7 +143,7 @@ public class CreateShareRemoteOperation extends RemoteOperation { result.setData(sharesObjects); } } else if (xmlParser.isFileNotFound()){ - result = new RemoteOperationResult(ResultCode.FILE_NOT_FOUND); + result = new RemoteOperationResult(ResultCode.SHARE_NOT_FOUND); } else { result = new RemoteOperationResult(false, status, post.getResponseHeaders()); diff --git a/src/com/owncloud/android/lib/operations/remote/RemoveRemoteShareOperation.java b/src/com/owncloud/android/lib/operations/remote/RemoveRemoteShareOperation.java new file mode 100644 index 00000000..8f467ff4 --- /dev/null +++ b/src/com/owncloud/android/lib/operations/remote/RemoveRemoteShareOperation.java @@ -0,0 +1,118 @@ +/* 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.operations.remote; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; + +import org.apache.commons.httpclient.HttpStatus; +import org.apache.jackrabbit.webdav.client.methods.DeleteMethod; + +import android.util.Log; + +import com.owncloud.android.lib.network.OwnCloudClient; +import com.owncloud.android.lib.operations.common.RemoteOperation; +import com.owncloud.android.lib.operations.common.RemoteOperationResult; +import com.owncloud.android.lib.operations.common.RemoteOperationResult.ResultCode; +import com.owncloud.android.lib.utils.ShareUtils; +import com.owncloud.android.lib.utils.ShareXMLParser; + +/** + * Remove a share + * + * @author masensio + * + */ + +public class RemoveRemoteShareOperation extends RemoteOperation { + + private static final String TAG = RemoveRemoteShareOperation.class.getSimpleName(); + + private int mIdShare; + + /** + * Constructor + * + * @param idShare Share ID + */ + + public RemoveRemoteShareOperation(int idShare) { + mIdShare = idShare; + + } + + @Override + protected RemoteOperationResult run(OwnCloudClient client) { + RemoteOperationResult result = null; + int status = -1; + + DeleteMethod delete = null; + + try { + String id = "/" + String.valueOf(mIdShare); + delete = new DeleteMethod(client.getBaseUri() + ShareUtils.SHAREAPI_ROUTE + id); + Log.d(TAG, "URL ------> " + client.getBaseUri() + ShareUtils.SHAREAPI_ROUTE + id); + + status = client.executeMethod(delete); + + if(isSuccess(status)) { + String response = delete.getResponseBodyAsString(); + Log.d(TAG, "Successful response: " + response); + + result = new RemoteOperationResult(ResultCode.OK); + + // Parse xml response + // convert String into InputStream + InputStream is = new ByteArrayInputStream(response.getBytes()); + ShareXMLParser xmlParser = new ShareXMLParser(); + xmlParser.parseXMLResponse(is); + if (xmlParser.isSuccess()) { + result = new RemoteOperationResult(ResultCode.OK); + } else if (xmlParser.isFileNotFound()){ + result = new RemoteOperationResult(ResultCode.SHARE_NOT_FOUND); + } else { + result = new RemoteOperationResult(false, status, delete.getResponseHeaders()); + } + + Log.i(TAG, "Unshare " + id + ": " + result.getLogMessage()); + } else { + result = new RemoteOperationResult(false, status, delete.getResponseHeaders()); + } + } catch (Exception e) { + result = new RemoteOperationResult(e); + Log.e(TAG, "Unshare Link Exception " + result.getLogMessage(), e); + + } finally { + if (delete != null) + delete.releaseConnection(); + } + return result; + } + + + private boolean isSuccess(int status) { + return (status == HttpStatus.SC_OK); + } +} \ No newline at end of file diff --git a/src/com/owncloud/android/lib/utils/GetSharesForFileXMLParser.java b/src/com/owncloud/android/lib/utils/GetSharesForFileXMLParser.java deleted file mode 100644 index 25c46e15..00000000 --- a/src/com/owncloud/android/lib/utils/GetSharesForFileXMLParser.java +++ /dev/null @@ -1,353 +0,0 @@ -/* 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.utils; - -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; - -import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; -import org.xmlpull.v1.XmlPullParserFactory; - -import android.util.Log; -import android.util.Xml; - -import com.owncloud.android.lib.operations.common.OCShare; -import com.owncloud.android.lib.operations.common.ShareType; - -/** - * Parser for Share API Response: GetSharesForFile Operation - * @author masensio - * - */ -public class GetSharesForFileXMLParser { - - private static final String TAG = GetSharesForFileXMLParser.class.getSimpleName(); - - // No namespaces - private static final String ns = null; - - // NODES for XML Parser - private static final String NODE_OCS = "ocs"; - - private static final String NODE_META = "meta"; - private static final String NODE_STATUS = "status"; - private static final String NODE_STATUS_CODE = "statuscode"; - //private static final String NODE_MESSAGE = "message"; - - private static final String NODE_DATA = "data"; - private static final String NODE_ELEMENT = "element"; - private static final String NODE_ID = "id"; - private static final String NODE_ITEM_TYPE = "item_type"; - private static final String NODE_ITEM_SOURCE = "item_source"; - private static final String NODE_PARENT = "parent"; - private static final String NODE_SHARE_TYPE = "share_type"; - private static final String NODE_SHARE_WITH = "share_with"; - private static final String NODE_FILE_SOURCE = "file_source"; - private static final String NODE_PATH = "path"; - private static final String NODE_PERMISSIONS = "permissions"; - private static final String NODE_STIME = "stime"; - private static final String NODE_EXPIRATION = "expiration"; - private static final String NODE_TOKEN = "token"; - private static final String NODE_STORAGE = "storage"; - private static final String NODE_MAIL_SEND = "mail_send"; - private static final String NODE_SHARE_WITH_DISPLAY_NAME = "share_with_display_name"; - - - private static final String TYPE_FOLDER = "folder"; - - - private String mStatus; - private int mStatusCode; - - // Getters and Setters - public String getStatus() { - return mStatus; - } - - public void setStatus(String status) { - this.mStatus = status; - } - - public int getStatusCode() { - return mStatusCode; - } - - public void setStatusCode(int statusCode) { - this.mStatusCode = statusCode; - } - - // Constructor - public GetSharesForFileXMLParser() { - // TODO Auto-generated constructor stub - } - - /** - * Parse is as response of Share API - * @param is - * @return List of ShareRemoteFiles - * @throws XmlPullParserException - * @throws IOException - */ - public ArrayList parseXMLResponse(InputStream is) throws XmlPullParserException, IOException { - - try { - // XMLPullParser - XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); - factory.setNamespaceAware(true); - - XmlPullParser parser = Xml.newPullParser(); - parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false); - parser.setInput(is, null); - parser.nextTag(); - return readOCS(parser); - - } finally { - is.close(); - } - } - - /** - * Parse OCS node - * @param parser - * @return List of ShareRemoteFiles - * @throws XmlPullParserException - * @throws IOException - */ - private ArrayList readOCS (XmlPullParser parser) throws XmlPullParserException, IOException { - ArrayList shares = new ArrayList(); - parser.require(XmlPullParser.START_TAG, ns , NODE_OCS); - while (parser.next() != XmlPullParser.END_TAG) { - if (parser.getEventType() != XmlPullParser.START_TAG) { - continue; - } - String name = parser.getName(); - // read NODE_META and NODE_DATA - if (name.equalsIgnoreCase(NODE_META)) { - readMeta(parser); - } else if (name.equalsIgnoreCase(NODE_DATA)) { - shares = readData(parser); - } else { - skip(parser); - } - - } - return shares; - - } - - /** - * Parse Meta node - * @param parser - * @throws XmlPullParserException - * @throws IOException - */ - private void readMeta(XmlPullParser parser) throws XmlPullParserException, IOException { - parser.require(XmlPullParser.START_TAG, ns, NODE_META); - Log.d(TAG, "---- NODE META ---"); - while (parser.next() != XmlPullParser.END_TAG) { - if (parser.getEventType() != XmlPullParser.START_TAG) { - continue; - } - String name = parser.getName(); - - if (name.equalsIgnoreCase(NODE_STATUS)) { - setStatus(readNode(parser, NODE_STATUS)); - - } else if (name.equalsIgnoreCase(NODE_STATUS_CODE)) { - setStatusCode(Integer.parseInt(readNode(parser, NODE_STATUS_CODE))); - - } else { - skip(parser); - } - - } - } - - /** - * Parse Data node - * @param parser - * @return - * @throws XmlPullParserException - * @throws IOException - */ - private ArrayList readData(XmlPullParser parser) throws XmlPullParserException, IOException { - ArrayList shares = new ArrayList(); - - parser.require(XmlPullParser.START_TAG, ns, NODE_DATA); - Log.d(TAG, "---- NODE DATA ---"); - while (parser.next() != XmlPullParser.END_TAG) { - if (parser.getEventType() != XmlPullParser.START_TAG) { - continue; - } - String name = parser.getName(); - if (name.equalsIgnoreCase(NODE_ELEMENT)) { - shares.add(readElement(parser)); - } else { - skip(parser); - - } - } - - return shares; - - } - - - /** - * Parse Element node - * @param parser - * @return - * @throws XmlPullParserException - * @throws IOException - */ - private OCShare readElement(XmlPullParser parser) throws XmlPullParserException, IOException { - parser.require(XmlPullParser.START_TAG, ns, NODE_ELEMENT); - - OCShare share = new OCShare(); - - Log.d(TAG, "---- NODE ELEMENT ---"); - while (parser.next() != XmlPullParser.END_TAG) { - if (parser.getEventType() != XmlPullParser.START_TAG) { - continue; - } - - String name = parser.getName(); - - if (name.equalsIgnoreCase(NODE_ELEMENT)) { - share = readElement(parser); - - } else if (name.equalsIgnoreCase(NODE_ID)) { - share.setIdRemoteShared(Integer.parseInt(readNode(parser, NODE_ID))); - - } else if (name.equalsIgnoreCase(NODE_ITEM_TYPE)) { - share.setIsFolder(readNode(parser, NODE_ITEM_TYPE).equalsIgnoreCase(TYPE_FOLDER)); - - } else if (name.equalsIgnoreCase(NODE_ITEM_SOURCE)) { - share.setItemSource(Long.parseLong(readNode(parser, NODE_ITEM_SOURCE))); - - } else if (name.equalsIgnoreCase(NODE_PARENT)) { - readNode(parser, NODE_PARENT); - - } else if (name.equalsIgnoreCase(NODE_SHARE_TYPE)) { - int value = Integer.parseInt(readNode(parser, NODE_SHARE_TYPE)); - share.setShareType(ShareType.fromValue(value)); - - } else if (name.equalsIgnoreCase(NODE_SHARE_WITH)) { - share.setShareWith(readNode(parser, NODE_SHARE_WITH)); - - } else if (name.equalsIgnoreCase(NODE_FILE_SOURCE)) { - share.setFileSource(Long.parseLong(readNode(parser, NODE_FILE_SOURCE))); - - } else if (name.equalsIgnoreCase(NODE_PATH)) { - share.setPath(readNode(parser, NODE_PATH)); - - } else if (name.equalsIgnoreCase(NODE_PERMISSIONS)) { - share.setPermissions(Integer.parseInt(readNode(parser, NODE_PERMISSIONS))); - - } else if (name.equalsIgnoreCase(NODE_STIME)) { - share.setSharedDate(Long.parseLong(readNode(parser, NODE_STIME))); - - } else if (name.equalsIgnoreCase(NODE_EXPIRATION)) { - String value = readNode(parser, NODE_EXPIRATION); - if (!value.isEmpty()) { - share.setExpirationDate(Long.parseLong(readNode(parser, NODE_EXPIRATION))); // check if expiration is in long format or date format - } - - } else if (name.equalsIgnoreCase(NODE_TOKEN)) { - share.setToken(readNode(parser, NODE_TOKEN)); - - } else if (name.equalsIgnoreCase(NODE_STORAGE)) { - readNode(parser, NODE_STORAGE); - } else if (name.equalsIgnoreCase(NODE_MAIL_SEND)) { - readNode(parser, NODE_MAIL_SEND); - - } else if (name.equalsIgnoreCase(NODE_SHARE_WITH_DISPLAY_NAME)) { - share.setSharedWithDisplayName(readNode(parser, NODE_SHARE_WITH_DISPLAY_NAME)); - - } else { - skip(parser); - } - } - - return share; - } - - /** - * Parse a node, to obtain its text. Needs readText method - * @param parser - * @param node - * @return Text of the node - * @throws XmlPullParserException - * @throws IOException - */ - private String readNode (XmlPullParser parser, String node) throws XmlPullParserException, IOException{ - parser.require(XmlPullParser.START_TAG, ns, node); - String value = readText(parser); - Log.d(TAG, "node= " + node + ", value= " + value); - parser.require(XmlPullParser.END_TAG, ns, node); - return value; - } - - /** - * Read the text from a node - * @param parser - * @return Text of the node - * @throws IOException - * @throws XmlPullParserException - */ - private String readText(XmlPullParser parser) throws IOException, XmlPullParserException { - String result = ""; - if (parser.next() == XmlPullParser.TEXT) { - result = parser.getText(); - parser.nextTag(); - } - return result; - } - - /** - * Skip tags in parser procedure - * @param parser - * @throws XmlPullParserException - * @throws IOException - */ - private void skip(XmlPullParser parser) throws XmlPullParserException, IOException { - if (parser.getEventType() != XmlPullParser.START_TAG) { - throw new IllegalStateException(); - } - int depth = 1; - while (depth != 0) { - switch (parser.next()) { - case XmlPullParser.END_TAG: - depth--; - break; - case XmlPullParser.START_TAG: - depth++; - break; - } - } - } -} diff --git a/tests/res/values/setup.xml b/tests/res/values/setup.xml new file mode 100644 index 00000000..4839b1bc --- /dev/null +++ b/tests/res/values/setup.xml @@ -0,0 +1,32 @@ + + + + + + /remote.php/webdav + + + true + diff --git a/tests/src/com/owncloud/android/lib/test_project/TestActivity.java b/tests/src/com/owncloud/android/lib/test_project/TestActivity.java index d6caf3c6..39d16036 100644 --- a/tests/src/com/owncloud/android/lib/test_project/TestActivity.java +++ b/tests/src/com/owncloud/android/lib/test_project/TestActivity.java @@ -1,17 +1,24 @@ -/* ownCloud Android client application - * Copyright (C) 2012-2013 ownCloud Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . +/* 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. * */ @@ -23,13 +30,17 @@ import com.owncloud.android.lib.network.OwnCloudClientFactory; import com.owncloud.android.lib.network.OwnCloudClient; import com.owncloud.android.lib.operations.common.RemoteFile; import com.owncloud.android.lib.operations.common.RemoteOperationResult; +import com.owncloud.android.lib.operations.common.ShareType; import com.owncloud.android.lib.operations.remote.ChunkedUploadRemoteFileOperation; import com.owncloud.android.lib.operations.remote.CreateRemoteFolderOperation; +import com.owncloud.android.lib.operations.remote.CreateShareRemoteOperation; import com.owncloud.android.lib.operations.remote.DownloadRemoteFileOperation; +import com.owncloud.android.lib.operations.remote.GetRemoteSharesOperation; import com.owncloud.android.lib.operations.remote.ReadRemoteFolderOperation; import com.owncloud.android.lib.operations.remote.RemoveRemoteFileOperation; import com.owncloud.android.lib.operations.remote.RenameRemoteFileOperation; import com.owncloud.android.lib.operations.remote.UploadRemoteFileOperation; +import com.owncloud.android.lib.operations.remote.RemoveRemoteShareOperation; import com.owncloud.android.lib.test_project.R; import android.net.Uri; @@ -46,11 +57,12 @@ import android.view.Menu; public class TestActivity extends Activity { - // This account must exists on the simulator / device - private static final String mServerUri = "https://beta.owncloud.com/owncloud/remote.php/webdav"; - private static final String mUser = "testandroid"; - private static final String mPass = "testandroid"; - private static final boolean mChunked = true; + // This account must exists on the server side + private String mServerUri; + private String mWebdavPath; + private String mUser; + private String mPass; + private boolean mChunked; //private Account mAccount = null; private OwnCloudClient mClient; @@ -59,9 +71,18 @@ public class TestActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_test); - Uri uri = Uri.parse(mServerUri); + + mServerUri = getString(R.string.server_base_url); + mWebdavPath = getString(R.string.webdav_path); + mUser = getString(R.string.username); + mPass = getString(R.string.password); + mChunked = getResources().getBoolean(R.bool.chunked); + + Uri uri = Uri.parse(mServerUri + mWebdavPath); mClient = OwnCloudClientFactory.createOwnCloudClient(uri ,getApplicationContext(), true); mClient.setBasicCredentials(mUser, mPass); + mClient.setBaseUri(Uri.parse(mServerUri)); + } @Override @@ -171,4 +192,60 @@ public class TestActivity extends Activity { return result; } + + + /** Access to the library method to Get Shares + * + * @return + */ + public RemoteOperationResult getShares(){ + + GetRemoteSharesOperation getOperation = new GetRemoteSharesOperation(); + RemoteOperationResult result = getOperation.execute(mClient); + + 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){ + + CreateShareRemoteOperation createOperation = new CreateShareRemoteOperation(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; + + } } diff --git a/tests/test_cases/src/com/owncloud/android/lib/test_project/test/CreateShareTest.java b/tests/test_cases/src/com/owncloud/android/lib/test_project/test/CreateShareTest.java new file mode 100644 index 00000000..b9e89f0e --- /dev/null +++ b/tests/test_cases/src/com/owncloud/android/lib/test_project/test/CreateShareTest.java @@ -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.operations.common.RemoteOperationResult; +import com.owncloud.android.lib.operations.common.ShareType; +import com.owncloud.android.lib.test_project.TestActivity; + +import android.test.ActivityInstrumentationTestCase2; + +public class CreateShareTest extends ActivityInstrumentationTestCase2 { + + /* 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()); + } +} diff --git a/tests/test_cases/src/com/owncloud/android/lib/test_project/test/DownloadFileTest.java b/tests/test_cases/src/com/owncloud/android/lib/test_project/test/DownloadFileTest.java index 2eb523a2..904360ab 100644 --- a/tests/test_cases/src/com/owncloud/android/lib/test_project/test/DownloadFileTest.java +++ b/tests/test_cases/src/com/owncloud/android/lib/test_project/test/DownloadFileTest.java @@ -127,4 +127,6 @@ public class DownloadFileTest extends ActivityInstrumentationTestCase2 { + + private TestActivity mActivity; + + public GetSharesTest() { + super(TestActivity.class); + + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + setActivityInitialTouchMode(false); + mActivity = getActivity(); + } + + /** + * Test Get Shares: the server must support SHARE API + */ + public void testGetShares() { + RemoteOperationResult result = mActivity.getShares(); + assertTrue(result.isSuccess()); + } +} diff --git a/tests/test_cases/src/com/owncloud/android/lib/test_project/test/RemoveShareTest.java b/tests/test_cases/src/com/owncloud/android/lib/test_project/test/RemoveShareTest.java new file mode 100644 index 00000000..ac7db165 --- /dev/null +++ b/tests/test_cases/src/com/owncloud/android/lib/test_project/test/RemoveShareTest.java @@ -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.operations.common.OCShare; +import com.owncloud.android.lib.operations.common.RemoteOperationResult; +import com.owncloud.android.lib.test_project.TestActivity; + +import android.test.ActivityInstrumentationTestCase2; +import android.util.Log; + +public class RemoveShareTest extends ActivityInstrumentationTestCase2 { + + 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); + } + } +}