Manga parsers unit tests
parent
c765e03b28
commit
f0b3400103
@ -0,0 +1,114 @@
|
|||||||
|
package org.koitharu.kotatsu.parsers
|
||||||
|
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import org.junit.Assert
|
||||||
|
import org.junit.BeforeClass
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.junit.runners.Parameterized
|
||||||
|
import org.koin.core.context.startKoin
|
||||||
|
import org.koin.dsl.module
|
||||||
|
import org.koitharu.kotatsu.core.model.MangaSource
|
||||||
|
import org.koitharu.kotatsu.core.prefs.SourceConfig
|
||||||
|
import org.koitharu.kotatsu.domain.MangaLoaderContext
|
||||||
|
import org.koitharu.kotatsu.domain.MangaProviderFactory
|
||||||
|
import org.koitharu.kotatsu.utils.AssertX
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
@RunWith(Parameterized::class)
|
||||||
|
class RemoteRepositoryTest(source: MangaSource) {
|
||||||
|
|
||||||
|
private val repo = MangaProviderFactory.create(source)
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun getList() {
|
||||||
|
val list = runBlocking { repo.getList(60) }
|
||||||
|
Assert.assertFalse(list.isEmpty())
|
||||||
|
val item = list.random()
|
||||||
|
AssertX.assertContentType(item.coverUrl, "image")
|
||||||
|
AssertX.assertContentType(item.url, "text", "html")
|
||||||
|
Assert.assertFalse(item.title.isBlank())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun search() {
|
||||||
|
val list = runBlocking { repo.getList(0, query = "tail") }
|
||||||
|
Assert.assertFalse(list.isEmpty())
|
||||||
|
val item = list.random()
|
||||||
|
AssertX.assertContentType(item.coverUrl, "image")
|
||||||
|
AssertX.assertContentType(item.url, "text", "html")
|
||||||
|
Assert.assertFalse(item.title.isBlank())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun getTags() {
|
||||||
|
val tags = runBlocking { repo.getTags() }
|
||||||
|
Assert.assertFalse(tags.isEmpty())
|
||||||
|
val tag = tags.random()
|
||||||
|
Assert.assertFalse(tag.key.isBlank())
|
||||||
|
Assert.assertFalse(tag.title.isBlank())
|
||||||
|
val list = runBlocking { repo.getList(0, tag = tag) }
|
||||||
|
Assert.assertFalse(list.isEmpty())
|
||||||
|
val item = list.random()
|
||||||
|
AssertX.assertContentType(item.coverUrl, "image")
|
||||||
|
AssertX.assertContentType(item.url, "text", "html")
|
||||||
|
Assert.assertFalse(item.title.isBlank())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun getDetails() {
|
||||||
|
val manga = runBlocking { repo.getList(0) }.random()
|
||||||
|
val details = runBlocking { repo.getDetails(manga) }
|
||||||
|
Assert.assertFalse(details.chapters.isNullOrEmpty())
|
||||||
|
Assert.assertFalse(details.description.isNullOrEmpty())
|
||||||
|
val chapter = details.chapters!!.random()
|
||||||
|
Assert.assertFalse(chapter.name.isBlank())
|
||||||
|
AssertX.assertContentType(chapter.url, "text", "html")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun getPages() {
|
||||||
|
val manga = runBlocking { repo.getList(0) }.random()
|
||||||
|
val details = runBlocking { repo.getDetails(manga) }
|
||||||
|
val pages = runBlocking { repo.getPages(details.chapters!!.random()) }
|
||||||
|
Assert.assertFalse(pages.isEmpty())
|
||||||
|
val page = pages.random()
|
||||||
|
val fullUrl = runBlocking { repo.getPageFullUrl(page) }
|
||||||
|
AssertX.assertContentType(fullUrl, "image")
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
@BeforeClass
|
||||||
|
fun initialize() {
|
||||||
|
startKoin {
|
||||||
|
modules(listOf(
|
||||||
|
module {
|
||||||
|
factory {
|
||||||
|
OkHttpClient.Builder()
|
||||||
|
.connectTimeout(20, TimeUnit.SECONDS)
|
||||||
|
.readTimeout(60, TimeUnit.SECONDS)
|
||||||
|
.writeTimeout(20, TimeUnit.SECONDS)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
module {
|
||||||
|
single<MangaLoaderContext> {
|
||||||
|
object : MangaLoaderContext() {
|
||||||
|
override fun getSettings(source: MangaSource): SourceConfig {
|
||||||
|
return SourceConfigMock()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
@Parameterized.Parameters(name = "{0}")
|
||||||
|
fun getProviders() = (MangaSource.values().toList() - MangaSource.LOCAL).toTypedArray()
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,37 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.parsers
|
|
||||||
|
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
import okhttp3.OkHttpClient
|
|
||||||
import org.junit.BeforeClass
|
|
||||||
import org.koin.core.context.startKoin
|
|
||||||
import org.koin.dsl.module
|
|
||||||
import org.koitharu.kotatsu.core.model.MangaSource
|
|
||||||
import org.koitharu.kotatsu.core.parser.MangaRepository
|
|
||||||
import org.koitharu.kotatsu.domain.MangaLoaderContext
|
|
||||||
|
|
||||||
abstract class RepositoryTestEnvironment {
|
|
||||||
|
|
||||||
lateinit var repository: MangaRepository
|
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
fun initialize(source: MangaSource) {
|
|
||||||
startKoin {
|
|
||||||
module {
|
|
||||||
factory {
|
|
||||||
OkHttpClient()
|
|
||||||
}
|
|
||||||
single {
|
|
||||||
MangaLoaderContext()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val constructor = source.cls.getConstructor(MangaLoaderContext::class.java)
|
|
||||||
repository = constructor.newInstance(MangaLoaderContext())
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getMangaList() = runBlocking { repository.getList(2) }
|
|
||||||
|
|
||||||
fun getMangaItem() = runBlocking { repository.getDetails(repository.getList(5).last()) }
|
|
||||||
|
|
||||||
fun getTags() = runBlocking { repository.getTags() }
|
|
||||||
}
|
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
package org.koitharu.kotatsu.parsers
|
||||||
|
|
||||||
|
import org.koitharu.kotatsu.core.prefs.SourceConfig
|
||||||
|
|
||||||
|
class SourceConfigMock : SourceConfig {
|
||||||
|
|
||||||
|
override fun getDomain(defaultValue: String) = defaultValue
|
||||||
|
}
|
||||||
@ -1,66 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.parsers.repository
|
|
||||||
|
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
import org.junit.Assert
|
|
||||||
import org.junit.BeforeClass
|
|
||||||
import org.junit.Test
|
|
||||||
import org.junit.runner.RunWith
|
|
||||||
import org.koitharu.kotatsu.core.model.MangaSource
|
|
||||||
import org.koitharu.kotatsu.parsers.MangaParserTest
|
|
||||||
import org.koitharu.kotatsu.parsers.RepositoryTestEnvironment
|
|
||||||
import org.koitharu.kotatsu.utils.AssertX
|
|
||||||
import org.mockito.junit.MockitoJUnitRunner
|
|
||||||
|
|
||||||
@RunWith(MockitoJUnitRunner::class)
|
|
||||||
class MintMangaTest : MangaParserTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
override fun testMangaList() {
|
|
||||||
val list = getMangaList()
|
|
||||||
Assert.assertTrue(list.size == 70)
|
|
||||||
val item = list[40]
|
|
||||||
Assert.assertTrue(item.title.isNotEmpty())
|
|
||||||
Assert.assertTrue(item.rating in 0f..1f)
|
|
||||||
AssertX.assertValidUrl(item.url)
|
|
||||||
AssertX.assertValidUrl(item.coverUrl)
|
|
||||||
Assert.assertEquals(item.source, MangaSource.MINTMANGA)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
override fun testMangaDetails() {
|
|
||||||
val manga = getMangaItem()
|
|
||||||
Assert.assertNotNull(manga.largeCoverUrl)
|
|
||||||
AssertX.assertValidUrl(manga.largeCoverUrl!!)
|
|
||||||
Assert.assertNotNull(manga.chapters)
|
|
||||||
val chapter = manga.chapters!!.last()
|
|
||||||
Assert.assertEquals(chapter.source, MangaSource.MINTMANGA)
|
|
||||||
AssertX.assertValidUrl(chapter.url)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
override fun testMangaPages() {
|
|
||||||
val chapter = getMangaItem().chapters!!.first()
|
|
||||||
val pages = runBlocking { repository.getPages(chapter) }
|
|
||||||
Assert.assertFalse(pages.isEmpty())
|
|
||||||
Assert.assertEquals(pages.first().source, MangaSource.MINTMANGA)
|
|
||||||
AssertX.assertValidUrl(runBlocking { repository.getPageFullUrl(pages.first()) })
|
|
||||||
AssertX.assertValidUrl(runBlocking { repository.getPageFullUrl(pages.last()) })
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
override fun testTags() {
|
|
||||||
val tags = getTags()
|
|
||||||
Assert.assertFalse(tags.isEmpty())
|
|
||||||
val tag = tags.first()
|
|
||||||
Assert.assertFalse(tag.title.isBlank())
|
|
||||||
Assert.assertEquals(tag.source, MangaSource.MINTMANGA)
|
|
||||||
AssertX.assertValidUrl("https://mintmanga.live/list/genre/${tag.key}")
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object : RepositoryTestEnvironment() {
|
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
@BeforeClass
|
|
||||||
fun setUp() = initialize(MangaSource.MINTMANGA)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,66 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.parsers.repository
|
|
||||||
|
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
import org.junit.Assert
|
|
||||||
import org.junit.BeforeClass
|
|
||||||
import org.junit.Test
|
|
||||||
import org.junit.runner.RunWith
|
|
||||||
import org.koitharu.kotatsu.core.model.MangaSource
|
|
||||||
import org.koitharu.kotatsu.parsers.MangaParserTest
|
|
||||||
import org.koitharu.kotatsu.parsers.RepositoryTestEnvironment
|
|
||||||
import org.koitharu.kotatsu.utils.AssertX
|
|
||||||
import org.mockito.junit.MockitoJUnitRunner
|
|
||||||
|
|
||||||
@RunWith(MockitoJUnitRunner::class)
|
|
||||||
class ReadmangaRuTest : MangaParserTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
override fun testMangaList() {
|
|
||||||
val list = getMangaList()
|
|
||||||
Assert.assertTrue(list.size == 70)
|
|
||||||
val item = list[40]
|
|
||||||
Assert.assertTrue(item.title.isNotEmpty())
|
|
||||||
Assert.assertTrue(item.rating in 0f..1f)
|
|
||||||
AssertX.assertValidUrl(item.url)
|
|
||||||
AssertX.assertValidUrl(item.coverUrl)
|
|
||||||
Assert.assertEquals(item.source, MangaSource.READMANGA_RU)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
override fun testMangaDetails() {
|
|
||||||
val manga = getMangaItem()
|
|
||||||
Assert.assertNotNull(manga.largeCoverUrl)
|
|
||||||
AssertX.assertValidUrl(manga.largeCoverUrl!!)
|
|
||||||
Assert.assertNotNull(manga.chapters)
|
|
||||||
val chapter = manga.chapters!!.last()
|
|
||||||
Assert.assertEquals(chapter.source, MangaSource.READMANGA_RU)
|
|
||||||
AssertX.assertValidUrl(chapter.url)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
override fun testMangaPages() {
|
|
||||||
val chapter = getMangaItem().chapters!!.first()
|
|
||||||
val pages = runBlocking { repository.getPages(chapter) }
|
|
||||||
Assert.assertFalse(pages.isEmpty())
|
|
||||||
Assert.assertEquals(pages.first().source, MangaSource.READMANGA_RU)
|
|
||||||
AssertX.assertValidUrl(runBlocking { repository.getPageFullUrl(pages.first()) })
|
|
||||||
AssertX.assertValidUrl(runBlocking { repository.getPageFullUrl(pages.last()) })
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
override fun testTags() {
|
|
||||||
val tags = getTags()
|
|
||||||
Assert.assertFalse(tags.isEmpty())
|
|
||||||
val tag = tags.first()
|
|
||||||
Assert.assertFalse(tag.title.isBlank())
|
|
||||||
Assert.assertEquals(tag.source, MangaSource.READMANGA_RU)
|
|
||||||
AssertX.assertValidUrl("https://readmanga.me/list/genre/${tag.key}")
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object : RepositoryTestEnvironment() {
|
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
@BeforeClass
|
|
||||||
fun setUp() = initialize(MangaSource.READMANGA_RU)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,66 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.parsers.repository
|
|
||||||
|
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
import org.junit.Assert
|
|
||||||
import org.junit.BeforeClass
|
|
||||||
import org.junit.Test
|
|
||||||
import org.junit.runner.RunWith
|
|
||||||
import org.koitharu.kotatsu.core.model.MangaSource
|
|
||||||
import org.koitharu.kotatsu.parsers.MangaParserTest
|
|
||||||
import org.koitharu.kotatsu.parsers.RepositoryTestEnvironment
|
|
||||||
import org.koitharu.kotatsu.utils.AssertX
|
|
||||||
import org.mockito.junit.MockitoJUnitRunner
|
|
||||||
|
|
||||||
@RunWith(MockitoJUnitRunner::class)
|
|
||||||
class SelfMangaTest : MangaParserTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
override fun testMangaList() {
|
|
||||||
val list = getMangaList()
|
|
||||||
Assert.assertTrue(list.size == 70)
|
|
||||||
val item = list[40]
|
|
||||||
Assert.assertTrue(item.title.isNotEmpty())
|
|
||||||
Assert.assertTrue(item.rating in 0f..1f)
|
|
||||||
AssertX.assertValidUrl(item.url)
|
|
||||||
AssertX.assertValidUrl(item.coverUrl)
|
|
||||||
Assert.assertEquals(item.source, MangaSource.SELFMANGA)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
override fun testMangaDetails() {
|
|
||||||
val manga = getMangaItem()
|
|
||||||
Assert.assertNotNull(manga.largeCoverUrl)
|
|
||||||
AssertX.assertValidUrl(manga.largeCoverUrl!!)
|
|
||||||
Assert.assertNotNull(manga.chapters)
|
|
||||||
val chapter = manga.chapters!!.last()
|
|
||||||
Assert.assertEquals(chapter.source, MangaSource.SELFMANGA)
|
|
||||||
AssertX.assertValidUrl(chapter.url)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
override fun testMangaPages() {
|
|
||||||
val chapter = getMangaItem().chapters!!.first()
|
|
||||||
val pages = runBlocking { repository.getPages(chapter) }
|
|
||||||
Assert.assertFalse(pages.isEmpty())
|
|
||||||
Assert.assertEquals(pages.first().source, MangaSource.SELFMANGA)
|
|
||||||
AssertX.assertValidUrl(runBlocking { repository.getPageFullUrl(pages.first()) })
|
|
||||||
AssertX.assertValidUrl(runBlocking { repository.getPageFullUrl(pages.last()) })
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
override fun testTags() {
|
|
||||||
val tags = getTags()
|
|
||||||
Assert.assertFalse(tags.isEmpty())
|
|
||||||
val tag = tags.first()
|
|
||||||
Assert.assertFalse(tag.title.isBlank())
|
|
||||||
Assert.assertEquals(tag.source, MangaSource.SELFMANGA)
|
|
||||||
AssertX.assertValidUrl("https://selfmanga.ru/list/genre/${tag.key}")
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object : RepositoryTestEnvironment() {
|
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
@BeforeClass
|
|
||||||
fun setUp() = initialize(MangaSource.SELFMANGA)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue