From: masensio Date: Mon, 18 Nov 2013 13:20:30 +0000 (+0100) Subject: Change from PR comments. Creation of WebDavClient with AsynTask in UnitTest X-Git-Tag: oc-android-1.5.5~126^2^2 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/eec99ea7d8c5ba0dafa5d4e8ff0ee68374344bc8 Change from PR comments. Creation of WebDavClient with AsynTask in UnitTest --- diff --git a/oc_framework-test-project/src/com/owncloud/android/oc_framework_test_project/TestActivity.java b/oc_framework-test-project/src/com/owncloud/android/oc_framework_test_project/TestActivity.java index 082557de..e1c1edcb 100644 --- a/oc_framework-test-project/src/com/owncloud/android/oc_framework_test_project/TestActivity.java +++ b/oc_framework-test-project/src/com/owncloud/android/oc_framework_test_project/TestActivity.java @@ -8,12 +8,14 @@ import com.owncloud.android.oc_framework.network.webdav.WebdavClient; import com.owncloud.android.oc_framework.operations.RemoteOperationResult; import com.owncloud.android.oc_framework.operations.remote.CreateRemoteFolderOperation; +import android.os.AsyncTask; import android.os.Bundle; import android.accounts.Account; import android.accounts.AccountManager; import android.accounts.AuthenticatorException; import android.accounts.OperationCanceledException; import android.app.Activity; +import android.content.Context; import android.util.Log; import android.view.Menu; @@ -51,32 +53,10 @@ public class TestActivity extends Activity { } } -// if (mAccount == null) { -// mAccount = new Account(accountName, accountType); -// am.addAccountExplicitly(mAccount, accountPass, null); -// am.setUserData(mAccount, "oc_version", "5.0.14"); -// am.setUserData(mAccount, "oc_base_url", "http://beta.owncloud.com/owncloud"); -// } else { - Log.d(TAG, "oc_version --->"+ am.getUserData(mAccount, "oc_version") ); - Log.d(TAG, "oc_base_url --->"+ am.getUserData(mAccount, "oc_base_url") ); -// } - + // Get the WebDavClient + AuthTask task = new AuthTask(); + task.execute(this.getApplicationContext()); - try { - mClient = OwnCloudClientFactory.createOwnCloudClient(mAccount, this.getApplicationContext()); - } catch (OperationCanceledException e) { - Log.e(TAG, "Error while trying to access to " + mAccount.name, e); - e.printStackTrace(); - } catch (AuthenticatorException e) { - Log.e(TAG, "Error while trying to access to " + mAccount.name, e); - e.printStackTrace(); - } catch (AccountNotFoundException e) { - Log.e(TAG, "Error while trying to access to " + mAccount.name, e); - e.printStackTrace(); - } catch (IOException e) { - Log.e(TAG, "Error while trying to access to " + mAccount.name, e); - e.printStackTrace(); - } } @Override @@ -99,4 +79,39 @@ public class TestActivity extends Activity { return result; } + + private class AuthTask extends AsyncTask { + + @Override + protected WebdavClient doInBackground(Context... params) { + WebdavClient client = null; + try { + client = OwnCloudClientFactory.createOwnCloudClient(mAccount, (Context) params[0] ); + } catch (OperationCanceledException e) { + Log.e(TAG, "Error while trying to access to " + mAccount.name, e); + e.printStackTrace(); + } catch (AuthenticatorException e) { + Log.e(TAG, "Error while trying to access to " + mAccount.name, e); + e.printStackTrace(); + } catch (AccountNotFoundException e) { + Log.e(TAG, "Error while trying to access to " + mAccount.name, e); + e.printStackTrace(); + } catch (IOException e) { + Log.e(TAG, "Error while trying to access to " + mAccount.name, e); + e.printStackTrace(); + } catch (IllegalStateException e) { + Log.e(TAG, "Error while trying to access to " + mAccount.name, e); + e.printStackTrace(); + } + return client; + } + + @Override + protected void onPostExecute(WebdavClient result) { + // TODO Auto-generated method stub + super.onPostExecute(result); + mClient = result; + } + + } } diff --git a/oc_framework/src/com/owncloud/android/oc_framework/network/webdav/OwnCloudClientFactory.java b/oc_framework/src/com/owncloud/android/oc_framework/network/webdav/OwnCloudClientFactory.java index 0c0c2072..5c41edb0 100644 --- a/oc_framework/src/com/owncloud/android/oc_framework/network/webdav/OwnCloudClientFactory.java +++ b/oc_framework/src/com/owncloud/android/oc_framework/network/webdav/OwnCloudClientFactory.java @@ -78,8 +78,8 @@ public class OwnCloudClientFactory { } else { String username = account.name.substring(0, account.name.lastIndexOf('@')); - String password = am.getPassword(account); - //String password = am.blockingGetAuthToken(account, AccountTypeUtils.getAuthTokenTypePass(account.type), false); + //String password = am.getPassword(account); + String password = am.blockingGetAuthToken(account, AccountTypeUtils.getAuthTokenTypePass(account.type), false); client.setBasicCredentials(username, password); }