Permalink
Browse files

Add tests for real feed and clarify documentation

  • Loading branch information...
ouattararomuald committed Jan 3, 2019
1 parent 6d5ebfb commit 75bc59c51f8e4b3373a8d623f4f56c9923d2e26f
@@ -0,0 +1,37 @@
package com.ouattararomuald.sample

import com.google.common.truth.Truth.assertThat
import com.ouattararomuald.syndication.Syndication
import org.junit.jupiter.api.Test

class RealFeedTest {

private val atomFeedUrls = listOf(
"https://www.senat.fr/rss/rapports.xml",
"https://www.reddit.com/r/androiddev/.rss"
)

private val rssFeedUrls = listOf(
"https://www.senat.fr/rss/rapports.rss",
"https://www.lemonde.fr/rss/une.xml",
"https://www.howtogeek.com/feed/",
"https://rss.simplecast.com/podcasts/1684/rss"
)

@Test fun `atom feeds`() {
atomFeedUrls.forEach {
val syndication = Syndication(url = it)
val reader = syndication.create(RssReader::class.java)
assertThat(reader.readAtom()).isNotNull()
}
}

@Test fun `rss feeds`() {
rssFeedUrls.forEach {
val syndication = Syndication(url = it)
val reader = syndication.create(RssReader::class.java)
val feed = reader.readRss()
assertThat(feed).isNotNull()
}
}
}
@@ -0,0 +1,11 @@
package com.ouattararomuald.sample

import com.ouattararomuald.syndication.atom.AtomFeed
import com.ouattararomuald.syndication.rss.RssFeed

interface RssReader {

fun readAtom(): AtomFeed

fun readRss(): RssFeed
}
@@ -1,6 +1,7 @@
package com.ouattararomuald.syndication

import org.simpleframework.xml.Attribute
import org.simpleframework.xml.Root
import org.simpleframework.xml.Text
import java.io.Serializable

@@ -34,6 +35,7 @@ import java.io.Serializable
* @property type determines how this information is encoded.
* @property value content of tag.
*/
@Root(strict = false)
data class Copyright(
@field:Attribute(name = "type", required = false)
@param:Attribute(name = "type", required = false)
@@ -1,7 +1,7 @@
package com.ouattararomuald.syndication

import org.simpleframework.xml.Attribute
import org.simpleframework.xml.Element
import org.simpleframework.xml.Root
import org.simpleframework.xml.Text
import java.io.Serializable

@@ -34,7 +34,7 @@ import java.io.Serializable
*
* @property type determines how this information is encoded (default="text")
*/
@Element
@Root(strict = false)
data class Summary(
@get:Attribute(name = "type", required = false)
@param:Attribute(name = "type", required = false)
@@ -1,7 +1,7 @@
package com.ouattararomuald.syndication

import org.simpleframework.xml.Attribute
import org.simpleframework.xml.Element
import org.simpleframework.xml.Root
import org.simpleframework.xml.Text
import java.io.Serializable

@@ -34,7 +34,7 @@ import java.io.Serializable
*
* @property type determines how this information is encoded.
*/
@Element
@Root(strict = false)
data class Title(
@get:Attribute(name = "type", required = false)
@param:Attribute(name = "type", required = false)
@@ -1,7 +1,9 @@
package com.ouattararomuald.syndication.atom

import org.simpleframework.xml.Root
import java.io.Serializable

@Root(strict = false)
data class AtomSource(
val id: String? = null,
val title: String? = null,
@@ -0,0 +1,20 @@
package com.ouattararomuald.syndication.rss

import org.simpleframework.xml.Attribute
import org.simpleframework.xml.Root
import java.io.Serializable

@Root(strict = false)
data class Enclosure(
@field:Attribute(name = "url")
@param:Attribute(name = "url")
val url: String,

@field:Attribute(name = "length")
@param:Attribute(name = "length")
val length: Long,

@field:Attribute(name = "type")
@param:Attribute(name = "type")
val type: String
) : Serializable
@@ -1,20 +1,27 @@
package com.ouattararomuald.syndication.rss

import org.simpleframework.xml.Attribute
import org.simpleframework.xml.Element
import org.simpleframework.xml.Root
import java.io.Serializable

@Root(strict = false)
data class Image(
@field:Attribute(name = "href", required = false)
@param:Attribute(name = "href", required = false)
val href: String? = null,

@field:Element(name = "url", required = false)
@param:Element(name = "url", required = false)
val url: String,
val url: String? = null,

@field:Element(name = "title", required = false)
@param:Element(name = "title", required = false)
val title: String,
val title: String? = null,

@field:Element(name = "link", required = false)
@param:Element(name = "link", required = false)
val link: String,
val link: String? = null,

@field:Element(name = "subtitle", required = false)
@param:Element(name = "subtitle", required = false)
@@ -44,6 +44,10 @@ data class Item(
@param:Element(name = "comments", required = false)
val comments: String? = null,

@field:Element(name = "enclosure", required = false)
@param:Element(name = "enclosure", required = false)
val enclosure: Enclosure? = null,

@field:Element(name = "source", required = false)
@param:Element(name = "source", required = false)
val source: RssSource? = null,
@@ -1,11 +1,11 @@
package com.ouattararomuald.syndication.rss

import org.simpleframework.xml.Attribute
import org.simpleframework.xml.Element
import org.simpleframework.xml.Root
import org.simpleframework.xml.Text
import java.io.Serializable

@Element
@Root(strict = false)
data class RssSource(
@get:Attribute(name = "url", required = false)
@param:Attribute(name = "url", required = false)
@@ -11,7 +11,7 @@ import java.io.Serializable
* `Thursday`, `Friday`, `Saturday` or `Sunday`. Aggregators may not read the channel during days
* listed in the `<skipDays>` element.
*/
@Root
@Root(strict = false)
data class SkipDays(
@field:ElementList(name = "day", inline = true)
@param:ElementList(name = "day", inline = true)
@@ -11,7 +11,7 @@ import java.io.Serializable
* representing a time in GMT, when aggregators, if they support the feature, may not read the
* channel on hours listed in the `<skipHours>` element. The hour beginning at midnight is hour zero.
*/
@Root
@Root(strict = false)
data class SkipHours(
@field:ElementList(name = "hour", inline = true)
@param:ElementList(name = "hour", inline = true)
@@ -16,6 +16,25 @@ val syndicationReader = Syndication(
)
```

create and interface like the one below

```kotlin
interface RssReader {
fun readRss(): Deferred<RssFeed>
fun readAtom(): Deferred<AtomFeed>
}
```

then let `Syndication` class generates an implementation of that interface `RssReader`:

```kotlin
val reader = syndicationReader.create(RssReader::class.java)
val rssFeed = runBlocking { reader.readRss() }
val atomFeed = runBlocking { reader.readAtom() }
```

## Download

Snapshots of the development version are available in [Sonatype's snapshots repository](https://oss.sonatype.org/content/repositories/snapshots/).

0 comments on commit 75bc59c

Please sign in to comment.