Merge pull request #265 from mauriciocolli/improve-tests
Test if services recognizes their own items urls
This commit is contained in:
commit
65f0ec6057
|
@ -2,20 +2,29 @@ package org.schabi.newpipe.extractor.services;
|
||||||
|
|
||||||
import org.schabi.newpipe.extractor.InfoItem;
|
import org.schabi.newpipe.extractor.InfoItem;
|
||||||
import org.schabi.newpipe.extractor.ListExtractor;
|
import org.schabi.newpipe.extractor.ListExtractor;
|
||||||
|
import org.schabi.newpipe.extractor.NewPipe;
|
||||||
|
import org.schabi.newpipe.extractor.StreamingService;
|
||||||
|
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
|
||||||
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
|
import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
|
||||||
|
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
|
||||||
import org.schabi.newpipe.extractor.localization.DateWrapper;
|
import org.schabi.newpipe.extractor.localization.DateWrapper;
|
||||||
|
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static junit.framework.TestCase.assertFalse;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static org.schabi.newpipe.extractor.ExtractorAsserts.*;
|
import static org.schabi.newpipe.extractor.ExtractorAsserts.*;
|
||||||
|
import static org.schabi.newpipe.extractor.StreamingService.*;
|
||||||
|
|
||||||
public final class DefaultTests {
|
public final class DefaultTests {
|
||||||
public static void defaultTestListOfItems(int expectedServiceId, List<? extends InfoItem> itemsList, List<Throwable> errors) {
|
public static void defaultTestListOfItems(StreamingService expectedService, List<? extends InfoItem> itemsList, List<Throwable> errors) throws ParsingException {
|
||||||
assertTrue("List of items is empty", !itemsList.isEmpty());
|
assertFalse("List of items is empty", itemsList.isEmpty());
|
||||||
assertFalse("List of items contains a null element", itemsList.contains(null));
|
assertFalse("List of items contains a null element", itemsList.contains(null));
|
||||||
assertEmptyErrors("Errors during stream list extraction", errors);
|
assertEmptyErrors("Errors during extraction", errors);
|
||||||
|
|
||||||
for (InfoItem item : itemsList) {
|
for (InfoItem item : itemsList) {
|
||||||
assertIsSecureUrl(item.getUrl());
|
assertIsSecureUrl(item.getUrl());
|
||||||
|
@ -23,12 +32,17 @@ public final class DefaultTests {
|
||||||
assertIsSecureUrl(item.getThumbnailUrl());
|
assertIsSecureUrl(item.getThumbnailUrl());
|
||||||
}
|
}
|
||||||
assertNotNull("InfoItem type not set: " + item, item.getInfoType());
|
assertNotNull("InfoItem type not set: " + item, item.getInfoType());
|
||||||
assertEquals("Service id doesn't match: " + item, expectedServiceId, item.getServiceId());
|
assertEquals("Unexpected item service id", expectedService.getServiceId(), item.getServiceId());
|
||||||
|
assertNotEmpty("Item name not set: " + item, item.getName());
|
||||||
|
|
||||||
if (item instanceof StreamInfoItem) {
|
if (item instanceof StreamInfoItem) {
|
||||||
StreamInfoItem streamInfoItem = (StreamInfoItem) item;
|
StreamInfoItem streamInfoItem = (StreamInfoItem) item;
|
||||||
assertNotEmpty("Uploader name not set: " + item, streamInfoItem.getUploaderName());
|
assertNotEmpty("Uploader name not set: " + item, streamInfoItem.getUploaderName());
|
||||||
assertNotEmpty("Uploader url not set: " + item, streamInfoItem.getUploaderUrl());
|
assertNotEmpty("Uploader url not set: " + item, streamInfoItem.getUploaderUrl());
|
||||||
|
assertIsSecureUrl(streamInfoItem.getUploaderUrl());
|
||||||
|
|
||||||
|
assertExpectedLinkType(expectedService, streamInfoItem.getUrl(), LinkType.STREAM);
|
||||||
|
assertExpectedLinkType(expectedService, streamInfoItem.getUploaderUrl(), LinkType.CHANNEL);
|
||||||
|
|
||||||
final String textualUploadDate = streamInfoItem.getTextualUploadDate();
|
final String textualUploadDate = streamInfoItem.getTextualUploadDate();
|
||||||
if (textualUploadDate != null && !textualUploadDate.isEmpty()) {
|
if (textualUploadDate != null && !textualUploadDate.isEmpty()) {
|
||||||
|
@ -37,34 +51,56 @@ public final class DefaultTests {
|
||||||
assertTrue("Upload date not in the past", uploadDate.date().before(Calendar.getInstance()));
|
assertTrue("Upload date not in the past", uploadDate.date().before(Calendar.getInstance()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else if (item instanceof ChannelInfoItem) {
|
||||||
|
final ChannelInfoItem channelInfoItem = (ChannelInfoItem) item;
|
||||||
|
assertExpectedLinkType(expectedService, channelInfoItem.getUrl(), LinkType.CHANNEL);
|
||||||
|
|
||||||
|
} else if (item instanceof PlaylistInfoItem) {
|
||||||
|
final PlaylistInfoItem playlistInfoItem = (PlaylistInfoItem) item;
|
||||||
|
assertExpectedLinkType(expectedService, playlistInfoItem.getUrl(), LinkType.PLAYLIST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends InfoItem> ListExtractor.InfoItemsPage<T> defaultTestRelatedItems(ListExtractor<T> extractor, int expectedServiceId) throws Exception {
|
private static void assertExpectedLinkType(StreamingService expectedService, String url, LinkType expectedLinkType) throws ParsingException {
|
||||||
|
final LinkType linkTypeByUrl = expectedService.getLinkTypeByUrl(url);
|
||||||
|
|
||||||
|
assertNotEquals("Url is not recognized by its own service: \"" + url + "\"",
|
||||||
|
LinkType.NONE, linkTypeByUrl);
|
||||||
|
assertEquals("Service returned wrong link type for: \"" + url + "\"",
|
||||||
|
expectedLinkType, linkTypeByUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends InfoItem> void assertNoMoreItems(ListExtractor<T> extractor) throws Exception {
|
||||||
|
assertFalse("More items available when it shouldn't", extractor.hasNextPage());
|
||||||
|
final String nextPageUrl = extractor.getNextPageUrl();
|
||||||
|
assertTrue("Next page is not empty or null", nextPageUrl == null || nextPageUrl.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends InfoItem> ListExtractor.InfoItemsPage<T> defaultTestRelatedItems(ListExtractor<T> extractor) throws Exception {
|
||||||
final ListExtractor.InfoItemsPage<T> page = extractor.getInitialPage();
|
final ListExtractor.InfoItemsPage<T> page = extractor.getInitialPage();
|
||||||
final List<T> itemsList = page.getItems();
|
final List<T> itemsList = page.getItems();
|
||||||
List<Throwable> errors = page.getErrors();
|
List<Throwable> errors = page.getErrors();
|
||||||
|
|
||||||
defaultTestListOfItems(expectedServiceId, itemsList, errors);
|
defaultTestListOfItems(extractor.getService(), itemsList, errors);
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends InfoItem> ListExtractor.InfoItemsPage<T> defaultTestMoreItems(ListExtractor<T> extractor, int expectedServiceId) throws Exception {
|
public static <T extends InfoItem> ListExtractor.InfoItemsPage<T> defaultTestMoreItems(ListExtractor<T> extractor) throws Exception {
|
||||||
assertTrue("Doesn't have more items", extractor.hasNextPage());
|
assertTrue("Doesn't have more items", extractor.hasNextPage());
|
||||||
ListExtractor.InfoItemsPage<T> nextPage = extractor.getPage(extractor.getNextPageUrl());
|
ListExtractor.InfoItemsPage<T> nextPage = extractor.getPage(extractor.getNextPageUrl());
|
||||||
final List<T> items = nextPage.getItems();
|
final List<T> items = nextPage.getItems();
|
||||||
assertTrue("Next page is empty", !items.isEmpty());
|
assertFalse("Next page is empty", items.isEmpty());
|
||||||
assertEmptyErrors("Next page have errors", nextPage.getErrors());
|
assertEmptyErrors("Next page have errors", nextPage.getErrors());
|
||||||
|
|
||||||
defaultTestListOfItems(expectedServiceId, nextPage.getItems(), nextPage.getErrors());
|
defaultTestListOfItems(extractor.getService(), nextPage.getItems(), nextPage.getErrors());
|
||||||
return nextPage;
|
return nextPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void defaultTestGetPageInNewExtractor(ListExtractor<? extends InfoItem> extractor, ListExtractor<? extends InfoItem> newExtractor, int expectedServiceId) throws Exception {
|
public static void defaultTestGetPageInNewExtractor(ListExtractor<? extends InfoItem> extractor, ListExtractor<? extends InfoItem> newExtractor) throws Exception {
|
||||||
final String nextPageUrl = extractor.getNextPageUrl();
|
final String nextPageUrl = extractor.getNextPageUrl();
|
||||||
|
|
||||||
final ListExtractor.InfoItemsPage<? extends InfoItem> page = newExtractor.getPage(nextPageUrl);
|
final ListExtractor.InfoItemsPage<? extends InfoItem> page = newExtractor.getPage(nextPageUrl);
|
||||||
defaultTestListOfItems(expectedServiceId, page.getItems(), page.getErrors());
|
defaultTestListOfItems(extractor.getService(), page.getItems(), page.getErrors());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,12 +68,12 @@ public class PeertubeChannelExtractorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRelatedItems() throws Exception {
|
public void testRelatedItems() throws Exception {
|
||||||
defaultTestRelatedItems(extractor, PeerTube.getServiceId());
|
defaultTestRelatedItems(extractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMoreRelatedItems() throws Exception {
|
public void testMoreRelatedItems() throws Exception {
|
||||||
defaultTestMoreItems(extractor, PeerTube.getServiceId());
|
defaultTestMoreItems(extractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -127,7 +127,7 @@ public class PeertubeChannelExtractorTest {
|
||||||
@Test
|
@Test
|
||||||
public void testGetPageInNewExtractor() throws Exception {
|
public void testGetPageInNewExtractor() throws Exception {
|
||||||
final ChannelExtractor newExtractor = PeerTube.getChannelExtractor(extractor.getUrl());
|
final ChannelExtractor newExtractor = PeerTube.getChannelExtractor(extractor.getUrl());
|
||||||
defaultTestGetPageInNewExtractor(extractor, newExtractor, PeerTube.getServiceId());
|
defaultTestGetPageInNewExtractor(extractor, newExtractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -165,12 +165,12 @@ public class PeertubeChannelExtractorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRelatedItems() throws Exception {
|
public void testRelatedItems() throws Exception {
|
||||||
defaultTestRelatedItems(extractor, PeerTube.getServiceId());
|
defaultTestRelatedItems(extractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMoreRelatedItems() throws Exception {
|
public void testMoreRelatedItems() throws Exception {
|
||||||
defaultTestMoreItems(extractor, PeerTube.getServiceId());
|
defaultTestMoreItems(extractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -5,90 +5,75 @@ import org.junit.Test;
|
||||||
import org.schabi.newpipe.DownloaderTestImpl;
|
import org.schabi.newpipe.DownloaderTestImpl;
|
||||||
import org.schabi.newpipe.extractor.ListExtractor;
|
import org.schabi.newpipe.extractor.ListExtractor;
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
import org.schabi.newpipe.extractor.NewPipe;
|
||||||
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
|
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
|
||||||
|
import org.schabi.newpipe.extractor.services.BaseListExtractorTest;
|
||||||
import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeTrendingExtractor;
|
import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeTrendingExtractor;
|
||||||
|
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudChartsExtractor;
|
||||||
|
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeTrendingExtractor;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static org.schabi.newpipe.extractor.ServiceList.PeerTube;
|
import static org.schabi.newpipe.extractor.ServiceList.*;
|
||||||
|
import static org.schabi.newpipe.extractor.services.DefaultTests.*;
|
||||||
|
|
||||||
/**
|
|
||||||
* Test for {@link PeertubeTrendingExtractor}
|
|
||||||
*/
|
|
||||||
public class PeertubeTrendingExtractorTest {
|
public class PeertubeTrendingExtractorTest {
|
||||||
|
public static class Trending implements BaseListExtractorTest {
|
||||||
|
private static PeertubeTrendingExtractor extractor;
|
||||||
|
|
||||||
static KioskExtractor extractor;
|
@BeforeClass
|
||||||
|
public static void setUp() throws Exception {
|
||||||
@BeforeClass
|
NewPipe.init(DownloaderTestImpl.getInstance());
|
||||||
public static void setUp() throws Exception {
|
// setting instance might break test when running in parallel
|
||||||
NewPipe.init(DownloaderTestImpl.getInstance());
|
PeerTube.setInstance(new PeertubeInstance("https://peertube.mastodon.host", "PeerTube on Mastodon.host"));
|
||||||
// setting instance might break test when running in parallel
|
extractor = (PeertubeTrendingExtractor) PeerTube.getKioskList()
|
||||||
PeerTube.setInstance(new PeertubeInstance("https://peertube.mastodon.host", "PeerTube on Mastodon.host"));
|
.getExtractorById("Trending", null);
|
||||||
extractor = PeerTube
|
extractor.fetchPage();
|
||||||
.getKioskList()
|
|
||||||
.getExtractorById("Trending", null);
|
|
||||||
extractor.fetchPage();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetDownloader() throws Exception {
|
|
||||||
assertNotNull(NewPipe.getDownloader());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetName() throws Exception {
|
|
||||||
assertEquals(extractor.getName(), "Trending");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testId() {
|
|
||||||
assertEquals(extractor.getId(), "Trending");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetStreams() throws Exception {
|
|
||||||
ListExtractor.InfoItemsPage<StreamInfoItem> page = extractor.getInitialPage();
|
|
||||||
if (!page.getErrors().isEmpty()) {
|
|
||||||
System.err.println("----------");
|
|
||||||
List<Throwable> errors = page.getErrors();
|
|
||||||
for (Throwable e : errors) {
|
|
||||||
e.printStackTrace();
|
|
||||||
System.err.println("----------");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
assertTrue("no streams are received",
|
|
||||||
!page.getItems().isEmpty()
|
|
||||||
&& page.getErrors().isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
public void testGetStreamsErrors() throws Exception {
|
// Extractor
|
||||||
assertTrue("errors during stream list extraction", extractor.getInitialPage().getErrors().isEmpty());
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHasMoreStreams() throws Exception {
|
public void testServiceId() {
|
||||||
// Setup the streams
|
assertEquals(PeerTube.getServiceId(), extractor.getServiceId());
|
||||||
extractor.getInitialPage();
|
}
|
||||||
assertTrue("has more streams", extractor.hasNextPage());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetNextPageUrl() throws Exception {
|
public void testName() throws Exception {
|
||||||
assertTrue(extractor.hasNextPage());
|
assertEquals("Trending", extractor.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetNextPage() throws Exception {
|
public void testId() throws Exception {
|
||||||
extractor.getInitialPage().getItems();
|
assertEquals("Trending", extractor.getId());
|
||||||
assertFalse("extractor has next streams", extractor.getPage(extractor.getNextPageUrl()) == null
|
}
|
||||||
|| extractor.getPage(extractor.getNextPageUrl()).getItems().isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetCleanUrl() throws Exception {
|
public void testUrl() throws ParsingException {
|
||||||
assertEquals(extractor.getUrl(), "https://peertube.mastodon.host/api/v1/videos?sort=-trending");
|
assertEquals("https://peertube.mastodon.host/api/v1/videos?sort=-trending", extractor.getUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOriginalUrl() throws ParsingException {
|
||||||
|
assertEquals("https://peertube.mastodon.host/api/v1/videos?sort=-trending", extractor.getOriginalUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
// ListExtractor
|
||||||
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRelatedItems() throws Exception {
|
||||||
|
defaultTestRelatedItems(extractor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMoreRelatedItems() throws Exception {
|
||||||
|
defaultTestMoreItems(extractor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,12 +64,12 @@ public class SoundcloudChannelExtractorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRelatedItems() throws Exception {
|
public void testRelatedItems() throws Exception {
|
||||||
defaultTestRelatedItems(extractor, SoundCloud.getServiceId());
|
defaultTestRelatedItems(extractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMoreRelatedItems() throws Exception {
|
public void testMoreRelatedItems() throws Exception {
|
||||||
defaultTestMoreItems(extractor, SoundCloud.getServiceId());
|
defaultTestMoreItems(extractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -120,7 +120,7 @@ public class SoundcloudChannelExtractorTest {
|
||||||
@Test
|
@Test
|
||||||
public void testGetPageInNewExtractor() throws Exception {
|
public void testGetPageInNewExtractor() throws Exception {
|
||||||
final ChannelExtractor newExtractor = SoundCloud.getChannelExtractor(extractor.getUrl());
|
final ChannelExtractor newExtractor = SoundCloud.getChannelExtractor(extractor.getUrl());
|
||||||
defaultTestGetPageInNewExtractor(extractor, newExtractor, SoundCloud.getServiceId());
|
defaultTestGetPageInNewExtractor(extractor, newExtractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -158,12 +158,12 @@ public class SoundcloudChannelExtractorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRelatedItems() throws Exception {
|
public void testRelatedItems() throws Exception {
|
||||||
defaultTestRelatedItems(extractor, SoundCloud.getServiceId());
|
defaultTestRelatedItems(extractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMoreRelatedItems() throws Exception {
|
public void testMoreRelatedItems() throws Exception {
|
||||||
defaultTestMoreItems(extractor, SoundCloud.getServiceId());
|
defaultTestMoreItems(extractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -5,87 +5,127 @@ import org.junit.Test;
|
||||||
import org.schabi.newpipe.DownloaderTestImpl;
|
import org.schabi.newpipe.DownloaderTestImpl;
|
||||||
import org.schabi.newpipe.extractor.ListExtractor;
|
import org.schabi.newpipe.extractor.ListExtractor;
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
import org.schabi.newpipe.extractor.NewPipe;
|
||||||
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
|
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
|
||||||
|
import org.schabi.newpipe.extractor.services.BaseListExtractorTest;
|
||||||
|
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeTrendingExtractor;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
||||||
|
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
||||||
|
import static org.schabi.newpipe.extractor.services.DefaultTests.*;
|
||||||
|
|
||||||
/**
|
|
||||||
* Test for {@link SoundcloudChartsLinkHandlerFactory}
|
|
||||||
*/
|
|
||||||
public class SoundcloudChartsExtractorTest {
|
public class SoundcloudChartsExtractorTest {
|
||||||
|
public static class NewAndHot implements BaseListExtractorTest {
|
||||||
|
private static SoundcloudChartsExtractor extractor;
|
||||||
|
|
||||||
static KioskExtractor extractor;
|
@BeforeClass
|
||||||
|
public static void setUp() throws Exception {
|
||||||
@BeforeClass
|
NewPipe.init(DownloaderTestImpl.getInstance());
|
||||||
public static void setUp() throws Exception {
|
extractor = (SoundcloudChartsExtractor) SoundCloud.getKioskList()
|
||||||
NewPipe.init(DownloaderTestImpl.getInstance());
|
.getExtractorById("New & hot", null);
|
||||||
extractor = SoundCloud
|
extractor.fetchPage();
|
||||||
.getKioskList()
|
}
|
||||||
.getExtractorById("Top 50", null);
|
|
||||||
extractor.fetchPage();
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
}
|
// Extractor
|
||||||
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
@Test
|
|
||||||
public void testGetDownloader() throws Exception {
|
@Test
|
||||||
assertNotNull(NewPipe.getDownloader());
|
public void testServiceId() {
|
||||||
}
|
assertEquals(SoundCloud.getServiceId(), extractor.getServiceId());
|
||||||
|
}
|
||||||
@Test
|
|
||||||
public void testGetName() throws Exception {
|
@Test
|
||||||
assertEquals(extractor.getName(), "Top 50");
|
public void testName() {
|
||||||
}
|
assertEquals("New & hot", extractor.getName());
|
||||||
|
}
|
||||||
@Test
|
|
||||||
public void testId() {
|
@Test
|
||||||
assertEquals(extractor.getId(), "Top 50");
|
public void testId() {
|
||||||
}
|
assertEquals("New & hot", extractor.getId());
|
||||||
|
}
|
||||||
@Test
|
|
||||||
public void testGetStreams() throws Exception {
|
@Test
|
||||||
ListExtractor.InfoItemsPage<StreamInfoItem> page = extractor.getInitialPage();
|
public void testUrl() throws ParsingException {
|
||||||
if (!page.getErrors().isEmpty()) {
|
assertEquals("https://soundcloud.com/charts/new", extractor.getUrl());
|
||||||
System.err.println("----------");
|
}
|
||||||
List<Throwable> errors = page.getErrors();
|
|
||||||
for (Throwable e : errors) {
|
@Test
|
||||||
e.printStackTrace();
|
public void testOriginalUrl() throws ParsingException {
|
||||||
System.err.println("----------");
|
assertEquals("https://soundcloud.com/charts/new", extractor.getOriginalUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
// ListExtractor
|
||||||
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRelatedItems() throws Exception {
|
||||||
|
defaultTestRelatedItems(extractor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMoreRelatedItems() throws Exception {
|
||||||
|
defaultTestMoreItems(extractor);
|
||||||
}
|
}
|
||||||
assertTrue("no streams are received",
|
|
||||||
!page.getItems().isEmpty()
|
|
||||||
&& page.getErrors().isEmpty());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public static class Top50Charts implements BaseListExtractorTest {
|
||||||
public void testGetStreamsErrors() throws Exception {
|
private static SoundcloudChartsExtractor extractor;
|
||||||
assertTrue("errors during stream list extraction", extractor.getInitialPage().getErrors().isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@BeforeClass
|
||||||
public void testHasMoreStreams() throws Exception {
|
public static void setUp() throws Exception {
|
||||||
// Setup the streams
|
NewPipe.init(DownloaderTestImpl.getInstance());
|
||||||
extractor.getInitialPage();
|
extractor = (SoundcloudChartsExtractor) SoundCloud.getKioskList()
|
||||||
assertTrue("has more streams", extractor.hasNextPage());
|
.getExtractorById("Top 50", null);
|
||||||
}
|
extractor.fetchPage();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
public void testGetNextPageUrl() throws Exception {
|
// Extractor
|
||||||
assertTrue(extractor.hasNextPage());
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetNextPage() throws Exception {
|
public void testServiceId() {
|
||||||
extractor.getInitialPage().getItems();
|
assertEquals(SoundCloud.getServiceId(), extractor.getServiceId());
|
||||||
assertFalse("extractor has next streams", extractor.getPage(extractor.getNextPageUrl()) == null
|
}
|
||||||
|| extractor.getPage(extractor.getNextPageUrl()).getItems().isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetCleanUrl() throws Exception {
|
public void testName() {
|
||||||
assertEquals(extractor.getUrl(), "https://soundcloud.com/charts/top");
|
assertEquals("Top 50", extractor.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testId() {
|
||||||
|
assertEquals("Top 50", extractor.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUrl() throws ParsingException {
|
||||||
|
assertEquals("https://soundcloud.com/charts/top", extractor.getUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOriginalUrl() throws ParsingException {
|
||||||
|
assertEquals("https://soundcloud.com/charts/top", extractor.getOriginalUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
// ListExtractor
|
||||||
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRelatedItems() throws Exception {
|
||||||
|
defaultTestRelatedItems(extractor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMoreRelatedItems() throws Exception {
|
||||||
|
defaultTestMoreItems(extractor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import org.junit.Test;
|
||||||
import org.schabi.newpipe.DownloaderTestImpl;
|
import org.schabi.newpipe.DownloaderTestImpl;
|
||||||
import org.schabi.newpipe.extractor.ListExtractor;
|
import org.schabi.newpipe.extractor.ListExtractor;
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
import org.schabi.newpipe.extractor.NewPipe;
|
||||||
import org.schabi.newpipe.extractor.ServiceList;
|
|
||||||
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
|
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
|
||||||
import org.schabi.newpipe.extractor.services.BasePlaylistExtractorTest;
|
import org.schabi.newpipe.extractor.services.BasePlaylistExtractorTest;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||||
|
@ -67,13 +66,13 @@ public class SoundcloudPlaylistExtractorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRelatedItems() throws Exception {
|
public void testRelatedItems() throws Exception {
|
||||||
defaultTestRelatedItems(extractor, SoundCloud.getServiceId());
|
defaultTestRelatedItems(extractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMoreRelatedItems() {
|
public void testMoreRelatedItems() {
|
||||||
try {
|
try {
|
||||||
defaultTestMoreItems(extractor, SoundCloud.getServiceId());
|
defaultTestMoreItems(extractor);
|
||||||
} catch (Throwable ignored) {
|
} catch (Throwable ignored) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -165,12 +164,12 @@ public class SoundcloudPlaylistExtractorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRelatedItems() throws Exception {
|
public void testRelatedItems() throws Exception {
|
||||||
defaultTestRelatedItems(extractor, SoundCloud.getServiceId());
|
defaultTestRelatedItems(extractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMoreRelatedItems() throws Exception {
|
public void testMoreRelatedItems() throws Exception {
|
||||||
defaultTestMoreItems(extractor, SoundCloud.getServiceId());
|
defaultTestMoreItems(extractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -226,11 +225,10 @@ public class SoundcloudPlaylistExtractorTest {
|
||||||
// Additional Testing
|
// Additional Testing
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
@Ignore
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetPageInNewExtractor() throws Exception {
|
public void testGetPageInNewExtractor() throws Exception {
|
||||||
final PlaylistExtractor newExtractor = SoundCloud.getPlaylistExtractor(extractor.getUrl());
|
final PlaylistExtractor newExtractor = SoundCloud.getPlaylistExtractor(extractor.getUrl());
|
||||||
defaultTestGetPageInNewExtractor(extractor, newExtractor, SoundCloud.getServiceId());
|
defaultTestGetPageInNewExtractor(extractor, newExtractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -269,18 +267,18 @@ public class SoundcloudPlaylistExtractorTest {
|
||||||
@Ignore
|
@Ignore
|
||||||
@Test
|
@Test
|
||||||
public void testRelatedItems() throws Exception {
|
public void testRelatedItems() throws Exception {
|
||||||
defaultTestRelatedItems(extractor, SoundCloud.getServiceId());
|
defaultTestRelatedItems(extractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: FUCK THIS: This triggers a 500 at sever
|
//TODO: FUCK THIS: This triggers a 500 at sever
|
||||||
@Ignore
|
@Ignore
|
||||||
@Test
|
@Test
|
||||||
public void testMoreRelatedItems() throws Exception {
|
public void testMoreRelatedItems() throws Exception {
|
||||||
ListExtractor.InfoItemsPage<StreamInfoItem> currentPage = defaultTestMoreItems(extractor, ServiceList.SoundCloud.getServiceId());
|
ListExtractor.InfoItemsPage<StreamInfoItem> currentPage = defaultTestMoreItems(extractor);
|
||||||
// Test for 2 more levels
|
// Test for 2 more levels
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
currentPage = extractor.getPage(currentPage.getNextPageUrl());
|
currentPage = extractor.getPage(currentPage.getNextPageUrl());
|
||||||
defaultTestListOfItems(SoundCloud.getServiceId(), currentPage.getItems(), currentPage.getErrors());
|
defaultTestListOfItems(SoundCloud, currentPage.getItems(), currentPage.getErrors());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.schabi.newpipe.DownloaderTestImpl;
|
import org.schabi.newpipe.DownloaderTestImpl;
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
import org.schabi.newpipe.extractor.NewPipe;
|
||||||
import org.schabi.newpipe.extractor.ServiceList;
|
|
||||||
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
|
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
|
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
|
@ -88,12 +87,12 @@ public class YoutubeChannelExtractorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRelatedItems() throws Exception {
|
public void testRelatedItems() throws Exception {
|
||||||
defaultTestRelatedItems(extractor, YouTube.getServiceId());
|
defaultTestRelatedItems(extractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMoreRelatedItems() throws Exception {
|
public void testMoreRelatedItems() throws Exception {
|
||||||
defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId());
|
defaultTestMoreItems(extractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -178,12 +177,12 @@ public class YoutubeChannelExtractorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRelatedItems() throws Exception {
|
public void testRelatedItems() throws Exception {
|
||||||
defaultTestRelatedItems(extractor, YouTube.getServiceId());
|
defaultTestRelatedItems(extractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMoreRelatedItems() throws Exception {
|
public void testMoreRelatedItems() throws Exception {
|
||||||
defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId());
|
defaultTestMoreItems(extractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -241,7 +240,7 @@ public class YoutubeChannelExtractorTest {
|
||||||
@Test
|
@Test
|
||||||
public void testGetPageInNewExtractor() throws Exception {
|
public void testGetPageInNewExtractor() throws Exception {
|
||||||
final ChannelExtractor newExtractor = YouTube.getChannelExtractor(extractor.getUrl());
|
final ChannelExtractor newExtractor = YouTube.getChannelExtractor(extractor.getUrl());
|
||||||
defaultTestGetPageInNewExtractor(extractor, newExtractor, YouTube.getServiceId());
|
defaultTestGetPageInNewExtractor(extractor, newExtractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -280,12 +279,12 @@ public class YoutubeChannelExtractorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRelatedItems() throws Exception {
|
public void testRelatedItems() throws Exception {
|
||||||
defaultTestRelatedItems(extractor, YouTube.getServiceId());
|
defaultTestRelatedItems(extractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMoreRelatedItems() throws Exception {
|
public void testMoreRelatedItems() throws Exception {
|
||||||
defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId());
|
defaultTestMoreItems(extractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -371,12 +370,12 @@ public class YoutubeChannelExtractorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRelatedItems() throws Exception {
|
public void testRelatedItems() throws Exception {
|
||||||
defaultTestRelatedItems(extractor, YouTube.getServiceId());
|
defaultTestRelatedItems(extractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMoreRelatedItems() throws Exception {
|
public void testMoreRelatedItems() throws Exception {
|
||||||
defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId());
|
defaultTestMoreItems(extractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -461,12 +460,12 @@ public class YoutubeChannelExtractorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRelatedItems() throws Exception {
|
public void testRelatedItems() throws Exception {
|
||||||
defaultTestRelatedItems(extractor, YouTube.getServiceId());
|
defaultTestRelatedItems(extractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMoreRelatedItems() throws Exception {
|
public void testMoreRelatedItems() throws Exception {
|
||||||
defaultTestMoreItems(extractor, YouTube.getServiceId());
|
defaultTestMoreItems(extractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -553,13 +552,13 @@ public class YoutubeChannelExtractorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRelatedItems() throws Exception {
|
public void testRelatedItems() throws Exception {
|
||||||
defaultTestRelatedItems(extractor, YouTube.getServiceId());
|
defaultTestRelatedItems(extractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMoreRelatedItems() {
|
public void testMoreRelatedItems() {
|
||||||
try {
|
try {
|
||||||
defaultTestMoreItems(extractor, YouTube.getServiceId());
|
defaultTestMoreItems(extractor);
|
||||||
} catch (Throwable ignored) {
|
} catch (Throwable ignored) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ public class YoutubeChannelLocalizationTest {
|
||||||
final ChannelExtractor extractor = YouTube.getChannelExtractor(channelUrl);
|
final ChannelExtractor extractor = YouTube.getChannelExtractor(channelUrl);
|
||||||
extractor.forceLocalization(currentLocalization);
|
extractor.forceLocalization(currentLocalization);
|
||||||
extractor.fetchPage();
|
extractor.fetchPage();
|
||||||
itemsPage = defaultTestRelatedItems(extractor, YouTube.getServiceId());
|
itemsPage = defaultTestRelatedItems(extractor);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
System.out.println("[!] " + currentLocalization + " → failed");
|
System.out.println("[!] " + currentLocalization + " → failed");
|
||||||
throw e;
|
throw e;
|
||||||
|
|
|
@ -84,7 +84,7 @@ public class YoutubeCommentsExtractorTest {
|
||||||
public void testGetCommentsAllData() throws IOException, ExtractionException {
|
public void testGetCommentsAllData() throws IOException, ExtractionException {
|
||||||
InfoItemsPage<CommentsInfoItem> comments = extractorYT.getInitialPage();
|
InfoItemsPage<CommentsInfoItem> comments = extractorYT.getInitialPage();
|
||||||
|
|
||||||
DefaultTests.defaultTestListOfItems(YouTube.getServiceId(), comments.getItems(), comments.getErrors());
|
DefaultTests.defaultTestListOfItems(YouTube, comments.getItems(), comments.getErrors());
|
||||||
for (CommentsInfoItem c : comments.getItems()) {
|
for (CommentsInfoItem c : comments.getItems()) {
|
||||||
assertFalse(StringUtil.isBlank(c.getAuthorEndpoint()));
|
assertFalse(StringUtil.isBlank(c.getAuthorEndpoint()));
|
||||||
assertFalse(StringUtil.isBlank(c.getAuthorName()));
|
assertFalse(StringUtil.isBlank(c.getAuthorName()));
|
||||||
|
|
|
@ -10,6 +10,7 @@ import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeFeedExtra
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
||||||
|
import static org.schabi.newpipe.extractor.services.DefaultTests.assertNoMoreItems;
|
||||||
import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestRelatedItems;
|
import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestRelatedItems;
|
||||||
|
|
||||||
public class YoutubeFeedExtractorTest {
|
public class YoutubeFeedExtractorTest {
|
||||||
|
@ -60,13 +61,12 @@ public class YoutubeFeedExtractorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRelatedItems() throws Exception {
|
public void testRelatedItems() throws Exception {
|
||||||
defaultTestRelatedItems(extractor, YouTube.getServiceId());
|
defaultTestRelatedItems(extractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMoreRelatedItems() {
|
public void testMoreRelatedItems() throws Exception {
|
||||||
assertFalse(extractor.hasNextPage());
|
assertNoMoreItems(extractor);
|
||||||
assertNull(extractor.getNextPageUrl());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
package org.schabi.newpipe.extractor.services.youtube;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.schabi.newpipe.DownloaderTestImpl;
|
||||||
|
import org.schabi.newpipe.extractor.NewPipe;
|
||||||
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
|
import org.schabi.newpipe.extractor.services.BaseListExtractorTest;
|
||||||
|
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeTrendingExtractor;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
||||||
|
import static org.schabi.newpipe.extractor.services.DefaultTests.assertNoMoreItems;
|
||||||
|
import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestRelatedItems;
|
||||||
|
|
||||||
|
public class YoutubeKioskExtractorTest {
|
||||||
|
public static class Trending implements BaseListExtractorTest {
|
||||||
|
private static YoutubeTrendingExtractor extractor;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void setUp() throws Exception {
|
||||||
|
NewPipe.init(DownloaderTestImpl.getInstance());
|
||||||
|
extractor = (YoutubeTrendingExtractor) YouTube.getKioskList().getDefaultKioskExtractor();
|
||||||
|
extractor.fetchPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
// Extractor
|
||||||
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testServiceId() {
|
||||||
|
assertEquals(YouTube.getServiceId(), extractor.getServiceId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testName() throws Exception {
|
||||||
|
assertEquals("Trending", extractor.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testId() throws Exception {
|
||||||
|
assertEquals("Trending", extractor.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUrl() throws ParsingException {
|
||||||
|
assertEquals("https://www.youtube.com/feed/trending", extractor.getUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOriginalUrl() throws ParsingException {
|
||||||
|
assertEquals("https://www.youtube.com/feed/trending", extractor.getOriginalUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
// ListExtractor
|
||||||
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRelatedItems() throws Exception {
|
||||||
|
defaultTestRelatedItems(extractor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMoreRelatedItems() throws Exception {
|
||||||
|
assertNoMoreItems(extractor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,7 +6,7 @@ import org.junit.Test;
|
||||||
import org.schabi.newpipe.DownloaderTestImpl;
|
import org.schabi.newpipe.DownloaderTestImpl;
|
||||||
import org.schabi.newpipe.extractor.ListExtractor;
|
import org.schabi.newpipe.extractor.ListExtractor;
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
import org.schabi.newpipe.extractor.NewPipe;
|
||||||
import org.schabi.newpipe.extractor.ServiceList;
|
|
||||||
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
|
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
|
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
|
||||||
|
@ -93,12 +93,12 @@ public class YoutubePlaylistExtractorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRelatedItems() throws Exception {
|
public void testRelatedItems() throws Exception {
|
||||||
defaultTestRelatedItems(extractor, YouTube.getServiceId());
|
defaultTestRelatedItems(extractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMoreRelatedItems() throws Exception {
|
public void testMoreRelatedItems() throws Exception {
|
||||||
defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId());
|
defaultTestMoreItems(extractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -161,7 +161,7 @@ public class YoutubePlaylistExtractorTest {
|
||||||
@Test
|
@Test
|
||||||
public void testGetPageInNewExtractor() throws Exception {
|
public void testGetPageInNewExtractor() throws Exception {
|
||||||
final PlaylistExtractor newExtractor = YouTube.getPlaylistExtractor(extractor.getUrl());
|
final PlaylistExtractor newExtractor = YouTube.getPlaylistExtractor(extractor.getUrl());
|
||||||
defaultTestGetPageInNewExtractor(extractor, newExtractor, YouTube.getServiceId());
|
defaultTestGetPageInNewExtractor(extractor, newExtractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -200,18 +200,17 @@ public class YoutubePlaylistExtractorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRelatedItems() throws Exception {
|
public void testRelatedItems() throws Exception {
|
||||||
defaultTestRelatedItems(extractor, YouTube.getServiceId());
|
defaultTestRelatedItems(extractor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMoreRelatedItems() throws Exception {
|
public void testMoreRelatedItems() throws Exception {
|
||||||
ListExtractor.InfoItemsPage<StreamInfoItem> currentPage
|
ListExtractor.InfoItemsPage<StreamInfoItem> currentPage = defaultTestMoreItems(extractor);
|
||||||
= defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId());
|
|
||||||
|
|
||||||
// test for 2 more levels
|
// test for 2 more levels
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
currentPage = extractor.getPage(currentPage.getNextPageUrl());
|
currentPage = extractor.getPage(currentPage.getNextPageUrl());
|
||||||
defaultTestListOfItems(YouTube.getServiceId(), currentPage.getItems(), currentPage.getErrors());
|
defaultTestListOfItems(YouTube, currentPage.getItems(), currentPage.getErrors());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,101 +0,0 @@
|
||||||
package org.schabi.newpipe.extractor.services.youtube;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Created by Christian Schabesberger on 12.08.17.
|
|
||||||
*
|
|
||||||
* Copyright (C) Christian Schabesberger 2017 <chris.schabesberger@mailbox.org>
|
|
||||||
* YoutubeTrendingExtractorTest.java is part of NewPipe.
|
|
||||||
*
|
|
||||||
* NewPipe is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* NewPipe is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.schabi.newpipe.DownloaderTestImpl;
|
|
||||||
import org.schabi.newpipe.extractor.ListExtractor;
|
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
|
||||||
import org.schabi.newpipe.extractor.localization.ContentCountry;
|
|
||||||
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeTrendingExtractor;
|
|
||||||
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeTrendingLinkHandlerFactory;
|
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
|
||||||
import org.schabi.newpipe.extractor.utils.Utils;
|
|
||||||
|
|
||||||
import static junit.framework.TestCase.assertFalse;
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmptyErrors;
|
|
||||||
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test for {@link YoutubeTrendingLinkHandlerFactory}
|
|
||||||
*/
|
|
||||||
public class YoutubeTrendingExtractorTest {
|
|
||||||
|
|
||||||
static YoutubeTrendingExtractor extractor;
|
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
public static void setUp() throws Exception {
|
|
||||||
NewPipe.init(DownloaderTestImpl.getInstance());
|
|
||||||
extractor = (YoutubeTrendingExtractor) YouTube
|
|
||||||
.getKioskList()
|
|
||||||
.getExtractorById("Trending", null);
|
|
||||||
extractor.forceContentCountry(new ContentCountry("de"));
|
|
||||||
extractor.fetchPage();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetDownloader() throws Exception {
|
|
||||||
assertNotNull(NewPipe.getDownloader());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetName() throws Exception {
|
|
||||||
assertFalse(extractor.getName().isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testId() throws Exception {
|
|
||||||
assertEquals(extractor.getId(), "Trending");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetStreamsQuantity() throws Exception {
|
|
||||||
ListExtractor.InfoItemsPage<StreamInfoItem> page = extractor.getInitialPage();
|
|
||||||
Utils.printErrors(page.getErrors());
|
|
||||||
assertTrue("no streams are received", page.getItems().size() >= 20);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetStreamsErrors() throws Exception {
|
|
||||||
assertEmptyErrors("errors during stream list extraction", extractor.getInitialPage().getErrors());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHasMoreStreams() throws Exception {
|
|
||||||
// Setup the streams
|
|
||||||
extractor.getInitialPage();
|
|
||||||
assertFalse("has more streams", extractor.hasNextPage());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetNextPage() {
|
|
||||||
assertTrue("extractor has next streams", extractor.getPage(extractor.getNextPageUrl()) == null
|
|
||||||
|| extractor.getPage(extractor.getNextPageUrl()).getItems().isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetUrl() throws Exception {
|
|
||||||
assertEquals(extractor.getUrl(), extractor.getUrl(), "https://www.youtube.com/feed/trending");
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue