mirror of
https://github.com/nextcloud/android.git
synced 2024-11-25 14:45:47 +03:00
Merge pull request #6552 from nextcloud/contactsBackupTest
Contacts backup tests
This commit is contained in:
commit
372e478bfd
5 changed files with 132 additions and 3 deletions
17
src/androidTest/assets/vcard.vcf
Normal file
17
src/androidTest/assets/vcard.vcf
Normal file
|
@ -0,0 +1,17 @@
|
|||
BEGIN:VCARD
|
||||
VERSION:3.0
|
||||
N:Mustermann;Erika;;Dr.;
|
||||
FN:Dr. Erika Mustermann
|
||||
ORG:Wikimedia
|
||||
ROLE:Kommunikation
|
||||
TITLE:Redaktion & Gestaltung
|
||||
PHOTO;VALUE=URL;TYPE=JPEG:http://commons.wikimedia.org/wiki/File:Erika_Mustermann_2010.jpg
|
||||
TEL;TYPE=WORK,VOICE:+49 221 9999123
|
||||
TEL;TYPE=HOME,VOICE:+49 221 1234567
|
||||
ADR;TYPE=HOME:;;Heidestraße 17;Köln;;51147;Germany
|
||||
EMAIL;TYPE=PREF,INTERNET:erika@mustermann.de
|
||||
URL:http://de.wikipedia.org/
|
||||
REV:2014-03-01T22:11:10Z
|
||||
END:VCARD
|
||||
|
||||
## from https://de.wikipedia.org/wiki/VCard#vCard_3.0 on 27.07.2020
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2020 Tobias Kaminsky
|
||||
* Copyright (C) 2020 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.nextcloud.client.jobs
|
||||
|
||||
import android.Manifest
|
||||
import androidx.test.rule.GrantPermissionRule
|
||||
import androidx.work.WorkManager
|
||||
import com.nextcloud.client.core.ClockImpl
|
||||
import com.owncloud.android.AbstractIT
|
||||
import com.owncloud.android.AbstractOnServerIT
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.operations.DownloadFileOperation
|
||||
import ezvcard.Ezvcard
|
||||
import ezvcard.VCard
|
||||
import junit.framework.Assert.assertEquals
|
||||
import junit.framework.Assert.assertTrue
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
|
||||
class ContactsBackupIT : AbstractOnServerIT() {
|
||||
val workmanager = WorkManager.getInstance(targetContext)
|
||||
private val backgroundJobManager = BackgroundJobManagerImpl(workmanager, ClockImpl())
|
||||
|
||||
@get:Rule
|
||||
val writeContactsRule = GrantPermissionRule.grant(Manifest.permission.WRITE_CONTACTS)
|
||||
|
||||
@get:Rule
|
||||
val readContactsRule = GrantPermissionRule.grant(Manifest.permission.READ_CONTACTS)
|
||||
|
||||
private val vcard: String = "vcard.vcf"
|
||||
|
||||
@Test
|
||||
fun importExport() {
|
||||
val intArray = IntArray(1)
|
||||
intArray[0] = 0
|
||||
|
||||
// import file to local contacts
|
||||
backgroundJobManager.startImmediateContactsImport(null, null, getFile(vcard).absolutePath, intArray)
|
||||
|
||||
shortSleep()
|
||||
|
||||
// export contact
|
||||
backgroundJobManager.startImmediateContactsBackup(user)
|
||||
|
||||
longSleep()
|
||||
|
||||
val backupFolder: String = targetContext.resources.getString(R.string.contacts_backup_folder) +
|
||||
OCFile.PATH_SEPARATOR
|
||||
|
||||
refreshFolder("/")
|
||||
longSleep()
|
||||
|
||||
refreshFolder(backupFolder)
|
||||
longSleep()
|
||||
|
||||
val backupOCFile = storageManager.getFolderContent(
|
||||
storageManager.getFileByDecryptedRemotePath(backupFolder),
|
||||
false
|
||||
)[0]
|
||||
|
||||
assertTrue(DownloadFileOperation(account, backupOCFile, AbstractIT.targetContext).execute(client).isSuccess)
|
||||
|
||||
val backupFile = File(backupOCFile.storagePath)
|
||||
|
||||
// verify same
|
||||
val originalCards: ArrayList<VCard> = ArrayList()
|
||||
originalCards.addAll(Ezvcard.parse(getFile(vcard)).all())
|
||||
|
||||
val backupCards: ArrayList<VCard> = ArrayList()
|
||||
backupCards.addAll(Ezvcard.parse(backupFile).all())
|
||||
|
||||
assertEquals(originalCards.size, backupCards.size)
|
||||
assertEquals(originalCards[0].formattedName.toString(), backupCards[0].formattedName.toString())
|
||||
}
|
||||
}
|
|
@ -88,7 +88,9 @@ public abstract class AbstractIT {
|
|||
AccountManager platformAccountManager = AccountManager.get(targetContext);
|
||||
|
||||
for (Account account : platformAccountManager.getAccounts()) {
|
||||
platformAccountManager.removeAccountExplicitly(account);
|
||||
if (account.type.equalsIgnoreCase("nextcloud")) {
|
||||
platformAccountManager.removeAccountExplicitly(account);
|
||||
}
|
||||
}
|
||||
|
||||
Account temp = new Account("test@https://server.com", MainApp.getAccountType(targetContext));
|
||||
|
|
|
@ -27,6 +27,7 @@ import com.owncloud.android.lib.resources.e2ee.ToggleEncryptionRemoteOperation;
|
|||
import com.owncloud.android.lib.resources.files.ReadFolderRemoteOperation;
|
||||
import com.owncloud.android.lib.resources.files.RemoveFileRemoteOperation;
|
||||
import com.owncloud.android.lib.resources.files.model.RemoteFile;
|
||||
import com.owncloud.android.operations.RefreshFolderOperation;
|
||||
import com.owncloud.android.operations.UploadFileOperation;
|
||||
import com.owncloud.android.utils.FileStorageUtils;
|
||||
|
||||
|
@ -59,7 +60,9 @@ public abstract class AbstractOnServerIT extends AbstractIT {
|
|||
AccountManager platformAccountManager = AccountManager.get(targetContext);
|
||||
|
||||
for (Account account : platformAccountManager.getAccounts()) {
|
||||
platformAccountManager.removeAccountExplicitly(account);
|
||||
if (account.type.equalsIgnoreCase("nextcloud")) {
|
||||
platformAccountManager.removeAccountExplicitly(account);
|
||||
}
|
||||
}
|
||||
|
||||
Bundle arguments = androidx.test.platform.app.InstrumentationRegistry.getArguments();
|
||||
|
@ -242,4 +245,15 @@ public abstract class AbstractOnServerIT extends AbstractIT {
|
|||
//
|
||||
// assertNotNull(getStorageManager().getFileByDecryptedRemotePath(ocUpload.getRemotePath()).getRemoteId());
|
||||
}
|
||||
|
||||
protected void refreshFolder(String path) {
|
||||
assertTrue(new RefreshFolderOperation(getStorageManager().getFileByEncryptedRemotePath(path),
|
||||
System.currentTimeMillis(),
|
||||
false,
|
||||
false,
|
||||
getStorageManager(),
|
||||
account,
|
||||
targetContext
|
||||
).execute(client).isSuccess());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -166,7 +166,7 @@ class ContactsBackupWork(
|
|||
UploadFileOperation.CREATED_BY_USER,
|
||||
false,
|
||||
false,
|
||||
FileUploader.NameCollisionPolicy.ASK_USER
|
||||
FileUploader.NameCollisionPolicy.RENAME
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue