This commit is contained in:
Aria Moradi
2021-11-01 23:46:46 +03:30
parent 100a4c9d35
commit 64ea8416b2
8 changed files with 91 additions and 81 deletions

View File

@@ -22,7 +22,7 @@ import org.kodein.di.instance
import suwayomi.tachidesk.manga.impl.extension.Extension.getExtensionIconUrl import suwayomi.tachidesk.manga.impl.extension.Extension.getExtensionIconUrl
import suwayomi.tachidesk.manga.impl.util.source.GetCatalogueSource.getCatalogueSource import suwayomi.tachidesk.manga.impl.util.source.GetCatalogueSource.getCatalogueSource
import suwayomi.tachidesk.manga.impl.util.source.GetCatalogueSource.getCatalogueSourceOrStub import suwayomi.tachidesk.manga.impl.util.source.GetCatalogueSource.getCatalogueSourceOrStub
import suwayomi.tachidesk.manga.impl.util.source.GetCatalogueSource.invalidateSourceCache import suwayomi.tachidesk.manga.impl.util.source.GetCatalogueSource.unregisterCatalogueSource
import suwayomi.tachidesk.manga.model.dataclass.SourceDataClass import suwayomi.tachidesk.manga.model.dataclass.SourceDataClass
import suwayomi.tachidesk.manga.model.table.ExtensionTable import suwayomi.tachidesk.manga.model.table.ExtensionTable
import suwayomi.tachidesk.manga.model.table.SourceTable import suwayomi.tachidesk.manga.model.table.SourceTable
@@ -136,7 +136,7 @@ object Source {
pref.saveNewValue(newValue) pref.saveNewValue(newValue)
pref.callChangeListener(newValue) pref.callChangeListener(newValue)
// must reload the source cache because a preference was changed // must reload the source because a preference was changed
invalidateSourceCache(sourceId) unregisterCatalogueSource(sourceId)
} }
} }

View File

@@ -240,7 +240,7 @@ object Extension {
PackageTools.jarLoaderMap.remove(jarPath)?.close() PackageTools.jarLoaderMap.remove(jarPath)?.close()
// clear all loaded sources // clear all loaded sources
sources.forEach { GetCatalogueSource.invalidateSourceCache(it) } sources.forEach { GetCatalogueSource.unregisterCatalogueSource(it) }
File(jarPath).delete() File(jarPath).delete()
} }

View File

@@ -64,7 +64,7 @@ object GetCatalogueSource {
sourceCache += sourcePair sourceCache += sourcePair
} }
fun invalidateSourceCache(sourceId: Long) { fun unregisterCatalogueSource(sourceId: Long) {
sourceCache.remove(sourceId) sourceCache.remove(sourceId)
} }
} }

View File

