Loading src/com/owncloud/android/lib/resources/users/GetRemoteUserQuotaOperation.java→src/com/owncloud/android/lib/resources/users/RemoteGetUserQuotaOperation.java +48 −26 Original line number Diff line number Diff line package com.owncloud.android.lib.resources.users; /* ownCloud Android Library is available under MIT license * * Copyright (C) 2015 ownCloud Inc. * Copyright (C) 2015 Bartosz Przybylski * Copyright (C) 2014 Marcello Steiner * * 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. * */ import android.util.Base64; import android.util.Log; package com.owncloud.android.lib.resources.users; import com.owncloud.android.lib.common.OwnCloudBasicCredentials; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.OwnCloudCredentials; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.http.HttpStatus; import org.json.JSONObject; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.ArrayList; /** * Created by marcello on 11/11/14. * @author marcello */ public class GetRemoteUserQuotaOperation extends RemoteOperation { public class RemoteGetUserQuotaOperation extends RemoteOperation { private static final String TAG = GetRemoteUserNameOperation.class.getSimpleName(); static public class Quota { long mFree, mUsed, mTotal; double mRelative; public Quota(long free, long used, long total, double relative) { mFree = free; mUsed = used; mTotal = total; mRelative = relative; } public long getFree() { return mFree; } public long getUsed() { return mUsed; } public long getTotal() { return mTotal; } public double getRelative() { return mRelative; } } private static final String TAG = RemoteGetUserQuotaOperation.class.getSimpleName(); private static final String NODE_OCS = "ocs"; private static final String NODE_DATA = "data"; Loading @@ -43,7 +78,7 @@ public class GetRemoteUserQuotaOperation extends RemoteOperation { @Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = null; int status = -1; int status; GetMethod get = null; Loading @@ -53,7 +88,6 @@ public class GetRemoteUserQuotaOperation extends RemoteOperation { String url = client.getBaseUri() + OCS_ROUTE + credentials.getUsername(); get = new GetMethod(url); get.addRequestHeader(createAuthenticationHeader(credentials)); get.setQueryString(new NameValuePair[]{new NameValuePair("format","json")}); status = client.executeMethod(get); Loading @@ -75,10 +109,7 @@ public class GetRemoteUserQuotaOperation extends RemoteOperation { result = new RemoteOperationResult(true, status, get.getResponseHeaders()); //Quota data in data collection ArrayList<Object> data = new ArrayList<Object>(); data.add(quotaFree); data.add(quotaUsed); data.add(quotaTotal); data.add(quotaRelative); data.add(new Quota(quotaFree, quotaUsed, quotaTotal, quotaRelative)); result.setData(data); } else { Loading Loading @@ -106,14 +137,5 @@ public class GetRemoteUserQuotaOperation extends RemoteOperation { return (status == HttpStatus.SC_OK); } private Header createAuthenticationHeader(OwnCloudCredentials credentials){ Header h = new Header(); h.setName("Authorization"); String authString = credentials.getUsername()+":"+credentials.getAuthToken(); String encodedString = Base64.encodeToString(authString.getBytes(), Base64.NO_WRAP); h.setValue("Basic "+encodedString); return h; } } test_client/src/com/owncloud/android/lib/test_project/TestActivity.java +7 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.OwnCloudClientFactory; import com.owncloud.android.lib.common.OwnCloudCredentialsFactory; import com.owncloud.android.lib.common.network.NetworkUtils; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.resources.files.ChunkedUploadRemoteFileOperation; import com.owncloud.android.lib.resources.files.CreateRemoteFolderOperation; Loading @@ -48,6 +49,7 @@ import com.owncloud.android.lib.resources.shares.CreateRemoteShareOperation; import com.owncloud.android.lib.resources.shares.GetRemoteSharesOperation; import com.owncloud.android.lib.resources.shares.RemoveRemoteShareOperation; import com.owncloud.android.lib.resources.shares.ShareType; import com.owncloud.android.lib.resources.users.RemoteGetUserQuotaOperation; import org.apache.commons.httpclient.protocol.Protocol; import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; Loading Loading @@ -336,6 +338,11 @@ public class TestActivity extends Activity { } public RemoteOperationResult getQuota() { RemoteGetUserQuotaOperation getUserQuotaOperation = new RemoteGetUserQuotaOperation(); return getUserQuotaOperation.execute(mClient); } /** * Extracts file from AssetManager to cache folder. Loading test_client/tests/src/com/owncloud/android/lib/test_project/test/GetUserQuotaTest.java 0 → 100644 +81 −0 Original line number Diff line number Diff line /* ownCloud Android Library is available under MIT license * * Copyright (C) 2015 ownCloud Inc. * Copyright (C) 2015 Bartosz Przybylski * * 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 java.io.File; import java.util.*; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.lib.resources.users.RemoteGetUserQuotaOperation.Quota; import com.owncloud.android.lib.test_project.TestActivity; import com.owncloud.android.lib.resources.files.*; /** * Class to test Get User Quota * * @author Bartosz Przybylski * */ public class GetUserQuotaTest extends RemoteTest { private static final String LOG_TAG = GetUserQuotaTest.class.getCanonicalName(); /* Files to download. These files must exist on the account */ private static final String IMAGE_PATH = "/fileToDownload.png"; private static final String IMAGE_PATH_WITH_SPECIAL_CHARS = "/@file@download.png"; private static final String IMAGE_NOT_FOUND = "/fileNotFound.png"; private String mFullPath2Image; private String mFullPath2ImageWitSpecialChars; private String mFullPath2ImageNotFound; private String mDownloadedFilePath; private TestActivity mActivity; @Override protected void setUp() throws Exception { super.setUp(); setActivityInitialTouchMode(false); mActivity = getActivity(); } /** * Test GetUserQuota */ public void testGetUserQuota() { RemoteOperationResult result = mActivity.getQuota(); assertTrue(result.isSuccess()); Quota quota = (Quota)((ArrayList<Object>)result.getData()).get(0); assertTrue(quota.getFree() >= 0); assertTrue(quota.getUsed() >= 0); assertTrue(quota.getTotal() > 0); } } Loading
src/com/owncloud/android/lib/resources/users/GetRemoteUserQuotaOperation.java→src/com/owncloud/android/lib/resources/users/RemoteGetUserQuotaOperation.java +48 −26 Original line number Diff line number Diff line package com.owncloud.android.lib.resources.users; /* ownCloud Android Library is available under MIT license * * Copyright (C) 2015 ownCloud Inc. * Copyright (C) 2015 Bartosz Przybylski * Copyright (C) 2014 Marcello Steiner * * 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. * */ import android.util.Base64; import android.util.Log; package com.owncloud.android.lib.resources.users; import com.owncloud.android.lib.common.OwnCloudBasicCredentials; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.OwnCloudCredentials; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.http.HttpStatus; import org.json.JSONObject; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.ArrayList; /** * Created by marcello on 11/11/14. * @author marcello */ public class GetRemoteUserQuotaOperation extends RemoteOperation { public class RemoteGetUserQuotaOperation extends RemoteOperation { private static final String TAG = GetRemoteUserNameOperation.class.getSimpleName(); static public class Quota { long mFree, mUsed, mTotal; double mRelative; public Quota(long free, long used, long total, double relative) { mFree = free; mUsed = used; mTotal = total; mRelative = relative; } public long getFree() { return mFree; } public long getUsed() { return mUsed; } public long getTotal() { return mTotal; } public double getRelative() { return mRelative; } } private static final String TAG = RemoteGetUserQuotaOperation.class.getSimpleName(); private static final String NODE_OCS = "ocs"; private static final String NODE_DATA = "data"; Loading @@ -43,7 +78,7 @@ public class GetRemoteUserQuotaOperation extends RemoteOperation { @Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = null; int status = -1; int status; GetMethod get = null; Loading @@ -53,7 +88,6 @@ public class GetRemoteUserQuotaOperation extends RemoteOperation { String url = client.getBaseUri() + OCS_ROUTE + credentials.getUsername(); get = new GetMethod(url); get.addRequestHeader(createAuthenticationHeader(credentials)); get.setQueryString(new NameValuePair[]{new NameValuePair("format","json")}); status = client.executeMethod(get); Loading @@ -75,10 +109,7 @@ public class GetRemoteUserQuotaOperation extends RemoteOperation { result = new RemoteOperationResult(true, status, get.getResponseHeaders()); //Quota data in data collection ArrayList<Object> data = new ArrayList<Object>(); data.add(quotaFree); data.add(quotaUsed); data.add(quotaTotal); data.add(quotaRelative); data.add(new Quota(quotaFree, quotaUsed, quotaTotal, quotaRelative)); result.setData(data); } else { Loading Loading @@ -106,14 +137,5 @@ public class GetRemoteUserQuotaOperation extends RemoteOperation { return (status == HttpStatus.SC_OK); } private Header createAuthenticationHeader(OwnCloudCredentials credentials){ Header h = new Header(); h.setName("Authorization"); String authString = credentials.getUsername()+":"+credentials.getAuthToken(); String encodedString = Base64.encodeToString(authString.getBytes(), Base64.NO_WRAP); h.setValue("Basic "+encodedString); return h; } }
test_client/src/com/owncloud/android/lib/test_project/TestActivity.java +7 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.OwnCloudClientFactory; import com.owncloud.android.lib.common.OwnCloudCredentialsFactory; import com.owncloud.android.lib.common.network.NetworkUtils; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.resources.files.ChunkedUploadRemoteFileOperation; import com.owncloud.android.lib.resources.files.CreateRemoteFolderOperation; Loading @@ -48,6 +49,7 @@ import com.owncloud.android.lib.resources.shares.CreateRemoteShareOperation; import com.owncloud.android.lib.resources.shares.GetRemoteSharesOperation; import com.owncloud.android.lib.resources.shares.RemoveRemoteShareOperation; import com.owncloud.android.lib.resources.shares.ShareType; import com.owncloud.android.lib.resources.users.RemoteGetUserQuotaOperation; import org.apache.commons.httpclient.protocol.Protocol; import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; Loading Loading @@ -336,6 +338,11 @@ public class TestActivity extends Activity { } public RemoteOperationResult getQuota() { RemoteGetUserQuotaOperation getUserQuotaOperation = new RemoteGetUserQuotaOperation(); return getUserQuotaOperation.execute(mClient); } /** * Extracts file from AssetManager to cache folder. Loading
test_client/tests/src/com/owncloud/android/lib/test_project/test/GetUserQuotaTest.java 0 → 100644 +81 −0 Original line number Diff line number Diff line /* ownCloud Android Library is available under MIT license * * Copyright (C) 2015 ownCloud Inc. * Copyright (C) 2015 Bartosz Przybylski * * 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 java.io.File; import java.util.*; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.lib.resources.users.RemoteGetUserQuotaOperation.Quota; import com.owncloud.android.lib.test_project.TestActivity; import com.owncloud.android.lib.resources.files.*; /** * Class to test Get User Quota * * @author Bartosz Przybylski * */ public class GetUserQuotaTest extends RemoteTest { private static final String LOG_TAG = GetUserQuotaTest.class.getCanonicalName(); /* Files to download. These files must exist on the account */ private static final String IMAGE_PATH = "/fileToDownload.png"; private static final String IMAGE_PATH_WITH_SPECIAL_CHARS = "/@file@download.png"; private static final String IMAGE_NOT_FOUND = "/fileNotFound.png"; private String mFullPath2Image; private String mFullPath2ImageWitSpecialChars; private String mFullPath2ImageNotFound; private String mDownloadedFilePath; private TestActivity mActivity; @Override protected void setUp() throws Exception { super.setUp(); setActivityInitialTouchMode(false); mActivity = getActivity(); } /** * Test GetUserQuota */ public void testGetUserQuota() { RemoteOperationResult result = mActivity.getQuota(); assertTrue(result.isSuccess()); Quota quota = (Quota)((ArrayList<Object>)result.getData()).get(0); assertTrue(quota.getFree() >= 0); assertTrue(quota.getUsed() >= 0); assertTrue(quota.getTotal() > 0); } }