mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 07:05:49 +03:00
Simplify ContactsBackupIT tests, make errors more clear
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
4abba845d0
commit
210a96936e
1 changed files with 40 additions and 12 deletions
|
@ -22,6 +22,7 @@ import ezvcard.Ezvcard
|
||||||
import ezvcard.VCard
|
import ezvcard.VCard
|
||||||
import junit.framework.Assert.assertEquals
|
import junit.framework.Assert.assertEquals
|
||||||
import junit.framework.Assert.assertTrue
|
import junit.framework.Assert.assertTrue
|
||||||
|
import junit.framework.Assert.fail
|
||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import java.io.BufferedInputStream
|
import java.io.BufferedInputStream
|
||||||
|
@ -46,36 +47,52 @@ class ContactsBackupIT : AbstractOnServerIT() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun importExport() {
|
fun importExport() {
|
||||||
val intArray = IntArray(1)
|
val intArray = intArrayOf(0)
|
||||||
intArray[0] = 0
|
|
||||||
|
|
||||||
// import file to local contacts
|
// import file to local contacts
|
||||||
backgroundJobManager.startImmediateContactsImport(null, null, getFile(vcard).absolutePath, intArray)
|
backgroundJobManager.startImmediateContactsImport(null, null, getFile(vcard).absolutePath, intArray)
|
||||||
|
longSleep()
|
||||||
shortSleep()
|
|
||||||
|
|
||||||
// export contact
|
// export contact
|
||||||
backgroundJobManager.startImmediateContactsBackup(user)
|
backgroundJobManager.startImmediateContactsBackup(user)
|
||||||
|
|
||||||
longSleep()
|
longSleep()
|
||||||
|
|
||||||
val backupFolder: String = targetContext.resources.getString(R.string.contacts_backup_folder) +
|
val backupFolderPath: String = targetContext.resources.getString(R.string.contacts_backup_folder) +
|
||||||
OCFile.PATH_SEPARATOR
|
OCFile.PATH_SEPARATOR
|
||||||
|
|
||||||
refreshFolder("/")
|
refreshFolder("/")
|
||||||
longSleep()
|
longSleep()
|
||||||
|
|
||||||
refreshFolder(backupFolder)
|
|
||||||
longSleep()
|
longSleep()
|
||||||
|
|
||||||
|
refreshFolder(backupFolderPath)
|
||||||
|
longSleep()
|
||||||
|
longSleep()
|
||||||
|
|
||||||
|
if (backupFolderPath.isEmpty()) {
|
||||||
|
fail("backupFolderPath cannot be empty")
|
||||||
|
}
|
||||||
|
|
||||||
val backupOCFile = storageManager.getFolderContent(
|
val backupOCFile = storageManager.getFolderContent(
|
||||||
storageManager.getFileByDecryptedRemotePath(backupFolder),
|
storageManager.getFileByDecryptedRemotePath(backupFolderPath),
|
||||||
false
|
false
|
||||||
)[0]
|
).firstOrNull()
|
||||||
|
|
||||||
|
if (backupOCFile == null) {
|
||||||
|
fail("backup file cannot be null")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (backupOCFile?.storagePath == null) {
|
||||||
|
fail("storage path cannot be null")
|
||||||
|
}
|
||||||
|
|
||||||
assertTrue(DownloadFileOperation(user, backupOCFile, AbstractIT.targetContext).execute(client).isSuccess)
|
assertTrue(DownloadFileOperation(user, backupOCFile, AbstractIT.targetContext).execute(client).isSuccess)
|
||||||
|
|
||||||
val backupFile = File(backupOCFile.storagePath)
|
val backupFile = backupOCFile?.storagePath?.let { File(it) }
|
||||||
|
|
||||||
|
if (backupFile == null) {
|
||||||
|
fail("backupFile cannot be null")
|
||||||
|
}
|
||||||
|
|
||||||
val vcardInputStream = BufferedInputStream(FileInputStream(getFile(vcard)))
|
val vcardInputStream = BufferedInputStream(FileInputStream(getFile(vcard)))
|
||||||
val backupFileInputStream = BufferedInputStream(FileInputStream(backupFile))
|
val backupFileInputStream = BufferedInputStream(FileInputStream(backupFile))
|
||||||
|
|
||||||
|
@ -87,6 +104,17 @@ class ContactsBackupIT : AbstractOnServerIT() {
|
||||||
backupCards.addAll(Ezvcard.parse(backupFileInputStream).all())
|
backupCards.addAll(Ezvcard.parse(backupFileInputStream).all())
|
||||||
|
|
||||||
assertEquals(originalCards.size, backupCards.size)
|
assertEquals(originalCards.size, backupCards.size)
|
||||||
assertEquals(originalCards[0].formattedName.toString(), backupCards[0].formattedName.toString())
|
|
||||||
|
val originalCardFormattedName = originalCards.firstOrNull()?.formattedName
|
||||||
|
if (originalCardFormattedName == null) {
|
||||||
|
fail("originalCardFormattedName cannot be null")
|
||||||
|
}
|
||||||
|
|
||||||
|
val backupCardFormattedName = backupCards.firstOrNull()?.formattedName
|
||||||
|
if (backupCardFormattedName == null) {
|
||||||
|
fail("backupCardFormattedName cannot be null")
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(originalCardFormattedName.toString(), backupCardFormattedName.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue