mirror of
https://github.com/owncloud/android-library.git
synced 2026-08-11 16:33:03 +00:00
Fix unit test
This commit is contained in:
@@ -26,5 +26,6 @@
|
||||
<resources>
|
||||
|
||||
<string name="app_name">Oc_framework-testTest</string>
|
||||
<string name ="user_agent">Android-ownCloud</string>
|
||||
|
||||
</resources>
|
||||
|
||||
+30
-15
@@ -279,7 +279,8 @@ public class MoveFileTest extends RemoteTest {
|
||||
mBaseFolderPath + TARGET_PATH_TO_FILE_1,
|
||||
false
|
||||
);
|
||||
RemoteOperationResult result = moveOperation.execute(mClient);
|
||||
RemoteOperationResult result = moveOperation.execute(mClient,
|
||||
getContext().getString(R.string.user_agent));
|
||||
assertTrue(result.isSuccess());
|
||||
|
||||
// move & rename file, different location
|
||||
@@ -288,7 +289,8 @@ public class MoveFileTest extends RemoteTest {
|
||||
mBaseFolderPath + TARGET_PATH_TO_FILE_2_RENAMED,
|
||||
false
|
||||
);
|
||||
result = moveOperation.execute(mClient);
|
||||
result = moveOperation.execute(mClient,
|
||||
getContext().getString(R.string.user_agent));
|
||||
assertTrue(result.isSuccess());
|
||||
|
||||
// move & rename file, same location (rename file)
|
||||
@@ -297,7 +299,8 @@ public class MoveFileTest extends RemoteTest {
|
||||
mBaseFolderPath + SRC_PATH_TO_FILE_3_RENAMED,
|
||||
false
|
||||
);
|
||||
result = moveOperation.execute(mClient);
|
||||
result = moveOperation.execute(mClient,
|
||||
getContext().getString(R.string.user_agent));
|
||||
assertTrue(result.isSuccess());
|
||||
|
||||
// move empty folder
|
||||
@@ -306,7 +309,8 @@ public class MoveFileTest extends RemoteTest {
|
||||
mBaseFolderPath + TARGET_PATH_TO_EMPTY_FOLDER,
|
||||
false
|
||||
);
|
||||
result = moveOperation.execute(mClient);
|
||||
result = moveOperation.execute(mClient,
|
||||
getContext().getString(R.string.user_agent));
|
||||
assertTrue(result.isSuccess());
|
||||
|
||||
// move non-empty folder
|
||||
@@ -315,7 +319,8 @@ public class MoveFileTest extends RemoteTest {
|
||||
mBaseFolderPath + TARGET_PATH_TO_FULL_FOLDER_1,
|
||||
false
|
||||
);
|
||||
result = moveOperation.execute(mClient);
|
||||
result = moveOperation.execute(mClient,
|
||||
getContext().getString(R.string.user_agent));
|
||||
assertTrue(result.isSuccess());
|
||||
|
||||
// move & rename folder, different location
|
||||
@@ -324,7 +329,8 @@ public class MoveFileTest extends RemoteTest {
|
||||
mBaseFolderPath + TARGET_PATH_TO_FULL_FOLDER_2_RENAMED,
|
||||
false
|
||||
);
|
||||
result = moveOperation.execute(mClient);
|
||||
result = moveOperation.execute(mClient,
|
||||
getContext().getString(R.string.user_agent));
|
||||
assertTrue(result.isSuccess());
|
||||
|
||||
// move & rename folder, same location (rename folder)
|
||||
@@ -333,7 +339,8 @@ public class MoveFileTest extends RemoteTest {
|
||||
mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_3_RENAMED,
|
||||
false
|
||||
);
|
||||
result = moveOperation.execute(mClient);
|
||||
result = moveOperation.execute(mClient,
|
||||
getContext().getString(R.string.user_agent));
|
||||
assertTrue(result.isSuccess());
|
||||
|
||||
// move for nothing (success, but no interaction with network)
|
||||
@@ -342,7 +349,8 @@ public class MoveFileTest extends RemoteTest {
|
||||
mBaseFolderPath + SRC_PATH_TO_FILE_4,
|
||||
false
|
||||
);
|
||||
result = moveOperation.execute(mClient);
|
||||
result = moveOperation.execute(mClient,
|
||||
getContext().getString(R.string.user_agent));
|
||||
assertTrue(result.isSuccess());
|
||||
|
||||
// move overwriting
|
||||
@@ -351,7 +359,8 @@ public class MoveFileTest extends RemoteTest {
|
||||
mBaseFolderPath + TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4,
|
||||
true
|
||||
);
|
||||
result = moveOperation.execute(mClient);
|
||||
result = moveOperation.execute(mClient,
|
||||
getContext().getString(R.string.user_agent));
|
||||
assertTrue(result.isSuccess());
|
||||
|
||||
|
||||
@@ -363,7 +372,8 @@ public class MoveFileTest extends RemoteTest {
|
||||
mBaseFolderPath + TARGET_PATH_TO_NON_EXISTENT_FILE,
|
||||
false
|
||||
);
|
||||
result = moveOperation.execute(mClient);
|
||||
result = moveOperation.execute(mClient,
|
||||
getContext().getString(R.string.user_agent));
|
||||
assertTrue(result.getCode() == ResultCode.FILE_NOT_FOUND);
|
||||
|
||||
// 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,
|
||||
false
|
||||
);
|
||||
result = moveOperation.execute(mClient);
|
||||
result = moveOperation.execute(mClient,
|
||||
getContext().getString(R.string.user_agent));
|
||||
assertTrue(result.getHttpCode() == HttpStatus.SC_CONFLICT);
|
||||
|
||||
// target location (renaming) has invalid characters
|
||||
@@ -381,7 +392,8 @@ public class MoveFileTest extends RemoteTest {
|
||||
mBaseFolderPath + TARGET_PATH_RENAMED_WITH_INVALID_CHARS,
|
||||
false
|
||||
);
|
||||
result = moveOperation.execute(mClient);
|
||||
result = moveOperation.execute(mClient,
|
||||
getContext().getString(R.string.user_agent));
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
// name collision
|
||||
@@ -390,7 +402,8 @@ public class MoveFileTest extends RemoteTest {
|
||||
mBaseFolderPath + TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7,
|
||||
false
|
||||
);
|
||||
result = moveOperation.execute(mClient);
|
||||
result = moveOperation.execute(mClient,
|
||||
getContext().getString(R.string.user_agent));
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_OVERWRITE);
|
||||
|
||||
// move a folder into a descendant
|
||||
@@ -399,7 +412,8 @@ public class MoveFileTest extends RemoteTest {
|
||||
mBaseFolderPath + SRC_PATH_TO_EMPTY_FOLDER,
|
||||
false
|
||||
);
|
||||
result = moveOperation.execute(mClient);
|
||||
result = moveOperation.execute(mClient,
|
||||
getContext().getString(R.string.user_agent));
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_MOVE_INTO_DESCENDANT);
|
||||
|
||||
}
|
||||
@@ -436,7 +450,8 @@ public class MoveFileTest extends RemoteTest {
|
||||
|
||||
mClient = new OwnCloudClient(
|
||||
Uri.parse(mServerUri),
|
||||
NetworkUtils.getMultiThreadedConnManager()
|
||||
NetworkUtils.getMultiThreadedConnManager(),
|
||||
getContext().getString(R.string.user_agent)
|
||||
);
|
||||
mClient.setDefaultTimeouts(
|
||||
OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT,
|
||||
|
||||
+22
-11
@@ -64,6 +64,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
|
||||
private Uri mServerUri;
|
||||
private String mUsername;
|
||||
private String mPassword;
|
||||
private String mUserAgent;
|
||||
|
||||
public OwnCloudClientTest() {
|
||||
super();
|
||||
@@ -90,12 +91,14 @@ public class OwnCloudClientTest extends AndroidTestCase {
|
||||
mServerUri = Uri.parse(getContext().getString(R.string.server_base_url));
|
||||
mUsername = getContext().getString(R.string.username);
|
||||
mPassword = getContext().getString(R.string.password);
|
||||
mUserAgent = getContext().getString(R.string.user_agent);
|
||||
}
|
||||
|
||||
|
||||
public void testConstructor() {
|
||||
try {
|
||||
new OwnCloudClient(null, NetworkUtils.getMultiThreadedConnManager());
|
||||
new OwnCloudClient(null, NetworkUtils.getMultiThreadedConnManager(),
|
||||
mUserAgent);
|
||||
throw new AssertionFailedError("Accepted NULL parameter");
|
||||
|
||||
} catch(Exception e) {
|
||||
@@ -104,7 +107,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
|
||||
}
|
||||
|
||||
try {
|
||||
new OwnCloudClient(mServerUri, null);
|
||||
new OwnCloudClient(mServerUri, null, mUserAgent);
|
||||
throw new AssertionFailedError("Accepted NULL parameter");
|
||||
|
||||
} catch(Exception e) {
|
||||
@@ -113,17 +116,19 @@ public class OwnCloudClientTest extends AndroidTestCase {
|
||||
}
|
||||
|
||||
OwnCloudClient client =
|
||||
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
|
||||
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(),
|
||||
mUserAgent);
|
||||
assertNotNull("OwnCloudClient instance not built", client);
|
||||
assertEquals("Wrong user agent",
|
||||
client.getParams().getParameter(HttpMethodParams.USER_AGENT),
|
||||
OwnCloudClient.USER_AGENT);
|
||||
mUserAgent);
|
||||
}
|
||||
|
||||
|
||||
public void testGetSetCredentials() {
|
||||
OwnCloudClient client =
|
||||
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
|
||||
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(),
|
||||
mUserAgent);
|
||||
|
||||
assertNotNull("Returned NULL credentials", client.getCredentials());
|
||||
assertEquals("Not instanced without credentials",
|
||||
@@ -146,7 +151,8 @@ public class OwnCloudClientTest extends AndroidTestCase {
|
||||
|
||||
public void testExecuteMethodWithTimeouts() throws HttpException, IOException {
|
||||
OwnCloudClient client =
|
||||
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
|
||||
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(),
|
||||
mUserAgent);
|
||||
int connectionTimeout = client.getConnectionTimeout();
|
||||
int readTimeout = client.getDataTimeout();
|
||||
|
||||
@@ -194,7 +200,8 @@ public class OwnCloudClientTest extends AndroidTestCase {
|
||||
|
||||
public void testExecuteMethod() {
|
||||
OwnCloudClient client =
|
||||
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
|
||||
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(),
|
||||
mUserAgent);
|
||||
HeadMethod head = new HeadMethod(client.getWebdavUri() + "/");
|
||||
int status = -1;
|
||||
try {
|
||||
@@ -215,7 +222,8 @@ public class OwnCloudClientTest extends AndroidTestCase {
|
||||
|
||||
public void testExhaustResponse() {
|
||||
OwnCloudClient client =
|
||||
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
|
||||
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(),
|
||||
mUserAgent);
|
||||
|
||||
PropFindMethod propfind = null;
|
||||
try {
|
||||
@@ -257,7 +265,8 @@ public class OwnCloudClientTest extends AndroidTestCase {
|
||||
|
||||
public void testGetSetDefaultTimeouts() {
|
||||
OwnCloudClient client =
|
||||
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
|
||||
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(),
|
||||
mUserAgent);
|
||||
|
||||
int oldDataTimeout = client.getDataTimeout();
|
||||
int oldConnectionTimeout = client.getConnectionTimeout();
|
||||
@@ -297,7 +306,8 @@ public class OwnCloudClientTest extends AndroidTestCase {
|
||||
|
||||
public void testGetWebdavUri() {
|
||||
OwnCloudClient client =
|
||||
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
|
||||
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(),
|
||||
mUserAgent);
|
||||
client.setCredentials(OwnCloudCredentialsFactory.newBearerCredentials("fakeToken"));
|
||||
Uri webdavUri = client.getWebdavUri();
|
||||
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() {
|
||||
OwnCloudClient client =
|
||||
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
|
||||
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(),
|
||||
mUserAgent);
|
||||
assertEquals("Returned base URI different that URI passed to constructor",
|
||||
mServerUri, client.getBaseUri());
|
||||
|
||||
|
||||
+10
-5
@@ -95,13 +95,16 @@ public class SimpleFactoryManagerTest extends AndroidTestCase {
|
||||
|
||||
public void testGetClientFor() {
|
||||
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",
|
||||
client, mSFMgr.getClientFor(mValidAccount, getContext()));
|
||||
client, mSFMgr.getClientFor(mValidAccount, getContext(),
|
||||
getContext().getString(R.string.user_agent)));
|
||||
|
||||
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) {
|
||||
throw new AssertionFailedError("Exception getting client for account: " + e.getMessage());
|
||||
@@ -111,10 +114,12 @@ public class SimpleFactoryManagerTest extends AndroidTestCase {
|
||||
|
||||
public void testRemoveClientFor() {
|
||||
try {
|
||||
OwnCloudClient client = mSFMgr.getClientFor(mValidAccount, getContext());
|
||||
OwnCloudClient client = mSFMgr.getClientFor(mValidAccount, getContext(),
|
||||
getContext().getString(R.string.user_agent));
|
||||
mSFMgr.removeClientFor(mValidAccount);
|
||||
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) {
|
||||
throw new AssertionFailedError("Exception getting client for account: " + e.getMessage());
|
||||
|
||||
+10
-5
@@ -94,13 +94,16 @@ public class SingleSessionManagerTest extends AndroidTestCase {
|
||||
|
||||
public void testGetClientFor() {
|
||||
try {
|
||||
OwnCloudClient client1 = mSSMgr.getClientFor(mValidAccount, getContext());
|
||||
OwnCloudClient client2 = mSSMgr.getClientFor(mAnonymousAccount, getContext());
|
||||
OwnCloudClient client1 = mSSMgr.getClientFor(mValidAccount, 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",
|
||||
client1, client2);
|
||||
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) {
|
||||
throw new AssertionFailedError("Exception getting client for account: " + e.getMessage());
|
||||
@@ -111,10 +114,12 @@ public class SingleSessionManagerTest extends AndroidTestCase {
|
||||
|
||||
public void testRemoveClientFor() {
|
||||
try {
|
||||
OwnCloudClient client1 = mSSMgr.getClientFor(mValidAccount, getContext());
|
||||
OwnCloudClient client1 = mSSMgr.getClientFor(mValidAccount, getContext(),
|
||||
getContext().getString(R.string.user_agent));
|
||||
mSSMgr.removeClientFor(mValidAccount);
|
||||
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) {
|
||||
throw new AssertionFailedError("Exception getting client for account: " + e.getMessage());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user