-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
- Loading branch information
1 parent
12982fe
commit 48671c8
Showing
31 changed files
with
1,779 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "dav4jvm"] | ||
path = dav4jvm | ||
url = /home/tobi/projekt/github/bitfireAT/dav4jvm |
Submodule dav4jvm
added at
c61e4b
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
247 changes: 247 additions & 0 deletions
247
library/src/androidTest/java/com/owncloud/android/Dav4JVM.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,247 @@ | ||
/* | ||
* Nextcloud Android client application | ||
* | ||
* @author Tobias Kaminsky | ||
* Copyright (C) 2022 Tobias Kaminsky | ||
* Copyright (C) 2022 Nextcloud GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package com.owncloud.android | ||
|
||
import at.bitfire.dav4jvm.DavResource | ||
import at.bitfire.dav4jvm.Response | ||
import at.bitfire.dav4jvm.property.CreationDate | ||
import com.nextcloud.common.NextcloudAuthenticator | ||
import com.owncloud.android.lib.common.network.WebdavUtils | ||
import com.owncloud.android.lib.common.utils.WebDavFileUtils | ||
import com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation | ||
import com.owncloud.android.lib.resources.files.ReadFolderRemoteOperation | ||
import com.owncloud.android.lib.resources.files.SearchRemoteOperation | ||
import com.owncloud.android.lib.resources.files.ToggleFavoriteRemoteOperation | ||
import com.owncloud.android.lib.resources.files.UploadFileRemoteOperation | ||
import com.owncloud.android.lib.resources.files.model.RemoteFile | ||
import com.owncloud.android.lib.resources.files.webdav.NCFavorite | ||
import com.owncloud.android.lib.resources.shares.CreateShareRemoteOperation | ||
import com.owncloud.android.lib.resources.shares.OCShare | ||
import com.owncloud.android.lib.resources.shares.ShareType | ||
import com.owncloud.android.lib.resources.status.OCCapability | ||
import okhttp3.HttpUrl.Companion.toHttpUrl | ||
import org.apache.jackrabbit.webdav.DavConstants | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Test | ||
import java.io.IOException | ||
|
||
/* | ||
can be removed after fully switching to dav4jvm as other tests should cover it | ||
*/ | ||
class Dav4JVM : AbstractIT() { | ||
@Test | ||
@Throws(IOException::class) | ||
fun singlePropfind() { | ||
val path = "/testFolder/" | ||
|
||
// create folder | ||
CreateFolderRemoteOperation( | ||
path, | ||
true | ||
).execute(client).isSuccess | ||
|
||
// verify folder | ||
assertTrue(ReadFolderRemoteOperation(path).execute(client).isSuccess) | ||
|
||
// add favorite | ||
assertTrue(ToggleFavoriteRemoteOperation(true, path).execute(client).isSuccess) | ||
|
||
// share it | ||
assertTrue( | ||
CreateShareRemoteOperation( | ||
path, | ||
ShareType.USER, | ||
"admin", | ||
false, | ||
"", | ||
OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER, | ||
true | ||
).execute(client) | ||
.isSuccess | ||
) | ||
|
||
// do old read folder operation to compare data against it | ||
val result = ReadFolderRemoteOperation(path).execute(client).data as List<RemoteFile> | ||
val oldRemoteFile = result[0] | ||
|
||
// new | ||
val httpUrl = (nextcloudClient.filesDavUri.toString() + path).toHttpUrl() | ||
|
||
var davResponse: Response? = null | ||
|
||
val memberElements: MutableList<Response> = ArrayList() | ||
var rootElement: Response? = null | ||
|
||
// disable redirect | ||
val client = nextcloudClient.client | ||
.newBuilder() | ||
.followRedirects(false) | ||
.authenticator(NextcloudAuthenticator(nextcloudClient.credentials, "Authorization")) | ||
.build() | ||
|
||
// register custom property | ||
WebdavUtils.registerCustomFactories() | ||
|
||
DavResource(client, httpUrl) | ||
.propfind( | ||
DavConstants.DEPTH_1, | ||
*WebdavUtils.getAllPropertiesList() | ||
) { response: Response, hrefRelation: Response.HrefRelation? -> | ||
davResponse = response | ||
when (hrefRelation) { | ||
Response.HrefRelation.MEMBER -> memberElements.add(response) | ||
Response.HrefRelation.SELF -> rootElement = response | ||
Response.HrefRelation.OTHER -> {} | ||
else -> {} | ||
} | ||
} | ||
|
||
assertTrue(davResponse?.isSuccess() == true) | ||
assertTrue(rootElement != null) | ||
assertEquals(0, memberElements.size) | ||
|
||
val remoteFile = WebDavFileUtils().parseResponse(rootElement, nextcloudClient.filesDavUri) | ||
|
||
val date = davResponse?.get(CreationDate::class.java) | ||
assertEquals( | ||
oldRemoteFile.creationTimestamp, | ||
(WebdavUtils.parseResponseDate(date?.creationDate)?.time ?: 0) / 1000 | ||
) | ||
|
||
assertTrue(oldRemoteFile.isFavorite) | ||
val favorite = davResponse?.get(NCFavorite::class.java) | ||
assertTrue(favorite?.isOcFavorite == true) | ||
|
||
assertEquals(oldRemoteFile.remotePath, remoteFile.remotePath) | ||
assertEquals(oldRemoteFile.mimeType, remoteFile.mimeType) | ||
assertEquals(oldRemoteFile.length, remoteFile.length) | ||
assertEquals(oldRemoteFile.creationTimestamp, remoteFile.creationTimestamp) | ||
// assertEquals(oldRemoteFile.modifiedTimestamp, remoteFile.modifiedTimestamp) | ||
assertEquals(oldRemoteFile.uploadTimestamp, remoteFile.uploadTimestamp) | ||
assertEquals(oldRemoteFile.etag, remoteFile.etag) | ||
assertEquals(oldRemoteFile.permissions, remoteFile.permissions) | ||
assertEquals(oldRemoteFile.remoteId, remoteFile.remoteId) | ||
assertEquals(oldRemoteFile.size, remoteFile.size) | ||
assertEquals(oldRemoteFile.isFavorite, remoteFile.isFavorite) | ||
assertEquals(oldRemoteFile.isEncrypted, remoteFile.isEncrypted) | ||
assertEquals(oldRemoteFile.mountType, remoteFile.mountType) | ||
assertEquals(oldRemoteFile.ownerId, remoteFile.ownerId) | ||
assertEquals(oldRemoteFile.ownerDisplayName, remoteFile.ownerDisplayName) | ||
assertEquals(oldRemoteFile.unreadCommentsCount, remoteFile.unreadCommentsCount) | ||
assertEquals(oldRemoteFile.isHasPreview, remoteFile.isHasPreview) | ||
assertEquals(oldRemoteFile.note, remoteFile.note) | ||
assertEquals(oldRemoteFile.sharees.size, remoteFile.sharees.size) | ||
assertEquals(oldRemoteFile.richWorkspace, remoteFile.richWorkspace) | ||
assertEquals(oldRemoteFile.isLocked, remoteFile.isLocked) | ||
assertEquals(oldRemoteFile.lockType, remoteFile.lockType) | ||
assertEquals(oldRemoteFile.lockOwner, remoteFile.lockOwner) | ||
assertEquals(oldRemoteFile.lockOwnerDisplayName, remoteFile.lockOwnerDisplayName) | ||
assertEquals(oldRemoteFile.lockTimestamp, remoteFile.lockTimestamp) | ||
assertEquals(oldRemoteFile.lockOwnerEditor, remoteFile.lockOwnerEditor) | ||
assertEquals(oldRemoteFile.lockTimeout, remoteFile.lockTimeout) | ||
assertEquals(oldRemoteFile.lockToken, remoteFile.lockToken) | ||
assertEquals(oldRemoteFile.localId, remoteFile.localId) | ||
} | ||
|
||
@Test | ||
fun search() { | ||
val path = "/testFolder/" | ||
|
||
// create folder | ||
assertTrue( | ||
CreateFolderRemoteOperation( | ||
path, | ||
true | ||
).execute(client).isSuccess | ||
) | ||
|
||
// create file | ||
val filePath = createFile("text") | ||
val remotePath = "/test.md" | ||
|
||
assertTrue( | ||
UploadFileRemoteOperation( | ||
filePath, | ||
remotePath, | ||
"text/markdown", | ||
"", | ||
RANDOM_MTIME, | ||
System.currentTimeMillis(), | ||
true | ||
).execute(client).isSuccess | ||
) | ||
|
||
WebdavUtils.registerCustomFactories() | ||
|
||
var ror = SearchRemoteOperation( | ||
"test", | ||
SearchRemoteOperation.SearchType.FILE_SEARCH, | ||
false, | ||
OCCapability(23, 0, 0) | ||
).execute( | ||
client | ||
) | ||
|
||
assertTrue(ror.isSuccess) | ||
assertEquals(2, ror.resultData.size) | ||
|
||
val oldRemoteFile = ror.resultData[0] | ||
assertEquals(path, oldRemoteFile.remotePath) | ||
|
||
ror = SearchRemoteOperation( | ||
"test", | ||
SearchRemoteOperation.SearchType.FILE_SEARCH, | ||
false, | ||
OCCapability(23, 0, 0) | ||
).execute( | ||
nextcloudClient | ||
) | ||
|
||
assertTrue(ror.isSuccess) | ||
assertEquals(2, ror.resultData.size) | ||
|
||
val remoteFile = ror.resultData[0] | ||
assertEquals(path, remoteFile.remotePath) | ||
|
||
assertEquals(oldRemoteFile.remoteId, remoteFile.remoteId) | ||
} | ||
|
||
@Test | ||
fun propPatch() { | ||
val path = "/testFolder/" | ||
|
||
// create folder | ||
assertTrue(CreateFolderRemoteOperation(path, true).execute(client).isSuccess) | ||
|
||
// make it favorite | ||
assertTrue( | ||
ToggleFavoriteRemoteOperation(true, path).execute(nextcloudClient).isSuccess | ||
) | ||
|
||
val result = ReadFolderRemoteOperation(path).execute(client) | ||
assertTrue(result.isSuccess) | ||
val list = result.data as List<RemoteFile> | ||
assertTrue(list[0].isFavorite) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.