Skip to content

Commit 48671c8

Browse files
use dav4jvm search and proppatch
Signed-off-by: tobiasKaminsky <[email protected]>
1 parent 12982fe commit 48671c8

31 files changed

+1779
-117
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "dav4jvm"]
2+
path = dav4jvm
3+
url = /home/tobi/projekt/github/bitfireAT/dav4jvm

dav4jvm

Submodule dav4jvm added at c61e4b0

library/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ configurations {
5050
dependencies {
5151
implementation 'org.apache.jackrabbit:jackrabbit-webdav:2.13.5'
5252
api 'com.squareup.okhttp3:okhttp:5.0.0-alpha.10'
53-
implementation 'com.gitlab.bitfireAT:dav4jvm:2.1.3' // in transition phase, we use old and new libs
54-
implementation group: 'com.google.code.gson', name: 'gson', version: '2.10'
53+
implementation 'com.github.bitfireAT:dav4jvm:2.2' // in transition phase, we use old and new libs
54+
implementation group: 'com.google.code.gson', name: 'gson', version: '2.9.1'
5555
implementation 'androidx.annotation:annotation:1.5.0'
5656
compileOnly 'com.google.code.findbugs:annotations:3.0.1u2'
5757

library/src/androidTest/java/com/owncloud/android/AbstractIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public static void beforeAll() throws InterruptedException,
121121
String userId = loginName; // for test same as userId
122122
String credentials = Credentials.basic(loginName, password);
123123
nextcloudClient = new NextcloudClient(url, userId, credentials, context);
124+
nextcloudClient.setUserId(userId);
124125

125126
waitForServer(client, url);
126127
testConnection();
Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
/*
2+
* Nextcloud Android client application
3+
*
4+
* @author Tobias Kaminsky
5+
* Copyright (C) 2022 Tobias Kaminsky
6+
* Copyright (C) 2022 Nextcloud GmbH
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Affero General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
23+
package com.owncloud.android
24+
25+
import at.bitfire.dav4jvm.DavResource
26+
import at.bitfire.dav4jvm.Response
27+
import at.bitfire.dav4jvm.property.CreationDate
28+
import com.nextcloud.common.NextcloudAuthenticator
29+
import com.owncloud.android.lib.common.network.WebdavUtils
30+
import com.owncloud.android.lib.common.utils.WebDavFileUtils
31+
import com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation
32+
import com.owncloud.android.lib.resources.files.ReadFolderRemoteOperation
33+
import com.owncloud.android.lib.resources.files.SearchRemoteOperation
34+
import com.owncloud.android.lib.resources.files.ToggleFavoriteRemoteOperation
35+
import com.owncloud.android.lib.resources.files.UploadFileRemoteOperation
36+
import com.owncloud.android.lib.resources.files.model.RemoteFile
37+
import com.owncloud.android.lib.resources.files.webdav.NCFavorite
38+
import com.owncloud.android.lib.resources.shares.CreateShareRemoteOperation
39+
import com.owncloud.android.lib.resources.shares.OCShare
40+
import com.owncloud.android.lib.resources.shares.ShareType
41+
import com.owncloud.android.lib.resources.status.OCCapability
42+
import okhttp3.HttpUrl.Companion.toHttpUrl
43+
import org.apache.jackrabbit.webdav.DavConstants
44+
import org.junit.Assert.assertEquals
45+
import org.junit.Assert.assertTrue
46+
import org.junit.Test
47+
import java.io.IOException
48+
49+
/*
50+
can be removed after fully switching to dav4jvm as other tests should cover it
51+
*/
52+
class Dav4JVM : AbstractIT() {
53+
@Test
54+
@Throws(IOException::class)
55+
fun singlePropfind() {
56+
val path = "/testFolder/"
57+
58+
// create folder
59+
CreateFolderRemoteOperation(
60+
path,
61+
true
62+
).execute(client).isSuccess
63+
64+
// verify folder
65+
assertTrue(ReadFolderRemoteOperation(path).execute(client).isSuccess)
66+
67+
// add favorite
68+
assertTrue(ToggleFavoriteRemoteOperation(true, path).execute(client).isSuccess)
69+
70+
// share it
71+
assertTrue(
72+
CreateShareRemoteOperation(
73+
path,
74+
ShareType.USER,
75+
"admin",
76+
false,
77+
"",
78+
OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER,
79+
true
80+
).execute(client)
81+
.isSuccess
82+
)
83+
84+
// do old read folder operation to compare data against it
85+
val result = ReadFolderRemoteOperation(path).execute(client).data as List<RemoteFile>
86+
val oldRemoteFile = result[0]
87+
88+
// new
89+
val httpUrl = (nextcloudClient.filesDavUri.toString() + path).toHttpUrl()
90+
91+
var davResponse: Response? = null
92+
93+
val memberElements: MutableList<Response> = ArrayList()
94+
var rootElement: Response? = null
95+
96+
// disable redirect
97+
val client = nextcloudClient.client
98+
.newBuilder()
99+
.followRedirects(false)
100+
.authenticator(NextcloudAuthenticator(nextcloudClient.credentials, "Authorization"))
101+
.build()
102+
103+
// register custom property
104+
WebdavUtils.registerCustomFactories()
105+
106+
DavResource(client, httpUrl)
107+
.propfind(
108+
DavConstants.DEPTH_1,
109+
*WebdavUtils.getAllPropertiesList()
110+
) { response: Response, hrefRelation: Response.HrefRelation? ->
111+
davResponse = response
112+
when (hrefRelation) {
113+
Response.HrefRelation.MEMBER -> memberElements.add(response)
114+
Response.HrefRelation.SELF -> rootElement = response
115+
Response.HrefRelation.OTHER -> {}
116+
else -> {}
117+
}
118+
}
119+
120+
assertTrue(davResponse?.isSuccess() == true)
121+
assertTrue(rootElement != null)
122+
assertEquals(0, memberElements.size)
123+
124+
val remoteFile = WebDavFileUtils().parseResponse(rootElement, nextcloudClient.filesDavUri)
125+
126+
val date = davResponse?.get(CreationDate::class.java)
127+
assertEquals(
128+
oldRemoteFile.creationTimestamp,
129+
(WebdavUtils.parseResponseDate(date?.creationDate)?.time ?: 0) / 1000
130+
)
131+
132+
assertTrue(oldRemoteFile.isFavorite)
133+
val favorite = davResponse?.get(NCFavorite::class.java)
134+
assertTrue(favorite?.isOcFavorite == true)
135+
136+
assertEquals(oldRemoteFile.remotePath, remoteFile.remotePath)
137+
assertEquals(oldRemoteFile.mimeType, remoteFile.mimeType)
138+
assertEquals(oldRemoteFile.length, remoteFile.length)
139+
assertEquals(oldRemoteFile.creationTimestamp, remoteFile.creationTimestamp)
140+
// assertEquals(oldRemoteFile.modifiedTimestamp, remoteFile.modifiedTimestamp)
141+
assertEquals(oldRemoteFile.uploadTimestamp, remoteFile.uploadTimestamp)
142+
assertEquals(oldRemoteFile.etag, remoteFile.etag)
143+
assertEquals(oldRemoteFile.permissions, remoteFile.permissions)
144+
assertEquals(oldRemoteFile.remoteId, remoteFile.remoteId)
145+
assertEquals(oldRemoteFile.size, remoteFile.size)
146+
assertEquals(oldRemoteFile.isFavorite, remoteFile.isFavorite)
147+
assertEquals(oldRemoteFile.isEncrypted, remoteFile.isEncrypted)
148+
assertEquals(oldRemoteFile.mountType, remoteFile.mountType)
149+
assertEquals(oldRemoteFile.ownerId, remoteFile.ownerId)
150+
assertEquals(oldRemoteFile.ownerDisplayName, remoteFile.ownerDisplayName)
151+
assertEquals(oldRemoteFile.unreadCommentsCount, remoteFile.unreadCommentsCount)
152+
assertEquals(oldRemoteFile.isHasPreview, remoteFile.isHasPreview)
153+
assertEquals(oldRemoteFile.note, remoteFile.note)
154+
assertEquals(oldRemoteFile.sharees.size, remoteFile.sharees.size)
155+
assertEquals(oldRemoteFile.richWorkspace, remoteFile.richWorkspace)
156+
assertEquals(oldRemoteFile.isLocked, remoteFile.isLocked)
157+
assertEquals(oldRemoteFile.lockType, remoteFile.lockType)
158+
assertEquals(oldRemoteFile.lockOwner, remoteFile.lockOwner)
159+
assertEquals(oldRemoteFile.lockOwnerDisplayName, remoteFile.lockOwnerDisplayName)
160+
assertEquals(oldRemoteFile.lockTimestamp, remoteFile.lockTimestamp)
161+
assertEquals(oldRemoteFile.lockOwnerEditor, remoteFile.lockOwnerEditor)
162+
assertEquals(oldRemoteFile.lockTimeout, remoteFile.lockTimeout)
163+
assertEquals(oldRemoteFile.lockToken, remoteFile.lockToken)
164+
assertEquals(oldRemoteFile.localId, remoteFile.localId)
165+
}
166+
167+
@Test
168+
fun search() {
169+
val path = "/testFolder/"
170+
171+
// create folder
172+
assertTrue(
173+
CreateFolderRemoteOperation(
174+
path,
175+
true
176+
).execute(client).isSuccess
177+
)
178+
179+
// create file
180+
val filePath = createFile("text")
181+
val remotePath = "/test.md"
182+
183+
assertTrue(
184+
UploadFileRemoteOperation(
185+
filePath,
186+
remotePath,
187+
"text/markdown",
188+
"",
189+
RANDOM_MTIME,
190+
System.currentTimeMillis(),
191+
true
192+
).execute(client).isSuccess
193+
)
194+
195+
WebdavUtils.registerCustomFactories()
196+
197+
var ror = SearchRemoteOperation(
198+
"test",
199+
SearchRemoteOperation.SearchType.FILE_SEARCH,
200+
false,
201+
OCCapability(23, 0, 0)
202+
).execute(
203+
client
204+
)
205+
206+
assertTrue(ror.isSuccess)
207+
assertEquals(2, ror.resultData.size)
208+
209+
val oldRemoteFile = ror.resultData[0]
210+
assertEquals(path, oldRemoteFile.remotePath)
211+
212+
ror = SearchRemoteOperation(
213+
"test",
214+
SearchRemoteOperation.SearchType.FILE_SEARCH,
215+
false,
216+
OCCapability(23, 0, 0)
217+
).execute(
218+
nextcloudClient
219+
)
220+
221+
assertTrue(ror.isSuccess)
222+
assertEquals(2, ror.resultData.size)
223+
224+
val remoteFile = ror.resultData[0]
225+
assertEquals(path, remoteFile.remotePath)
226+
227+
assertEquals(oldRemoteFile.remoteId, remoteFile.remoteId)
228+
}
229+
230+
@Test
231+
fun propPatch() {
232+
val path = "/testFolder/"
233+
234+
// create folder
235+
assertTrue(CreateFolderRemoteOperation(path, true).execute(client).isSuccess)
236+
237+
// make it favorite
238+
assertTrue(
239+
ToggleFavoriteRemoteOperation(true, path).execute(nextcloudClient).isSuccess
240+
)
241+
242+
val result = ReadFolderRemoteOperation(path).execute(client)
243+
assertTrue(result.isSuccess)
244+
val list = result.data as List<RemoteFile>
245+
assertTrue(list[0].isFavorite)
246+
}
247+
}

library/src/androidTest/java/com/owncloud/android/FileIT.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
*/
2727
package com.owncloud.android;
2828

29+
import static org.junit.Assert.assertEquals;
30+
import static org.junit.Assert.assertFalse;
31+
import static org.junit.Assert.assertTrue;
32+
2933
import android.net.Uri;
3034

3135
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
@@ -43,10 +47,6 @@
4347
import java.util.ArrayList;
4448
import java.util.List;
4549

46-
import static org.junit.Assert.assertEquals;
47-
import static org.junit.Assert.assertFalse;
48-
import static org.junit.Assert.assertTrue;
49-
5050
/**
5151
* Tests related to file operations
5252
*/
@@ -60,6 +60,7 @@ public void testCreateFolderSuccess() {
6060

6161
// verify folder
6262
assertTrue(new ReadFolderRemoteOperation(path).execute(client).isSuccess());
63+
assertTrue(new ReadFolderRemoteOperation(path).execute(nextcloudClient).isSuccess());
6364

6465
// remove folder
6566
assertTrue(new RemoveFileRemoteOperation(path).execute(client).isSuccess());

library/src/androidTest/java/com/owncloud/android/lib/resources/files/SearchRemoteOperationIT.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,22 +164,43 @@ public void noFavorites() {
164164
@Test
165165
public void oneFavorite() {
166166
String path = "/testFolder/";
167+
String path2 = "/testFolder2/";
167168

168169
// create folder, make it favorite
169170
new CreateFolderRemoteOperation(path, true).execute(client);
171+
new CreateFolderRemoteOperation(path2, true).execute(client);
170172
assertTrue(new ToggleFavoriteRemoteOperation(true, path).execute(client).isSuccess());
173+
assertTrue(new ToggleFavoriteRemoteOperation(true, path2).execute(nextcloudClient).isSuccess());
171174

172175
SearchRemoteOperation sut = new SearchRemoteOperation("",
173176
SearchRemoteOperation.SearchType.FAVORITE_SEARCH,
174177
false,
175178
capability);
176-
RemoteOperationResult<List<RemoteFile>> result = sut.execute(client);
179+
RemoteOperationResult<List<RemoteFile>> result = sut.execute(nextcloudClient);
177180

178181
// test
179182
assertTrue(result.isSuccess());
180-
assertEquals(1, result.getResultData().size());
183+
assertEquals(2, result.getResultData().size());
184+
181185
RemoteFile remoteFile = result.getResultData().get(0);
182186
assertEquals(path, remoteFile.getRemotePath());
187+
188+
RemoteFile remoteFile2 = result.getResultData().get(1);
189+
assertEquals(path2, remoteFile2.getRemotePath());
190+
191+
// unfavorite
192+
assertTrue(new ToggleFavoriteRemoteOperation(false, path).execute(client).isSuccess());
193+
assertTrue(new ToggleFavoriteRemoteOperation(false, path2).execute(nextcloudClient).isSuccess());
194+
195+
// test
196+
sut = new SearchRemoteOperation("",
197+
SearchRemoteOperation.SearchType.FAVORITE_SEARCH,
198+
false,
199+
capability);
200+
result = sut.execute(nextcloudClient);
201+
202+
assertTrue(result.isSuccess());
203+
assertEquals(0, result.getResultData().size());
183204
}
184205

185206
@Test

0 commit comments

Comments
 (0)