1 package net.pterodactylus.rhynodge.filters.torrents;
3 import java.io.IOException;
5 import net.pterodactylus.rhynodge.filters.ResourceLoader;
7 import org.hamcrest.Description;
8 import org.hamcrest.Matcher;
9 import org.hamcrest.MatcherAssert;
10 import org.hamcrest.Matchers;
11 import org.hamcrest.TypeSafeDiagnosingMatcher;
12 import org.jsoup.nodes.Document;
13 import org.jsoup.nodes.Element;
14 import org.jsoup.select.Elements;
15 import org.junit.Test;
18 * Unit test for {@link KickAssTorrentsFilter}.
20 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
22 public class KickAssTorrentsFilterTest {
24 private final KickAssTorrentsFilter filter = new KickAssTorrentsFilter();
25 private final Document document;
27 public KickAssTorrentsFilterTest() throws IOException {
28 document = ResourceLoader.loadDocument(getClass(), "kickass-to-results.html", "https://kickass.to/");
32 public void filterCanParseTorrentFiles() {
33 Elements torrentRows = filter.getDataRows(document);
35 MatcherAssert.assertThat(torrentRows, Matchers.contains(
36 matchesTorrent("ubuntu 14.10 desktop amd64.iso", "1.08 GB", "magnet:?xt=urn:btih:2CCB0AFFD641FB6A4B5395C602BE71B43AB85B5A&dn=ubuntu+14+10+desktop+amd64+iso&tr=http%3A%2F%2Ftracker.aletorrenty.pl%3A2710%2Fannounce&tr=udp%3A%2F%2Fopen.demonii.com%3A1337", "http://torcache.net/torrent/2CCB0AFFD641FB6A4B5395C602BE71B43AB85B5A.torrent?title=[kickass.to]ubuntu.14.10.desktop.amd64.iso", 1, 5, 2),
37 matchesTorrent("ubuntu gnome 14.10 desktop amd64.iso", "998 MB", "magnet:?xt=urn:btih:DD2FD99B6DE623B14146EA32E659AAE44FE0E15D&dn=ubuntu+gnome+14+10+desktop+amd64+iso&tr=udp%3A%2F%2Fopen.demonii.com%3A1337%2Fannounce", "http://torcache.net/torrent/DD2FD99B6DE623B14146EA32E659AAE44FE0E15D.torrent?title=[kickass.to]ubuntu.gnome.14.10.desktop.amd64.iso", 1, 4, 1),
38 matchesTorrent("Ubuntu Utopic 14.10 Server AMD64.iso", "582 MB", "magnet:?xt=urn:btih:EC5CE22050E0E3D7E7A279C241901B5BC1F36FE7&dn=ubuntu+utopic+14+10+server+amd64+iso&tr=udp%3A%2F%2Fopen.demonii.com%3A1337%2Fannounce", "http://torcache.net/torrent/EC5CE22050E0E3D7E7A279C241901B5BC1F36FE7.torrent?title=[kickass.to]ubuntu.utopic.14.10.server.amd64.iso", 1, 13, 0),
39 matchesTorrent("Ubuntu Utopic 14.10 Server i386.iso", "576 MB", "magnet:?xt=urn:btih:108F0624B9FD0AB708FA284F6B1F3C3022BDEDD6&dn=ubuntu+utopic+14+10+server+i386+iso&tr=udp%3A%2F%2Fopen.demonii.com%3A1337%2Fannounce", "http://torcache.net/torrent/108F0624B9FD0AB708FA284F6B1F3C3022BDEDD6.torrent?title=[kickass.to]ubuntu.utopic.14.10.server.i386.iso", 1, 4, 0),
40 matchesTorrent("ubuntu 14.10 desktop amd64.iso", "1.08 GB", "magnet:?xt=urn:btih:F7D6ECA0E176901119A7457C917A9A3547CB3CC3&dn=ubuntu+14+10+desktop+amd64+iso&tr=udp%3A%2F%2Fopen.demonii.com%3A1337%2Fannounce", "http://torcache.net/torrent/F7D6ECA0E176901119A7457C917A9A3547CB3CC3.torrent?title=[kickass.to]ubuntu.14.10.desktop.amd64.iso", 1, 0, 0),
41 matchesTorrent("Ubuntu 14.10 Desktop 32bit ISO", "1.11 GB", "magnet:?xt=urn:btih:1619ECC9373C3639F4EE3E261638F29B33A6CBD6&dn=ubuntu+14+10+desktop+32bit+iso&tr=udp%3A%2F%2Fopen.demonii.com%3A1337%2Fannounce", "http://torcache.net/torrent/1619ECC9373C3639F4EE3E261638F29B33A6CBD6.torrent?title=[kickass.to]ubuntu.14.10.desktop.32bit.iso", 1, 90, 13),
42 matchesTorrent("Ubuntu 14.10 Desktop 64bit ISO", "1.08 GB", "magnet:?xt=urn:btih:B415C913643E5FF49FE37D304BBB5E6E11AD5101&dn=ubuntu+14+10+desktop+64bit+iso&tr=udp%3A%2F%2Fopen.demonii.com%3A1337%2Fannounce", "http://torcache.net/torrent/B415C913643E5FF49FE37D304BBB5E6E11AD5101.torrent?title=[kickass.to]ubuntu.14.10.desktop.64bit.iso", 1, 228, 32),
43 matchesTorrent("ubuntu gnome 14.10 beta2 desktop amd64.iso", "993 MB", "magnet:?xt=urn:btih:5D31B3DD8FA36E04B8FEA196F133056672567BCA&dn=ubuntu+gnome+14+10+beta2+desktop+amd64+iso&tr=udp%3A%2F%2Fopen.demonii.com%3A1337%2Fannounce", "http://torcache.net/torrent/5D31B3DD8FA36E04B8FEA196F133056672567BCA.torrent?title=[kickass.to]ubuntu.gnome.14.10.beta2.desktop.amd64.iso", 1, 12, 2),
44 matchesTorrent("ubuntukylin 14.10 beta2 desktop amd64.iso", "1.27 GB", "magnet:?xt=urn:btih:9EDE5CF4F404030251F8319234CE81157D4FE001&dn=ubuntukylin+14+10+beta2+desktop+amd64+iso&tr=udp%3A%2F%2Fopen.demonii.com%3A1337%2Fannounce", "http://torcache.net/torrent/9EDE5CF4F404030251F8319234CE81157D4FE001.torrent?title=[kickass.to]ubuntukylin.14.10.beta2.desktop.amd64.iso", 1, 3, 0),
45 matchesTorrent("ubuntukylin 14.10 beta2 desktop i386.iso", "1.28 GB", "magnet:?xt=urn:btih:E97417DB2F25D0FD87F7DF1E7B3B44CE1212F38E&dn=ubuntukylin+14+10+beta2+desktop+i386+iso&tr=udp%3A%2F%2Fopen.demonii.com%3A1337%2Fannounce", "http://torcache.net/torrent/E97417DB2F25D0FD87F7DF1E7B3B44CE1212F38E.torrent?title=[kickass.to]ubuntukylin.14.10.beta2.desktop.i386.iso", 1, 2, 0),
46 matchesTorrent("ubuntustudio 14.10 beta2 dvd amd64.iso", "2.06 GB", "magnet:?xt=urn:btih:9230D72299A38213609104661181FE46918B6455&dn=ubuntustudio+14+10+beta2+dvd+amd64+iso&tr=udp%3A%2F%2Fopen.demonii.com%3A1337%2Fannounce", "http://torcache.net/torrent/9230D72299A38213609104661181FE46918B6455.torrent?title=[kickass.to]ubuntustudio.14.10.beta2.dvd.amd64.iso", 1, 2, 0),
47 matchesTorrent("Ubuntustudio 14.10 Beta2 i386.iso", "2.19 GB", "magnet:?xt=urn:btih:6C50D760243D02D238726F6A62D6725F667E1AA9&dn=ubuntustudio+14+10+beta2+i386+iso&tr=udp%3A%2F%2Fopen.demonii.com%3A1337%2Fannounce", "http://torcache.net/torrent/6C50D760243D02D238726F6A62D6725F667E1AA9.torrent?title=[kickass.to]ubuntustudio.14.10.beta2.i386.iso", 1, 2, 0),
48 matchesTorrent("Ubuntu 14.10 Desktop AMD64.iso", "1.1 GB", "magnet:?xt=urn:btih:18FC1F0208015A23BC08AD3AC5BDD2C46E20E8D0&dn=ubuntu+14+10+desktop+amd64+iso&tr=udp%3A%2F%2Fopen.demonii.com%3A1337%2Fannounce", "http://torcache.net/torrent/18FC1F0208015A23BC08AD3AC5BDD2C46E20E8D0.torrent?title=[kickass.to]ubuntu.14.10.desktop.amd64.iso", 1, 1, 0),
49 matchesTorrent("Ubuntu Utopic 14.10 Desktop i386.iso", "1.12 GB", "magnet:?xt=urn:btih:54ADDC06D2DD7BF33DDFA9DB49FEA1A79C990D44&dn=ubuntu+utopic+14+10+desktop+i386+iso&tr=udp%3A%2F%2Fopen.demonii.com%3A1337%2Fannounce", "http://torcache.net/torrent/54ADDC06D2DD7BF33DDFA9DB49FEA1A79C990D44.torrent?title=[kickass.to]ubuntu.utopic.14.10.desktop.i386.iso", 1, 2, 0)
53 private Matcher<? super Element> matchesTorrent(String name, String size, String magnetUri, String downloadUri, int fileCount, int seedCount, int leechCount) {
54 return new TypeSafeDiagnosingMatcher<Element>() {
56 protected boolean matchesSafely(Element dataRow, Description mismatchDescription) {
57 String extractedName = filter.extractName(dataRow);
58 if (!extractedName.equals(name)) {
59 mismatchDescription.appendText("name is ").appendValue(extractedName);
62 String extractedSize = filter.extractSize(dataRow);
63 if (!extractedSize.equals(size)) {
64 mismatchDescription.appendText("size is ").appendValue(extractedSize);
67 String extractedMagnetUri = filter.extractMagnetUri(dataRow);
68 if (!extractedMagnetUri.equals(magnetUri)) {
69 mismatchDescription.appendText("magnet is ").appendValue(extractedMagnetUri);
72 String extractedDownloadUri = filter.extractDownloadUri(dataRow);
73 if (!extractedDownloadUri.equals(downloadUri)) {
74 mismatchDescription.appendText("download is ").appendValue(extractedDownloadUri);
77 int extractedFileCount = filter.extractFileCount(dataRow);
78 if (extractedFileCount != fileCount) {
79 mismatchDescription.appendText("file count is ").appendValue(extractedFileCount);
82 int extractedSeedCount = filter.extractSeedCount(dataRow);
83 if (extractedSeedCount != seedCount) {
84 mismatchDescription.appendText("seed count is ").appendValue(extractedSeedCount);
87 int extractedLeechCount = filter.extractLeechCount(dataRow);
88 if (extractedLeechCount != leechCount) {
89 mismatchDescription.appendText("leech count is ").appendValue(extractedLeechCount);
96 public void describeTo(Description description) {
98 .appendText("matches torrent with name ").appendValue(name)
99 .appendText(", size ").appendValue(size)
100 .appendText(", magnet ").appendValue(magnetUri)
101 .appendText(", download ").appendValue(downloadUri)
102 .appendText(", file count ").appendValue(fileCount)
103 .appendText(", seed count ").appendValue(seedCount)
104 .appendText(", leech count ").appendValue(leechCount);