diff --git a/readium/lcp/src/main/java/org/readium/r2/lcp/license/model/components/Link.kt b/readium/lcp/src/main/java/org/readium/r2/lcp/license/model/components/Link.kt index fafb9ca193..cdeafd2671 100644 --- a/readium/lcp/src/main/java/org/readium/r2/lcp/license/model/components/Link.kt +++ b/readium/lcp/src/main/java/org/readium/r2/lcp/license/model/components/Link.kt @@ -35,16 +35,14 @@ public data class Link( json: JSONObject, mediaTypeRetriever: MediaTypeRetriever = MediaTypeRetriever() ): Link { - val hrefString = json.optNullableString("href") - ?: throw LcpException.Parsing.Link - - val href = - if (json.optBoolean("templated", false)) { - Href.fromTemplate(hrefString) - } else { - Url(hrefString)?.let { Href(it) } + val href = json.optNullableString("href") + ?.let { + Href( + href = it, + templated = json.optBoolean("templated", false) + ) } - ?: throw LcpException.Parsing.Link + ?: throw LcpException.Parsing.Link return Link( href = href, diff --git a/readium/opds/src/test/java/org/readium/r2/opds/OPDS1ParserTest.kt b/readium/opds/src/test/java/org/readium/r2/opds/OPDS1ParserTest.kt index 4be28109e7..c748060409 100644 --- a/readium/opds/src/test/java/org/readium/r2/opds/OPDS1ParserTest.kt +++ b/readium/opds/src/test/java/org/readium/r2/opds/OPDS1ParserTest.kt @@ -34,7 +34,7 @@ class OPDS1ParserTest { ), links = mutableListOf( Link( - href = Href(Url("https://example.com/opds-catalogs/root.xml")!!), + href = Href("https://example.com/opds-catalogs/root.xml")!!, mediaType = MediaType( "application/atom+xml;profile=opds-catalog;kind=navigation" )!!, @@ -42,7 +42,7 @@ class OPDS1ParserTest { properties = Properties() ), Link( - href = Href(Url("https://example.com/opds-catalogs/root.xml")!!), + href = Href("https://example.com/opds-catalogs/root.xml")!!, mediaType = MediaType( "application/atom+xml;profile=opds-catalog;kind=navigation" )!!, @@ -51,7 +51,7 @@ class OPDS1ParserTest { ), navigation = mutableListOf( Link( - href = Href(Url("https://example.com/opds-catalogs/popular.xml")!!), + href = Href("https://example.com/opds-catalogs/popular.xml")!!, mediaType = MediaType( "application/atom+xml;profile=opds-catalog;kind=acquisition" )!!, @@ -59,7 +59,7 @@ class OPDS1ParserTest { rels = setOf("http://opds-spec.org/sort/popular") ), Link( - href = Href(Url("https://example.com/opds-catalogs/new.xml")!!), + href = Href("https://example.com/opds-catalogs/new.xml")!!, mediaType = MediaType( "application/atom+xml;profile=opds-catalog;kind=acquisition" )!!, @@ -67,7 +67,7 @@ class OPDS1ParserTest { rels = setOf("http://opds-spec.org/sort/new") ), Link( - href = Href(Url("https://example.com/opds-catalogs/unpopular.xml")!!), + href = Href("https://example.com/opds-catalogs/unpopular.xml")!!, mediaType = MediaType( "application/atom+xml;profile=opds-catalog;kind=acquisition" )!!, @@ -102,28 +102,28 @@ class OPDS1ParserTest { assertEquals( mutableListOf( Link( - href = Href(Url("https://example.com/opds-catalogs/vampire.farming.xml")!!), + href = Href("https://example.com/opds-catalogs/vampire.farming.xml")!!, mediaType = MediaType( "application/atom+xml;profile=opds-catalog;kind=acquisition" )!!, rels = setOf("related") ), Link( - href = Href(Url("https://example.com/opds-catalogs/unpopular.xml")!!), + href = Href("https://example.com/opds-catalogs/unpopular.xml")!!, mediaType = MediaType( "application/atom+xml;profile=opds-catalog;kind=acquisition" )!!, rels = setOf("self") ), Link( - href = Href(Url("https://example.com/opds-catalogs/root.xml")!!), + href = Href("https://example.com/opds-catalogs/root.xml")!!, mediaType = MediaType( "application/atom+xml;profile=opds-catalog;kind=navigation" )!!, rels = setOf("start") ), Link( - href = Href(Url("https://example.com/opds-catalogs/root.xml")!!), + href = Href("https://example.com/opds-catalogs/root.xml")!!, mediaType = MediaType( "application/atom+xml;profile=opds-catalog;kind=navigation" )!!, @@ -139,12 +139,12 @@ class OPDS1ParserTest { metadata = OpdsMetadata(title = "Categories"), links = mutableListOf( Link( - href = Href(Url("https://example.com/sci-fi")!!), + href = Href("https://example.com/sci-fi")!!, title = "Science-Fiction", rels = setOf("http://opds-spec.org/facet") ), Link( - href = Href(Url("https://example.com/romance")!!), + href = Href("https://example.com/romance")!!, title = "Romance", rels = setOf("http://opds-spec.org/facet"), properties = Properties(mapOf("numberOfItems" to 600)) @@ -175,7 +175,7 @@ class OPDS1ParserTest { Contributor( localizedName = LocalizedString("Bob the Recursive"), links = listOf( - Link(href = Href(Url("http://opds-spec.org/authors/1285")!!)) + Link(href = Href("http://opds-spec.org/authors/1285")!!) ) ) ), @@ -183,16 +183,14 @@ class OPDS1ParserTest { ), links = listOf( Link( - href = Href(Url("https://example.com/covers/4561.thmb.gif")!!), + href = Href("https://example.com/covers/4561.thmb.gif")!!, mediaType = MediaType("image/gif")!!, rels = setOf("http://opds-spec.org/image/thumbnail") ), Link( href = Href( - Url( - "https://example.com/opds-catalogs/entries/4571.complete.xml" - )!! - ), + "https://example.com/opds-catalogs/entries/4571.complete.xml" + )!!, mediaType = MediaType( "application/atom+xml;type=entry;profile=opds-catalog" )!!, @@ -200,12 +198,12 @@ class OPDS1ParserTest { rels = setOf("alternate") ), Link( - href = Href(Url("https://example.com/content/free/4561.epub")!!), + href = Href("https://example.com/content/free/4561.epub")!!, mediaType = MediaType("application/epub+zip")!!, rels = setOf("http://opds-spec.org/acquisition") ), Link( - href = Href(Url("https://example.com/content/free/4561.mobi")!!), + href = Href("https://example.com/content/free/4561.mobi")!!, mediaType = MediaType("application/x-mobipocket-ebook")!!, rels = setOf("http://opds-spec.org/acquisition") ) @@ -215,7 +213,7 @@ class OPDS1ParserTest { PublicationCollection( links = listOf( Link( - href = Href(Url("https://example.com/covers/4561.lrg.png")!!), + href = Href("https://example.com/covers/4561.lrg.png")!!, mediaType = MediaType("image/png")!!, rels = setOf("http://opds-spec.org/image") ) @@ -238,19 +236,19 @@ class OPDS1ParserTest { Contributor( localizedName = LocalizedString("Stampy McGee"), links = listOf( - Link(href = Href(Url("http://opds-spec.org/authors/21285")!!)) + Link(href = Href("http://opds-spec.org/authors/21285")!!) ) ), Contributor( localizedName = LocalizedString("Alice McGee"), links = listOf( - Link(href = Href(Url("http://opds-spec.org/authors/21284")!!)) + Link(href = Href("http://opds-spec.org/authors/21284")!!) ) ), Contributor( localizedName = LocalizedString("Harold McGee"), links = listOf( - Link(href = Href(Url("http://opds-spec.org/authors/21283")!!)) + Link(href = Href("http://opds-spec.org/authors/21283")!!) ) ) ), @@ -261,7 +259,7 @@ class OPDS1ParserTest { ), links = listOf( Link( - href = Href(Url("https://example.com/content/buy/11241.epub")!!), + href = Href("https://example.com/content/buy/11241.epub")!!, mediaType = MediaType("application/epub+zip")!!, rels = setOf("http://opds-spec.org/acquisition/buy"), properties = Properties( @@ -274,7 +272,7 @@ class OPDS1ParserTest { PublicationCollection( links = listOf( Link( - href = Href(Url("https://example.com/covers/11241.lrg.jpg")!!), + href = Href("https://example.com/covers/11241.lrg.jpg")!!, mediaType = MediaType("image/jpeg")!!, rels = setOf("http://opds-spec.org/image") ) @@ -311,7 +309,7 @@ class OPDS1ParserTest { Contributor( localizedName = LocalizedString("Bob the Recursive"), links = listOf( - Link(href = Href(Url("http://opds-spec.org/authors/1285")!!)) + Link(href = Href("http://opds-spec.org/authors/1285")!!) ) ) ), @@ -319,28 +317,26 @@ class OPDS1ParserTest { ), links = listOf( Link( - href = Href(Url("https://example.com/covers/4561.thmb.gif")!!), + href = Href("https://example.com/covers/4561.thmb.gif")!!, mediaType = MediaType("image/gif")!!, rels = setOf("http://opds-spec.org/image/thumbnail") ), Link( href = Href( - Url( - "https://example.com/opds-catalogs/entries/4571.complete.xml" - )!! - ), + "https://example.com/opds-catalogs/entries/4571.complete.xml" + )!!, mediaType = MediaType( "application/atom+xml;type=entry;profile=opds-catalog" )!!, rels = setOf("self") ), Link( - href = Href(Url("https://example.com/content/free/4561.epub")!!), + href = Href("https://example.com/content/free/4561.epub")!!, mediaType = MediaType("application/epub+zip")!!, rels = setOf("http://opds-spec.org/acquisition") ), Link( - href = Href(Url("https://example.com/content/free/4561.mobi")!!), + href = Href("https://example.com/content/free/4561.mobi")!!, mediaType = MediaType("application/x-mobipocket-ebook")!!, rels = setOf("http://opds-spec.org/acquisition") ) @@ -350,7 +346,7 @@ class OPDS1ParserTest { PublicationCollection( links = listOf( Link( - href = Href(Url("https://example.com/covers/4561.lrg.png")!!), + href = Href("https://example.com/covers/4561.lrg.png")!!, mediaType = MediaType("image/png")!!, rels = setOf("http://opds-spec.org/image") ) diff --git a/readium/shared/src/main/java/org/readium/r2/shared/publication/Href.kt b/readium/shared/src/main/java/org/readium/r2/shared/publication/Href.kt index 5b8f2ec5e9..1287ac2b50 100644 --- a/readium/shared/src/main/java/org/readium/r2/shared/publication/Href.kt +++ b/readium/shared/src/main/java/org/readium/r2/shared/publication/Href.kt @@ -21,19 +21,23 @@ import timber.log.Timber @Parcelize public class Href private constructor(private val href: Url) : Parcelable { - public companion object { - /** - * Creates an [Href] from a valid URL. - */ - public operator fun invoke(href: SharedUrl): Href = - Href(StaticUrl(href)) + /** + * Creates an [Href] from a valid URL. + */ + public constructor(href: SharedUrl) : this(StaticUrl(href)) + public companion object { /** - * Creates an [Href] from an URL template (RFC 6570). + * Creates an [Href] from a valid URL or URL template (RFC 6570). + * + * @param templated Indicates whether [href] is a URL template. */ - @Suppress("RedundantNullableReturnType") // In case we validate the URI template at some point. - public fun fromTemplate(href: String): Href? = - Href(TemplatedUrl(href)) + public operator fun invoke(href: String, templated: Boolean = false): Href? = + if (templated) { + Href(TemplatedUrl(href)) + } else { + SharedUrl(href)?.let { Href(StaticUrl(it)) } + } } /** diff --git a/readium/shared/src/main/java/org/readium/r2/shared/publication/Link.kt b/readium/shared/src/main/java/org/readium/r2/shared/publication/Link.kt index 9375a13a38..1e45962a56 100644 --- a/readium/shared/src/main/java/org/readium/r2/shared/publication/Link.kt +++ b/readium/shared/src/main/java/org/readium/r2/shared/publication/Link.kt @@ -202,7 +202,7 @@ public data class Link( val templated = json.optBoolean("templated", false) val href = if (templated) { - Href.fromTemplate(hrefString) + Href(hrefString, templated = true) } else { // We support existing publications with incorrect HREFs (not valid percent-encoded // URIs). We try to parse them first as valid, but fall back on a percent-decoded diff --git a/readium/shared/src/main/java/org/readium/r2/shared/publication/services/ContentProtectionService.kt b/readium/shared/src/main/java/org/readium/r2/shared/publication/services/ContentProtectionService.kt index 1c680723eb..e2e0d527b3 100644 --- a/readium/shared/src/main/java/org/readium/r2/shared/publication/services/ContentProtectionService.kt +++ b/readium/shared/src/main/java/org/readium/r2/shared/publication/services/ContentProtectionService.kt @@ -285,7 +285,7 @@ private sealed class RouteHandler { private val path = "/~readium/rights/copy" override val link: Link = Link( - href = Href.fromTemplate("$path{?text,peek}")!!, + href = Href("$path{?text,peek}", templated = true)!!, mediaType = mediaType ) @@ -323,7 +323,7 @@ private sealed class RouteHandler { private val path = "/~readium/rights/print" override val link = Link( - href = Href.fromTemplate("$path{?pageCount,peek}")!!, + href = Href("$path{?pageCount,peek}", templated = true)!!, mediaType = mediaType ) diff --git a/readium/shared/src/test/java/org/readium/r2/shared/publication/ContributorTest.kt b/readium/shared/src/test/java/org/readium/r2/shared/publication/ContributorTest.kt index f6cdd727ee..c6a3b5c252 100644 --- a/readium/shared/src/test/java/org/readium/r2/shared/publication/ContributorTest.kt +++ b/readium/shared/src/test/java/org/readium/r2/shared/publication/ContributorTest.kt @@ -17,7 +17,6 @@ import org.junit.Test import org.junit.runner.RunWith import org.readium.r2.shared.assertJSONEquals import org.readium.r2.shared.toJSON -import org.readium.r2.shared.util.Url import org.robolectric.RobolectricTestRunner @RunWith(RobolectricTestRunner::class) @@ -46,8 +45,8 @@ class ContributorTest { roles = setOf("bassist"), position = 4.0, links = listOf( - Link(href = Href(Url("http://link1")!!)), - Link(href = Href(Url("http://link2")!!)) + Link(href = Href("http://link1")!!), + Link(href = Href("http://link2")!!) ) ), Contributor.fromJSON( @@ -218,8 +217,8 @@ class ContributorTest { roles = setOf("bassist"), position = 4.0, links = listOf( - Link(href = Href(Url("http://link1")!!)), - Link(href = Href(Url("http://link2")!!)) + Link(href = Href("http://link1")!!), + Link(href = Href("http://link2")!!) ) ).toJSON() ) diff --git a/readium/shared/src/test/java/org/readium/r2/shared/publication/HrefTest.kt b/readium/shared/src/test/java/org/readium/r2/shared/publication/HrefTest.kt index cfff5c960f..e35d2bb90b 100644 --- a/readium/shared/src/test/java/org/readium/r2/shared/publication/HrefTest.kt +++ b/readium/shared/src/test/java/org/readium/r2/shared/publication/HrefTest.kt @@ -35,7 +35,7 @@ class HrefTest { @Test fun `convert templated Href to Url`() { - val template = Href.fromTemplate("url{?x,hello,y}name")!! + val template = Href("url{?x,hello,y}name", templated = true)!! val parameters = mapOf( "x" to "aaa", @@ -67,22 +67,22 @@ class HrefTest { @Test fun `get is templated`() { - assertFalse(Href(Url("url")!!).isTemplated) - assertTrue(Href.fromTemplate("url")!!.isTemplated) - assertTrue(Href.fromTemplate("url{?x,hello,y}name")!!.isTemplated) + assertFalse(Href("url", templated = false)!!.isTemplated) + assertTrue(Href("url", templated = true)!!.isTemplated) + assertTrue(Href("url{?x,hello,y}name", templated = true)!!.isTemplated) } @Test fun `get template parameters`() { - assertNull(Href(Url("url")!!).parameters) + assertNull(Href("url", templated = false)!!.parameters) assertEquals( listOf(), - Href.fromTemplate("url")!!.parameters + Href("url", templated = true)!!.parameters ) assertEquals( listOf("x", "hello", "y"), - Href.fromTemplate("url{?x,hello,y}name")!!.parameters + Href("url{?x,hello,y}name", templated = true)!!.parameters ) } @@ -91,7 +91,7 @@ class HrefTest { assertEquals("folder/chapter.xhtml", Href(Url("folder/chapter.xhtml")!!).toString()) assertEquals( "url{?x,hello,y}name", - Href.fromTemplate("url{?x,hello,y}name")!!.toString() + Href("url{?x,hello,y}name", templated = true)!!.toString() ) } @@ -102,7 +102,7 @@ class HrefTest { assertEquals(Href(url1), Href(url1)) assertNotEquals(Href(url1), Href(url2)) - assertEquals(Href.fromTemplate("template1"), Href.fromTemplate("template1")!!) - assertNotEquals(Href.fromTemplate("template1"), Href.fromTemplate("template2")!!) + assertEquals(Href("template1", templated = true), Href("template1", templated = true)!!) + assertNotEquals(Href("template1", templated = true), Href("template2", templated = true)!!) } } diff --git a/readium/shared/src/test/java/org/readium/r2/shared/publication/LinkTest.kt b/readium/shared/src/test/java/org/readium/r2/shared/publication/LinkTest.kt index 1de88499d5..dc4eed37f2 100644 --- a/readium/shared/src/test/java/org/readium/r2/shared/publication/LinkTest.kt +++ b/readium/shared/src/test/java/org/readium/r2/shared/publication/LinkTest.kt @@ -33,7 +33,7 @@ class LinkTest { @Test fun `parse full JSON`() { assertEquals( Link( - href = Href(Url("http://href")!!), + href = Href("http://href")!!, mediaType = MediaType.PDF, title = "Link Title", rels = setOf("publication", "cover"), @@ -111,7 +111,7 @@ class LinkTest { @Test fun `parse JSON multiple languages`() { assertEquals( Link.fromJSON(JSONObject("{'href': 'a', 'language': ['fr', 'en']}")), - Link(href = Href(Url("a")!!), languages = listOf("fr", "en")) + Link(href = Href("a")!!, languages = listOf("fr", "en")) ) } @@ -211,7 +211,7 @@ class LinkTest { }""" ), Link( - href = Href.fromTemplate("http://href")!!, + href = Href("http://href", templated = true)!!, mediaType = MediaType.PDF, title = "Link Title", rels = setOf("publication", "cover"), @@ -262,7 +262,7 @@ class LinkTest { @Test fun `Make a copy after adding the given {properties}`() { val link = Link( - href = Href.fromTemplate("http://href")!!, + href = Href("http://href", templated = true)!!, mediaType = MediaType.PDF, title = "Link Title", rels = setOf("publication", "cover"), diff --git a/readium/shared/src/test/java/org/readium/r2/shared/publication/LocatorTest.kt b/readium/shared/src/test/java/org/readium/r2/shared/publication/LocatorTest.kt index 4e054c5ff3..06ddbd0b1d 100644 --- a/readium/shared/src/test/java/org/readium/r2/shared/publication/LocatorTest.kt +++ b/readium/shared/src/test/java/org/readium/r2/shared/publication/LocatorTest.kt @@ -514,12 +514,12 @@ class LocatorCollectionTest { links = listOf( Link( rels = setOf("self"), - href = Href(Url("/978-1503222687/search?query=apple")!!), + href = Href("/978-1503222687/search?query=apple")!!, mediaType = MediaType("application/vnd.readium.locators+json")!! ), Link( rels = setOf("next"), - href = Href(Url("/978-1503222687/search?query=apple&page=2")!!), + href = Href("/978-1503222687/search?query=apple&page=2")!!, mediaType = MediaType("application/vnd.readium.locators+json")!! ) ), @@ -682,12 +682,12 @@ class LocatorCollectionTest { links = listOf( Link( rels = setOf("self"), - href = Href(Url("/978-1503222687/search?query=apple")!!), + href = Href("/978-1503222687/search?query=apple")!!, mediaType = MediaType("application/vnd.readium.locators+json")!! ), Link( rels = setOf("next"), - href = Href(Url("/978-1503222687/search?query=apple&page=2")!!), + href = Href("/978-1503222687/search?query=apple&page=2")!!, mediaType = MediaType("application/vnd.readium.locators+json")!! ) ), diff --git a/readium/shared/src/test/java/org/readium/r2/shared/publication/ManifestTest.kt b/readium/shared/src/test/java/org/readium/r2/shared/publication/ManifestTest.kt index a4b234cb3c..53604a6733 100644 --- a/readium/shared/src/test/java/org/readium/r2/shared/publication/ManifestTest.kt +++ b/readium/shared/src/test/java/org/readium/r2/shared/publication/ManifestTest.kt @@ -48,18 +48,18 @@ class ManifestTest { Manifest( context = listOf("https://readium.org/webpub-manifest/context.jsonld"), metadata = Metadata(localizedTitle = LocalizedString("Title")), - links = listOf(Link(href = Href(Url("manifest.json")!!), rels = setOf("self"))), + links = listOf(Link(href = Href("manifest.json")!!, rels = setOf("self"))), readingOrder = listOf( - Link(href = Href(Url("chap1.html")!!), mediaType = MediaType.HTML) + Link(href = Href("chap1.html")!!, mediaType = MediaType.HTML) ), - resources = listOf(Link(href = Href(Url("image.png")!!), mediaType = MediaType.PNG)), + resources = listOf(Link(href = Href("image.png")!!, mediaType = MediaType.PNG)), tableOfContents = listOf( - Link(href = Href(Url("cover.html")!!)), - Link(href = Href(Url("chap1.html")!!)) + Link(href = Href("cover.html")!!), + Link(href = Href("chap1.html")!!) ), subcollections = mapOf( "sub" to listOf( - PublicationCollection(links = listOf(Link(href = Href(Url("sublink")!!)))) + PublicationCollection(links = listOf(Link(href = Href("sublink")!!))) ) ) ), @@ -98,9 +98,9 @@ class ManifestTest { Manifest( context = listOf("context1", "context2"), metadata = Metadata(localizedTitle = LocalizedString("Title")), - links = listOf(Link(href = Href(Url("manifest.json")!!), rels = setOf("self"))), + links = listOf(Link(href = Href("manifest.json")!!, rels = setOf("self"))), readingOrder = listOf( - Link(href = Href(Url("chap1.html")!!), mediaType = MediaType.HTML) + Link(href = Href("chap1.html")!!, mediaType = MediaType.HTML) ) ), Manifest.fromJSON( @@ -144,9 +144,9 @@ class ManifestTest { assertEquals( Manifest( metadata = Metadata(localizedTitle = LocalizedString("Title")), - links = listOf(Link(href = Href(Url("manifest.json")!!), rels = setOf("self"))), + links = listOf(Link(href = Href("manifest.json")!!, rels = setOf("self"))), readingOrder = listOf( - Link(href = Href(Url("chap1.html")!!), mediaType = MediaType.HTML) + Link(href = Href("chap1.html")!!, mediaType = MediaType.HTML) ) ), Manifest.fromJSON( @@ -170,9 +170,9 @@ class ManifestTest { assertEquals( Manifest( metadata = Metadata(localizedTitle = LocalizedString("Title")), - links = listOf(Link(href = Href(Url("manifest.json")!!), rels = setOf("self"))), + links = listOf(Link(href = Href("manifest.json")!!, rels = setOf("self"))), readingOrder = listOf( - Link(href = Href(Url("chap1.html")!!), mediaType = MediaType.HTML) + Link(href = Href("chap1.html")!!, mediaType = MediaType.HTML) ) ), Manifest.fromJSON( @@ -197,11 +197,11 @@ class ManifestTest { assertEquals( Manifest( metadata = Metadata(localizedTitle = LocalizedString("Title")), - links = listOf(Link(href = Href(Url("manifest.json")!!), rels = setOf("self"))), + links = listOf(Link(href = Href("manifest.json")!!, rels = setOf("self"))), readingOrder = listOf( - Link(href = Href(Url("chap1.html")!!), mediaType = MediaType.HTML) + Link(href = Href("chap1.html")!!, mediaType = MediaType.HTML) ), - resources = listOf(Link(href = Href(Url("withtype")!!), mediaType = MediaType.HTML)) + resources = listOf(Link(href = Href("withtype")!!, mediaType = MediaType.HTML)) ), Manifest.fromJSON( JSONObject( @@ -272,18 +272,18 @@ class ManifestTest { Manifest( context = listOf("https://readium.org/webpub-manifest/context.jsonld"), metadata = Metadata(localizedTitle = LocalizedString("Title")), - links = listOf(Link(href = Href(Url("manifest.json")!!), rels = setOf("self"))), + links = listOf(Link(href = Href("manifest.json")!!, rels = setOf("self"))), readingOrder = listOf( - Link(href = Href(Url("chap1.html")!!), mediaType = MediaType.HTML) + Link(href = Href("chap1.html")!!, mediaType = MediaType.HTML) ), - resources = listOf(Link(href = Href(Url("image.png")!!), mediaType = MediaType.PNG)), + resources = listOf(Link(href = Href("image.png")!!, mediaType = MediaType.PNG)), tableOfContents = listOf( - Link(href = Href(Url("cover.html")!!)), - Link(href = Href(Url("chap1.html")!!)) + Link(href = Href("cover.html")!!), + Link(href = Href("chap1.html")!!) ), subcollections = mapOf( "sub" to listOf( - PublicationCollection(links = listOf(Link(href = Href(Url("sublink")!!)))) + PublicationCollection(links = listOf(Link(href = Href("sublink")!!))) ) ) ).toJSON() @@ -294,7 +294,7 @@ class ManifestTest { val manifest = Manifest( metadata = Metadata(localizedTitle = LocalizedString()), readingOrder = listOf( - Link(href = Href(Url("href")!!), mediaType = MediaType.HTML, title = "Resource") + Link(href = Href("href")!!, mediaType = MediaType.HTML, title = "Resource") ) ) Assert.assertEquals( @@ -304,16 +304,16 @@ class ManifestTest { title = "Resource", locations = Locator.Locations(progression = 0.0) ), - manifest.locatorFromLink(Link(href = Href(Url("href")!!))) + manifest.locatorFromLink(Link(href = Href("href")!!)) ) } @Test fun `get a {Locator} from a link in the reading order, resources or links`() { val manifest = Manifest( metadata = Metadata(localizedTitle = LocalizedString()), - readingOrder = listOf(Link(href = Href(Url("href1")!!), mediaType = MediaType.HTML)), - resources = listOf(Link(href = Href(Url("href2")!!), mediaType = MediaType.HTML)), - links = listOf(Link(href = Href(Url("href3")!!), mediaType = MediaType.HTML)) + readingOrder = listOf(Link(href = Href("href1")!!, mediaType = MediaType.HTML)), + resources = listOf(Link(href = Href("href2")!!, mediaType = MediaType.HTML)), + links = listOf(Link(href = Href("href3")!!, mediaType = MediaType.HTML)) ) Assert.assertEquals( Locator( @@ -321,7 +321,7 @@ class ManifestTest { mediaType = MediaType.HTML, locations = Locator.Locations(progression = 0.0) ), - manifest.locatorFromLink(Link(href = Href(Url("href1")!!))) + manifest.locatorFromLink(Link(href = Href("href1")!!)) ) Assert.assertEquals( Locator( @@ -329,7 +329,7 @@ class ManifestTest { mediaType = MediaType.HTML, locations = Locator.Locations(progression = 0.0) ), - manifest.locatorFromLink(Link(href = Href(Url("href2")!!))) + manifest.locatorFromLink(Link(href = Href("href2")!!)) ) Assert.assertEquals( Locator( @@ -337,7 +337,7 @@ class ManifestTest { mediaType = MediaType.HTML, locations = Locator.Locations(progression = 0.0) ), - manifest.locatorFromLink(Link(href = Href(Url("href3")!!))) + manifest.locatorFromLink(Link(href = Href("href3")!!)) ) } @@ -345,7 +345,7 @@ class ManifestTest { val manifest = Manifest( metadata = Metadata(localizedTitle = LocalizedString()), readingOrder = listOf( - Link(href = Href(Url("href")!!), mediaType = MediaType.HTML, title = "Resource") + Link(href = Href("href")!!, mediaType = MediaType.HTML, title = "Resource") ) ) Assert.assertEquals( @@ -356,11 +356,7 @@ class ManifestTest { locations = Locator.Locations(fragments = listOf("page=42")) ), manifest.locatorFromLink( - Link( - href = Href(Url("href#page=42")!!), - mediaType = MediaType.XML, - title = "My link" - ) + Link(href = Href("href#page=42")!!, mediaType = MediaType.XML, title = "My link") ) ) } @@ -368,7 +364,7 @@ class ManifestTest { @Test fun `get a {Locator} falling back on the {Link} title`() { val manifest = Manifest( metadata = Metadata(localizedTitle = LocalizedString()), - readingOrder = listOf(Link(href = Href(Url("href")!!), mediaType = MediaType.HTML)) + readingOrder = listOf(Link(href = Href("href")!!, mediaType = MediaType.HTML)) ) Assert.assertEquals( Locator( @@ -378,11 +374,7 @@ class ManifestTest { locations = Locator.Locations(fragments = listOf("page=42")) ), manifest.locatorFromLink( - Link( - href = Href(Url("href#page=42")!!), - mediaType = MediaType.XML, - title = "My link" - ) + Link(href = Href("href#page=42")!!, mediaType = MediaType.XML, title = "My link") ) ) } @@ -390,8 +382,8 @@ class ManifestTest { @Test fun `get a {Locator} from a {Link} not found in the manifest`() { val manifest = Manifest( metadata = Metadata(localizedTitle = LocalizedString()), - readingOrder = listOf(Link(href = Href(Url("href")!!), mediaType = MediaType.HTML)) + readingOrder = listOf(Link(href = Href("href")!!, mediaType = MediaType.HTML)) ) - Assert.assertNull(manifest.locatorFromLink(Link(href = Href(Url("notfound")!!)))) + Assert.assertNull(manifest.locatorFromLink(Link(href = Href("notfound")!!))) } } diff --git a/readium/shared/src/test/java/org/readium/r2/shared/publication/PublicationCollectionTest.kt b/readium/shared/src/test/java/org/readium/r2/shared/publication/PublicationCollectionTest.kt index f810e77f76..a4ce6c177d 100644 --- a/readium/shared/src/test/java/org/readium/r2/shared/publication/PublicationCollectionTest.kt +++ b/readium/shared/src/test/java/org/readium/r2/shared/publication/PublicationCollectionTest.kt @@ -15,7 +15,6 @@ import org.junit.Assert.assertNull import org.junit.Test import org.junit.runner.RunWith import org.readium.r2.shared.assertJSONEquals -import org.readium.r2.shared.util.Url import org.robolectric.RobolectricTestRunner @RunWith(RobolectricTestRunner::class) @@ -24,7 +23,7 @@ class PublicationCollectionTest { @Test fun `parse minimal JSON`() { assertEquals( PublicationCollection( - links = listOf(Link(href = Href(Url("/link")!!))) + links = listOf(Link(href = Href("/link")!!)) ), PublicationCollection.fromJSON( JSONObject( @@ -41,22 +40,22 @@ class PublicationCollectionTest { assertEquals( PublicationCollection( metadata = mapOf("metadata1" to "value"), - links = listOf(Link(href = Href(Url("/link")!!))), + links = listOf(Link(href = Href("/link")!!)), subcollections = mapOf( "sub1" to listOf( - PublicationCollection(links = listOf(Link(href = Href(Url("/sublink")!!)))) + PublicationCollection(links = listOf(Link(href = Href("/sublink")!!))) ), "sub2" to listOf( PublicationCollection( links = listOf( - Link(href = Href(Url("/sublink1")!!)), - Link(href = Href(Url("/sublink2")!!)) + Link(href = Href("/sublink1")!!), + Link(href = Href("/sublink2")!!) ) ) ), "sub3" to listOf( - PublicationCollection(links = listOf(Link(href = Href(Url("/sublink3")!!)))), - PublicationCollection(links = listOf(Link(href = Href(Url("/sublink4")!!)))) + PublicationCollection(links = listOf(Link(href = Href("/sublink3")!!))), + PublicationCollection(links = listOf(Link(href = Href("/sublink4")!!))) ) ) ), @@ -104,19 +103,19 @@ class PublicationCollectionTest { assertEquals( mapOf( "sub1" to listOf( - PublicationCollection(links = listOf(Link(href = Href(Url("/sublink")!!)))) + PublicationCollection(links = listOf(Link(href = Href("/sublink")!!))) ), "sub2" to listOf( PublicationCollection( links = listOf( - Link(href = Href(Url("/sublink1")!!)), - Link(href = Href(Url("/sublink2")!!)) + Link(href = Href("/sublink1")!!), + Link(href = Href("/sublink2")!!) ) ) ), "sub3" to listOf( - PublicationCollection(links = listOf(Link(href = Href(Url("/sublink3")!!)))), - PublicationCollection(links = listOf(Link(href = Href(Url("/sublink4")!!)))) + PublicationCollection(links = listOf(Link(href = Href("/sublink3")!!))), + PublicationCollection(links = listOf(Link(href = Href("/sublink4")!!))) ) ), PublicationCollection.collectionsFromJSON( @@ -157,7 +156,7 @@ class PublicationCollectionTest { "links": [{"href": "/link", "templated": false}] }""" ), - PublicationCollection(links = listOf(Link(href = Href(Url("/link")!!)))).toJSON() + PublicationCollection(links = listOf(Link(href = Href("/link")!!))).toJSON() ) } @@ -202,22 +201,22 @@ class PublicationCollectionTest { ), PublicationCollection( metadata = mapOf("metadata1" to "value"), - links = listOf(Link(href = Href(Url("/link")!!))), + links = listOf(Link(href = Href("/link")!!)), subcollections = mapOf( "sub1" to listOf( - PublicationCollection(links = listOf(Link(href = Href(Url("/sublink")!!)))) + PublicationCollection(links = listOf(Link(href = Href("/sublink")!!))) ), "sub2" to listOf( PublicationCollection( links = listOf( - Link(href = Href(Url("/sublink1")!!)), - Link(href = Href(Url("/sublink2")!!)) + Link(href = Href("/sublink1")!!), + Link(href = Href("/sublink2")!!) ) ) ), "sub3" to listOf( - PublicationCollection(links = listOf(Link(href = Href(Url("/sublink3")!!)))), - PublicationCollection(links = listOf(Link(href = Href(Url("/sublink4")!!)))) + PublicationCollection(links = listOf(Link(href = Href("/sublink3")!!))), + PublicationCollection(links = listOf(Link(href = Href("/sublink4")!!))) ) ) ).toJSON() @@ -259,19 +258,19 @@ class PublicationCollectionTest { ), mapOf( "sub1" to listOf( - PublicationCollection(links = listOf(Link(href = Href(Url("/sublink")!!)))) + PublicationCollection(links = listOf(Link(href = Href("/sublink")!!))) ), "sub2" to listOf( PublicationCollection( links = listOf( - Link(href = Href(Url("/sublink1")!!)), - Link(href = Href(Url("/sublink2")!!)) + Link(href = Href("/sublink1")!!), + Link(href = Href("/sublink2")!!) ) ) ), "sub3" to listOf( - PublicationCollection(links = listOf(Link(href = Href(Url("/sublink3")!!)))), - PublicationCollection(links = listOf(Link(href = Href(Url("/sublink4")!!)))) + PublicationCollection(links = listOf(Link(href = Href("/sublink3")!!))), + PublicationCollection(links = listOf(Link(href = Href("/sublink4")!!))) ) ).toJSONObject() ) diff --git a/readium/shared/src/test/java/org/readium/r2/shared/publication/PublicationTest.kt b/readium/shared/src/test/java/org/readium/r2/shared/publication/PublicationTest.kt index 6f765000ed..1718dfbc2e 100644 --- a/readium/shared/src/test/java/org/readium/r2/shared/publication/PublicationTest.kt +++ b/readium/shared/src/test/java/org/readium/r2/shared/publication/PublicationTest.kt @@ -121,10 +121,7 @@ class PublicationTest { @Test fun `get {baseUrl} computes the URL from the {self} link`() { val publication = createPublication( links = listOf( - Link( - href = Href(Url("http://domain.com/path/manifest.json")!!), - rels = setOf("self") - ) + Link(href = Href("http://domain.com/path/manifest.json")!!, rels = setOf("self")) ) ) assertEquals( @@ -147,24 +144,24 @@ class PublicationTest { assertTrue( createPublication( readingOrder = listOf( - Link(href = Href(Url("c1.mp3")!!), mediaType = MediaType.MP3), - Link(href = Href(Url("c2.aac")!!), mediaType = MediaType.AAC) + Link(href = Href("c1.mp3")!!, mediaType = MediaType.MP3), + Link(href = Href("c2.aac")!!, mediaType = MediaType.AAC) ) ).conformsTo(Profile.AUDIOBOOK) ) assertTrue( createPublication( readingOrder = listOf( - Link(href = Href(Url("c1.jpg")!!), mediaType = MediaType.JPEG), - Link(href = Href(Url("c2.png")!!), mediaType = MediaType.PNG) + Link(href = Href("c1.jpg")!!, mediaType = MediaType.JPEG), + Link(href = Href("c2.png")!!, mediaType = MediaType.PNG) ) ).conformsTo(Profile.DIVINA) ) assertTrue( createPublication( readingOrder = listOf( - Link(href = Href(Url("c1.pdf")!!), mediaType = MediaType.PDF), - Link(href = Href(Url("c2.pdf")!!), mediaType = MediaType.PDF) + Link(href = Href("c1.pdf")!!, mediaType = MediaType.PDF), + Link(href = Href("c2.pdf")!!, mediaType = MediaType.PDF) ) ).conformsTo(Profile.PDF) ) @@ -173,16 +170,16 @@ class PublicationTest { assertFalse( createPublication( readingOrder = listOf( - Link(href = Href(Url("c1.mp3")!!), mediaType = MediaType.MP3), - Link(href = Href(Url("c2.jpg")!!), mediaType = MediaType.JPEG) + Link(href = Href("c1.mp3")!!, mediaType = MediaType.MP3), + Link(href = Href("c2.jpg")!!, mediaType = MediaType.JPEG) ) ).conformsTo(Profile.AUDIOBOOK) ) assertFalse( createPublication( readingOrder = listOf( - Link(href = Href(Url("c1.mp3")!!), mediaType = MediaType.MP3), - Link(href = Href(Url("c2.jpg")!!), mediaType = MediaType.JPEG) + Link(href = Href("c1.mp3")!!, mediaType = MediaType.MP3), + Link(href = Href("c2.jpg")!!, mediaType = MediaType.JPEG) ) ).conformsTo(Profile.DIVINA) ) @@ -191,8 +188,8 @@ class PublicationTest { assertTrue( createPublication( readingOrder = listOf( - Link(href = Href(Url("c1.xhtml")!!), mediaType = MediaType.XHTML), - Link(href = Href(Url("c2.xhtml")!!), mediaType = MediaType.XHTML) + Link(href = Href("c1.xhtml")!!, mediaType = MediaType.XHTML), + Link(href = Href("c2.xhtml")!!, mediaType = MediaType.XHTML) ), conformsTo = setOf(Profile.EPUB) ).conformsTo(Profile.EPUB) @@ -200,8 +197,8 @@ class PublicationTest { assertTrue( createPublication( readingOrder = listOf( - Link(href = Href(Url("c1.html")!!), mediaType = MediaType.HTML), - Link(href = Href(Url("c2.html")!!), mediaType = MediaType.HTML) + Link(href = Href("c1.html")!!, mediaType = MediaType.HTML), + Link(href = Href("c2.html")!!, mediaType = MediaType.HTML) ), conformsTo = setOf(Profile.EPUB) ).conformsTo(Profile.EPUB) @@ -209,24 +206,24 @@ class PublicationTest { assertFalse( createPublication( readingOrder = listOf( - Link(href = Href(Url("c1.xhtml")!!), mediaType = MediaType.XHTML), - Link(href = Href(Url("c2.xhtml")!!), mediaType = MediaType.XHTML) + Link(href = Href("c1.xhtml")!!, mediaType = MediaType.XHTML), + Link(href = Href("c2.xhtml")!!, mediaType = MediaType.XHTML) ) ).conformsTo(Profile.EPUB) ) assertFalse( createPublication( readingOrder = listOf( - Link(href = Href(Url("c1.html")!!), mediaType = MediaType.HTML), - Link(href = Href(Url("c2.html")!!), mediaType = MediaType.HTML) + Link(href = Href("c1.html")!!, mediaType = MediaType.HTML), + Link(href = Href("c2.html")!!, mediaType = MediaType.HTML) ) ).conformsTo(Profile.EPUB) ) assertFalse( createPublication( readingOrder = listOf( - Link(href = Href(Url("c1.pdf")!!), mediaType = MediaType.PDF), - Link(href = Href(Url("c2.pdf")!!), mediaType = MediaType.PDF) + Link(href = Href("c1.pdf")!!, mediaType = MediaType.PDF), + Link(href = Href("c2.pdf")!!, mediaType = MediaType.PDF) ), conformsTo = setOf(Profile.EPUB) ).conformsTo(Profile.EPUB) @@ -236,8 +233,8 @@ class PublicationTest { assertTrue( createPublication( readingOrder = listOf( - Link(href = Href(Url("c1.mp3")!!), mediaType = MediaType.MP3), - Link(href = Href(Url("c2.aac")!!), mediaType = MediaType.AAC) + Link(href = Href("c1.mp3")!!, mediaType = MediaType.MP3), + Link(href = Href("c2.aac")!!, mediaType = MediaType.AAC) ), conformsTo = setOf(Profile.DIVINA) ).conformsTo(Profile.AUDIOBOOK) @@ -245,8 +242,8 @@ class PublicationTest { assertFalse( createPublication( readingOrder = listOf( - Link(href = Href(Url("c1.mp3")!!), mediaType = MediaType.MP3), - Link(href = Href(Url("c2.aac")!!), mediaType = MediaType.AAC) + Link(href = Href("c1.mp3")!!, mediaType = MediaType.MP3), + Link(href = Href("c2.aac")!!, mediaType = MediaType.AAC) ), conformsTo = setOf(Profile.DIVINA) ).conformsTo(Profile.DIVINA) @@ -256,20 +253,20 @@ class PublicationTest { val profile = Profile("http://extension") assertTrue( createPublication( - readingOrder = listOf(Link(href = Href(Url("file")!!))), + readingOrder = listOf(Link(href = Href("file")!!)), conformsTo = setOf(profile) ).conformsTo(profile) ) } @Test fun `find the first {Link} with the given {rel}`() { - val link1 = Link(href = Href(Url("found")!!), rels = setOf("rel1")) - val link2 = Link(href = Href(Url("found")!!), rels = setOf("rel2")) - val link3 = Link(href = Href(Url("found")!!), rels = setOf("rel3")) + val link1 = Link(href = Href("found")!!, rels = setOf("rel1")) + val link2 = Link(href = Href("found")!!, rels = setOf("rel2")) + val link3 = Link(href = Href("found")!!, rels = setOf("rel3")) val publication = createPublication( - links = listOf(Link(href = Href(Url("other")!!)), link1), - readingOrder = listOf(Link(href = Href(Url("other")!!)), link2), - resources = listOf(Link(href = Href(Url("other")!!)), link3) + links = listOf(Link(href = Href("other")!!), link1), + readingOrder = listOf(Link(href = Href("other")!!), link2), + resources = listOf(Link(href = Href("other")!!), link3) ) assertEquals(link1, publication.linkWithRel("rel1")) @@ -284,29 +281,29 @@ class PublicationTest { @Test fun `find all the links with the given {rel}`() { val publication = createPublication( links = listOf( - Link(href = Href(Url("l1")!!)), - Link(href = Href(Url("l2")!!), rels = setOf("rel1")) + Link(href = Href("l1")!!), + Link(href = Href("l2")!!, rels = setOf("rel1")) ), readingOrder = listOf( - Link(href = Href(Url("l3")!!)), - Link(href = Href(Url("l4")!!), rels = setOf("rel1")) + Link(href = Href("l3")!!), + Link(href = Href("l4")!!, rels = setOf("rel1")) ), resources = listOf( Link( - href = Href(Url("l5")!!), + href = Href("l5")!!, alternates = listOf( - Link(href = Href(Url("alternate")!!), rels = setOf("rel1")) + Link(href = Href("alternate")!!, rels = setOf("rel1")) ) ), - Link(href = Href(Url("l6")!!), rels = setOf("rel1")) + Link(href = Href("l6")!!, rels = setOf("rel1")) ) ) assertEquals( listOf( - Link(href = Href(Url("l4")!!), rels = setOf("rel1")), - Link(href = Href(Url("l6")!!), rels = setOf("rel1")), - Link(href = Href(Url("l2")!!), rels = setOf("rel1")) + Link(href = Href("l4")!!, rels = setOf("rel1")), + Link(href = Href("l6")!!, rels = setOf("rel1")), + Link(href = Href("l2")!!, rels = setOf("rel1")) ), publication.linksWithRel("rel1") ) @@ -317,19 +314,19 @@ class PublicationTest { } @Test fun `find the first {Link} with the given {href}`() { - val link1 = Link(href = Href(Url("href1")!!)) - val link2 = Link(href = Href(Url("href2")!!)) - val link3 = Link(href = Href(Url("href3")!!)) - val link4 = Link(href = Href(Url("href4")!!)) - val link5 = Link(href = Href(Url("href5")!!)) + val link1 = Link(href = Href("href1")!!) + val link2 = Link(href = Href("href2")!!) + val link3 = Link(href = Href("href3")!!) + val link4 = Link(href = Href("href4")!!) + val link5 = Link(href = Href("href5")!!) val publication = createPublication( - links = listOf(Link(href = Href(Url("other")!!)), link1), + links = listOf(Link(href = Href("other")!!), link1), readingOrder = listOf( Link( - href = Href(Url("other")!!), + href = Href("other")!!, alternates = listOf( Link( - href = Href(Url("alt1")!!), + href = Href("alt1")!!, alternates = listOf( link2 ) @@ -340,10 +337,10 @@ class PublicationTest { ), resources = listOf( Link( - href = Href(Url("other")!!), + href = Href("other")!!, children = listOf( Link( - href = Href(Url("alt1")!!), + href = Href("alt1")!!, children = listOf( link4 ) @@ -362,9 +359,9 @@ class PublicationTest { } @Test fun `find the first {Link} with the given {href} without query parameters`() { - val link = Link(href = Href(Url("http://example.com/index.html")!!)) + val link = Link(href = Href("http://example.com/index.html")!!) val publication = createPublication( - readingOrder = listOf(Link(href = Href(Url("other")!!)), link) + readingOrder = listOf(Link(href = Href("other")!!), link) ) assertEquals( @@ -374,9 +371,9 @@ class PublicationTest { } @Test fun `find the first {Link} with the given {href} without anchor`() { - val link = Link(href = Href(Url("http://example.com/index.html")!!)) + val link = Link(href = Href("http://example.com/index.html")!!) val publication = createPublication( - readingOrder = listOf(Link(href = Href(Url("other")!!)), link) + readingOrder = listOf(Link(href = Href("other")!!), link) ) assertEquals(link, publication.linkWithHref(Url("http://example.com/index.html#sec1")!!)) @@ -394,7 +391,7 @@ class PublicationTest { } } - val link = Link(href = Href(Url("link?param1=a¶m2=b")!!)) + val link = Link(href = Href("link?param1=a¶m2=b")!!) val publication = createPublication( resources = listOf(link), servicesBuilder = Publication.ServicesBuilder( @@ -408,13 +405,13 @@ class PublicationTest { } @Test fun `find the first resource {Link} with the given {href}`() { - val link1 = Link(href = Href(Url("href1")!!)) - val link2 = Link(href = Href(Url("href2")!!)) - val link3 = Link(href = Href(Url("href3")!!)) + val link1 = Link(href = Href("href1")!!) + val link2 = Link(href = Href("href2")!!) + val link3 = Link(href = Href("href3")!!) val publication = createPublication( - links = listOf(Link(href = Href(Url("other")!!)), link1), - readingOrder = listOf(Link(href = Href(Url("other")!!)), link2), - resources = listOf(Link(href = Href(Url("other")!!)), link3) + links = listOf(Link(href = Href("other")!!), link1), + readingOrder = listOf(Link(href = Href("other")!!), link2), + resources = listOf(Link(href = Href("other")!!), link3) ) assertEquals(link1, publication.linkWithHref(Url("href1")!!)) diff --git a/readium/shared/src/test/java/org/readium/r2/shared/publication/SubjectTest.kt b/readium/shared/src/test/java/org/readium/r2/shared/publication/SubjectTest.kt index 6db198f937..78fd6c3bff 100644 --- a/readium/shared/src/test/java/org/readium/r2/shared/publication/SubjectTest.kt +++ b/readium/shared/src/test/java/org/readium/r2/shared/publication/SubjectTest.kt @@ -17,7 +17,6 @@ import org.junit.Test import org.junit.runner.RunWith import org.readium.r2.shared.assertJSONEquals import org.readium.r2.shared.toJSON -import org.readium.r2.shared.util.Url import org.robolectric.RobolectricTestRunner @RunWith(RobolectricTestRunner::class) @@ -45,8 +44,8 @@ class SubjectTest { scheme = "http://scheme", code = "CODE", links = listOf( - Link(href = Href(Url("pub1")!!)), - Link(href = Href(Url("pub2")!!)) + Link(href = Href("pub1")!!), + Link(href = Href("pub2")!!) ) ), Subject.fromJSON( @@ -182,8 +181,8 @@ class SubjectTest { scheme = "http://scheme", code = "CODE", links = listOf( - Link(href = Href(Url("pub1")!!)), - Link(href = Href(Url("pub2")!!)) + Link(href = Href("pub1")!!), + Link(href = Href("pub2")!!) ) ).toJSON() ) diff --git a/readium/shared/src/test/java/org/readium/r2/shared/publication/epub/PresentationTest.kt b/readium/shared/src/test/java/org/readium/r2/shared/publication/epub/PresentationTest.kt index 7b31386dc3..c31dd04e77 100644 --- a/readium/shared/src/test/java/org/readium/r2/shared/publication/epub/PresentationTest.kt +++ b/readium/shared/src/test/java/org/readium/r2/shared/publication/epub/PresentationTest.kt @@ -16,7 +16,6 @@ import org.readium.r2.shared.publication.Href import org.readium.r2.shared.publication.Link import org.readium.r2.shared.publication.Properties import org.readium.r2.shared.publication.presentation.Presentation -import org.readium.r2.shared.util.Url import org.robolectric.RobolectricTestRunner @RunWith(RobolectricTestRunner::class) @@ -63,7 +62,7 @@ class PresentationTest { } private fun createLink(layout: EpubLayout?) = Link( - href = Href(Url("res")!!), + href = Href("res")!!, properties = Properties( otherProperties = layout?.let { mapOf("layout" to layout.value) } ?: emptyMap() diff --git a/readium/shared/src/test/java/org/readium/r2/shared/publication/epub/PublicationTest.kt b/readium/shared/src/test/java/org/readium/r2/shared/publication/epub/PublicationTest.kt index ae4bc10817..76ef8c5013 100644 --- a/readium/shared/src/test/java/org/readium/r2/shared/publication/epub/PublicationTest.kt +++ b/readium/shared/src/test/java/org/readium/r2/shared/publication/epub/PublicationTest.kt @@ -13,7 +13,6 @@ import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith import org.readium.r2.shared.publication.* -import org.readium.r2.shared.util.Url import org.robolectric.RobolectricTestRunner @RunWith(RobolectricTestRunner::class) @@ -29,7 +28,7 @@ class PublicationTest { ) @Test fun `get {pageList}`() { - val links = listOf(Link(href = Href(Url("/page1.html")!!))) + val links = listOf(Link(href = Href("/page1.html")!!)) assertEquals( links, createPublication( @@ -45,7 +44,7 @@ class PublicationTest { } @Test fun `get {landmarks}`() { - val links = listOf(Link(href = Href(Url("/landmark.html")!!))) + val links = listOf(Link(href = Href("/landmark.html")!!)) assertEquals( links, createPublication( @@ -61,7 +60,7 @@ class PublicationTest { } @Test fun `get {listOfAudioClips}`() { - val links = listOf(Link(href = Href(Url("/audio.mp3")!!))) + val links = listOf(Link(href = Href("/audio.mp3")!!)) assertEquals( links, createPublication( @@ -77,7 +76,7 @@ class PublicationTest { } @Test fun `get {listOfIllustrations}`() { - val links = listOf(Link(href = Href(Url("/image.jpg")!!))) + val links = listOf(Link(href = Href("/image.jpg")!!)) assertEquals( links, createPublication( @@ -93,7 +92,7 @@ class PublicationTest { } @Test fun `get {listOfTables}`() { - val links = listOf(Link(href = Href(Url("/table.html")!!))) + val links = listOf(Link(href = Href("/table.html")!!)) assertEquals( links, createPublication( @@ -111,7 +110,7 @@ class PublicationTest { } @Test fun `get {listOfVideoClips}`() { - val links = listOf(Link(href = Href(Url("/video.mov")!!))) + val links = listOf(Link(href = Href("/video.mov")!!)) assertEquals( links, createPublication( diff --git a/readium/shared/src/test/java/org/readium/r2/shared/publication/opds/PropertiesTest.kt b/readium/shared/src/test/java/org/readium/r2/shared/publication/opds/PropertiesTest.kt index 4ce38b9025..0d32607d0d 100644 --- a/readium/shared/src/test/java/org/readium/r2/shared/publication/opds/PropertiesTest.kt +++ b/readium/shared/src/test/java/org/readium/r2/shared/publication/opds/PropertiesTest.kt @@ -17,7 +17,6 @@ import org.readium.r2.shared.opds.* import org.readium.r2.shared.publication.Href import org.readium.r2.shared.publication.Link import org.readium.r2.shared.publication.Properties -import org.readium.r2.shared.util.Url import org.readium.r2.shared.util.mediatype.MediaType import org.robolectric.RobolectricTestRunner @@ -113,7 +112,7 @@ class PropertiesTest { @Test fun `get Properties {authenticate} when available`() { assertEquals( Link( - href = Href(Url("https://example.com/authentication.json")!!), + href = Href("https://example.com/authentication.json")!!, mediaType = MediaType("application/opds-authentication+json")!! ), Properties( diff --git a/readium/shared/src/test/java/org/readium/r2/shared/publication/opds/PublicationTest.kt b/readium/shared/src/test/java/org/readium/r2/shared/publication/opds/PublicationTest.kt index 5e98e164af..2614548695 100644 --- a/readium/shared/src/test/java/org/readium/r2/shared/publication/opds/PublicationTest.kt +++ b/readium/shared/src/test/java/org/readium/r2/shared/publication/opds/PublicationTest.kt @@ -13,7 +13,6 @@ import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith import org.readium.r2.shared.publication.* -import org.readium.r2.shared.util.Url import org.robolectric.RobolectricTestRunner @RunWith(RobolectricTestRunner::class) @@ -29,7 +28,7 @@ class PublicationTest { ) @Test fun `get {images}`() { - val links = listOf(Link(href = Href(Url("/image.png")!!))) + val links = listOf(Link(href = Href("/image.png")!!)) assertEquals( links, createPublication( diff --git a/readium/shared/src/test/java/org/readium/r2/shared/publication/services/LocatorServiceTest.kt b/readium/shared/src/test/java/org/readium/r2/shared/publication/services/LocatorServiceTest.kt index 974e1154bc..0199ed243d 100644 --- a/readium/shared/src/test/java/org/readium/r2/shared/publication/services/LocatorServiceTest.kt +++ b/readium/shared/src/test/java/org/readium/r2/shared/publication/services/LocatorServiceTest.kt @@ -26,9 +26,9 @@ class LocatorServiceTest { fun `locate from Locator`() = runTest { val service = createService( readingOrder = listOf( - Link(href = Href(Url("chap1")!!), mediaType = MediaType.XML), - Link(href = Href(Url("chap2")!!), mediaType = MediaType.XML), - Link(href = Href(Url("chap3")!!), mediaType = MediaType.XML) + Link(href = Href("chap1")!!, mediaType = MediaType.XML), + Link(href = Href("chap2")!!, mediaType = MediaType.XML), + Link(href = Href("chap3")!!, mediaType = MediaType.XML) ) ) val locator = Locator( @@ -54,8 +54,8 @@ class LocatorServiceTest { fun `locate from Locator not found`() = runTest { val service = createService( readingOrder = listOf( - Link(href = Href(Url("chap1")!!), mediaType = MediaType.XML), - Link(href = Href(Url("chap3")!!), mediaType = MediaType.XML) + Link(href = Href("chap1")!!, mediaType = MediaType.XML), + Link(href = Href("chap3")!!, mediaType = MediaType.XML) ) ) val locator = Locator( diff --git a/readium/shared/src/test/java/org/readium/r2/shared/publication/services/PositionsServiceTest.kt b/readium/shared/src/test/java/org/readium/r2/shared/publication/services/PositionsServiceTest.kt index 161b4f05cf..4b1b628646 100644 --- a/readium/shared/src/test/java/org/readium/r2/shared/publication/services/PositionsServiceTest.kt +++ b/readium/shared/src/test/java/org/readium/r2/shared/publication/services/PositionsServiceTest.kt @@ -124,7 +124,7 @@ class PerResourcePositionsServiceTest { @Test fun `Positions from a {readingOrder} with one resource`() { val service = PerResourcePositionsService( - readingOrder = listOf(Link(href = Href(Url("res")!!), mediaType = MediaType.PNG)), + readingOrder = listOf(Link(href = Href("res")!!, mediaType = MediaType.PNG)), fallbackMediaType = MediaType.BINARY ) @@ -147,9 +147,9 @@ class PerResourcePositionsServiceTest { fun `Positions from a {readingOrder} with a few resources`() { val service = PerResourcePositionsService( readingOrder = listOf( - Link(href = Href(Url("res")!!)), - Link(href = Href(Url("chap1")!!), mediaType = MediaType.PNG), - Link(href = Href(Url("chap2")!!), mediaType = MediaType.PNG, title = "Chapter 2") + Link(href = Href("res")!!), + Link(href = Href("chap1")!!, mediaType = MediaType.PNG), + Link(href = Href("chap2")!!, mediaType = MediaType.PNG, title = "Chapter 2") ), fallbackMediaType = MediaType.BINARY ) @@ -190,7 +190,7 @@ class PerResourcePositionsServiceTest { fun `{type} fallbacks on the given media type`() { val services = PerResourcePositionsService( readingOrder = listOf( - Link(href = Href(Url("res")!!)) + Link(href = Href("res")!!) ), fallbackMediaType = MediaType("image/*")!! ) diff --git a/readium/shared/src/test/java/org/readium/r2/shared/publication/services/content/iterators/HtmlResourceContentIteratorTest.kt b/readium/shared/src/test/java/org/readium/r2/shared/publication/services/content/iterators/HtmlResourceContentIteratorTest.kt index 36bed6bdfb..bc8e1c4d19 100644 --- a/readium/shared/src/test/java/org/readium/r2/shared/publication/services/content/iterators/HtmlResourceContentIteratorTest.kt +++ b/readium/shared/src/test/java/org/readium/r2/shared/publication/services/content/iterators/HtmlResourceContentIteratorTest.kt @@ -27,7 +27,7 @@ import org.robolectric.RobolectricTestRunner @RunWith(RobolectricTestRunner::class) class HtmlResourceContentIteratorTest { - private val link = Link(href = Href(Url("/dir/res.xhtml")!!), mediaType = MediaType.XHTML) + private val link = Link(href = Href("/dir/res.xhtml")!!, mediaType = MediaType.XHTML) private val locator = Locator(href = Url("/dir/res.xhtml")!!, mediaType = MediaType.XHTML) private val html = """ @@ -383,7 +383,7 @@ class HtmlResourceContentIteratorTest { progression = 0.0, selector = "html > body > img:nth-child(1)" ), - embeddedLink = Link(href = Href(Url("/dir/image.png")!!)), + embeddedLink = Link(href = Href("/dir/image.png")!!), caption = null, attributes = emptyList() ), @@ -392,7 +392,7 @@ class HtmlResourceContentIteratorTest { progression = 0.5, selector = "html > body > img:nth-child(2)" ), - embeddedLink = Link(href = Href(Url("/cover.jpg")!!)), + embeddedLink = Link(href = Href("/cover.jpg")!!), caption = null, attributes = listOf(Attribute(ACCESSIBILITY_LABEL, "Accessibility description")) ) @@ -423,7 +423,7 @@ class HtmlResourceContentIteratorTest { progression = 0.0, selector = "html > body > audio:nth-child(1)" ), - embeddedLink = Link(href = Href(Url("/dir/audio.mp3")!!)), + embeddedLink = Link(href = Href("/dir/audio.mp3")!!), attributes = emptyList() ), Content.AudioElement( @@ -432,10 +432,10 @@ class HtmlResourceContentIteratorTest { selector = "html > body > audio:nth-child(2)" ), embeddedLink = Link( - href = Href(Url("/dir/audio.mp3")!!), + href = Href("/dir/audio.mp3")!!, mediaType = MediaType.MP3, alternates = listOf( - Link(href = Href(Url("/dir/audio.ogg")!!), mediaType = MediaType.OGG) + Link(href = Href("/dir/audio.ogg")!!, mediaType = MediaType.OGG) ) ), attributes = emptyList() @@ -467,7 +467,7 @@ class HtmlResourceContentIteratorTest { progression = 0.0, selector = "html > body > video:nth-child(1)" ), - embeddedLink = Link(href = Href(Url("/dir/video.mp4")!!)), + embeddedLink = Link(href = Href("/dir/video.mp4")!!), attributes = emptyList() ), Content.VideoElement( @@ -476,11 +476,11 @@ class HtmlResourceContentIteratorTest { selector = "html > body > video:nth-child(2)" ), embeddedLink = Link( - href = Href(Url("/dir/video.mp4")!!), + href = Href("/dir/video.mp4")!!, mediaType = MediaType("video/mp4")!!, alternates = listOf( Link( - href = Href(Url("/dir/video.m4v")!!), + href = Href("/dir/video.m4v")!!, mediaType = MediaType("video/x-m4v")!! ) ) diff --git a/readium/streamer/src/test/java/org/readium/r2/streamer/parser/audio/AudioLocatorServiceTest.kt b/readium/streamer/src/test/java/org/readium/r2/streamer/parser/audio/AudioLocatorServiceTest.kt index 51c1c8cb84..1131667b2a 100644 --- a/readium/streamer/src/test/java/org/readium/r2/streamer/parser/audio/AudioLocatorServiceTest.kt +++ b/readium/streamer/src/test/java/org/readium/r2/streamer/parser/audio/AudioLocatorServiceTest.kt @@ -25,8 +25,8 @@ class AudioLocatorServiceTest { fun `locate(Locator) matching reading order HREF`() = runBlocking { val service = AudioLocatorService( listOf( - Link(Href(Url("l1")!!)), - Link(Href(Url("l2")!!)) + Link(Href("l1")!!), + Link(Href("l2")!!) ) ) @@ -42,8 +42,8 @@ class AudioLocatorServiceTest { fun `locate(Locator) returns null if no match`() = runBlocking { val service = AudioLocatorService( listOf( - Link(Href(Url("l1")!!)), - Link(Href(Url("l2")!!)) + Link(Href("l1")!!), + Link(Href("l2")!!) ) ) @@ -59,8 +59,8 @@ class AudioLocatorServiceTest { fun `locate(Locator) uses totalProgression`() = runBlocking { val service = AudioLocatorService( listOf( - Link(Href(Url("l1")!!), mediaType = MediaType.MP3, duration = 100.0), - Link(Href(Url("l2")!!), mediaType = MediaType.MP3, duration = 100.0) + Link(Href("l1")!!, mediaType = MediaType.MP3, duration = 100.0), + Link(Href("l2")!!, mediaType = MediaType.MP3, duration = 100.0) ) ) @@ -126,8 +126,8 @@ class AudioLocatorServiceTest { fun `locate(Locator) using totalProgression keeps title and text`() = runBlocking { val service = AudioLocatorService( listOf( - Link(Href(Url("l1")!!), mediaType = MediaType.MP3, duration = 100.0), - Link(Href(Url("l2")!!), mediaType = MediaType.MP3, duration = 100.0) + Link(Href("l1")!!, mediaType = MediaType.MP3, duration = 100.0), + Link(Href("l2")!!, mediaType = MediaType.MP3, duration = 100.0) ) ) @@ -165,8 +165,8 @@ class AudioLocatorServiceTest { fun `locate progression`() = runBlocking { val service = AudioLocatorService( listOf( - Link(Href(Url("l1")!!), mediaType = MediaType.MP3, duration = 100.0), - Link(Href(Url("l2")!!), mediaType = MediaType.MP3, duration = 100.0) + Link(Href("l1")!!, mediaType = MediaType.MP3, duration = 100.0), + Link(Href("l2")!!, mediaType = MediaType.MP3, duration = 100.0) ) ) @@ -240,8 +240,8 @@ class AudioLocatorServiceTest { fun `locate invalid progression`() = runBlocking { val service = AudioLocatorService( listOf( - Link(Href(Url("l1")!!), mediaType = MediaType.MP3, duration = 100.0), - Link(Href(Url("l2")!!), mediaType = MediaType.MP3, duration = 100.0) + Link(Href("l1")!!, mediaType = MediaType.MP3, duration = 100.0), + Link(Href("l2")!!, mediaType = MediaType.MP3, duration = 100.0) ) ) diff --git a/readium/streamer/src/test/java/org/readium/r2/streamer/parser/epub/MetadataTest.kt b/readium/streamer/src/test/java/org/readium/r2/streamer/parser/epub/MetadataTest.kt index ba718162a6..eae4288dcd 100644 --- a/readium/streamer/src/test/java/org/readium/r2/streamer/parser/epub/MetadataTest.kt +++ b/readium/streamer/src/test/java/org/readium/r2/streamer/parser/epub/MetadataTest.kt @@ -20,7 +20,6 @@ import org.readium.r2.shared.publication.Link as SharedLink import org.readium.r2.shared.publication.epub.EpubLayout import org.readium.r2.shared.publication.presentation.Presentation import org.readium.r2.shared.publication.presentation.presentation -import org.readium.r2.shared.util.Url import org.readium.r2.shared.util.mediatype.MediaType import org.robolectric.RobolectricTestRunner @@ -339,7 +338,7 @@ class MetadataMiscTest { @Test fun `Cover link is rightly identified`() { val expected = SharedLink( - href = Href(Url("OEBPS/cover.jpg")!!), + href = Href("OEBPS/cover.jpg")!!, mediaType = MediaType.JPEG, rels = setOf("cover") ) diff --git a/readium/streamer/src/test/java/org/readium/r2/streamer/parser/epub/NavigationDocumentParserTest.kt b/readium/streamer/src/test/java/org/readium/r2/streamer/parser/epub/NavigationDocumentParserTest.kt index c7bf225ecb..ee468858af 100644 --- a/readium/streamer/src/test/java/org/readium/r2/streamer/parser/epub/NavigationDocumentParserTest.kt +++ b/readium/streamer/src/test/java/org/readium/r2/streamer/parser/epub/NavigationDocumentParserTest.kt @@ -42,7 +42,7 @@ class NavigationDocumentParserTest { @Test fun `nav can be a non-direct descendant of body`() { assertThat(navSection["toc"]).containsExactly( - Link(title = "Chapter 1", href = Href(Url("OEBPS/xhtml/chapter1.xhtml")!!)) + Link(title = "Chapter 1", href = Href("OEBPS/xhtml/chapter1.xhtml")!!) ) } @@ -51,7 +51,7 @@ class NavigationDocumentParserTest { assertThat(navTitles["toc"]).contains( Link( title = "A link with new lines splitting the text", - href = Href(Url("OEBPS/xhtml/chapter1.xhtml")!!) + href = Href("OEBPS/xhtml/chapter1.xhtml")!! ) ) } @@ -61,7 +61,7 @@ class NavigationDocumentParserTest { assertThat(navTitles["toc"]).contains( Link( title = "A link with ignorable spaces", - href = Href(Url("OEBPS/xhtml/chapter2.xhtml")!!) + href = Href("OEBPS/xhtml/chapter2.xhtml")!! ) ) } @@ -71,7 +71,7 @@ class NavigationDocumentParserTest { assertThat(navTitles["toc"]).contains( Link( title = "A link with nested HTML elements", - href = Href(Url("OEBPS/xhtml/chapter3.xhtml")!!) + href = Href("OEBPS/xhtml/chapter3.xhtml")!! ) ) } @@ -79,7 +79,7 @@ class NavigationDocumentParserTest { @Test fun `Entries with a zero-length title and no children are ignored`() { assertThat(navTitles["toc"]).doesNotContain( - Link(title = "", href = Href(Url("OEBPS/xhtml/chapter4.xhtml")!!)) + Link(title = "", href = Href("OEBPS/xhtml/chapter4.xhtml")!!) ) } @@ -88,7 +88,7 @@ class NavigationDocumentParserTest { assertThat(navTitles["toc"]).doesNotContain( Link( title = "An unlinked element without children must be ignored", - href = Href(Url("#")!!) + href = Href("#")!! ) ) } @@ -96,33 +96,21 @@ class NavigationDocumentParserTest { @Test fun `Hierarchical items are allowed`() { assertThat(navChildren["toc"]).containsExactly( - Link(title = "Introduction", href = Href(Url("OEBPS/xhtml/introduction.xhtml")!!)), + Link(title = "Introduction", href = Href("OEBPS/xhtml/introduction.xhtml")!!), Link( title = "Part I", - href = Href(Url("#")!!), + href = Href("#")!!, children = listOf( - Link( - title = "Chapter 1", - href = Href(Url("OEBPS/xhtml/part1/chapter1.xhtml")!!) - ), - Link( - title = "Chapter 2", - href = Href(Url("OEBPS/xhtml/part1/chapter2.xhtml")!!) - ) + Link(title = "Chapter 1", href = Href("OEBPS/xhtml/part1/chapter1.xhtml")!!), + Link(title = "Chapter 2", href = Href("OEBPS/xhtml/part1/chapter2.xhtml")!!) ) ), Link( title = "Part II", - href = Href(Url("OEBPS/xhtml/part2/chapter1.xhtml")!!), + href = Href("OEBPS/xhtml/part2/chapter1.xhtml")!!, children = listOf( - Link( - title = "Chapter 1", - href = Href(Url("OEBPS/xhtml/part2/chapter1.xhtml")!!) - ), - Link( - title = "Chapter 2", - href = Href(Url("OEBPS/xhtml/part2/chapter2.xhtml")!!) - ) + Link(title = "Chapter 1", href = Href("OEBPS/xhtml/part2/chapter1.xhtml")!!), + Link(title = "Chapter 2", href = Href("OEBPS/xhtml/part2/chapter2.xhtml")!!) ) ) ) @@ -136,24 +124,24 @@ class NavigationDocumentParserTest { @Test fun `toc is rightly parsed`() { assertThat(navComplex["toc"]).containsExactly( - Link(title = "Chapter 1", href = Href(Url("OEBPS/xhtml/chapter1.xhtml")!!)), - Link(title = "Chapter 2", href = Href(Url("OEBPS/xhtml/chapter2.xhtml")!!)) + Link(title = "Chapter 1", href = Href("OEBPS/xhtml/chapter1.xhtml")!!), + Link(title = "Chapter 2", href = Href("OEBPS/xhtml/chapter2.xhtml")!!) ) } @Test fun `landmarks are rightly parsed`() { assertThat(navComplex["landmarks"]).containsExactly( - Link(title = "Table of Contents", href = Href(Url("OEBPS/xhtml/nav.xhtml#toc")!!)), - Link(title = "Begin Reading", href = Href(Url("OEBPS/xhtml/chapter1.xhtml")!!)) + Link(title = "Table of Contents", href = Href("OEBPS/xhtml/nav.xhtml#toc")!!), + Link(title = "Begin Reading", href = Href("OEBPS/xhtml/chapter1.xhtml")!!) ) } @Test fun `page-list is rightly parsed`() { assertThat(navComplex["page-list"]).containsExactly( - Link(title = "1", href = Href(Url("OEBPS/xhtml/chapter1.xhtml#page1")!!)), - Link(title = "2", href = Href(Url("OEBPS/xhtml/chapter1.xhtml#page2")!!)) + Link(title = "1", href = Href("OEBPS/xhtml/chapter1.xhtml#page1")!!), + Link(title = "2", href = Href("OEBPS/xhtml/chapter1.xhtml#page2")!!) ) } } diff --git a/readium/streamer/src/test/java/org/readium/r2/streamer/parser/epub/NcxParserTest.kt b/readium/streamer/src/test/java/org/readium/r2/streamer/parser/epub/NcxParserTest.kt index 92ba31d224..d090a33f63 100644 --- a/readium/streamer/src/test/java/org/readium/r2/streamer/parser/epub/NcxParserTest.kt +++ b/readium/streamer/src/test/java/org/readium/r2/streamer/parser/epub/NcxParserTest.kt @@ -40,7 +40,7 @@ class NcxParserTest { Assertions.assertThat(ncxTitles["toc"]).contains( Link( title = "A link with new lines splitting the text", - href = Href(Url("OEBPS/xhtml/chapter1.xhtml")!!) + href = Href("OEBPS/xhtml/chapter1.xhtml")!! ) ) } @@ -50,7 +50,7 @@ class NcxParserTest { Assertions.assertThat(ncxTitles["toc"]).contains( Link( title = "A link with ignorable spaces", - href = Href(Url("OEBPS/xhtml/chapter2.xhtml")!!) + href = Href("OEBPS/xhtml/chapter2.xhtml")!! ) ) } @@ -58,7 +58,7 @@ class NcxParserTest { @Test fun `Entries with a zero-length title and no children are ignored`() { Assertions.assertThat(ncxTitles["toc"]).doesNotContain( - Link(title = "", href = Href(Url("OEBPS/xhtml/chapter3.xhtml")!!)) + Link(title = "", href = Href("OEBPS/xhtml/chapter3.xhtml")!!) ) } @@ -67,7 +67,7 @@ class NcxParserTest { Assertions.assertThat(ncxTitles["toc"]).doesNotContain( Link( title = "An unlinked element without children must be ignored", - href = Href(Url("#")!!) + href = Href("#")!! ) ) } @@ -75,33 +75,21 @@ class NcxParserTest { @Test fun `Hierarchical items are allowed`() { Assertions.assertThat(ncxChildren["toc"]).containsExactly( - Link(title = "Introduction", href = Href(Url("OEBPS/xhtml/introduction.xhtml")!!)), + Link(title = "Introduction", href = Href("OEBPS/xhtml/introduction.xhtml")!!), Link( title = "Part I", - href = Href(Url("#")!!), + href = Href("#")!!, children = listOf( - Link( - title = "Chapter 1", - href = Href(Url("OEBPS/xhtml/part1/chapter1.xhtml")!!) - ), - Link( - title = "Chapter 2", - href = Href(Url("OEBPS/xhtml/part1/chapter2.xhtml")!!) - ) + Link(title = "Chapter 1", href = Href("OEBPS/xhtml/part1/chapter1.xhtml")!!), + Link(title = "Chapter 2", href = Href("OEBPS/xhtml/part1/chapter2.xhtml")!!) ) ), Link( title = "Part II", - href = Href(Url("OEBPS/xhtml/part2/chapter1.xhtml")!!), + href = Href("OEBPS/xhtml/part2/chapter1.xhtml")!!, children = listOf( - Link( - title = "Chapter 1", - href = Href(Url("OEBPS/xhtml/part2/chapter1.xhtml")!!) - ), - Link( - title = "Chapter 2", - href = Href(Url("OEBPS/xhtml/part2/chapter2.xhtml")!!) - ) + Link(title = "Chapter 1", href = Href("OEBPS/xhtml/part2/chapter1.xhtml")!!), + Link(title = "Chapter 2", href = Href("OEBPS/xhtml/part2/chapter2.xhtml")!!) ) ) ) @@ -115,16 +103,16 @@ class NcxParserTest { @Test fun `toc is rightly parsed`() { Assertions.assertThat(ncxComplex["toc"]).containsExactly( - Link(title = "Chapter 1", href = Href(Url("OEBPS/xhtml/chapter1.xhtml")!!)), - Link(title = "Chapter 2", href = Href(Url("OEBPS/xhtml/chapter2.xhtml")!!)) + Link(title = "Chapter 1", href = Href("OEBPS/xhtml/chapter1.xhtml")!!), + Link(title = "Chapter 2", href = Href("OEBPS/xhtml/chapter2.xhtml")!!) ) } @Test fun `page list is rightly parsed`() { Assertions.assertThat(ncxComplex["page-list"]).containsExactly( - Link(title = "1", href = Href(Url("OEBPS/xhtml/chapter1.xhtml#page1")!!)), - Link(title = "2", href = Href(Url("OEBPS/xhtml/chapter1.xhtml#page2")!!)) + Link(title = "1", href = Href("OEBPS/xhtml/chapter1.xhtml#page1")!!), + Link(title = "2", href = Href("OEBPS/xhtml/chapter1.xhtml#page2")!!) ) } } diff --git a/readium/streamer/src/test/java/org/readium/r2/streamer/parser/epub/PackageDocumentTest.kt b/readium/streamer/src/test/java/org/readium/r2/streamer/parser/epub/PackageDocumentTest.kt index 8bf54cd4f5..ce62a39dbe 100644 --- a/readium/streamer/src/test/java/org/readium/r2/streamer/parser/epub/PackageDocumentTest.kt +++ b/readium/streamer/src/test/java/org/readium/r2/streamer/parser/epub/PackageDocumentTest.kt @@ -146,11 +146,11 @@ class LinkTest { fun `readingOrder is rightly computed`() { assertThat(resourcesPub.readingOrder).containsExactly( Link( - href = Href(Url("titlepage.xhtml")!!), + href = Href("titlepage.xhtml")!!, mediaType = MediaType.XHTML ), Link( - href = Href(Url("OEBPS/chapter01.xhtml")!!), + href = Href("OEBPS/chapter01.xhtml")!!, mediaType = MediaType.XHTML ) ) @@ -160,42 +160,42 @@ class LinkTest { fun `resources are rightly computed`() { assertThat(resourcesPub.resources).containsExactlyInAnyOrder( Link( - href = Href(Url("OEBPS/fonts/MinionPro.otf")!!), + href = Href("OEBPS/fonts/MinionPro.otf")!!, mediaType = MediaType("application/vnd.ms-opentype")!! ), Link( - href = Href(Url("OEBPS/nav.xhtml")!!), + href = Href("OEBPS/nav.xhtml")!!, mediaType = MediaType.XHTML, rels = setOf("contents") ), Link( - href = Href(Url("style.css")!!), + href = Href("style.css")!!, mediaType = MediaType.CSS ), Link( - href = Href(Url("OEBPS/chapter01.smil")!!), + href = Href("OEBPS/chapter01.smil")!!, mediaType = MediaType.SMIL ), Link( - href = Href(Url("OEBPS/chapter02.smil")!!), + href = Href("OEBPS/chapter02.smil")!!, mediaType = MediaType.SMIL, duration = 1949.0 ), Link( - href = Href(Url("OEBPS/images/alice01a.png")!!), + href = Href("OEBPS/images/alice01a.png")!!, mediaType = MediaType.PNG, rels = setOf("cover") ), Link( - href = Href(Url("OEBPS/images/alice02a.gif")!!), + href = Href("OEBPS/images/alice02a.gif")!!, mediaType = MediaType.GIF ), Link( - href = Href(Url("OEBPS/chapter02.xhtml")!!), + href = Href("OEBPS/chapter02.xhtml")!!, mediaType = MediaType.XHTML ), Link( - href = Href(Url("OEBPS/nomediatype.txt")!!) + href = Href("OEBPS/nomediatype.txt")!! ) ) } @@ -206,15 +206,15 @@ class LinkMiscTest { fun `Fallbacks are mapped to alternates`() { assertThat(parsePackageDocument("package/fallbacks.opf")).isEqualTo( Link( - href = Href(Url("OEBPS/chap1_docbook.xml")!!), + href = Href("OEBPS/chap1_docbook.xml")!!, mediaType = MediaType("application/docbook+xml")!!, alternates = listOf( Link( - href = Href(Url("OEBPS/chap1.xml")!!), + href = Href("OEBPS/chap1.xml")!!, mediaType = MediaType("application/z3998-auth+xml")!!, alternates = listOf( Link( - href = Href(Url("OEBPS/chap1.xhtml")!!), + href = Href("OEBPS/chap1.xhtml")!!, mediaType = MediaType.XHTML ) ) diff --git a/readium/streamer/src/test/java/org/readium/r2/streamer/parser/pdf/PdfPositionsServiceTest.kt b/readium/streamer/src/test/java/org/readium/r2/streamer/parser/pdf/PdfPositionsServiceTest.kt index bbd8a9c405..ce9ac826fb 100644 --- a/readium/streamer/src/test/java/org/readium/r2/streamer/parser/pdf/PdfPositionsServiceTest.kt +++ b/readium/streamer/src/test/java/org/readium/r2/streamer/parser/pdf/PdfPositionsServiceTest.kt @@ -98,7 +98,7 @@ class PdfPositionsServiceTest { } private fun createService( - link: Link = Link(href = Href(Url("publication.pdf")!!)), + link: Link = Link(href = Href("publication.pdf")!!), pageCount: Int ) = PdfPositionsService( link = link,