mirror of https://github.com/readrops/Readrops.git
Add tests for method LocalRSSDataSource.handleSpecialCases()
This commit is contained in:
parent
63497bd049
commit
8304e7709f
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US">
|
||||||
|
<id>tag:github.com,2008:/readrops/Readrops/commits/develop</id>
|
||||||
|
<title>Recent Commits to Readrops:develop</title>
|
||||||
|
<updated>2020-09-06T21:09:59Z</updated>
|
||||||
|
<subtitle>Here is a subtitle</subtitle>
|
||||||
|
</feed>
|
|
@ -0,0 +1,31 @@
|
||||||
|
<rdf:RDF xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:syn="http://purl.org/rss/1.0/modules/syndication/"
|
||||||
|
xmlns="http://purl.org/rss/1.0/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
|
||||||
|
|
||||||
|
<channel>
|
||||||
|
<title>Slashdot</title>
|
||||||
|
<description>News for nerds, stuff that matters</description>
|
||||||
|
<dc:language>en-us</dc:language>
|
||||||
|
<dc:rights>Copyright 1997-2016, SlashdotMedia. All Rights Reserved.</dc:rights>
|
||||||
|
<dc:date>2020-09-23T16:20:20+00:00</dc:date>
|
||||||
|
<dc:publisher>Dice</dc:publisher>
|
||||||
|
<dc:creator>help@slashdot.org</dc:creator>
|
||||||
|
<dc:subject>Technology</dc:subject>
|
||||||
|
<syn:updateBase>1970-01-01T00:00+00:00</syn:updateBase>
|
||||||
|
<syn:updateFrequency>1</syn:updateFrequency>
|
||||||
|
<syn:updatePeriod>hourly</syn:updatePeriod>
|
||||||
|
<image rdf:resource="https://a.fsdn.com/sd/topics/topicslashdot.gif" />
|
||||||
|
<textinput rdf:resource="https://slashdot.org/search.pl" />
|
||||||
|
<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" href="http://rss.slashdot.org/slashdot/slashdotMain"
|
||||||
|
rel="self" type="application/rdf+xml" />
|
||||||
|
<feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0"
|
||||||
|
uri="slashdot/slashdotmain" />
|
||||||
|
<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" href="http://pubsubhubbub.appspot.com/"
|
||||||
|
rel="hub" />
|
||||||
|
</channel>
|
||||||
|
<image rdf:about="https://a.fsdn.com/sd/topics/topicslashdot.gif">
|
||||||
|
<title>Slashdot</title>
|
||||||
|
<url>https://a.fsdn.com/sd/topics/topicslashdot.gif</url>
|
||||||
|
<link>https://slashdot.org/</link>
|
||||||
|
</image>
|
||||||
|
</rdf:RDF>
|
|
@ -96,6 +96,34 @@ class LocalRSSDataSourceTest {
|
||||||
assertEquals(pair.second.size, 10)
|
assertEquals(pair.second.size, 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun specialCasesAtomTest() {
|
||||||
|
val stream = context.resources.assets.open("localfeed/atom/atom_feed_no_url_siteurl.xml")
|
||||||
|
|
||||||
|
mockServer.enqueue(MockResponse().setResponseCode(HttpURLConnection.HTTP_OK)
|
||||||
|
.addHeader(LibUtils.CONTENT_TYPE_HEADER, "application/atom+xml")
|
||||||
|
.setBody(Buffer().readFrom(stream)))
|
||||||
|
|
||||||
|
val pair = localRSSDataSource.queryRSSResource(url.toString(), null)!!
|
||||||
|
|
||||||
|
assertEquals(pair.first.url, "http://localhost:8080/rss")
|
||||||
|
assertEquals(pair.first.siteUrl, "http://localhost")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun specialCasesRSS1Test() {
|
||||||
|
val stream = context.resources.assets.open("localfeed/rss1/rss1_feed_no_url_siteurl.xml")
|
||||||
|
|
||||||
|
mockServer.enqueue(MockResponse().setResponseCode(HttpURLConnection.HTTP_OK)
|
||||||
|
.addHeader(LibUtils.CONTENT_TYPE_HEADER, "application/rdf+xml")
|
||||||
|
.setBody(Buffer().readFrom(stream)))
|
||||||
|
|
||||||
|
val pair = localRSSDataSource.queryRSSResource(url.toString(), null)!!
|
||||||
|
|
||||||
|
assertEquals(pair.first.url, "http://localhost:8080/rss")
|
||||||
|
assertEquals(pair.first.siteUrl, "http://localhost")
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun response304Test() {
|
fun response304Test() {
|
||||||
mockServer.enqueue(MockResponse().setResponseCode(HttpURLConnection.HTTP_NOT_MODIFIED))
|
mockServer.enqueue(MockResponse().setResponseCode(HttpURLConnection.HTTP_NOT_MODIFIED))
|
||||||
|
|
|
@ -63,6 +63,11 @@ class LocalRSSDataSource(private val httpClient: OkHttpClient) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the provided url is a RSS resource
|
||||||
|
* @param url url to check
|
||||||
|
* @return true if [url] is a RSS resource, false otherwise
|
||||||
|
*/
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
fun isUrlRSSResource(url: String): Boolean {
|
fun isUrlRSSResource(url: String): Boolean {
|
||||||
val response = queryUrl(url, null)
|
val response = queryUrl(url, null)
|
||||||
|
@ -131,7 +136,7 @@ class LocalRSSDataSource(private val httpClient: OkHttpClient) {
|
||||||
// if an atom:link element was parsed, we still replace its value as it is unreliable,
|
// if an atom:link element was parsed, we still replace its value as it is unreliable,
|
||||||
// otherwise we just add the rss url
|
// otherwise we just add the rss url
|
||||||
url = response.request.url.toString()
|
url = response.request.url.toString()
|
||||||
} else if (type == LocalRSSHelper.RSSType.ATOM) {
|
} else if (type == LocalRSSHelper.RSSType.ATOM || type == LocalRSSHelper.RSSType.RSS_1) {
|
||||||
if (url == null) url = response.request.url.toString()
|
if (url == null) url = response.request.url.toString()
|
||||||
if (siteUrl == null) siteUrl = response.request.url.scheme + "://" + response.request.url.host
|
if (siteUrl == null) siteUrl = response.request.url.scheme + "://" + response.request.url.host
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ class RSS1FeedAdapter : XmlAdapter<Feed> {
|
||||||
return try {
|
return try {
|
||||||
konsume.child("RDF") {
|
konsume.child("RDF") {
|
||||||
allChildrenAutoIgnore("channel") {
|
allChildrenAutoIgnore("channel") {
|
||||||
feed.url = attributes.getValue("about",
|
feed.url = attributes.getValueOpt("about",
|
||||||
namespace = "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
|
namespace = "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
|
||||||
|
|
||||||
allChildrenAutoIgnore(names) {
|
allChildrenAutoIgnore(names) {
|
||||||
|
|
Loading…
Reference in New Issue