@@ -30,12 +30,14 @@ import suwayomi.tachidesk.manga.impl.util.lang.awaitSingle
import suwayomi.tachidesk.manga.impl.util.source.GetCatalogueSource.getCatalogueSource import suwayomi.tachidesk.manga.impl.util.source.GetCatalogueSource.getCatalogueSource
import suwayomi.tachidesk.manga.model.dataclass.ExtensionDataClass import suwayomi.tachidesk.manga.model.dataclass.ExtensionDataClass
import suwayomi.tachidesk.server.applicationSetup import suwayomi.tachidesk.server.applicationSetup
import suwayomi.tachidesk.test.BASE_PATH
import suwayomi.tachidesk.test.setLoggingEnabled
import xyz.nulldev.ts.config.CONFIG_PREFIX import xyz.nulldev.ts.config.CONFIG_PREFIX
import java.io.File import java.io.File
import java.util.concurrent.atomic.AtomicInteger import java.util.concurrent.atomic.AtomicInteger
@TestInstance(TestInstance.Lifecycle.PER_CLASS) @TestInstance(TestInstance.Lifecycle.PER_CLASS)
class TestExtensions { class TestExtensionCompatibility {
private val logger = KotlinLogging.logger {} private val logger = KotlinLogging.logger {}
private lateinit var extensions: List<ExtensionDataClass> private lateinit var extensions: List<ExtensionDataClass>
private lateinit var sources: List<HttpSource> private lateinit var sources: List<HttpSource>

View File

@@ -1,21 +0,0 @@
package masstest
/*
* Copyright (C) Contributors to the Suwayomi project
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import ch.qos.logback.classic.Level
import mu.KotlinLogging
import org.slf4j.Logger
fun setLoggingEnabled(enabled: Boolean = true) {
val logger = (KotlinLogging.logger(Logger.ROOT_LOGGER_NAME).underlyingLogger as ch.qos.logback.classic.Logger)
logger.level = if (enabled) {
Level.DEBUG
} else Level.ERROR
}
const val BASE_PATH = "build/tmp/TestDesk"

View File

@@ -7,14 +7,13 @@ package suwayomi.tachidesk.manga.controller
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import org.jetbrains.exposed.sql.deleteAll
import org.jetbrains.exposed.sql.transactions.transaction
import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import suwayomi.tachidesk.ApplicationTest
import suwayomi.tachidesk.manga.impl.Category import suwayomi.tachidesk.manga.impl.Category
import suwayomi.tachidesk.manga.model.table.CategoryTable import suwayomi.tachidesk.manga.model.table.CategoryTable
import suwayomi.tachidesk.test.ApplicationTest
import suwayomi.tachidesk.test.clearTables
internal class CategoryControllerTest : ApplicationTest() { internal class CategoryControllerTest : ApplicationTest() {
@Test @Test
@@ -36,8 +35,8 @@ internal class CategoryControllerTest : ApplicationTest() {
@AfterEach @AfterEach
internal fun tearDown() { internal fun tearDown() {
transaction { clearTables(
CategoryTable.deleteAll() CategoryTable
} )
} }
} }

View File

@@ -7,25 +7,19 @@ package suwayomi.tachidesk.manga.impl
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import org.jetbrains.exposed.sql.batchInsert
import org.jetbrains.exposed.sql.deleteAll
import org.jetbrains.exposed.sql.insertAndGetId
import org.jetbrains.exposed.sql.transactions.transaction
import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance import org.junit.jupiter.api.TestInstance
import suwayomi.tachidesk.ApplicationTest
import suwayomi.tachidesk.manga.impl.Category.DEFAULT_CATEGORY_ID import suwayomi.tachidesk.manga.impl.Category.DEFAULT_CATEGORY_ID
import suwayomi.tachidesk.manga.model.table.CategoryMangaTable import suwayomi.tachidesk.manga.model.table.CategoryMangaTable
import suwayomi.tachidesk.manga.model.table.CategoryTable import suwayomi.tachidesk.manga.model.table.CategoryTable
import suwayomi.tachidesk.manga.model.table.ChapterTable import suwayomi.tachidesk.manga.model.table.ChapterTable
import suwayomi.tachidesk.manga.model.table.ChapterTable.isRead
import suwayomi.tachidesk.manga.model.table.ChapterTable.manga
import suwayomi.tachidesk.manga.model.table.ChapterTable.name
import suwayomi.tachidesk.manga.model.table.ChapterTable.sourceOrder
import suwayomi.tachidesk.manga.model.table.ChapterTable.url
import suwayomi.tachidesk.manga.model.table.MangaTable import suwayomi.tachidesk.manga.model.table.MangaTable
import suwayomi.tachidesk.test.ApplicationTest
import suwayomi.tachidesk.test.clearTables
import suwayomi.tachidesk.test.createChapters
import suwayomi.tachidesk.test.createLibraryManga
@TestInstance(TestInstance.Lifecycle.PER_CLASS) @TestInstance(TestInstance.Lifecycle.PER_CLASS)
class CategoryMangaTest : ApplicationTest() { class CategoryMangaTest : ApplicationTest() {
@@ -67,45 +61,13 @@ class CategoryMangaTest : ApplicationTest() {
) )
} }
private fun createLibraryManga(
_title: String
): Int {
return transaction {
MangaTable.insertAndGetId {
it[title] = _title
it[url] = _title
it[sourceReference] = 1
it[defaultCategory] = true
it[inLibrary] = true
}.value
}
}
private fun createChapters(
mangaId: Int,
amount: Int,
read: Boolean
) {
val list = listOf((0 until amount)).flatten().map { 1 }
transaction {
ChapterTable
.batchInsert(list) {
this[url] = "$it"
this[name] = "$it"
this[sourceOrder] = it
this[isRead] = read
this[manga] = mangaId
}
}
}
@AfterEach @AfterEach
internal fun tearDown() { internal fun tearDown() {
transaction { clearTables(
ChapterTable.deleteAll() ChapterTable,
CategoryMangaTable.deleteAll() CategoryMangaTable,
MangaTable.deleteAll() MangaTable,
CategoryTable.deleteAll() CategoryTable
} )
} }
} }

View File

@@ -0,0 +1,68 @@
package suwayomi.tachidesk.test
/*
* Copyright (C) Contributors to the Suwayomi project
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import ch.qos.logback.classic.Level
import mu.KotlinLogging
import org.jetbrains.exposed.dao.id.IdTable
import org.jetbrains.exposed.sql.batchInsert
import org.jetbrains.exposed.sql.deleteAll
import org.jetbrains.exposed.sql.insertAndGetId
import org.jetbrains.exposed.sql.transactions.transaction
import org.slf4j.Logger
import suwayomi.tachidesk.manga.model.table.ChapterTable
import suwayomi.tachidesk.manga.model.table.MangaTable
fun setLoggingEnabled(enabled: Boolean = true) {
val logger = (KotlinLogging.logger(Logger.ROOT_LOGGER_NAME).underlyingLogger as ch.qos.logback.classic.Logger)
logger.level = if (enabled) {
Level.DEBUG
} else Level.ERROR
}
const val BASE_PATH = "build/tmp/TestDesk"
fun createLibraryManga(
_title: String
): Int {
return transaction {
MangaTable.insertAndGetId {
it[title] = _title
it[url] = _title
it[sourceReference] = 1
it[defaultCategory] = true
it[inLibrary] = true
}.value
}
}
fun createChapters(
mangaId: Int,
amount: Int,
read: Boolean
) {
val list = listOf((0 until amount)).flatten().map { 1 }
transaction {
ChapterTable
.batchInsert(list) {
this[ChapterTable.url] = "$it"
this[ChapterTable.name] = "$it"
this[ChapterTable.sourceOrder] = it
this[ChapterTable.isRead] = read
this[ChapterTable.manga] = mangaId
}
}
}
fun clearTables(vararg tables: IdTable<*>) {
transaction {
for (table in tables) {
table.deleteAll()
}
}
}