+ fun `element loader can extract description if html is more complicated`() {
+ runWithCallback(textKey) { elementLoader, _, callback, _ ->
+ callback.loaded(FreenetURI(textKey), "text/html; charset=UTF-8", read("element-loader3.html"))
+ val linkedElement = elementLoader.loadElement(textKey)
+ assertThat(linkedElement, isLinkedElement(equalTo(textKey), allOf(
+ hasEntry("type", "html"), hasEntry("size", 204), hasEntry("sizeHuman", "204 B"),
+ hasEntry("title", "Some Nice Page Title"),
+ hasEntry("description", "This is the first paragraph of the very nice freesite.")
+ )))
+ }
+ }
+
+ @Test
+ fun `element loader can not extract title if it is missing`() {
+ runWithCallback(textKey) { elementLoader, _, callback, _ ->
+ callback.loaded(FreenetURI(textKey), "text/html; charset=UTF-8", read("element-loader4.html"))
+ val linkedElement = elementLoader.loadElement(textKey)
+ assertThat(linkedElement, isLinkedElement(equalTo(textKey), allOf(
+ hasEntry("type", "html"), hasEntry("size", 229), hasEntry("sizeHuman", "229 B"), hasEntry("title", null),
+ hasEntry("description", "This is an example of a very nice freesite.")
+ )))
+ }
+ }
+
+ @Test
+ fun `element loader can extract first paragraph from real-world example`() {
+ runWithCallback(textKey) { elementLoader, _, callback, _ ->
+ callback.loaded(FreenetURI(textKey), "text/html; charset=UTF-8", read("element-loader5.html"))
+ val linkedElement = elementLoader.loadElement(textKey)
+ assertThat(linkedElement, isLinkedElement(equalTo(textKey), allOf(
+ hasEntry("type", "html"), hasEntry("title", "Some Nice Page Title"),
+ hasEntry("description", "This is the first paragraph of the very nice freesite.")
+ )))
+ }
+ }
+
+ @Test
+ fun `image is not loaded again after it failed`() {
+ runWithCallback(IMAGE_ID) { elementLoader, _, callback, _ ->
+ elementLoader.loadElement(IMAGE_ID)
+ callback.failed(freenetURI)
+ assertThat(elementLoader.loadElement(IMAGE_ID).failed, equalTo(true))
+ }
+ }
+
+ @Test
+ fun `image is loaded again after failure cache is expired`() {
+ runWithCallback(IMAGE_ID, createTicker(1, MINUTES.toNanos(31))) { elementLoader, _, callback, _ ->
+ elementLoader.loadElement(IMAGE_ID)
+ callback.failed(freenetURI)
+ val linkedElement = elementLoader.loadElement(IMAGE_ID)
+ assertThat(linkedElement.failed, equalTo(false))
+ assertThat(linkedElement.loading, equalTo(true))
+ }