1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-07 16:06:08 +00:00

Fix unit test

This commit is contained in:
masensio 2015-03-20 14:42:32 +01:00
parent 87582c4a8e
commit 43f6fe93e6
9 changed files with 95 additions and 52 deletions

View File

@ -27,4 +27,5 @@
<string name="server_base_url"></string> <string name="server_base_url"></string>
<string name="username"></string> <string name="username"></string>
<string name="password"></string> <string name="password"></string>
<string name ="user_agent">Android-ownCloud</string>
</resources> </resources>

View File

@ -79,7 +79,8 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
mHandler = new Handler(); mHandler = new Handler();
Uri serverUri = Uri.parse(getString(R.string.server_base_url)); Uri serverUri = Uri.parse(getString(R.string.server_base_url));
mClient = OwnCloudClientFactory.createOwnCloudClient(serverUri, this, true); mClient = OwnCloudClientFactory.createOwnCloudClient(serverUri, this, true,
getString(R.string.user_agent));
mClient.setCredentials( mClient.setCredentials(
OwnCloudCredentialsFactory.newBasicCredentials( OwnCloudCredentialsFactory.newBasicCredentials(
getString(R.string.username), getString(R.string.username),
@ -149,7 +150,7 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
private void startRefresh() { private void startRefresh() {
ReadRemoteFolderOperation refreshOperation = new ReadRemoteFolderOperation(FileUtils.PATH_SEPARATOR); ReadRemoteFolderOperation refreshOperation = new ReadRemoteFolderOperation(FileUtils.PATH_SEPARATOR);
refreshOperation.execute(mClient, this, mHandler); refreshOperation.execute(mClient, getString(R.string.user_agent), this, mHandler);
} }
private void startUpload() { private void startUpload() {
@ -159,7 +160,7 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
String mimeType = getString(R.string.sample_file_mimetype); String mimeType = getString(R.string.sample_file_mimetype);
UploadRemoteFileOperation uploadOperation = new UploadRemoteFileOperation(fileToUpload.getAbsolutePath(), remotePath, mimeType); UploadRemoteFileOperation uploadOperation = new UploadRemoteFileOperation(fileToUpload.getAbsolutePath(), remotePath, mimeType);
uploadOperation.addDatatransferProgressListener(this); uploadOperation.addDatatransferProgressListener(this);
uploadOperation.execute(mClient, this, mHandler); uploadOperation.execute(mClient, getString(R.string.user_agent), this, mHandler);
} }
private void startRemoteDeletion() { private void startRemoteDeletion() {
@ -167,7 +168,7 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
File fileToUpload = upFolder.listFiles()[0]; File fileToUpload = upFolder.listFiles()[0];
String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName(); String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName();
RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath); RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath);
removeOperation.execute(mClient, this, mHandler); removeOperation.execute(mClient, getString(R.string.user_agent), this, mHandler);
} }
private void startDownload() { private void startDownload() {
@ -178,7 +179,7 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName(); String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName();
DownloadRemoteFileOperation downloadOperation = new DownloadRemoteFileOperation(remotePath, downFolder.getAbsolutePath()); DownloadRemoteFileOperation downloadOperation = new DownloadRemoteFileOperation(remotePath, downFolder.getAbsolutePath());
downloadOperation.addDatatransferProgressListener(this); downloadOperation.addDatatransferProgressListener(this);
downloadOperation.execute(mClient, this, mHandler); downloadOperation.execute(mClient, getString(R.string.user_agent), this, mHandler);
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")

View File

@ -28,4 +28,5 @@
<string name="server_base_url"></string> <string name="server_base_url"></string>
<string name="username"></string> <string name="username"></string>
<string name="password"></string> <string name="password"></string>
<string name ="user_agent">Android-ownCloud</string>
</resources> </resources>

View File

@ -72,6 +72,7 @@ public class TestActivity extends Activity {
private String mServerUri; private String mServerUri;
private String mUser; private String mUser;
private String mPass; private String mPass;
private static String mUserAgent;
private static final int BUFFER_SIZE = 1024; private static final int BUFFER_SIZE = 1024;
@ -90,6 +91,7 @@ public class TestActivity extends Activity {
mServerUri = getString(R.string.server_base_url); mServerUri = getString(R.string.server_base_url);
mUser = getString(R.string.username); mUser = getString(R.string.username);
mPass = getString(R.string.password); mPass = getString(R.string.password);
mUserAgent = getString(R.string.user_agent);
Protocol pr = Protocol.getProtocol("https"); Protocol pr = Protocol.getProtocol("https");
if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) { if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) {
@ -104,7 +106,8 @@ public class TestActivity extends Activity {
} }
} }
mClient = new OwnCloudClient(Uri.parse(mServerUri), NetworkUtils.getMultiThreadedConnManager()); mClient = new OwnCloudClient(Uri.parse(mServerUri), NetworkUtils.getMultiThreadedConnManager(),
mUserAgent);
mClient.setDefaultTimeouts( mClient.setDefaultTimeouts(
OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT, OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT,
OwnCloudClientFactory.DEFAULT_CONNECTION_TIMEOUT); OwnCloudClientFactory.DEFAULT_CONNECTION_TIMEOUT);
@ -156,7 +159,7 @@ public class TestActivity extends Activity {
CreateRemoteFolderOperation createOperation = CreateRemoteFolderOperation createOperation =
new CreateRemoteFolderOperation(remotePath, createFullPath); new CreateRemoteFolderOperation(remotePath, createFullPath);
RemoteOperationResult result = createOperation.execute(client); RemoteOperationResult result = createOperation.execute(client, mUserAgent);
return result; return result;
} }
@ -174,7 +177,7 @@ public class TestActivity extends Activity {
public RemoteOperationResult renameFile(String oldName, String oldRemotePath, String newName, boolean isFolder) { public RemoteOperationResult renameFile(String oldName, String oldRemotePath, String newName, boolean isFolder) {
RenameRemoteFileOperation renameOperation = new RenameRemoteFileOperation(oldName, oldRemotePath, newName, isFolder); RenameRemoteFileOperation renameOperation = new RenameRemoteFileOperation(oldName, oldRemotePath, newName, isFolder);
RemoteOperationResult result = renameOperation.execute(mClient); RemoteOperationResult result = renameOperation.execute(mClient, mUserAgent);
return result; return result;
} }
@ -187,7 +190,7 @@ public class TestActivity extends Activity {
*/ */
public RemoteOperationResult removeFile(String remotePath) { public RemoteOperationResult removeFile(String remotePath) {
RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath); RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath);
RemoteOperationResult result = removeOperation.execute(mClient); RemoteOperationResult result = removeOperation.execute(mClient, mUserAgent);
return result; return result;
} }
@ -199,7 +202,7 @@ public class TestActivity extends Activity {
*/ */
public static RemoteOperationResult removeFile(String remotePath, OwnCloudClient client) { public static RemoteOperationResult removeFile(String remotePath, OwnCloudClient client) {
RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath); RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath);
RemoteOperationResult result = removeOperation.execute(client); RemoteOperationResult result = removeOperation.execute(client, mUserAgent);
return result; return result;
} }
@ -213,7 +216,7 @@ public class TestActivity extends Activity {
public RemoteOperationResult readFile(String remotePath) { public RemoteOperationResult readFile(String remotePath) {
ReadRemoteFolderOperation readOperation= new ReadRemoteFolderOperation(remotePath); ReadRemoteFolderOperation readOperation= new ReadRemoteFolderOperation(remotePath);
RemoteOperationResult result = readOperation.execute(mClient); RemoteOperationResult result = readOperation.execute(mClient, mUserAgent);
return result; return result;
} }
@ -232,7 +235,7 @@ public class TestActivity extends Activity {
folder.mkdirs(); folder.mkdirs();
DownloadRemoteFileOperation downloadOperation = new DownloadRemoteFileOperation(remoteFile.getRemotePath(), folder.getAbsolutePath()); DownloadRemoteFileOperation downloadOperation = new DownloadRemoteFileOperation(remoteFile.getRemotePath(), folder.getAbsolutePath());
RemoteOperationResult result = downloadOperation.execute(mClient); RemoteOperationResult result = downloadOperation.execute(mClient, mUserAgent);
return result; return result;
} }
@ -273,7 +276,7 @@ public class TestActivity extends Activity {
); );
} }
RemoteOperationResult result = uploadOperation.execute(client); RemoteOperationResult result = uploadOperation.execute(client, mUserAgent);
return result; return result;
} }
@ -284,7 +287,7 @@ public class TestActivity extends Activity {
public RemoteOperationResult getShares(){ public RemoteOperationResult getShares(){
GetRemoteSharesOperation getOperation = new GetRemoteSharesOperation(); GetRemoteSharesOperation getOperation = new GetRemoteSharesOperation();
RemoteOperationResult result = getOperation.execute(mClient); RemoteOperationResult result = getOperation.execute(mClient, mUserAgent);
return result; return result;
} }
@ -312,7 +315,7 @@ public class TestActivity extends Activity {
String password, int permissions){ String password, int permissions){
CreateRemoteShareOperation createOperation = new CreateRemoteShareOperation(path, shareType, shareWith, publicUpload, password, permissions); CreateRemoteShareOperation createOperation = new CreateRemoteShareOperation(path, shareType, shareWith, publicUpload, password, permissions);
RemoteOperationResult result = createOperation.execute(mClient); RemoteOperationResult result = createOperation.execute(mClient, mUserAgent);
return result; return result;
} }
@ -326,7 +329,7 @@ public class TestActivity extends Activity {
public RemoteOperationResult removeShare(int idShare) { public RemoteOperationResult removeShare(int idShare) {
RemoveRemoteShareOperation removeOperation = new RemoveRemoteShareOperation(idShare); RemoveRemoteShareOperation removeOperation = new RemoveRemoteShareOperation(idShare);
RemoteOperationResult result = removeOperation.execute(mClient); RemoteOperationResult result = removeOperation.execute(mClient, mUserAgent);
return result; return result;

View File

@ -26,5 +26,6 @@
<resources> <resources>
<string name="app_name">Oc_framework-testTest</string> <string name="app_name">Oc_framework-testTest</string>
<string name ="user_agent">Android-ownCloud</string>
</resources> </resources>

View File

@ -279,7 +279,8 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + TARGET_PATH_TO_FILE_1, mBaseFolderPath + TARGET_PATH_TO_FILE_1,
false false
); );
RemoteOperationResult result = moveOperation.execute(mClient); RemoteOperationResult result = moveOperation.execute(mClient,
getContext().getString(R.string.user_agent));
assertTrue(result.isSuccess()); assertTrue(result.isSuccess());
// move & rename file, different location // move & rename file, different location
@ -288,7 +289,8 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + TARGET_PATH_TO_FILE_2_RENAMED, mBaseFolderPath + TARGET_PATH_TO_FILE_2_RENAMED,
false false
); );
result = moveOperation.execute(mClient); result = moveOperation.execute(mClient,
getContext().getString(R.string.user_agent));
assertTrue(result.isSuccess()); assertTrue(result.isSuccess());
// move & rename file, same location (rename file) // move & rename file, same location (rename file)
@ -297,7 +299,8 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + SRC_PATH_TO_FILE_3_RENAMED, mBaseFolderPath + SRC_PATH_TO_FILE_3_RENAMED,
false false
); );
result = moveOperation.execute(mClient); result = moveOperation.execute(mClient,
getContext().getString(R.string.user_agent));
assertTrue(result.isSuccess()); assertTrue(result.isSuccess());
// move empty folder // move empty folder
@ -306,7 +309,8 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + TARGET_PATH_TO_EMPTY_FOLDER, mBaseFolderPath + TARGET_PATH_TO_EMPTY_FOLDER,
false false
); );
result = moveOperation.execute(mClient); result = moveOperation.execute(mClient,
getContext().getString(R.string.user_agent));
assertTrue(result.isSuccess()); assertTrue(result.isSuccess());
// move non-empty folder // move non-empty folder
@ -315,7 +319,8 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + TARGET_PATH_TO_FULL_FOLDER_1, mBaseFolderPath + TARGET_PATH_TO_FULL_FOLDER_1,
false false
); );
result = moveOperation.execute(mClient); result = moveOperation.execute(mClient,
getContext().getString(R.string.user_agent));
assertTrue(result.isSuccess()); assertTrue(result.isSuccess());
// move & rename folder, different location // move & rename folder, different location
@ -324,7 +329,8 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + TARGET_PATH_TO_FULL_FOLDER_2_RENAMED, mBaseFolderPath + TARGET_PATH_TO_FULL_FOLDER_2_RENAMED,
false false
); );
result = moveOperation.execute(mClient); result = moveOperation.execute(mClient,
getContext().getString(R.string.user_agent));
assertTrue(result.isSuccess()); assertTrue(result.isSuccess());
// move & rename folder, same location (rename folder) // move & rename folder, same location (rename folder)
@ -333,7 +339,8 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_3_RENAMED, mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_3_RENAMED,
false false
); );
result = moveOperation.execute(mClient); result = moveOperation.execute(mClient,
getContext().getString(R.string.user_agent));
assertTrue(result.isSuccess()); assertTrue(result.isSuccess());
// move for nothing (success, but no interaction with network) // move for nothing (success, but no interaction with network)
@ -342,7 +349,8 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + SRC_PATH_TO_FILE_4, mBaseFolderPath + SRC_PATH_TO_FILE_4,
false false
); );
result = moveOperation.execute(mClient); result = moveOperation.execute(mClient,
getContext().getString(R.string.user_agent));
assertTrue(result.isSuccess()); assertTrue(result.isSuccess());
// move overwriting // move overwriting
@ -351,7 +359,8 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4, mBaseFolderPath + TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4,
true true
); );
result = moveOperation.execute(mClient); result = moveOperation.execute(mClient,
getContext().getString(R.string.user_agent));
assertTrue(result.isSuccess()); assertTrue(result.isSuccess());
@ -363,7 +372,8 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + TARGET_PATH_TO_NON_EXISTENT_FILE, mBaseFolderPath + TARGET_PATH_TO_NON_EXISTENT_FILE,
false false
); );
result = moveOperation.execute(mClient); result = moveOperation.execute(mClient,
getContext().getString(R.string.user_agent));
assertTrue(result.getCode() == ResultCode.FILE_NOT_FOUND); assertTrue(result.getCode() == ResultCode.FILE_NOT_FOUND);
// folder to move into does no exist // folder to move into does no exist
@ -372,7 +382,8 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + TARGET_PATH_TO_FILE_5_INTO_NON_EXISTENT_FOLDER, mBaseFolderPath + TARGET_PATH_TO_FILE_5_INTO_NON_EXISTENT_FOLDER,
false false
); );
result = moveOperation.execute(mClient); result = moveOperation.execute(mClient,
getContext().getString(R.string.user_agent));
assertTrue(result.getHttpCode() == HttpStatus.SC_CONFLICT); assertTrue(result.getHttpCode() == HttpStatus.SC_CONFLICT);
// target location (renaming) has invalid characters // target location (renaming) has invalid characters
@ -381,7 +392,8 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + TARGET_PATH_RENAMED_WITH_INVALID_CHARS, mBaseFolderPath + TARGET_PATH_RENAMED_WITH_INVALID_CHARS,
false false
); );
result = moveOperation.execute(mClient); result = moveOperation.execute(mClient,
getContext().getString(R.string.user_agent));
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
// name collision // name collision
@ -390,7 +402,8 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7, mBaseFolderPath + TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7,
false false
); );
result = moveOperation.execute(mClient); result = moveOperation.execute(mClient,
getContext().getString(R.string.user_agent));
assertTrue(result.getCode() == ResultCode.INVALID_OVERWRITE); assertTrue(result.getCode() == ResultCode.INVALID_OVERWRITE);
// move a folder into a descendant // move a folder into a descendant
@ -399,7 +412,8 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + SRC_PATH_TO_EMPTY_FOLDER, mBaseFolderPath + SRC_PATH_TO_EMPTY_FOLDER,
false false
); );
result = moveOperation.execute(mClient); result = moveOperation.execute(mClient,
getContext().getString(R.string.user_agent));
assertTrue(result.getCode() == ResultCode.INVALID_MOVE_INTO_DESCENDANT); assertTrue(result.getCode() == ResultCode.INVALID_MOVE_INTO_DESCENDANT);
} }
@ -436,7 +450,8 @@ public class MoveFileTest extends RemoteTest {
mClient = new OwnCloudClient( mClient = new OwnCloudClient(
Uri.parse(mServerUri), Uri.parse(mServerUri),
NetworkUtils.getMultiThreadedConnManager() NetworkUtils.getMultiThreadedConnManager(),
getContext().getString(R.string.user_agent)
); );
mClient.setDefaultTimeouts( mClient.setDefaultTimeouts(
OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT, OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT,

View File

@ -64,6 +64,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
private Uri mServerUri; private Uri mServerUri;
private String mUsername; private String mUsername;
private String mPassword; private String mPassword;
private String mUserAgent;
public OwnCloudClientTest() { public OwnCloudClientTest() {
super(); super();
@ -90,12 +91,14 @@ public class OwnCloudClientTest extends AndroidTestCase {
mServerUri = Uri.parse(getContext().getString(R.string.server_base_url)); mServerUri = Uri.parse(getContext().getString(R.string.server_base_url));
mUsername = getContext().getString(R.string.username); mUsername = getContext().getString(R.string.username);
mPassword = getContext().getString(R.string.password); mPassword = getContext().getString(R.string.password);
mUserAgent = getContext().getString(R.string.user_agent);
} }
public void testConstructor() { public void testConstructor() {
try { try {
new OwnCloudClient(null, NetworkUtils.getMultiThreadedConnManager()); new OwnCloudClient(null, NetworkUtils.getMultiThreadedConnManager(),
mUserAgent);
throw new AssertionFailedError("Accepted NULL parameter"); throw new AssertionFailedError("Accepted NULL parameter");
} catch(Exception e) { } catch(Exception e) {
@ -104,7 +107,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
} }
try { try {
new OwnCloudClient(mServerUri, null); new OwnCloudClient(mServerUri, null, mUserAgent);
throw new AssertionFailedError("Accepted NULL parameter"); throw new AssertionFailedError("Accepted NULL parameter");
} catch(Exception e) { } catch(Exception e) {
@ -113,17 +116,19 @@ public class OwnCloudClientTest extends AndroidTestCase {
} }
OwnCloudClient client = OwnCloudClient client =
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager()); new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(),
mUserAgent);
assertNotNull("OwnCloudClient instance not built", client); assertNotNull("OwnCloudClient instance not built", client);
assertEquals("Wrong user agent", assertEquals("Wrong user agent",
client.getParams().getParameter(HttpMethodParams.USER_AGENT), client.getParams().getParameter(HttpMethodParams.USER_AGENT),
OwnCloudClient.USER_AGENT); mUserAgent);
} }
public void testGetSetCredentials() { public void testGetSetCredentials() {
OwnCloudClient client = OwnCloudClient client =
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager()); new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(),
mUserAgent);
assertNotNull("Returned NULL credentials", client.getCredentials()); assertNotNull("Returned NULL credentials", client.getCredentials());
assertEquals("Not instanced without credentials", assertEquals("Not instanced without credentials",
@ -146,7 +151,8 @@ public class OwnCloudClientTest extends AndroidTestCase {
public void testExecuteMethodWithTimeouts() throws HttpException, IOException { public void testExecuteMethodWithTimeouts() throws HttpException, IOException {
OwnCloudClient client = OwnCloudClient client =
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager()); new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(),
mUserAgent);
int connectionTimeout = client.getConnectionTimeout(); int connectionTimeout = client.getConnectionTimeout();
int readTimeout = client.getDataTimeout(); int readTimeout = client.getDataTimeout();
@ -194,7 +200,8 @@ public class OwnCloudClientTest extends AndroidTestCase {
public void testExecuteMethod() { public void testExecuteMethod() {
OwnCloudClient client = OwnCloudClient client =
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager()); new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(),
mUserAgent);
HeadMethod head = new HeadMethod(client.getWebdavUri() + "/"); HeadMethod head = new HeadMethod(client.getWebdavUri() + "/");
int status = -1; int status = -1;
try { try {
@ -215,7 +222,8 @@ public class OwnCloudClientTest extends AndroidTestCase {
public void testExhaustResponse() { public void testExhaustResponse() {
OwnCloudClient client = OwnCloudClient client =
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager()); new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(),
mUserAgent);
PropFindMethod propfind = null; PropFindMethod propfind = null;
try { try {
@ -257,7 +265,8 @@ public class OwnCloudClientTest extends AndroidTestCase {
public void testGetSetDefaultTimeouts() { public void testGetSetDefaultTimeouts() {
OwnCloudClient client = OwnCloudClient client =
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager()); new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(),
mUserAgent);
int oldDataTimeout = client.getDataTimeout(); int oldDataTimeout = client.getDataTimeout();
int oldConnectionTimeout = client.getConnectionTimeout(); int oldConnectionTimeout = client.getConnectionTimeout();
@ -297,7 +306,8 @@ public class OwnCloudClientTest extends AndroidTestCase {
public void testGetWebdavUri() { public void testGetWebdavUri() {
OwnCloudClient client = OwnCloudClient client =
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager()); new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(),
mUserAgent);
client.setCredentials(OwnCloudCredentialsFactory.newBearerCredentials("fakeToken")); client.setCredentials(OwnCloudCredentialsFactory.newBearerCredentials("fakeToken"));
Uri webdavUri = client.getWebdavUri(); Uri webdavUri = client.getWebdavUri();
assertTrue("WebDAV URI does not point to the right entry point for OAuth2 " + assertTrue("WebDAV URI does not point to the right entry point for OAuth2 " +
@ -335,7 +345,8 @@ public class OwnCloudClientTest extends AndroidTestCase {
public void testGetSetBaseUri() { public void testGetSetBaseUri() {
OwnCloudClient client = OwnCloudClient client =
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager()); new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(),
mUserAgent);
assertEquals("Returned base URI different that URI passed to constructor", assertEquals("Returned base URI different that URI passed to constructor",
mServerUri, client.getBaseUri()); mServerUri, client.getBaseUri());

View File

@ -95,13 +95,16 @@ public class SimpleFactoryManagerTest extends AndroidTestCase {
public void testGetClientFor() { public void testGetClientFor() {
try { try {
OwnCloudClient client = mSFMgr.getClientFor(mValidAccount, getContext()); OwnCloudClient client = mSFMgr.getClientFor(mValidAccount, getContext(),
getContext().getString(R.string.user_agent));
assertNotSame("Got same client instances for same account", assertNotSame("Got same client instances for same account",
client, mSFMgr.getClientFor(mValidAccount, getContext())); client, mSFMgr.getClientFor(mValidAccount, getContext(),
getContext().getString(R.string.user_agent)));
assertNotSame("Got same client instances for different accounts", assertNotSame("Got same client instances for different accounts",
client, mSFMgr.getClientFor(mAnonymousAccount, getContext())); client, mSFMgr.getClientFor(mAnonymousAccount, getContext(),
getContext().getString(R.string.user_agent)));
} catch (Exception e) { } catch (Exception e) {
throw new AssertionFailedError("Exception getting client for account: " + e.getMessage()); throw new AssertionFailedError("Exception getting client for account: " + e.getMessage());
@ -111,10 +114,12 @@ public class SimpleFactoryManagerTest extends AndroidTestCase {
public void testRemoveClientFor() { public void testRemoveClientFor() {
try { try {
OwnCloudClient client = mSFMgr.getClientFor(mValidAccount, getContext()); OwnCloudClient client = mSFMgr.getClientFor(mValidAccount, getContext(),
getContext().getString(R.string.user_agent));
mSFMgr.removeClientFor(mValidAccount); mSFMgr.removeClientFor(mValidAccount);
assertNotSame("Got same client instance after removing it from manager", assertNotSame("Got same client instance after removing it from manager",
client, mSFMgr.getClientFor(mValidAccount, getContext())); client, mSFMgr.getClientFor(mValidAccount, getContext(),
getContext().getString(R.string.user_agent)));
} catch (Exception e) { } catch (Exception e) {
throw new AssertionFailedError("Exception getting client for account: " + e.getMessage()); throw new AssertionFailedError("Exception getting client for account: " + e.getMessage());

View File

@ -94,13 +94,16 @@ public class SingleSessionManagerTest extends AndroidTestCase {
public void testGetClientFor() { public void testGetClientFor() {
try { try {
OwnCloudClient client1 = mSSMgr.getClientFor(mValidAccount, getContext()); OwnCloudClient client1 = mSSMgr.getClientFor(mValidAccount, getContext(),
OwnCloudClient client2 = mSSMgr.getClientFor(mAnonymousAccount, getContext()); getContext().getString(R.string.user_agent));
OwnCloudClient client2 = mSSMgr.getClientFor(mAnonymousAccount, getContext(),
getContext().getString(R.string.user_agent));
assertNotSame("Got same client instances for different accounts", assertNotSame("Got same client instances for different accounts",
client1, client2); client1, client2);
assertSame("Got different client instances for same account", assertSame("Got different client instances for same account",
client1, mSSMgr.getClientFor(mValidAccount, getContext())); client1, mSSMgr.getClientFor(mValidAccount, getContext(),
getContext().getString(R.string.user_agent)));
} catch (Exception e) { } catch (Exception e) {
throw new AssertionFailedError("Exception getting client for account: " + e.getMessage()); throw new AssertionFailedError("Exception getting client for account: " + e.getMessage());
@ -111,10 +114,12 @@ public class SingleSessionManagerTest extends AndroidTestCase {
public void testRemoveClientFor() { public void testRemoveClientFor() {
try { try {
OwnCloudClient client1 = mSSMgr.getClientFor(mValidAccount, getContext()); OwnCloudClient client1 = mSSMgr.getClientFor(mValidAccount, getContext(),
getContext().getString(R.string.user_agent));
mSSMgr.removeClientFor(mValidAccount); mSSMgr.removeClientFor(mValidAccount);
assertNotSame("Got same client instance after removing it from manager", assertNotSame("Got same client instance after removing it from manager",
client1, mSSMgr.getClientFor(mValidAccount, getContext())); client1, mSSMgr.getClientFor(mValidAccount, getContext(),
getContext().getString(R.string.user_agent)));
} catch (Exception e) { } catch (Exception e) {
throw new AssertionFailedError("Exception getting client for account: " + e.getMessage()); throw new AssertionFailedError("Exception getting client for account: " + e.getMessage());
} }