Skip to content
Merged
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
@@ -0,0 +1,50 @@
package com.nextcloud.common

import android.net.Uri
import org.junit.Assert
import org.junit.Before
import org.junit.Test

class NextcloudUriDelegateIT {

lateinit var sut: NextcloudUriDelegate

@Before
fun setUp() {
sut = NextcloudUriDelegate(Uri.parse(BASEURL), USERID)
}

@Test
fun testFilesDavUri_leadingSlashInPath() {
val expected = "$EXPECTED_FILES_DAV/path/to/file.txt"
val actual = sut.getFilesDavUri("/path/to/file.txt")
Assert.assertEquals("Wrong URL", expected, actual)
}

@Test
fun testFilesDavUri_noLeadingSlashInPath() {
val expected = "$EXPECTED_FILES_DAV/path/to/file.txt"
val actual = sut.getFilesDavUri("path/to/file.txt")
Assert.assertEquals("Wrong URL", expected, actual)
}

@Test
fun testFilesDavUri_emptyPath() {
val expected = "$EXPECTED_FILES_DAV/"
val actual = sut.getFilesDavUri("")
Assert.assertEquals("Wrong URL", expected, actual)
}

@Test
fun testFilesDavUri_rootPath() {
val expected = "$EXPECTED_FILES_DAV/"
val actual = sut.getFilesDavUri("/")
Assert.assertEquals("Wrong URL", expected, actual)
}

companion object {
private const val USERID = "user"
private const val BASEURL = "http://test.localhost"
private const val EXPECTED_FILES_DAV = "$BASEURL/remote.php/dav/files/$USERID"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class NextcloudUriDelegate(baseUri: Uri, var userId: String?) : NextcloudUriProv
get() = Uri.parse(baseUri.toString() + AccountUtils.WEBDAV_PATH_9_0)

override fun getFilesDavUri(path: String): String {
return "$filesDavUri/${WebdavUtils.encodePath(path)}"
// encodePath already adds leading slash if needed
return "$filesDavUri${WebdavUtils.encodePath(path)}"
}

override fun getCommentsUri(fileId: String): String {
Expand Down