Add filter for TorrentHound results page.
[rhynodge.git] / src / test / java / net / pterodactylus / rhynodge / filters / torrents / TorrentHoundFilterTest.java
1 package net.pterodactylus.rhynodge.filters.torrents;
2
3 import java.io.IOException;
4
5 import net.pterodactylus.rhynodge.State;
6 import net.pterodactylus.rhynodge.states.HtmlState;
7 import net.pterodactylus.rhynodge.states.TorrentState;
8
9 import org.hamcrest.MatcherAssert;
10 import org.hamcrest.Matchers;
11 import org.jsoup.Jsoup;
12 import org.jsoup.nodes.Document;
13 import org.junit.Test;
14
15 /**
16  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
17  */
18 public class TorrentHoundFilterTest {
19
20         private final TorrentHoundFilter filter = new TorrentHoundFilter();
21
22         @Test
23         public void canParseResults() throws IOException {
24                 Document document = Jsoup.parse(getClass().getResourceAsStream("torrent-hound-results.html"), "UTF-8", "http://www.torrenthound.com/search/1/Ubuntu+14+04+amd64+ISO/added:desc");
25                 HtmlState htmlState = new HtmlState("http://www.torrenthound.com/search/1/Ubuntu+14+04+amd64+ISO/added:desc", document);
26                 State newState = filter.filter(htmlState);
27                 MatcherAssert.assertThat(newState, Matchers.notNullValue());
28                 MatcherAssert.assertThat(newState, Matchers.instanceOf(TorrentState.class));
29                 TorrentState torrentState = (TorrentState) newState;
30                 MatcherAssert.assertThat(torrentState.torrentFiles(), Matchers.hasSize(5));
31                 MatcherAssert.assertThat(torrentState.torrentFiles(), Matchers.contains(
32                                 TorrentMatcher.isTorrent("Ubuntu 14 04 1 server amd64 ISO", "572.0 Mb", "magnet:?xl=599785472&xt=urn:btih:2d066c94480adcf52bfd1185a75eb4ddc1777673&dn=ubuntu+14+04+1+server+amd64+iso&tr=udp%3A%2F%2Ftracker.istole.it%3A80&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80", 5, 3),
33                                 TorrentMatcher.isTorrent("Ubuntu 14 04 1 desktop amd64 ISO", "981.0 Mb", 34, 23),
34                                 TorrentMatcher.isTorrent("Ubuntu 14 04 1 desktop amd64+mac ISO", "979.0 Mb", 1, 0),
35                                 TorrentMatcher.isTorrent("Ubuntu gnome 14 04 1 desktop amd64 ISO", "935.0 Mb", 1, 1),
36                                 TorrentMatcher.isTorrent("Ubuntu gnome 14.04 beta1 desktop amd64.ISO", "890.0 Mb", 2, 0)
37                 ));
38         }
39
40 }