Initial QSfera import

This commit is contained in:
Курнат Андрей
2026-06-07 10:20:04 +03:00
commit 2315f25754
16485 changed files with 4826827 additions and 0 deletions
@@ -0,0 +1,59 @@
/**
* qsfera Android client application
*
* @author Abel García de Prada
* Copyright (C) 2021 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.authentication.oauth
import eu.qsfera.android.domain.exceptions.ServerNotReachableException
import eu.qsfera.android.testutil.OC_SECURE_SERVER_INFO_BASIC_AUTH
import eu.qsfera.android.testutil.oauth.OC_OIDC_SERVER_CONFIGURATION
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert
import org.junit.Test
class OIDCDiscoveryUseCaseTest {
private val repository: OAuthRepository = spyk()
private val useCase = OIDCDiscoveryUseCase(repository)
private val useCaseParams = OIDCDiscoveryUseCase.Params(OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl)
@Test
fun `test perform oidc discovery - ok`() {
every { repository.performOIDCDiscovery(useCaseParams.baseUrl) } returns OC_OIDC_SERVER_CONFIGURATION
val useCaseResult = useCase(useCaseParams)
Assert.assertTrue(useCaseResult.isSuccess)
Assert.assertEquals(OC_OIDC_SERVER_CONFIGURATION, useCaseResult.getDataOrNull())
verify(exactly = 1) { repository.performOIDCDiscovery(useCaseParams.baseUrl) }
}
@Test
fun `test perform oidc discovery - ko`() {
every { repository.performOIDCDiscovery(useCaseParams.baseUrl) } throws ServerNotReachableException()
val useCaseResult = useCase(useCaseParams)
Assert.assertTrue(useCaseResult.isError)
Assert.assertTrue(useCaseResult.getThrowableOrNull() is ServerNotReachableException)
verify(exactly = 1) { repository.performOIDCDiscovery(useCaseParams.baseUrl) }
}
}
@@ -0,0 +1,59 @@
/**
* qsfera Android client application
*
* @author Abel García de Prada
* Copyright (C) 2021 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.authentication.oauth
import eu.qsfera.android.domain.exceptions.ServerNotReachableException
import eu.qsfera.android.testutil.oauth.OC_CLIENT_REGISTRATION
import eu.qsfera.android.testutil.oauth.OC_CLIENT_REGISTRATION_REQUEST
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert
import org.junit.Test
class RegisterClientUseCaseTest {
private val repository: OAuthRepository = spyk()
private val useCase = RegisterClientUseCase(repository)
private val useCaseParams = RegisterClientUseCase.Params(OC_CLIENT_REGISTRATION_REQUEST)
@Test
fun `test register client - ok`() {
every { repository.registerClient(useCaseParams.clientRegistrationRequest) } returns OC_CLIENT_REGISTRATION
val useCaseResult = useCase(useCaseParams)
Assert.assertTrue(useCaseResult.isSuccess)
Assert.assertEquals(OC_CLIENT_REGISTRATION, useCaseResult.getDataOrNull())
verify(exactly = 1) { repository.registerClient(useCaseParams.clientRegistrationRequest) }
}
@Test
fun `test register client - ko`() {
every { repository.registerClient(useCaseParams.clientRegistrationRequest) } throws ServerNotReachableException()
val useCaseResult = useCase(useCaseParams)
Assert.assertTrue(useCaseResult.isError)
Assert.assertTrue(useCaseResult.getThrowableOrNull() is ServerNotReachableException)
verify(exactly = 1) { repository.registerClient(useCaseParams.clientRegistrationRequest) }
}
}
@@ -0,0 +1,59 @@
/**
* qsfera Android client application
*
* @author Abel García de Prada
* Copyright (C) 2021 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.authentication.oauth
import eu.qsfera.android.domain.exceptions.ServerNotReachableException
import eu.qsfera.android.testutil.oauth.OC_TOKEN_REQUEST_REFRESH
import eu.qsfera.android.testutil.oauth.OC_TOKEN_RESPONSE
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert
import org.junit.Test
class RequestTokenUseCaseTest {
private val repository: OAuthRepository = spyk()
private val useCase = RequestTokenUseCase(repository)
private val useCaseParams = RequestTokenUseCase.Params(OC_TOKEN_REQUEST_REFRESH)
@Test
fun `test request token use case - ok`() {
every { repository.performTokenRequest(useCaseParams.tokenRequest) } returns OC_TOKEN_RESPONSE
val useCaseResult = useCase(useCaseParams)
Assert.assertTrue(useCaseResult.isSuccess)
Assert.assertEquals(OC_TOKEN_RESPONSE, useCaseResult.getDataOrNull())
verify(exactly = 1) { repository.performTokenRequest(useCaseParams.tokenRequest) }
}
@Test
fun `test request token use case - ko`() {
every { repository.performTokenRequest(useCaseParams.tokenRequest) } throws ServerNotReachableException()
val useCaseResult = useCase(useCaseParams)
Assert.assertTrue(useCaseResult.isError)
Assert.assertTrue(useCaseResult.getThrowableOrNull() is ServerNotReachableException)
verify(exactly = 1) { repository.performTokenRequest(useCaseParams.tokenRequest) }
}
}
@@ -0,0 +1,75 @@
/**
* qsfera Android client application
*
* @author David González Verdugo
* Copyright (C) 2020 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.authentication.usecases
import eu.qsfera.android.domain.authentication.AuthenticationRepository
import eu.qsfera.android.domain.exceptions.AccountNotFoundException
import eu.qsfera.android.testutil.OC_ACCOUNT_NAME
import eu.qsfera.android.testutil.OC_SECURE_BASE_URL
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
class GetBaseUrlUseCaseTest {
private val repository: AuthenticationRepository = spyk()
private val useCase = GetBaseUrlUseCase(repository)
private val useCaseParams = GetBaseUrlUseCase.Params(
accountName = OC_ACCOUNT_NAME
)
@Test
fun `get base url - ko - invalid params`() {
val invalidGetBaseUrlUseCaseParams = useCaseParams.copy(accountName = "")
val getBaseUrlUseCaseResult = useCase(invalidGetBaseUrlUseCaseParams)
assertTrue(getBaseUrlUseCaseResult.isError)
assertTrue(getBaseUrlUseCaseResult.getThrowableOrNull() is IllegalArgumentException)
verify(exactly = 0) { repository.getBaseUrl(any()) }
}
@Test
fun `get base url - ok`() {
every { repository.getBaseUrl(any()) } returns OC_SECURE_BASE_URL
val getBaseUrlUseCaseResult = useCase(useCaseParams)
assertTrue(getBaseUrlUseCaseResult.isSuccess)
assertEquals(OC_SECURE_BASE_URL, getBaseUrlUseCaseResult.getDataOrNull())
verify(exactly = 1) { repository.getBaseUrl(any()) }
}
@Test
fun `get base url - ko - another exception`() {
every { repository.getBaseUrl(any()) } throws AccountNotFoundException()
val getBaseUrlUseCaseResult = useCase(useCaseParams)
assertTrue(getBaseUrlUseCaseResult.isError)
assertTrue(getBaseUrlUseCaseResult.getThrowableOrNull() is AccountNotFoundException)
verify(exactly = 1) { repository.getBaseUrl(any()) }
}
}
@@ -0,0 +1,88 @@
/**
* qsfera Android client application
*
* @author Abel García de Prada
* Copyright (C) 2020 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.authentication.usecases
import eu.qsfera.android.domain.authentication.AuthenticationRepository
import eu.qsfera.android.testutil.OC_ACCOUNT_NAME
import eu.qsfera.android.testutil.OC_SECURE_SERVER_INFO_BASIC_AUTH
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
class LoginBasicAsyncUseCaseTest {
private val repository: AuthenticationRepository = spyk()
private val useCase = LoginBasicAsyncUseCase(repository)
private val useCaseParams = LoginBasicAsyncUseCase.Params(
serverInfo = OC_SECURE_SERVER_INFO_BASIC_AUTH,
username = "test",
password = "test",
updateAccountWithUsername = null
)
@Test
fun `login basic - ko - invalid params`() {
var invalidLoginBasicUseCaseParams = useCaseParams.copy(serverInfo = null)
var loginBasicUseCaseResult = useCase(invalidLoginBasicUseCaseParams)
assertTrue(loginBasicUseCaseResult.isError)
assertTrue(loginBasicUseCaseResult.getThrowableOrNull() is IllegalArgumentException)
invalidLoginBasicUseCaseParams = useCaseParams.copy(username = "")
loginBasicUseCaseResult = useCase(invalidLoginBasicUseCaseParams)
assertTrue(loginBasicUseCaseResult.isError)
assertTrue(loginBasicUseCaseResult.getThrowableOrNull() is IllegalArgumentException)
invalidLoginBasicUseCaseParams = useCaseParams.copy(password = "")
loginBasicUseCaseResult = useCase(invalidLoginBasicUseCaseParams)
assertTrue(loginBasicUseCaseResult.isError)
assertTrue(loginBasicUseCaseResult.getThrowableOrNull() is IllegalArgumentException)
verify(exactly = 0) { repository.loginBasic(any(), any(), any(), any()) }
}
@Test
fun `login basic - ok`() {
every { repository.loginBasic(any(), any(), any(), any()) } returns OC_ACCOUNT_NAME
val loginBasicUseCaseResult = useCase(useCaseParams)
assertTrue(loginBasicUseCaseResult.isSuccess)
assertEquals(OC_ACCOUNT_NAME, loginBasicUseCaseResult.getDataOrNull())
verify(exactly = 1) { repository.loginBasic(any(), any(), any(), any()) }
}
@Test
fun `login basic - ko - another exception`() {
every { repository.loginBasic(any(), any(), any(), any()) } throws Exception()
val loginBasicUseCaseResult = useCase(useCaseParams)
assertTrue(loginBasicUseCaseResult.isError)
assertTrue(loginBasicUseCaseResult.getThrowableOrNull() is Exception)
verify(exactly = 1) { repository.loginBasic(any(), any(), any(), any()) }
}
}
@@ -0,0 +1,103 @@
/**
* qsfera Android client application
*
* @author David González Verdugo
* Copyright (C) 2020 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.authentication.usecases
import eu.qsfera.android.domain.authentication.AuthenticationRepository
import eu.qsfera.android.testutil.OC_ACCESS_TOKEN
import eu.qsfera.android.testutil.OC_ACCOUNT_NAME
import eu.qsfera.android.testutil.OC_AUTH_TOKEN_TYPE
import eu.qsfera.android.testutil.OC_REFRESH_TOKEN
import eu.qsfera.android.testutil.OC_SCOPE
import eu.qsfera.android.testutil.OC_SECURE_SERVER_INFO_BASIC_AUTH
import eu.qsfera.android.testutil.oauth.OC_CLIENT_REGISTRATION
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
class LoginOAuthAsyncUseCaseTest {
private val repository: AuthenticationRepository = spyk()
private val useCase = LoginOAuthAsyncUseCase(repository)
private val useCaseParams = LoginOAuthAsyncUseCase.Params(
serverInfo = OC_SECURE_SERVER_INFO_BASIC_AUTH,
username = "test",
authTokenType = OC_AUTH_TOKEN_TYPE,
accessToken = OC_ACCESS_TOKEN,
refreshToken = OC_REFRESH_TOKEN,
scope = OC_SCOPE,
updateAccountWithUsername = null,
clientRegistrationInfo = OC_CLIENT_REGISTRATION
)
@Test
fun `login oauth - ko - invalid params`() {
var invalidLoginOAuthUseCaseParams = useCaseParams.copy(serverInfo = null)
var loginOAuthUseCaseResult = useCase(invalidLoginOAuthUseCaseParams)
assertTrue(loginOAuthUseCaseResult.isError)
assertTrue(loginOAuthUseCaseResult.getThrowableOrNull() is IllegalArgumentException)
invalidLoginOAuthUseCaseParams = useCaseParams.copy(authTokenType = "")
loginOAuthUseCaseResult = useCase(invalidLoginOAuthUseCaseParams)
assertTrue(loginOAuthUseCaseResult.isError)
assertTrue(loginOAuthUseCaseResult.getThrowableOrNull() is IllegalArgumentException)
invalidLoginOAuthUseCaseParams = useCaseParams.copy(accessToken = "")
loginOAuthUseCaseResult = useCase(invalidLoginOAuthUseCaseParams)
assertTrue(loginOAuthUseCaseResult.isError)
assertTrue(loginOAuthUseCaseResult.getThrowableOrNull() is IllegalArgumentException)
invalidLoginOAuthUseCaseParams = useCaseParams.copy(refreshToken = "")
loginOAuthUseCaseResult = useCase(invalidLoginOAuthUseCaseParams)
assertTrue(loginOAuthUseCaseResult.isError)
assertTrue(loginOAuthUseCaseResult.getThrowableOrNull() is IllegalArgumentException)
verify(exactly = 0) { repository.loginOAuth(any(), any(), any(), any(), any(), any(), any(), any()) }
}
@Test
fun `login oauth - ok`() {
every { repository.loginOAuth(any(), any(), any(), any(), any(), any(), any(), any()) } returns OC_ACCOUNT_NAME
val loginOAuthUseCaseResult = useCase(useCaseParams)
assertTrue(loginOAuthUseCaseResult.isSuccess)
assertEquals(OC_ACCOUNT_NAME, loginOAuthUseCaseResult.getDataOrNull())
verify(exactly = 1) { repository.loginOAuth(any(), any(), any(), any(), any(), any(), any(), any()) }
}
@Test
fun `login oauth - ko - another exception`() {
every { repository.loginOAuth(any(), any(), any(), any(), any(), any(), any(), any()) } throws Exception()
val loginOAuthUseCaseResult = useCase(useCaseParams)
assertTrue(loginOAuthUseCaseResult.isError)
assertTrue(loginOAuthUseCaseResult.getThrowableOrNull() is Exception)
verify(exactly = 1) { repository.loginOAuth(any(), any(), any(), any(), any(), any(), any(), any()) }
}
}
@@ -0,0 +1,72 @@
/**
* qsfera Android client application
*
* @author David González Verdugo
* Copyright (C) 2020 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.authentication.usecases
import eu.qsfera.android.domain.authentication.AuthenticationRepository
import eu.qsfera.android.testutil.OC_ACCOUNT_NAME
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
class SupportsOAuth2UseCaseTest {
private val repository: AuthenticationRepository = spyk()
private val useCase = SupportsOAuth2UseCase(repository)
private val useCaseParams = SupportsOAuth2UseCase.Params(OC_ACCOUNT_NAME)
@Test
fun `supports OAuth2 - ko - invalid params`() {
val invalidSupportsOAuth2UseCaseParams = useCaseParams.copy(accountName = "")
val supportsOAuth2UseCaseResult = useCase(invalidSupportsOAuth2UseCaseParams)
assertTrue(supportsOAuth2UseCaseResult.isError)
assertTrue(supportsOAuth2UseCaseResult.getThrowableOrNull() is IllegalArgumentException)
verify(exactly = 0) { repository.supportsOAuth2UseCase(any()) }
}
@Test
fun `supports OAuth2 - ok`() {
every { repository.supportsOAuth2UseCase(any()) } returns true
val supportsOAuth2UseCaseResult = useCase(useCaseParams)
assertTrue(supportsOAuth2UseCaseResult.isSuccess)
assertEquals(true, supportsOAuth2UseCaseResult.getDataOrNull())
verify(exactly = 1) { repository.supportsOAuth2UseCase(any()) }
}
@Test
fun `supports OAuth2 - ko - another exception`() {
every { repository.supportsOAuth2UseCase(any()) } throws Exception()
val supportsOAuth2UseCaseResult = useCase(useCaseParams)
assertTrue(supportsOAuth2UseCaseResult.isError)
assertTrue(supportsOAuth2UseCaseResult.getThrowableOrNull() is Exception)
verify(exactly = 1) { repository.supportsOAuth2UseCase(any()) }
}
}
@@ -0,0 +1,62 @@
/**
* qsfera Android client application
*
* Copyright (C) 2026 QSfera.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*/
package eu.qsfera.android.domain.automaticuploads.model
import eu.qsfera.android.domain.automaticuploads.model.FolderBackUpConfiguration.Companion.encodeSourcePaths
import eu.qsfera.android.domain.automaticuploads.model.FolderBackUpConfiguration.Companion.parseSourcePaths
import org.junit.Assert.assertEquals
import org.junit.Test
class FolderBackUpConfigurationTest {
@Test
fun `parseSourcePaths returns single legacy source path`() {
val legacySourcePath = "content://com.android.externalstorage.documents/tree/primary%3ADCIM"
val sourcePaths = parseSourcePaths(legacySourcePath)
assertEquals(listOf(legacySourcePath), sourcePaths)
}
@Test
fun `parseSourcePaths trims empty lines and removes duplicates`() {
val firstSourcePath = "content://com.android.externalstorage.documents/tree/primary%3ADCIM"
val secondSourcePath = "content://com.android.externalstorage.documents/tree/primary%3APictures"
val sourcePaths = parseSourcePaths(
"""
$firstSourcePath
$secondSourcePath
$firstSourcePath
""".trimIndent()
)
assertEquals(listOf(firstSourcePath, secondSourcePath), sourcePaths)
}
@Test
fun `encodeSourcePaths stores normalized newline separated source paths`() {
val firstSourcePath = "content://com.android.externalstorage.documents/tree/primary%3ADCIM"
val secondSourcePath = "content://com.android.externalstorage.documents/tree/primary%3APictures"
val encodedSourcePaths = encodeSourcePaths(
listOf(
firstSourcePath,
"",
" $secondSourcePath ",
firstSourcePath
)
)
assertEquals("$firstSourcePath\n$secondSourcePath", encodedSourcePaths)
}
}
@@ -0,0 +1,85 @@
/**
* qsfera Android client application
*
* @author Abel García de Prada
* Copyright (C) 2020 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.capabilities.model
import eu.qsfera.android.domain.capabilities.model.CapabilityBooleanType.Companion.fromBooleanValue
import eu.qsfera.android.domain.capabilities.model.CapabilityBooleanType.Companion.fromValue
import eu.qsfera.android.domain.capabilities.model.CapabilityBooleanType.FALSE
import eu.qsfera.android.domain.capabilities.model.CapabilityBooleanType.TRUE
import eu.qsfera.android.domain.capabilities.model.CapabilityBooleanType.UNKNOWN
import eu.qsfera.android.testutil.OC_CAPABILITY
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
class OCCapabilityTest {
@Test
fun testCapabilityBooleanType() {
val fromValueUnknownType = fromValue(-1)
val fromValueFalseType = fromValue(0)
val fromValueTrueType = fromValue(1)
val fromValueDifferentValue = fromValue(2)
val fromBooleanTrue = fromBooleanValue(true)
val fromBooleanFalse = fromBooleanValue(false)
val capabilityUnknown = UNKNOWN
val capabilityFalse = FALSE
val capabilityTrue = TRUE
assertEquals(UNKNOWN, fromValueUnknownType)
assertEquals(FALSE, fromValueFalseType)
assertEquals(TRUE, fromValueTrueType)
assertEquals(UNKNOWN, fromValueDifferentValue)
assertEquals(TRUE, fromBooleanTrue)
assertEquals(FALSE, fromBooleanFalse)
assertEquals(true, capabilityUnknown.isUnknown)
assertEquals(false, capabilityUnknown.isTrue)
assertEquals(true, capabilityFalse.isFalse)
assertEquals(true, capabilityTrue.isTrue)
}
@Test
fun isChunkingAvailable() {
val item1 = OC_CAPABILITY.copy(davChunkingVersion = "", filesBigFileChunking = TRUE)
assertEquals(false, item1.isChunkingAllowed())
val item2 = OC_CAPABILITY.copy(davChunkingVersion = "0", filesBigFileChunking = TRUE)
assertEquals(false, item2.isChunkingAllowed())
val item3 = OC_CAPABILITY.copy(davChunkingVersion = "notADouble", filesBigFileChunking = TRUE)
assertEquals(false, item3.isChunkingAllowed())
val item4 = OC_CAPABILITY.copy(davChunkingVersion = "1.0", filesBigFileChunking = TRUE)
assertEquals(true, item4.isChunkingAllowed())
val item5 = OC_CAPABILITY.copy(davChunkingVersion = "1.0", filesBigFileChunking = FALSE)
assertEquals(false, item5.isChunkingAllowed())
}
@Test
fun isOpenInWebAllowed() {
val item1 = OC_CAPABILITY.copy(filesAppProviders = OCCapability.AppProviders(true, "", null, null, "/open-with-web", null))
assertTrue(item1.isOpenInWebAllowed())
val item2 = OC_CAPABILITY.copy(filesAppProviders = null)
assertFalse(item2.isOpenInWebAllowed())
}
}
@@ -0,0 +1,70 @@
/**
* qsfera Android client application
*
* @author David González Verdugo
* Copyright (C) 2020 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.capabilities.usecases
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import androidx.lifecycle.MutableLiveData
import eu.qsfera.android.domain.capabilities.CapabilityRepository
import eu.qsfera.android.domain.capabilities.model.OCCapability
import eu.qsfera.android.testutil.OC_CAPABILITY
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert
import org.junit.Rule
import org.junit.Test
class GetCapabilitiesAsLiveDataUseCaseTest {
@Rule
@JvmField
var instantTaskExecutorRule = InstantTaskExecutorRule()
private val repository: CapabilityRepository = spyk()
private val useCase = GetCapabilitiesAsLiveDataUseCase((repository))
private val useCaseParams = GetCapabilitiesAsLiveDataUseCase.Params("")
@Test
fun `get capabilities as livedata - ok`() {
val capabilitiesLiveData = MutableLiveData<OCCapability>()
every { repository.getCapabilitiesAsLiveData(any()) } returns capabilitiesLiveData
val capabilitiesToEmit = listOf(OC_CAPABILITY)
val capabilitiesEmitted = mutableListOf<OCCapability>()
useCase(useCaseParams).observeForever {
capabilitiesEmitted.add(it!!)
}
capabilitiesToEmit.forEach { capabilitiesLiveData.postValue(it) }
Assert.assertEquals(capabilitiesToEmit, capabilitiesEmitted)
verify(exactly = 1) { repository.getCapabilitiesAsLiveData(any()) }
}
@Test(expected = Exception::class)
fun `get capabilities as livedata - ko`() {
every { repository.getCapabilitiesAsLiveData(any()) } throws Exception()
useCase(useCaseParams)
}
}
@@ -0,0 +1,65 @@
/**
* qsfera Android client application
*
* @author Abel García de Prada
* Copyright (C) 2020 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.capabilities.usecases
import eu.qsfera.android.domain.capabilities.CapabilityRepository
import eu.qsfera.android.testutil.OC_CAPABILITY
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
class GetStoredCapabilitiesUseCaseTest {
private val repository: CapabilityRepository = spyk()
private val useCase = GetStoredCapabilitiesUseCase((repository))
private val useCaseParams = GetStoredCapabilitiesUseCase.Params("user@server")
@Test
fun `get stored capabilities - ok`() {
every { repository.getStoredCapabilities(any()) } returns OC_CAPABILITY
val capability = useCase(useCaseParams)
assertEquals(OC_CAPABILITY, capability)
verify(exactly = 1) { repository.getStoredCapabilities(any()) }
}
@Test
fun `get stored capabilities - ok - null`() {
every { repository.getStoredCapabilities(any()) } returns null
val capability = useCase(useCaseParams)
assertNull(capability)
verify(exactly = 1) { repository.getStoredCapabilities(any()) }
}
@Test(expected = Exception::class)
fun `get stored capabilities - ko`() {
every { repository.getStoredCapabilities(any()) } throws Exception()
useCase(useCaseParams)
}
}
@@ -0,0 +1,59 @@
/**
* qsfera Android client application
*
* @author David González Verdugo
* Copyright (C) 2020 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.capabilities.usecases
import eu.qsfera.android.domain.capabilities.CapabilityRepository
import eu.qsfera.android.domain.exceptions.UnauthorizedException
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert
import org.junit.Test
class RefreshCapabilitiesFromServerAsyncUseCaseTest {
private val repository: CapabilityRepository = spyk()
private val useCase = RefreshCapabilitiesFromServerAsyncUseCase((repository))
private val useCaseParams = RefreshCapabilitiesFromServerAsyncUseCase.Params("")
@Test
fun `refresh capabilities from server - ok`() {
every { repository.refreshCapabilitiesForAccount(any()) } returns Unit
val useCaseResult = useCase(useCaseParams)
Assert.assertTrue(useCaseResult.isSuccess)
Assert.assertEquals(Unit, useCaseResult.getDataOrNull())
verify(exactly = 1) { repository.refreshCapabilitiesForAccount("") }
}
@Test
fun `refresh capabilities from server - ko`() {
every { repository.refreshCapabilitiesForAccount(any()) } throws UnauthorizedException()
val useCaseResult = useCase(useCaseParams)
Assert.assertTrue(useCaseResult.isError)
Assert.assertTrue(useCaseResult.getThrowableOrNull() is UnauthorizedException)
verify(exactly = 1) { repository.refreshCapabilitiesForAccount("") }
}
}
@@ -0,0 +1,235 @@
/**
* qsfera Android client application
*
* @author Abel García de Prada
* Copyright (C) 2020 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.files.model
import eu.qsfera.android.testutil.OC_FILE
import eu.qsfera.android.testutil.OC_FOLDER
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertTrue
import org.junit.Test
class OCFileTest {
@Test
fun `test equals - ok`() {
val item1 = OCFile(
OC_FILE.id,
OC_FILE.parentId,
OC_FILE.owner,
OC_FILE.length,
OC_FILE.creationTimestamp,
OC_FILE.modificationTimestamp,
OC_FILE.remotePath,
OC_FILE.mimeType,
OC_FILE.etag,
OC_FILE.remoteEtag,
OC_FILE.permissions,
OC_FILE.remoteId,
OC_FILE.privateLink,
OC_FILE.storagePath,
OC_FILE.treeEtag,
OC_FILE.availableOfflineStatus,
OC_FILE.lastSyncDateForData,
OC_FILE.lastUsage,
OC_FILE.needsToUpdateThumbnail,
OC_FILE.modifiedAtLastSyncForData,
OC_FILE.etagInConflict,
OC_FILE.fileIsDownloading,
OC_FILE.sharedWithSharee,
OC_FILE.sharedByLink
)
val item2 = OCFile(
id = OC_FILE.id,
parentId = OC_FILE.parentId,
owner = OC_FILE.owner,
length = OC_FILE.length,
creationTimestamp = OC_FILE.creationTimestamp,
modificationTimestamp = OC_FILE.modificationTimestamp,
remotePath = OC_FILE.remotePath,
mimeType = OC_FILE.mimeType,
etag = OC_FILE.etag,
remoteEtag = OC_FILE.remoteEtag,
permissions = OC_FILE.permissions,
remoteId = OC_FILE.remoteId,
privateLink = OC_FILE.privateLink,
storagePath = OC_FILE.storagePath,
treeEtag = OC_FILE.treeEtag,
availableOfflineStatus = OC_FILE.availableOfflineStatus,
lastSyncDateForData = OC_FILE.lastSyncDateForData,
lastUsage = OC_FILE.lastUsage,
needsToUpdateThumbnail = OC_FILE.needsToUpdateThumbnail,
modifiedAtLastSyncForData = OC_FILE.modifiedAtLastSyncForData,
etagInConflict = OC_FILE.etagInConflict,
fileIsDownloading = OC_FILE.fileIsDownloading,
sharedWithSharee = OC_FILE.sharedWithSharee,
sharedByLink = OC_FILE.sharedByLink
)
assertTrue(item1 == item2)
assertFalse(item1 === item2)
}
@Test
fun `test equals - ko`() {
val item1 = OCFile(
OC_FILE.id,
OC_FILE.parentId,
OC_FILE.owner,
OC_FILE.length,
OC_FILE.creationTimestamp,
OC_FILE.modificationTimestamp,
OC_FILE.remotePath,
OC_FILE.mimeType,
OC_FILE.etag,
OC_FILE.remoteEtag,
OC_FILE.permissions,
OC_FILE.remoteId,
OC_FILE.privateLink,
OC_FILE.storagePath,
OC_FILE.treeEtag,
OC_FILE.availableOfflineStatus,
OC_FILE.lastSyncDateForData,
OC_FILE.lastUsage,
OC_FILE.needsToUpdateThumbnail,
OC_FILE.modifiedAtLastSyncForData,
OC_FILE.etagInConflict,
OC_FILE.fileIsDownloading,
OC_FILE.sharedWithSharee,
OC_FILE.sharedByLink
)
val item2 = OCFile(
id = 123,
parentId = OC_FILE.parentId,
owner = OC_FILE.owner,
length = OC_FILE.length,
creationTimestamp = OC_FILE.creationTimestamp,
modificationTimestamp = OC_FILE.modificationTimestamp,
remotePath = OC_FILE.remotePath,
mimeType = OC_FILE.mimeType,
etag = OC_FILE.etag,
permissions = OC_FILE.permissions,
remoteId = OC_FILE.remoteId,
privateLink = OC_FILE.privateLink,
storagePath = OC_FILE.storagePath,
treeEtag = OC_FILE.treeEtag,
availableOfflineStatus = OC_FILE.availableOfflineStatus,
lastSyncDateForData = OC_FILE.lastSyncDateForData,
lastUsage = OC_FILE.lastUsage,
needsToUpdateThumbnail = OC_FILE.needsToUpdateThumbnail,
modifiedAtLastSyncForData = OC_FILE.modifiedAtLastSyncForData,
etagInConflict = OC_FILE.etagInConflict,
fileIsDownloading = OC_FILE.fileIsDownloading,
sharedWithSharee = OC_FILE.sharedWithSharee,
sharedByLink = OC_FILE.sharedByLink
)
assertFalse(item1 == item2)
assertFalse(item1 === item2)
}
@Test
fun `test filename - ok`() {
val ocFile = OCFile(
owner = OC_FILE.owner,
length = OC_FILE.length,
modificationTimestamp = OC_FILE.modificationTimestamp,
remotePath = "/Photos/",
mimeType = OC_FILE.mimeType
)
assertNotNull(ocFile.fileName)
assertEquals("Photos", ocFile.fileName)
}
@Test
fun `test file is folder - unix dir`() {
val ocFile = OC_FOLDER.copy(mimeType = MIME_DIR_UNIX)
assertTrue(ocFile.isFolder)
}
@Test
fun `test file is folder - dir`() {
val ocFile = OC_FOLDER.copy(mimeType = MIME_DIR)
assertTrue(ocFile.isFolder)
}
@Test
fun `test file is audio - ok`() {
val ocFile = OC_FILE.copy(mimeType = "${MIME_PREFIX_AUDIO}ogg")
assertTrue(ocFile.isAudio)
}
@Test
fun `test file is video - ok`() {
val ocFile = OC_FILE.copy(mimeType = "${MIME_PREFIX_VIDEO}mp4")
assertTrue(ocFile.isVideo)
}
@Test
fun `test is image - ok`() {
val ocFile = OC_FILE.copy(mimeType = "${MIME_PREFIX_IMAGE}jpeg")
assertTrue(ocFile.isImage)
}
@Test
fun `test file is available locally - ok - null`() {
val ocFile = OC_FILE.copy(storagePath = null)
assertFalse(ocFile.isAvailableLocally)
}
@Test
fun `test file exists - ok - null`() {
val ocFile = OC_FILE.copy(id = null)
assertFalse(ocFile.fileExists)
}
@Test
fun `test file exists - ok - (-1)`() {
val ocFile = OC_FILE.copy(id = -1)
assertFalse(ocFile.fileExists)
}
@Test
fun `test file exists - ok`() {
val ocFile = OC_FILE.copy(id = 1123)
assertTrue(ocFile.fileExists)
}
@Test
fun `test is hidden - ok`() {
val ocFile = OC_FILE.copy(remotePath = ".secretFile")
assertTrue(ocFile.isHidden)
}
@Test
fun `test shared with me - ok`() {
val ocFile = OC_FILE.copy(permissions = "RDNSCK")
assertTrue(ocFile.isSharedWithMe)
}
@Test
fun `test shared with me - ok - false`() {
val ocFile = OC_FILE.copy(permissions = "RDCK")
assertFalse(ocFile.isSharedWithMe)
}
}
@@ -0,0 +1,145 @@
/**
* qsfera Android client application
*
* @author Abel García de Prada
* Copyright (C) 2021 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.files.usecases
import eu.qsfera.android.domain.exceptions.CopyIntoDescendantException
import eu.qsfera.android.domain.exceptions.UnauthorizedException
import eu.qsfera.android.domain.files.FileRepository
import eu.qsfera.android.domain.files.model.OCFile
import eu.qsfera.android.testutil.OC_FILE
import eu.qsfera.android.testutil.OC_FOLDER
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
class CopyFileUseCaseTest {
private val repository: FileRepository = spyk()
private val useCase = CopyFileUseCase(repository)
private val useCaseParams = CopyFileUseCase.Params(
listOfFilesToCopy = listOf(OC_FILE.copy(remotePath = "/video.mp4", parentId = 101)),
targetFolder = OC_FOLDER.copy(id = 100),
isUserLogged = true,
)
@Test
fun `copy file - ok`() {
every { repository.copyFile(any(), any(), any(), any()) } returns emptyList()
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isSuccess)
assertEquals(useCaseResult.getDataOrNull(), emptyList<OCFile>())
verify(exactly = 1) { repository.copyFile(any(), any(), any(), any()) }
}
@Test
fun `copy file - ok - single copy into same folder`() {
val useCaseParams = CopyFileUseCase.Params(
listOfFilesToCopy = listOf(element = OC_FOLDER.copy(remotePath = "/Photos/", parentId = 100)),
targetFolder = OC_FOLDER.copy(remotePath = "/Directory/Descendant/", id = 100),
isUserLogged = true,
)
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isSuccess)
verify(exactly = 1) { repository.copyFile(any(), any(), any(), any()) }
}
@Test
fun `copy file - ko - empty list`() {
val useCaseResult = useCase(useCaseParams.copy(listOfFilesToCopy = listOf(), targetFolder = OC_FOLDER))
assertTrue(useCaseResult.isError)
assertTrue(useCaseResult.getThrowableOrNull() is IllegalArgumentException)
verify(exactly = 0) { repository.copyFile(any(), any(), any(), any()) }
}
@Test
fun `copy file - ko - single copy into descendant`() {
val useCaseParams = CopyFileUseCase.Params(
listOfFilesToCopy = listOf(OC_FOLDER.copy(remotePath = "/Directory")),
targetFolder = OC_FOLDER.copy(remotePath = "/Directory/Descendant/"),
isUserLogged = true
)
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isError)
assertTrue(useCaseResult.getThrowableOrNull() is CopyIntoDescendantException)
verify(exactly = 0) { repository.copyFile(any(), any(), any(), any()) }
}
@Test
fun `copy file - ko - multiple copy into descendant`() {
val useCaseParams = CopyFileUseCase.Params(
listOfFilesToCopy = listOf(OC_FOLDER.copy(remotePath = "/Directory"), OC_FILE.copy(remotePath = "/Document.pdf")),
targetFolder = OC_FOLDER.copy(remotePath = "/Directory/Descendant/"),
isUserLogged = true
)
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isError)
verify(exactly = 0) { repository.copyFile(any(), any(), any(), any()) }
}
@Test
fun `copy file - ko - other exception`() {
every { repository.copyFile(any(), any(), any(), any()) } throws UnauthorizedException()
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isError)
assertTrue(useCaseResult.getThrowableOrNull() is UnauthorizedException)
verify(exactly = 1) { repository.copyFile(any(), any(), any(), any()) }
}
@Test
fun `copy file - ok - return list files`() {
val filesList = listOf(OC_FILE, OC_FILE)
every { repository.copyFile(any(), any(), any(), any()) } returns filesList
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isSuccess)
assertEquals(filesList, useCaseResult.getDataOrNull())
verify(exactly = 1) { repository.copyFile(any(), any(), any(), any()) }
}
@Test
fun `copy file - ok - passing replace`() {
val replace = listOf(true, false)
every { repository.copyFile(any(), any(), replace, any()) } returns emptyList()
val useCaseResult = useCase(useCaseParams.copy(replace = replace))
assertTrue(useCaseResult.isSuccess)
verify(exactly = 1) { repository.copyFile(any(), any(), replace, any()) }
}
}
@@ -0,0 +1,85 @@
/**
* qsfera Android client application
*
* @author Abel García de Prada
* @author Christian Schabesberger
* Copyright (C) 2020 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.files.usecases
import eu.qsfera.android.domain.exceptions.UnauthorizedException
import eu.qsfera.android.domain.exceptions.validation.FileNameException
import eu.qsfera.android.domain.exceptions.validation.FileNameException.FileNameExceptionType.FILE_NAME_EMPTY
import eu.qsfera.android.domain.exceptions.validation.FileNameException.FileNameExceptionType.FILE_NAME_FORBIDDEN_CHARACTERS
import eu.qsfera.android.domain.files.FileRepository
import eu.qsfera.android.testutil.OC_FOLDER
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
class CreateFolderAsyncUseCaseTest {
private val repository: FileRepository = spyk()
private val useCase = CreateFolderAsyncUseCase(repository)
private val useCaseParams = CreateFolderAsyncUseCase.Params("new folder", OC_FOLDER)
@Test
fun `create folder - ok`() {
every { repository.createFolder(any(), any()) } returns Unit
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isSuccess)
assertEquals(Unit, useCaseResult.getDataOrNull())
verify(exactly = 1) { repository.createFolder(any(), useCaseParams.parentFile) }
}
@Test
fun `create folder - ko - empty name`() {
val useCaseResult = useCase(useCaseParams.copy(folderName = " "))
assertTrue(useCaseResult.isError)
assertEquals(
FileNameException(type = FILE_NAME_EMPTY),
useCaseResult.getThrowableOrNull()
)
}
@Test
fun `create folder - ko - forbidden chars`() {
val useCaseResult = useCase(useCaseParams.copy(folderName = "/Photos"))
assertTrue(useCaseResult.isError)
assertEquals(
FileNameException(type = FILE_NAME_FORBIDDEN_CHARACTERS),
useCaseResult.getThrowableOrNull()
)
}
@Test
fun `create folder - ko - other exception`() {
every { repository.createFolder(any(), any()) } throws UnauthorizedException()
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isError)
assertTrue(useCaseResult.getThrowableOrNull() is UnauthorizedException)
verify(exactly = 1) { repository.createFolder(any(), useCaseParams.parentFile) }
}
}
@@ -0,0 +1,72 @@
/**
* qsfera Android client application
*
* @author Abel García de Prada
* @author Christian Schabesberger
* Copyright (C) 2020 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.files.usecases
import eu.qsfera.android.domain.exceptions.UnauthorizedException
import eu.qsfera.android.domain.files.FileRepository
import eu.qsfera.android.testutil.OC_FOLDER
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert
import org.junit.Test
class GetFileByIdUseCaseTest {
private val repository: FileRepository = spyk()
private val useCase = GetFileByIdUseCase(repository)
private val useCaseParams = GetFileByIdUseCase.Params(OC_FOLDER.id!!)
@Test
fun `get file by id - ok`() {
every { repository.getFileById(useCaseParams.fileId) } returns OC_FOLDER
val useCaseResult = useCase(useCaseParams)
Assert.assertTrue(useCaseResult.isSuccess)
Assert.assertEquals(OC_FOLDER, useCaseResult.getDataOrNull())
verify(exactly = 1) { repository.getFileById(useCaseParams.fileId) }
}
@Test
fun `get file by id - ok - null`() {
every { repository.getFileById(useCaseParams.fileId) } returns null
val useCaseResult = useCase(useCaseParams)
Assert.assertTrue(useCaseResult.isSuccess)
Assert.assertEquals(null, useCaseResult.getDataOrNull())
verify(exactly = 1) { repository.getFileById(useCaseParams.fileId) }
}
@Test
fun `get file by id - ko`() {
every { repository.getFileById(useCaseParams.fileId) } throws UnauthorizedException()
val useCaseResult = useCase(useCaseParams)
Assert.assertTrue(useCaseResult.isError)
Assert.assertTrue(useCaseResult.getThrowableOrNull() is UnauthorizedException)
verify(exactly = 1) { repository.getFileById(useCaseParams.fileId) }
}
}
@@ -0,0 +1,75 @@
/**
* qsfera Android client application
*
* @author Abel García de Prada
* @author Christian Schabesberger
* Copyright (C) 2020 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.files.usecases
import eu.qsfera.android.domain.exceptions.UnauthorizedException
import eu.qsfera.android.domain.files.FileRepository
import eu.qsfera.android.testutil.OC_FOLDER
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert
import org.junit.Test
class GetFileByRemotePathUseCaseTest {
private val repository: FileRepository = spyk()
private val useCase = GetFileByRemotePathUseCase(repository)
private val useCaseParams = GetFileByRemotePathUseCase.Params("owner", "remotePath")
@Test
fun `get file by remote path - ok`() {
every { repository.getFileByRemotePath(useCaseParams.remotePath, useCaseParams.owner) } returns OC_FOLDER
val useCaseResult = useCase(useCaseParams)
Assert.assertTrue(useCaseResult.isSuccess)
Assert.assertEquals(OC_FOLDER, useCaseResult.getDataOrNull())
verify(exactly = 1) { repository.getFileByRemotePath(useCaseParams.remotePath, useCaseParams.owner) }
}
@Test
fun `get file by remote path - ok - null`() {
every { repository.getFileByRemotePath(useCaseParams.remotePath, useCaseParams.owner) } returns null
val useCaseResult = useCase(useCaseParams)
Assert.assertTrue(useCaseResult.isSuccess)
Assert.assertEquals(null, useCaseResult.getDataOrNull())
verify(exactly = 1) { repository.getFileByRemotePath(useCaseParams.remotePath, useCaseParams.owner) }
}
@Test
fun `get file by remote path - ko`() {
every {
repository.getFileByRemotePath(useCaseParams.remotePath, useCaseParams.owner)
} throws UnauthorizedException()
val useCaseResult = useCase(useCaseParams)
Assert.assertTrue(useCaseResult.isError)
Assert.assertTrue(useCaseResult.getThrowableOrNull() is UnauthorizedException)
verify(exactly = 1) { repository.getFileByRemotePath(useCaseParams.remotePath, useCaseParams.owner) }
}
}
@@ -0,0 +1,43 @@
package eu.qsfera.android.domain.files.usecases
import eu.qsfera.android.domain.files.FileRepository
import eu.qsfera.android.testutil.OC_FILE
import eu.qsfera.android.testutil.OC_FILE_WITH_SYNC_INFO_AND_SPACE
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.test.runTest
import org.junit.Assert
import org.junit.Test
@ExperimentalCoroutinesApi
class GetFileWithSyncInfoByIdUseCaseTest {
private val repository: FileRepository = spyk()
private val useCase = GetFileWithSyncInfoByIdUseCase(repository)
private val useCaseParams = GetFileWithSyncInfoByIdUseCase.Params(OC_FILE.id!!)
@Test
fun `getFileWithSyncInfoByIdAsFlow returns OCFileWithSyncInfo when no error`() = runTest {
every { repository.getFileWithSyncInfoByIdAsFlow(useCaseParams.fileId) } returns flowOf(OC_FILE_WITH_SYNC_INFO_AND_SPACE)
val useCaseResult = useCase(useCaseParams).first()
Assert.assertEquals(OC_FILE_WITH_SYNC_INFO_AND_SPACE, useCaseResult)
verify(exactly = 1) { repository.getFileWithSyncInfoByIdAsFlow(useCaseParams.fileId) }
}
@Test
fun `getFileWithSyncInfoByIdAsFlow returns true when repository is null`() = runTest {
val useCaseResult = useCase(useCaseParams)
every { repository.getFileWithSyncInfoByIdAsFlow(useCaseParams.fileId) } returns flowOf(null)
Assert.assertEquals(null, useCaseResult)
verify(exactly = 1) { repository.getFileWithSyncInfoByIdAsFlow(useCaseParams.fileId) }
}
}
@@ -0,0 +1,72 @@
/*
* qsfera Android client application
*
* Copyright (C) 2021 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.files.usecases
import eu.qsfera.android.domain.availableoffline.usecases.GetFilesAvailableOfflineFromAccountUseCase
import eu.qsfera.android.domain.exceptions.UnauthorizedException
import eu.qsfera.android.domain.files.FileRepository
import eu.qsfera.android.testutil.OC_AVAILABLE_OFFLINE_FILES
import eu.qsfera.android.testutil.OC_FILES_EMPTY
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert
import org.junit.Test
class GetFilesAvailableOfflineFromAccountUseCaseTest {
private val repository: FileRepository = spyk()
private val useCase = GetFilesAvailableOfflineFromAccountUseCase(repository)
private val useCaseParams = GetFilesAvailableOfflineFromAccountUseCase.Params(owner = "owner")
@Test
fun `get files available offline - ok`() {
every { repository.getFilesAvailableOfflineFromAccount(useCaseParams.owner) } returns OC_AVAILABLE_OFFLINE_FILES
val useCaseResult = useCase(useCaseParams)
Assert.assertTrue(useCaseResult.isSuccess)
Assert.assertEquals(OC_AVAILABLE_OFFLINE_FILES, useCaseResult.getDataOrNull())
verify(exactly = 1) { repository.getFilesAvailableOfflineFromAccount(useCaseParams.owner) }
}
@Test
fun `get files available offline - ok - empty list`() {
every { repository.getFilesAvailableOfflineFromAccount(useCaseParams.owner) } returns OC_FILES_EMPTY
val useCaseResult = useCase(useCaseParams)
Assert.assertTrue(useCaseResult.isSuccess)
Assert.assertEquals(OC_FILES_EMPTY, useCaseResult.getDataOrNull())
verify(exactly = 1) { repository.getFilesAvailableOfflineFromAccount(useCaseParams.owner) }
}
@Test
fun `get files savailable offline - ko`() {
every { repository.getFilesAvailableOfflineFromAccount(useCaseParams.owner) } throws UnauthorizedException()
val useCaseResult = useCase(useCaseParams)
Assert.assertTrue(useCaseResult.isError)
Assert.assertTrue(useCaseResult.getThrowableOrNull() is UnauthorizedException)
verify(exactly = 1) { repository.getFilesAvailableOfflineFromAccount(useCaseParams.owner) }
}
}
@@ -0,0 +1,60 @@
/**
* qsfera Android client application
*
* @author Abel García de Prada
* Copyright (C) 2020 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.files.usecases
import eu.qsfera.android.domain.exceptions.UnauthorizedException
import eu.qsfera.android.domain.files.FileRepository
import eu.qsfera.android.testutil.OC_FILE
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
class GetFolderContentUseCaseTest {
private val repository: FileRepository = spyk()
private val useCase = GetFolderContentUseCase(repository)
private val useCaseParams = GetFolderContentUseCase.Params(OC_FILE.parentId!!)
@Test
fun `get folder content - ok`() {
every { repository.getFolderContent(useCaseParams.folderId) } returns listOf(OC_FILE)
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isSuccess)
assertEquals(listOf(OC_FILE), useCaseResult.getDataOrNull())
verify(exactly = 1) { repository.getFolderContent(useCaseParams.folderId) }
}
@Test
fun `get folder content - ko`() {
every { repository.getFolderContent(useCaseParams.folderId) } throws UnauthorizedException()
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isError)
assertTrue(useCaseResult.getThrowableOrNull() is UnauthorizedException)
verify(exactly = 1) { repository.getFolderContent(useCaseParams.folderId) }
}
}
@@ -0,0 +1,68 @@
/**
* qsfera Android client application
*
* @author Fernando Sanz Velasco
* @author Juan Carlos Garrote Gascón
*
* Copyright (C) 2022 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.files.usecases
import eu.qsfera.android.domain.files.FileRepository
import eu.qsfera.android.domain.files.model.OCFileWithSyncInfo
import eu.qsfera.android.testutil.OC_FILES_WITH_SYNC_INFO
import eu.qsfera.android.testutil.OC_FILES_WITH_SYNC_INFO_EMPTY
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.test.runTest
import org.junit.Assert
import org.junit.Test
@OptIn(ExperimentalCoroutinesApi::class)
class GetSharedByLinkForAccountAsStreamUseCaseTest {
private val repository: FileRepository = spyk()
private val useCase = GetSharedByLinkForAccountAsStreamUseCase(repository)
private val useCaseParams = GetSharedByLinkForAccountAsStreamUseCase.Params(owner = "owner")
@Test
fun `get files shared by link - ok`() = runTest {
every { repository.getSharedByLinkWithSyncInfoForAccountAsFlow(useCaseParams.owner) } returns flowOf(OC_FILES_WITH_SYNC_INFO)
val useCaseResult = useCase(useCaseParams)
val listEmittedByFlow: List<OCFileWithSyncInfo> = useCaseResult.first()
Assert.assertTrue(listEmittedByFlow.containsAll(OC_FILES_WITH_SYNC_INFO))
verify(exactly = 1) { repository.getSharedByLinkWithSyncInfoForAccountAsFlow(useCaseParams.owner) }
}
@Test
fun `get files shared by link - ok - empty list`() = runTest {
every { repository.getSharedByLinkWithSyncInfoForAccountAsFlow(useCaseParams.owner) } returns flowOf(OC_FILES_WITH_SYNC_INFO_EMPTY)
val useCaseResult = useCase(useCaseParams)
val listEmittedByFlow: List<OCFileWithSyncInfo> = useCaseResult.first()
Assert.assertTrue(listEmittedByFlow.isEmpty())
verify(exactly = 1) { repository.getSharedByLinkWithSyncInfoForAccountAsFlow(useCaseParams.owner) }
}
}
@@ -0,0 +1,150 @@
/**
* qsfera Android client application
*
* @author Abel García de Prada
* Copyright (C) 2021 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.files.usecases
import eu.qsfera.android.domain.exceptions.MoveIntoDescendantException
import eu.qsfera.android.domain.exceptions.MoveIntoSameFolderException
import eu.qsfera.android.domain.exceptions.UnauthorizedException
import eu.qsfera.android.domain.files.FileRepository
import eu.qsfera.android.testutil.OC_FILE
import eu.qsfera.android.testutil.OC_FOLDER
import io.mockk.every
import io.mockk.mockk
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert
import org.junit.Assert.assertTrue
import org.junit.Test
class MoveFileUseCaseTest {
private val repository: FileRepository = spyk()
private val setLastUsageFileUseCase: SetLastUsageFileUseCase = mockk(relaxed = true)
private val useCase = MoveFileUseCase(repository, setLastUsageFileUseCase)
private val useCaseParams = MoveFileUseCase.Params(
listOfFilesToMove = listOf(OC_FILE.copy(remotePath = "/video.mp4", parentId = 123)),
targetFolder = OC_FOLDER.copy(id = 100),
isUserLogged = true,
)
@Test
fun `move file - ok`() {
every { repository.moveFile(any(), any(), any(), any()) } returns emptyList()
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isSuccess)
verify(exactly = 1) { repository.moveFile(any(), any(), any(), any()) }
}
@Test
fun `move file - ko - empty list`() {
val useCaseResult = useCase(useCaseParams.copy(listOfFilesToMove = listOf(), targetFolder = OC_FOLDER))
assertTrue(useCaseResult.isError)
assertTrue(useCaseResult.getThrowableOrNull() is IllegalArgumentException)
verify(exactly = 0) { repository.moveFile(any(), any(), any(), any()) }
}
@Test
fun `move file - ko - single move into descendant`() {
val useCaseParams = MoveFileUseCase.Params(
listOfFilesToMove = listOf(OC_FOLDER.copy(remotePath = "/Directory")),
targetFolder = OC_FOLDER.copy(remotePath = "/Directory/Descendant/"),
isUserLogged = true,
)
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isError)
assertTrue(useCaseResult.getThrowableOrNull() is MoveIntoDescendantException)
verify(exactly = 0) { repository.moveFile(any(), any(), any(), any()) }
}
@Test
fun `move file - ko - multiple move into descendant`() {
val useCaseParams = MoveFileUseCase.Params(
listOfFilesToMove = listOf(
OC_FOLDER.copy(remotePath = "/Directory", parentId = 1),
OC_FILE.copy(remotePath = "/Document.pdf", parentId = 1),
),
targetFolder = OC_FOLDER.copy(remotePath = "/Directory/Descendant/", id = 100),
isUserLogged = true,
)
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isError)
verify(exactly = 0) { repository.moveFile(any(), any(), any(), any()) }
}
@Test
fun `move file - ko - single move into same folder`() {
val useCaseParams = MoveFileUseCase.Params(
listOfFilesToMove = listOf(element = OC_FOLDER.copy(remotePath = "/Photos/", parentId = 100)),
targetFolder = OC_FOLDER.copy(remotePath = "/Directory/Descendant/", id = 100),
isUserLogged = true,
)
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isError)
assertTrue(useCaseResult.getThrowableOrNull() is MoveIntoSameFolderException)
verify(exactly = 0) { repository.moveFile(any(), any(), any(), any()) }
}
@Test
fun `move file - ko - other exception`() {
every { repository.moveFile(any(), any(), any(), any()) } throws UnauthorizedException()
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isError)
assertTrue(useCaseResult.getThrowableOrNull() is UnauthorizedException)
verify(exactly = 1) { repository.moveFile(any(), any(), any(), any()) }
}
@Test
fun ` move file - ok - return list files`() {
val filesList = listOf(OC_FILE, OC_FILE)
every { repository.moveFile(any(), any(), any(), any()) } returns filesList
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isSuccess)
Assert.assertEquals(filesList, useCaseResult.getDataOrNull())
verify(exactly = 1) { repository.moveFile(any(), any(), any(), any()) }
}
@Test
fun `mov file - ok - passing replace`() {
val replace = listOf(true, false)
every { repository.moveFile(any(), any(), replace, any()) } returns emptyList()
val useCaseResult = useCase(useCaseParams.copy(replace = replace))
assertTrue(useCaseResult.isSuccess)
verify(exactly = 1) { repository.moveFile(any(), any(), replace, any()) }
}
}
@@ -0,0 +1,82 @@
/**
* qsfera Android client application
*
* @author Abel García de Prada
* Copyright (C) 2021 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.files.usecases
import eu.qsfera.android.domain.exceptions.UnauthorizedException
import eu.qsfera.android.domain.files.FileRepository
import eu.qsfera.android.testutil.OC_FILE
import eu.qsfera.android.testutil.OC_FOLDER
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
class RemoveFileUseCaseTest {
private val repository: FileRepository = spyk()
private val useCase = RemoveFileUseCase(repository)
private val useCaseParams = RemoveFileUseCase.Params(listOf(OC_FILE, OC_FOLDER), removeOnlyLocalCopy = true)
@Test
fun `remove file - ok`() {
every { repository.deleteFiles(any(), any()) } returns Unit
val useCaseResult = useCase(useCaseParams.copy(removeOnlyLocalCopy = false))
assertTrue(useCaseResult.isSuccess)
assertEquals(Unit, useCaseResult.getDataOrNull())
verify(exactly = 1) { repository.deleteFiles(any(), removeOnlyLocalCopy = false) }
}
@Test
fun `remove file - ok - remove local only`() {
every { repository.deleteFiles(any(), any()) } returns Unit
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isSuccess)
assertEquals(Unit, useCaseResult.getDataOrNull())
verify(exactly = 1) { repository.deleteFiles(any(), removeOnlyLocalCopy = true) }
}
@Test
fun `remove file - ko - empty list`() {
val useCaseResult = useCase(useCaseParams.copy(listOfFilesToDelete = listOf()))
assertTrue(useCaseResult.isError)
assertTrue(useCaseResult.getThrowableOrNull() is IllegalArgumentException)
verify(exactly = 0) { repository.deleteFiles(any(), removeOnlyLocalCopy = true) }
}
@Test
fun `remove file - ko - other exception`() {
every { repository.deleteFiles(any(), any()) } throws UnauthorizedException()
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isError)
assertTrue(useCaseResult.getThrowableOrNull() is UnauthorizedException)
verify(exactly = 1) { repository.deleteFiles(any(), any()) }
}
}
@@ -0,0 +1,61 @@
/**
* qsfera Android client application
*
* @author Abel García de Prada
* Copyright (C) 2021 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.files.usecases
import eu.qsfera.android.domain.exceptions.UnauthorizedException
import eu.qsfera.android.domain.files.FileRepository
import eu.qsfera.android.testutil.OC_FILE
import io.mockk.every
import io.mockk.mockk
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
class RenameFileUseCaseTest {
private val repository: FileRepository = spyk()
private val setLastUsageFileUseCase: SetLastUsageFileUseCase = mockk(relaxed = true)
private val useCase = RenameFileUseCase(repository, setLastUsageFileUseCase)
private val useCaseParams = RenameFileUseCase.Params(OC_FILE, "Video.mp4")
@Test
fun `rename file - ok`() {
every { repository.renameFile(any(), any()) } returns Unit
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isSuccess)
assertEquals(Unit, useCaseResult.getDataOrNull())
verify(exactly = 1) { repository.renameFile(any(), useCaseParams.newName) }
}
@Test
fun `rename file - ko - other exception`() {
every { repository.renameFile(any(), any()) } throws UnauthorizedException()
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isError)
assertTrue(useCaseResult.getThrowableOrNull() is UnauthorizedException)
verify(exactly = 1) { repository.renameFile(any(), any()) }
}
}
@@ -0,0 +1,57 @@
/**
* qsfera Android client application
*
* @author Christian Schabesberger
* Copyright (C) 2020 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.files.usecases
import eu.qsfera.android.domain.exceptions.UnauthorizedException
import eu.qsfera.android.domain.files.FileRepository
import eu.qsfera.android.testutil.OC_FILE
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert
import org.junit.Test
class SaveFileOrFolderUseCaseTest {
private val fileRepository: FileRepository = spyk()
private val useCase = SaveFileOrFolderUseCase(fileRepository)
private val useCaseParamsFile = SaveFileOrFolderUseCase.Params(OC_FILE)
@Test
fun `save file or folder - ok`() {
val useCaseResult = useCase(useCaseParamsFile)
Assert.assertTrue(useCaseResult.isSuccess)
Assert.assertFalse(useCaseResult.isError)
Assert.assertEquals(Unit, useCaseResult.getDataOrNull())
verify(exactly = 1) { fileRepository.saveFile(useCaseParamsFile.fileToSave) }
}
@Test
fun `save file or folder - ko`() {
every { fileRepository.saveFile(any()) } throws UnauthorizedException()
val useCaseResult = useCase(useCaseParamsFile)
Assert.assertFalse(useCaseResult.isSuccess)
Assert.assertTrue(useCaseResult.getThrowableOrNull() is UnauthorizedException)
verify(exactly = 1) { fileRepository.saveFile(useCaseParamsFile.fileToSave) }
}
}
@@ -0,0 +1,47 @@
/**
* qsfera Android client application
*
* Copyright (C) 2022 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.server.model
import org.junit.Assert.assertEquals
import org.junit.Test
class AuthenticationMethodTest {
@Test
fun basicAuthenticationMethodToString() {
val expectedValue = "basic"
val currentValue = AuthenticationMethod.BASIC_HTTP_AUTH.toString()
assertEquals(expectedValue, currentValue)
}
@Test
fun bearerAuthenticationMethodToString() {
val expectedValue = "bearer"
val currentValue = AuthenticationMethod.BEARER_TOKEN.toString()
assertEquals(expectedValue, currentValue)
}
@Test
fun noneAuthenticationMethodToString() {
val expectedValue = "none"
val currentValue = AuthenticationMethod.NONE.toString()
assertEquals(expectedValue, currentValue)
}
}
@@ -0,0 +1,74 @@
/**
* qsfera Android client application
*
* @author Abel García de Prada
* @author Juan Carlos Garrote Gascón
*
* Copyright (C) 2023 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.server.model
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
class ServerInfoTest {
@Test
fun testConstructor() {
val item = ServerInfo.BasicServer(
"10.3.2.1",
"https://demo.qsfera.eu"
)
assertEquals("https://demo.qsfera.eu", item.baseUrl)
assertEquals("10.3.2.1", item.qsferaVersion)
assertTrue(item.isSecureConnection)
}
@Test
fun testEqualsOk() {
val item1 = ServerInfo.BasicServer(
baseUrl = "https://demo.qsfera.eu",
qsferaVersion = "10.3.2.1",
)
val item2 = ServerInfo.BasicServer(
"10.3.2.1",
"https://demo.qsfera.eu",
)
assertTrue(item1 == item2)
assertFalse(item1 === item2)
}
@Test
fun testEqualsKo() {
val item1 = ServerInfo.BasicServer(
baseUrl = "https://demo.qsfera.eu",
qsferaVersion = "10.3.2.1",
)
val item2 = ServerInfo.BasicServer(
"10.0.0.0",
"https://demo.qsfera.eu",
)
assertFalse(item1 == item2)
assertFalse(item1 === item2)
}
}
@@ -0,0 +1,107 @@
/**
* qsfera Android client application
*
* @author Abel García de Prada
* Copyright (C) 2020 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.server.usecases
import eu.qsfera.android.domain.exceptions.SSLErrorException
import eu.qsfera.android.domain.server.ServerInfoRepository
import eu.qsfera.android.domain.server.usecases.GetServerInfoAsyncUseCase.Companion.TRAILING_SLASH
import eu.qsfera.android.testutil.OC_INSECURE_SERVER_INFO_BASIC_AUTH
import eu.qsfera.android.testutil.OC_SECURE_SERVER_INFO_BASIC_AUTH
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
class GetServerInfoAsyncUseCaseTest {
private val repository: ServerInfoRepository = spyk()
private val useCase = GetServerInfoAsyncUseCase((repository))
private val useCaseParams = GetServerInfoAsyncUseCase.Params(
serverPath = "http://demo.qsfera.eu",
creatingAccount = false,
enforceOIDC = false,
secureConnectionEnforced = false,
)
private val useCaseParamsWithSlash = useCaseParams.copy(serverPath = useCaseParams.serverPath.plus(TRAILING_SLASH))
@Test
fun `get server info - ok`() {
every { repository.getServerInfo(useCaseParams.serverPath, false, false) } returns OC_SECURE_SERVER_INFO_BASIC_AUTH
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isSuccess)
assertEquals(OC_SECURE_SERVER_INFO_BASIC_AUTH, useCaseResult.getDataOrNull())
verify(exactly = 1) { repository.getServerInfo(useCaseParams.serverPath, false, false) }
}
@Test
fun `get server info - ok - slash trimmed`() {
every { repository.getServerInfo(useCaseParams.serverPath, false, false) } returns OC_SECURE_SERVER_INFO_BASIC_AUTH
val useCaseResult = useCase(useCaseParamsWithSlash)
assertTrue(useCaseResult.isSuccess)
assertEquals(OC_SECURE_SERVER_INFO_BASIC_AUTH, useCaseResult.getDataOrNull())
verify(exactly = 1) { repository.getServerInfo(useCaseParams.serverPath, false, false) }
}
@Test
fun `get server info - ko`() {
every { repository.getServerInfo(useCaseParams.serverPath, false, false) } throws Exception()
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isError)
assertTrue(useCaseResult.getThrowableOrNull() is Exception)
verify(exactly = 1) { repository.getServerInfo(useCaseParams.serverPath, false, false) }
}
@Suppress("MaxLineLength")
@Test
fun `Should throw SSLErrorException when secureConnectionEnforced is true and ServerInfoRepository returns ServerInfo with isSecureConnection returning false`() {
every { repository.getServerInfo(useCaseParams.serverPath, false, false) } returns OC_INSECURE_SERVER_INFO_BASIC_AUTH
val useCaseResult = useCase(useCaseParams.copy(secureConnectionEnforced = true))
assertTrue(useCaseResult.isError)
assertTrue(useCaseResult.getThrowableOrNull() is SSLErrorException)
verify(exactly = 1) { repository.getServerInfo(useCaseParams.serverPath, false, false) }
}
@Suppress("MaxLineLength")
@Test
fun `Should work correctly when secureConnectionEnforced is true and ServerInfoRepository returns ServerInfo with isSecureConnection returning true`() {
every { repository.getServerInfo(useCaseParams.serverPath, false, false) } returns OC_SECURE_SERVER_INFO_BASIC_AUTH
val useCaseResult = useCase(useCaseParams.copy(secureConnectionEnforced = true))
assertTrue(useCaseResult.isSuccess)
assertEquals(OC_SECURE_SERVER_INFO_BASIC_AUTH, useCaseResult.getDataOrNull())
verify(exactly = 1) { repository.getServerInfo(useCaseParams.serverPath, false, false) }
}
}
@@ -0,0 +1,64 @@
/**
* qsfera Android client application
*
* @author David González Verdugo
* Copyright (C) 2020 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.sharees.usecases
import eu.qsfera.android.domain.exceptions.NoConnectionWithServerException
import eu.qsfera.android.domain.sharing.sharees.GetShareesAsyncUseCase
import eu.qsfera.android.domain.sharing.sharees.ShareeRepository
import eu.qsfera.android.testutil.OC_ACCOUNT_NAME
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert.assertTrue
import org.junit.Test
class GetShareesAsyncUseCaseTest {
private val repository: ShareeRepository = spyk()
private val useCase = GetShareesAsyncUseCase(repository)
private val useCaseParams = GetShareesAsyncUseCase.Params("user", 1, 5, OC_ACCOUNT_NAME)
@Test
fun `get sharees from server - ok`() {
every { repository.getSharees(any(), any(), any(), any()) } returns arrayListOf()
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isSuccess)
verify(exactly = 1) {
repository.getSharees("user", 1, 5, OC_ACCOUNT_NAME)
}
}
@Test
fun `get sharees from server - ko`() {
every { repository.getSharees(any(), any(), any(), any()) } throws NoConnectionWithServerException()
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isError)
assertTrue(useCaseResult.getThrowableOrNull() is NoConnectionWithServerException)
verify(exactly = 1) {
repository.getSharees("user", 1, 5, OC_ACCOUNT_NAME)
}
}
}
@@ -0,0 +1,240 @@
/**
* qsfera Android client application
*
* @author Abel García de Prada
* Copyright (C) 2020 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.shares.model
import eu.qsfera.android.domain.sharing.shares.model.OCShare
import eu.qsfera.android.domain.sharing.shares.model.ShareType
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
class OCShareTest {
@Test
fun testConstructor() {
val item = OCShare(
1,
ShareType.USER,
"",
"/Photos/image.jpg",
1,
1542628397,
0,
"AnyToken",
"",
"",
false,
"1",
"admin@server",
"",
""
)
assertEquals(1, item.id)
assertEquals(ShareType.USER, item.shareType)
assertEquals("", item.shareWith)
assertEquals("/Photos/image.jpg", item.path)
assertEquals(1, item.permissions)
assertEquals(1542628397, item.sharedDate)
assertEquals(0, item.expirationDate)
assertEquals("AnyToken", item.token)
assertEquals("", item.sharedWithDisplayName)
assertEquals("", item.sharedWithAdditionalInfo)
assertEquals(false, item.isFolder)
assertEquals("1", item.remoteId)
assertEquals("admin@server", item.accountOwner)
assertEquals("", item.name)
assertEquals("", item.shareLink)
}
@Test
fun testEqualsOk() {
val item1 = OCShare(
id = 1,
shareType = ShareType.USER,
shareWith = "",
path = "/Photos/image.jpg",
permissions = 1,
sharedDate = 1542628397,
expirationDate = 0,
token = "AnyToken",
sharedWithDisplayName = "",
sharedWithAdditionalInfo = "",
isFolder = false,
remoteId = "1",
accountOwner = "admin@server",
name = "",
shareLink = ""
)
val item2 = OCShare(
1,
ShareType.USER,
"",
"/Photos/image.jpg",
1,
1542628397,
0,
"AnyToken",
"",
"",
false,
"1",
"admin@server",
"",
""
)
assertTrue(item1 == item2)
assertFalse(item1 === item2)
}
@Test
fun testEqualsDefaultValues() {
val item1 = OCShare(
shareType = ShareType.USER,
shareWith = "",
path = "/Photos/image.jpg",
permissions = 1,
sharedDate = 1542628397,
expirationDate = 0,
token = "AnyToken",
sharedWithDisplayName = "",
sharedWithAdditionalInfo = "",
isFolder = false,
remoteId = "1",
name = "",
shareLink = ""
)
val item2 = OCShare(
null,
ShareType.USER,
"",
"/Photos/image.jpg",
1,
1542628397,
0,
"AnyToken",
"",
"",
false,
"1",
"",
"",
""
)
assertTrue(item1 == item2)
assertFalse(item1 === item2)
}
@Test
fun testEqualsKo() {
val item1 = OCShare(
id = 123,
shareType = ShareType.USER,
shareWith = "",
path = "/Photos/image.jpg",
permissions = 1,
sharedDate = 1542628397,
expirationDate = 0,
token = "AnyToken",
sharedWithDisplayName = "",
sharedWithAdditionalInfo = "",
isFolder = false,
remoteId = "1",
accountOwner = "admin@server",
name = "",
shareLink = ""
)
val item2 = OCShare(
456,
ShareType.USER,
"",
"/Photos/image.jpg",
1,
1542628397,
0,
"AnyToken",
"",
"",
false,
"1",
"admin@server",
"",
""
)
assertFalse(item1 == item2)
assertFalse(item1 === item2)
}
@Test
fun testIsPasswordProtected() {
val item1 = OCShare(
id = 123,
shareType = ShareType.PUBLIC_LINK,
shareWith = "user@server",
path = "/Photos/image.jpg",
permissions = 1,
sharedDate = 1542628397,
expirationDate = 0,
token = "AnyToken",
sharedWithDisplayName = "",
sharedWithAdditionalInfo = "",
isFolder = false,
remoteId = "1",
accountOwner = "admin@server",
name = "",
shareLink = ""
)
assertEquals(true, item1.isPasswordProtected)
val item2 = item1.copy(shareWith = "")
assertEquals(false, item2.isPasswordProtected)
val item3 = item1.copy(shareType = ShareType.GROUP)
assertEquals(false, item3.isPasswordProtected)
}
@Test
fun testShareType() {
val unknown = ShareType.fromValue(-1)
val user = ShareType.fromValue(0)
val group = ShareType.fromValue(1)
val publicLink = ShareType.fromValue(3)
val email = ShareType.fromValue(4)
val contact = ShareType.fromValue(5)
val federated = ShareType.fromValue(6)
val fromValue2 = ShareType.fromValue(2)
assertEquals(ShareType.UNKNOWN, unknown)
assertEquals(ShareType.USER, user)
assertEquals(ShareType.GROUP, group)
assertEquals(ShareType.PUBLIC_LINK, publicLink)
assertEquals(ShareType.EMAIL, email)
assertEquals(ShareType.CONTACT, contact)
assertEquals(ShareType.FEDERATED, federated)
assertNull(fromValue2)
}
}
@@ -0,0 +1,80 @@
/**
* qsfera Android client application
*
* @author Abel García de Prada
* Copyright (C) 2020 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.shares.usecases
import eu.qsfera.android.domain.exceptions.UnauthorizedException
import eu.qsfera.android.domain.sharing.shares.ShareRepository
import eu.qsfera.android.domain.sharing.shares.model.ShareType
import eu.qsfera.android.domain.sharing.shares.usecases.CreatePrivateShareAsyncUseCase
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
class CreatePrivateShareAsyncUseCaseTest {
private val repository: ShareRepository = spyk()
private val useCase = CreatePrivateShareAsyncUseCase(repository)
private val useCaseParams = CreatePrivateShareAsyncUseCase.Params("", ShareType.USER, "", 1, "")
@Test
fun `create private share - ok`() {
every {
repository.insertPrivateShare(any(), any(), any(), any(), any())
} returns Unit
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isSuccess)
assertEquals(Unit, useCaseResult.getDataOrNull())
verify(exactly = 1) { repository.insertPrivateShare("", ShareType.USER, "", 1, "") }
}
@Test
fun `create private share - ko - unauthorized exception`() {
every { repository.insertPrivateShare(any(), any(), any(), any(), any()) } throws UnauthorizedException()
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isError)
assertTrue(useCaseResult.getThrowableOrNull() is UnauthorizedException)
verify(exactly = 1) { repository.insertPrivateShare("", ShareType.USER, "", 1, "") }
}
@Test
fun `create private share - ko - illegal argument exception`() {
val useCaseParamsNotValid1 = useCaseParams.copy(shareType = null)
val useCaseResult1 = useCase(useCaseParamsNotValid1)
assertTrue(useCaseResult1.isError)
assertTrue(useCaseResult1.getThrowableOrNull() is IllegalArgumentException)
val useCaseParamsNotValid2 = useCaseParams.copy(shareType = ShareType.CONTACT)
val useCaseResult2 = useCase(useCaseParamsNotValid2)
assertTrue(useCaseResult2.isError)
assertTrue(useCaseResult2.getThrowableOrNull() is IllegalArgumentException)
verify(exactly = 0) { repository.insertPrivateShare(any(), any(), any(), any(), any()) }
}
}
@@ -0,0 +1,79 @@
/**
* qsfera Android client application
*
* @author Abel García de Prada
* Copyright (C) 2020 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.shares.usecases
import eu.qsfera.android.domain.exceptions.UnauthorizedException
import eu.qsfera.android.domain.sharing.shares.ShareRepository
import eu.qsfera.android.domain.sharing.shares.usecases.CreatePublicShareAsyncUseCase
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
class CreatePublicShareAsyncUseCaseTest {
private val repository: ShareRepository = spyk()
private val useCase = CreatePublicShareAsyncUseCase(repository)
private val useCaseParams = CreatePublicShareAsyncUseCase.Params("", 1, "", "", 100, "")
@Test
fun `create public share - ok`() {
every {
repository.insertPublicShare(any(), any(), any(), any(), any(), any())
} returns Unit
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isSuccess)
assertEquals(Unit, useCaseResult.getDataOrNull())
verify(exactly = 1) { repository.insertPublicShare("", 1, "", "", 100, "") }
}
@Test
fun `create public share - ko`() {
every {
repository.insertPublicShare(any(), any(), any(), any(), any(), any())
} throws UnauthorizedException()
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isError)
assertTrue(useCaseResult.getThrowableOrNull() is UnauthorizedException)
verify(exactly = 1) { repository.insertPublicShare("", 1, "", "", 100, "") }
}
@Test
fun `create public share - ko - illegal argument exception`() {
every {
repository.insertPublicShare(any(), any(), any(), any(), any(), any())
} throws IllegalArgumentException()
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isError)
assertTrue(useCaseResult.getThrowableOrNull() is IllegalArgumentException)
verify(exactly = 1) { repository.insertPublicShare("", 1, "", "", 100, "") }
}
}
@@ -0,0 +1,62 @@
/**
* qsfera Android client application
*
* @author Abel García de Prada
* Copyright (C) 2020 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.shares.usecases
import eu.qsfera.android.domain.exceptions.UnauthorizedException
import eu.qsfera.android.domain.sharing.shares.ShareRepository
import eu.qsfera.android.domain.sharing.shares.usecases.DeleteShareAsyncUseCase
import eu.qsfera.android.testutil.OC_SHARE
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
class DeleteShareAsyncUseCaseTest {
private val repository: ShareRepository = spyk()
private val useCase = DeleteShareAsyncUseCase(repository)
private val useCaseParams = DeleteShareAsyncUseCase.Params(OC_SHARE.remoteId, OC_SHARE.accountOwner)
@Test
fun `delete share - ok`() {
every { repository.deleteShare(any(), any()) } returns Unit
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isSuccess)
assertEquals(Unit, useCaseResult.getDataOrNull())
verify(exactly = 1) { repository.deleteShare(OC_SHARE.remoteId, OC_SHARE.accountOwner) }
}
@Test
fun `delete share - ko`() {
every { repository.deleteShare(any(), any()) } throws UnauthorizedException()
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isError)
assertTrue(useCaseResult.getThrowableOrNull() is UnauthorizedException)
verify(exactly = 1) { repository.deleteShare(OC_SHARE.remoteId, OC_SHARE.accountOwner) }
}
}
@@ -0,0 +1,74 @@
/**
* qsfera Android client application
*
* @author Abel García de Prada
* Copyright (C) 2020 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.shares.usecases
import eu.qsfera.android.domain.exceptions.UnauthorizedException
import eu.qsfera.android.domain.sharing.shares.ShareRepository
import eu.qsfera.android.domain.sharing.shares.usecases.EditPrivateShareAsyncUseCase
import eu.qsfera.android.testutil.OC_SHARE
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
class EditPrivateShareAsyncUseCaseTest {
private val repository: ShareRepository = spyk()
private val useCase = EditPrivateShareAsyncUseCase(repository)
private val useCaseParams =
EditPrivateShareAsyncUseCase.Params(OC_SHARE.remoteId, OC_SHARE.permissions, OC_SHARE.accountOwner)
@Test
fun `edit private share - ok`() {
every { repository.updatePrivateShare(any(), any(), any()) } returns Unit
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isSuccess)
assertEquals(Unit, useCaseResult.getDataOrNull())
verify(exactly = 1) {
repository.updatePrivateShare(
OC_SHARE.remoteId,
OC_SHARE.permissions,
OC_SHARE.accountOwner
)
}
}
@Test
fun `edit private share - ko`() {
every { repository.updatePrivateShare(any(), any(), any()) } throws UnauthorizedException()
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isError)
assertTrue(useCaseResult.getThrowableOrNull() is UnauthorizedException)
verify(exactly = 1) {
repository.updatePrivateShare(
OC_SHARE.remoteId,
OC_SHARE.permissions,
OC_SHARE.accountOwner
)
}
}
}
@@ -0,0 +1,90 @@
/**
* qsfera Android client application
*
* @author Abel García de Prada
* Copyright (C) 2020 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.shares.usecases
import eu.qsfera.android.domain.exceptions.UnauthorizedException
import eu.qsfera.android.domain.sharing.shares.ShareRepository
import eu.qsfera.android.domain.sharing.shares.usecases.EditPublicShareAsyncUseCase
import eu.qsfera.android.testutil.OC_SHARE
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
class EditPublicShareAsyncUseCaseTest {
private val repository: ShareRepository = spyk()
private val useCase = EditPublicShareAsyncUseCase(repository)
private val useCaseParams = EditPublicShareAsyncUseCase.Params(
OC_SHARE.remoteId,
"",
"",
OC_SHARE.expirationDate,
OC_SHARE.permissions,
OC_SHARE.accountOwner
)
@Test
fun `edit public share - ok`() {
every {
repository.updatePublicShare(any(), any(), any(), any(), any(), any())
} returns Unit
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isSuccess)
assertEquals(Unit, useCaseResult.getDataOrNull())
verify(exactly = 1) {
repository.updatePublicShare(
remoteId = OC_SHARE.remoteId,
name = "",
password = "",
expirationDateInMillis = OC_SHARE.expirationDate,
permissions = OC_SHARE.permissions,
accountName = OC_SHARE.accountOwner
)
}
}
@Test
fun `edit public share - ko`() {
every {
repository.updatePublicShare(any(), any(), any(), any(), any(), any())
} throws UnauthorizedException()
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isError)
assertTrue(useCaseResult.getThrowableOrNull() is UnauthorizedException)
verify(exactly = 1) {
repository.updatePublicShare(
remoteId = OC_SHARE.remoteId,
name = "",
password = "",
expirationDateInMillis = OC_SHARE.expirationDate,
permissions = OC_SHARE.permissions,
accountName = OC_SHARE.accountOwner
)
}
}
}
@@ -0,0 +1,71 @@
/**
* qsfera Android client application
*
* @author Abel García de Prada
* Copyright (C) 2020 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.shares.usecases
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import androidx.lifecycle.MutableLiveData
import eu.qsfera.android.domain.sharing.shares.ShareRepository
import eu.qsfera.android.domain.sharing.shares.model.OCShare
import eu.qsfera.android.domain.sharing.shares.usecases.GetShareAsLiveDataUseCase
import eu.qsfera.android.testutil.OC_SHARE
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Rule
import org.junit.Test
class GetShareAsLiveDataUseCaseTest {
@Rule
@JvmField
var instantTaskExecutorRule = InstantTaskExecutorRule()
private val repository: ShareRepository = spyk()
private val useCase = GetShareAsLiveDataUseCase(repository)
private val useCaseParams = GetShareAsLiveDataUseCase.Params(OC_SHARE.remoteId)
@Test
fun `get share as livedata - ok`() {
val shareLiveData = MutableLiveData<OCShare>()
every { repository.getShareAsLiveData(any()) } returns shareLiveData
val shareToEmit = listOf(OC_SHARE)
val shareEmitted = mutableListOf<OCShare>()
useCase(useCaseParams).observeForever {
shareEmitted.add(it)
}
shareToEmit.forEach { shareLiveData.postValue(it) }
assertEquals(shareToEmit, shareEmitted)
verify(exactly = 1) { repository.getShareAsLiveData(OC_SHARE.remoteId) }
}
@Test(expected = Exception::class)
fun `get share as livedata - ko`() {
every { repository.getShareAsLiveData(any()) } throws Exception()
useCase(useCaseParams)
}
}
@@ -0,0 +1,75 @@
/**
* qsfera Android client application
*
* @author Abel García de Prada
* Copyright (C) 2020 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.shares.usecases
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import androidx.lifecycle.MutableLiveData
import eu.qsfera.android.domain.sharing.shares.ShareRepository
import eu.qsfera.android.domain.sharing.shares.model.OCShare
import eu.qsfera.android.domain.sharing.shares.usecases.GetSharesAsLiveDataUseCase
import eu.qsfera.android.testutil.OC_SHARE
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Rule
import org.junit.Test
class GetSharesAsLiveDataUseCaseTest {
@Rule
@JvmField
var instantTaskExecutorRule = InstantTaskExecutorRule()
private val repository: ShareRepository = spyk()
private val useCase = GetSharesAsLiveDataUseCase(repository)
private val useCaseParams = GetSharesAsLiveDataUseCase.Params("", "")
@Test
fun `get shares as livedata - ok`() {
val sharesLiveData = MutableLiveData<List<OCShare>>()
every { repository.getSharesAsLiveData(any(), any()) } returns sharesLiveData
val sharesToEmit = listOf(
OC_SHARE,
OC_SHARE.copy(id = 2),
OC_SHARE.copy(id = 3)
)
val sharesEmitted = mutableListOf<OCShare>()
useCase(useCaseParams).observeForever {
it?.forEach { ocShare -> sharesEmitted.add(ocShare) }
}
sharesLiveData.postValue(sharesToEmit)
assertEquals(sharesToEmit, sharesEmitted)
verify(exactly = 1) { repository.getSharesAsLiveData(any(), any()) }
}
@Test(expected = Exception::class)
fun `get shares as livedata - ko`() {
every { repository.getSharesAsLiveData(any(), any()) } throws Exception()
useCase(useCaseParams)
}
}
@@ -0,0 +1,59 @@
/**
* qsfera Android client application
*
* @author Abel García de Prada
* Copyright (C) 2020 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.shares.usecases
import eu.qsfera.android.domain.exceptions.UnauthorizedException
import eu.qsfera.android.domain.sharing.shares.ShareRepository
import eu.qsfera.android.domain.sharing.shares.usecases.RefreshSharesFromServerAsyncUseCase
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
class RefreshSharesFromServerAsyncUseCaseTest {
private val shareRepository: ShareRepository = spyk()
private val useCase = RefreshSharesFromServerAsyncUseCase((shareRepository))
private val useCaseParams = RefreshSharesFromServerAsyncUseCase.Params("", "")
@Test
fun `refresh shares from server - ok`() {
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isSuccess)
assertEquals(Unit, useCaseResult.getDataOrNull())
verify(exactly = 1) { shareRepository.refreshSharesFromNetwork("", "") }
}
@Test
fun `refresh shares from server - ko`() {
every { shareRepository.refreshSharesFromNetwork(any(), any()) } throws UnauthorizedException()
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isError)
assertTrue(useCaseResult.getThrowableOrNull() is UnauthorizedException)
verify(exactly = 1) { shareRepository.refreshSharesFromNetwork("", "") }
}
}
@@ -0,0 +1,83 @@
/**
* qsfera Android client application
*
* @author Juan Carlos Garrote Gascón
*
* Copyright (C) 2023 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.spaces.model
import eu.qsfera.android.testutil.OC_SPACE_PERSONAL
import eu.qsfera.android.testutil.OC_SPACE_PROJECT_DISABLED
import eu.qsfera.android.testutil.OC_SPACE_PROJECT_WITHOUT_IMAGE
import eu.qsfera.android.testutil.OC_SPACE_PROJECT_WITH_IMAGE
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
class OCSpaceTest {
@Test
fun `test space is personal - ok - true`() {
val ocSpace = OC_SPACE_PERSONAL
assertTrue(ocSpace.isPersonal)
}
@Test
fun `test space is personal - ok - false`() {
val ocSpace = OC_SPACE_PROJECT_WITH_IMAGE
assertFalse(ocSpace.isPersonal)
}
@Test
fun `test space is project - ok - true`() {
val ocSpace = OC_SPACE_PROJECT_WITH_IMAGE
assertTrue(ocSpace.isProject)
}
@Test
fun `test space is project - ok - false`() {
val ocSpace = OC_SPACE_PERSONAL
assertFalse(ocSpace.isProject)
}
@Test
fun `test space is disabled - ok - true`() {
val ocSpace = OC_SPACE_PROJECT_DISABLED
assertTrue(ocSpace.isDisabled)
}
@Test
fun `test space is disabled - ok - false`() {
val ocSpace = OC_SPACE_PROJECT_WITH_IMAGE
assertFalse(ocSpace.isDisabled)
}
@Test
fun `test get space special image - ok - has image`() {
val ocSpace = OC_SPACE_PROJECT_WITH_IMAGE
assertNotNull(ocSpace.getSpaceSpecialImage())
}
@Test
fun `test get space special image - ok - does not have image`() {
val ocSpace = OC_SPACE_PROJECT_WITHOUT_IMAGE
assertNull(ocSpace.getSpaceSpecialImage())
}
}
@@ -0,0 +1,74 @@
/**
* qsfera Android client application
*
* Copyright (C) 2022 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.user.model
import org.junit.Assert
import org.junit.Test
class UserAvatarTest {
@Test
fun testConstructor() {
val item = UserAvatar(
byteArrayOf(1, 2, 3),
"image/png",
"edcdc7d39dc218d197c269c8f75ab0f4"
)
Assert.assertArrayEquals(byteArrayOf(1, 2, 3), item.avatarData)
Assert.assertEquals("image/png", item.mimeType)
Assert.assertEquals("edcdc7d39dc218d197c269c8f75ab0f4", item.eTag)
}
@Test
fun testEqualsOk() {
val item1 = UserAvatar(
byteArrayOf(1, 2, 3),
"image/png",
"edcdc7d39dc218d197c269c8f75ab0f4"
)
val item2 = UserAvatar(
avatarData = byteArrayOf(1, 2, 3),
mimeType = "image/png",
eTag = "edcdc7d39dc218d197c269c8f75ab0f4"
)
Assert.assertTrue(item1 == item2)
Assert.assertFalse(item1 === item2)
}
@Test
fun testEqualsKo() {
val item1 = UserAvatar(
byteArrayOf(1, 3, 2),
"image/png",
"edcdc7d39dc218d197c269c8f75ab0f4"
)
val item2 = UserAvatar(
avatarData = byteArrayOf(1, 2, 3),
mimeType = "image/png",
eTag = "edcdc7d39dc218d197c269c8f75ab0f4"
)
Assert.assertFalse(item1 == item2)
Assert.assertFalse(item1 === item2)
}
}
@@ -0,0 +1,75 @@
/**
* qsfera Android client application
*
* @author Abel García de Prada
* Copyright (C) 2020 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.user.model
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
class UserInfoTest {
@Test
fun testConstructor() {
val item = UserInfo(
"admin",
"adminOc",
"admin@qsfera.eu"
)
assertEquals("admin", item.id)
assertEquals("adminOc", item.displayName)
assertEquals("admin@qsfera.eu", item.email)
}
@Test
fun testEqualsOk() {
val item1 = UserInfo(
id = "admin",
displayName = "adminOc",
email = null
)
val item2 = UserInfo(
"admin",
"adminOc",
null
)
assertTrue(item1 == item2)
assertFalse(item1 === item2)
}
@Test
fun testEqualsKo() {
val item1 = UserInfo(
id = "admin",
displayName = "adminOc",
email = null
)
val item2 = UserInfo(
"admin",
"adminOc",
"demo@qsfera.eu"
)
assertFalse(item1 == item2)
assertFalse(item1 === item2)
}
}
@@ -0,0 +1,203 @@
/**
* qsfera Android client application
*
* @author Abel García de Prada
* Copyright (C) 2020 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.user.model
import eu.qsfera.android.testutil.OC_ACCOUNT_NAME
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
class UserQuotaTest {
@Test
fun testConstructor() {
val item = UserQuota(
"",
800,
200,
1000,
UserQuotaState.NORMAL
)
assertEquals(800, item.available)
assertEquals(200, item.used)
assertEquals(1000, item.getTotal())
}
@Test
fun testEqualsOk() {
val item1 = UserQuota(
accountName = OC_ACCOUNT_NAME,
available = 800,
used = 200,
total = 1000,
state = UserQuotaState.NORMAL
)
val item2 = UserQuota(
OC_ACCOUNT_NAME,
800,
200,
1000,
UserQuotaState.NORMAL
)
assertTrue(item1 == item2)
assertFalse(item1 === item2)
}
@Test
fun testEqualsKo() {
val item1 = UserQuota(
accountName = OC_ACCOUNT_NAME,
available = 800,
used = 200,
total = 1000,
state = UserQuotaState.NORMAL
)
val item2 = UserQuota(
OC_ACCOUNT_NAME,
1000,
200,
1000,
UserQuotaState.NORMAL
)
assertFalse(item1 == item2)
assertFalse(item1 === item2)
}
@Test
fun testGetTotal() {
val item = UserQuota(
accountName = OC_ACCOUNT_NAME,
available = 800_000_000,
used = 20_000_000,
total = 820_000_000,
state = UserQuotaState.NORMAL
)
assertTrue(item.total == 820_000_000.toLong())
}
@Test
fun testGetTotalFullQuota() {
val item = UserQuota(
accountName = OC_ACCOUNT_NAME,
available = 0,
used = 20_000_000,
total = 0,
state = UserQuotaState.NORMAL
)
assertTrue(item.total == 0.toLong())
}
@Test
fun testGetTotalUnlimitedQuota() {
val item1 = UserQuota(
accountName = OC_ACCOUNT_NAME,
available = -3,
used = 20_000_000,
total = 0,
state = UserQuotaState.NORMAL
)
assertTrue(item1.total == 0.toLong())
}
@Test
fun testQuotaLimited() {
val item = UserQuota(
accountName = OC_ACCOUNT_NAME,
available = 200_000,
used = 20_000,
total = 220_000,
state = UserQuotaState.NORMAL
)
assertTrue(item.available > 0)
}
@Test
fun testQuotaUnLimited() {
val item = UserQuota(
accountName = OC_ACCOUNT_NAME,
available = -3,
used = 20_000,
total = 0,
state = UserQuotaState.NORMAL
)
assertFalse(item.available > 0)
}
@Test
fun testGetRelativeUnlimited() {
val item = UserQuota(
accountName = OC_ACCOUNT_NAME,
available = -3,
used = 20_000,
total = 0,
state = UserQuotaState.NORMAL
)
assertEquals(0.0, item.getRelative(), 0.0001)
}
@Test
fun testQuotaRelativeOk() {
val item = UserQuota(
accountName = OC_ACCOUNT_NAME,
available = 80_000,
used = 20_000,
total = 100_000,
state = UserQuotaState.NORMAL
)
assertEquals(20.0, item.getRelative(), 0.0001)
}
@Test
fun testQuotaRelativeTotalIs0() {
val item = UserQuota(
accountName = OC_ACCOUNT_NAME,
available = 0,
used = 0,
total = 0,
state = UserQuotaState.NORMAL
)
assertEquals(0.0, item.getRelative(), 0.0001)
}
@Test
fun testQuotaRelativeTwoDecimals() {
val item = UserQuota(
accountName = OC_ACCOUNT_NAME,
available = 75_000,
used = 20_000,
total = 95_000,
state = UserQuotaState.NORMAL
)
assertEquals(21.05, item.getRelative(), 0.0001)
}
}
@@ -0,0 +1,61 @@
/**
* qsfera Android client application
*
* @author Abel García de Prada
* Copyright (C) 2020 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.user.usecases
import eu.qsfera.android.domain.exceptions.UnauthorizedException
import eu.qsfera.android.domain.user.UserRepository
import eu.qsfera.android.testutil.OC_ACCOUNT_NAME
import eu.qsfera.android.testutil.OC_USER_QUOTA
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
class GetStoredQuotaUseCaseTest {
private val repository: UserRepository = spyk()
private val useCase = GetStoredQuotaUseCase(repository)
private val useCaseParams = GetStoredQuotaUseCase.Params(OC_ACCOUNT_NAME)
@Test
fun `get stored quota - ok`() {
every { repository.getStoredUserQuota(OC_ACCOUNT_NAME) } returns OC_USER_QUOTA
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isSuccess)
assertEquals(OC_USER_QUOTA, useCaseResult.getDataOrNull())
verify(exactly = 1) { repository.getStoredUserQuota(OC_ACCOUNT_NAME) }
}
@Test
fun `get stored quota - ko`() {
every { repository.getStoredUserQuota(OC_ACCOUNT_NAME) } throws UnauthorizedException()
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isError)
assertTrue(useCaseResult.getThrowableOrNull() is UnauthorizedException)
verify(exactly = 1) { repository.getStoredUserQuota(OC_ACCOUNT_NAME) }
}
}
@@ -0,0 +1,61 @@
/**
* qsfera Android client application
*
* @author Abel García de Prada
* Copyright (C) 2020 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.user.usecases
import eu.qsfera.android.domain.exceptions.UnauthorizedException
import eu.qsfera.android.domain.user.UserRepository
import eu.qsfera.android.testutil.OC_ACCOUNT_NAME
import eu.qsfera.android.testutil.OC_USER_AVATAR
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
class GetUserAvatarAsyncUseCaseTest {
private val repository: UserRepository = spyk()
private val useCase = GetUserAvatarAsyncUseCase(repository)
private val useCaseParams = GetUserAvatarAsyncUseCase.Params(OC_ACCOUNT_NAME)
@Test
fun `get user avatar - ok`() {
every { repository.getUserAvatar(OC_ACCOUNT_NAME) } returns OC_USER_AVATAR
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isSuccess)
assertEquals(OC_USER_AVATAR, useCaseResult.getDataOrNull())
verify(exactly = 1) { repository.getUserAvatar(OC_ACCOUNT_NAME) }
}
@Test
fun `get user avatar - ko`() {
every { repository.getUserAvatar(OC_ACCOUNT_NAME) } throws UnauthorizedException()
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isError)
assertTrue(useCaseResult.getThrowableOrNull() is UnauthorizedException)
verify(exactly = 1) { repository.getUserAvatar(OC_ACCOUNT_NAME) }
}
}
@@ -0,0 +1,61 @@
/**
* qsfera Android client application
*
* @author Abel García de Prada
* Copyright (C) 2020 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.user.usecases
import eu.qsfera.android.domain.exceptions.UnauthorizedException
import eu.qsfera.android.domain.user.UserRepository
import eu.qsfera.android.testutil.OC_ACCOUNT_NAME
import eu.qsfera.android.testutil.OC_USER_INFO
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
class GetUserInfoAsyncUseCaseTest {
private val repository: UserRepository = spyk()
private val useCase = GetUserInfoAsyncUseCase(repository)
private val useCaseParams = GetUserInfoAsyncUseCase.Params(OC_ACCOUNT_NAME)
@Test
fun `get user info - ok`() {
every { repository.getUserInfo(OC_ACCOUNT_NAME) } returns OC_USER_INFO
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isSuccess)
assertEquals(OC_USER_INFO, useCaseResult.getDataOrNull())
verify(exactly = 1) { repository.getUserInfo(OC_ACCOUNT_NAME) }
}
@Test
fun `get user info - ko`() {
every { repository.getUserInfo(OC_ACCOUNT_NAME) } throws UnauthorizedException()
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isError)
assertTrue(useCaseResult.getThrowableOrNull() is UnauthorizedException)
verify(exactly = 1) { repository.getUserInfo(OC_ACCOUNT_NAME) }
}
}
@@ -0,0 +1,61 @@
/**
* qsfera Android client application
*
* @author Abel García de Prada
* Copyright (C) 2020 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.user.usecases
import eu.qsfera.android.domain.exceptions.UnauthorizedException
import eu.qsfera.android.domain.user.UserRepository
import eu.qsfera.android.testutil.OC_ACCOUNT_NAME
import eu.qsfera.android.testutil.OC_USER_QUOTA
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
class RefreshUserQuotaFromServerAsyncUseCaseTest {
private val repository: UserRepository = spyk()
private val useCase = RefreshUserQuotaFromServerAsyncUseCase(repository)
private val useCaseParams = RefreshUserQuotaFromServerAsyncUseCase.Params(accountName = OC_ACCOUNT_NAME)
@Test
fun `refresh user quota - ok`() {
every { repository.getUserQuota(OC_ACCOUNT_NAME) } returns OC_USER_QUOTA
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isSuccess)
assertEquals(OC_USER_QUOTA, useCaseResult.getDataOrNull())
verify(exactly = 1) { repository.getUserQuota(OC_ACCOUNT_NAME) }
}
@Test
fun `refresh user quota - ko`() {
every { repository.getUserQuota(OC_ACCOUNT_NAME) } throws UnauthorizedException()
val useCaseResult = useCase(useCaseParams)
assertTrue(useCaseResult.isError)
assertTrue(useCaseResult.getThrowableOrNull() is UnauthorizedException)
verify(exactly = 1) { repository.getUserQuota(OC_ACCOUNT_NAME) }
}
}
@@ -0,0 +1,75 @@
/**
* qsfera Android client application
*
* @author Abel García de Prada
* Copyright (C) 2020 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.qsfera.android.domain.validator
import eu.qsfera.android.domain.exceptions.validation.FileNameException
import eu.qsfera.android.domain.exceptions.validation.FileNameException.FileNameExceptionType
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
class FileNameValidatorTest {
private val validator = FileNameValidator()
@Test
fun `validate name - ok`() {
val result = runCatching { validator.validateOrThrowException("Photos") }
assertEquals(Unit, result.getOrNull())
}
@Test
fun `validate name - ko - empty`() {
val result = runCatching { validator.validateOrThrowException(" ") }
validateExceptionAndType(result, FileNameExceptionType.FILE_NAME_EMPTY)
}
@Test
fun `validate name - ko - back slash`() {
val result = runCatching { validator.validateOrThrowException("/Photos") }
validateExceptionAndType(result, FileNameExceptionType.FILE_NAME_FORBIDDEN_CHARACTERS)
}
@Test
fun `validate name - ko - forward slash`() {
val result = runCatching { validator.validateOrThrowException("\\Photos") }
validateExceptionAndType(result, FileNameExceptionType.FILE_NAME_FORBIDDEN_CHARACTERS)
}
@Test
fun `validate name - ko - both slashes()`() {
val result = runCatching { validator.validateOrThrowException("\\Photos/") }
validateExceptionAndType(result, FileNameExceptionType.FILE_NAME_FORBIDDEN_CHARACTERS)
}
}
private fun validateExceptionAndType(
result: Result<Unit>,
type: FileNameExceptionType
) {
with(result.exceptionOrNull()) {
assertTrue(this is FileNameException)
assertEquals(type, (this as FileNameException).type)
}
}