1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-07 16:06:08 +00:00

add basic test functionality for andorid library

This commit is contained in:
Christian Schabesberger 2020-09-15 13:51:56 +02:00 committed by Abel García de Prada
parent cc91ad9dde
commit 257cbcff03
2 changed files with 45 additions and 3 deletions

View File

@ -68,7 +68,7 @@ class GetRemoteStatusOperation : RemoteOperation<OwnCloudVersion>() {
return latestResult return latestResult
} }
private fun updateLocationWithRelativePath(oldLocation: String, redirectedLocation: String): String { fun updateLocationWithRedirectPath(oldLocation: String, redirectedLocation: String): String {
if(!redirectedLocation.startsWith("/")) if(!redirectedLocation.startsWith("/"))
return redirectedLocation return redirectedLocation
val oldLocation = URL(oldLocation) val oldLocation = URL(oldLocation)
@ -97,7 +97,7 @@ class GetRemoteStatusOperation : RemoteOperation<OwnCloudVersion>() {
return successfulConnection return successfulConnection
} }
var redirectedLocation = updateLocationWithRelativePath(baseUrlStr, latestResult.redirectedLocation) var redirectedLocation = updateLocationWithRedirectPath(baseUrlStr, latestResult.redirectedLocation)
while (!redirectedLocation.isNullOrEmpty() && !latestResult.isSuccess) { while (!redirectedLocation.isNullOrEmpty() && !latestResult.isSuccess) {
isRedirectToNonSecureConnection = isRedirectToNonSecureConnection =
isRedirectToNonSecureConnection || isRedirectToNonSecureConnection ||
@ -112,7 +112,7 @@ class GetRemoteStatusOperation : RemoteOperation<OwnCloudVersion>() {
status = client.executeHttpMethod(getMethod) status = client.executeHttpMethod(getMethod)
latestResult = RemoteOperationResult(getMethod) latestResult = RemoteOperationResult(getMethod)
redirectedLocation = updateLocationWithRelativePath(redirectedLocation, latestResult.redirectedLocation) redirectedLocation = updateLocationWithRedirectPath(redirectedLocation, latestResult.redirectedLocation)
} }
if (isSuccess(status)) { if (isSuccess(status)) {

View File

@ -0,0 +1,42 @@
package com.owncloud.android.lib
import com.owncloud.android.lib.resources.status.GetRemoteStatusOperation
import org.junit.Assert.assertEquals
import org.junit.Test
class GetRemoteStatusOperationTest {
private val remoteStatusOperation = GetRemoteStatusOperation()
@Test
fun `update location with an absolute path`() {
val newLocation = remoteStatusOperation.updateLocationWithRedirectPath(
"https://cloud.somewhere.com", "https://cloud.somewhere.com/subdir"
)
assertEquals("https://cloud.somewhere.com/subdir", newLocation)
}
@Test
fun `update location with a smaler aboslute path`() {
val newLocation = remoteStatusOperation.updateLocationWithRedirectPath(
"https://cloud.somewhere.com/subdir", "https://cloud.somewhere.com/"
)
assertEquals("https://cloud.somewhere.com/", newLocation)
}
@Test
fun `update location with a relative path`() {
val newLocation = remoteStatusOperation.updateLocationWithRedirectPath(
"https://cloud.somewhere.com", "/subdir"
)
assertEquals("https://cloud.somewhere.com/subdir", newLocation)
}
@Test
fun `update location by replacing the relative path`() {
val newLocation = remoteStatusOperation.updateLocationWithRedirectPath(
"https://cloud.somewhere.com/some/other/subdir", "/subdir"
)
assertEquals("https://cloud.somewhere.com/subdir", newLocation)
}
}