mirror of
https://github.com/owncloud/android-library.git
synced 2026-08-11 16:33:03 +00:00
Refactor parameter user_agent out of RemoteOperation and children
This commit is contained in:
@@ -72,7 +72,6 @@ public class TestActivity extends Activity {
|
||||
private String mServerUri;
|
||||
private String mUser;
|
||||
private String mPass;
|
||||
private static String mUserAgent;
|
||||
|
||||
private static final int BUFFER_SIZE = 1024;
|
||||
|
||||
@@ -91,7 +90,6 @@ public class TestActivity extends Activity {
|
||||
mServerUri = getString(R.string.server_base_url);
|
||||
mUser = getString(R.string.username);
|
||||
mPass = getString(R.string.password);
|
||||
mUserAgent = getString(R.string.user_agent);
|
||||
|
||||
Protocol pr = Protocol.getProtocol("https");
|
||||
if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) {
|
||||
@@ -106,8 +104,7 @@ public class TestActivity extends Activity {
|
||||
}
|
||||
}
|
||||
|
||||
mClient = new OwnCloudClient(Uri.parse(mServerUri), NetworkUtils.getMultiThreadedConnManager(),
|
||||
mUserAgent);
|
||||
mClient = new OwnCloudClient(Uri.parse(mServerUri), NetworkUtils.getMultiThreadedConnManager());
|
||||
mClient.setDefaultTimeouts(
|
||||
OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT,
|
||||
OwnCloudClientFactory.DEFAULT_CONNECTION_TIMEOUT);
|
||||
@@ -159,7 +156,7 @@ public class TestActivity extends Activity {
|
||||
|
||||
CreateRemoteFolderOperation createOperation =
|
||||
new CreateRemoteFolderOperation(remotePath, createFullPath);
|
||||
RemoteOperationResult result = createOperation.execute(client, mUserAgent);
|
||||
RemoteOperationResult result = createOperation.execute(client);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -177,7 +174,7 @@ public class TestActivity extends Activity {
|
||||
public RemoteOperationResult renameFile(String oldName, String oldRemotePath, String newName, boolean isFolder) {
|
||||
|
||||
RenameRemoteFileOperation renameOperation = new RenameRemoteFileOperation(oldName, oldRemotePath, newName, isFolder);
|
||||
RemoteOperationResult result = renameOperation.execute(mClient, mUserAgent);
|
||||
RemoteOperationResult result = renameOperation.execute(mClient);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -190,7 +187,7 @@ public class TestActivity extends Activity {
|
||||
*/
|
||||
public RemoteOperationResult removeFile(String remotePath) {
|
||||
RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath);
|
||||
RemoteOperationResult result = removeOperation.execute(mClient, mUserAgent);
|
||||
RemoteOperationResult result = removeOperation.execute(mClient);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -202,7 +199,7 @@ public class TestActivity extends Activity {
|
||||
*/
|
||||
public static RemoteOperationResult removeFile(String remotePath, OwnCloudClient client) {
|
||||
RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath);
|
||||
RemoteOperationResult result = removeOperation.execute(client, mUserAgent);
|
||||
RemoteOperationResult result = removeOperation.execute(client);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -216,7 +213,7 @@ public class TestActivity extends Activity {
|
||||
public RemoteOperationResult readFile(String remotePath) {
|
||||
|
||||
ReadRemoteFolderOperation readOperation= new ReadRemoteFolderOperation(remotePath);
|
||||
RemoteOperationResult result = readOperation.execute(mClient, mUserAgent);
|
||||
RemoteOperationResult result = readOperation.execute(mClient);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -235,7 +232,7 @@ public class TestActivity extends Activity {
|
||||
folder.mkdirs();
|
||||
|
||||
DownloadRemoteFileOperation downloadOperation = new DownloadRemoteFileOperation(remoteFile.getRemotePath(), folder.getAbsolutePath());
|
||||
RemoteOperationResult result = downloadOperation.execute(mClient, mUserAgent);
|
||||
RemoteOperationResult result = downloadOperation.execute(mClient);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -276,7 +273,7 @@ public class TestActivity extends Activity {
|
||||
);
|
||||
}
|
||||
|
||||
RemoteOperationResult result = uploadOperation.execute(client, mUserAgent);
|
||||
RemoteOperationResult result = uploadOperation.execute(client);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -287,7 +284,7 @@ public class TestActivity extends Activity {
|
||||
public RemoteOperationResult getShares(){
|
||||
|
||||
GetRemoteSharesOperation getOperation = new GetRemoteSharesOperation();
|
||||
RemoteOperationResult result = getOperation.execute(mClient, mUserAgent);
|
||||
RemoteOperationResult result = getOperation.execute(mClient);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -315,7 +312,7 @@ public class TestActivity extends Activity {
|
||||
String password, int permissions){
|
||||
|
||||
CreateRemoteShareOperation createOperation = new CreateRemoteShareOperation(path, shareType, shareWith, publicUpload, password, permissions);
|
||||
RemoteOperationResult result = createOperation.execute(mClient, mUserAgent);
|
||||
RemoteOperationResult result = createOperation.execute(mClient);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -329,7 +326,7 @@ public class TestActivity extends Activity {
|
||||
|
||||
public RemoteOperationResult removeShare(int idShare) {
|
||||
RemoveRemoteShareOperation removeOperation = new RemoveRemoteShareOperation(idShare);
|
||||
RemoteOperationResult result = removeOperation.execute(mClient, mUserAgent);
|
||||
RemoteOperationResult result = removeOperation.execute(mClient);
|
||||
|
||||
return result;
|
||||
|
||||
|
||||
+15
-30
@@ -279,8 +279,7 @@ public class MoveFileTest extends RemoteTest {
|
||||
mBaseFolderPath + TARGET_PATH_TO_FILE_1,
|
||||
false
|
||||
);
|
||||
RemoteOperationResult result = moveOperation.execute(mClient,
|
||||
getContext().getString(R.string.user_agent));
|
||||
RemoteOperationResult result = moveOperation.execute(mClient);
|
||||
assertTrue(result.isSuccess());
|
||||
|
||||
// move & rename file, different location
|
||||
@@ -289,8 +288,7 @@ public class MoveFileTest extends RemoteTest {
|
||||
mBaseFolderPath + TARGET_PATH_TO_FILE_2_RENAMED,
|
||||
false
|
||||
);
|
||||
result = moveOperation.execute(mClient,
|
||||
getContext().getString(R.string.user_agent));
|
||||
result = moveOperation.execute(mClient);
|
||||
assertTrue(result.isSuccess());
|
||||
|
||||
// move & rename file, same location (rename file)
|
||||
@@ -299,8 +297,7 @@ public class MoveFileTest extends RemoteTest {
|
||||
mBaseFolderPath + SRC_PATH_TO_FILE_3_RENAMED,
|
||||
false
|
||||
);
|
||||
result = moveOperation.execute(mClient,
|
||||
getContext().getString(R.string.user_agent));
|
||||
result = moveOperation.execute(mClient);
|
||||
assertTrue(result.isSuccess());
|
||||
|
||||
// move empty folder
|
||||
@@ -309,8 +306,7 @@ public class MoveFileTest extends RemoteTest {
|
||||
mBaseFolderPath + TARGET_PATH_TO_EMPTY_FOLDER,
|
||||
false
|
||||
);
|
||||
result = moveOperation.execute(mClient,
|
||||
getContext().getString(R.string.user_agent));
|
||||
result = moveOperation.execute(mClient);
|
||||
assertTrue(result.isSuccess());
|
||||
|
||||
// move non-empty folder
|
||||
@@ -319,8 +315,7 @@ public class MoveFileTest extends RemoteTest {
|
||||
mBaseFolderPath + TARGET_PATH_TO_FULL_FOLDER_1,
|
||||
false
|
||||
);
|
||||
result = moveOperation.execute(mClient,
|
||||
getContext().getString(R.string.user_agent));
|
||||
result = moveOperation.execute(mClient);
|
||||
assertTrue(result.isSuccess());
|
||||
|
||||
// move & rename folder, different location
|
||||
@@ -329,8 +324,7 @@ public class MoveFileTest extends RemoteTest {
|
||||
mBaseFolderPath + TARGET_PATH_TO_FULL_FOLDER_2_RENAMED,
|
||||
false
|
||||
);
|
||||
result = moveOperation.execute(mClient,
|
||||
getContext().getString(R.string.user_agent));
|
||||
result = moveOperation.execute(mClient);
|
||||
assertTrue(result.isSuccess());
|
||||
|
||||
// move & rename folder, same location (rename folder)
|
||||
@@ -339,8 +333,7 @@ public class MoveFileTest extends RemoteTest {
|
||||
mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_3_RENAMED,
|
||||
false
|
||||
);
|
||||
result = moveOperation.execute(mClient,
|
||||
getContext().getString(R.string.user_agent));
|
||||
result = moveOperation.execute(mClient);
|
||||
assertTrue(result.isSuccess());
|
||||
|
||||
// move for nothing (success, but no interaction with network)
|
||||
@@ -349,8 +342,7 @@ public class MoveFileTest extends RemoteTest {
|
||||
mBaseFolderPath + SRC_PATH_TO_FILE_4,
|
||||
false
|
||||
);
|
||||
result = moveOperation.execute(mClient,
|
||||
getContext().getString(R.string.user_agent));
|
||||
result = moveOperation.execute(mClient);
|
||||
assertTrue(result.isSuccess());
|
||||
|
||||
// move overwriting
|
||||
@@ -359,8 +351,7 @@ public class MoveFileTest extends RemoteTest {
|
||||
mBaseFolderPath + TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4,
|
||||
true
|
||||
);
|
||||
result = moveOperation.execute(mClient,
|
||||
getContext().getString(R.string.user_agent));
|
||||
result = moveOperation.execute(mClient);
|
||||
assertTrue(result.isSuccess());
|
||||
|
||||
|
||||
@@ -372,8 +363,7 @@ public class MoveFileTest extends RemoteTest {
|
||||
mBaseFolderPath + TARGET_PATH_TO_NON_EXISTENT_FILE,
|
||||
false
|
||||
);
|
||||
result = moveOperation.execute(mClient,
|
||||
getContext().getString(R.string.user_agent));
|
||||
result = moveOperation.execute(mClient);
|
||||
assertTrue(result.getCode() == ResultCode.FILE_NOT_FOUND);
|
||||
|
||||
// folder to move into does no exist
|
||||
@@ -382,8 +372,7 @@ public class MoveFileTest extends RemoteTest {
|
||||
mBaseFolderPath + TARGET_PATH_TO_FILE_5_INTO_NON_EXISTENT_FOLDER,
|
||||
false
|
||||
);
|
||||
result = moveOperation.execute(mClient,
|
||||
getContext().getString(R.string.user_agent));
|
||||
result = moveOperation.execute(mClient);
|
||||
assertTrue(result.getHttpCode() == HttpStatus.SC_CONFLICT);
|
||||
|
||||
// target location (renaming) has invalid characters
|
||||
@@ -392,8 +381,7 @@ public class MoveFileTest extends RemoteTest {
|
||||
mBaseFolderPath + TARGET_PATH_RENAMED_WITH_INVALID_CHARS,
|
||||
false
|
||||
);
|
||||
result = moveOperation.execute(mClient,
|
||||
getContext().getString(R.string.user_agent));
|
||||
result = moveOperation.execute(mClient);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
// name collision
|
||||
@@ -402,8 +390,7 @@ public class MoveFileTest extends RemoteTest {
|
||||
mBaseFolderPath + TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7,
|
||||
false
|
||||
);
|
||||
result = moveOperation.execute(mClient,
|
||||
getContext().getString(R.string.user_agent));
|
||||
result = moveOperation.execute(mClient);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_OVERWRITE);
|
||||
|
||||
// move a folder into a descendant
|
||||
@@ -412,8 +399,7 @@ public class MoveFileTest extends RemoteTest {
|
||||
mBaseFolderPath + SRC_PATH_TO_EMPTY_FOLDER,
|
||||
false
|
||||
);
|
||||
result = moveOperation.execute(mClient,
|
||||
getContext().getString(R.string.user_agent));
|
||||
result = moveOperation.execute(mClient);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_MOVE_INTO_DESCENDANT);
|
||||
|
||||
}
|
||||
@@ -450,8 +436,7 @@ public class MoveFileTest extends RemoteTest {
|
||||
|
||||
mClient = new OwnCloudClient(
|
||||
Uri.parse(mServerUri),
|
||||
NetworkUtils.getMultiThreadedConnManager(),
|
||||
getContext().getString(R.string.user_agent)
|
||||
NetworkUtils.getMultiThreadedConnManager()
|
||||
);
|
||||
mClient.setDefaultTimeouts(
|
||||
OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT,
|
||||
|
||||
+10
-19
@@ -97,8 +97,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
|
||||
|
||||
public void testConstructor() {
|
||||
try {
|
||||
new OwnCloudClient(null, NetworkUtils.getMultiThreadedConnManager(),
|
||||
mUserAgent);
|
||||
new OwnCloudClient(null, NetworkUtils.getMultiThreadedConnManager());
|
||||
throw new AssertionFailedError("Accepted NULL parameter");
|
||||
|
||||
} catch(Exception e) {
|
||||
@@ -107,7 +106,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
|
||||
}
|
||||
|
||||
try {
|
||||
new OwnCloudClient(mServerUri, null, mUserAgent);
|
||||
new OwnCloudClient(mServerUri, null);
|
||||
throw new AssertionFailedError("Accepted NULL parameter");
|
||||
|
||||
} catch(Exception e) {
|
||||
@@ -116,8 +115,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
|
||||
}
|
||||
|
||||
OwnCloudClient client =
|
||||
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(),
|
||||
mUserAgent);
|
||||
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
|
||||
assertNotNull("OwnCloudClient instance not built", client);
|
||||
assertEquals("Wrong user agent",
|
||||
client.getParams().getParameter(HttpMethodParams.USER_AGENT),
|
||||
@@ -127,8 +125,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
|
||||
|
||||
public void testGetSetCredentials() {
|
||||
OwnCloudClient client =
|
||||
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(),
|
||||
mUserAgent);
|
||||
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
|
||||
|
||||
assertNotNull("Returned NULL credentials", client.getCredentials());
|
||||
assertEquals("Not instanced without credentials",
|
||||
@@ -151,8 +148,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
|
||||
|
||||
public void testExecuteMethodWithTimeouts() throws HttpException, IOException {
|
||||
OwnCloudClient client =
|
||||
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(),
|
||||
mUserAgent);
|
||||
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
|
||||
int connectionTimeout = client.getConnectionTimeout();
|
||||
int readTimeout = client.getDataTimeout();
|
||||
|
||||
@@ -200,8 +196,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
|
||||
|
||||
public void testExecuteMethod() {
|
||||
OwnCloudClient client =
|
||||
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(),
|
||||
mUserAgent);
|
||||
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
|
||||
HeadMethod head = new HeadMethod(client.getWebdavUri() + "/");
|
||||
int status = -1;
|
||||
try {
|
||||
@@ -222,8 +217,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
|
||||
|
||||
public void testExhaustResponse() {
|
||||
OwnCloudClient client =
|
||||
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(),
|
||||
mUserAgent);
|
||||
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
|
||||
|
||||
PropFindMethod propfind = null;
|
||||
try {
|
||||
@@ -265,8 +259,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
|
||||
|
||||
public void testGetSetDefaultTimeouts() {
|
||||
OwnCloudClient client =
|
||||
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(),
|
||||
mUserAgent);
|
||||
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
|
||||
|
||||
int oldDataTimeout = client.getDataTimeout();
|
||||
int oldConnectionTimeout = client.getConnectionTimeout();
|
||||
@@ -306,8 +299,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
|
||||
|
||||
public void testGetWebdavUri() {
|
||||
OwnCloudClient client =
|
||||
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(),
|
||||
mUserAgent);
|
||||
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
|
||||
client.setCredentials(OwnCloudCredentialsFactory.newBearerCredentials("fakeToken"));
|
||||
Uri webdavUri = client.getWebdavUri();
|
||||
assertTrue("WebDAV URI does not point to the right entry point for OAuth2 " +
|
||||
@@ -345,8 +337,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
|
||||
|
||||
public void testGetSetBaseUri() {
|
||||
OwnCloudClient client =
|
||||
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(),
|
||||
mUserAgent);
|
||||
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
|
||||
assertEquals("Returned base URI different that URI passed to constructor",
|
||||
mServerUri, client.getBaseUri());
|
||||
|
||||
|
||||
+5
-10
@@ -95,16 +95,13 @@ public class SimpleFactoryManagerTest extends AndroidTestCase {
|
||||
|
||||
public void testGetClientFor() {
|
||||
try {
|
||||
OwnCloudClient client = mSFMgr.getClientFor(mValidAccount, getContext(),
|
||||
getContext().getString(R.string.user_agent));
|
||||
OwnCloudClient client = mSFMgr.getClientFor(mValidAccount, getContext());
|
||||
|
||||
assertNotSame("Got same client instances for same account",
|
||||
client, mSFMgr.getClientFor(mValidAccount, getContext(),
|
||||
getContext().getString(R.string.user_agent)));
|
||||
client, mSFMgr.getClientFor(mValidAccount, getContext()));
|
||||
|
||||
assertNotSame("Got same client instances for different accounts",
|
||||
client, mSFMgr.getClientFor(mAnonymousAccount, getContext(),
|
||||
getContext().getString(R.string.user_agent)));
|
||||
client, mSFMgr.getClientFor(mAnonymousAccount, getContext()));
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new AssertionFailedError("Exception getting client for account: " + e.getMessage());
|
||||
@@ -114,12 +111,10 @@ public class SimpleFactoryManagerTest extends AndroidTestCase {
|
||||
|
||||
public void testRemoveClientFor() {
|
||||
try {
|
||||
OwnCloudClient client = mSFMgr.getClientFor(mValidAccount, getContext(),
|
||||
getContext().getString(R.string.user_agent));
|
||||
OwnCloudClient client = mSFMgr.getClientFor(mValidAccount, getContext());
|
||||
mSFMgr.removeClientFor(mValidAccount);
|
||||
assertNotSame("Got same client instance after removing it from manager",
|
||||
client, mSFMgr.getClientFor(mValidAccount, getContext(),
|
||||
getContext().getString(R.string.user_agent)));
|
||||
client, mSFMgr.getClientFor(mValidAccount, getContext()));
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new AssertionFailedError("Exception getting client for account: " + e.getMessage());
|
||||
|
||||
+5
-10
@@ -94,16 +94,13 @@ public class SingleSessionManagerTest extends AndroidTestCase {
|
||||
|
||||
public void testGetClientFor() {
|
||||
try {
|
||||
OwnCloudClient client1 = mSSMgr.getClientFor(mValidAccount, getContext(),
|
||||
getContext().getString(R.string.user_agent));
|
||||
OwnCloudClient client2 = mSSMgr.getClientFor(mAnonymousAccount, getContext(),
|
||||
getContext().getString(R.string.user_agent));
|
||||
OwnCloudClient client1 = mSSMgr.getClientFor(mValidAccount, getContext());
|
||||
OwnCloudClient client2 = mSSMgr.getClientFor(mAnonymousAccount, getContext());
|
||||
|
||||
assertNotSame("Got same client instances for different accounts",
|
||||
client1, client2);
|
||||
assertSame("Got different client instances for same account",
|
||||
client1, mSSMgr.getClientFor(mValidAccount, getContext(),
|
||||
getContext().getString(R.string.user_agent)));
|
||||
client1, mSSMgr.getClientFor(mValidAccount, getContext()));
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new AssertionFailedError("Exception getting client for account: " + e.getMessage());
|
||||
@@ -114,12 +111,10 @@ public class SingleSessionManagerTest extends AndroidTestCase {
|
||||
|
||||
public void testRemoveClientFor() {
|
||||
try {
|
||||
OwnCloudClient client1 = mSSMgr.getClientFor(mValidAccount, getContext(),
|
||||
getContext().getString(R.string.user_agent));
|
||||
OwnCloudClient client1 = mSSMgr.getClientFor(mValidAccount, getContext());
|
||||
mSSMgr.removeClientFor(mValidAccount);
|
||||
assertNotSame("Got same client instance after removing it from manager",
|
||||
client1, mSSMgr.getClientFor(mValidAccount, getContext(),
|
||||
getContext().getString(R.string.user_agent)));
|
||||
client1, mSSMgr.getClientFor(mValidAccount, getContext()));
|
||||
} catch (Exception e) {
|
||||
throw new AssertionFailedError("Exception getting client for account: " + e.getMessage());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user