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 @@ -42,7 +42,7 @@ public void generateAppPassword() {

client.setCredentials(newOwnCloudCredentials);

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

// using app password to generate new password should fail
assertFalse(new GenerateAppPasswordRemoteOperation().execute(client).isSuccess());
Expand Down
19 changes: 12 additions & 7 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 All @@ -98,10 +99,15 @@ public static void beforeAll() throws InterruptedException,
// and blocks all other clients, e.g. 3rd party apps using this lib
OwnCloudClientManagerFactory.setUserAgent("Mozilla/5.0 (Android) Nextcloud-android/3.13.0");

// Account 1
client = OwnCloudClientFactory.createOwnCloudClient(url, context, true);
client.setCredentials(new OwnCloudBasicCredentials(loginName, password));
client.setUserId(loginName); // for test same as userId

String userId = loginName; // for test same as userId
String credentials = Credentials.basic(loginName, password);
nextcloudClient = new NextcloudClient(url, userId, credentials, context);

// second user to test internal sharing
String loginName2 = arguments.getString("TEST_SERVER_USERNAME2");
String password2 = arguments.getString("TEST_SERVER_PASSWORD2");
Expand All @@ -110,9 +116,8 @@ public static void beforeAll() throws InterruptedException,
client2.setCredentials(new OwnCloudBasicCredentials(loginName2, password2));
client2.setUserId(loginName2); // for test same as userId

String userId = loginName; // for test same as userId
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 @@ -264,12 +269,12 @@ 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()) {
Expand Down
37 changes: 19 additions & 18 deletions library/src/androidTest/java/com/owncloud/android/FileIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.owncloud.android.lib.resources.status.NextcloudVersion;
import com.owncloud.android.lib.resources.status.OCCapability;

import org.jetbrains.annotations.NotNull;
import org.junit.Test;

import java.util.ArrayList;
Expand All @@ -43,7 +44,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 +72,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 +95,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);
RemoteOperationResult<@NotNull List<? extends @NotNull RemoteFile>> 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 = (RemoteFile) result.getResultData().get(i);

if (path.equals(child.getRemotePath())) {
assertEquals(0, child.getSharees().length);
Expand All @@ -117,7 +118,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,7 +130,7 @@ 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);
Expand All @@ -149,7 +150,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,7 +170,7 @@ public void testShareToGroupSharees() {
.execute(client).isSuccess());

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

RemoteFile parentFolder = (RemoteFile) result.getData().get(0);
Expand All @@ -190,7 +191,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,7 +205,7 @@ public void testOneSharees() {
.execute(client).isSuccess());

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

RemoteFile parentFolder = (RemoteFile) result.getData().get(0);
Expand All @@ -225,7 +226,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,7 +250,7 @@ public void testTwoShareesOnParent() {
.execute(client).isSuccess());

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

RemoteFile parentFolder = (RemoteFile) result.getData().get(0);
Expand All @@ -273,7 +274,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,7 +298,7 @@ public void testTwoSharees() {
.execute(client).isSuccess());

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

RemoteFile folder = (RemoteFile) result.getData().get(0);
Expand All @@ -315,7 +316,7 @@ public void testLocalID() {
String path = "/testFolder/";
assertTrue(new CreateFolderRemoteOperation(path, true).execute(client).isSuccess());

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

RemoteFile folder = (RemoteFile) result.getData().get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@ 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.common.network.WebdavEntry
import com.owncloud.android.lib.resources.status.NextcloudVersion
import com.owncloud.android.lib.resources.tags.CreateTagRemoteOperation
import com.owncloud.android.lib.resources.tags.GetTagsRemoteOperation
import com.owncloud.android.lib.resources.tags.GetTagsRemoteOperationIT.Companion.TAG_URL
import com.owncloud.android.lib.resources.tags.PutTagRemoteOperation
import junit.framework.TestCase
import org.apache.commons.httpclient.HttpStatus
import org.apache.jackrabbit.webdav.client.methods.PropPatchMethod
import org.apache.jackrabbit.webdav.property.DavPropertyNameSet
import org.apache.jackrabbit.webdav.property.DavPropertySet
import org.apache.jackrabbit.webdav.property.DefaultDavProperty
import org.apache.jackrabbit.webdav.xml.Namespace
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
Expand All @@ -24,6 +32,7 @@ class ReadFolderRemoteOperationIT : AbstractIT() {
}

@Test
@Suppress("LongMethod")
fun readRemoteFolderWithContent() {
val remotePath = "/test/"

Expand All @@ -37,65 +46,96 @@ 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)
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)
assertEquals(0, remoteFile.tags.size)

