Add tests for method LocalRSSDataSource.handleSpecialCases()

This commit is contained in:
Shinokuni 2020-10-04 22:53:00 +02:00
parent 63497bd049
commit 8304e7709f
5 changed files with 73 additions and 2 deletions

View File

@ -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>

View File

@ -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>

View File

@ -96,6 +96,34 @@ class LocalRSSDataSourceTest {
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
fun response304Test() {
mockServer.enqueue(MockResponse().setResponseCode(HttpURLConnection.HTTP_NOT_MODIFIED))

View File

@ -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
fun isUrlRSSResource(url: String): Boolean {
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,
// otherwise we just add the rss url
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 (siteUrl == null) siteUrl = response.request.url.scheme + "://" + response.request.url.host
}

View File

@ -19,7 +19,7 @@ class RSS1FeedAdapter : XmlAdapter<Feed> {
return try {
konsume.child("RDF") {
allChildrenAutoIgnore("channel") {
feed.url = attributes.getValue("about",
feed.url = attributes.getValueOpt("about",
namespace = "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
allChildrenAutoIgnore(names) {