Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import com.owncloud.android.lib.common.OwnCloudBasicCredentials;
import com.owncloud.android.lib.common.OwnCloudCredentials;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.files.ReadFolderRemoteOperation;
import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation;

import org.junit.Test;

Expand All @@ -42,7 +42,7 @@ public void generateAppPassword() {

client.setCredentials(newOwnCloudCredentials);

assertTrue(new ReadFolderRemoteOperation("/").execute(client).isSuccess());
assertTrue(new ReadFileRemoteOperation("/").execute(client).isSuccess());

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is ReadFolderRemoteOperation needed here?


// using app password to generate new password should fail
assertFalse(new GenerateAppPasswordRemoteOperation().execute(client).isSuccess());
Expand Down
25 changes: 12 additions & 13 deletions library/src/androidTest/java/com/owncloud/android/AbstractIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public abstract class AbstractIT {
public static OwnCloudClient client;
public static OwnCloudClient client2;
protected static NextcloudClient nextcloudClient;
protected static NextcloudClient nextcloudClient2;
protected static Context context;
protected static Uri url;

Expand Down Expand Up @@ -112,6 +113,9 @@ public static void beforeAll() throws InterruptedException,
String credentials = Credentials.basic(loginName, password);
nextcloudClient = new NextcloudClient(url, userId, credentials, context);

String credentials2 = Credentials.basic(loginName2, password2);
nextcloudClient2 = new NextcloudClient(url, loginName2, credentials2, context);

waitForServer(client, url);
testConnection();
}
Expand Down Expand Up @@ -262,20 +266,15 @@ public static File extractAsset(String fileName, Context context) throws IOExcep

@After
public void after() {
removeOnClient(client);
removeOnClient(client2);
removeOnClient(nextcloudClient);
removeOnClient(nextcloudClient2);
}

private void removeOnClient(OwnCloudClient client) {
final var result = new ReadFolderRemoteOperation("/").execute(client);
private void removeOnClient(NextcloudClient nextcloudClient) {
final var result = new ReadFolderRemoteOperation("/").execute(nextcloudClient);
assertTrue(result.getLogMessage(context), result.isSuccess());

for (Object object : result.getData()) {
if (!(object instanceof RemoteFile remoteFile)) {
Log_OC.d(TAG, "Skipping removeOnClient: not instance of RemoteFile");
continue;
}

for (RemoteFile remoteFile : result.getResultData()) {
String remotePath = remoteFile.getRemotePath();

if ("/".equals(remotePath) || remoteFile.getMountType() == WebdavEntry.MountType.GROUP) {
Expand All @@ -284,7 +283,7 @@ private void removeOnClient(OwnCloudClient client) {
}

if (remoteFile.isEncrypted()) {
assertTrue(toggleEncryptionRemoteFile(remoteFile));
assertTrue(toggleEncryptionRemoteFile(remoteFile, nextcloudClient));
}

if (remoteFile.isLocked() && remotePath != null) {
Expand All @@ -299,9 +298,9 @@ private void removeOnClient(OwnCloudClient client) {
Log_OC.d(TAG, "KeyStore file deletion result: " + isKeyStoreDeleted);
}

private boolean toggleEncryptionRemoteFile(RemoteFile remoteFile) {
private boolean toggleEncryptionRemoteFile(RemoteFile remoteFile, NextcloudClient nextcloudClient) {
final var operation = new ToggleEncryptionRemoteOperation(remoteFile.getLocalId(), remoteFile.getRemotePath(), false);
final var result = operation.execute(client);
final var result = operation.execute(nextcloudClient);
return result.isSuccess();
}

Expand Down
67 changes: 32 additions & 35 deletions library/src/androidTest/java/com/owncloud/android/FileIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import android.net.Uri;

import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation;
import com.owncloud.android.lib.resources.files.ReadFolderRemoteOperation;
import com.owncloud.android.lib.resources.files.RemoveFileRemoteOperation;
Expand Down Expand Up @@ -43,7 +42,7 @@ public void testCreateFolderSuccess() {
assertTrue(new CreateFolderRemoteOperation(path, true).execute(client).isSuccess());

// verify folder
assertTrue(new ReadFolderRemoteOperation(path).execute(client).isSuccess());
assertTrue(new ReadFolderRemoteOperation(path).execute(nextcloudClient).isSuccess());

// remove folder
assertTrue(new RemoveFileRemoteOperation(path).execute(client).isSuccess());
Expand Down Expand Up @@ -71,7 +70,7 @@ public void testCreateNonExistingSubFolder() {
assertTrue(new CreateFolderRemoteOperation(path, true).execute(client).isSuccess());

// verify folder
assertTrue(new ReadFolderRemoteOperation(path).execute(client).isSuccess());
assertTrue(new ReadFolderRemoteOperation(path).execute(nextcloudClient).isSuccess());

// remove folder
assertTrue(new RemoveFileRemoteOperation(top).execute(client).isSuccess());
Expand All @@ -94,17 +93,17 @@ public void testZeroSharees() {
// create & verify folder
String path = "/testFolder/";
assertTrue(new CreateFolderRemoteOperation(path, true).execute(client).isSuccess());
assertTrue(new ReadFolderRemoteOperation(path).execute(client).isSuccess());
assertTrue(new ReadFolderRemoteOperation(path).execute(nextcloudClient).isSuccess());

// verify
RemoteOperationResult result = new ReadFolderRemoteOperation("/").execute(client);
var result = new ReadFolderRemoteOperation("/").execute(nextcloudClient);
assertTrue(result.isSuccess());

RemoteFile parentFolder = (RemoteFile) result.getData().get(0);
RemoteFile parentFolder = result.getResultData().get(0);
assertEquals("/", parentFolder.getRemotePath());

for (int i = 1; i < result.getData().size(); i++) {
RemoteFile child = (RemoteFile) result.getData().get(i);
for (int i = 1; i < result.getResultData().size(); i++) {
RemoteFile child = result.getResultData().get(i);

if (path.equals(child.getRemotePath())) {
assertEquals(0, child.getSharees().length);
Expand All @@ -117,7 +116,7 @@ public void testShareViaLinkSharees() {
// create & verify folder
String path = "/testFolder/";
assertTrue(new CreateFolderRemoteOperation(path, true).execute(client).isSuccess());
assertTrue(new ReadFolderRemoteOperation(path).execute(client).isSuccess());
assertTrue(new ReadFolderRemoteOperation(path).execute(nextcloudClient).isSuccess());

// share folder
assertTrue(new CreateShareRemoteOperation(path,
Expand All @@ -129,16 +128,14 @@ public void testShareViaLinkSharees() {
.execute(client).isSuccess());

// verify
final var result = new ReadFolderRemoteOperation("/").execute(client);
final var result = new ReadFolderRemoteOperation("/").execute(nextcloudClient);
assertTrue(result.isSuccess());

RemoteFile parentFolder = (RemoteFile) result.getData().get(0);
RemoteFile parentFolder = result.getResultData().get(0);
assertEquals("/", parentFolder.getRemotePath());

for (Object item : result.getData()) {
if (item instanceof RemoteFile child &&
path.equals(child.getRemotePath()) &&
child.getSharees() != null) {
for (RemoteFile child : result.getResultData()) {
if (path.equals(child.getRemotePath()) && child.getSharees() != null) {
assertEquals(1, child.getSharees().length);
}
}
Expand All @@ -149,7 +146,7 @@ public void testShareToGroupSharees() {
// create & verify folder
String path = "/testFolder/";
assertTrue(new CreateFolderRemoteOperation(path, true).execute(client).isSuccess());
assertTrue(new ReadFolderRemoteOperation(path).execute(client).isSuccess());
assertTrue(new ReadFolderRemoteOperation(path).execute(nextcloudClient).isSuccess());

ShareeUser sharee = new ShareeUser("users", "", ShareType.GROUP);

Expand All @@ -169,14 +166,14 @@ public void testShareToGroupSharees() {
.execute(client).isSuccess());

// verify
RemoteOperationResult result = new ReadFolderRemoteOperation("/").execute(client);
var result = new ReadFolderRemoteOperation("/").execute(nextcloudClient);
assertTrue(result.isSuccess());

RemoteFile parentFolder = (RemoteFile) result.getData().get(0);
RemoteFile parentFolder = result.getResultData().get(0);
assertEquals("/", parentFolder.getRemotePath());

for (int i = 1; i < result.getData().size(); i++) {
RemoteFile child = (RemoteFile) result.getData().get(i);
for (int i = 1; i < result.getResultData().size(); i++) {
RemoteFile child = result.getResultData().get(i);

if (path.equals(child.getRemotePath())) {
assertEquals(1, child.getSharees().length);
Expand All @@ -190,7 +187,7 @@ public void testOneSharees() {
// create & verify folder
String path = "/testFolder/";
assertTrue(new CreateFolderRemoteOperation(path, true).execute(client).isSuccess());
assertTrue(new ReadFolderRemoteOperation(path).execute(client).isSuccess());
assertTrue(new ReadFolderRemoteOperation(path).execute(nextcloudClient).isSuccess());

ShareeUser sharee = new ShareeUser("user1", "User One", ShareType.USER);

Expand All @@ -204,14 +201,14 @@ public void testOneSharees() {
.execute(client).isSuccess());

// verify
RemoteOperationResult result = new ReadFolderRemoteOperation("/").execute(client);
var result = new ReadFolderRemoteOperation("/").execute(nextcloudClient);
assertTrue(result.isSuccess());

RemoteFile parentFolder = (RemoteFile) result.getData().get(0);
RemoteFile parentFolder = result.getResultData().get(0);
assertEquals("/", parentFolder.getRemotePath());

for (int i = 1; i < result.getData().size(); i++) {
RemoteFile child = (RemoteFile) result.getData().get(i);
for (int i = 1; i < result.getResultData().size(); i++) {
RemoteFile child = result.getResultData().get(i);

if (path.equals(child.getRemotePath())) {
assertEquals(1, child.getSharees().length);
Expand All @@ -225,7 +222,7 @@ public void testTwoShareesOnParent() {
// create & verify folder
String path = "/testFolder/";
assertTrue(new CreateFolderRemoteOperation(path, true).execute(client).isSuccess());
assertTrue(new ReadFolderRemoteOperation(path).execute(client).isSuccess());
assertTrue(new ReadFolderRemoteOperation(path).execute(nextcloudClient).isSuccess());

List<ShareeUser> sharees = new ArrayList<>();
sharees.add(new ShareeUser("user1", "User One", ShareType.USER));
Expand All @@ -249,14 +246,14 @@ public void testTwoShareesOnParent() {
.execute(client).isSuccess());

// verify
RemoteOperationResult result = new ReadFolderRemoteOperation("/").execute(client);
var result = new ReadFolderRemoteOperation("/").execute(nextcloudClient);
assertTrue(result.isSuccess());

RemoteFile parentFolder = (RemoteFile) result.getData().get(0);
RemoteFile parentFolder = result.getResultData().get(0);
assertEquals("/", parentFolder.getRemotePath());

for (int i = 1; i < result.getData().size(); i++) {
RemoteFile child = (RemoteFile) result.getData().get(i);
for (int i = 1; i < result.getResultData().size(); i++) {
RemoteFile child = result.getResultData().get(i);

if (path.equals(child.getRemotePath())) {
assertEquals(2, child.getSharees().length);
Expand All @@ -273,7 +270,7 @@ public void testTwoSharees() {
// create & verify folder
String path = "/testFolder/";
assertTrue(new CreateFolderRemoteOperation(path, true).execute(client).isSuccess());
assertTrue(new ReadFolderRemoteOperation(path).execute(client).isSuccess());
assertTrue(new ReadFolderRemoteOperation(path).execute(nextcloudClient).isSuccess());

List<ShareeUser> sharees = new ArrayList<>();
sharees.add(new ShareeUser("user1", "User One", ShareType.USER));
Expand All @@ -297,10 +294,10 @@ public void testTwoSharees() {
.execute(client).isSuccess());

// verify
RemoteOperationResult result = new ReadFolderRemoteOperation(path).execute(client);
var result = new ReadFolderRemoteOperation(path).execute(nextcloudClient);
assertTrue(result.isSuccess());

RemoteFile folder = (RemoteFile) result.getData().get(0);
RemoteFile folder = result.getResultData().get(0);
assertEquals(path, folder.getRemotePath());
assertEquals(2, folder.getSharees().length);

Expand All @@ -315,10 +312,10 @@ public void testLocalID() {
String path = "/testFolder/";
assertTrue(new CreateFolderRemoteOperation(path, true).execute(client).isSuccess());

RemoteOperationResult result = new ReadFolderRemoteOperation(path).execute(client);
var result = new ReadFolderRemoteOperation(path).execute(nextcloudClient);
assertTrue(result.isSuccess());

RemoteFile folder = (RemoteFile) result.getData().get(0);
RemoteFile folder = result.getResultData().get(0);

// we do this only here for testing, this might not work on large installations
int localId = Integer.parseInt(folder.getRemoteId().substring(0, 8).replaceAll("^0*", ""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class UpdateMetadataRemoteOperationIT : AbstractIT() {
remoteFolder!!.localId,
remoteFolder.remotePath,
true
).execute(client)
).execute(nextcloudClient)
.isSuccess
)

Expand Down Expand Up @@ -128,7 +128,7 @@ class UpdateMetadataRemoteOperationIT : AbstractIT() {
remoteFolder!!.localId,
remoteFolder.remotePath,
true
).execute(client)
).execute(nextcloudClient)
.isSuccess
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class ReadFileRemoteOperationIT : AbstractIT() {
remoteFile.localId,
remotePath,
true
).execute(client)
).execute(nextcloudClient)
.isSuccess
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package com.owncloud.android.lib.resources.files

import com.nextcloud.test.RandomStringGenerator
import com.owncloud.android.AbstractIT
import com.owncloud.android.lib.resources.files.model.RemoteFile
import com.owncloud.android.lib.resources.status.NextcloudVersion
import com.owncloud.android.lib.resources.tags.CreateTagRemoteOperation
import com.owncloud.android.lib.resources.tags.GetTagsRemoteOperation
Expand Down Expand Up @@ -37,21 +36,21 @@ class ReadFolderRemoteOperationIT : AbstractIT() {
.isSuccess
)

var result = ReadFolderRemoteOperation(remotePath).execute(client)
var result = ReadFolderRemoteOperation(remotePath).execute(nextcloudClient)

assertTrue(result.isSuccess)
assertEquals(2, result.data.size)
assertEquals(2, result.resultData.size)

// tag testing only on NC27+
testOnlyOnServer(NextcloudVersion.nextcloud_27)

// Folder
var remoteFolder = result.data[0] as RemoteFile
var remoteFolder = result.resultData[0]
assertEquals(remotePath, remoteFolder.remotePath)
assertEquals(0, remoteFolder.tags?.size)

// File
var remoteFile = result.data[1] as RemoteFile
var remoteFile = result.resultData[1]
assertEquals(remotePath + "1.txt", remoteFile.remotePath)
assertEquals(0, remoteFile.tags?.size)

Expand Down Expand Up @@ -79,18 +78,18 @@ class ReadFolderRemoteOperationIT : AbstractIT() {
)

// check again
result = ReadFolderRemoteOperation(remotePath).execute(client)
result = ReadFolderRemoteOperation(remotePath).execute(nextcloudClient)

assertTrue(result.isSuccess)
assertEquals(2, result.data.size)
assertEquals(2, result.resultData.size)

// Folder
remoteFolder = result.data[0] as RemoteFile
remoteFolder = result.resultData[0]
assertEquals(remotePath, remoteFolder.remotePath)
assertEquals(0, remoteFolder.tags?.size)

// File
remoteFile = result.data[1] as RemoteFile
remoteFile = result.resultData[1]
assertEquals(remotePath + "1.txt", remoteFile.remotePath)
assertEquals(2, remoteFile.tags?.size)

Expand Down
Loading
Loading