// create tag
val tag1 = "a" + RandomStringGenerator.make(TAG_LENGTH)
val tag2 = "b" + RandomStringGenerator.make(TAG_LENGTH)
assertTrue(CreateTagRemoteOperation(tag1).execute(nextcloudClient).isSuccess)
assertTrue(CreateTagRemoteOperation(tag2).execute(nextcloudClient).isSuccess)
val name1 = "a" + RandomStringGenerator.make(TAG_LENGTH)
val color1 = "#001122"

val name2 = "b" + RandomStringGenerator.make(TAG_LENGTH)

assertTrue(CreateTagRemoteOperation(name1).execute(nextcloudClient).isSuccess)
assertTrue(CreateTagRemoteOperation(name2).execute(nextcloudClient).isSuccess)

// list tags
val tags = GetTagsRemoteOperation().execute(client).resultData
val tag1 = tags.find { it.name == name1 }
val tag2 = tags.find { it.name == name2 }

// add color
val newProps = DavPropertySet()
newProps.add(
DefaultDavProperty(
"nc:color",
color1.replace("#", ""),
Namespace.getNamespace(WebdavEntry.NAMESPACE_NC)
)
)
val propPatchMethod =
PropPatchMethod(
client2.baseUri.toString() + TAG_URL + tag1?.id,
newProps,
DavPropertyNameSet()
)
val propPatchStatus = client2.executeMethod(propPatchMethod)
propPatchMethod.releaseConnection()
TestCase.assertEquals(HttpStatus.SC_MULTI_STATUS, propPatchStatus)

// add tag
assertTrue(
PutTagRemoteOperation(
tags[0].id,
tag1?.id.orEmpty(),
remoteFile.localId
).execute(nextcloudClient).isSuccess
)
assertTrue(
PutTagRemoteOperation(
tags[1].id,
tag2?.id.orEmpty(),
remoteFile.localId
).execute(nextcloudClient).isSuccess
)

// 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)
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)
assertEquals(2, remoteFile.tags.size)

remoteFile.tags.sortBy { it?.name }

// tag1
val resultTag1 = remoteFile.tags[0]
assertEquals(name1, resultTag1?.name)
assertEquals(color1, resultTag1?.color)

remoteFile.tags?.sortBy { it?.name }
assertEquals(tag1, remoteFile.tags?.get(0)?.name)
assertEquals(tag2, remoteFile.tags?.get(1)?.name)
// tag2
val resultTag2 = remoteFile.tags[1]
assertEquals(name2, resultTag2?.name)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class UploadFileRemoteOperationIT : AbstractIT() {
)

// ReadFolderRemoteOperation
var result2 = ReadFolderRemoteOperation(remotePath).execute(client)
var result2 = ReadFolderRemoteOperation(remotePath).execute(nextcloudClient)
assertTrue(result2.isSuccess)

remoteFile = result2.data[0] as RemoteFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class DeleteTagRemoteOperationIT : AbstractIT() {
)

// verify the tag is on the folder
var rootMetadata = ReadFolderRemoteOperation("/").execute(client)
var rootMetadata = ReadFolderRemoteOperation("/").execute(nextcloudClient)
var folderTags =
(rootMetadata.data as ArrayList<RemoteFile>)
.find { it.remotePath == folder }
Expand All @@ -70,7 +70,7 @@ class DeleteTagRemoteOperationIT : AbstractIT() {
)

// verify the tag is no longer on the folder
rootMetadata = ReadFolderRemoteOperation("/").execute(client)
rootMetadata = ReadFolderRemoteOperation("/").execute(nextcloudClient)
folderTags =
(rootMetadata.data as ArrayList<RemoteFile>)
.find { it.remotePath == folder }
Expand Down
Loading