Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New arch/capabilities #2508

Merged
merged 23 commits into from
May 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
564186f
Create OCCapability entity, DAO and datasources
davigonz Apr 2, 2019
dea1c6d
Create OCCapabilityRepository
davigonz Apr 5, 2019
9c51b78
Include OCCapabilityViewModel
davigonz Apr 5, 2019
2eb9756
Load capabilities from ShareFileFragment [WIP]
davigonz Apr 5, 2019
6b26d17
Use capabilities from ShareFileFragment
davigonz Apr 8, 2019
5ce92e9
Accept pending licenses
davigonz Apr 8, 2019
fb56ffd
Rebase library with new_arch/shares
davigonz Apr 9, 2019
09200ea
Get and insert capabilities when needed
davigonz Apr 10, 2019
6804c24
Include tests for CapabilityContentProvider
davigonz Apr 10, 2019
163bcf6
Fix share unit tests
davigonz Apr 11, 2019
f7ebfd5
OCCapabilityViewModel tests
davigonz Apr 11, 2019
f45a584
Include capability datasources tests
davigonz Apr 11, 2019
0824fa9
Include tests in OCCapabilityRepository
davigonz Apr 11, 2019
d4b6371
Include OCCapabilityDao tests, revert capability changes in file cont…
davigonz Apr 12, 2019
f2a5564
Fix some public share tests and prepare the code to inject capabiliti…
davigonz Apr 12, 2019
cade17d
Add more UI tests for capabilities
davigonz Apr 12, 2019
63fb47e
Add expiration date UI tests to cover public share creation with capa…
davigonz Apr 15, 2019
aec2f8c
extend capabilities tests
jesmrec Apr 16, 2019
ea4652a
add capability ViewModel to shareFragment in ShareFolderFragmentTest
jesmrec Apr 16, 2019
8ab4b98
Apply CR changes
davigonz Apr 26, 2019
28d8068
More CR changes
davigonz Apr 29, 2019
15fd0f2
Fix capabilities not refreshed
davigonz May 2, 2019
9a018dd
Fix Allow users to share via link not refreshed the first time
davigonz May 3, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
/**
* ownCloud Android client application
*
* @author David González Verdugo
* Copyright (C) 2019 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 com.owncloud.android.capabilities.db

import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import androidx.test.platform.app.InstrumentationRegistry
import com.owncloud.android.db.OwncloudDatabase
import com.owncloud.android.lib.resources.shares.ShareType
import com.owncloud.android.lib.resources.status.CapabilityBooleanType
import com.owncloud.android.utils.LiveDataTestUtil.getValue
import com.owncloud.android.utils.TestUtil
import junit.framework.Assert.assertEquals
import org.hamcrest.CoreMatchers.notNullValue
import org.hamcrest.CoreMatchers.nullValue
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@SmallTest
class OCCapabilityDaoTest {
private lateinit var ocCapabilityDao: OCCapabilityDao

@Rule
@JvmField
val instantExecutorRule = InstantTaskExecutorRule()

@Before
fun setUp() {
val context = InstrumentationRegistry.getInstrumentation().targetContext
OwncloudDatabase.switchToInMemory(context)
val db: OwncloudDatabase = OwncloudDatabase.getDatabase(context)
ocCapabilityDao = db.capabilityDao()
}

@Test
fun insertCapabilitiesAndRead() {
ocCapabilityDao.insert(
listOf(
TestUtil.createCapability("user1@server", 3, 2, 1, "3.1"),
TestUtil.createCapability("user2@server", 6, 5, 4, "6.0")
)
)

val capability = getValue(
ocCapabilityDao.getCapabilityForAccount(
"user2@server"
)
)

assertThat(capability, notNullValue())
assertEquals(capability.accountName, "user2@server")
assertEquals(capability.versionMayor, 6)
assertEquals(capability.versionMinor, 5)
assertEquals(capability.versionMicro, 4)
assertEquals(capability.versionString, "6.0")
}

@Test
fun getNonExistingCapabilities() {
ocCapabilityDao.insert(
listOf(
TestUtil.createCapability("user@server", 10, 9, 8, "10.1.4")
)
)

val capability = getValue(
ocCapabilityDao.getCapabilityForAccount(
"user@server2"
)
)

assertThat(capability, nullValue())
}

@Test
fun replaceCapabilityIfAlreadyExists_exists() {
ocCapabilityDao.insert(
listOf(
TestUtil.createCapability(
"admin@server",
3,
2,
1,
"3.7.5",
sharingPublicPasswordEnforced = CapabilityBooleanType.FALSE.value
)
)
)

ocCapabilityDao.replace(
listOf( // Update capability
TestUtil.createCapability(
"admin@server",
3,
2,
1,
"3.7.5",
sharingPublicPasswordEnforced = CapabilityBooleanType.TRUE.value
)
)
)

val capability = getValue(
ocCapabilityDao.getCapabilityForAccount(
"admin@server"
)
)

assertThat(capability, notNullValue())
assertEquals(capability.accountName, "admin@server")
assertEquals(capability.versionMayor, 3)
assertEquals(capability.versionMinor, 2)
assertEquals(capability.versionMicro, 1)
assertEquals(capability.versionString, "3.7.5")
assertEquals(capability.filesSharingPublicPasswordEnforced, 1)
}

@Test
fun replacePublicShareIfAlreadyExists_doesNotExist() {
ocCapabilityDao.insert(
listOf(
TestUtil.createCapability(
"cto@server",
10,
8,
6,
"10.0.2",
sharingPublicPasswordEnforcedReadOnly = CapabilityBooleanType.FALSE.value
)
)
)

ocCapabilityDao.replace(
listOf( // Update capability
TestUtil.createCapability(
"seo@server",
14,
13,
12,
"14.3.8",
sharingPublicPasswordEnforcedReadOnly = CapabilityBooleanType.TRUE.value
)
)
)

val capability1 = getValue(
ocCapabilityDao.getCapabilityForAccount(
"cto@server"
)
)

assertThat(capability1, notNullValue())
assertEquals(capability1.accountName, "cto@server")
assertEquals(capability1.versionMayor, 10)
assertEquals(capability1.versionMinor, 8)
assertEquals(capability1.versionMicro, 6)
assertEquals(capability1.versionString, "10.0.2")
assertEquals(capability1.filesSharingPublicPasswordEnforcedReadOnly, CapabilityBooleanType.FALSE.value)

// capability2 didn't exist before, it should not replace the old one but got created
val capability2 = getValue(
ocCapabilityDao.getCapabilityForAccount(
"seo@server"
)
)

assertThat(capability2, notNullValue())
assertEquals(capability2.accountName, "seo@server")
assertEquals(capability2.versionMayor, 14)
assertEquals(capability2.versionMinor, 13)
assertEquals(capability2.versionMicro, 12)
assertEquals(capability2.versionString, "14.3.8")
assertEquals(capability2.filesSharingPublicPasswordEnforcedReadOnly, CapabilityBooleanType.TRUE.value)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class OCShareDaoTest {
TestUtil.createPublicShare(
path = "/Texts/text1.txt",
isFolder = false,
name = "Text 1 link",
name = "Text 2 link",
shareLink = "http://server:port/s/1"
)
)
Expand All @@ -260,7 +260,7 @@ class OCShareDaoTest {
)

assertThat(textShares, notNullValue())
assertEquals(textShares.size, 1)
assertEquals(textShares.size, 2)
assertEquals(textShares.get(0).name, "Text 1 link")
}

Expand Down
Loading