mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
New tests for the federated sharing
This commit is contained in:
parent
1e1d424ffb
commit
add2aab31e
@ -29,6 +29,7 @@ import java.io.File;
|
|||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
||||||
import com.owncloud.android.lib.resources.shares.ShareType;
|
import com.owncloud.android.lib.resources.shares.ShareType;
|
||||||
|
import com.owncloud.android.lib.test_project.R;
|
||||||
import com.owncloud.android.lib.test_project.TestActivity;
|
import com.owncloud.android.lib.test_project.TestActivity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,6 +48,7 @@ public class CreateShareTest extends RemoteTest {
|
|||||||
private TestActivity mActivity;
|
private TestActivity mActivity;
|
||||||
private String mFullPath2FileToShare;
|
private String mFullPath2FileToShare;
|
||||||
private String mFullPath2NonExistentFile;
|
private String mFullPath2NonExistentFile;
|
||||||
|
private String mRemoteServer;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
@ -55,6 +57,7 @@ public class CreateShareTest extends RemoteTest {
|
|||||||
mActivity = getActivity();
|
mActivity = getActivity();
|
||||||
mFullPath2FileToShare = mBaseFolderPath + FILE_TO_SHARE;
|
mFullPath2FileToShare = mBaseFolderPath + FILE_TO_SHARE;
|
||||||
mFullPath2NonExistentFile = mBaseFolderPath + NON_EXISTENT_FILE;
|
mFullPath2NonExistentFile = mBaseFolderPath + NON_EXISTENT_FILE;
|
||||||
|
mRemoteServer = getActivity().getString(R.string.server_base_url_2);
|
||||||
|
|
||||||
File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
|
File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
|
||||||
RemoteOperationResult result = mActivity.uploadFile(
|
RemoteOperationResult result = mActivity.uploadFile(
|
||||||
@ -217,6 +220,82 @@ public class CreateShareTest extends RemoteTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test creation of federated shares with remote users
|
||||||
|
*/
|
||||||
|
public void testCreateFederatedShareWithUser() {
|
||||||
|
|
||||||
|
String remoteDomain = mRemoteServer.split("//")[1];
|
||||||
|
|
||||||
|
/// Successful cases
|
||||||
|
RemoteOperationResult result = mActivity.createShare(
|
||||||
|
mFullPath2FileToShare,
|
||||||
|
ShareType.FEDERATED,
|
||||||
|
"admin@" + remoteDomain,
|
||||||
|
false,
|
||||||
|
"",
|
||||||
|
1);
|
||||||
|
assertTrue(result.isSuccess());
|
||||||
|
|
||||||
|
|
||||||
|
/// Failed cases
|
||||||
|
|
||||||
|
// sharee doesn't exist in an existing remote server
|
||||||
|
result = mActivity.createShare(
|
||||||
|
mFullPath2FileToShare,
|
||||||
|
ShareType.FEDERATED,
|
||||||
|
"no_exist@" + remoteDomain,
|
||||||
|
false,
|
||||||
|
"",
|
||||||
|
31);
|
||||||
|
assertFalse(result.isSuccess());
|
||||||
|
assertEquals(
|
||||||
|
RemoteOperationResult.ResultCode.SHARE_FORBIDDEN,
|
||||||
|
result.getCode()
|
||||||
|
);
|
||||||
|
assertTrue( // error message from server as part of the result
|
||||||
|
result.getData().size() == 1 &&
|
||||||
|
result.getData().get(0) instanceof String
|
||||||
|
);
|
||||||
|
|
||||||
|
// remote server doesn't exist
|
||||||
|
result = mActivity.createShare(
|
||||||
|
mFullPath2FileToShare,
|
||||||
|
ShareType.FEDERATED,
|
||||||
|
"no_exist",
|
||||||
|
false,
|
||||||
|
"",
|
||||||
|
31);
|
||||||
|
assertFalse(result.isSuccess());
|
||||||
|
assertEquals(
|
||||||
|
RemoteOperationResult.ResultCode.SHARE_WRONG_PARAMETER,
|
||||||
|
result.getCode()
|
||||||
|
);
|
||||||
|
assertTrue( // error message from server as part of the result
|
||||||
|
result.getData().size() == 1 &&
|
||||||
|
result.getData().get(0) instanceof String
|
||||||
|
);
|
||||||
|
|
||||||
|
// file doesn't exist
|
||||||
|
result = mActivity.createShare(
|
||||||
|
mFullPath2NonExistentFile,
|
||||||
|
ShareType.FEDERATED,
|
||||||
|
"admin@" + remoteDomain,
|
||||||
|
false,
|
||||||
|
"",
|
||||||
|
31);
|
||||||
|
assertFalse(result.isSuccess());
|
||||||
|
assertEquals(
|
||||||
|
RemoteOperationResult.ResultCode.SHARE_NOT_FOUND,
|
||||||
|
result.getCode()
|
||||||
|
);
|
||||||
|
assertTrue( // error message from server as part of the result
|
||||||
|
result.getData().size() == 1 &&
|
||||||
|
result.getData().get(0) instanceof String
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
|
@ -69,7 +69,7 @@ public class GetShareesTest extends RemoteTest {
|
|||||||
|
|
||||||
private static final String LOG_TAG = GetShareesTest.class.getCanonicalName();
|
private static final String LOG_TAG = GetShareesTest.class.getCanonicalName();
|
||||||
|
|
||||||
String mServerUri, mUser, mPass;
|
String mServerUri, mUser, mPass, mServerUri2;
|
||||||
OwnCloudClient mClient = null;
|
OwnCloudClient mClient = null;
|
||||||
|
|
||||||
public GetShareesTest() {
|
public GetShareesTest() {
|
||||||
@ -191,6 +191,59 @@ public class GetShareesTest extends RemoteTest {
|
|||||||
assertTrue(!result.isSuccess() && result.getHttpCode() == HttpStatus.SC_BAD_REQUEST);
|
assertTrue(!result.isSuccess() && result.getHttpCode() == HttpStatus.SC_BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test get federated sharees
|
||||||
|
*
|
||||||
|
* Requires OC server 8.2 or later
|
||||||
|
*/
|
||||||
|
public void testGetFederatedShareesOperation() {
|
||||||
|
Log.v(LOG_TAG, "testGetFederatedSharees in");
|
||||||
|
|
||||||
|
/// successful cases
|
||||||
|
|
||||||
|
// search for sharees including "@"
|
||||||
|
GetRemoteShareesOperation getShareesOperation = new GetRemoteShareesOperation("@", 1, 50);
|
||||||
|
RemoteOperationResult result = getShareesOperation.execute(mClient);
|
||||||
|
JSONObject resultItem;
|
||||||
|
JSONObject value;
|
||||||
|
int type;
|
||||||
|
int fedCount = 0;
|
||||||
|
assertTrue(result.isSuccess() && result.getData().size() > 0);
|
||||||
|
try {
|
||||||
|
for (int i=0; i<result.getData().size(); i++) {
|
||||||
|
resultItem = (JSONObject) result.getData().get(i);
|
||||||
|
value = resultItem.getJSONObject(GetRemoteShareesOperation.NODE_VALUE);
|
||||||
|
type = value.getInt(GetRemoteShareesOperation.PROPERTY_SHARE_TYPE);
|
||||||
|
if (type == ShareType.FEDERATED.getValue()) {
|
||||||
|
fedCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertTrue(fedCount > 0);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
AssertionFailedError afe = new AssertionFailedError(e.getLocalizedMessage());
|
||||||
|
afe.setStackTrace(e.getStackTrace());
|
||||||
|
throw afe;
|
||||||
|
}
|
||||||
|
|
||||||
|
// search for 'admin' sharee from external server - expecting at least 1 result
|
||||||
|
String remoteSharee = "admin@" + mServerUri2.split("//")[1];
|
||||||
|
getShareesOperation = new GetRemoteShareesOperation(remoteSharee, 1, 50);
|
||||||
|
result = getShareesOperation.execute(mClient);
|
||||||
|
assertTrue(result.isSuccess() && result.getData().size() > 0);
|
||||||
|
|
||||||
|
|
||||||
|
/// failed cases
|
||||||
|
|
||||||
|
// search for sharees including wrong page values
|
||||||
|
getShareesOperation = new GetRemoteShareesOperation("@", 0, 50);
|
||||||
|
result = getShareesOperation.execute(mClient);
|
||||||
|
assertTrue(!result.isSuccess() && result.getHttpCode() == HttpStatus.SC_BAD_REQUEST);
|
||||||
|
|
||||||
|
getShareesOperation = new GetRemoteShareesOperation("@", 1, 0);
|
||||||
|
result = getShareesOperation.execute(mClient);
|
||||||
|
assertTrue(!result.isSuccess() && result.getHttpCode() == HttpStatus.SC_BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
Log.v(LOG_TAG, "Deleting remote fixture...");
|
Log.v(LOG_TAG, "Deleting remote fixture...");
|
||||||
@ -203,6 +256,7 @@ public class GetShareesTest extends RemoteTest {
|
|||||||
Log.v(LOG_TAG, "Setting up client instance to access OC server...");
|
Log.v(LOG_TAG, "Setting up client instance to access OC server...");
|
||||||
|
|
||||||
mServerUri = context.getString(R.string.server_base_url);
|
mServerUri = context.getString(R.string.server_base_url);
|
||||||
|
mServerUri2 = context.getString(R.string.server_base_url_2);
|
||||||
mUser = context.getString(R.string.username);
|
mUser = context.getString(R.string.username);
|
||||||
mPass = context.getString(R.string.password);
|
mPass = context.getString(R.string.password);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user