DesuMe parser
This commit is contained in:
@@ -26,8 +26,8 @@ class RemoteRepositoryTest(source: MangaSource) {
|
||||
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")
|
||||
AssertX.assertContentType(item.coverUrl, "image/*")
|
||||
AssertX.assertContentType(item.url, "text/html", "application/json")
|
||||
Assert.assertFalse(item.title.isBlank())
|
||||
}
|
||||
|
||||
@@ -36,8 +36,8 @@ class RemoteRepositoryTest(source: MangaSource) {
|
||||
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")
|
||||
AssertX.assertContentType(item.coverUrl, "image/*")
|
||||
AssertX.assertContentType(item.url, "text/html", "application/json")
|
||||
Assert.assertFalse(item.title.isBlank())
|
||||
}
|
||||
|
||||
@@ -51,8 +51,8 @@ class RemoteRepositoryTest(source: MangaSource) {
|
||||
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")
|
||||
AssertX.assertContentType(item.coverUrl, "image/*")
|
||||
AssertX.assertContentType(item.url, "text/html", "application/json")
|
||||
Assert.assertFalse(item.title.isBlank())
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ class RemoteRepositoryTest(source: MangaSource) {
|
||||
Assert.assertFalse(details.description.isNullOrEmpty())
|
||||
val chapter = details.chapters!!.random()
|
||||
Assert.assertFalse(chapter.name.isBlank())
|
||||
AssertX.assertContentType(chapter.url, "text", "html")
|
||||
AssertX.assertContentType(chapter.url, "text/html", "application/json")
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -75,7 +75,7 @@ class RemoteRepositoryTest(source: MangaSource) {
|
||||
Assert.assertFalse(pages.isEmpty())
|
||||
val page = pages.random()
|
||||
val fullUrl = runBlocking { repo.getPageFullUrl(page) }
|
||||
AssertX.assertContentType(fullUrl, "image")
|
||||
AssertX.assertContentType(fullUrl, "image/*")
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -6,22 +6,22 @@ import java.net.URL
|
||||
|
||||
object AssertX {
|
||||
|
||||
fun assertContentType(url: String, type: String, subtype: String? = null) {
|
||||
fun assertContentType(url: String, vararg types: String) {
|
||||
Assert.assertFalse("URL is empty", url.isEmpty())
|
||||
val cn = URL(url).openConnection() as HttpURLConnection
|
||||
cn.requestMethod = "HEAD"
|
||||
cn.connect()
|
||||
when (val code = cn.responseCode) {
|
||||
HttpURLConnection.HTTP_MOVED_PERM,
|
||||
HttpURLConnection.HTTP_MOVED_TEMP -> assertContentType(cn.getHeaderField("Location"), type, subtype)
|
||||
HttpURLConnection.HTTP_MOVED_TEMP -> assertContentType(cn.getHeaderField("Location"), *types)
|
||||
HttpURLConnection.HTTP_OK -> {
|
||||
val ct = cn.contentType.substringBeforeLast(';').split("/")
|
||||
Assert.assertEquals(type, ct.first())
|
||||
if (subtype != null) {
|
||||
Assert.assertEquals(subtype, ct.last())
|
||||
}
|
||||
Assert.assertTrue(types.any {
|
||||
val x = it.split('/')
|
||||
x[0] == ct[0] && (x[1] == "*" || x[1] == ct[1])
|
||||
})
|
||||
}
|
||||
else -> Assert.fail("Invalid response code $code")
|
||||
else -> Assert.fail("Invalid response code $code at $url")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user